Compare commits

..
47 Commits
Author SHA1 Message Date
Nigel Tao b69ebf4606 wuffs gen -version=0.3.6 2026-10-20 14:29:37 +11:00
Nigel Tao 5527993842 lib: fix "go test" example names
This backports commit 689f84213f from the
main branch (working on an unstable v0.4) to the v0.3 branch.
2026-10-20 14:25:29 +11:00
Nigel Tao 32a23a9bb5 base: backport parse_number_{u64,f64} fixes
This backports commits 9d41525a2f and
c99f5af9fe from the main branch (working
on an unstable v0.4) to the v0.3 branch.
2026-10-20 14:17:58 +11:00
Nigel Tao d1a6f2c3de wuffs gen -version=0.3.5 2026-07-11 20:37:47 +10:00
Nigel Tao 40445d992b mimiclib: #include <limits.h> and <stdint.h>
This backports commit 39baf44c19d0759c42853f5e7d72bd1ba0070321 from the
main branch (working on an unstable v0.4) to the v0.3 branch.
2026-07-11 20:36:12 +10:00
Nigel Tao e7b15476b8 test/data: rename non-ascii/😻.txt
This backports commit 7250990196 from the
main branch (working on an unstable v0.4) to the v0.3 branch.
2026-07-11 20:33:41 +10:00
Nigel Tao ec71f9c6d8 wuffs gen -version=0.3.4 2024-04-19 21:44:35 +10:00
Nigel Tao a138188d57 std/png: ignore tRNS chunks for color types 4, 6
This backports commit da0d51d802 from the
main branch (working on an unstable v0.4) to the v0.3 branch.

Updates #146
2024-04-19 21:41:16 +10:00
Nigel Tao d910658bce wuffs gen -version=0.3.3 2023-04-08 14:57:52 +10:00
Nigel Tao 00d5e35865 floatconv: optimize parse_number_f64 fallback
The time taken running script/manual-test-parse-number-f64.cc on the
parse-number-fxx-test-data suite falls from 3.565s to 2.491s (a 1.43x
ratio; the inverse is 0.70 = 100% - 30%).

Fixes #113
2023-04-08 14:56:32 +10:00
Nigel Tao 05f0172b93 script/manual-test-truncated-input: re-enable WBMP 2023-04-07 16:06:09 +10:00
Nigel Tao 57bd11bf39 wuffs gen -version=0.3.2 2023-04-07 13:53:11 +10:00
Nigel Tao 67d9a68c49 Update doc/changelog.md for v0.3.2 2023-04-07 13:52:02 +10:00
Nigel Tao 17f7613262 std/{bmp,nie}: allow decode_frame to small pixbuf 2023-03-27 21:22:06 +11:00
Nigel Tao baac49dca7 script: add manual-test-truncated-input.cc
Updates #96
2023-03-27 21:15:38 +11:00
Nigel Tao a12a807d0e script/print-image-metadata: fix infinite loop
Fixes #107
2023-03-18 14:49:50 +11:00
Nigel Tao 000b0a3445 std/png: decode "truncated input" for short chunks
Updates #101
2023-03-12 19:23:41 +11:00
Nigel Tao ef74175a20 wuffs gen -version=0.3.1 2023-03-04 09:54:01 +11:00
Nigel Tao 02844cdca4 go.{mod,sum}: go get -u golang.org/x/image/draw 2023-02-24 10:04:51 +11:00
Nigel Tao 3db9e96b0d root: add .gitattributes
Fixes #100
2023-02-24 09:47:23 +11:00
Nigel Tao be37cc46c0 A+C: add sarastro-nl 2023-02-04 16:06:37 +11:00
Nigel Tao 4d4c3c4c3c floatconv: tweak Simple Decimal Conversion
This tweaks the code and comments added in commit 36d7748e "Merge pull
request #90 from sarastro-nl/improvement/optimize-SDC" and commit
d46220ca "optimize SDC". Both of those two commit messages are short but
see the discussion re algorithmic changes on PR 87 (yes, 87, not 90):
https://github.com/google/wuffs/pull/87

Also run clang-format.

Also update doc/changelog.md

Compared to before commit d46220ca "optimize SDC", when running
script/manual-test-parse-number-f64.cc and disabling both the
etc__parse_number_f64_eisel_lemire function and the "If both man and
(10 ** exp10) are exactly representable by a double" fast path, the
tests still pass but the number of etc__high_prec_dec__small_lshift and
etc__high_prec_dec__small_rshift calls drop:

Function    Before      After       Ratio
lshift      31174584    25762258    82.64% = 100% - 17.36%
rshift      21592604    20982502    97.17% = 100% -  2.83%

The time taken drops from 15.984s to 13.710s (85.77% = 100% - 14.23%).

To repeat, these are the improvements after disabling the Eisel-Lemire
and other fast paths. Simple Decimal Conversion is the rarely invoked
fallback parse_number_f64 algorithm. The practical improvement (with
Eisel-Lemire etc enabled) is smaller.
2023-02-04 14:48:25 +11:00
Nigel Tao 36d7748ed5 Merge pull request #90 from sarastro-nl/improvement/optimize-SDC
optimize SDC
2023-02-04 10:30:29 +11:00
Nigel Tao 43ca567205 fuzz: check "short read" and io_reader.is_closed
Updates #96
2023-02-01 22:32:36 +11:00
Nigel Tao 3474af988b std/{cbor,json}: add test for empty input
Updates #96
2023-02-01 21:43:25 +11:00
Nigel Tao 248bddcfd2 std/*image_decoder*: add "#truncated input"
name                                                       old speed      new speed       delta

wuffs_bmp_decode_40k/clang11                               4.36GB/s ± 0%   4.48GB/s ± 0%   +2.74%  (p=0.008 n=5+5)

wuffs_bmp_decode_40k/gcc10                                 4.49GB/s ± 0%   4.50GB/s ± 0%   +0.15%  (p=0.008 n=5+5)

wuffs_gif_decode_1k_bw/clang11                              723MB/s ± 0%    742MB/s ± 0%   +2.64%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/clang11                 177MB/s ± 0%    177MB/s ± 0%     ~     (p=0.841 n=5+5)
wuffs_gif_decode_1k_color_part_init/clang11                 216MB/s ± 0%    217MB/s ± 0%   +0.66%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/clang11                           793MB/s ± 0%    785MB/s ± 0%   -1.04%  (p=0.016 n=4+5)
wuffs_gif_decode_10k_indexed/clang11                        210MB/s ± 0%    209MB/s ± 0%   -0.38%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/clang11                                254MB/s ± 0%    255MB/s ± 0%   +0.37%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/clang11                    568MB/s ± 0%    569MB/s ± 0%   +0.14%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/clang11                     221MB/s ± 0%    221MB/s ± 0%     ~     (p=0.222 n=5+5)
wuffs_gif_decode_1000k_full_init/clang11                    224MB/s ± 0%    224MB/s ± 0%     ~     (p=0.690 n=5+5)
wuffs_gif_decode_1000k_part_init/clang11                    224MB/s ± 0%    224MB/s ± 0%     ~     (p=0.841 n=5+5)
wuffs_gif_decode_anim_screencap/clang11                    1.30GB/s ± 0%   1.30GB/s ± 0%     ~     (p=0.111 n=5+5)

wuffs_gif_decode_1k_bw/gcc10                                638MB/s ± 0%    672MB/s ± 0%   +5.23%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/gcc10                   175MB/s ± 0%    181MB/s ± 0%   +3.03%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/gcc10                   203MB/s ± 0%    209MB/s ± 0%   +3.38%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/gcc10                             798MB/s ± 0%    804MB/s ± 0%   +0.70%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/gcc10                          210MB/s ± 0%    212MB/s ± 0%   +0.84%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/gcc10                                  265MB/s ± 0%    265MB/s ± 0%     ~     (p=0.222 n=5+5)
wuffs_gif_decode_100k_artificial/gcc10                      576MB/s ± 0%    577MB/s ± 0%     ~     (p=0.690 n=5+5)
wuffs_gif_decode_100k_realistic/gcc10                       226MB/s ± 0%    227MB/s ± 0%   +0.21%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_full_init/gcc10                      230MB/s ± 0%    231MB/s ± 0%   +0.32%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/gcc10                      230MB/s ± 0%    231MB/s ± 0%   +0.43%  (p=0.008 n=5+5)
wuffs_gif_decode_anim_screencap/gcc10                      1.32GB/s ± 0%   1.32GB/s ± 0%   +0.18%  (p=0.008 n=5+5)

wuffs_png_decode_image_19k_8bpp/clang11                     267MB/s ± 0%    273MB/s ± 0%   +2.47%  (p=0.008 n=5+5)
wuffs_png_decode_image_40k_24bpp/clang11                    326MB/s ± 0%    327MB/s ± 0%   +0.51%  (p=0.008 n=5+5)
wuffs_png_decode_image_77k_8bpp/clang11                     954MB/s ± 0%    969MB/s ± 0%   +1.58%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang11   865MB/s ± 0%    864MB/s ± 0%   -0.18%  (p=0.016 n=5+5)
wuffs_png_decode_image_552k_32bpp_verify_checksum/clang11   832MB/s ± 0%    831MB/s ± 0%   -0.11%  (p=0.016 n=5+5)
wuffs_png_decode_image_4002k_24bpp/clang11                  331MB/s ± 0%    332MB/s ± 0%   +0.18%  (p=0.016 n=5+5)

wuffs_png_decode_image_19k_8bpp/gcc10                       298MB/s ± 0%    292MB/s ± 0%   -2.17%  (p=0.008 n=5+5)
wuffs_png_decode_image_40k_24bpp/gcc10                      352MB/s ± 0%    349MB/s ± 0%   -0.75%  (p=0.008 n=5+5)
wuffs_png_decode_image_77k_8bpp/gcc10                      1.05GB/s ± 0%   1.03GB/s ± 0%   -1.56%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10     950MB/s ± 0%    949MB/s ± 0%     ~     (p=0.310 n=5+5)
wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10     905MB/s ± 0%    902MB/s ± 0%   -0.35%  (p=0.008 n=5+5)
wuffs_png_decode_image_4002k_24bpp/gcc10                    360MB/s ± 0%    358MB/s ± 0%   -0.40%  (p=0.008 n=5+5)

wuffs_tga_decode_19k_8bpp/clang11                          7.81GB/s ± 0%   7.90GB/s ± 0%   +1.22%  (p=0.008 n=5+5)
wuffs_tga_decode_77k_24bpp/clang11                         4.34GB/s ± 0%   4.36GB/s ± 0%   +0.59%  (p=0.008 n=5+5)

wuffs_tga_decode_19k_8bpp/gcc10                            7.10GB/s ± 0%   7.13GB/s ± 0%   +0.33%  (p=0.008 n=5+5)
wuffs_tga_decode_77k_24bpp/gcc10                           4.61GB/s ± 0%   4.60GB/s ± 0%   -0.35%  (p=0.008 n=5+5)

Updates #96
2023-02-01 16:36:56 +11:00
Nigel Tao 3705e0d93a cgen: io_reader.is_closed doesn't need derived var 2023-01-31 23:33:02 +11:00
Nigel Tao f01f0859f0 std/*io_transformer*: add "#truncated input"
name                                              old speed      new speed       delta

wuffs_bzip2_decode_10k/clang11                    58.5MB/s ± 0%   59.9MB/s ± 0%   +2.50%  (p=0.008 n=5+5)
wuffs_bzip2_decode_100k/clang11                   45.7MB/s ± 0%   50.5MB/s ± 0%  +10.66%  (p=0.008 n=5+5)

wuffs_bzip2_decode_10k/gcc10                      56.2MB/s ± 0%   61.9MB/s ± 0%  +10.01%  (p=0.008 n=5+5)
wuffs_bzip2_decode_100k/gcc10                     46.5MB/s ± 0%   50.4MB/s ± 0%   +8.41%  (p=0.016 n=4+5)

wuffs_deflate_decode_1k_full_init/clang11          195MB/s ± 0%    191MB/s ± 0%   -1.71%  (p=0.008 n=5+5)
wuffs_deflate_decode_1k_part_init/clang11          224MB/s ± 0%    225MB/s ± 0%   +0.87%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_full_init/clang11         421MB/s ± 0%    401MB/s ± 0%   -4.59%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_part_init/clang11         432MB/s ± 0%    413MB/s ± 0%   -4.49%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_just_one_read/clang11    542MB/s ± 0%    518MB/s ± 0%   -4.43%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_many_big_reads/clang11   338MB/s ± 0%    325MB/s ± 0%   -3.81%  (p=0.008 n=5+5)

wuffs_deflate_decode_1k_full_init/gcc10            181MB/s ± 0%    185MB/s ± 0%   +1.76%  (p=0.008 n=5+5)
wuffs_deflate_decode_1k_part_init/gcc10            209MB/s ± 0%    212MB/s ± 0%   +1.79%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_full_init/gcc10           410MB/s ± 0%    407MB/s ± 0%   -0.93%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_part_init/gcc10           421MB/s ± 0%    418MB/s ± 0%   -0.87%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_just_one_read/gcc10      533MB/s ± 0%    533MB/s ± 0%     ~     (p=0.548 n=5+5)
wuffs_deflate_decode_100k_many_big_reads/gcc10     336MB/s ± 0%    334MB/s ± 1%   -0.67%  (p=0.008 n=5+5)

wuffs_gzip_decode_10k/clang11                      401MB/s ± 0%    398MB/s ± 0%   -0.77%  (p=0.008 n=5+5)
wuffs_gzip_decode_100k/clang11                     505MB/s ± 0%    503MB/s ± 0%   -0.46%  (p=0.008 n=5+5)

wuffs_gzip_decode_10k/gcc10                        403MB/s ± 0%    410MB/s ± 0%   +1.90%  (p=0.008 n=5+5)
wuffs_gzip_decode_100k/gcc10                       522MB/s ± 0%    523MB/s ± 0%   +0.10%  (p=0.032 n=5+5)

wuffs_zlib_decode_10k/clang11                      418MB/s ± 0%    417MB/s ± 1%     ~     (p=0.310 n=5+5)
wuffs_zlib_decode_100k/clang11                     530MB/s ± 0%    529MB/s ± 0%     ~     (p=0.421 n=5+5)

wuffs_zlib_decode_10k/gcc10                        428MB/s ± 0%    434MB/s ± 0%   +1.50%  (p=0.008 n=5+5)
wuffs_zlib_decode_100k/gcc10                       551MB/s ± 0%    551MB/s ± 0%     ~     (p=0.690 n=5+5)

Fixes #96
2023-01-31 23:09:37 +11:00
Nigel Tao d7c48ae76b cgen: have io_limit update meta.closed 2023-01-31 22:05:20 +11:00
Nigel Tao 8ad397fc93 std/png: add test for multiple IDAT chunks 2023-01-31 21:37:57 +11:00
Nigel Tao 48e69da5af std/lzw: add "#truncated input" error
name                                         old speed      new speed      delta

wuffs_gif_decode_1k_bw/clang11                659MB/s ± 0%   748MB/s ± 0%  +13.43%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/clang11   182MB/s ± 0%   178MB/s ± 0%   -2.17%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/clang11   223MB/s ± 0%   219MB/s ± 0%   -2.00%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/clang11             799MB/s ± 0%   795MB/s ± 0%   -0.52%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/clang11          211MB/s ± 0%   210MB/s ± 0%   -0.47%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/clang11                  250MB/s ± 1%   254MB/s ± 0%   +1.75%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/clang11      581MB/s ± 0%   568MB/s ± 0%   -2.09%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/clang11       221MB/s ± 0%   221MB/s ± 0%     ~     (p=0.690 n=5+5)
wuffs_gif_decode_1000k_full_init/clang11      222MB/s ± 0%   224MB/s ± 0%   +0.65%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/clang11      223MB/s ± 0%   224MB/s ± 0%   +0.58%  (p=0.008 n=5+5)
wuffs_gif_decode_anim_screencap/clang11      1.28GB/s ± 0%  1.30GB/s ± 0%   +1.45%  (p=0.008 n=5+5)

wuffs_gif_decode_1k_bw/gcc10                  595MB/s ± 0%   642MB/s ± 0%   +7.91%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/gcc10     168MB/s ± 0%   169MB/s ± 0%   +0.36%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/gcc10     202MB/s ± 0%   203MB/s ± 0%   +0.46%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/gcc10               790MB/s ± 0%   798MB/s ± 0%   +1.04%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/gcc10            208MB/s ± 0%   210MB/s ± 0%   +1.00%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/gcc10                    258MB/s ± 0%   266MB/s ± 0%   +3.08%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/gcc10        566MB/s ± 0%   577MB/s ± 0%   +1.83%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/gcc10         220MB/s ± 0%   227MB/s ± 0%   +3.03%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_full_init/gcc10        223MB/s ± 0%   231MB/s ± 0%   +3.23%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/gcc10        224MB/s ± 0%   231MB/s ± 0%   +3.14%  (p=0.008 n=5+5)
wuffs_gif_decode_anim_screencap/gcc10        1.30GB/s ± 0%  1.32GB/s ± 0%   +1.70%  (p=0.008 n=5+5)

wuffs_lzw_decode_20k/clang11                  294MB/s ± 0%   321MB/s ± 0%   +9.11%  (p=0.008 n=5+5)
wuffs_lzw_decode_100k/clang11                 533MB/s ± 0%   560MB/s ± 0%   +5.13%  (p=0.008 n=5+5)

wuffs_lzw_decode_20k/gcc10                    271MB/s ± 0%   272MB/s ± 0%   +0.55%  (p=0.008 n=5+5)
wuffs_lzw_decode_100k/gcc10                   527MB/s ± 0%   521MB/s ± 0%   -1.31%  (p=0.008 n=5+5)

Updates #96
2023-01-31 20:18:53 +11:00
Nigel Tao 5640296546 Tweak README.md "it is fast" section 2023-01-27 10:07:25 +11:00
Nigel Tao 1e03a0c84f wuffs gen -version=0.3.0 2023-01-26 17:18:14 +11:00
Nigel Tao c698d81b4d Update README.md, doc/changelog.md 2023-01-26 17:17:12 +11:00
Nigel Tao 95164c7a3f Update doc/binary-size.md 2023-01-26 15:56:07 +11:00
Nigel Tao 255d3a0a29 Fix C++ "init-statement in selection" warning 2023-01-26 15:39:23 +11:00
Nigel Tao e915543f09 Fix jsonfindptrs "internal error" false positive 2022-12-08 15:07:42 +11:00
sarastro-nl d46220ca00 optimize SDC 2022-11-21 22:10:19 +01:00
Nigel Tao dee65c0e61 wuffs gen -version=0.3.0-rc.3 2022-10-28 17:29:05 +11:00
Nigel Tao c27250f52f Add -Wall to build-example.sh 2022-10-28 17:17:09 +11:00
Nigel Tao 9445c8b9d0 Guard header declarations on the MODULE_ETC macros 2022-10-28 17:11:14 +11:00
Nigel Tao b5ccd9e8e7 wuffs gen -version=0.3.0-rc.2 2022-10-20 11:23:06 +11:00
Nigel Tao b0e9efff3f Avoid (NULL + 0) in derived io_buffer variables
This addresses a "runtime error: applying zero offset to null pointer"
UBSAN (Undefined Behavior Sanitizer) warning using clang 15.0.1:
https://logs.chromium.org/logs/skia/5e005cc1b1981011/+/steps/dm/0/stdout

The offending line of code was "io1_a_dst = io0_a_dst + a_dst->meta.wi"
in wuffs_lzw__decoder__write_to and "io1_a_dst = NULL + 0" was Undefined
Behavior even though io1_a_dst was never dereferenced.

This commit avoids initializing io1_a_dst to (NULL + 0) when io0_a_dst
is NULL, falling back to initializing it with just NULL.

As discussed in https://reviews.llvm.org/D67122 while (nullptr + 0) is
Defined Behavior according to the C++ spec, (NULL + 0) is Undefined
Behavior (by omission) in C11 6.5.6/8: "If both the pointer operand and
the result point to elements of the same array object, or one past the
last element of the array object, the evaluation shall not produce an
overflow; otherwise, the behavior is undefined."

The benchmarks (an excerpt of the full suite is below) seem quite
sensitive to this simple change that's outside of hot loops, sometimes
much better and sometimes much worse. I don't know why.

name                                               old speed       new speed      delta

wuffs_bzip2_decode_10k/clang11                    63.1MB/s ± 0%   58.4MB/s ± 0%   -7.43%  (p=0.008 n=5+5)
wuffs_bzip2_decode_100k/clang11                   49.4MB/s ± 0%   46.2MB/s ± 0%   -6.35%  (p=0.008 n=5+5)

wuffs_bzip2_decode_10k/gcc10                      60.9MB/s ± 0%   56.3MB/s ± 0%   -7.59%  (p=0.016 n=5+4)
wuffs_bzip2_decode_100k/gcc10                     49.6MB/s ± 0%   47.0MB/s ± 0%   -5.15%  (p=0.008 n=5+5)

wuffs_deflate_decode_1k_full_init/clang11          196MB/s ± 0%    195MB/s ± 1%   -0.63%  (p=0.008 n=5+5)
wuffs_deflate_decode_1k_part_init/clang11          226MB/s ± 0%    224MB/s ± 0%   -0.95%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_full_init/clang11         409MB/s ± 0%    420MB/s ± 0%   +2.84%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_part_init/clang11         418MB/s ± 0%    431MB/s ± 0%   +2.97%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_just_one_read/clang11    517MB/s ± 1%    542MB/s ± 0%   +4.78%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_many_big_reads/clang11   330MB/s ± 0%    338MB/s ± 0%   +2.45%  (p=0.008 n=5+5)

wuffs_deflate_decode_1k_full_init/gcc10            188MB/s ± 0%    177MB/s ± 0%   -5.38%  (p=0.008 n=5+5)
wuffs_deflate_decode_1k_part_init/gcc10            218MB/s ± 0%    209MB/s ± 0%   -4.11%  (p=0.016 n=4+5)
wuffs_deflate_decode_10k_full_init/gcc10           402MB/s ± 0%    407MB/s ± 1%   +1.19%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k_part_init/gcc10           413MB/s ± 0%    419MB/s ± 1%   +1.64%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_just_one_read/gcc10      520MB/s ± 0%    532MB/s ± 0%   +2.25%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k_many_big_reads/gcc10     330MB/s ± 0%    335MB/s ± 0%   +1.56%  (p=0.008 n=5+5)

wuffs_gif_decode_1k_bw/clang11                     781MB/s ± 0%    645MB/s ± 0%  -17.46%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/clang11        176MB/s ± 0%    181MB/s ± 0%   +3.11%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/clang11        215MB/s ± 0%    223MB/s ± 0%   +3.46%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/clang11                  786MB/s ± 0%    801MB/s ± 0%   +1.94%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/clang11               208MB/s ± 0%    211MB/s ± 0%   +1.44%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/clang11                       261MB/s ± 0%    252MB/s ± 0%   -3.43%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/clang11           578MB/s ± 0%    583MB/s ± 0%   +0.86%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/clang11            224MB/s ± 0%    223MB/s ± 0%   -0.79%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_full_init/clang11           229MB/s ± 0%    225MB/s ± 0%   -1.73%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/clang11           229MB/s ± 0%    225MB/s ± 0%   -1.69%  (p=0.008 n=5+5)
wuffs_gif_decode_anim_screencap/clang11           1.31GB/s ± 0%   1.29GB/s ± 0%   -1.06%  (p=0.008 n=5+5)

wuffs_gif_decode_1k_bw/gcc10                       650MB/s ± 0%    631MB/s ± 0%   -3.03%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_full_init/gcc10          169MB/s ± 0%    168MB/s ± 0%   -0.51%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color_part_init/gcc10          202MB/s ± 0%    202MB/s ± 0%   -0.18%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/gcc10                    766MB/s ± 0%    790MB/s ± 0%   +3.08%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/gcc10                 202MB/s ± 0%    208MB/s ± 0%   +3.16%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/gcc10                         250MB/s ± 0%    258MB/s ± 0%   +3.20%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/gcc10             563MB/s ± 0%    566MB/s ± 0%   +0.57%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/gcc10              217MB/s ± 0%    220MB/s ± 0%   +1.49%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_full_init/gcc10             220MB/s ± 0%    224MB/s ± 0%   +1.49%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k_part_init/gcc10             220MB/s ± 0%    224MB/s ± 0%   +1.43%  (p=0.008 n=5+5)
wuffs_gif_decode_anim_screencap/gcc10             1.30GB/s ± 0%   1.30GB/s ± 0%   +0.34%  (p=0.008 n=5+5)

wuffs_lzw_decode_20k/clang11                       293MB/s ± 0%    292MB/s ± 0%   -0.41%  (p=0.008 n=5+5)
wuffs_lzw_decode_100k/clang11                      486MB/s ± 0%    537MB/s ± 0%  +10.49%  (p=0.008 n=5+5)

wuffs_lzw_decode_20k/gcc10                         258MB/s ± 0%    276MB/s ± 0%   +7.19%  (p=0.016 n=4+5)
wuffs_lzw_decode_100k/gcc10                        512MB/s ± 0%    527MB/s ± 0%   +3.08%  (p=0.016 n=4+5)
2022-10-20 11:18:09 +11:00
Nigel Tao 8b7f82142c Update doc/roadmap.md 2022-10-17 19:13:19 +11:00
Nigel Tao b245252e1e Update doc/benchmarks.md 2022-09-04 00:54:21 +10:00
Nigel Tao bad2693efb Add lib/litonlylzma.FileFormatXz 2022-08-24 22:46:01 +10:00
Nigel Tao be1f605108 Run gofmt 2022-08-21 21:41:06 +10:00
73 changed files with 7322 additions and 2287 deletions

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
# Source code is always LF, never CRLF.
#
# For example, tools like the wuffs-c compiler (and its internal/cgen package)
# look for hard-coded strings containing "\n" but not "\r\n".
*.c text eol=lf
*.cc text eol=lf
*.go text eol=lf
*.h text eol=lf
*.hh text eol=lf
*.rs text eol=lf
*.sh text eol=lf
*.wuffs text eol=lf
+1
View File
@@ -18,3 +18,4 @@ Michael Mc Donnell <michael@mcdonnell.dk>
Mike Kaufman <mkaufman@microsoft.com>
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
Přemysl Eric Janouch <p@janouch.name>
sarastro-nl <nlsarastro@gmail.com>
+1
View File
@@ -43,3 +43,4 @@ Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
Nigel Tao <nigeltao@golang.org>
Peter Kasting <pkasting@chromium.org>
Přemysl Eric Janouch <p@janouch.name>
sarastro-nl <nlsarastro@gmail.com>
+32 -14
View File
@@ -1,17 +1,21 @@
![WUFFS Logo](./doc/logo/wuffs-acronym-logo-1536x1024.png)
Wuffs (Wrangling Untrusted File Formats Safely) is [formerly known as
Puffs](https://groups.google.com/d/topic/puffslang/ZX-ymyf8xh0/discussion)
(Parsing Untrusted File Formats Safely).
Wuffs is a **memory-safe programming language** (and a **standard library**
written in that language) for wrangling **untrusted file formats** safely.
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 also **fast**. On many of its GIF decoding
[benchmarks](/doc/benchmarks.md), Wuffs measures **2x faster than "giflib" (C),
3x faster than "image/gif" (Go) and 7x faster than "gif" (Rust)**.
It is **fast**. 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)**.
- It can decode deflate up to **1.4x faster than zlib-the-library (C)**.
- It can decode GIF **2x-6x faster than "giflib" (C), "image/gif" (Go) and
"gif" (Rust)**.
- It can decode PNG **[1.2x-2.7x faster than "libpng" (C), "image/png" (Go) and
"png"
(Rust)](https://nigeltao.github.io/blog/2021/fastest-safest-png-decoder.html)**.
## Goals and Non-Goals
@@ -44,11 +48,21 @@ the increment would otherwise overflow. Similarly, an integer arithmetic
expression like `x / y` is a compile time error unless the compiler can also
prove that `y` is not zero.
## Hermeticity
Wuffs is not a general purpose programming language. **It is for writing
libraries, not programs**. The idea isn't to write your whole program in Wuffs,
only the **parts that are both performance-conscious and security-conscious**.
For example, while technically possible, it is unlikely that a Wuffs compiler
would be worth writing entirely in Wuffs.
libraries, not programs**. Wuffs code is [hermetic](/doc/note/hermeticity.md)
and can only compute (e.g. convert "compressed bytes" to "decompressed bytes").
**It cannot make any syscalls** (e.g. it has no ambient authority to read your
files), implying that it cannot allocate or free memory (and is therefore
trivially safe against things like memory leaks, use-after-frees and
double-frees).
The idea isn't to write your whole program in Wuffs, **only the parts that are
both performance-conscious and security-conscious**. For example, while
technically possible, it is unlikely that a Wuffs compiler would be worth
writing entirely in Wuffs.
## What Does Wuffs Code Look Like?
@@ -187,12 +201,16 @@ The [Note](/doc/note) directory also contains various short articles.
# Status
Version 0.2. The API and ABI aren't stabilized yet. The compiler undoubtedly
Version 0.3. The API and ABI aren't stabilized yet. The compiler undoubtedly
has bugs. Assertion checking needs more rigor, especially around side effects
and aliasing, and being sufficiently well specified to allow alternative
implementations. Lots of detail needs work, but the broad brushstrokes are
there.
Nonetheless, Wuffs' GIF decoder has shipped in the Google Chrome web browser
[since June
2021](https://chromium-review.googlesource.com/c/chromium/src/+/2940044).
# Discussion
@@ -223,4 +241,4 @@ owned by Google.
---
Updated on December 2019.
Updated on January 2023.
+2 -2
View File
@@ -28,8 +28,8 @@ LDFLAGS=${LDFLAGS:-}
# The "-fdata-sections -ffunction-sections -Wl,--gc-sections" produces smaller
# binaries. See commit 41fce8a8 "Strip examples of unused data and functions".
CFLAGS=${CFLAGS:--O3 -fdata-sections -ffunction-sections -Wl,--gc-sections}
CXXFLAGS=${CXXFLAGS:--O3 -fdata-sections -ffunction-sections -Wl,--gc-sections}
CFLAGS=${CFLAGS:--O3 -fdata-sections -ffunction-sections -Wall -Wl,--gc-sections}
CXXFLAGS=${CXXFLAGS:--O3 -fdata-sections -ffunction-sections -Wall -Wl,--gc-sections}
mkdir -p gen/bin
+14 -14
View File
@@ -35,20 +35,20 @@
// To quantify "much faster", on this one C file, this program was 80 times
// faster than `clang-format`, even without a column limit:
//
// $ wc release/c/wuffs-v0.2.c
// 11858 35980 431885 release/c/wuffs-v0.2.c
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.008s
// user 0m0.005s
// sys 0m0.005s
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.668s
// user 0m0.618s
// sys 0m0.032s
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.641s
// user 0m0.585s
// sys 0m0.037s
// $ wc release/c/wuffs-v0.2.c
// 11858 35980 431885 release/c/wuffs-v0.2.c
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.008s
// user 0m0.005s
// sys 0m0.005s
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.668s
// user 0m0.618s
// sys 0m0.032s
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.641s
// user 0m0.585s
// sys 0m0.037s
//
// More commentary is at:
// https://godoc.org/github.com/google/wuffs/lib/dumbindent
+137 -137
View File
@@ -33,7 +33,7 @@ https://github.com/google/wuffs/blob/main/doc/spec/rac-spec.md
Usage:
ractool [flags] [input_filename]
ractool [flags] [input_filename]
If no input_filename is given, stdin is used. Either way, output is written to
stdout.
@@ -63,10 +63,10 @@ or temporary disk space.
Examples:
ractool -decode foo.rac | sha256sum
ractool -decode -drange=400..500 foo.rac
ractool -encode foo.dat > foo.rac
ractool -encode -codec=zlib -dchunksize=256k foo.dat > foo.rac
ractool -decode foo.rac | sha256sum
ractool -decode -drange=400..500 foo.rac
ractool -encode foo.dat > foo.rac
ractool -encode -codec=zlib -dchunksize=256k foo.dat > foo.rac
The "400..500" flag value means the 100 bytes ranging from a DSpace offset
(offset in terms of decompressed bytes, not compressed bytes) of 400
@@ -79,42 +79,42 @@ Similarly, "1m" and "1M" both mean 1 mebibyte (1048576 bytes).
General Flags:
-decode
whether to decode the input
-encode
whether to encode the input
-quiet
whether to suppress messages
-decode
whether to decode the input
-encode
whether to encode the input
-quiet
whether to suppress messages
Decode-Related Flags:
-drange
the "i..j" range to decompress, "..8" means the first 8 bytes
-singlethreaded
whether to decode on a single execution thread
-drange
the "i..j" range to decompress, "..8" means the first 8 bytes
-singlethreaded
whether to decode on a single execution thread
Encode-Related Flags:
-cchunksize
the chunk size (in CSpace)
-codec
the compression codec (default "zstd")
-cpagesize
the page size (in CSpace)
-dchunksize
the chunk size (in DSpace)
-indexlocation
the index location, "start" or "end" (default "start")
-resources
comma-separated list of resource files, such as shared dictionaries
-tmpdir
directory (e.g. $TMPDIR) for intermediate work; empty means in-memory
-cchunksize
the chunk size (in CSpace)
-codec
the compression codec (default "zstd")
-cpagesize
the page size (in CSpace)
-dchunksize
the chunk size (in DSpace)
-indexlocation
the index location, "start" or "end" (default "start")
-resources
comma-separated list of resource files, such as shared dictionaries
-tmpdir
directory (e.g. $TMPDIR) for intermediate work; empty means in-memory
Codecs:
lz4
zlib
zstd
lz4
zlib
zstd
Only zlib is fully supported. The others will work for the flags' default
values, but they (1) don't support -cchunksize, only -dchunksize, and (2) don't
@@ -125,123 +125,123 @@ Installation:
Like any other implemented-in-Go program, to install the ractool program:
go install github.com/google/wuffs/cmd/ractool
go install github.com/google/wuffs/cmd/ractool
Extended Example:
--------
$ # Fetch and unzip the enwik8 test file, a sample of Wikipedia.
$ wget http://mattmahoney.net/dc/enwik8.zip
$ unzip enwik8.zip
--------
$ # Fetch and unzip the enwik8 test file, a sample of Wikipedia.
$ wget http://mattmahoney.net/dc/enwik8.zip
$ unzip enwik8.zip
$ # Also zstd-encode it, as a reference point. Using compression level 15,
$ # instead of the default of 3, matches what ractool uses.
$ zstd -15 enwik8
$ # Also zstd-encode it, as a reference point. Using compression level 15,
$ # instead of the default of 3, matches what ractool uses.
$ zstd -15 enwik8
$ # Create a shared dictionary. Using zstd-the-program produces a
$ # dictionary that is especially useful for zstd-the-format, but it can
$ # also be used by other formats as a 'raw' prefix dictionary.
$ zstd -15 --train -B64K --maxdict=32K -o dict.dat enwik8
$ # Create a shared dictionary. Using zstd-the-program produces a
$ # dictionary that is especially useful for zstd-the-format, but it can
$ # also be used by other formats as a 'raw' prefix dictionary.
$ zstd -15 --train -B64K --maxdict=32K -o dict.dat enwik8
$ # RAC-encode it with various codecs, with and without that dictionary.
$ ractool -encode -codec=zlib -resources=dict.dat enwik8 > zlib.withdict.rac
$ ractool -encode -codec=zlib enwik8 > zlib.sansdict.rac
$ ractool -encode -codec=zstd -resources=dict.dat enwik8 > zstd.withdict.rac
$ ractool -encode -codec=zstd enwik8 > zstd.sansdict.rac
$ ractool -encode -codec=lz4 enwik8 > lz4.sansdict.rac
$ # RAC-encode it with various codecs, with and without that dictionary.
$ ractool -encode -codec=zlib -resources=dict.dat enwik8 > zlib.withdict.rac
$ ractool -encode -codec=zlib enwik8 > zlib.sansdict.rac
$ ractool -encode -codec=zstd -resources=dict.dat enwik8 > zstd.withdict.rac
$ ractool -encode -codec=zstd enwik8 > zstd.sansdict.rac
$ ractool -encode -codec=lz4 enwik8 > lz4.sansdict.rac
$ # The size overhead (comparing RAC+Xxx to Xxx) is about 0.2% (with) or
$ # 4.8% (sans) for zlib/zip and about 13% (with) or 28% (sans) for zstd,
$ # depending on whether we used a shared dictionary (with or sans).
$ ls -l
total 362080
-rw-r----- 1 tao tao 32768 Oct 25 10:10 dict.dat
-rw-r----- 1 tao tao 100000000 Jun 2 2011 enwik8
-rw-r----- 1 tao tao 36445475 Sep 2 2011 enwik8.zip
-rw-r----- 1 tao tao 29563109 Jun 2 2011 enwik8.zst
-rw-r----- 1 tao tao 58813316 Oct 25 10:17 lz4.sansdict.rac
-rw-r----- 1 tao tao 38185178 Oct 25 10:16 zlib.sansdict.rac
-rw-r----- 1 tao tao 36505786 Oct 25 10:16 zlib.withdict.rac
-rw-r----- 1 tao tao 37820491 Oct 25 10:17 zstd.sansdict.rac
-rw-r----- 1 tao tao 33386395 Oct 25 10:17 zstd.withdict.rac
$ # The size overhead (comparing RAC+Xxx to Xxx) is about 0.2% (with) or
$ # 4.8% (sans) for zlib/zip and about 13% (with) or 28% (sans) for zstd,
$ # depending on whether we used a shared dictionary (with or sans).
$ ls -l
total 362080
-rw-r----- 1 tao tao 32768 Oct 25 10:10 dict.dat
-rw-r----- 1 tao tao 100000000 Jun 2 2011 enwik8
-rw-r----- 1 tao tao 36445475 Sep 2 2011 enwik8.zip
-rw-r----- 1 tao tao 29563109 Jun 2 2011 enwik8.zst
-rw-r----- 1 tao tao 58813316 Oct 25 10:17 lz4.sansdict.rac
-rw-r----- 1 tao tao 38185178 Oct 25 10:16 zlib.sansdict.rac
-rw-r----- 1 tao tao 36505786 Oct 25 10:16 zlib.withdict.rac
-rw-r----- 1 tao tao 37820491 Oct 25 10:17 zstd.sansdict.rac
-rw-r----- 1 tao tao 33386395 Oct 25 10:17 zstd.withdict.rac
$ # Check that the decompressed forms all match.
$ cat enwik8 | sha256sum
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
$ unzip -p enwik8.zip | sha256sum
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
$ unzstd --stdout enwik8.zst | sha256sum
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
$ for f in *.rac; do ractool -decode $f | sha256sum; done
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
$ # Check that the decompressed forms all match.
$ cat enwik8 | sha256sum
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
$ unzip -p enwik8.zip | sha256sum
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
$ unzstd --stdout enwik8.zst | sha256sum
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
$ for f in *.rac; do ractool -decode $f | sha256sum; done
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8 -
$ # Compare how long it takes to produce 8 bytes from the middle of
$ # the decompressed file, which happens to be the word "Business".
$ time unzip -p enwik8.zip | dd if=/dev/stdin status=none \
> iflag=skip_bytes,count_bytes skip=50000000 count=8
Business
real 0m0.379s
user 0m0.410s
sys 0m0.080s
$ time unzstd --stdout enwik8.zst | dd if=/dev/stdin status=none \
> iflag=skip_bytes,count_bytes skip=50000000 count=8
Business
real 0m0.172s
user 0m0.141s
sys 0m0.103s
$ time ractool -decode -drange=50000000..50000008 zstd.withdict.rac
Business
real 0m0.004s
user 0m0.005s
sys 0m0.001s
$ # Compare how long it takes to produce 8 bytes from the middle of
$ # the decompressed file, which happens to be the word "Business".
$ time unzip -p enwik8.zip | dd if=/dev/stdin status=none \
> iflag=skip_bytes,count_bytes skip=50000000 count=8
Business
real 0m0.379s
user 0m0.410s
sys 0m0.080s
$ time unzstd --stdout enwik8.zst | dd if=/dev/stdin status=none \
> iflag=skip_bytes,count_bytes skip=50000000 count=8
Business
real 0m0.172s
user 0m0.141s
sys 0m0.103s
$ time ractool -decode -drange=50000000..50000008 zstd.withdict.rac
Business
real 0m0.004s
user 0m0.005s
sys 0m0.001s
$ # A RAC file's chunks can be decoded in parallel, unlike ZIP,
$ # substantially reducing the real (wall clock) time taken even
$ # though both of these files use DEFLATE (RFC 1951) compression.
$ #
$ # Comparing the -singlethreaded time suggests that zlib-the-library's
$ # DEFLATE implementation is faster than unzip's.
$ time unzip -p enwik8.zip > /dev/null
real 0m0.711s
user 0m0.690s
sys 0m0.021s
$ time ractool -decode -singlethreaded zlib.withdict.rac > /dev/null
real 0m0.519s
user 0m0.513s
sys 0m0.017s
$ time ractool -decode zlib.withdict.rac > /dev/null
real 0m0.052s
user 0m0.678s
sys 0m0.036s
$ # A RAC file's chunks can be decoded in parallel, unlike ZIP,
$ # substantially reducing the real (wall clock) time taken even
$ # though both of these files use DEFLATE (RFC 1951) compression.
$ #
$ # Comparing the -singlethreaded time suggests that zlib-the-library's
$ # DEFLATE implementation is faster than unzip's.
$ time unzip -p enwik8.zip > /dev/null
real 0m0.711s
user 0m0.690s
sys 0m0.021s
$ time ractool -decode -singlethreaded zlib.withdict.rac > /dev/null
real 0m0.519s
user 0m0.513s
sys 0m0.017s
$ time ractool -decode zlib.withdict.rac > /dev/null
real 0m0.052s
user 0m0.678s
sys 0m0.036s
$ # A similar comparison can be made for Zstandard.
$ time unzstd --stdout enwik8.zst > /dev/null
real 0m0.203s
user 0m0.187s
sys 0m0.016s
$ time ractool -decode -singlethreaded zstd.withdict.rac > /dev/null
real 0m0.235s
user 0m0.206s
sys 0m0.033s
$ time ractool -decode zstd.withdict.rac > /dev/null
real 0m0.037s
user 0m0.374s
sys 0m0.080s
$ # A similar comparison can be made for Zstandard.
$ time unzstd --stdout enwik8.zst > /dev/null
real 0m0.203s
user 0m0.187s
sys 0m0.016s
$ time ractool -decode -singlethreaded zstd.withdict.rac > /dev/null
real 0m0.235s
user 0m0.206s
sys 0m0.033s
$ time ractool -decode zstd.withdict.rac > /dev/null
real 0m0.037s
user 0m0.374s
sys 0m0.080s
$ # For reference, LZ4 numbers.
$ time ractool -decode -singlethreaded lz4.sansdict.rac > /dev/null
real 0m0.072s
user 0m0.053s
sys 0m0.021s
$ time ractool -decode lz4.sansdict.rac > /dev/null
real 0m0.024s
user 0m0.097s
sys 0m0.034s
--------
$ # For reference, LZ4 numbers.
$ time ractool -decode -singlethreaded lz4.sansdict.rac > /dev/null
real 0m0.072s
user 0m0.053s
sys 0m0.021s
$ time ractool -decode lz4.sansdict.rac > /dev/null
real 0m0.024s
user 0m0.097s
sys 0m0.034s
--------
*/
package main
+262 -204
View File
@@ -5,20 +5,34 @@ below. Higher is better.
"Mimic" tests check that Wuffs' output mimics (i.e. exactly matches) other
libraries' output. "Mimic" benchmarks give the numbers for those other
libraries, as shipped with Debian. These were measured on a Debian Testing
system as of October 2019, which meant these compiler versions:
libraries, as shipped with Debian. These were measured on a Debian Bullseye
system as of September 2022, which meant these compiler versions:
- clang/llvm 8.0.1
- gcc 9.2.1
- clang/llvm 11.0.1
- gcc 10.2.1
and these "mimic" library versions, all written in C:
and these popular "mimic" library versions, all written in C:
- libgif 5.1.4
- zlib 1.2.11
- libbz2 1.0.8
- libgif 5.1.9
- libpng 1.6.37
- zlib 1.2.11 (we'll call this "ztl" or "zlib the library", as opposed to "zlib
the format")
Unless otherwise stated, the numbers below were measured on an Intel x86\_64
Broadwell, and were taken as of Wuffs git commit ffdce5ef "Have bench-rust-gif
process animated / RGBA images".
and these alternative "mimic" library versions, again all written in C:
- [libdeflate](https://github.com/ebiggers/libdeflate) 1.7.1
- [libspng](https://github.com/randy408/libspng) 0.7.3
- [lodepng](https://github.com/lvandeve/lodepng) 20220717
- [miniz](https://github.com/richgel999/miniz) 2.2.0
- [stb](https://github.com/nothings/stb) 2.27
Unless otherwise stated, the numbers below were taken as of Wuffs git commit
315b2e52 "wuffs gen -version=0.3.0-rc.1", the first Wuffs v0.3 release
candidate. As for the CPU model:
$ cat /proc/cpuinfo | grep model.name | uniq
model name: Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
## Reproducing
@@ -89,65 +103,110 @@ power management can be controlled with:
The `1k`, `10k`, etc. numbers are approximately how many bytes are hashed.
name speed vs_mimic
name speed vs_mimic
wuffs_adler32_10k/clang8 2.41GB/s 0.84x
wuffs_adler32_100k/clang8 2.42GB/s 0.84x
wuffs_adler32_10k/clang11 22.3 GB/s 6.4x
wuffs_adler32_100k/clang11 26.4 GB/s 7.5x
wuffs_adler32_10k/gcc9 3.24GB/s 1.13x
wuffs_adler32_100k/gcc9 3.24GB/s 1.12x
wuffs_adler32_10k/gcc10 21.9 GB/s 6.3x
wuffs_adler32_100k/gcc10 22.4 GB/s 6.4x
mimic_adler32_10k 2.87GB/s 1.00x
mimic_adler32_100k 2.90GB/s 1.00x
mimicztl_adler32_10k 3.50 GB/s 1.0x
mimicztl_adler32_100k 3.52 GB/s 1.0x
mimiclibdeflate_adler32_10k 50.4 GB/s 14.4x
mimiclibdeflate_adler32_100k 49.4 GB/s 14.0x
# Bzip2
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
decoded output.
name speed vs_mimic
wuffs_bzip2_decode_10k/clang11 63.0 MB/s 1.86x
wuffs_bzip2_decode_100k/clang11 48.9 MB/s 1.62x
wuffs_bzip2_decode_10k/gcc10 61.1 MB/s 1.81x
wuffs_bzip2_decode_100k/gcc10 49.1 MB/s 1.62x
mimic_bzip2_decode_10k 33.8 MB/s 1.00x
mimic_bzip2_decode_100k 30.2 MB/s 1.00x
# CRC-32
The `1k`, `10k`, etc. numbers are approximately how many bytes are hashed.
name speed vs_mimic
name speed vs_mimic
wuffs_crc32_ieee_10k/clang8 2.85GB/s 2.11x
wuffs_crc32_ieee_100k/clang8 2.87GB/s 2.13x
wuffs_crc32_ieee_10k/clang11 14.7 GB/s 9.1x
wuffs_crc32_ieee_100k/clang11 21.6 GB/s 13.3x
wuffs_crc32_ieee_10k/gcc9 3.38GB/s 2.50x
wuffs_crc32_ieee_100k/gcc9 3.40GB/s 2.52x
wuffs_crc32_ieee_10k/gcc10 14.9 GB/s 9.2x
wuffs_crc32_ieee_100k/gcc10 23.8 GB/s 14.7x
mimic_crc32_ieee_10k 1.35GB/s 1.00x
mimic_crc32_ieee_100k 1.35GB/s 1.00x
mimicztl_crc32_ieee_10k 1.62 GB/s 1.0x
mimicztl_crc32_ieee_100k 1.62 GB/s 1.0x
mimiclibdeflate_crc32_ieee_10k 24.6 GB/s 15.2x
mimiclibdeflate_crc32_ieee_100k 25.4 GB/s 15.7x
# Deflate
The `1k`, `10k`, etc. numbers are approximately how many bytes there in the
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
decoded output.
The `full_init` vs `part_init` suffixes are whether
[`WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED`](/doc/note/initialization.md#partial-zero-initialization)
is unset or set.
name speed vs_mimic
name speed vs_mimic
wuffs_deflate_decode_1k_full_init/clang8 160MB/s 0.74x
wuffs_deflate_decode_1k_part_init/clang8 199MB/s 0.92x
wuffs_deflate_decode_10k_full_init/clang8 255MB/s 0.94x
wuffs_deflate_decode_10k_part_init/clang8 263MB/s 0.97x
wuffs_deflate_decode_100k_just_one_read/clang8 306MB/s 0.93x
wuffs_deflate_decode_100k_many_big_reads/clang8 250MB/s 0.98x
wuffs_deflate_decode_1k_full_init/clang11 195 MB/s 0.81x
wuffs_deflate_decode_1k_part_init/clang11 226 MB/s 0.93x
wuffs_deflate_decode_10k_full_init/clang11 409 MB/s 1.41x
wuffs_deflate_decode_10k_part_init/clang11 418 MB/s 1.47x
wuffs_deflate_decode_100k_just_one_read/clang11 521 MB/s 1.48x
wuffs_deflate_decode_100k_many_big_reads/clang11 330 MB/s 1.19x
wuffs_deflate_decode_1k_full_init/gcc9 164MB/s 0.76x
wuffs_deflate_decode_1k_part_init/gcc9 207MB/s 0.95x
wuffs_deflate_decode_10k_full_init/gcc9 247MB/s 0.91x
wuffs_deflate_decode_10k_part_init/gcc9 254MB/s 0.94x
wuffs_deflate_decode_100k_just_one_read/gcc9 333MB/s 1.01x
wuffs_deflate_decode_100k_many_big_reads/gcc9 261MB/s 1.02x
wuffs_deflate_decode_1k_full_init/gcc10 183 MB/s 0.76x
wuffs_deflate_decode_1k_part_init/gcc10 217 MB/s 0.90x
wuffs_deflate_decode_10k_full_init/gcc10 402 MB/s 1.39x
wuffs_deflate_decode_10k_part_init/gcc10 414 MB/s 1.43x
wuffs_deflate_decode_100k_just_one_read/gcc10 522 MB/s 1.48x
wuffs_deflate_decode_100k_many_big_reads/gcc10 330 MB/s 1.19x
mimic_deflate_decode_1k 217MB/s 1.00x
mimic_deflate_decode_10k 270MB/s 1.00x
mimic_deflate_decode_100k_just_one_read 329MB/s 1.00x
mimic_deflate_decode_100k_many_big_reads 256MB/s 1.00x
mimicztl_deflate_decode_1k_full_init 241 MB/s 1.00x
mimicztl_deflate_decode_10k_full_init 289 MB/s 1.00x
mimicztl_deflate_decode_100k_just_one_read 352 MB/s 1.00x
mimicztl_deflate_decode_100k_many_big_reads 277 MB/s 1.00x
32-bit ARMv7 (2012 era Samsung Exynos 5 Chromebook), Debian Stretch (2017):
mimiclibdeflate_deflate_decode_1k_full_init 326 MB/s 1.35x
mimiclibdeflate_deflate_decode_10k_full_init 503 MB/s 1.74x
mimiclibdeflate_deflate_decode_100k_just_one_read 507 MB/s 1.44x
mimicminiz_deflate_decode_1k_full_init 204 MB/s 0.85x
mimicminiz_deflate_decode_10k_full_init 252 MB/s 0.87x
mimicminiz_deflate_decode_100k_just_one_read 287 MB/s 0.82x
go_deflate_decode_1k_full_init 71 MB/s 0.29x
go_deflate_decode_10k_full_init 120 MB/s 0.42x
go_deflate_decode_100k_just_one_read 135 MB/s 0.38x
rust_deflate_decode_1k_full_init 165 MB/s 0.68x
rust_deflate_decode_10k_full_init 259 MB/s 0.90x
rust_deflate_decode_100k_just_one_read 272 MB/s 0.77x
To reproduce the libdeflate or miniz numbers, look in
`test/c/mimiclib/deflate-gzip-zlib.c`. For Go 1.19, run `go run main.go` in
`script/bench-go-deflate`. For Rust 1.48 / flate2 1.0.24 / miniz\_oxide 0.5.3,
run `cargo run --release` in `script/bench-rust-deflate`.
Historical (Wuffs v0.2; 2019) numbers for 32-bit ARMv7 (2012 era Samsung Exynos
5 Chromebook), Debian Stretch (2017):
name speed vs_mimic
@@ -171,63 +230,6 @@ is unset or set.
mimic_deflate_decode_100k_many_big_reads 90.0MB/s 1.00x
## Deflate (C, miniz)
For comparison, here are [miniz](https://github.com/richgel999/miniz) 2.1.0's
numbers.
name speed vs_mimic
miniz_deflate_decode_1k/clang8 174MB/s 0.80x
miniz_deflate_decode_10k/clang8 245MB/s 0.91x
miniz_deflate_decode_100k_just_one_read/clang8 309MB/s 0.94x
miniz_deflate_decode_1k/gcc9 158MB/s 0.73x
miniz_deflate_decode_10k/gcc9 221MB/s 0.82x
miniz_deflate_decode_100k_just_one_read/gcc9 250MB/s 0.76x
To reproduce these numbers, look in `test/c/mimiclib/deflate-gzip-zlib.c`.
## Deflate (Go)
For comparison, here are Go 1.12.10's numbers, using Go's standard library's
`compress/flate` package.
name speed vs_mimic
go_deflate_decode_1k 45.4MB/s 0.21x
go_deflate_decode_10k 82.5MB/s 0.31x
go_deflate_decode_100k 94.0MB/s 0.29x
To reproduce these numbers:
git clone https://github.com/google/wuffs.git
cd wuffs/script/bench-go-deflate/
go run main.go
## Deflate (Rust)
For comparison, here are Rust 1.37.0's numbers, using the
[alexcrichton/flate2-rs](https://github.com/alexcrichton/flate2-rs) and
[Frommi/miniz_oxide](https://github.com/Frommi/miniz_oxide) crates, which [this
file](https://github.com/sile/libflate/blob/77a1004edf6518a0badab7ce8837bc5338ff9bc3/README.md#an-informal-benchmark)
suggests is the fastest pure-Rust Deflate decoder.
name speed vs_mimic
rust_deflate_decode_1k 104MB/s 0.48x
rust_deflate_decode_10k 202MB/s 0.75x
rust_deflate_decode_100k 218MB/s 0.66x
To reproduce these numbers:
git clone https://github.com/google/wuffs.git
cd wuffs/script/bench-rust-deflate/
cargo run --release
# GIF
The `1k`, `10k`, etc. numbers are approximately how many pixels there are in
@@ -245,42 +247,67 @@ is unset or set.
The libgif library doesn't export any API for decode-to-BGRA or decode-to-RGBA,
so there are no mimic numbers to compare to for the `bgra` suffix.
name speed vs_mimic
name speed vs_mimic
wuffs_gif_decode_1k_bw/clang8 461MB/s 3.18x
wuffs_gif_decode_1k_color_full_init/clang8 141MB/s 1.85x
wuffs_gif_decode_1k_color_part_init/clang8 189MB/s 2.48x
wuffs_gif_decode_10k_bgra/clang8 743MB/s n/a
wuffs_gif_decode_10k_indexed/clang8 200MB/s 2.11x
wuffs_gif_decode_20k/clang8 245MB/s 2.50x
wuffs_gif_decode_100k_artificial/clang8 531MB/s 3.43x
wuffs_gif_decode_100k_realistic/clang8 218MB/s 2.27x
wuffs_gif_decode_1000k_full_init/clang8 221MB/s 2.25x
wuffs_gif_decode_1000k_part_init/clang8 221MB/s 2.25x
wuffs_gif_decode_anim_screencap/clang8 1.07GB/s 6.01x
wuffs_gif_decode_1k_bw/clang11 758 MB/s 4.38x
wuffs_gif_decode_1k_color_full_init/clang11 176 MB/s 1.96x
wuffs_gif_decode_1k_color_part_init/clang11 213 MB/s 2.37x
wuffs_gif_decode_10k_bgra/clang11 786 MB/s n/a
wuffs_gif_decode_10k_indexed/clang11 208 MB/s 1.98x
wuffs_gif_decode_20k/clang11 262 MB/s 2.47x
wuffs_gif_decode_100k_artificial/clang11 580 MB/s 3.52x
wuffs_gif_decode_100k_realistic/clang11 225 MB/s 2.18x
wuffs_gif_decode_1000k_full_init/clang11 229 MB/s 2.16x
wuffs_gif_decode_1000k_part_init/clang11 229 MB/s 2.16x
wuffs_gif_decode_anim_screencap/clang11 1.31 GB/s 6.58x
wuffs_gif_decode_1k_bw/gcc9 478MB/s 3.30x
wuffs_gif_decode_1k_color_full_init/gcc9 148MB/s 1.94x
wuffs_gif_decode_1k_color_part_init/gcc9 194MB/s 2.54x
wuffs_gif_decode_10k_bgra/gcc9 645MB/s n/a
wuffs_gif_decode_10k_indexed/gcc9 203MB/s 2.14x
wuffs_gif_decode_20k/gcc9 244MB/s 2.49x
wuffs_gif_decode_100k_artificial/gcc9 532MB/s 3.43x
wuffs_gif_decode_100k_realistic/gcc9 214MB/s 2.23x
wuffs_gif_decode_1000k_full_init/gcc9 217MB/s 2.21x
wuffs_gif_decode_1000k_part_init/gcc9 218MB/s 2.22x
wuffs_gif_decode_anim_screencap/gcc9 1.11GB/s 6.24x
wuffs_gif_decode_1k_bw/gcc10 659 MB/s 3.80x
wuffs_gif_decode_1k_color_full_init/gcc10 175 MB/s 1.94x
wuffs_gif_decode_1k_color_part_init/gcc10 202 MB/s 2.24x
wuffs_gif_decode_10k_bgra/gcc10 768 MB/s n/a
wuffs_gif_decode_10k_indexed/gcc10 202 MB/s 1.92x
wuffs_gif_decode_20k/gcc10 250 MB/s 2.36x
wuffs_gif_decode_100k_artificial/gcc10 564 MB/s 3.42x
wuffs_gif_decode_100k_realistic/gcc10 217 MB/s 2.11x
wuffs_gif_decode_1000k_full_init/gcc10 221 MB/s 2.08x
wuffs_gif_decode_1000k_part_init/gcc10 221 MB/s 2.08x
wuffs_gif_decode_anim_screencap/gcc10 1.31 GB/s 6.58x
mimic_gif_decode_1k_bw 145MB/s 1.00x
mimic_gif_decode_1k_color 76.3MB/s 1.00x
mimic_gif_decode_10k_indexed 94.9MB/s 1.00x
mimic_gif_decode_20k 98.1MB/s 1.00x
mimic_gif_decode_100k_artificial 155MB/s 1.00x
mimic_gif_decode_100k_realistic 96.1MB/s 1.00x
mimic_gif_decode_1000k 98.4MB/s 1.00x
mimic_gif_decode_anim_screencap 178MB/s 1.00x
mimic_gif_decode_1k_bw 173 MB/s 1.00x
mimic_gif_decode_1k_color_full_init 90 MB/s 1.00x
mimic_gif_decode_10k_indexed 105 MB/s 1.00x
mimic_gif_decode_20k 106 MB/s 1.00x
mimic_gif_decode_100k_artificial 165 MB/s 1.00x
mimic_gif_decode_100k_realistic 103 MB/s 1.00x
mimic_gif_decode_1000k_full_init 106 MB/s 1.00x
mimic_gif_decode_anim_screencap 199 MB/s 1.00x
32-bit ARMv7 (2012 era Samsung Exynos 5 Chromebook), Debian Stretch (2017):
go_gif_decode_1k_bw 167 MB/s 0.97x
go_gif_decode_1k_color_full_init 63 MB/s 0.70x
go_gif_decode_10k_bgra 216 MB/s n/a
go_gif_decode_10k_indexed 92 MB/s 0.88x
go_gif_decode_20k 102 MB/s 0.96x
go_gif_decode_100k_artificial 202 MB/s 1.22x
go_gif_decode_100k_realistic 102 MB/s 0.99x
go_gif_decode_1000k_full_init 103 MB/s 0.97x
go_gif_decode_anim_screencap 237 MB/s 1.19x
rust_gif_decode_1k_bw 362 MB/s 2.09x
rust_gif_decode_1k_color_full_init 113 MB/s 1.26x
rust_gif_decode_10k_bgra 333 MB/s n/a
rust_gif_decode_10k_indexed 101 MB/s 0.96x
rust_gif_decode_20k 119 MB/s 1.12x
rust_gif_decode_100k_artificial 248 MB/s 1.50x
rust_gif_decode_100k_realistic 113 MB/s 1.10x
rust_gif_decode_1000k_full_init 115 MB/s 1.08x
rust_gif_decode_anim_screencap 513 MB/s 2.58x
To reproduce the Go 1.19 numbers, run `go run main.go` in
`script/bench-go-gif`. For Rust 1.48 / gif 0.11.4, run `cargo run --release` in
`script/bench-rust-gif`.
Historical (Wuffs v0.2; 2019) numbers for 32-bit ARMv7 (2012 era Samsung Exynos
5 Chromebook), Debian Stretch (2017):
name speed vs_mimic
@@ -318,106 +345,137 @@ so there are no mimic numbers to compare to for the `bgra` suffix.
mimic_gif_decode_anim_screencap 60.3MB/s 1.00x
## GIF (Go)
For comparison, here are Go 1.12.10's numbers, using Go's standard library's
`image/gif` package.
name speed vs_mimic
go_gif_decode_1k_bw 107MB/s 0.74x
go_gif_decode_1k_color 39.2MB/s 0.51x
go_gif_decode_10k_bgra 117MB/s n/a
go_gif_decode_10k_indexed 57.8MB/s 0.61x
go_gif_decode_20k 67.2MB/s 0.69x
go_gif_decode_100k_artificial 151MB/s 0.97x
go_gif_decode_100k_realistic 67.2MB/s 0.70x
go_gif_decode_1000k 68.1MB/s 0.69x
go_gif_decode_anim_screencap 206MB/s 1.16x
To reproduce these numbers:
git clone https://github.com/google/wuffs.git
cd wuffs/script/bench-go-gif/
go run main.go
## GIF (Rust)
For comparison, here are Rust 1.37.0's numbers, using the
[image-rs/image-gif](https://github.com/image-rs/image-gif) crate, easily the
top `crates.io` result for ["gif"](https://crates.io/search?q=gif).
name speed vs_mimic
rust_gif_decode_1k_bw 89.2MB/s 0.62x
rust_gif_decode_1k_color 20.7MB/s 0.27x
rust_gif_decode_10k_bgra 74.5MB/s n/a
rust_gif_decode_10k_indexed 20.4MB/s 0.21x
rust_gif_decode_20k 28.9MB/s 0.29x
rust_gif_decode_100k_artificial 79.1MB/s 0.51x
rust_gif_decode_100k_realistic 27.9MB/s 0.29x
rust_gif_decode_1000k 27.9MB/s 0.28x
rust_gif_decode_anim_screencap 144MB/s 0.81x
To reproduce these numbers:
git clone https://github.com/google/wuffs.git
cd wuffs/script/bench-rust-gif/
cargo run --release
# Gzip (Deflate + CRC-32)
The `1k`, `10k`, etc. numbers are approximately how many bytes there in the
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
decoded output.
name speed vs_mimic
name speed vs_mimic
wuffs_gzip_decode_10k/clang8 238MB/s 1.05x
wuffs_gzip_decode_100k/clang8 273MB/s 1.03x
wuffs_gzip_decode_10k/clang11 420 MB/s 1.71x
wuffs_gzip_decode_100k/clang11 527 MB/s 1.81x
wuffs_gzip_decode_10k/gcc9 239MB/s 1.06x
wuffs_gzip_decode_100k/gcc9 297MB/s 1.12x
wuffs_gzip_decode_10k/gcc10 427 MB/s 1.74x
wuffs_gzip_decode_100k/gcc10 550 MB/s 1.89x
mimic_gzip_decode_10k 226MB/s 1.00x
mimic_gzip_decode_100k 265MB/s 1.00x
mimicztl_gzip_decode_10k 246 MB/s 1.00x
mimicztl_gzip_decode_100k 291 MB/s 1.00x
mimiclibdeflate_gzip_decode_10k 494 MB/s 2.01x
mimiclibdeflate_gzip_decode_100k 496 MB/s 1.70x
# LZW
The `1k`, `10k`, etc. numbers are approximately how many bytes there in the
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
decoded output.
The libgif library doesn't export its LZW decoder in its API, so there are no
mimic numbers to compare to.
name speed vs_mimic
name speed vs_mimic
wuffs_lzw_decode_20k/clang8 263MB/s n/a
wuffs_lzw_decode_100k/clang8 438MB/s n/a
wuffs_lzw_decode_20k/clang11 293 MB/s n/a
wuffs_lzw_decode_100k/clang11 489 MB/s n/a
wuffs_lzw_decode_20k/gcc9 266MB/s n/a
wuffs_lzw_decode_100k/gcc9 450MB/s n/a
wuffs_lzw_decode_20k/gcc10 259 MB/s n/a
wuffs_lzw_decode_100k/gcc10 516 MB/s n/a
# PNG
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
decoded image. For example, the `test/data/harvesters.*` images are 1165 × 859,
approximately 1000k pixels and hence 4000k bytes at 4 bytes per pixel.
The `full_init` vs `part_init` suffixes are whether
[`WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED`](/doc/note/initialization.md#partial-zero-initialization)
is unset or set.
libpng's "simplified API" doesn't provide a way to ignore the checksum. We copy
the `verify_checksum` numbers for a 1.00x baseline.
name speed vs_mimic
wuffs_png_decode_image_19k_8bpp/clang11 279 MB/s 2.29x
wuffs_png_decode_image_40k_24bpp/clang11 323 MB/s 2.20x
wuffs_png_decode_image_77k_8bpp/clang11 984 MB/s 2.66x
wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang11 871 MB/s 3.01x
wuffs_png_decode_image_552k_32bpp_verify_checksum/clang11 837 MB/s 2.90x
wuffs_png_decode_image_4002k_24bpp/clang11 331 MB/s 1.55x
wuffs_png_decode_image_19k_8bpp/gcc10 277 MB/s 2.27x
wuffs_png_decode_image_40k_24bpp/gcc10 343 MB/s 2.33x
wuffs_png_decode_image_77k_8bpp/gcc10 1.00 GB/s 2.70x
wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10 914 MB/s 3.16x
wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10 870 MB/s 3.01x
wuffs_png_decode_image_4002k_24bpp/gcc10 353 MB/s 1.65x
mimiclibpng_png_decode_image_19k_8bpp 122 MB/s 1.00x
mimiclibpng_png_decode_image_40k_24bpp 147 MB/s 1.00x
mimiclibpng_png_decode_image_77k_8bpp 370 MB/s 1.00x
mimiclibpng_png_decode_image_552k_32bpp_verify_checksum 289 MB/s 1.00x
mimiclibpng_png_decode_image_4002k_24bpp 214 MB/s 1.00x
mimiclibspng_png_decode_image_19k_8bpp 125 MB/s 1.02x
mimiclibspng_png_decode_image_40k_24bpp 155 MB/s 1.05x
mimiclibspng_png_decode_image_77k_8bpp 384 MB/s 1.04x
mimiclibspng_png_decode_image_552k_32bpp_ignore_checksum 461 MB/s 1.60x
mimiclibspng_png_decode_image_552k_32bpp_verify_checksum 392 MB/s 1.36x
mimiclibspng_png_decode_image_4002k_24bpp 225 MB/s 1.05x
mimiclodepng_png_decode_image_19k_8bpp 138 MB/s 1.13x
mimiclodepng_png_decode_image_40k_24bpp 166 MB/s 1.13x
mimiclodepng_png_decode_image_77k_8bpp 404 MB/s 1.09x
mimiclodepng_png_decode_image_552k_32bpp_verify_checksum 258 MB/s 0.89x
mimiclodepng_png_decode_image_4002k_24bpp 165 MB/s 0.77x
mimicstb_png_decode_image_19k_8bpp 150 MB/s 1.23x
mimicstb_png_decode_image_40k_24bpp 166 MB/s 1.13x
mimicstb_png_decode_image_77k_8bpp 443 MB/s 1.20x
mimicstb_png_decode_image_552k_32bpp_ignore_checksum 288 MB/s 1.00x
mimicstb_png_decode_image_4002k_24bpp 163 MB/s 0.76x
go_png_decode_image_19k_8bpp 92 MB/s 0.75x
go_png_decode_image_40k_24bpp 107 MB/s 0.73x
go_png_decode_image_77k_8bpp 207 MB/s 0.56x
go_png_decode_image_552k_32bpp_verify_checksum 246 MB/s 0.85x
go_png_decode_image_4002k_24bpp 116 MB/s 0.54x
rust_png_decode_image_19k_8bpp 187 MB/s 1.53x
rust_png_decode_image_40k_24bpp 260 MB/s 1.77x
rust_png_decode_image_77k_8bpp 330 MB/s 0.89x
rust_png_decode_image_552k_32bpp_verify_checksum 299 MB/s 1.03x
rust_png_decode_image_4002k_24bpp 264 MB/s 1.23x
To reproduce the Go 1.19 numbers, run `go run main.go` in
`script/bench-go-png`. For Rust 1.48 / png 0.17.5 / deflate 1.0.0 /
miniz\_oxide 0.5.3, run `cargo run --release` in `script/bench-rust-png`.
# Zlib (Deflate + Adler-32)
The `1k`, `10k`, etc. numbers are approximately how many bytes there in the
The `1k`, `10k`, etc. numbers are approximately how many bytes there are in the
decoded output.
name speed vs_mimic
name speed vs_mimic
wuffs_zlib_decode_10k/clang8 237MB/s 0.96x
wuffs_zlib_decode_100k/clang8 272MB/s 0.92x
wuffs_zlib_decode_10k/clang11 410 MB/s 1.53x
wuffs_zlib_decode_100k/clang11 505 MB/s 1.56x
wuffs_zlib_decode_10k/gcc9 242MB/s 0.98x
wuffs_zlib_decode_100k/gcc9 294MB/s 0.99x
wuffs_zlib_decode_10k/gcc10 431 MB/s 1.61x
wuffs_zlib_decode_100k/gcc10 548 MB/s 1.70x
mimic_zlib_decode_10k 247MB/s 1.00x
mimic_zlib_decode_100k 296MB/s 1.00x
mimicztl_zlib_decode_10k 268 MB/s 1.00x
mimicztl_zlib_decode_100k 323 MB/s 1.00x
mimiclibdeflate_zlib_decode_10k 497 MB/s 1.85x
mimiclibdeflate_zlib_decode_100k 499 MB/s 1.54x
mimicminiz_zlib_decode_10k 237 MB/s 0.88x
mimicminiz_zlib_decode_100k 272 MB/s 0.84x
---
Updated on December 2019.
Updated on September 2022.
+107 -47
View File
@@ -3,68 +3,128 @@
Binary size measurements of `wuffs genlib` libraries on x86\_64 are below.
Lower is better.
clang8-dynamic:
-rwxr-xr-x 1 tao tao 90488 Oct 19 05:34 libwuffs.so
-rw-r--r-- 1 tao tao 7096 Oct 19 05:34 wuffs-base.lo
-rw-r--r-- 1 tao tao 2192 Oct 19 05:34 wuffs-std-adler32.lo
-rw-r--r-- 1 tao tao 19296 Oct 19 05:34 wuffs-std-crc32.lo
-rw-r--r-- 1 tao tao 20568 Oct 19 05:34 wuffs-std-deflate.lo
-rw-r--r-- 1 tao tao 26720 Oct 19 05:34 wuffs-std-gif.lo
-rw-r--r-- 1 tao tao 6592 Oct 19 05:34 wuffs-std-gzip.lo
-rw-r--r-- 1 tao tao 5808 Oct 19 05:34 wuffs-std-lzw.lo
-rw-r--r-- 1 tao tao 6584 Oct 19 05:34 wuffs-std-zlib.lo
clang11-dynamic:
-rwxr-xr-x 1 tao tao 322264 Jan 26 15:33 libwuffs.so
-rw-r--r-- 1 tao tao 5232 Jan 26 15:32 wuffs-base-core.lo
-rw-r--r-- 1 tao tao 26976 Jan 26 15:32 wuffs-base-floatconv.lo
-rw-r--r-- 1 tao tao 9312 Jan 26 15:32 wuffs-base-intconv.lo
-rw-r--r-- 1 tao tao 7920 Jan 26 15:33 wuffs-base-interfaces.lo
-rw-r--r-- 1 tao tao 3216 Jan 26 15:33 wuffs-base-magic.lo
-rw-r--r-- 1 tao tao 56192 Jan 26 15:33 wuffs-base-pixconv.lo
-rw-r--r-- 1 tao tao 3080 Jan 26 15:33 wuffs-base-utf8.lo
-rw-r--r-- 1 tao tao 4056 Jan 26 15:33 wuffs-std-adler32.lo
-rw-r--r-- 1 tao tao 28600 Jan 26 15:33 wuffs-std-bmp.lo
-rw-r--r-- 1 tao tao 17304 Jan 26 15:33 wuffs-std-bzip2.lo
-rw-r--r-- 1 tao tao 10168 Jan 26 15:33 wuffs-std-cbor.lo
-rw-r--r-- 1 tao tao 22336 Jan 26 15:33 wuffs-std-crc32.lo
-rw-r--r-- 1 tao tao 24816 Jan 26 15:33 wuffs-std-deflate.lo
-rw-r--r-- 1 tao tao 25088 Jan 26 15:33 wuffs-std-gif.lo
-rw-r--r-- 1 tao tao 7408 Jan 26 15:33 wuffs-std-gzip.lo
-rw-r--r-- 1 tao tao 20136 Jan 26 15:33 wuffs-std-json.lo
-rw-r--r-- 1 tao tao 6344 Jan 26 15:33 wuffs-std-lzw.lo
-rw-r--r-- 1 tao tao 9928 Jan 26 15:33 wuffs-std-nie.lo
-rw-r--r-- 1 tao tao 54760 Jan 26 15:33 wuffs-std-png.lo
-rw-r--r-- 1 tao tao 14552 Jan 26 15:33 wuffs-std-tga.lo
-rw-r--r-- 1 tao tao 9080 Jan 26 15:33 wuffs-std-wbmp.lo
-rw-r--r-- 1 tao tao 7224 Jan 26 15:33 wuffs-std-zlib.lo
clang8-static:
-rw-r--r-- 1 tao tao 101560 Oct 19 05:34 libwuffs.a
-rw-r--r-- 1 tao tao 7176 Oct 19 05:34 wuffs-base.o
-rw-r--r-- 1 tao tao 2176 Oct 19 05:34 wuffs-std-adler32.o
-rw-r--r-- 1 tao tao 20296 Oct 19 05:34 wuffs-std-crc32.o
-rw-r--r-- 1 tao tao 20432 Oct 19 05:34 wuffs-std-deflate.o
-rw-r--r-- 1 tao tao 26856 Oct 19 05:34 wuffs-std-gif.o
-rw-r--r-- 1 tao tao 6840 Oct 19 05:34 wuffs-std-gzip.o
-rw-r--r-- 1 tao tao 5776 Oct 19 05:34 wuffs-std-lzw.o
-rw-r--r-- 1 tao tao 6608 Oct 19 05:34 wuffs-std-zlib.o
clang11-static:
-rw-r--r-- 1 tao tao 398014 Jan 26 15:32 libwuffs.a
-rw-r--r-- 1 tao tao 5232 Jan 26 15:32 wuffs-base-core.o
-rw-r--r-- 1 tao tao 27136 Jan 26 15:32 wuffs-base-floatconv.o
-rw-r--r-- 1 tao tao 9912 Jan 26 15:32 wuffs-base-intconv.o
-rw-r--r-- 1 tao tao 7856 Jan 26 15:32 wuffs-base-interfaces.o
-rw-r--r-- 1 tao tao 3112 Jan 26 15:32 wuffs-base-magic.o
-rw-r--r-- 1 tao tao 59000 Jan 26 15:32 wuffs-base-pixconv.o
-rw-r--r-- 1 tao tao 3080 Jan 26 15:32 wuffs-base-utf8.o
-rw-r--r-- 1 tao tao 4088 Jan 26 15:32 wuffs-std-adler32.o
-rw-r--r-- 1 tao tao 29384 Jan 26 15:32 wuffs-std-bmp.o
-rw-r--r-- 1 tao tao 16784 Jan 26 15:32 wuffs-std-bzip2.o
-rw-r--r-- 1 tao tao 10304 Jan 26 15:32 wuffs-std-cbor.o
-rw-r--r-- 1 tao tao 23352 Jan 26 15:32 wuffs-std-crc32.o
-rw-r--r-- 1 tao tao 25344 Jan 26 15:32 wuffs-std-deflate.o
-rw-r--r-- 1 tao tao 25608 Jan 26 15:32 wuffs-std-gif.o
-rw-r--r-- 1 tao tao 7000 Jan 26 15:32 wuffs-std-gzip.o
-rw-r--r-- 1 tao tao 21000 Jan 26 15:32 wuffs-std-json.o
-rw-r--r-- 1 tao tao 6272 Jan 26 15:32 wuffs-std-lzw.o
-rw-r--r-- 1 tao tao 9840 Jan 26 15:32 wuffs-std-nie.o
-rw-r--r-- 1 tao tao 56560 Jan 26 15:32 wuffs-std-png.o
-rw-r--r-- 1 tao tao 14720 Jan 26 15:32 wuffs-std-tga.o
-rw-r--r-- 1 tao tao 8984 Jan 26 15:32 wuffs-std-wbmp.o
-rw-r--r-- 1 tao tao 7064 Jan 26 15:32 wuffs-std-zlib.o
gcc9-dynamic:
-rwxr-xr-x 1 tao tao 94464 Oct 19 05:34 libwuffs.so
-rw-r--r-- 1 tao tao 9784 Oct 19 05:34 wuffs-base.lo
-rw-r--r-- 1 tao tao 2512 Oct 19 05:34 wuffs-std-adler32.lo
-rw-r--r-- 1 tao tao 19568 Oct 19 05:34 wuffs-std-crc32.lo
-rw-r--r-- 1 tao tao 20752 Oct 19 05:34 wuffs-std-deflate.lo
-rw-r--r-- 1 tao tao 27936 Oct 19 05:34 wuffs-std-gif.lo
-rw-r--r-- 1 tao tao 7232 Oct 19 05:34 wuffs-std-gzip.lo
-rw-r--r-- 1 tao tao 6552 Oct 19 05:34 wuffs-std-lzw.lo
-rw-r--r-- 1 tao tao 7360 Oct 19 05:34 wuffs-std-zlib.lo
gcc10-dynamic:
-rwxr-xr-x 1 tao tao 388712 Jan 26 15:33 libwuffs.so
-rw-r--r-- 1 tao tao 5632 Jan 26 15:33 wuffs-base-core.lo
-rw-r--r-- 1 tao tao 26904 Jan 26 15:33 wuffs-base-floatconv.lo
-rw-r--r-- 1 tao tao 8584 Jan 26 15:33 wuffs-base-intconv.lo
-rw-r--r-- 1 tao tao 7664 Jan 26 15:33 wuffs-base-interfaces.lo
-rw-r--r-- 1 tao tao 4448 Jan 26 15:33 wuffs-base-magic.lo
-rw-r--r-- 1 tao tao 109488 Jan 26 15:33 wuffs-base-pixconv.lo
-rw-r--r-- 1 tao tao 3248 Jan 26 15:33 wuffs-base-utf8.lo
-rw-r--r-- 1 tao tao 4624 Jan 26 15:33 wuffs-std-adler32.lo
-rw-r--r-- 1 tao tao 28984 Jan 26 15:33 wuffs-std-bmp.lo
-rw-r--r-- 1 tao tao 18920 Jan 26 15:33 wuffs-std-bzip2.lo
-rw-r--r-- 1 tao tao 10040 Jan 26 15:33 wuffs-std-cbor.lo
-rw-r--r-- 1 tao tao 23056 Jan 26 15:33 wuffs-std-crc32.lo
-rw-r--r-- 1 tao tao 24264 Jan 26 15:33 wuffs-std-deflate.lo
-rw-r--r-- 1 tao tao 29808 Jan 26 15:33 wuffs-std-gif.lo
-rw-r--r-- 1 tao tao 8328 Jan 26 15:33 wuffs-std-gzip.lo
-rw-r--r-- 1 tao tao 20128 Jan 26 15:33 wuffs-std-json.lo
-rw-r--r-- 1 tao tao 7128 Jan 26 15:33 wuffs-std-lzw.lo
-rw-r--r-- 1 tao tao 11960 Jan 26 15:33 wuffs-std-nie.lo
-rw-r--r-- 1 tao tao 68440 Jan 26 15:33 wuffs-std-png.lo
-rw-r--r-- 1 tao tao 15736 Jan 26 15:33 wuffs-std-tga.lo
-rw-r--r-- 1 tao tao 10440 Jan 26 15:33 wuffs-std-wbmp.lo
-rw-r--r-- 1 tao tao 7744 Jan 26 15:33 wuffs-std-zlib.lo
gcc9-static:
-rw-r--r-- 1 tao tao 106120 Oct 19 05:34 libwuffs.a
-rw-r--r-- 1 tao tao 9784 Oct 19 05:34 wuffs-base.o
-rw-r--r-- 1 tao tao 2448 Oct 19 05:34 wuffs-std-adler32.o
-rw-r--r-- 1 tao tao 19488 Oct 19 05:34 wuffs-std-crc32.o
-rw-r--r-- 1 tao tao 20632 Oct 19 05:34 wuffs-std-deflate.o
-rw-r--r-- 1 tao tao 27528 Oct 19 05:34 wuffs-std-gif.o
-rw-r--r-- 1 tao tao 7144 Oct 19 05:34 wuffs-std-gzip.o
-rw-r--r-- 1 tao tao 6448 Oct 19 05:34 wuffs-std-lzw.o
-rw-r--r-- 1 tao tao 7248 Oct 19 05:34 wuffs-std-zlib.o
gcc10-static:
-rw-r--r-- 1 tao tao 480206 Jan 26 15:33 libwuffs.a
-rw-r--r-- 1 tao tao 5632 Jan 26 15:33 wuffs-base-core.o
-rw-r--r-- 1 tao tao 27008 Jan 26 15:33 wuffs-base-floatconv.o
-rw-r--r-- 1 tao tao 8768 Jan 26 15:33 wuffs-base-intconv.o
-rw-r--r-- 1 tao tao 7560 Jan 26 15:33 wuffs-base-interfaces.o
-rw-r--r-- 1 tao tao 4448 Jan 26 15:33 wuffs-base-magic.o
-rw-r--r-- 1 tao tao 109408 Jan 26 15:33 wuffs-base-pixconv.o
-rw-r--r-- 1 tao tao 3824 Jan 26 15:33 wuffs-base-utf8.o
-rw-r--r-- 1 tao tao 4680 Jan 26 15:33 wuffs-std-adler32.o
-rw-r--r-- 1 tao tao 29512 Jan 26 15:33 wuffs-std-bmp.o
-rw-r--r-- 1 tao tao 19000 Jan 26 15:33 wuffs-std-bzip2.o
-rw-r--r-- 1 tao tao 10400 Jan 26 15:33 wuffs-std-cbor.o
-rw-r--r-- 1 tao tao 23112 Jan 26 15:33 wuffs-std-crc32.o
-rw-r--r-- 1 tao tao 24936 Jan 26 15:33 wuffs-std-deflate.o
-rw-r--r-- 1 tao tao 30232 Jan 26 15:33 wuffs-std-gif.o
-rw-r--r-- 1 tao tao 8424 Jan 26 15:33 wuffs-std-gzip.o
-rw-r--r-- 1 tao tao 21456 Jan 26 15:33 wuffs-std-json.o
-rw-r--r-- 1 tao tao 7144 Jan 26 15:33 wuffs-std-lzw.o
-rw-r--r-- 1 tao tao 12168 Jan 26 15:33 wuffs-std-nie.o
-rw-r--r-- 1 tao tao 71504 Jan 26 15:33 wuffs-std-png.o
-rw-r--r-- 1 tao tao 16184 Jan 26 15:33 wuffs-std-tga.o
-rw-r--r-- 1 tao tao 10520 Jan 26 15:33 wuffs-std-wbmp.o
-rw-r--r-- 1 tao tao 7904 Jan 26 15:33 wuffs-std-zlib.o
## Comparison
Below are some standard C libraries shipped as part of Debian Testing as of
October 2019. The numbers aren't directly comparable, as these libraries have a
Below are some standard C libraries shipped as part of Debian 11 Bullseye as of
January 2023. The numbers aren't directly comparable, as these libraries have a
richer API, especially in providing an encoder and not just a decoder. Still,
it is a reference point for e.g. Wuffs (adler32 + crc32 + deflate + gzip +
zlib) vs libz and Wuffs (gif + lzw) vs libgif.
dynamic:
-rw-r--r-- 1 root root 113088 Aug 6 16:44 /lib/x86_64-linux-gnu/libz.so.1.2.11
-rw-r--r-- 1 root root 34656 Jun 5 2018 /usr/lib/x86_64-linux-gnu/libgif.so.7.0.0
-rw-r--r-- 1 root root 74688 Jul 20 2020 /lib/x86_64-linux-gnu/libbz2.so.1.0.4
-rw-r--r-- 1 root root 38752 Dec 21 2020 /lib/x86_64-linux-gnu/libgif.so.7.1.0
-rw-r--r-- 1 root root 231344 Sep 16 2020 /lib/x86_64-linux-gnu/libpng16.so.16.37.0
-rw-r--r-- 1 root root 113088 Aug 24 04:54 /lib/x86_64-linux-gnu/libz.so.1.2.11
static:
-rw-r--r-- 1 root root 50800 Jun 5 2018 /usr/lib/x86_64-linux-gnu/libgif.a
-rw-r--r-- 1 root root 143250 Aug 6 16:44 /usr/lib/x86_64-linux-gnu/libz.a
-rw-r--r-- 1 root root 80690 Jul 20 2020 /lib/x86_64-linux-gnu/libbz2.a
-rw-r--r-- 1 root root 51940 Dec 21 2020 /lib/x86_64-linux-gnu/libgif.a
-rw-r--r-- 1 root root 374338 Sep 16 2020 /lib/x86_64-linux-gnu/libpng16.a
-rw-r--r-- 1 root root 144866 Aug 24 04:54 /lib/x86_64-linux-gnu/libz.a
---
Updated on October 2019.
Updated on January 2023.
+39 -3
View File
@@ -1,7 +1,43 @@
# Changelog
## Work In Progress
## 2024-04-19 version 0.3.4
- Have `std/png` ignore tRNS chunks for color types 4 (YA) and 6 (RGBA).
## 2023-04-08 version 0.3.3
The `wuffs_base__parse_number_f64` function has been further optimized.
## 2023-04-07 version 0.3.2
The `std/bmp` and `std/nie` image decoders' `decode_frame` method now allow
decoding to a pixel buffer that's smaller than the source image. This makes
these two image decoders consistent with the other ones in `std`.
## 2023-03-04 version 0.3.1
For a *closed* `io_reader`, the standard library now returns `"#truncated
input"` instead of `"$short read"`. Importantly, this is an error, not a
suspension.
The `wuffs_base__parse_number_f64` function's Simple Decimal Conversion
fallback algorithm has been optimized.
## 2023-01-26 version 0.3.0
The headline feature is that we have a production quality PNG decoder. It's
also [the fastest, safest PNG decoder in the
world](https://nigeltao.github.io/blog/2021/fastest-safest-png-decoder.html).
There's also a [memory-safe, zero-allocation JSON
decoder](https://nigeltao.github.io/blog/2020/jsonptr.html).
The dot points below probably aren't of interest unless you're upgrading from
Wuffs version 0.2.
- Added `0b` prefixed binary numbers.
- Added `WUFFS_BASE__PIXEL_BLEND__SRC_OVER`.
@@ -14,6 +50,7 @@
- Added `cpu_arch`.
- Added `doc/logo`.
- Added `endwhile` syntax.
- Added `example/bzcat`.
- Added `example/cbor-to-json`.
- Added `example/convert-to-nia`.
- Added `example/imageviewer`.
@@ -37,7 +74,6 @@
- Added double-curly blocks.
- Added interfaces.
- Added iterate advance parameter.
- Added preprocessor.
- Added single-quoted strings.
- Added slice `uintptr_low_12_bits` method.
- Added tokens.
@@ -156,4 +192,4 @@ Wuffs version 0.1.
---
Updated on January 2020.
Updated on April 2023.
+1 -4
View File
@@ -2,11 +2,8 @@
Short term:
- [Image decode API for color spaces and gamma
correction.](https://github.com/google/wuffs/issues/39)
- [Image decode API for Region of
Interest.](https://github.com/google/wuffs/issues/40)
- [Decode APNG.](https://github.com/google/wuffs/issues/41)
- [Decode JPEG.](https://github.com/google/wuffs/issues/42)
- [Decode LZ4.](https://github.com/google/wuffs/issues/43)
- [Decode RAC.](https://github.com/google/wuffs/issues/22)
@@ -41,4 +38,4 @@ Long term:
---
Updated on March 2021.
Updated on October 2022.
+1 -1
View File
@@ -78,7 +78,7 @@ for a C compiler $CC, such as clang or gcc.
#endif
#define WORK_BUFFER_ARRAY_SIZE \
WUFFS_GZIP__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
WUFFS_BZIP2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
uint8_t g_dst_buffer_array[DST_BUFFER_ARRAY_SIZE];
uint8_t g_src_buffer_array[SRC_BUFFER_ARRAY_SIZE];
+6 -4
View File
@@ -385,10 +385,8 @@ flush_dst() {
if (n == 0) {
break;
}
ssize_t i = fwrite(g_dst.reader_pointer(), 1, n, stdout);
if (i >= 0) {
g_dst.meta.ri += i;
}
size_t i = fwrite(g_dst.reader_pointer(), 1, n, stdout);
g_dst.meta.ri += i;
if (i < n) {
return "main: error writing to stdout";
}
@@ -788,6 +786,10 @@ compute_exit_code(std::string status_msg) {
// (other non-zero exit codes). Specifically, exit code 2 for internal
// invariant violation, exit code 139 (which is 128 + SIGSEGV on x86_64
// linux) for a segmentation fault (e.g. null pointer dereference).
size_t i = status_msg.find('=');
if (i != std::string::npos) {
status_msg = status_msg.substr(0, i);
}
return (status_msg.find("internal error:") != std::string::npos) ? 2 : 1;
}
+6 -4
View File
@@ -215,10 +215,8 @@ flush_dst() {
if (n == 0) {
break;
}
ssize_t i = fwrite(g_dst.reader_pointer(), 1, n, stdout);
if (i >= 0) {
g_dst.meta.ri += i;
}
size_t i = fwrite(g_dst.reader_pointer(), 1, n, stdout);
g_dst.meta.ri += i;
if (i < n) {
return "main: error writing to stdout";
}
@@ -383,6 +381,10 @@ compute_exit_code(std::string status_msg) {
// (other non-zero exit codes). Specifically, exit code 2 for internal
// invariant violation, exit code 139 (which is 128 + SIGSEGV on x86_64
// linux) for a segmentation fault (e.g. null pointer dereference).
size_t i = status_msg.find('=');
if (i != std::string::npos) {
status_msg = status_msg.substr(0, i);
}
return (status_msg.find("internal error:") != std::string::npos) ? 2 : 1;
}
+5 -1
View File
@@ -479,7 +479,7 @@ class Callbacks : public wuffs_aux::DecodeJsonCallbacks {
top.has_map_key = false;
auto iter = jmap.find(top.map_key);
if (iter != jmap.end()) {
return "main: duplicate key: " + top.map_key;
return "main: duplicate key: key=" + top.map_key;
}
jmap.insert(iter, JsonMap::value_type(std::move(top.map_key),
std::move(jvalue)));
@@ -593,6 +593,10 @@ compute_exit_code(std::string status_msg) {
// (other non-zero exit codes). Specifically, exit code 2 for internal
// invariant violation, exit code 139 (which is 128 + SIGSEGV on x86_64
// linux) for a segmentation fault (e.g. null pointer dereference).
size_t i = status_msg.find('=');
if (i != std::string::npos) {
status_msg = status_msg.substr(0, i);
}
return (status_msg.find("internal error:") != std::string::npos) ? 2 : 1;
}
+32 -2
View File
@@ -27,6 +27,30 @@ intentional_segfault() {
*ptr = 0;
}
static uint32_t //
popcount32(uint32_t x) {
static const uint8_t table[256] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, //
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, //
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, //
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, //
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, //
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, //
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, //
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, //
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, //
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, //
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, //
};
return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
}
// jenkins_hash_u32 implements
// https://en.wikipedia.org/wiki/Jenkins_hash_function
static uint32_t //
@@ -68,15 +92,21 @@ llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
// The ! means that closed will be true for (size == 0).
const bool closed = !(1 & popcount32(hash0));
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader((uint8_t*)data, size, true);
wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
const char* msg = fuzz(&src, hash);
if (msg) {
if (strnlen(msg, 2047) >= 2047) {
msg = "fuzzlib: internal error: error message is too long";
}
if (strstr(msg, "internal error:")) {
if (closed && strstr(msg, "base: short read")) {
fprintf(stderr, "short read on a closed io_reader\n");
intentional_segfault();
} else if (strstr(msg, "internal error:")) {
fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
intentional_segfault();
}
+3 -2
View File
@@ -317,6 +317,9 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
no_progress_count = 0;
} else if (no_progress_count < 999) {
no_progress_count++;
} else if (!full_src->meta.closed &&
(status.repr == wuffs_base__suspension__short_read)) {
return wuffs_base__status__message(&status);
} else {
return "fuzz: internal error: no progress";
}
@@ -345,8 +348,6 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
break;
} else if (status.repr == wuffs_base__suspension__short_read) {
// Some Wuffs packages can yield "$short read" for a closed io_reader,
// but Wuffs' cbor package does not.
if (src.meta.closed) {
return "fuzz: internal error: short read on a closed io_reader";
}
+3 -2
View File
@@ -338,6 +338,9 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
no_progress_count = 0;
} else if (no_progress_count < 999) {
no_progress_count++;
} else if (!full_src->meta.closed &&
(status.repr == wuffs_base__suspension__short_read)) {
return wuffs_base__status__message(&status);
} else {
return "fuzz: internal error: no progress";
}
@@ -366,8 +369,6 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
break;
} else if (status.repr == wuffs_base__suspension__short_read) {
// Some Wuffs packages can yield "$short read" for a closed io_reader,
// but Wuffs' json package does not.
if (src.meta.closed) {
return "fuzz: internal error: short read on a closed io_reader";
}
+1 -1
View File
@@ -4,5 +4,5 @@ go 1.16
require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/image v0.5.0 // indirect
)
+25
View File
@@ -1,6 +1,31 @@
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+114 -53
View File
@@ -276,14 +276,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
uint8_t* q = s.ptr + s.len;
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
// Parse sign.
do {
@@ -296,14 +294,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
break;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
} while (0);
// Parse digits, up to (and including) a '.', 'E' or 'e'. Examples for each
@@ -355,9 +351,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
h->digits[nd++] = (uint8_t)(*p - '0');
dp = (int32_t)nd;
} else if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
} else {
dp++;
if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
}
}
} else if (*p ==
((options &
@@ -417,14 +416,12 @@ after_sep:
after_exp:
do {
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
int32_t exp_sign = +1;
if (*p == '+') {
@@ -1264,6 +1261,27 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// powers converts decimal powers of 10 to binary powers of 2. For example,
// (10000 >> 13) is 1. It stops before the elements exceed 60, also known
// as WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
//
// This rounds down (1<<13 is a lower bound for 1e4). Adding 1 to the array
// element value rounds up (1<<14 is an upper bound for 1e4) while staying
// at or below WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
//
// When starting in the range [1e+1 .. 1e+2] (i.e. h->decimal_point == +2),
// powers[2] == 6 and so:
// - Right shifting by 6+0 produces the range [10/64 .. 100/64] =
// [0.156250 .. 1.56250]. The resultant h->decimal_point is +0 or +1.
// - Right shifting by 6+1 produces the range [10/128 .. 100/128] =
// [0.078125 .. 0.78125]. The resultant h->decimal_point is -1 or -0.
//
// When starting in the range [1e-3 .. 1e-2] (i.e. h->decimal_point == -2),
// powers[2] == 6 and so:
// - Left shifting by 6+0 produces the range [0.001*64 .. 0.01*64] =
// [0.064 .. 0.64]. The resultant h->decimal_point is -1 or -0.
// - Left shifting by 6+1 produces the range [0.001*128 .. 0.01*128] =
// [0.128 .. 1.28]. The resultant h->decimal_point is +0 or +1.
//
// Thus, when targeting h->decimal_point being +0 or +1, use (powers[n]+0)
// when right shifting but (powers[n]+1) when left shifting.
static const uint32_t num_powers = 19;
static const uint8_t powers[19] = {
0, 3, 6, 9, 13, 16, 19, 23, 26, 29, //
@@ -1283,36 +1301,54 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
// for the common cases (e.g. assuming no underscores or a leading '+'
// sign) rather than the full set of cases allowed by the Wuffs API.
if (h->num_digits <= 19) {
//
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
// for an exact result). When we have more than 19 mantissa digits, run it
// twice to get a lower and upper bound. We still have an exact result
// (within f64's rounding margin) if both bounds are equal (and valid).
uint32_t i_max = h->num_digits;
if (i_max > 19) {
i_max = 19;
}
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
if ((-307 <= exp10) && (exp10 <= 288)) {
uint64_t man = 0;
uint32_t i;
for (i = 0; i < h->num_digits; i++) {
for (i = 0; i < i_max; i++) {
man = (10 * man) + h->digits[i];
}
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
int64_t r =
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
int64_t r0 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man, exp10);
if (r >= 0) {
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
return ret;
man + 0, exp10);
if (r0 < 0) {
break;
} else if (h->num_digits > 19) {
int64_t r1 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man + 1, exp10);
if (r1 != r0) {
break;
}
}
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
return ret;
}
}
// When Eisel-Lemire fails, fall back to Simple Decimal Conversion. See
// https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
//
// Scale by powers of 2 until we're in the range [½ .. 1], which gives us
// our exponent (in base-2). First we shift right, possibly a little too
// far, ending with a value certainly below 1 and possibly below ½...
// Scale by powers of 2 until we're in the range [0.1 .. 10]. Equivalently,
// that h->decimal_point is +0 or +1.
//
// First we shift right while at or above 10...
const int32_t f64_bias = -1023;
int32_t exp2 = 0;
while (h->decimal_point > 0) {
while (h->decimal_point > 1) {
uint32_t n = (uint32_t)(+h->decimal_point);
uint32_t shift =
(n < num_powers)
@@ -1326,20 +1362,15 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
}
exp2 += (int32_t)shift;
}
// ...then we shift left, putting us in [½ .. 1].
while (h->decimal_point <= 0) {
// ...then we shift left while below 0.1.
while (h->decimal_point < 0) {
uint32_t shift;
if (h->decimal_point == 0) {
if (h->digits[0] >= 5) {
break;
}
shift = (h->digits[0] < 2) ? 2 : 1;
} else {
uint32_t n = (uint32_t)(-h->decimal_point);
shift = (n < num_powers)
? powers[n]
: WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
}
uint32_t n = (uint32_t)(-h->decimal_point);
shift = (n < num_powers)
// The +1 is per "when targeting h->decimal_point being +0 or
// +1... when left shifting" in the powers comment above.
? (powers[n] + 1)
: WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
wuffs_base__private_implementation__high_prec_dec__small_lshift(h, shift);
if (h->decimal_point >
@@ -1349,8 +1380,37 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
exp2 -= (int32_t)shift;
}
// We're in the range [½ .. 1] but f64 uses [1 .. 2].
exp2--;
// To get from "in the range [0.1 .. 10]" to "in the range [1 .. 2]" (which
// will give us our exponent in base-2), the mantissa's first 3 digits will
// determine the final left shift, equal to 52 (the number of explicit f64
// bits) plus an additional adjustment.
int man3 = (100 * h->digits[0]) +
((h->num_digits > 1) ? (10 * h->digits[1]) : 0) +
((h->num_digits > 2) ? h->digits[2] : 0);
int32_t additional_lshift = 0;
if (h->decimal_point == 0) { // The value is in [0.1 .. 1].
if (man3 < 125) {
additional_lshift = +4;
} else if (man3 < 250) {
additional_lshift = +3;
} else if (man3 < 500) {
additional_lshift = +2;
} else {
additional_lshift = +1;
}
} else { // The value is in [1 .. 10].
if (man3 < 200) {
additional_lshift = -0;
} else if (man3 < 400) {
additional_lshift = -1;
} else if (man3 < 800) {
additional_lshift = -2;
} else {
additional_lshift = -3;
}
}
exp2 -= additional_lshift;
uint32_t final_lshift = (uint32_t)(52 + additional_lshift);
// The minimum normal exponent is (f64_bias + 1).
while ((f64_bias + 1) > exp2) {
@@ -1368,7 +1428,8 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
}
// Extract 53 bits for the mantissa (in base-2).
wuffs_base__private_implementation__high_prec_dec__small_lshift(h, 53);
wuffs_base__private_implementation__high_prec_dec__small_lshift(
h, final_lshift);
uint64_t man2 =
wuffs_base__private_implementation__high_prec_dec__rounded_integer(h);
+2
View File
@@ -219,6 +219,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto hexadecimal;
}
goto fail_bad_argument;
} else if ((*p == 'd') || (*p == 'D')) {
p++;
@@ -229,6 +230,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto decimal;
}
goto fail_bad_argument;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
+16 -10
View File
@@ -76,15 +76,16 @@ const (
//
// At the start of a function, these pointers are initialized from an
// io_buffer's fields (ptr, ri, wi, len). For an io_reader:
// - io0_etc = ptr
// - io1_etc = ptr + ri
// - iop_etc = ptr + ri
// - io2_etc = ptr + wi
// - io0_etc = ptr
// - io1_etc = ptr + ri
// - iop_etc = ptr + ri
// - io2_etc = ptr + wi
//
// and for an io_writer:
// - io0_etc = ptr
// - io1_etc = ptr + wi
// - iop_etc = ptr + wi
// - io2_etc = ptr + len
// - io0_etc = ptr
// - io1_etc = ptr + wi
// - iop_etc = ptr + wi
// - io2_etc = ptr + len
const (
io0Prefix = "io0_" // Base.
io1Prefix = "io1_" // Lower bound.
@@ -674,6 +675,7 @@ func (g *gen) genIncludes(b *buffer) error {
b.writes("#if defined(WUFFS_IMPLEMENTATION) && !defined(WUFFS_CONFIG__MODULES)\n")
b.writes("#define WUFFS_CONFIG__MODULES\n")
b.printf("#define WUFFS_CONFIG__MODULE__%s\n", g.PKGNAME)
b.writes("#define WUFFS_NONMONOLITHIC\n")
b.writes("#endif\n\n")
usesList := []string(nil)
@@ -709,7 +711,10 @@ func (g *gen) genIncludes(b *buffer) error {
}
func (g *gen) genHeader(b *buffer) error {
b.writes("\n")
module := "!defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__" + g.PKGNAME +
") || defined(WUFFS_NONMONOLITHIC)"
b.printf("#if %s\n\n", module)
b.writes("// ---------------- Status Codes\n\n")
wroteStatus := false
@@ -813,6 +818,7 @@ func (g *gen) genHeader(b *buffer) error {
}
b.writes("#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)\n\n")
b.printf("#endif // %s\n", module)
return nil
}
@@ -872,7 +878,7 @@ func (g *gen) genImpl(b *buffer) error {
return err
}
b.printf("#endif // %s\n\n", module)
b.printf("#endif // %s\n", module)
return nil
}
+21 -9
View File
@@ -305,9 +305,9 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
if e.Operator() != 0 {
prefix = aPrefix
}
cTyp, end, qualifier := "reader", "meta.wi", "const "
cTyp, end, qualifier, isWriter := "reader", "meta.wi", "const ", false
if e.MType().QID()[1] == t.IDIOWriter {
cTyp, end, qualifier = "writer", "data.len", ""
cTyp, end, qualifier, isWriter = "writer", "data.len", "", true
}
name := e.Ident().Str(g.tm)
@@ -350,6 +350,10 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
b.writes(");\n")
} else {
if !isWriter {
b.printf("const bool %s%d_closed_%s%s = %s%s->meta.closed;\n",
oPrefix, ioBindNum, prefix, name, prefix, name)
}
b.printf("%suint8_t *%s%d_%s%s%s = %s%s%s;\n",
qualifier, oPrefix, ioBindNum, io2Prefix, prefix, name, io2Prefix, prefix, name)
b.printf("wuffs_base__io_%s__limit(&%s%s%s, %s%s%s,\n",
@@ -360,11 +364,16 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
return err
}
b.writes(");\n")
b.printf("if (%s%s) {\n%s%s->%s = ((size_t)(%s%s%s - %s%s->data.ptr));\n}\n",
prefix, name,
prefix, name, end,
io2Prefix, prefix, name,
prefix, name)
b.printf("if (%s%s) {\n", prefix, name)
b.printf("size_t n = ((size_t)(%s%s%s - %s%s->data.ptr));\n",
io2Prefix, prefix, name, prefix, name)
if !isWriter {
b.printf("%s%s->meta.closed = %s%s->meta.closed && (%s%s->%s <= n);\n",
prefix, name, prefix, name, prefix, name, end)
}
b.printf("%s%s->%s = n;\n",
prefix, name, end)
b.printf("}\n")
}
}
@@ -393,11 +402,14 @@ func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error
io2Prefix, prefix, name,
oPrefix, ioBindNum, io2Prefix, prefix, name)
if n.Keyword() == t.IDIOLimit {
b.printf("if (%s%s) {\n%s%s->%s = ((size_t)(%s%s%s - %s%s->data.ptr));\n}\n",
prefix, name,
b.printf("if (%s%s) {\n", prefix, name)
b.printf("%s%s->meta.closed = %s%d_closed_%s%s;\n",
prefix, name, oPrefix, ioBindNum, prefix, name)
b.printf("%s%s->%s = ((size_t)(%s%s%s - %s%s->data.ptr));\n",
prefix, name, end,
io2Prefix, prefix, name,
prefix, name)
b.printf("}\n")
}
}
b.writes("}\n")
+6 -3
View File
@@ -50,6 +50,9 @@ func (g *gen) needDerivedVar(name t.ID) bool {
return nil
}
if recv.IsArgsDotFoo() == name {
if meth == t.IDIsClosed {
return nil
}
return errNeedDerivedVar
}
// Some built-in methods will also need a derived var for their
@@ -125,7 +128,7 @@ func (g *gen) writeInitialLoadDerivedVar(b *buffer, n *a.Field) error {
b.printf("%s%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", c, elem, io1Prefix, preName)
b.printf("%s%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", c, elem, io2Prefix, preName)
b.printf("if (%s) {\n", preName)
b.printf("if (%s && %s->data.ptr) {\n", preName, preName)
b.printf("%s%s = %s->data.ptr;\n", io0Prefix, preName, preName)
b.printf("%s%s = %s%s + %s->%s;\n", io1Prefix, preName, io0Prefix, preName, preName, i1)
@@ -149,8 +152,8 @@ func (g *gen) writeFinalSaveDerivedVar(b *buffer, n *a.Field) error {
}
preName := aPrefix + n.Name().Str(g.tm)
b.printf("if (%s) {\n%s->%s = ((size_t)(%s%s - %s->data.ptr));\n}\n",
preName, preName, i1, iopPrefix, preName, preName)
b.printf("if (%s && %s->data.ptr) {\n%s->%s = ((size_t)(%s%s - %s->data.ptr));\n}\n",
preName, preName, preName, i1, iopPrefix, preName, preName)
return nil
}
+82 -82
View File
@@ -328,12 +328,12 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
const MaxExprDepth = 255
// Expr is an expression, such as "i", "+j" or "k + l[m(n, o)].p":
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDotDot|IDDot>
// - ID2: <0|literal|ident>
// - LHS: <nil|Expr>
// - MHS: <nil|Expr>
// - RHS: <nil|Expr|TypeExpr>
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDotDot|IDDot>
// - ID2: <0|literal|ident>
// - LHS: <nil|Expr>
// - MHS: <nil|Expr>
// - RHS: <nil|Expr|TypeExpr>
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
//
// A zero ID0 means an identifier or literal in ID2, like `foo`, `42` or a
// status literal like `"#foo"`.
@@ -468,10 +468,10 @@ func NewExpr(flags Flags, operator t.ID, ident t.ID, lhs *Node, mhs *Node, rhs *
// Assert is "assert RHS via ID2(args)", "choose etc", "pre etc", "inv etc" or
// "post etc":
// - ID0: <IDAssert|IDChoose|IDPre|IDInv|IDPost>
// - ID2: <"-string literal> reason
// - RHS: <Expr>
// - List0: <Arg> reason arguments
// - ID0: <IDAssert|IDChoose|IDPre|IDInv|IDPost>
// - ID2: <"-string literal> reason
// - RHS: <Expr>
// - List0: <Arg> reason arguments
type Assert Node
func (n *Assert) AsNode() *Node { return (*Node)(n) }
@@ -513,8 +513,8 @@ func NewAssert(keyword t.ID, condition *Expr, reason t.ID, args []*Node) *Assert
}
// Arg is "name:value".
// - ID2: <ident> name
// - RHS: <Expr> value
// - ID2: <ident> name
// - RHS: <Expr> value
type Arg Node
func (n *Arg) AsNode() *Node { return (*Node)(n) }
@@ -530,9 +530,9 @@ func NewArg(name t.ID, value *Expr) *Arg {
}
// Assign is "LHS = RHS" or "LHS op= RHS" or "RHS":
// - ID0: operator
// - LHS: <nil|Expr>
// - RHS: <Expr>
// - ID0: operator
// - LHS: <nil|Expr>
// - RHS: <Expr>
type Assign Node
func (n *Assign) AsNode() *Node { return (*Node)(n) }
@@ -550,8 +550,8 @@ func NewAssign(operator t.ID, lhs *Expr, rhs *Expr) *Assign {
}
// Var is "var ID2 LHS":
// - ID2: name
// - LHS: <TypeExpr>
// - ID2: name
// - LHS: <TypeExpr>
type Var Node
func (n *Var) AsNode() *Node { return (*Node)(n) }
@@ -569,9 +569,9 @@ func NewVar(name t.ID, xType *TypeExpr) *Var {
}
// Field is a "name : type" struct field:
// - FlagsPrivateData is the initializer need not explicitly memset to zero.
// - ID2: name
// - LHS: <TypeExpr>
// - FlagsPrivateData is the initializer need not explicitly memset to zero.
// - ID2: name
// - LHS: <TypeExpr>
type Field Node
func (n *Field) AsNode() *Node { return (*Node)(n) }
@@ -590,11 +590,11 @@ func NewField(flags Flags, name t.ID, xType *TypeExpr) *Field {
// IOManip is "io_bind (io:LHS, data:MHS, history_position:RHS) { List2 }" or
// "io_limit (io:LHS, limit:MHS) { List2 }":
// - ID0: <IDIOBind|IDIOLimit>
// - LHS: <Expr>
// - MHS: <Expr>
// - RHS: <Expr>
// - List2: <Statement> body
// - ID0: <IDIOBind|IDIOLimit>
// - LHS: <Expr>
// - MHS: <Expr>
// - RHS: <Expr>
// - List2: <Statement> body
type IOManip Node
func (n *IOManip) AsNode() *Node { return (*Node)(n) }
@@ -617,16 +617,16 @@ func NewIOManip(keyword t.ID, io *Expr, arg1 *Expr, historyPosition *Expr, body
// Iterate is
// "iterate.ID1 (assigns)(length:ID2, advance:ID0, unroll:LHS), List1 { List2 } else RHS":
// - FlagsHasBreak is the iterate has an explicit break
// - FlagsHasContinue is the iterate has an explicit continue
// - ID0: advance
// - ID1: <0|label>
// - ID2: length
// - LHS: <Expr> unroll
// - RHS: <nil|Iterate>
// - List0: <Assign> assigns
// - List1: <Assert> asserts
// - List2: <Statement> body
// - FlagsHasBreak is the iterate has an explicit break
// - FlagsHasContinue is the iterate has an explicit continue
// - ID0: advance
// - ID1: <0|label>
// - ID2: length
// - LHS: <Expr> unroll
// - RHS: <nil|Iterate>
// - List0: <Assign> assigns
// - List1: <Assert> asserts
// - List2: <Statement> body
type Iterate Node
func (n *Iterate) AsNode() *Node { return (*Node)(n) }
@@ -661,12 +661,12 @@ func NewIterate(label t.ID, assigns []*Node, length t.ID, advance t.ID, unroll t
}
// While is "while.ID1 MHS, List1 { List2 } endwhile.ID1":
// - FlagsHasBreak is the while has an explicit break
// - FlagsHasContinue is the while has an explicit continue
// - ID1: <0|label>
// - MHS: <Expr>
// - List1: <Assert> asserts
// - List2: <Statement> body
// - FlagsHasBreak is the while has an explicit break
// - FlagsHasContinue is the while has an explicit continue
// - ID1: <0|label>
// - MHS: <Expr>
// - List1: <Assert> asserts
// - List2: <Statement> body
//
// TODO: should we be able to unroll while loops too?
type While Node
@@ -699,10 +699,10 @@ func NewWhile(label t.ID, condition *Expr, asserts []*Node) *While {
}
// If is "if MHS { List2 } else RHS" or "if MHS { List2 } else { List1 }":
// - MHS: <Expr>
// - RHS: <nil|If>
// - List1: <Statement> if-false body
// - List2: <Statement> if-true body
// - MHS: <Expr>
// - RHS: <nil|If>
// - List1: <Statement> if-false body
// - List2: <Statement> if-true body
type If Node
func (n *If) AsNode() *Node { return (*Node)(n) }
@@ -722,8 +722,8 @@ func NewIf(condition *Expr, bodyIfTrue []*Node, bodyIfFalse []*Node, elseIf *If)
}
// Choose is "choose ID2: List0":
// - ID2: name
// - List0: <Expr> method names.
// - ID2: name
// - List0: <Expr> method names.
type Choose Node
func (n *Choose) AsNode() *Node { return (*Node)(n) }
@@ -739,9 +739,9 @@ func NewChoose(name t.ID, args []*Node) *Choose {
}
// Ret is "return LHS" or "yield LHS":
// - FlagsReturnsError LHS is an error status
// - ID0: <IDReturn|IDYield>
// - LHS: <Expr>
// - FlagsReturnsError LHS is an error status
// - ID0: <IDReturn|IDYield>
// - LHS: <Expr>
type Ret Node
func (n *Ret) AsNode() *Node { return (*Node)(n) }
@@ -760,8 +760,8 @@ func NewRet(keyword t.ID, value *Expr) *Ret {
}
// Jump is "break" or "continue", with an optional label, "break.label":
// - ID0: <IDBreak|IDContinue>
// - ID1: <0|label>
// - ID0: <IDBreak|IDContinue>
// - ID1: <0|label>
type Jump Node
func (n *Jump) AsNode() *Node { return (*Node)(n) }
@@ -784,12 +784,12 @@ const MaxTypeExprDepth = 63
// TypeExpr is a type expression, such as "base.u32", "base.u32[..= 8]", "foo",
// "pkg.bar", "ptr T", "array[8] T", "slice T" or "table T":
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
// - ID1: <0|pkg>
// - ID2: <0|type name>
// - LHS: <nil|Expr>
// - MHS: <nil|Expr>
// - RHS: <nil|TypeExpr>
// - ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
// - ID1: <0|pkg>
// - ID2: <0|type name>
// - LHS: <nil|Expr>
// - MHS: <nil|Expr>
// - RHS: <nil|TypeExpr>
//
// An IDNptr or IDPtr ID0 means "nptr RHS" or "ptr RHS". RHS is the inner type.
//
@@ -958,14 +958,14 @@ func NewTypeExpr(decorator t.ID, pkg t.ID, name t.ID, alenRecvMin *Node, max *Ex
const MaxBodyDepth = 255
// Func is "func ID2.ID0(LHS)(RHS) { List2 }":
// - FlagsPublic is "pub" vs "pri"
// - ID0: funcName
// - ID1: <0|receiverPkg> (set by calling SetPackage)
// - ID2: <0|receiverName>
// - LHS: <Struct> in-parameters
// - RHS: <Struct> out-parameters
// - List1: <Assert> asserts
// - List2: <Statement> body
// - FlagsPublic is "pub" vs "pri"
// - ID0: funcName
// - ID1: <0|receiverPkg> (set by calling SetPackage)
// - ID2: <0|receiverName>
// - LHS: <Struct> in-parameters
// - RHS: <Struct> out-parameters
// - List1: <Assert> asserts
// - List2: <Statement> body
type Func Node
func (n *Func) AsNode() *Node { return (*Node)(n) }
@@ -1033,9 +1033,9 @@ func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcN
}
// Status is "error (RHS) ID2" or "suspension (RHS) ID2":
// - FlagsPublic is "pub" vs "pri"
// - ID1: <0|pkg> (set by calling SetPackage)
// - ID2: message
// - FlagsPublic is "pub" vs "pri"
// - ID1: <0|pkg> (set by calling SetPackage)
// - ID2: message
type Status Node
func (n *Status) AsNode() *Node { return (*Node)(n) }
@@ -1055,11 +1055,11 @@ func NewStatus(flags Flags, filename string, line uint32, message t.ID) *Status
}
// Const is "const ID2 LHS = RHS":
// - FlagsPublic is "pub" vs "pri"
// - ID1: <0|pkg> (set by calling SetPackage)
// - ID2: name
// - LHS: <TypeExpr>
// - RHS: <Expr>
// - FlagsPublic is "pub" vs "pri"
// - ID1: <0|pkg> (set by calling SetPackage)
// - ID2: name
// - LHS: <TypeExpr>
// - RHS: <Expr>
type Const Node
func (n *Const) AsNode() *Node { return (*Node)(n) }
@@ -1087,12 +1087,12 @@ func NewConst(flags Flags, filename string, line uint32, name t.ID, xType *TypeE
const MaxImplements = 63
// Struct is "struct ID2? implements List0 (List1)":
// - FlagsPublic is "pub" vs "pri"
// - FlagsClassy is "ID2" vs "ID2?"
// - ID1: <0|pkg> (set by calling SetPackage)
// - ID2: name
// - List0: <TypeExpr> implements
// - List1: <Field> fields
// - FlagsPublic is "pub" vs "pri"
// - FlagsClassy is "ID2" vs "ID2?"
// - ID1: <0|pkg> (set by calling SetPackage)
// - ID2: name
// - List0: <TypeExpr> implements
// - List1: <Field> fields
//
// The question mark indicates a classy struct - one that supports methods,
// especially coroutines.
@@ -1120,7 +1120,7 @@ func NewStruct(flags Flags, filename string, line uint32, name t.ID, implements
}
// Use is "use ID2":
// - ID2: <"-string literal> package path
// - ID2: <"-string literal> package path
type Use Node
func (n *Use) AsNode() *Node { return (*Node)(n) }
@@ -1138,7 +1138,7 @@ func NewUse(filename string, line uint32, path t.ID) *Use {
}
// File is a file of source code:
// - List0: <Const|Func|Status|Struct|Use> top-level declarations
// - List0: <Const|Func|Status|Struct|Use> top-level declarations
type File Node
func (n *File) AsNode() *Node { return (*Node)(n) }
+15 -12
View File
@@ -201,16 +201,16 @@ type Token struct {
}
// nBuiltInIDs is the number of built-in IDs. The packing is:
// - 0x00 is invalid.
// - 0x01 ..= 0x0F are squiggly punctuation, such as ";", "." and "?".
// - 0x10 ..= 0x1F are squiggly bookends, such as "(", ")" and "]".
// - 0x20 ..= 0x3F are squiggly assignments, such as "=" and "+=".
// - 0x40 ..= 0x6F are operators, such as "+", "==" and "not".
// - 0x70 ..= 0xAF are x-ops (disambiguation forms): unary vs binary "+".
// - 0xB0 ..= 0xCF are keywords, such as "if" and "return".
// - 0xD0 ..= 0xDF are type modifiers, such as "ptr" and "slice".
// - 0xE0 ..= 0xFF are literals, such as "ok" and "true".
// - 0x100 ..= 0x3FF are identifiers, such as "bool", "u32" and "read_u8".
// - 0x00 is invalid.
// - 0x01 ..= 0x0F are squiggly punctuation, such as ";", "." and "?".
// - 0x10 ..= 0x1F are squiggly bookends, such as "(", ")" and "]".
// - 0x20 ..= 0x3F are squiggly assignments, such as "=" and "+=".
// - 0x40 ..= 0x6F are operators, such as "+", "==" and "not".
// - 0x70 ..= 0xAF are x-ops (disambiguation forms): unary vs binary "+".
// - 0xB0 ..= 0xCF are keywords, such as "if" and "return".
// - 0xD0 ..= 0xDF are type modifiers, such as "ptr" and "slice".
// - 0xE0 ..= 0xFF are literals, such as "ok" and "true".
// - 0x100 ..= 0x3FF are identifiers, such as "bool", "u32" and "read_u8".
//
// Squiggly means a sequence of non-alpha-numeric bytes, such as "+" and "&=".
const (
@@ -1299,9 +1299,12 @@ func init() {
// addXForms modifies table so that, if table[x] == y, then table[y] = y.
//
// For example, for the unaryForms table, the explicit entries are like:
// IDPlus: IDXUnaryPlus,
//
// IDPlus: IDXUnaryPlus,
//
// and this function implicitly addes entries like:
// IDXUnaryPlus: IDXUnaryPlus,
//
// IDXUnaryPlus: IDXUnaryPlus,
func addXForms(table *[nBuiltInSymbolicIDs]ID) {
implicitEntries := [nBuiltInSymbolicIDs]bool{}
for _, y := range table {
+41 -41
View File
@@ -27,57 +27,57 @@
// repository was 80 times faster than `clang-format`, even without a column
// limit:
//
// $ wc release/c/wuffs-v0.2.c
// 11858 35980 431885 release/c/wuffs-v0.2.c
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.008s
// user 0m0.005s
// sys 0m0.005s
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.668s
// user 0m0.618s
// sys 0m0.032s
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.641s
// user 0m0.585s
// sys 0m0.037s
// $ wc release/c/wuffs-v0.2.c
// 11858 35980 431885 release/c/wuffs-v0.2.c
// $ time dumbindent < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.008s
// user 0m0.005s
// sys 0m0.005s
// $ time clang-format-9 < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.668s
// user 0m0.618s
// sys 0m0.032s
// $ time clang-format-9 -style='{ColumnLimit: 0}' < release/c/wuffs-v0.2.c > /dev/null
// real 0m0.641s
// user 0m0.585s
// sys 0m0.037s
//
// Apart from some rare and largely uninteresting exceptions, the dumbindent
// algorithm only considers:
//
// ∙ '{' and '}' curly braces,
// ∙ '(' and ')' round parentheses,
// ∙ '\n' line breaks,
// ∙ ' ' spaces and '\t' tabs that start or end a line, and
// ∙ strings, comments and preprocessor directives (in order to ignore any of
// the above special characters within them),
// ∙ '{' and '}' curly braces,
// ∙ '(' and ')' round parentheses,
// ∙ '\n' line breaks,
// ∙ ' ' spaces and '\t' tabs that start or end a line, and
// ∙ strings, comments and preprocessor directives (in order to ignore any of
// the above special characters within them),
//
// Everything else is an opaque byte. Consider this input:
//
// for (i = 0; i < 3; i++) {
// j = 0; // Ignore { in a comment.
// if (i < j) { foo(); }
// u = (v +
// w);
// }
// for (i = 0; i < 3; i++) {
// j = 0; // Ignore { in a comment.
// if (i < j) { foo(); }
// u = (v +
// w);
// }
//
// From the algorithm's point of view, this input is equivalent to:
//
// ....(.................).{
// .................................
// ...(.....).{....()..}
// ....(...
// .);
// }
// ....(.................).{
// .................................
// ...(.....).{....()..}
// ....(...
// .);
// }
//
// The formatted output (using the default of 2 spaces per indent level) is:
//
// ....(.................).{
// .................................
// ...(.....).{....()..}
// ....(...
// .);
// }
// ....(.................).{
// .................................
// ...(.....).{....()..}
// ....(...
// .);
// }
//
// Dumbindent adjusts lines horizontally (indenting) but not vertically (it
// does not break or un-break lines, or collapse consecutive blank lines),
@@ -103,9 +103,9 @@
//
// Similarly, dumbindent will not correct this mis-indentation:
//
// if (condition)
// goto fail;
// goto fail;
// if (condition)
// goto fail;
// goto fail;
//
// Instead, when automatically or manually generating the input for dumbindent,
// it is recommended to always emit curly braces (again, similar to `gofmt`
+14 -14
View File
@@ -130,23 +130,23 @@ func (b *bitstream) take(nBits uint32) int32 {
// 4, 4)" example from RFC 1951 section 3.2.2, the huffman struct is
// initialized by calling:
//
// h.construct([]uint32{
// 'A': 3, 'B': 3, 'C': 3, 'D': 3, 'E': 3, 'F': 2, 'G': 4, 'H': 4,
// })
// h.construct([]uint32{
// 'A': 3, 'B': 3, 'C': 3, 'D': 3, 'E': 3, 'F': 2, 'G': 4, 'H': 4,
// })
//
// which results in:
//
// huffman{
// counts: [maxCodeBits + 1]uint32{
// 2: 1, 3: 5, 4: 2,
// },
// symbols: [maxNumCodes]int32{
// 0: 'F', 1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'G', 7: 'H',
// },
// lookUpTable: [256]uint32{
// etc,
// },
// }
// huffman{
// counts: [maxCodeBits + 1]uint32{
// 2: 1, 3: 5, 4: 2,
// },
// symbols: [maxNumCodes]int32{
// 0: 'F', 1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'G', 7: 'H',
// },
// lookUpTable: [256]uint32{
// etc,
// },
// }
//
// Continuing the example from the RFC, decoding "1110" from the bitstream will
// produce the 'G' symbol.
+31 -28
View File
@@ -1057,18 +1057,19 @@ func orOneNegOneNonNeg(neg IntRange, non IntRange) (z IntRange) {
// possible xx in x and yy in y.
//
// Algorithm:
// // If the two intervals overlap, the result is the minimum of the two
// // intervals' maxima.
// //
// // This overlaps code path is just an optimization.
// if overlaps(x, y) {
// return min(xMax, yMax)
// }
// xFlip = bitFillRight(bitFillRight(xMax & ~xMin) & xMax & ~yMax)
// xResult = yMax & ((xMax & ~xFlip) | (xFlip >> 1))
// yFlip = bitFillRight(bitFillRight(yMax & ~yMin) & yMax & ~xMax)
// yResult = xMax & ((yMax & ~yFlip) | (yFlip >> 1))
// return max(xResult, yResult)
//
// // If the two intervals overlap, the result is the minimum of the two
// // intervals' maxima.
// //
// // This overlaps code path is just an optimization.
// if overlaps(x, y) {
// return min(xMax, yMax)
// }
// xFlip = bitFillRight(bitFillRight(xMax & ~xMin) & xMax & ~yMax)
// xResult = yMax & ((xMax & ~xFlip) | (xFlip >> 1))
// yFlip = bitFillRight(bitFillRight(yMax & ~yMin) & yMax & ~xMax)
// yResult = xMax & ((yMax & ~yFlip) | (yFlip >> 1))
// return max(xResult, yResult)
//
// If xMin and yMin are both zero, the overlaps branch is taken.
//
@@ -1189,13 +1190,15 @@ func (x IntRange) andMax(y IntRange) *big.Int {
// possible xx in x and yy in y.
//
// Algorithm:
// droppable = bitFillRight((xMax & ~xMin) | (yMax & ~yMin))
// available = xMax & yMax & droppable
// return xMax | yMax | (bitFillRight(available) >> 1)
//
// droppable = bitFillRight((xMax & ~xMin) | (yMax & ~yMin))
// available = xMax & yMax & droppable
// return xMax | yMax | (bitFillRight(available) >> 1)
//
// If xMin and yMin are both zero, this simplifies to:
// available = xMax & yMax
// return xMax | yMax | (bitFillRight(available) >> 1)
//
// available = xMax & yMax
// return xMax | yMax | (bitFillRight(available) >> 1)
func (x IntRange) orMax(y IntRange) *big.Int {
if x[0].Sign() == 0 && y[0].Sign() == 0 {
i := big.NewInt(0)
@@ -1257,17 +1260,17 @@ func (x IntRange) orMax(y IntRange) *big.Int {
}
// bitFillRight modifies i to round up to the next power of 2 minus 1:
// - If i is +0 then bitFillRight(i) sets i to 0.
// - If i is +1 then bitFillRight(i) sets i to 1.
// - If i is +2 then bitFillRight(i) sets i to 3.
// - If i is +3 then bitFillRight(i) sets i to 3.
// - If i is +4 then bitFillRight(i) sets i to 7.
// - If i is +5 then bitFillRight(i) sets i to 7.
// - If i is +6 then bitFillRight(i) sets i to 7.
// - If i is +7 then bitFillRight(i) sets i to 7.
// - If i is +8 then bitFillRight(i) sets i to 15.
// - If i is +9 then bitFillRight(i) sets i to 15.
// - Etc.
// - If i is +0 then bitFillRight(i) sets i to 0.
// - If i is +1 then bitFillRight(i) sets i to 1.
// - If i is +2 then bitFillRight(i) sets i to 3.
// - If i is +3 then bitFillRight(i) sets i to 3.
// - If i is +4 then bitFillRight(i) sets i to 7.
// - If i is +5 then bitFillRight(i) sets i to 7.
// - If i is +6 then bitFillRight(i) sets i to 7.
// - If i is +7 then bitFillRight(i) sets i to 7.
// - If i is +8 then bitFillRight(i) sets i to 15.
// - If i is +9 then bitFillRight(i) sets i to 15.
// - Etc.
func bitFillRight(i *big.Int) {
if s := i.Sign(); s < 0 {
panic("pre-condition failure")
+40 -4
View File
@@ -21,7 +21,7 @@ import (
"github.com/google/wuffs/lib/litonlylzma"
)
func ExampleRoundTrip() {
func Example_roundTripLZMA() {
original := []byte("Hello world.\n")
compressed, err := litonlylzma.FileFormatLZMA.Encode(nil, original)
if err != nil {
@@ -31,15 +31,51 @@ func ExampleRoundTrip() {
if err != nil {
log.Fatalf("Decode: %v", err)
}
for i, c := range compressed {
if i > 0 {
if (i & 15) > 0 {
fmt.Printf(" ")
}
fmt.Printf("%02X", c)
if ((i & 15) == 15) || ((i + 1) == len(compressed)) {
fmt.Println()
}
}
fmt.Printf("\n%s\n", recovered)
fmt.Printf("%s", recovered)
// Output:
// 5D 00 10 00 00 0D 00 00 00 00 00 00 00 00 24 19 49 86 E7 D5 E5 E2 56 ED 6A E6 0E 81 FE B8 00 00
// 5D 00 10 00 00 0D 00 00 00 00 00 00 00 00 24 19
// 49 86 E7 D5 E5 E2 56 ED 6A E6 0E 81 FE B8 00 00
// Hello world.
}
func Example_roundTripXz() {
original := []byte("Hello world.\n")
compressed, err := litonlylzma.FileFormatXz.Encode(nil, original)
if err != nil {
log.Fatalf("Encode: %v", err)
}
recovered, _, err := litonlylzma.FileFormatXz.Decode(nil, compressed)
if err != nil {
log.Fatalf("Decode: %v", err)
}
for i, c := range compressed {
if (i & 15) > 0 {
fmt.Printf(" ")
}
fmt.Printf("%02X", c)
if ((i & 15) == 15) || ((i + 1) == len(compressed)) {
fmt.Println()
}
}
fmt.Printf("%s", recovered)
// Output:
// FD 37 7A 58 5A 00 00 01 69 22 DE 36 02 00 21 01
// 00 00 00 00 37 27 97 D6 01 00 0C 48 65 6C 6C 6F
// 20 77 6F 72 6C 64 2E 0A 00 00 00 00 8E F8 31 35
// 00 01 21 0D 75 DC A8 D2 90 42 99 0D 01 00 00 00
// 00 01 59 5A
// Hello world.
}
+390 -102
View File
@@ -14,39 +14,45 @@
// ----------------
// Package litonlylzma provides a decoder and encoder for Literal Only LZMA, a
// subset of the LZMA compressed file format.
// Package litonlylzma provides a decoder and encoder for Literal Only LZMA (or
// Literal Only Xz), a subset of the LZMA (or Xz) compressed file formats.
//
// Subset means that the Encode method's output is a valid LZMA file and can be
// decompressed by the tools available at https://www.7-zip.org/sdk.html (and
// available as /usr/bin/lzma on a Debian system).
// Subset means that:
// - the Encode methods' output is a valid LZMA/Xz file and can be
// decompressed by the tools available at https://www.7-zip.org/sdk.html or
// https://tukaani.org/xz/ (and available as /usr/bin/lzma or /usr/bin/xz
// on a Debian system).
// - the Decode methods supports the Encode methods' output but they do not
// support the full set of valid LZMA/Xz files.
// - this codec's compression ratios are not as good as full LZMA/Xz
// (although compression times are much faster). Moderate compression is
// still achieved, through range coding, but there are no Lempel Ziv
// back-references.
//
// Subset also means that this codec's compression ratios are not as good as
// full-LZMA (although compression times are much faster). Moderate compression
// is still achieved, through range coding, but there are no Lempel Ziv
// back-references. The main benefit, compared to full-LZMA, is that this
// implementation is much simpler and hence easier to study. It is only a few
// hundred lines of code.
// The main benefit, compared to full LZMA/Xz, is that this implementation is
// much simpler and hence easier to study. It is around 800 lines of code.
//
// Example compression numbers on a small English text file (at
// https://github.com/google/wuffs/blob/main/test/data/romeo.txt):
// - romeo.txt is 942 bytes (100%).
// - romeo.txt.litonlylzma is 659 bytes (70%).
// - romeo.txt.xz is 644 bytes (68%).
// - romeo.txt.lzma is 598 bytes (63%).
// - romeo.txt.bz2 is 568 bytes (60%).
// - romeo.txt.zst is 559 bytes (59%).
// - romeo.txt.gz is 558 bytes (59%).
// - romeo.txt is 942 bytes (100%).
// - romeo.txt.litonlyxz is 708 bytes (75%).
// - romeo.txt.litonlylzma is 659 bytes (70%).
// - romeo.txt.xz is 644 bytes (68%).
// - romeo.txt.lzma is 598 bytes (63%).
// - romeo.txt.bz2 is 568 bytes (60%).
// - romeo.txt.zst is 559 bytes (59%).
// - romeo.txt.gz is 558 bytes (59%).
//
// Example compression numbers on a large archive of source code (at
// https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.1.tar.xz):
// - linux-5.0.1.tar is 863313920 bytes (100%).
// - linux-5.0.1.tar.litonlylzma is 449726070 bytes (52%).
// - linux-5.0.1.tar.gz is 164575959 bytes (19%).
// - linux-5.0.1.tar.zst is 156959897 bytes (18%).
// - linux-5.0.1.tar.bz2 is 125873134 bytes (15%).
// - linux-5.0.1.tar.xz is 108233572 bytes (13%).
// - linux-5.0.1.tar.lzma is 108216601 bytes (13%).
// - linux-5.0.1.tar is 863313920 bytes (100%).
// - linux-5.0.1.tar.litonlyxz is 454480932 bytes (53%).
// - linux-5.0.1.tar.litonlylzma is 449726070 bytes (52%).
// - linux-5.0.1.tar.gz is 164575959 bytes (19%).
// - linux-5.0.1.tar.zst is 156959897 bytes (18%).
// - linux-5.0.1.tar.bz2 is 125873134 bytes (15%).
// - linux-5.0.1.tar.xz is 108233572 bytes (13%).
// - linux-5.0.1.tar.lzma is 108216601 bytes (13%).
//
// The various tools (/usr/bin/gzip, /usr/bin/xz, etc) were all ran with their
// default settings, not their "maximum compression" settings. This is why the
@@ -55,13 +61,16 @@ package litonlylzma
import (
"errors"
"hash/crc32"
)
var (
// ErrUnsupportedLZMAData is potentially returned by Decode.
// ErrUnsupportedXxxData is potentially returned by Decode.
ErrUnsupportedLZMAData = errors.New("litonlylzma: unsupported LZMA data")
ErrUnsupportedXzData = errors.New("litonlylzma: unsupported Xz data")
errInvalidLZMAData = errors.New("litonlylzma: invalid LZMA data")
errInvalidXzData = errors.New("litonlylzma: invalid Xz data")
errUnexpectedEOF = errors.New("litonlylzma: unexpected EOF")
errUnsupportedFileFormat = errors.New("litonlylzma: unsupported FileFormat")
)
@@ -79,13 +88,30 @@ const (
pbMask = (1 << pb) - 1
)
// lzmaHeader5 is the first 5 bytes of the LZMA header using the hard-coded
// configuration for the subset-of-LZMA that this package supports. 0x5D
// encodes the (lc, lp, pb) triple and the next four bytes hold the u32le
// dictionary size. 0x1000 is LZMA's minimum dictionary size, although our
// lzmaHeader5 is the first 5 bytes of an LZMA file using the hard-coded
// configuration for the subset-of-LZMA that this package supports.
//
// 0x5D encodes the (lc, lp, pb) triple and the next four bytes hold the u32le
// dictionary size. 0x00001000 is LZMA's minimum dictionary size, although our
// subset-of-LZMA does not use a dictionary (also called a "sliding window").
const lzmaHeader5 = "\x5D\x00\x10\x00\x00"
// xzHeader24 is the first 24 bytes of an Xz file using the hard-coded
// configuration for the subset-of-Xz that this package supports.
const xzHeader24 = "" +
"\xFD\x37\x7A\x58\x5A\x00" + // Stream Header Magic Bytes.
// ----
"\x00\x01" + // Stream Flags (0x01 means CRC-32).
"\x69\x22\xDE\x36" + // CRC-32 of the previous 2 bytes.
// ----
"\x02" + // Block Header Size (0x02 * 4 = 8 bytes).
"\x00" + // Block Flags.
"\x21" + // Filter ID (0x21 means LZMA2).
"\x01" + // Size of Filter Properties (size of the next line).
"\x00" + // Filter Properties (0x00 means an 0x1000 dictionary size).
"\x00\x00\x00" + // Padding to 4-byte alignment.
"\x37\x27\x97\xD6" // CRC-32 of the previous 8 bytes.
// rangeDecoder and rangeEncoder hold the state for range coding (also known as
// arithmetic coding, roughly speaking). "range" is a keyword in Go, so in this
// implementation, what's traditionally called the "range" fields are called
@@ -120,13 +146,13 @@ const lzmaHeader5 = "\x5D\x00\x10\x00\x00"
// digit is stashed as the pendingHead field. low is set to 8872, width is set
// to (46055 - 38872) = 7183 and we progress until the width drops below 1000,
// causing a 'zoom in' event. There are three cases:
// - if low is less than 9000 (but starts with an '8'), we can emit the '3'
// with confidence (and then stash '8' in the pendingHead field).
// - if low overflows 9999, we can emit the '4' with confidence (and then stash
// low's 'thousands digit' in the pendingHead field).
// - if low is in 9000 ..= 9999 then we could still be unsure. Keep the '3'
// pending but extend it so that there are two pending digits: '39'. If this
// occurs again: '399', and so on.
// - if low is less than 9000 (but starts with an '8'), we can emit the '3'
// with confidence (and then stash '8' in the pendingHead field).
// - if low overflows 9999, we can emit the '4' with confidence (and then
// stash low's 'thousands digit' in the pendingHead field).
// - if low is in 9000 ..= 9999 then we could still be unsure. Keep the '3'
// pending but extend it so that there are two pending digits: '39'. If
// this occurs again: '399', and so on.
//
// In all three cases, 'zooming in' causes us to shift out the most significant
// digit of the low field. This method is therefore named shiftLow here, the
@@ -260,39 +286,39 @@ func (p *prob) encodeBit(rEnc *rangeEncoder, bitValue uint32) {
// byteProbs hold probabilities for coding 8 bits (1 byte) of data. It is a 256
// element array such that:
// - The 0th element is unused.
// - The 1st element holds the probability that the 7th bit (the highest, most
// significant bit) is 0.
// - The 2nd element holds the probability that the 6th bit is 0, conditional
// on the high bit being 0.
// - The 3rd element holds the probability that the 6th bit is 0, conditional
// on the high bit being 1.
// - The 4th element holds the probability that the 5th bit is 0, conditional
// on the high two bits being 00.
// - The 5th element holds the probability that the 5th bit is 0, conditional
// on the high two bits being 01.
// - The 6th element holds the probability that the 5th bit is 0, conditional
// on the high two bits being 10.
// - The 7th element holds the probability that the 5th bit is 0, conditional
// on the high two bits being 11.
// - The 8th element holds the probability that the 4th bit is 0, conditional
// on the high three bits being 000.
// - etc
// - The 255th element holds the probability that the 0th bit (the lowest,
// least significant bit) is 0, conditional on the high seven bits being
// 1111111.
// - The 0th element is unused.
// - The 1st element holds the probability that the 7th bit (the highest, most
// significant bit) is 0.
// - The 2nd element holds the probability that the 6th bit is 0, conditional
// on the high bit being 0.
// - The 3rd element holds the probability that the 6th bit is 0, conditional
// on the high bit being 1.
// - The 4th element holds the probability that the 5th bit is 0, conditional
// on the high two bits being 00.
// - The 5th element holds the probability that the 5th bit is 0, conditional
// on the high two bits being 01.
// - The 6th element holds the probability that the 5th bit is 0, conditional
// on the high two bits being 10.
// - The 7th element holds the probability that the 5th bit is 0, conditional
// on the high two bits being 11.
// - The 8th element holds the probability that the 4th bit is 0, conditional
// on the high three bits being 000.
// - etc
// - The 255th element holds the probability that the 0th bit (the lowest,
// least significant bit) is 0, conditional on the high seven bits being
// 1111111.
//
// Put another way, the 256 elements' value of N, as in "it's a probability for
// the Nth bit", looks like this (when arranged in 8 rows of 32 elements):
//
// u7665555444444443333333333333333
// 22222222222222222222222222222222
// 11111111111111111111111111111111
// 11111111111111111111111111111111
// 00000000000000000000000000000000
// 00000000000000000000000000000000
// 00000000000000000000000000000000
// 00000000000000000000000000000000
// u7665555444444443333333333333333
// 22222222222222222222222222222222
// 11111111111111111111111111111111
// 11111111111111111111111111111111
// 00000000000000000000000000000000
// 00000000000000000000000000000000
// 00000000000000000000000000000000
// 00000000000000000000000000000000
//
// The 'u' means that the 0th element is unused.
type byteProbs [0x100]prob
@@ -320,7 +346,7 @@ func (p *byteProbs) encodeByte(rEnc *rangeEncoder, byteValue byte) {
}
// FileFormat is a compressed file format, either the original LZMA format
// itself or something that builds on or varies that.
// itself or something like Xz that builds on or varies that.
//
// Each valid FileFormatXxx value does not distinguish between the full file
// format (as spoken by numerous Xxx software tools) and the subset-of-Xxx
@@ -328,26 +354,27 @@ func (p *byteProbs) encodeByte(rEnc *rangeEncoder, byteValue byte) {
// produce compressed data that is valid full-LZMA (and is also valid
// subset-of-LZMA). FileFormatLZMA.Decode can decode subset-of-LZMA (but not
// full-LZMA).
//
// This package currently defines only one valid FileFormatXxx value:
// FileFormatLZMA. Future versions of this package could define e.g.
// FileFormatLZMA2 or FileFormatXz such that FileFormatXz.Encode would produce
// valid full-XZ data: a valid XZ file (that could be decoded by official XZ
// tools) that used the LZMA compression filter, but elected not to use the
// full capabilities of that filter (using LZ literals only, not matches).
type FileFormat uint32
const (
FileFormatInvalid = FileFormat(0)
FileFormatLZMA = FileFormat(1)
FileFormatXz = FileFormat(2)
)
// Decode converts src from the Literal Only LZMA compressed file format,
func (f FileFormat) String() string {
switch f {
case FileFormatLZMA:
return "FileFormatLZMA"
case FileFormatXz:
return "FileFormatXz"
}
return "FileFormatInvalid"
}
// Decode converts src from the Literal Only LZMA/Xz compressed file format,
// appending the decoding to dst.
//
// f should be FileFormatLZMA but future versions of this package may support
// other file formats.
//
// It is valid to pass a nil dst, like the way it's valid to pass nil to the
// built-in append function.
//
@@ -356,14 +383,19 @@ const (
// It can also return partial results. The appendedDst and remainingSrc return
// values may be non-zero even if retErr is non-zero.
//
// It returns ErrUnsupportedLZMAData if the source bytes look like LZMA
// formatted data that is outside the subset-of-LZMA that this package
// implements.
// It returns ErrUnsupportedXxxData if the source bytes look like Xxx formatted
// data that is outside the subset-of-Xxx that this package implements.
func (f FileFormat) Decode(dst []byte, src []byte) (appendedDst []byte, remainingSrc []byte, retErr error) {
if f != FileFormatLZMA {
return dst, nil, errUnsupportedFileFormat
switch f {
case FileFormatLZMA:
return decodeLZMA(dst, src)
case FileFormatXz:
return decodeXz(dst, src)
}
return nil, nil, errUnsupportedFileFormat
}
func decodeLZMA(dst []byte, src []byte) (appendedDst []byte, remainingSrc []byte, retErr error) {
// LZMA consists of a 13 byte header and then at least a 5 byte payload
// (range coded data). The 13 byte header is:
// - 1 byte for the (lc, lp, pb) triple with max values (8, 4, 4),
@@ -371,12 +403,7 @@ func (f FileFormat) Decode(dst []byte, src []byte) (appendedDst []byte, remainin
// - 8 bytes i64le uncompressed size.
if (len(src) < 18) || (src[0] >= (9 * 5 * 5)) {
return dst, nil, errInvalidLZMAData
} else if (src[0] != lzmaHeader5[0]) ||
(src[1] != lzmaHeader5[1]) ||
(src[2] != lzmaHeader5[2]) ||
(src[3] != lzmaHeader5[3]) ||
(src[4] != lzmaHeader5[4]) ||
(src[13] != 0x00) {
} else if string(src[:5]) != lzmaHeader5 {
return dst, nil, ErrUnsupportedLZMAData
}
@@ -390,12 +417,151 @@ func (f FileFormat) Decode(dst []byte, src []byte) (appendedDst []byte, remainin
return dst, nil, ErrUnsupportedLZMAData
}
return decodeRaw(dst, src[13:], size, ErrUnsupportedLZMAData)
}
func decodeXz(dst []byte, src []byte) (appendedDst []byte, remainingSrc []byte, retErr error) {
originalDstLen := len(dst)
originalSrcLen := len(src)
// Decode the headers.
if (len(src) < 24) || (string(src[:6]) != xzHeader24[:6]) {
return dst, src, errInvalidXzData
} else if string(src[6:24]) != xzHeader24[6:24] {
return dst, src, ErrUnsupportedXzData
}
src = src[24:]
// Decode the payload as multiple chunks.
for {
if len(src) == 0 {
return dst, src, errInvalidXzData
} else if src[0] == 0x00 { // No more chunks.
src = src[1:]
break
} else if src[0] == 0x01 { // Independent uncompressed chunk.
if len(src) < 3 {
return dst, src, errInvalidXzData
}
uncompressedSize := (uint32(src[1]) << 8) + (uint32(src[2]) << 0) + 1
src = src[3:]
if uint64(uncompressedSize) > uint64(len(src)) {
return dst, src, errInvalidXzData
}
dst = append(dst, src[:uncompressedSize]...)
src = src[uncompressedSize:]
} else if src[0] == 0xE0 { // Independent LZMA chunk.
if len(src) < 6 {
return dst, src, errInvalidXzData
} else if src[5] != 0x5D { // Like lzmaHeader5[0], this encodes lc=3, lp=0, pb=2.
return dst, src, ErrUnsupportedXzData
}
uncompressedSize := (uint32(src[1]) << 8) + (uint32(src[2]) << 0) + 1
compressedSize := (uint32(src[3]) << 8) + (uint32(src[4]) << 0) + 1
src = src[6:]
if uint64(compressedSize) > uint64(len(src)) {
return dst, src, errInvalidXzData
}
lenSrc := len(src)
dst, src, retErr = decodeRaw(dst, src, uint64(uncompressedSize), ErrUnsupportedXzData)
if retErr != nil {
return dst, src, retErr
} else if lenSrc != (len(src) + int(compressedSize)) {
return dst, src, errInvalidXzData
}
} else {
return dst, src, ErrUnsupportedXzData
}
}
unpaddedSizeWant := uint64((originalSrcLen - 12) - len(src) + 4)
for i := unpaddedSizeWant & 3; (i & 3) != 0; i++ {
if (len(src) == 0) || (src[0] != 0x00) {
return dst, src, errInvalidXzData
}
src = src[1:]
}
if len(src) < 4 {
return dst, src, errInvalidXzData
}
checksum := crc32.ChecksumIEEE(dst[originalDstLen:])
if (src[0] != uint8(checksum>>0)) ||
(src[1] != uint8(checksum>>8)) ||
(src[2] != uint8(checksum>>16)) ||
(src[3] != uint8(checksum>>24)) {
return dst, src, errInvalidXzData
}
src = src[4:]
// Decode the index.
srcCheckpoint1 := src
if (len(src) < 2) || (src[0] != 0x00) || (src[1] != 0x01) {
return dst, src, errInvalidXzData
}
src = src[2:]
src, unpaddedSizeHave, ok := decodeUvarint(src)
if !ok || (unpaddedSizeHave != unpaddedSizeWant) {
return dst, src, errInvalidXzData
}
src, uncompressedSize, ok := decodeUvarint(src)
if !ok || (uncompressedSize != uint64(len(dst)-originalDstLen)) {
return dst, src, errInvalidXzData
}
for i := (len(srcCheckpoint1) - len(src)) & 3; (i & 3) != 0; i++ {
if (len(src) == 0) || (src[0] != 0x00) {
return dst, src, errInvalidXzData
}
src = src[1:]
}
backwardSize := (len(srcCheckpoint1) - len(src)) >> 2
if len(src) < 4 {
return dst, src, errInvalidXzData
}
checksum = crc32.ChecksumIEEE(srcCheckpoint1[:len(srcCheckpoint1)-len(src)])
if (src[0] != uint8(checksum>>0)) ||
(src[1] != uint8(checksum>>8)) ||
(src[2] != uint8(checksum>>16)) ||
(src[3] != uint8(checksum>>24)) {
return dst, src, errInvalidXzData
}
src = src[4:]
// Decode the footer.
if len(src) < 12 {
return dst, src, errInvalidXzData
}
checksum = crc32.ChecksumIEEE(src[4:10])
if (src[0] != uint8(checksum>>0)) || // Checksum.
(src[1] != uint8(checksum>>8)) ||
(src[2] != uint8(checksum>>16)) ||
(src[3] != uint8(checksum>>24)) ||
(src[4] != uint8(backwardSize>>0)) || // Backward Size.
(src[5] != uint8(backwardSize>>8)) ||
(src[6] != uint8(backwardSize>>16)) ||
(src[7] != uint8(backwardSize>>24)) ||
(src[8] != xzHeader24[6]) || // Stream Flags again.
(src[9] != xzHeader24[7]) ||
(src[10] != 0x59) || // Stream Footer Magic Bytes.
(src[11] != 0x5A) {
return dst, src, errInvalidXzData
}
return dst, src[12:], nil
}
func decodeRaw(dst []byte, src []byte, size uint64, errUnsupported error) (appendedDst []byte, remainingSrc []byte, retErr error) {
if (len(src) < 5) || (src[0] != 0x00) {
return dst, src, errUnsupported
}
rDec := rangeDecoder{
src: src[18:],
bits: (uint32(src[14]) << 24) |
(uint32(src[15]) << 16) |
(uint32(src[16]) << 8) |
(uint32(src[17]) << 0),
src: src[5:],
bits: (uint32(src[1]) << 24) |
(uint32(src[2]) << 16) |
(uint32(src[3]) << 8) |
(uint32(src[4]) << 0),
width: 0xFFFF_FFFF,
}
@@ -412,12 +578,12 @@ func (f FileFormat) Decode(dst []byte, src []byte) (appendedDst []byte, remainin
curr := byte(0)
for ; size > 0; size-- {
if bitValue, err := posProbs[pos&pbMask].decodeBit(&rDec); err != nil {
return dst, nil, err
return dst, rDec.src, err
} else if bitValue != 0 {
// A full-LZMA decoder would implement Lempel Ziv matches (or the
// End of Stream marker) here. Our simpler subset-of-LZMA decoder
// only uses literals.
return dst, rDec.src, ErrUnsupportedLZMAData
return dst, rDec.src, errUnsupported
}
i := (pos & lpMask) << lc
@@ -433,26 +599,141 @@ func (f FileFormat) Decode(dst []byte, src []byte) (appendedDst []byte, remainin
return dst, rDec.src, nil
}
func decodeUvarint(src []byte) (remainingSrc []byte, x uint64, ok bool) {
for i := uint32(0); (i < 63) && (len(src) > 0); i += 7 {
s := src[0]
src = src[1:]
x |= uint64(s&0x7F) << i
if (s & 0x80) == 0 {
return src, x, true
}
}
return src, 0, false
}
// Encode converts src to the Literal Only LZMA compressed file format,
// appending the encoding to dst.
//
// f should be FileFormatLZMA but future versions of this package may support
// other file formats.
//
// It is valid to pass a nil dst, like the way it's valid to pass nil to the
// built-in append function.
func (f FileFormat) Encode(dst []byte, src []byte) (appendedDst []byte, retErr error) {
if f != FileFormatLZMA {
return nil, errUnsupportedFileFormat
switch f {
case FileFormatLZMA:
return encodeLZMA(dst, src)
case FileFormatXz:
return encodeXz(dst, src)
}
return nil, errUnsupportedFileFormat
}
func encodeLZMA(dst []byte, src []byte) (appendedDst []byte, retErr error) {
dst = append(dst, lzmaHeader5...)
size := len(src)
for i := 0; i < 8; i++ {
dst = append(dst, byte(size))
size >>= 8
}
return encodeRaw(dst, src), nil
}
func encodeXz(dst []byte, src []byte) (appendedDst []byte, retErr error) {
// Encode the headers (12 byte stream header then 12 byte block header).
// The block's unpaddedSize calculation ignores the stream header.
dstLen0 := len(dst) + 12
dst = append(dst, xzHeader24...)
// Encode the payload as multiple chunks.
//
// Later XZ chunks can depend on earlier ones (and doing so can help
// compression ratios) but for simplicity, this encoder emits independent
// chunks. Each chunk's maximum compressed and uncompressed size are both
// equal to 0x10000 = 65536 bytes, roughly speaking. The encoder partitions
// the src into 65536 byte sub-slices. If a sub-slice's LZMA-compressed
// form would be longer, the encoder emits an uncompressed chunk instead.
rawLZMA := []byte(nil)
for remaining := src; len(remaining) > 0; {
srcChunk := []byte(nil)
if len(remaining) > 0x10000 {
srcChunk, remaining = remaining[:0x10000], remaining[0x10000:]
} else {
srcChunk, remaining = remaining, nil
}
rawLZMA = encodeRaw(rawLZMA[:0], srcChunk)
if (len(srcChunk) + 3) <= (len(rawLZMA) + 6) {
dst = append(dst,
0x01, // Independent uncompressed chunk.
uint8((len(srcChunk)-1)>>8),
uint8((len(srcChunk)-1)>>0),
)
dst = append(dst, srcChunk...)
} else {
dst = append(dst,
0xE0, // Independent LZMA chunk.
uint8((len(srcChunk)-1)>>8),
uint8((len(srcChunk)-1)>>0),
uint8((len(rawLZMA)-1)>>8),
uint8((len(rawLZMA)-1)>>0),
0x5D, // Like lzmaHeader5[0], this encodes lc=3, lp=0, pb=2.
)
dst = append(dst, rawLZMA...)
}
}
dst = append(dst, 0x00) // No more chunks.
unpaddedSize := uint64(len(dst)-dstLen0) + 4 // +4 for the upcoming checksum.
for 0 != 3&(len(dst)-dstLen0) {
dst = append(dst, 0x00) // Padding
}
checksum := crc32.ChecksumIEEE(src)
dst = append(dst,
uint8(checksum>>0),
uint8(checksum>>8),
uint8(checksum>>16),
uint8(checksum>>24),
)
// Encode the index.
dstLen1 := len(dst)
dst = append(dst,
0x00, // Index Indicator.
0x01, // Number of Records.
)
dst = encodeUvarint(dst, unpaddedSize)
dst = encodeUvarint(dst, uint64(len(src)))
for 0 != 3&(len(dst)-dstLen1) {
dst = append(dst, 0x00) // Padding
}
backwardSize := (len(dst) - dstLen1) >> 2
checksum = crc32.ChecksumIEEE(dst[dstLen1:])
dst = append(dst,
uint8(checksum>>0),
uint8(checksum>>8),
uint8(checksum>>16),
uint8(checksum>>24),
)
// Encode the footer.
dstLen2 := len(dst)
dst = append(dst,
0, 0, 0, 0, // Space for the checksum.
uint8(backwardSize>>0), // Backward Size.
uint8(backwardSize>>8),
uint8(backwardSize>>16),
uint8(backwardSize>>24),
xzHeader24[6], // Stream Flags again.
xzHeader24[7],
0x59, // Stream Footer Magic Bytes.
0x5A,
)
checksum = crc32.ChecksumIEEE(dst[dstLen2+4 : dstLen2+10])
dst[dstLen2+0] = uint8(checksum >> 0)
dst[dstLen2+1] = uint8(checksum >> 8)
dst[dstLen2+2] = uint8(checksum >> 16)
dst[dstLen2+3] = uint8(checksum >> 24)
return dst, nil
}
func encodeRaw(dst []byte, src []byte) (appendedDst []byte) {
rEnc := rangeEncoder{
dst: dst,
width: 0xFFFF_FFFF,
@@ -487,5 +768,12 @@ func (f FileFormat) Encode(dst []byte, src []byte) (appendedDst []byte, retErr e
rEnc.shiftLow()
}
return rEnc.dst, nil
return rEnc.dst
}
func encodeUvarint(dst []byte, x uint64) []byte {
for ; x >= 0x80; x >>= 7 {
dst = append(dst, byte(x)|0x80)
}
return append(dst, byte(x))
}
+16 -9
View File
@@ -43,16 +43,23 @@ func testRoundTrip(tt *testing.T, filename string) {
original = o
}
compressed, err := FileFormatLZMA.Encode(nil, original)
if err != nil {
tt.Fatalf("Encode: %v", err)
fileFormats := [...]FileFormat{
FileFormatLZMA,
FileFormatXz,
}
recovered, _, err := FileFormatLZMA.Decode(nil, compressed)
if err != nil {
tt.Fatalf("Decode: %v", err)
}
if !bytes.Equal(original, recovered) {
tt.Fatalf("round trip produced different bytes")
for _, f := range fileFormats {
compressed, err := f.Encode(nil, original)
if err != nil {
tt.Fatalf("%v.Encode: %v", f, err)
}
recovered, _, err := f.Decode(nil, compressed)
if err != nil {
tt.Fatalf("%v.Decode: %v", f, err)
}
if !bytes.Equal(original, recovered) {
tt.Fatalf("%v: round trip produced different bytes", f)
}
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ import (
"github.com/google/wuffs/lib/zlibcut"
)
func ExampleCut() {
func Example() {
const sonnet18 = "" +
"Shall I compare thee to a summer’s day?\n" +
"Thou art more lovely and more temperate.\n" +
+2240 -694
View File
@@ -6344,6 +6344,8 @@ struct wuffs_base__token_decoder__struct {
} // extern "C"
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ADLER32) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
// ---------------- Public Consts
@@ -6526,10 +6528,15 @@ struct wuffs_adler32__hasher__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ADLER32) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_bmp__error__bad_header[];
extern const char wuffs_bmp__error__bad_rle_compression[];
extern const char wuffs_bmp__error__truncated_input[];
extern const char wuffs_bmp__error__unsupported_bmp_file[];
// ---------------- Public Consts
@@ -6708,8 +6715,12 @@ struct wuffs_bmp__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
uint32_t p_tell_me_more[1];
uint32_t p_read_palette[1];
} private_impl;
@@ -6719,10 +6730,10 @@ struct wuffs_bmp__decoder__struct {
struct {
uint64_t scratch;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
struct {
uint64_t scratch;
} s_decode_frame[1];
} s_do_decode_frame[1];
struct {
uint32_t v_i;
uint64_t scratch;
@@ -6874,6 +6885,10 @@ struct wuffs_bmp__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_bzip2__error__bad_huffman_code_over_subscribed[];
@@ -6883,6 +6898,7 @@ extern const char wuffs_bzip2__error__bad_block_length[];
extern const char wuffs_bzip2__error__bad_checksum[];
extern const char wuffs_bzip2__error__bad_header[];
extern const char wuffs_bzip2__error__bad_number_of_sections[];
extern const char wuffs_bzip2__error__truncated_input[];
extern const char wuffs_bzip2__error__unsupported_block_randomization[];
// ---------------- Public Consts
@@ -7008,6 +7024,7 @@ struct wuffs_bzip2__decoder__struct {
uint32_t f_code_lengths_bitmask;
uint32_t p_transform_io[1];
uint32_t p_do_transform_io[1];
uint32_t p_prepare_block[1];
uint32_t p_read_code_lengths[1];
uint32_t p_flush_slow[1];
@@ -7028,7 +7045,7 @@ struct wuffs_bzip2__decoder__struct {
uint32_t v_i;
uint64_t v_tag;
uint32_t v_final_checksum_want;
} s_transform_io[1];
} s_do_transform_io[1];
struct {
uint32_t v_i;
uint32_t v_selector;
@@ -7138,6 +7155,10 @@ struct wuffs_bzip2__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CBOR) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_cbor__error__bad_input[];
@@ -7363,6 +7384,10 @@ struct wuffs_cbor__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CBOR) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC32) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
// ---------------- Public Consts
@@ -7544,6 +7569,10 @@ struct wuffs_crc32__ieee_hasher__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC32) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_deflate__error__bad_huffman_code_over_subscribed[];
@@ -7559,6 +7588,7 @@ extern const char wuffs_deflate__error__bad_literal_length_code_count[];
extern const char wuffs_deflate__error__inconsistent_stored_block_length[];
extern const char wuffs_deflate__error__missing_end_of_block_code[];
extern const char wuffs_deflate__error__no_huffman_codes[];
extern const char wuffs_deflate__error__truncated_input[];
// ---------------- Public Consts
@@ -7673,6 +7703,7 @@ struct wuffs_deflate__decoder__struct {
bool f_end_of_block;
uint32_t p_transform_io[1];
uint32_t p_do_transform_io[1];
uint32_t p_decode_blocks[1];
uint32_t p_decode_uncompressed[1];
uint32_t p_init_dynamic_huffman[1];
@@ -7814,9 +7845,14 @@ struct wuffs_deflate__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__LZW) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_lzw__error__bad_code[];
extern const char wuffs_lzw__error__truncated_input[];
// ---------------- Public Consts
@@ -8049,6 +8085,10 @@ struct wuffs_lzw__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__LZW) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_gif__error__bad_extension_label[];
@@ -8057,6 +8097,7 @@ extern const char wuffs_gif__error__bad_graphic_control[];
extern const char wuffs_gif__error__bad_header[];
extern const char wuffs_gif__error__bad_literal_width[];
extern const char wuffs_gif__error__bad_palette[];
extern const char wuffs_gif__error__truncated_input[];
// ---------------- Public Consts
@@ -8257,10 +8298,14 @@ struct wuffs_gif__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_tell_me_more[1];
uint32_t p_do_tell_me_more[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_skip_frame[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
uint32_t p_decode_up_to_id_part1[1];
uint32_t p_decode_header[1];
uint32_t p_decode_lsd[1];
@@ -8281,7 +8326,7 @@ struct wuffs_gif__decoder__struct {
struct {
uint32_t v_background_color;
} s_decode_frame_config[1];
} s_do_decode_frame_config[1];
struct {
uint64_t scratch;
} s_skip_frame[1];
@@ -8471,12 +8516,17 @@ struct wuffs_gif__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GZIP) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_gzip__error__bad_checksum[];
extern const char wuffs_gzip__error__bad_compression_method[];
extern const char wuffs_gzip__error__bad_encoding_flags[];
extern const char wuffs_gzip__error__bad_header[];
extern const char wuffs_gzip__error__truncated_input[];
// ---------------- Public Consts
@@ -8581,6 +8631,7 @@ struct wuffs_gzip__decoder__struct {
bool f_ignore_checksum;
uint32_t p_transform_io[1];
uint32_t p_do_transform_io[1];
} private_impl;
struct {
@@ -8593,7 +8644,7 @@ struct wuffs_gzip__decoder__struct {
uint32_t v_decoded_length_got;
uint32_t v_checksum_want;
uint64_t scratch;
} s_transform_io[1];
} s_do_transform_io[1];
} private_data;
#ifdef __cplusplus
@@ -8683,6 +8734,10 @@ struct wuffs_gzip__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GZIP) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JSON) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_json__error__bad_c0_control_code[];
@@ -8951,9 +9006,14 @@ struct wuffs_json__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JSON) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_nie__error__bad_header[];
extern const char wuffs_nie__error__truncated_input[];
extern const char wuffs_nie__error__unsupported_nie_file[];
// ---------------- Public Consts
@@ -9114,14 +9174,17 @@ struct wuffs_nie__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
} private_impl;
struct {
struct {
uint64_t scratch;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
} private_data;
#ifdef __cplusplus
@@ -9269,6 +9332,10 @@ struct wuffs_nie__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ZLIB) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_zlib__note__dictionary_required[];
@@ -9277,6 +9344,7 @@ extern const char wuffs_zlib__error__bad_compression_method[];
extern const char wuffs_zlib__error__bad_compression_window_size[];
extern const char wuffs_zlib__error__bad_parity_check[];
extern const char wuffs_zlib__error__incorrect_dictionary[];
extern const char wuffs_zlib__error__truncated_input[];
// ---------------- Public Consts
@@ -9399,6 +9467,7 @@ struct wuffs_zlib__decoder__struct {
uint32_t f_dict_id_want;
uint32_t p_transform_io[1];
uint32_t p_do_transform_io[1];
} private_impl;
struct {
@@ -9409,7 +9478,7 @@ struct wuffs_zlib__decoder__struct {
struct {
uint32_t v_checksum_got;
uint64_t scratch;
} s_transform_io[1];
} s_do_transform_io[1];
} private_data;
#ifdef __cplusplus
@@ -9510,6 +9579,10 @@ struct wuffs_zlib__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ZLIB) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_png__error__bad_animation_sequence_number[];
@@ -9519,6 +9592,7 @@ extern const char wuffs_png__error__bad_filter[];
extern const char wuffs_png__error__bad_header[];
extern const char wuffs_png__error__bad_text_chunk_not_latin_1[];
extern const char wuffs_png__error__missing_palette[];
extern const char wuffs_png__error__truncated_input[];
extern const char wuffs_png__error__unsupported_cgbi_extension[];
extern const char wuffs_png__error__unsupported_png_compression_method[];
extern const char wuffs_png__error__unsupported_png_file[];
@@ -9755,6 +9829,7 @@ struct wuffs_png__decoder__struct {
wuffs_base__slice_u8 a_curr,
wuffs_base__slice_u8 a_prev);
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_ihdr[1];
uint32_t p_decode_other_chunk[1];
uint32_t p_decode_actl[1];
@@ -9766,10 +9841,13 @@ struct wuffs_png__decoder__struct {
uint32_t p_decode_srgb[1];
uint32_t p_decode_trns[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_skip_frame[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
uint32_t p_decode_pass[1];
uint32_t p_tell_me_more[1];
uint32_t p_do_tell_me_more[1];
wuffs_base__status (*choosy_filter_and_swizzle)(
wuffs_png__decoder* self,
wuffs_base__pixel_buffer* a_dst,
@@ -9785,7 +9863,7 @@ struct wuffs_png__decoder__struct {
struct {
uint32_t v_checksum_have;
uint64_t scratch;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
struct {
uint64_t scratch;
} s_decode_ihdr[1];
@@ -9819,20 +9897,20 @@ struct wuffs_png__decoder__struct {
} s_decode_trns[1];
struct {
uint64_t scratch;
} s_decode_frame_config[1];
} s_do_decode_frame_config[1];
struct {
uint64_t scratch;
} s_skip_frame[1];
struct {
uint64_t scratch;
} s_decode_frame[1];
} s_do_decode_frame[1];
struct {
uint64_t scratch;
} s_decode_pass[1];
struct {
wuffs_base__status v_zlib_status;
uint64_t scratch;
} s_tell_me_more[1];
} s_do_tell_me_more[1];
} private_data;
#ifdef __cplusplus
@@ -9980,10 +10058,15 @@ struct wuffs_png__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_tga__error__bad_header[];
extern const char wuffs_tga__error__bad_run_length_encoding[];
extern const char wuffs_tga__error__truncated_input[];
extern const char wuffs_tga__error__unsupported_tga_file[];
// ---------------- Public Consts
@@ -10154,8 +10237,11 @@ struct wuffs_tga__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
} private_impl;
struct {
@@ -10166,7 +10252,7 @@ struct wuffs_tga__decoder__struct {
struct {
uint32_t v_i;
uint64_t scratch;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
struct {
uint64_t v_dst_bytes_per_pixel;
uint32_t v_dst_x;
@@ -10177,7 +10263,7 @@ struct wuffs_tga__decoder__struct {
uint32_t v_run_length;
uint64_t v_num_dst_bytes;
uint64_t scratch;
} s_decode_frame[1];
} s_do_decode_frame[1];
} private_data;
#ifdef __cplusplus
@@ -10325,9 +10411,14 @@ struct wuffs_tga__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_wbmp__error__bad_header[];
extern const char wuffs_wbmp__error__truncated_input[];
// ---------------- Public Consts
@@ -10485,22 +10576,25 @@ struct wuffs_wbmp__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
} private_impl;
struct {
struct {
uint32_t v_i;
uint32_t v_x32;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
struct {
uint64_t v_dst_bytes_per_pixel;
uint32_t v_dst_x;
uint32_t v_dst_y;
uint8_t v_src[1];
uint8_t v_c;
} s_decode_frame[1];
} s_do_decode_frame[1];
} private_data;
#ifdef __cplusplus
@@ -10648,6 +10742,8 @@ struct wuffs_wbmp__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP) || defined(WUFFS_NONMONOLITHIC)
#if defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
// ---------------- Auxiliary - Base
@@ -13697,14 +13793,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
uint8_t* q = s.ptr + s.len;
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
// Parse sign.
do {
@@ -13717,14 +13811,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
break;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
} while (0);
// Parse digits, up to (and including) a '.', 'E' or 'e'. Examples for each
@@ -13776,9 +13868,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
h->digits[nd++] = (uint8_t)(*p - '0');
dp = (int32_t)nd;
} else if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
} else {
dp++;
if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
}
}
} else if (*p ==
((options &
@@ -13838,14 +13933,12 @@ after_sep:
after_exp:
do {
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
int32_t exp_sign = +1;
if (*p == '+') {
@@ -14685,6 +14778,27 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// powers converts decimal powers of 10 to binary powers of 2. For example,
// (10000 >> 13) is 1. It stops before the elements exceed 60, also known
// as WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
//
// This rounds down (1<<13 is a lower bound for 1e4). Adding 1 to the array
// element value rounds up (1<<14 is an upper bound for 1e4) while staying
// at or below WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
//
// When starting in the range [1e+1 .. 1e+2] (i.e. h->decimal_point == +2),
// powers[2] == 6 and so:
// - Right shifting by 6+0 produces the range [10/64 .. 100/64] =
// [0.156250 .. 1.56250]. The resultant h->decimal_point is +0 or +1.
// - Right shifting by 6+1 produces the range [10/128 .. 100/128] =
// [0.078125 .. 0.78125]. The resultant h->decimal_point is -1 or -0.
//
// When starting in the range [1e-3 .. 1e-2] (i.e. h->decimal_point == -2),
// powers[2] == 6 and so:
// - Left shifting by 6+0 produces the range [0.001*64 .. 0.01*64] =
// [0.064 .. 0.64]. The resultant h->decimal_point is -1 or -0.
// - Left shifting by 6+1 produces the range [0.001*128 .. 0.01*128] =
// [0.128 .. 1.28]. The resultant h->decimal_point is +0 or +1.
//
// Thus, when targeting h->decimal_point being +0 or +1, use (powers[n]+0)
// when right shifting but (powers[n]+1) when left shifting.
static const uint32_t num_powers = 19;
static const uint8_t powers[19] = {
0, 3, 6, 9, 13, 16, 19, 23, 26, 29, //
@@ -14704,36 +14818,54 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
// for the common cases (e.g. assuming no underscores or a leading '+'
// sign) rather than the full set of cases allowed by the Wuffs API.
if (h->num_digits <= 19) {
//
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
// for an exact result). When we have more than 19 mantissa digits, run it
// twice to get a lower and upper bound. We still have an exact result
// (within f64's rounding margin) if both bounds are equal (and valid).
uint32_t i_max = h->num_digits;
if (i_max > 19) {
i_max = 19;
}
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
if ((-307 <= exp10) && (exp10 <= 288)) {
uint64_t man = 0;
uint32_t i;
for (i = 0; i < h->num_digits; i++) {
for (i = 0; i < i_max; i++) {
man = (10 * man) + h->digits[i];
}
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
int64_t r =
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
int64_t r0 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man, exp10);
if (r >= 0) {
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
return ret;
man + 0, exp10);
if (r0 < 0) {
break;
} else if (h->num_digits > 19) {
int64_t r1 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man + 1, exp10);
if (r1 != r0) {
break;
}
}
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
return ret;
}
}
// When Eisel-Lemire fails, fall back to Simple Decimal Conversion. See
// https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
//
// Scale by powers of 2 until we're in the range [½ .. 1], which gives us
// our exponent (in base-2). First we shift right, possibly a little too
// far, ending with a value certainly below 1 and possibly below ½...
// Scale by powers of 2 until we're in the range [0.1 .. 10]. Equivalently,
// that h->decimal_point is +0 or +1.
//
// First we shift right while at or above 10...
const int32_t f64_bias = -1023;
int32_t exp2 = 0;
while (h->decimal_point > 0) {
while (h->decimal_point > 1) {
uint32_t n = (uint32_t)(+h->decimal_point);
uint32_t shift =
(n < num_powers)
@@ -14747,20 +14879,15 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
}
exp2 += (int32_t)shift;
}
// ...then we shift left, putting us in [½ .. 1].
while (h->decimal_point <= 0) {
// ...then we shift left while below 0.1.
while (h->decimal_point < 0) {
uint32_t shift;
if (h->decimal_point == 0) {
if (h->digits[0] >= 5) {
break;
}
shift = (h->digits[0] < 2) ? 2 : 1;
} else {
uint32_t n = (uint32_t)(-h->decimal_point);
shift = (n < num_powers)
? powers[n]
: WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
}
uint32_t n = (uint32_t)(-h->decimal_point);
shift = (n < num_powers)
// The +1 is per "when targeting h->decimal_point being +0 or
// +1... when left shifting" in the powers comment above.
? (powers[n] + 1)
: WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
wuffs_base__private_implementation__high_prec_dec__small_lshift(h, shift);
if (h->decimal_point >
@@ -14770,8 +14897,37 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
exp2 -= (int32_t)shift;
}
// We're in the range [½ .. 1] but f64 uses [1 .. 2].
exp2--;
// To get from "in the range [0.1 .. 10]" to "in the range [1 .. 2]" (which
// will give us our exponent in base-2), the mantissa's first 3 digits will
// determine the final left shift, equal to 52 (the number of explicit f64
// bits) plus an additional adjustment.
int man3 = (100 * h->digits[0]) +
((h->num_digits > 1) ? (10 * h->digits[1]) : 0) +
((h->num_digits > 2) ? h->digits[2] : 0);
int32_t additional_lshift = 0;
if (h->decimal_point == 0) { // The value is in [0.1 .. 1].
if (man3 < 125) {
additional_lshift = +4;
} else if (man3 < 250) {
additional_lshift = +3;
} else if (man3 < 500) {
additional_lshift = +2;
} else {
additional_lshift = +1;
}
} else { // The value is in [1 .. 10].
if (man3 < 200) {
additional_lshift = -0;
} else if (man3 < 400) {
additional_lshift = -1;
} else if (man3 < 800) {
additional_lshift = -2;
} else {
additional_lshift = -3;
}
}
exp2 -= additional_lshift;
uint32_t final_lshift = (uint32_t)(52 + additional_lshift);
// The minimum normal exponent is (f64_bias + 1).
while ((f64_bias + 1) > exp2) {
@@ -14789,7 +14945,8 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
}
// Extract 53 bits for the mantissa (in base-2).
wuffs_base__private_implementation__high_prec_dec__small_lshift(h, 53);
wuffs_base__private_implementation__high_prec_dec__small_lshift(
h, final_lshift);
uint64_t man2 =
wuffs_base__private_implementation__high_prec_dec__rounded_integer(h);
@@ -15590,6 +15747,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto hexadecimal;
}
goto fail_bad_argument;
} else if ((*p == 'd') || (*p == 'D')) {
p++;
@@ -15600,6 +15758,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto decimal;
}
goto fail_bad_argument;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
@@ -22472,6 +22631,7 @@ wuffs_adler32__hasher__up_x86_sse42(
const char wuffs_bmp__error__bad_header[] = "#bmp: bad header";
const char wuffs_bmp__error__bad_rle_compression[] = "#bmp: bad RLE compression";
const char wuffs_bmp__error__truncated_input[] = "#bmp: truncated input";
const char wuffs_bmp__error__unsupported_bmp_file[] = "#bmp: unsupported BMP file";
const char wuffs_bmp__note__internal_note_short_read[] = "@bmp: internal note: short read";
@@ -22509,6 +22669,27 @@ const char wuffs_bmp__note__internal_note_short_read[] = "@bmp: internal note: s
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_bmp__decoder__do_decode_image_config(
wuffs_bmp__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bmp__decoder__do_decode_frame_config(
wuffs_bmp__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bmp__decoder__do_decode_frame(
wuffs_bmp__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
static wuffs_base__status
wuffs_bmp__decoder__swizzle_none(
wuffs_bmp__decoder* self,
@@ -22533,6 +22714,13 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bmp__decoder__do_tell_me_more(
wuffs_bmp__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bmp__decoder__read_palette(
wuffs_bmp__decoder* self,
@@ -22687,6 +22875,52 @@ wuffs_bmp__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bmp__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bmp.decoder.do_decode_image_config
static wuffs_base__status
wuffs_bmp__decoder__do_decode_image_config(
wuffs_bmp__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_magic = 0;
uint32_t v_width = 0;
uint32_t v_height = 0;
@@ -22698,14 +22932,14 @@ wuffs_bmp__decoder__decode_image_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -22723,14 +22957,14 @@ wuffs_bmp__decoder__decode_image_config(
t_0 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22749,15 +22983,15 @@ wuffs_bmp__decoder__decode_image_config(
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
goto exit;
}
self->private_data.s_decode_image_config[0].scratch = 8;
self->private_data.s_do_decode_image_config[0].scratch = 8;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
uint32_t t_1;
@@ -22765,14 +22999,14 @@ wuffs_bmp__decoder__decode_image_config(
t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22800,14 +23034,14 @@ wuffs_bmp__decoder__decode_image_config(
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22835,14 +23069,14 @@ wuffs_bmp__decoder__decode_image_config(
t_3 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22864,14 +23098,14 @@ wuffs_bmp__decoder__decode_image_config(
t_4 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22893,14 +23127,14 @@ wuffs_bmp__decoder__decode_image_config(
t_5 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22926,14 +23160,14 @@ wuffs_bmp__decoder__decode_image_config(
t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_6 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22956,14 +23190,14 @@ wuffs_bmp__decoder__decode_image_config(
t_7 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_7 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22990,14 +23224,14 @@ wuffs_bmp__decoder__decode_image_config(
t_8 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_8 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23024,14 +23258,14 @@ wuffs_bmp__decoder__decode_image_config(
t_9 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(21);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_9 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23057,14 +23291,14 @@ wuffs_bmp__decoder__decode_image_config(
t_10 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(23);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_10 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23087,14 +23321,14 @@ wuffs_bmp__decoder__decode_image_config(
t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(25);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_11 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23121,14 +23355,14 @@ wuffs_bmp__decoder__decode_image_config(
t_12 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(27);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_12 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23159,14 +23393,14 @@ wuffs_bmp__decoder__decode_image_config(
t_13 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(29);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_13 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23192,14 +23426,14 @@ wuffs_bmp__decoder__decode_image_config(
t_14 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(31);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_14 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23221,14 +23455,14 @@ wuffs_bmp__decoder__decode_image_config(
t_15 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(33);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_15 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23256,15 +23490,15 @@ wuffs_bmp__decoder__decode_image_config(
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
self->private_data.s_decode_image_config[0].scratch = 20;
self->private_data.s_do_decode_image_config[0].scratch = 20;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(34);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
if (self->private_impl.f_bitmap_info_len == 40) {
if (self->private_impl.f_bits_per_pixel >= 16) {
if (self->private_impl.f_padding >= 16) {
@@ -23295,14 +23529,14 @@ wuffs_bmp__decoder__decode_image_config(
t_16 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(36);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_16 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23324,14 +23558,14 @@ wuffs_bmp__decoder__decode_image_config(
t_17 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(38);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_17 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23353,14 +23587,14 @@ wuffs_bmp__decoder__decode_image_config(
t_18 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(40);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_18 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23383,14 +23617,14 @@ wuffs_bmp__decoder__decode_image_config(
t_19 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(42);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_19 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23405,15 +23639,15 @@ wuffs_bmp__decoder__decode_image_config(
}
self->private_impl.f_channel_masks[3] = t_19;
}
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_bitmap_info_len - 56));
self->private_data.s_do_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_bitmap_info_len - 56));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(43);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
}
if ((self->private_impl.f_channel_masks[0] == 255) && (self->private_impl.f_channel_masks[1] == 65280) && (self->private_impl.f_channel_masks[2] == 16711680)) {
if (self->private_impl.f_bits_per_pixel == 24) {
@@ -23431,15 +23665,15 @@ wuffs_bmp__decoder__decode_image_config(
}
}
} else if (self->private_impl.f_bitmap_info_len >= 40) {
self->private_data.s_decode_image_config[0].scratch = (self->private_impl.f_bitmap_info_len - 40);
self->private_data.s_do_decode_image_config[0].scratch = (self->private_impl.f_bitmap_info_len - 40);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(45);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
} else {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
@@ -23562,24 +23796,20 @@ wuffs_bmp__decoder__decode_image_config(
self->private_impl.f_call_sequence = 32;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -23611,18 +23841,64 @@ wuffs_bmp__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bmp__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bmp.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_bmp__decoder__do_decode_frame_config(
wuffs_bmp__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -23632,7 +23908,7 @@ wuffs_bmp__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_bmp__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_bmp__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -23671,24 +23947,20 @@ wuffs_bmp__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -23725,18 +23997,72 @@ wuffs_bmp__decoder__decode_frame(
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bmp__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bmp.decoder.do_decode_frame
static wuffs_base__status
wuffs_bmp__decoder__do_decode_frame(
wuffs_bmp__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -23746,7 +24072,7 @@ wuffs_bmp__decoder__decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_bmp__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_bmp__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -23757,15 +24083,15 @@ wuffs_bmp__decoder__decode_frame(
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
self->private_data.s_decode_frame[0].scratch = self->private_impl.f_padding;
self->private_data.s_do_decode_frame[0].scratch = self->private_impl.f_padding;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame[0].scratch;
if ((self->private_impl.f_width > 0) && (self->private_impl.f_height > 0)) {
self->private_impl.f_dst_x = 0;
if (self->private_impl.f_top_down) {
@@ -23841,38 +24167,34 @@ wuffs_bmp__decoder__decode_frame(
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
}
label__0__break:;
self->private_data.s_decode_frame[0].scratch = self->private_impl.f_pending_pad;
self->private_data.s_do_decode_frame[0].scratch = self->private_impl.f_pending_pad;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame[0].scratch;
self->private_impl.f_pending_pad = 0;
}
self->private_impl.f_call_sequence = 96;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -23889,17 +24211,19 @@ wuffs_bmp__decoder__swizzle_none(
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint32_t v_src_bytes_per_pixel = 0;
wuffs_base__slice_u8 v_dst_palette = {0};
wuffs_base__table_u8 v_tab = {0};
wuffs_base__slice_u8 v_dst = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
uint64_t v_n = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -23926,7 +24250,6 @@ wuffs_bmp__decoder__swizzle_none(
self->private_impl.f_pending_pad -= 1;
iop_a_src += 1;
}
label__inner__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -23947,14 +24270,38 @@ wuffs_bmp__decoder__swizzle_none(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__inner__continue;
if (self->private_impl.f_bits_per_pixel > 32) {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
v_src_bytes_per_pixel = (self->private_impl.f_bits_per_pixel / 8);
if (v_src_bytes_per_pixel == 0) {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
v_j = v_n;
while (v_j >= 8) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
iop_a_src += (v_src_bytes_per_pixel * 8);
}
v_j -= 8;
}
while (v_j > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
iop_a_src += (v_src_bytes_per_pixel * 1);
}
v_j -= 1;
}
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
v_dst_palette,
&iop_a_src,
io2_a_src);
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
v_dst_palette,
&iop_a_src,
io2_a_src);
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
@@ -23969,7 +24316,7 @@ wuffs_bmp__decoder__swizzle_none(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24006,7 +24353,7 @@ wuffs_bmp__decoder__swizzle_rle(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -24231,7 +24578,7 @@ wuffs_bmp__decoder__swizzle_rle(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24268,7 +24615,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -24295,7 +24642,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
self->private_impl.f_pending_pad -= 1;
iop_a_src += 1;
}
label__inner__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -24354,9 +24700,10 @@ wuffs_bmp__decoder__swizzle_bitfields(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__inner__continue;
v_n = ((uint64_t)(v_p0));
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
@@ -24371,7 +24718,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24399,12 +24746,13 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
uint32_t v_p0 = 0;
uint32_t v_chunk_bits = 0;
uint32_t v_chunk_count = 0;
uint32_t v_pixels_per_chunk = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -24436,6 +24784,35 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
if (self->private_impl.f_bits_per_pixel == 1) {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 31) / 32);
v_pixels_per_chunk = 32;
} else if (self->private_impl.f_bits_per_pixel == 2) {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 15) / 16);
v_pixels_per_chunk = 16;
} else {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
v_pixels_per_chunk = 8;
}
while ((v_chunk_count >= 64) && (((uint64_t)(io2_a_src - iop_a_src)) >= 256)) {
iop_a_src += 256;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 64))));
v_chunk_count -= 64;
}
while ((v_chunk_count >= 8) && (((uint64_t)(io2_a_src - iop_a_src)) >= 32)) {
iop_a_src += 32;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 8))));
v_chunk_count -= 8;
}
while (v_chunk_count > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
}
iop_a_src += 4;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 1))));
v_chunk_count -= 1;
}
goto label__loop__continue;
}
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i);
@@ -24506,7 +24883,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
v_p0 = ((v_p0 & 511) + 16);
v_chunk_count -= 1;
}
} else if (self->private_impl.f_bits_per_pixel == 4) {
} else {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
v_chunk_count = wuffs_base__u32__min(v_chunk_count, 64);
while ((v_chunk_count > 0) && (((uint64_t)(io2_a_src - iop_a_src)) >= 4)) {
@@ -24539,7 +24916,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24687,6 +25064,53 @@ wuffs_bmp__decoder__tell_me_more(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bmp__decoder__do_tell_me_more(self, a_dst, a_minfo, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bmp.decoder.do_tell_me_more
static wuffs_base__status
wuffs_bmp__decoder__do_tell_me_more(
wuffs_bmp__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
if (self->private_impl.f_io_redirect_fourcc <= 1) {
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
@@ -24705,9 +25129,6 @@ wuffs_bmp__decoder__tell_me_more(
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -24742,7 +25163,7 @@ wuffs_bmp__decoder__read_palette(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -24856,7 +25277,7 @@ wuffs_bmp__decoder__read_palette(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24920,6 +25341,7 @@ const char wuffs_bzip2__error__bad_block_length[] = "#bzip2: bad block length";
const char wuffs_bzip2__error__bad_checksum[] = "#bzip2: bad checksum";
const char wuffs_bzip2__error__bad_header[] = "#bzip2: bad header";
const char wuffs_bzip2__error__bad_number_of_sections[] = "#bzip2: bad number of sections";
const char wuffs_bzip2__error__truncated_input[] = "#bzip2: truncated input";
const char wuffs_bzip2__error__unsupported_block_randomization[] = "#bzip2: unsupported block randomization";
const char wuffs_bzip2__error__internal_error_inconsistent_huffman_decoder_state[] = "#bzip2: internal error: inconsistent Huffman decoder state";
@@ -24970,6 +25392,13 @@ WUFFS_BZIP2__REV_CRC32_TABLE[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_bzip2__decoder__do_transform_io(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
static wuffs_base__status
wuffs_bzip2__decoder__prepare_block(
wuffs_bzip2__decoder* self,
@@ -25164,6 +25593,53 @@ wuffs_bzip2__decoder__transform_io(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bzip2__decoder__do_transform_io(self, a_dst, a_src, a_workbuf);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bzip2__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bzip2.decoder.do_transform_io
static wuffs_base__status
wuffs_bzip2__decoder__do_transform_io(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint32_t v_i = 0;
uint64_t v_tag = 0;
@@ -25174,18 +25650,18 @@ wuffs_bzip2__decoder__transform_io(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
uint32_t coro_susp_point = self->private_impl.p_do_transform_io[0];
if (coro_susp_point) {
v_i = self->private_data.s_transform_io[0].v_i;
v_tag = self->private_data.s_transform_io[0].v_tag;
v_final_checksum_want = self->private_data.s_transform_io[0].v_final_checksum_want;
v_i = self->private_data.s_do_transform_io[0].v_i;
v_tag = self->private_data.s_do_transform_io[0].v_tag;
v_final_checksum_want = self->private_data.s_do_transform_io[0].v_final_checksum_want;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -25374,27 +25850,23 @@ wuffs_bzip2__decoder__transform_io(
goto ok;
ok:
self->private_impl.p_transform_io[0] = 0;
self->private_impl.p_do_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_transform_io[0].v_i = v_i;
self->private_data.s_transform_io[0].v_tag = v_tag;
self->private_data.s_transform_io[0].v_final_checksum_want = v_final_checksum_want;
self->private_impl.p_do_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_transform_io[0].v_i = v_i;
self->private_data.s_do_transform_io[0].v_tag = v_tag;
self->private_data.s_do_transform_io[0].v_final_checksum_want = v_final_checksum_want;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -25418,7 +25890,7 @@ wuffs_bzip2__decoder__prepare_block(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -25712,7 +26184,7 @@ wuffs_bzip2__decoder__prepare_block(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -25735,7 +26207,7 @@ wuffs_bzip2__decoder__read_code_lengths(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -25840,7 +26312,7 @@ wuffs_bzip2__decoder__read_code_lengths(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -26013,7 +26485,7 @@ wuffs_bzip2__decoder__flush_fast(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -26066,7 +26538,7 @@ wuffs_bzip2__decoder__flush_fast(
if (v_block_size <= 900000) {
self->private_impl.f_block_size = v_block_size;
}
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
@@ -26093,7 +26565,7 @@ wuffs_bzip2__decoder__flush_slow(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -26187,7 +26659,7 @@ wuffs_bzip2__decoder__flush_slow(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
@@ -26222,7 +26694,7 @@ wuffs_bzip2__decoder__decode_huffman_fast(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -26317,7 +26789,7 @@ wuffs_bzip2__decoder__decode_huffman_fast(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -26346,7 +26818,7 @@ wuffs_bzip2__decoder__decode_huffman_slow(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -26450,7 +26922,7 @@ wuffs_bzip2__decoder__decode_huffman_slow(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -26647,7 +27119,7 @@ wuffs_cbor__decoder__decode_tokens(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -26660,7 +27132,7 @@ wuffs_cbor__decoder__decode_tokens(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -27184,10 +27656,10 @@ wuffs_cbor__decoder__decode_tokens(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -28357,6 +28829,7 @@ const char wuffs_deflate__error__bad_literal_length_code_count[] = "#deflate: ba
const char wuffs_deflate__error__inconsistent_stored_block_length[] = "#deflate: inconsistent stored block length";
const char wuffs_deflate__error__missing_end_of_block_code[] = "#deflate: missing end-of-block code";
const char wuffs_deflate__error__no_huffman_codes[] = "#deflate: no Huffman codes";
const char wuffs_deflate__error__truncated_input[] = "#deflate: truncated input";
const char wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state[] = "#deflate: internal error: inconsistent Huffman decoder state";
const char wuffs_deflate__error__internal_error_inconsistent_i_o[] = "#deflate: internal error: inconsistent I/O";
const char wuffs_deflate__error__internal_error_inconsistent_distance[] = "#deflate: internal error: inconsistent distance";
@@ -28431,6 +28904,13 @@ WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[32] WUFFS_BASE__POTENTIALLY_UNUSED = {
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_deflate__decoder__do_transform_io(
wuffs_deflate__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
static wuffs_base__status
wuffs_deflate__decoder__decode_blocks(
wuffs_deflate__decoder* self,
@@ -28674,6 +29154,53 @@ wuffs_deflate__decoder__transform_io(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_deflate__decoder__do_transform_io(self, a_dst, a_src, a_workbuf);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_deflate__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func deflate.decoder.do_transform_io
static wuffs_base__status
wuffs_deflate__decoder__do_transform_io(
wuffs_deflate__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint64_t v_mark = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
@@ -28681,7 +29208,7 @@ wuffs_deflate__decoder__transform_io(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -28691,7 +29218,7 @@ wuffs_deflate__decoder__transform_io(
}
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
uint32_t coro_susp_point = self->private_impl.p_do_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -28729,24 +29256,20 @@ wuffs_deflate__decoder__transform_io(
}
ok:
self->private_impl.p_transform_io[0] = 0;
self->private_impl.p_do_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_impl.p_do_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -28768,7 +29291,7 @@ wuffs_deflate__decoder__decode_blocks(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -28897,7 +29420,7 @@ wuffs_deflate__decoder__decode_blocks(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -28920,7 +29443,7 @@ wuffs_deflate__decoder__decode_uncompressed(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -28933,7 +29456,7 @@ wuffs_deflate__decoder__decode_uncompressed(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -29016,10 +29539,10 @@ wuffs_deflate__decoder__decode_uncompressed(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -29103,7 +29626,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -29324,7 +29847,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -29617,7 +30140,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -29630,7 +30153,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -29791,10 +30314,10 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
}
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -29830,7 +30353,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -29843,7 +30366,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -30049,10 +30572,10 @@ wuffs_deflate__decoder__decode_huffman_fast32(
}
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -30094,7 +30617,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -30107,7 +30630,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -30268,10 +30791,10 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
}
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -30311,7 +30834,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -30324,7 +30847,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -30603,10 +31126,10 @@ wuffs_deflate__decoder__decode_huffman_slow(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -30620,6 +31143,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
// ---------------- Status Codes Implementations
const char wuffs_lzw__error__bad_code[] = "#lzw: bad code";
const char wuffs_lzw__error__truncated_input[] = "#lzw: truncated input";
const char wuffs_lzw__error__internal_error_inconsistent_i_o[] = "#lzw: internal error: inconsistent I/O";
// ---------------- Private Consts
@@ -30842,6 +31366,9 @@ wuffs_lzw__decoder__transform_io(
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
} else if (self->private_impl.f_read_from_return_value == 3) {
status = wuffs_base__make_status(wuffs_lzw__error__truncated_input);
goto exit;
} else if (self->private_impl.f_read_from_return_value == 4) {
status = wuffs_base__make_status(wuffs_lzw__error__bad_code);
goto exit;
} else {
@@ -30895,7 +31422,7 @@ wuffs_lzw__decoder__read_from(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -30917,7 +31444,11 @@ wuffs_lzw__decoder__read_from(
iop_a_src += ((31 - v_n_bits) >> 3);
v_n_bits |= 24;
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
self->private_impl.f_read_from_return_value = 2;
if (a_src && a_src->meta.closed) {
self->private_impl.f_read_from_return_value = 3;
} else {
self->private_impl.f_read_from_return_value = 2;
}
goto label__0__break;
} else {
v_bits |= (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) << v_n_bits);
@@ -30925,14 +31456,18 @@ wuffs_lzw__decoder__read_from(
v_n_bits += 8;
if (v_n_bits >= v_width) {
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
self->private_impl.f_read_from_return_value = 2;
if (a_src && a_src->meta.closed) {
self->private_impl.f_read_from_return_value = 3;
} else {
self->private_impl.f_read_from_return_value = 2;
}
goto label__0__break;
} else {
v_bits |= (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) << v_n_bits);
iop_a_src += 1;
v_n_bits += 8;
if (v_n_bits < v_width) {
self->private_impl.f_read_from_return_value = 4;
self->private_impl.f_read_from_return_value = 5;
goto label__0__break;
}
}
@@ -31010,7 +31545,7 @@ wuffs_lzw__decoder__read_from(
v_prev_code = v_code;
}
} else {
self->private_impl.f_read_from_return_value = 3;
self->private_impl.f_read_from_return_value = 4;
goto label__0__break;
}
if (v_output_wi > 4095) {
@@ -31025,7 +31560,7 @@ wuffs_lzw__decoder__read_from(
if (iop_a_src > io1_a_src) {
iop_a_src--;
} else {
self->private_impl.f_read_from_return_value = 4;
self->private_impl.f_read_from_return_value = 5;
goto label__2__break;
}
}
@@ -31037,7 +31572,7 @@ wuffs_lzw__decoder__read_from(
self->private_impl.f_bits = v_bits;
self->private_impl.f_n_bits = v_n_bits;
self->private_impl.f_output_wi = v_output_wi;
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -31059,7 +31594,7 @@ wuffs_lzw__decoder__write_to(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -31104,7 +31639,7 @@ wuffs_lzw__decoder__write_to(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
@@ -31147,6 +31682,7 @@ const char wuffs_gif__error__bad_graphic_control[] = "#gif: bad graphic control"
const char wuffs_gif__error__bad_header[] = "#gif: bad header";
const char wuffs_gif__error__bad_literal_width[] = "#gif: bad literal width";
const char wuffs_gif__error__bad_palette[] = "#gif: bad palette";
const char wuffs_gif__error__truncated_input[] = "#gif: truncated input";
const char wuffs_gif__error__internal_error_inconsistent_ri_wi[] = "#gif: internal error: inconsistent ri/wi";
// ---------------- Private Consts
@@ -31198,11 +31734,39 @@ WUFFS_GIF__XMPDATAXMP[11] WUFFS_BASE__POTENTIALLY_UNUSED = {
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_gif__decoder__do_decode_image_config(
wuffs_gif__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_gif__decoder__do_tell_me_more(
wuffs_gif__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_gif__decoder__do_decode_frame_config(
wuffs_gif__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_gif__decoder__skip_frame(
wuffs_gif__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_gif__decoder__do_decode_frame(
wuffs_gif__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
static wuffs_base__empty_struct
wuffs_gif__decoder__reset_gc(
wuffs_gif__decoder* self);
@@ -31432,12 +31996,58 @@ wuffs_gif__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
bool v_ffio = false;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gif__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gif__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gif.decoder.do_decode_image_config
static wuffs_base__status
wuffs_gif__decoder__do_decode_image_config(
wuffs_gif__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
bool v_ffio = false;
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
@@ -31488,20 +32098,16 @@ wuffs_gif__decoder__decode_image_config(
goto ok;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -31556,20 +32162,67 @@ wuffs_gif__decoder__tell_me_more(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gif__decoder__do_tell_me_more(self, a_dst, a_minfo, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gif__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gif.decoder.do_tell_me_more
static wuffs_base__status
wuffs_gif__decoder__do_tell_me_more(
wuffs_gif__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint64_t v_chunk_length = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
uint32_t coro_susp_point = self->private_impl.p_do_tell_me_more[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -31651,24 +32304,20 @@ wuffs_gif__decoder__tell_me_more(
goto ok;
ok:
self->private_impl.p_tell_me_more[0] = 0;
self->private_impl.p_do_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -31821,6 +32470,52 @@ wuffs_gif__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gif__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gif__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gif.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_gif__decoder__do_decode_frame_config(
wuffs_gif__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_background_color = 0;
uint8_t v_flags = 0;
@@ -31828,16 +32523,16 @@ wuffs_gif__decoder__decode_frame_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
if (coro_susp_point) {
v_background_color = self->private_data.s_decode_frame_config[0].v_background_color;
v_background_color = self->private_data.s_do_decode_frame_config[0].v_background_color;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -31852,7 +32547,7 @@ wuffs_gif__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_gif__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_gif__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -31935,25 +32630,21 @@ wuffs_gif__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_data.s_decode_frame_config[0].v_background_color = v_background_color;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_frame_config[0].v_background_color = v_background_color;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -31972,7 +32663,7 @@ wuffs_gif__decoder__skip_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32047,7 +32738,7 @@ wuffs_gif__decoder__skip_frame(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32085,14 +32776,68 @@ wuffs_gif__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gif__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gif__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gif.decoder.do_decode_frame
static wuffs_base__status
wuffs_gif__decoder__do_decode_frame(
wuffs_gif__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64) {
} else if (self->private_impl.f_call_sequence < 64) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_gif__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_gif__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
@@ -32119,20 +32864,16 @@ wuffs_gif__decoder__decode_frame(
self->private_impl.f_call_sequence = 32;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -32162,7 +32903,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32238,7 +32979,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32260,7 +33001,7 @@ wuffs_gif__decoder__decode_header(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32311,7 +33052,7 @@ wuffs_gif__decoder__decode_header(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32337,7 +33078,7 @@ wuffs_gif__decoder__decode_lsd(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32513,7 +33254,7 @@ wuffs_gif__decoder__decode_lsd(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32534,7 +33275,7 @@ wuffs_gif__decoder__decode_extension(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32606,7 +33347,7 @@ wuffs_gif__decoder__decode_extension(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32627,7 +33368,7 @@ wuffs_gif__decoder__skip_blocks(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32674,7 +33415,7 @@ wuffs_gif__decoder__skip_blocks(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32700,7 +33441,7 @@ wuffs_gif__decoder__decode_ae(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32897,7 +33638,7 @@ wuffs_gif__decoder__decode_ae(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32920,7 +33661,7 @@ wuffs_gif__decoder__decode_gc(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -33027,7 +33768,7 @@ wuffs_gif__decoder__decode_gc(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -33046,7 +33787,7 @@ wuffs_gif__decoder__decode_id_part0(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -33194,7 +33935,7 @@ wuffs_gif__decoder__decode_id_part0(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -33223,7 +33964,7 @@ wuffs_gif__decoder__decode_id_part1(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -33365,7 +34106,7 @@ wuffs_gif__decoder__decode_id_part1(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -33403,7 +34144,7 @@ wuffs_gif__decoder__decode_id_part2(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -33593,7 +34334,7 @@ wuffs_gif__decoder__decode_id_part2(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -33735,6 +34476,7 @@ const char wuffs_gzip__error__bad_checksum[] = "#gzip: bad checksum";
const char wuffs_gzip__error__bad_compression_method[] = "#gzip: bad compression method";
const char wuffs_gzip__error__bad_encoding_flags[] = "#gzip: bad encoding flags";
const char wuffs_gzip__error__bad_header[] = "#gzip: bad header";
const char wuffs_gzip__error__truncated_input[] = "#gzip: truncated input";
// ---------------- Private Consts
@@ -33742,6 +34484,13 @@ const char wuffs_gzip__error__bad_header[] = "#gzip: bad header";
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_gzip__decoder__do_transform_io(
wuffs_gzip__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
// ---------------- VTables
const wuffs_base__io_transformer__func_ptrs
@@ -33906,6 +34655,53 @@ wuffs_gzip__decoder__transform_io(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gzip__decoder__do_transform_io(self, a_dst, a_src, a_workbuf);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gzip__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gzip.decoder.do_transform_io
static wuffs_base__status
wuffs_gzip__decoder__do_transform_io(
wuffs_gzip__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint8_t v_flags = 0;
uint16_t v_xlen = 0;
@@ -33920,7 +34716,7 @@ wuffs_gzip__decoder__transform_io(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -33933,19 +34729,19 @@ wuffs_gzip__decoder__transform_io(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
uint32_t coro_susp_point = self->private_impl.p_do_transform_io[0];
if (coro_susp_point) {
v_flags = self->private_data.s_transform_io[0].v_flags;
v_checksum_got = self->private_data.s_transform_io[0].v_checksum_got;
v_decoded_length_got = self->private_data.s_transform_io[0].v_decoded_length_got;
v_checksum_want = self->private_data.s_transform_io[0].v_checksum_want;
v_flags = self->private_data.s_do_transform_io[0].v_flags;
v_checksum_got = self->private_data.s_do_transform_io[0].v_checksum_got;
v_decoded_length_got = self->private_data.s_do_transform_io[0].v_decoded_length_got;
v_checksum_want = self->private_data.s_do_transform_io[0].v_checksum_want;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -33998,15 +34794,15 @@ wuffs_gzip__decoder__transform_io(
uint8_t t_3 = *iop_a_src++;
v_flags = t_3;
}
self->private_data.s_transform_io[0].scratch = 6;
self->private_data.s_do_transform_io[0].scratch = 6;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (self->private_data.s_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_transform_io[0].scratch;
iop_a_src += self->private_data.s_do_transform_io[0].scratch;
if ((v_flags & 4) != 0) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
@@ -34015,14 +34811,14 @@ wuffs_gzip__decoder__transform_io(
t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -34037,15 +34833,15 @@ wuffs_gzip__decoder__transform_io(
}
v_xlen = t_4;
}
self->private_data.s_transform_io[0].scratch = ((uint32_t)(v_xlen));
self->private_data.s_do_transform_io[0].scratch = ((uint32_t)(v_xlen));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (self->private_data.s_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_transform_io[0].scratch;
iop_a_src += self->private_data.s_do_transform_io[0].scratch;
}
if ((v_flags & 8) != 0) {
while (true) {
@@ -34082,15 +34878,15 @@ wuffs_gzip__decoder__transform_io(
label__1__break:;
}
if ((v_flags & 2) != 0) {
self->private_data.s_transform_io[0].scratch = 2;
self->private_data.s_do_transform_io[0].scratch = 2;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
if (self->private_data.s_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_transform_io[0].scratch;
iop_a_src += self->private_data.s_do_transform_io[0].scratch;
}
if ((v_flags & 224) != 0) {
status = wuffs_base__make_status(wuffs_gzip__error__bad_encoding_flags);
@@ -34132,14 +34928,14 @@ wuffs_gzip__decoder__transform_io(
t_8 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_8 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -34161,14 +34957,14 @@ wuffs_gzip__decoder__transform_io(
t_9 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_9 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -34189,31 +34985,27 @@ wuffs_gzip__decoder__transform_io(
}
ok:
self->private_impl.p_transform_io[0] = 0;
self->private_impl.p_do_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_transform_io[0].v_flags = v_flags;
self->private_data.s_transform_io[0].v_checksum_got = v_checksum_got;
self->private_data.s_transform_io[0].v_decoded_length_got = v_decoded_length_got;
self->private_data.s_transform_io[0].v_checksum_want = v_checksum_want;
self->private_impl.p_do_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_transform_io[0].v_flags = v_flags;
self->private_data.s_do_transform_io[0].v_checksum_got = v_checksum_got;
self->private_data.s_do_transform_io[0].v_decoded_length_got = v_decoded_length_got;
self->private_data.s_do_transform_io[0].v_checksum_want = v_checksum_want;
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -34697,7 +35489,7 @@ wuffs_json__decoder__decode_tokens(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -34710,7 +35502,7 @@ wuffs_json__decoder__decode_tokens(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -35640,10 +36432,10 @@ wuffs_json__decoder__decode_tokens(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -35667,7 +36459,7 @@ wuffs_json__decoder__decode_number(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -35782,7 +36574,7 @@ wuffs_json__decoder__decode_number(
goto label__goto_done__break;
}
label__goto_done__break:;
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return (v_n | v_floating_point);
@@ -35802,7 +36594,7 @@ wuffs_json__decoder__decode_digits(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -35832,7 +36624,7 @@ wuffs_json__decoder__decode_digits(
if (v_n == a_n) {
v_n |= 256;
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return v_n;
@@ -35854,7 +36646,7 @@ wuffs_json__decoder__decode_leading(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -35867,7 +36659,7 @@ wuffs_json__decoder__decode_leading(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -35937,10 +36729,10 @@ wuffs_json__decoder__decode_leading(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -35964,7 +36756,7 @@ wuffs_json__decoder__decode_comment(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -35977,7 +36769,7 @@ wuffs_json__decoder__decode_comment(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -36119,10 +36911,10 @@ wuffs_json__decoder__decode_comment(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -36145,7 +36937,7 @@ wuffs_json__decoder__decode_inf_nan(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -36158,7 +36950,7 @@ wuffs_json__decoder__decode_inf_nan(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -36276,10 +37068,10 @@ wuffs_json__decoder__decode_inf_nan(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -36302,7 +37094,7 @@ wuffs_json__decoder__decode_trailer(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -36315,7 +37107,7 @@ wuffs_json__decoder__decode_trailer(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -36414,10 +37206,10 @@ wuffs_json__decoder__decode_trailer(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -36431,6 +37223,7 @@ wuffs_json__decoder__decode_trailer(
// ---------------- Status Codes Implementations
const char wuffs_nie__error__bad_header[] = "#nie: bad header";
const char wuffs_nie__error__truncated_input[] = "#nie: truncated input";
const char wuffs_nie__error__unsupported_nie_file[] = "#nie: unsupported NIE file";
const char wuffs_nie__note__internal_note_short_read[] = "@nie: internal note: short read";
@@ -36440,6 +37233,27 @@ const char wuffs_nie__note__internal_note_short_read[] = "@nie: internal note: s
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_nie__decoder__do_decode_image_config(
wuffs_nie__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_nie__decoder__do_decode_frame_config(
wuffs_nie__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_nie__decoder__do_decode_frame(
wuffs_nie__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
static wuffs_base__status
wuffs_nie__decoder__swizzle(
wuffs_nie__decoder* self,
@@ -36591,20 +37405,66 @@ wuffs_nie__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_nie__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_nie__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func nie.decoder.do_decode_image_config
static wuffs_base__status
wuffs_nie__decoder__do_decode_image_config(
wuffs_nie__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_a = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -36619,14 +37479,14 @@ wuffs_nie__decoder__decode_image_config(
t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -36652,14 +37512,14 @@ wuffs_nie__decoder__decode_image_config(
t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -36695,14 +37555,14 @@ wuffs_nie__decoder__decode_image_config(
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -36729,14 +37589,14 @@ wuffs_nie__decoder__decode_image_config(
t_3 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -36770,24 +37630,20 @@ wuffs_nie__decoder__decode_image_config(
goto ok;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -36819,18 +37675,64 @@ wuffs_nie__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_nie__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_nie__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func nie.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_nie__decoder__do_decode_frame_config(
wuffs_nie__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -36840,7 +37742,7 @@ wuffs_nie__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_nie__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_nie__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -36879,24 +37781,20 @@ wuffs_nie__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -36937,10 +37835,64 @@ wuffs_nie__decoder__decode_frame(
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_nie__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_nie__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func nie.decoder.do_decode_frame
static wuffs_base__status
wuffs_nie__decoder__do_decode_frame(
wuffs_nie__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64) {
} else if (self->private_impl.f_call_sequence < 64) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_nie__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_nie__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
@@ -36987,20 +37939,16 @@ wuffs_nie__decoder__decode_frame(
self->private_impl.f_call_sequence = 96;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -37017,16 +37965,18 @@ wuffs_nie__decoder__swizzle(
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint32_t v_src_bytes_per_pixel = 0;
wuffs_base__table_u8 v_tab = {0};
wuffs_base__slice_u8 v_dst = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
uint64_t v_n = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -37042,7 +37992,6 @@ wuffs_nie__decoder__swizzle(
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
label__0__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -37057,14 +38006,33 @@ wuffs_nie__decoder__swizzle(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__0__continue;
v_src_bytes_per_pixel = 4;
if (self->private_impl.f_pixfmt == 2164308923) {
v_src_bytes_per_pixel = 8;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
v_j = v_n;
while (v_j >= 8) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
iop_a_src += (v_src_bytes_per_pixel * 8);
}
v_j -= 8;
}
while (v_j > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
iop_a_src += (v_src_bytes_per_pixel * 1);
}
v_j -= 1;
}
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
wuffs_base__pixel_buffer__palette(a_dst),
&iop_a_src,
io2_a_src);
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
wuffs_base__pixel_buffer__palette(a_dst),
&iop_a_src,
io2_a_src);
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_nie__note__internal_note_short_read);
goto ok;
@@ -37078,7 +38046,7 @@ wuffs_nie__decoder__swizzle(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -37266,6 +38234,7 @@ const char wuffs_zlib__error__bad_compression_method[] = "#zlib: bad compression
const char wuffs_zlib__error__bad_compression_window_size[] = "#zlib: bad compression window size";
const char wuffs_zlib__error__bad_parity_check[] = "#zlib: bad parity check";
const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect dictionary";
const char wuffs_zlib__error__truncated_input[] = "#zlib: truncated input";
// ---------------- Private Consts
@@ -37277,6 +38246,13 @@ const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect diction
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_zlib__decoder__do_transform_io(
wuffs_zlib__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
// ---------------- VTables
const wuffs_base__io_transformer__func_ptrs
@@ -37494,6 +38470,53 @@ wuffs_zlib__decoder__transform_io(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_zlib__decoder__do_transform_io(self, a_dst, a_src, a_workbuf);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_zlib__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func zlib.decoder.do_transform_io
static wuffs_base__status
wuffs_zlib__decoder__do_transform_io(
wuffs_zlib__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint16_t v_x = 0;
uint32_t v_checksum_got = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
@@ -37504,7 +38527,7 @@ wuffs_zlib__decoder__transform_io(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -37517,16 +38540,16 @@ wuffs_zlib__decoder__transform_io(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
uint32_t coro_susp_point = self->private_impl.p_do_transform_io[0];
if (coro_susp_point) {
v_checksum_got = self->private_data.s_transform_io[0].v_checksum_got;
v_checksum_got = self->private_data.s_do_transform_io[0].v_checksum_got;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -37543,14 +38566,14 @@ wuffs_zlib__decoder__transform_io(
t_0 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -37587,14 +38610,14 @@ wuffs_zlib__decoder__transform_io(
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -37660,14 +38683,14 @@ wuffs_zlib__decoder__transform_io(
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -37689,28 +38712,24 @@ wuffs_zlib__decoder__transform_io(
}
ok:
self->private_impl.p_transform_io[0] = 0;
self->private_impl.p_do_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_transform_io[0].v_checksum_got = v_checksum_got;
self->private_impl.p_do_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_transform_io[0].v_checksum_got = v_checksum_got;
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -37727,6 +38746,7 @@ const char wuffs_png__error__bad_filter[] = "#png: bad filter";
const char wuffs_png__error__bad_header[] = "#png: bad header";
const char wuffs_png__error__bad_text_chunk_not_latin_1[] = "#png: bad text chunk (not Latin-1)";
const char wuffs_png__error__missing_palette[] = "#png: missing palette";
const char wuffs_png__error__truncated_input[] = "#png: truncated input";
const char wuffs_png__error__unsupported_cgbi_extension[] = "#png: unsupported CgBI extension";
const char wuffs_png__error__unsupported_png_compression_method[] = "#png: unsupported PNG compression method";
const char wuffs_png__error__unsupported_png_file[] = "#png: unsupported PNG file";
@@ -37952,6 +38972,12 @@ wuffs_png__decoder__filter_4_distance_4_x86_sse42(
wuffs_base__slice_u8 a_prev);
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
static wuffs_base__status
wuffs_png__decoder__do_decode_image_config(
wuffs_png__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_ihdr(
wuffs_png__decoder* self,
@@ -38021,17 +39047,39 @@ wuffs_png__decoder__decode_trns(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__do_decode_frame_config(
wuffs_png__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__skip_frame(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__do_decode_frame(
wuffs_png__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
static wuffs_base__status
wuffs_png__decoder__decode_pass(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
static wuffs_base__status
wuffs_png__decoder__do_tell_me_more(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__filter_and_swizzle(
wuffs_png__decoder* self,
@@ -39626,6 +40674,52 @@ wuffs_png__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_png__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func png.decoder.do_decode_image_config
static wuffs_base__status
wuffs_png__decoder__do_decode_image_config(
wuffs_png__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint64_t v_magic = 0;
uint64_t v_mark = 0;
uint32_t v_checksum_have = 0;
@@ -39636,16 +40730,16 @@ wuffs_png__decoder__decode_image_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
if (coro_susp_point) {
v_checksum_have = self->private_data.s_decode_image_config[0].v_checksum_have;
v_checksum_have = self->private_data.s_do_decode_image_config[0].v_checksum_have;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -39661,14 +40755,14 @@ wuffs_png__decoder__decode_image_config(
t_0 = wuffs_base__peek_u64le__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -39694,14 +40788,14 @@ wuffs_png__decoder__decode_image_config(
t_1 = wuffs_base__peek_u64le__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -39760,14 +40854,14 @@ wuffs_png__decoder__decode_image_config(
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -39792,14 +40886,12 @@ wuffs_png__decoder__decode_image_config(
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
label__1__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
goto label__1__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -39859,14 +40951,14 @@ wuffs_png__decoder__decode_image_config(
t_5 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -39916,25 +41008,21 @@ wuffs_png__decoder__decode_image_config(
self->private_impl.f_call_sequence = 32;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_decode_image_config[0].v_checksum_have = v_checksum_have;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_image_config[0].v_checksum_have = v_checksum_have;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -39953,7 +41041,7 @@ wuffs_png__decoder__decode_ihdr(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40132,7 +41220,7 @@ wuffs_png__decoder__decode_ihdr(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40301,7 +41389,7 @@ wuffs_png__decoder__decode_other_chunk(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40479,20 +41567,22 @@ wuffs_png__decoder__decode_other_chunk(
self->private_impl.f_seen_srgb = true;
}
} else if (self->private_impl.f_chunk_type == 1397641844) {
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
if (self->private_impl.f_seen_trns || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_png__decoder__decode_trns(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
} else if (self->private_impl.f_color_type > 3) {
} else {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_png__decoder__decode_trns(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
}
self->private_impl.f_seen_trns = true;
}
@@ -40521,7 +41611,7 @@ wuffs_png__decoder__decode_other_chunk(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40540,7 +41630,7 @@ wuffs_png__decoder__decode_actl(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40634,7 +41724,7 @@ wuffs_png__decoder__decode_actl(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40655,7 +41745,7 @@ wuffs_png__decoder__decode_chrm(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40931,7 +42021,7 @@ wuffs_png__decoder__decode_chrm(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40950,7 +42040,7 @@ wuffs_png__decoder__decode_exif(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40972,7 +42062,7 @@ wuffs_png__decoder__decode_exif(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40996,7 +42086,7 @@ wuffs_png__decoder__decode_fctl(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41309,7 +42399,7 @@ wuffs_png__decoder__decode_fctl(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41328,7 +42418,7 @@ wuffs_png__decoder__decode_gama(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41390,7 +42480,7 @@ wuffs_png__decoder__decode_gama(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41411,7 +42501,7 @@ wuffs_png__decoder__decode_iccp(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41479,7 +42569,7 @@ wuffs_png__decoder__decode_iccp(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41502,7 +42592,7 @@ wuffs_png__decoder__decode_plte(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41582,7 +42672,7 @@ wuffs_png__decoder__decode_plte(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41601,7 +42691,7 @@ wuffs_png__decoder__decode_srgb(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41643,7 +42733,7 @@ wuffs_png__decoder__decode_srgb(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41666,7 +42756,7 @@ wuffs_png__decoder__decode_trns(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41828,7 +42918,7 @@ wuffs_png__decoder__decode_trns(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41863,20 +42953,66 @@ wuffs_png__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_png__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func png.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_png__decoder__do_decode_frame_config(
wuffs_png__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_checksum_have = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -41889,7 +43025,7 @@ wuffs_png__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_png__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -41940,14 +43076,14 @@ wuffs_png__decoder__decode_frame_config(
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_frame_config[0].scratch = 0;
self->private_data.s_do_decode_frame_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_frame_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_frame_config[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -41969,14 +43105,14 @@ wuffs_png__decoder__decode_frame_config(
t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_frame_config[0].scratch = 0;
self->private_data.s_do_decode_frame_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_frame_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_frame_config[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -42003,14 +43139,14 @@ wuffs_png__decoder__decode_frame_config(
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_frame_config[0].scratch = 0;
self->private_data.s_do_decode_frame_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_frame_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_frame_config[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -42048,15 +43184,15 @@ wuffs_png__decoder__decode_frame_config(
if (status.repr) {
goto suspend;
}
self->private_data.s_decode_frame_config[0].scratch = 4;
self->private_data.s_do_decode_frame_config[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame_config[0].scratch;
goto label__0__break;
}
if (a_src) {
@@ -42075,15 +43211,15 @@ wuffs_png__decoder__decode_frame_config(
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
self->private_data.s_decode_frame_config[0].scratch = 4;
self->private_data.s_do_decode_frame_config[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame_config[0].scratch;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
@@ -42108,24 +43244,20 @@ wuffs_png__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -42143,7 +43275,7 @@ wuffs_png__decoder__skip_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -42160,13 +43292,10 @@ wuffs_png__decoder__skip_frame(
self->private_impl.f_chunk_type_array[3] = 0;
label__0__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
goto label__0__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -42274,7 +43403,7 @@ wuffs_png__decoder__skip_frame(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -42312,6 +43441,60 @@ wuffs_png__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_png__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func png.decoder.do_decode_frame
static wuffs_base__status
wuffs_png__decoder__do_decode_frame(
wuffs_png__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_seq_num = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t v_pass_width = 0;
@@ -42321,14 +43504,14 @@ wuffs_png__decoder__decode_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -42343,7 +43526,7 @@ wuffs_png__decoder__decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_png__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -42351,14 +43534,12 @@ wuffs_png__decoder__decode_frame(
goto suspend;
}
}
label__0__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
goto label__0__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -42392,14 +43573,14 @@ wuffs_png__decoder__decode_frame(
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_frame[0].scratch = 0;
self->private_data.s_do_decode_frame[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_frame[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_frame[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -42427,15 +43608,15 @@ wuffs_png__decoder__decode_frame(
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_data.s_decode_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12);
self->private_data.s_do_decode_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame[0].scratch;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
@@ -42493,14 +43674,12 @@ wuffs_png__decoder__decode_frame(
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
}
if (v_status.repr == wuffs_base__suspension__short_read) {
while (true) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
label__1__break:;
v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf);
@@ -42533,24 +43712,20 @@ wuffs_png__decoder__decode_frame(
self->private_impl.f_call_sequence = 32;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -42580,7 +43755,7 @@ wuffs_png__decoder__decode_pass(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -42615,11 +43790,14 @@ wuffs_png__decoder__decode_pass(
self->private_impl.f_pass_workbuf_length),
((uint64_t)(self->private_impl.f_workbuf_hist_pos_base + self->private_impl.f_workbuf_wi)));
{
const bool o_1_closed_a_src = a_src->meta.closed;
const uint8_t *o_1_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
a_src->meta.wi = n;
}
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
@@ -42642,6 +43820,7 @@ wuffs_png__decoder__decode_pass(
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_workbuf_wi, wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w))));
io2_a_src = o_1_io2_a_src;
if (a_src) {
a_src->meta.closed = o_1_closed_a_src;
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
@@ -42886,7 +44065,7 @@ wuffs_png__decoder__decode_pass(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -43052,6 +44231,53 @@ wuffs_png__decoder__tell_me_more(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_png__decoder__do_tell_me_more(self, a_dst, a_minfo, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func png.decoder.do_tell_me_more
static wuffs_base__status
wuffs_png__decoder__do_tell_me_more(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint16_t v_c2 = 0;
wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer();
@@ -43069,7 +44295,7 @@ wuffs_png__decoder__tell_me_more(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -43082,16 +44308,16 @@ wuffs_png__decoder__tell_me_more(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
uint32_t coro_susp_point = self->private_impl.p_do_tell_me_more[0];
if (coro_susp_point) {
v_zlib_status = self->private_data.s_tell_me_more[0].v_zlib_status;
v_zlib_status = self->private_data.s_do_tell_me_more[0].v_zlib_status;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -43153,11 +44379,14 @@ wuffs_png__decoder__tell_me_more(
if (self->private_impl.f_metadata_is_zlib_compressed) {
if (self->private_impl.f_chunk_type == 1346585449) {
{
const bool o_0_closed_a_src = a_src->meta.closed;
const uint8_t *o_0_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
a_src->meta.wi = n;
}
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
@@ -43179,6 +44408,7 @@ wuffs_png__decoder__tell_me_more(
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
io2_a_src = o_0_io2_a_src;
if (a_src) {
a_src->meta.closed = o_0_closed_a_src;
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
@@ -43199,11 +44429,14 @@ wuffs_png__decoder__tell_me_more(
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
} else if (self->private_impl.f_chunk_type == 1951945833) {
{
const bool o_1_closed_a_src = a_src->meta.closed;
const uint8_t *o_1_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
a_src->meta.wi = n;
}
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
@@ -43225,6 +44458,7 @@ wuffs_png__decoder__tell_me_more(
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
io2_a_src = o_1_io2_a_src;
if (a_src) {
a_src->meta.closed = o_1_closed_a_src;
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
@@ -43260,11 +44494,14 @@ wuffs_png__decoder__tell_me_more(
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
self->private_impl.f_ztxt_hist_pos);
{
const bool o_3_closed_a_src = a_src->meta.closed;
const uint8_t *o_3_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
a_src->meta.wi = n;
}
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
@@ -43284,6 +44521,7 @@ wuffs_png__decoder__tell_me_more(
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
io2_a_src = o_3_io2_a_src;
if (a_src) {
a_src->meta.closed = o_3_closed_a_src;
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
@@ -43502,15 +44740,15 @@ wuffs_png__decoder__tell_me_more(
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_data.s_tell_me_more[0].scratch = 4;
self->private_data.s_do_tell_me_more[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
iop_a_src += self->private_data.s_do_tell_me_more[0].scratch;
self->private_impl.f_metadata_flavor = 0;
self->private_impl.f_metadata_fourcc = 0;
self->private_impl.f_metadata_x = 0;
@@ -43521,28 +44759,24 @@ wuffs_png__decoder__tell_me_more(
goto ok;
ok:
self->private_impl.p_tell_me_more[0] = 0;
self->private_impl.p_do_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
self->private_data.s_tell_me_more[0].v_zlib_status = v_zlib_status;
self->private_impl.p_do_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_tell_me_more[0].v_zlib_status = v_zlib_status;
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -43933,6 +45167,7 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding";
const char wuffs_tga__error__truncated_input[] = "#tga: truncated input";
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
// ---------------- Private Consts
@@ -43941,6 +45176,27 @@ const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA fil
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_tga__decoder__do_decode_image_config(
wuffs_tga__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame_config(
wuffs_tga__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame(
wuffs_tga__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
@@ -44086,6 +45342,52 @@ wuffs_tga__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func tga.decoder.do_decode_image_config
static wuffs_base__status
wuffs_tga__decoder__do_decode_image_config(
wuffs_tga__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_c = 0;
uint32_t v_c5 = 0;
uint32_t v_i = 0;
@@ -44094,16 +45396,16 @@ wuffs_tga__decoder__decode_image_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
if (coro_susp_point) {
v_i = self->private_data.s_decode_image_config[0].v_i;
v_i = self->private_data.s_do_decode_image_config[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -44160,14 +45462,14 @@ wuffs_tga__decoder__decode_image_config(
t_3 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44189,14 +45491,14 @@ wuffs_tga__decoder__decode_image_config(
t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44237,15 +45539,15 @@ wuffs_tga__decoder__decode_image_config(
goto exit;
}
}
self->private_data.s_decode_image_config[0].scratch = 4;
self->private_data.s_do_decode_image_config[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
uint32_t t_6;
@@ -44253,14 +45555,14 @@ wuffs_tga__decoder__decode_image_config(
t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_6 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44282,14 +45584,14 @@ wuffs_tga__decoder__decode_image_config(
t_7 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_7 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44369,15 +45671,15 @@ wuffs_tga__decoder__decode_image_config(
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
goto exit;
}
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
self->private_data.s_do_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
if (self->private_impl.f_header_color_map_type != 0) {
while (v_i < ((uint32_t)(self->private_impl.f_header_color_map_length))) {
if (self->private_impl.f_header_color_map_entry_size == 24) {
@@ -44388,14 +45690,14 @@ wuffs_tga__decoder__decode_image_config(
t_10 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
iop_a_src += 3;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(18);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_10 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44422,14 +45724,14 @@ wuffs_tga__decoder__decode_image_config(
t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(20);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_11 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44456,14 +45758,14 @@ wuffs_tga__decoder__decode_image_config(
t_12 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(22);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_12 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44511,25 +45813,21 @@ wuffs_tga__decoder__decode_image_config(
goto ok;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_decode_image_config[0].v_i = v_i;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_image_config[0].v_i = v_i;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -44561,18 +45859,64 @@ wuffs_tga__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func tga.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame_config(
wuffs_tga__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -44582,7 +45926,7 @@ wuffs_tga__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_tga__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_tga__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -44621,24 +45965,20 @@ wuffs_tga__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -44673,6 +46013,60 @@ wuffs_tga__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func tga.decoder.do_decode_frame
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame(
wuffs_tga__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
@@ -44698,23 +46092,23 @@ wuffs_tga__decoder__decode_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
if (coro_susp_point) {
v_dst_bytes_per_pixel = self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel;
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
v_mark = self->private_data.s_decode_frame[0].v_mark;
v_num_pixels32 = self->private_data.s_decode_frame[0].v_num_pixels32;
v_lit_length = self->private_data.s_decode_frame[0].v_lit_length;
v_run_length = self->private_data.s_decode_frame[0].v_run_length;
v_num_dst_bytes = self->private_data.s_decode_frame[0].v_num_dst_bytes;
v_dst_bytes_per_pixel = self->private_data.s_do_decode_frame[0].v_dst_bytes_per_pixel;
v_dst_x = self->private_data.s_do_decode_frame[0].v_dst_x;
v_dst_y = self->private_data.s_do_decode_frame[0].v_dst_y;
v_mark = self->private_data.s_do_decode_frame[0].v_mark;
v_num_pixels32 = self->private_data.s_do_decode_frame[0].v_num_pixels32;
v_lit_length = self->private_data.s_do_decode_frame[0].v_lit_length;
v_run_length = self->private_data.s_do_decode_frame[0].v_run_length;
v_num_dst_bytes = self->private_data.s_do_decode_frame[0].v_num_dst_bytes;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -44725,7 +46119,7 @@ wuffs_tga__decoder__decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_tga__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_tga__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -44788,15 +46182,15 @@ wuffs_tga__decoder__decode_frame(
v_num_pixels32 = ((uint32_t)(wuffs_base__u64__min(v_num_pixels64, ((uint64_t)(v_lit_length)))));
v_num_dst_bytes = (((uint64_t)(v_num_pixels32)) * v_dst_bytes_per_pixel);
v_num_src_bytes = (v_num_pixels32 * self->private_impl.f_src_bytes_per_pixel);
self->private_data.s_decode_frame[0].scratch = v_num_src_bytes;
self->private_data.s_do_decode_frame[0].scratch = v_num_src_bytes;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame[0].scratch;
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
if (v_num_dst_bytes <= ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_num_dst_bytes);
@@ -44961,32 +46355,28 @@ wuffs_tga__decoder__decode_frame(
self->private_impl.f_call_sequence = 96;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
self->private_data.s_decode_frame[0].v_dst_x = v_dst_x;
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
self->private_data.s_decode_frame[0].v_mark = v_mark;
self->private_data.s_decode_frame[0].v_num_pixels32 = v_num_pixels32;
self->private_data.s_decode_frame[0].v_lit_length = v_lit_length;
self->private_data.s_decode_frame[0].v_run_length = v_run_length;
self->private_data.s_decode_frame[0].v_num_dst_bytes = v_num_dst_bytes;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
self->private_data.s_do_decode_frame[0].v_dst_x = v_dst_x;
self->private_data.s_do_decode_frame[0].v_dst_y = v_dst_y;
self->private_data.s_do_decode_frame[0].v_mark = v_mark;
self->private_data.s_do_decode_frame[0].v_num_pixels32 = v_num_pixels32;
self->private_data.s_do_decode_frame[0].v_lit_length = v_lit_length;
self->private_data.s_do_decode_frame[0].v_run_length = v_run_length;
self->private_data.s_do_decode_frame[0].v_num_dst_bytes = v_num_dst_bytes;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -45167,6 +46557,7 @@ wuffs_tga__decoder__workbuf_len(
// ---------------- Status Codes Implementations
const char wuffs_wbmp__error__bad_header[] = "#wbmp: bad header";
const char wuffs_wbmp__error__truncated_input[] = "#wbmp: truncated input";
// ---------------- Private Consts
@@ -45174,6 +46565,27 @@ const char wuffs_wbmp__error__bad_header[] = "#wbmp: bad header";
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_image_config(
wuffs_wbmp__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_frame_config(
wuffs_wbmp__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_frame(
wuffs_wbmp__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
@@ -45319,6 +46731,52 @@ wuffs_wbmp__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_wbmp__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_wbmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func wbmp.decoder.do_decode_image_config
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_image_config(
wuffs_wbmp__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint32_t v_i = 0;
uint32_t v_x32 = 0;
@@ -45328,17 +46786,17 @@ wuffs_wbmp__decoder__decode_image_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
if (coro_susp_point) {
v_i = self->private_data.s_decode_image_config[0].v_i;
v_x32 = self->private_data.s_decode_image_config[0].v_x32;
v_i = self->private_data.s_do_decode_image_config[0].v_i;
v_x32 = self->private_data.s_do_decode_image_config[0].v_x32;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -45411,26 +46869,22 @@ wuffs_wbmp__decoder__decode_image_config(
goto ok;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_decode_image_config[0].v_i = v_i;
self->private_data.s_decode_image_config[0].v_x32 = v_x32;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_image_config[0].v_i = v_i;
self->private_data.s_do_decode_image_config[0].v_x32 = v_x32;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -45462,18 +46916,64 @@ wuffs_wbmp__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_wbmp__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_wbmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func wbmp.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_frame_config(
wuffs_wbmp__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -45483,7 +46983,7 @@ wuffs_wbmp__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_wbmp__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_wbmp__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -45522,24 +47022,20 @@ wuffs_wbmp__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -45574,6 +47070,60 @@ wuffs_wbmp__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_wbmp__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_wbmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func wbmp.decoder.do_decode_frame
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_frame(
wuffs_wbmp__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
@@ -45590,20 +47140,20 @@ wuffs_wbmp__decoder__decode_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
if (coro_susp_point) {
v_dst_bytes_per_pixel = self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel;
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
memcpy(v_src, self->private_data.s_decode_frame[0].v_src, sizeof(v_src));
v_c = self->private_data.s_decode_frame[0].v_c;
v_dst_bytes_per_pixel = self->private_data.s_do_decode_frame[0].v_dst_bytes_per_pixel;
v_dst_x = self->private_data.s_do_decode_frame[0].v_dst_x;
v_dst_y = self->private_data.s_do_decode_frame[0].v_dst_y;
memcpy(v_src, self->private_data.s_do_decode_frame[0].v_src, sizeof(v_src));
v_c = self->private_data.s_do_decode_frame[0].v_c;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -45614,7 +47164,7 @@ wuffs_wbmp__decoder__decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_wbmp__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_wbmp__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -45686,29 +47236,25 @@ wuffs_wbmp__decoder__decode_frame(
self->private_impl.f_call_sequence = 96;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
self->private_data.s_decode_frame[0].v_dst_x = v_dst_x;
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
memcpy(self->private_data.s_decode_frame[0].v_src, v_src, sizeof(v_src));
self->private_data.s_decode_frame[0].v_c = v_c;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
self->private_data.s_do_decode_frame[0].v_dst_x = v_dst_x;
self->private_data.s_do_decode_frame[0].v_dst_y = v_dst_y;
memcpy(self->private_data.s_do_decode_frame[0].v_src, v_src, sizeof(v_src));
self->private_data.s_do_decode_frame[0].v_c = v_c;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
+2247 -701
View File
@@ -85,15 +85,15 @@ extern "C" {
// each major.minor branch, the commit count should increase monotonically.
//
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
// fac934b27259f37191285a8d9d1d9629ed2d9f5d committed on 2022-06-29.
#define WUFFS_VERSION 0x000030000
// 55279938422060f30cd487173b98a651da075e3a committed on 2026-10-20.
#define WUFFS_VERSION 0x000030006
#define WUFFS_VERSION_MAJOR 0
#define WUFFS_VERSION_MINOR 3
#define WUFFS_VERSION_PATCH 0
#define WUFFS_VERSION_PRE_RELEASE_LABEL "rc.1"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3360
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20220629
#define WUFFS_VERSION_STRING "0.3.0-rc.1+3360.20220629"
#define WUFFS_VERSION_PATCH 6
#define WUFFS_VERSION_PRE_RELEASE_LABEL ""
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3407
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20261020
#define WUFFS_VERSION_STRING "0.3.6+3407.20261020"
// ---------------- Configuration
@@ -6345,6 +6345,8 @@ struct wuffs_base__token_decoder__struct {
} // extern "C"
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ADLER32) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
// ---------------- Public Consts
@@ -6527,10 +6529,15 @@ struct wuffs_adler32__hasher__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ADLER32) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_bmp__error__bad_header[];
extern const char wuffs_bmp__error__bad_rle_compression[];
extern const char wuffs_bmp__error__truncated_input[];
extern const char wuffs_bmp__error__unsupported_bmp_file[];
// ---------------- Public Consts
@@ -6709,8 +6716,12 @@ struct wuffs_bmp__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
uint32_t p_tell_me_more[1];
uint32_t p_read_palette[1];
} private_impl;
@@ -6720,10 +6731,10 @@ struct wuffs_bmp__decoder__struct {
struct {
uint64_t scratch;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
struct {
uint64_t scratch;
} s_decode_frame[1];
} s_do_decode_frame[1];
struct {
uint32_t v_i;
uint64_t scratch;
@@ -6875,6 +6886,10 @@ struct wuffs_bmp__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_bzip2__error__bad_huffman_code_over_subscribed[];
@@ -6884,6 +6899,7 @@ extern const char wuffs_bzip2__error__bad_block_length[];
extern const char wuffs_bzip2__error__bad_checksum[];
extern const char wuffs_bzip2__error__bad_header[];
extern const char wuffs_bzip2__error__bad_number_of_sections[];
extern const char wuffs_bzip2__error__truncated_input[];
extern const char wuffs_bzip2__error__unsupported_block_randomization[];
// ---------------- Public Consts
@@ -7009,6 +7025,7 @@ struct wuffs_bzip2__decoder__struct {
uint32_t f_code_lengths_bitmask;
uint32_t p_transform_io[1];
uint32_t p_do_transform_io[1];
uint32_t p_prepare_block[1];
uint32_t p_read_code_lengths[1];
uint32_t p_flush_slow[1];
@@ -7029,7 +7046,7 @@ struct wuffs_bzip2__decoder__struct {
uint32_t v_i;
uint64_t v_tag;
uint32_t v_final_checksum_want;
} s_transform_io[1];
} s_do_transform_io[1];
struct {
uint32_t v_i;
uint32_t v_selector;
@@ -7139,6 +7156,10 @@ struct wuffs_bzip2__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BZIP2) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CBOR) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_cbor__error__bad_input[];
@@ -7364,6 +7385,10 @@ struct wuffs_cbor__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CBOR) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC32) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
// ---------------- Public Consts
@@ -7545,6 +7570,10 @@ struct wuffs_crc32__ieee_hasher__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC32) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_deflate__error__bad_huffman_code_over_subscribed[];
@@ -7560,6 +7589,7 @@ extern const char wuffs_deflate__error__bad_literal_length_code_count[];
extern const char wuffs_deflate__error__inconsistent_stored_block_length[];
extern const char wuffs_deflate__error__missing_end_of_block_code[];
extern const char wuffs_deflate__error__no_huffman_codes[];
extern const char wuffs_deflate__error__truncated_input[];
// ---------------- Public Consts
@@ -7674,6 +7704,7 @@ struct wuffs_deflate__decoder__struct {
bool f_end_of_block;
uint32_t p_transform_io[1];
uint32_t p_do_transform_io[1];
uint32_t p_decode_blocks[1];
uint32_t p_decode_uncompressed[1];
uint32_t p_init_dynamic_huffman[1];
@@ -7815,9 +7846,14 @@ struct wuffs_deflate__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__LZW) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_lzw__error__bad_code[];
extern const char wuffs_lzw__error__truncated_input[];
// ---------------- Public Consts
@@ -8050,6 +8086,10 @@ struct wuffs_lzw__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__LZW) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_gif__error__bad_extension_label[];
@@ -8058,6 +8098,7 @@ extern const char wuffs_gif__error__bad_graphic_control[];
extern const char wuffs_gif__error__bad_header[];
extern const char wuffs_gif__error__bad_literal_width[];
extern const char wuffs_gif__error__bad_palette[];
extern const char wuffs_gif__error__truncated_input[];
// ---------------- Public Consts
@@ -8258,10 +8299,14 @@ struct wuffs_gif__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_tell_me_more[1];
uint32_t p_do_tell_me_more[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_skip_frame[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
uint32_t p_decode_up_to_id_part1[1];
uint32_t p_decode_header[1];
uint32_t p_decode_lsd[1];
@@ -8282,7 +8327,7 @@ struct wuffs_gif__decoder__struct {
struct {
uint32_t v_background_color;
} s_decode_frame_config[1];
} s_do_decode_frame_config[1];
struct {
uint64_t scratch;
} s_skip_frame[1];
@@ -8472,12 +8517,17 @@ struct wuffs_gif__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GZIP) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_gzip__error__bad_checksum[];
extern const char wuffs_gzip__error__bad_compression_method[];
extern const char wuffs_gzip__error__bad_encoding_flags[];
extern const char wuffs_gzip__error__bad_header[];
extern const char wuffs_gzip__error__truncated_input[];
// ---------------- Public Consts
@@ -8582,6 +8632,7 @@ struct wuffs_gzip__decoder__struct {
bool f_ignore_checksum;
uint32_t p_transform_io[1];
uint32_t p_do_transform_io[1];
} private_impl;
struct {
@@ -8594,7 +8645,7 @@ struct wuffs_gzip__decoder__struct {
uint32_t v_decoded_length_got;
uint32_t v_checksum_want;
uint64_t scratch;
} s_transform_io[1];
} s_do_transform_io[1];
} private_data;
#ifdef __cplusplus
@@ -8684,6 +8735,10 @@ struct wuffs_gzip__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GZIP) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JSON) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_json__error__bad_c0_control_code[];
@@ -8952,9 +9007,14 @@ struct wuffs_json__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JSON) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_nie__error__bad_header[];
extern const char wuffs_nie__error__truncated_input[];
extern const char wuffs_nie__error__unsupported_nie_file[];
// ---------------- Public Consts
@@ -9115,14 +9175,17 @@ struct wuffs_nie__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
} private_impl;
struct {
struct {
uint64_t scratch;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
} private_data;
#ifdef __cplusplus
@@ -9270,6 +9333,10 @@ struct wuffs_nie__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ZLIB) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_zlib__note__dictionary_required[];
@@ -9278,6 +9345,7 @@ extern const char wuffs_zlib__error__bad_compression_method[];
extern const char wuffs_zlib__error__bad_compression_window_size[];
extern const char wuffs_zlib__error__bad_parity_check[];
extern const char wuffs_zlib__error__incorrect_dictionary[];
extern const char wuffs_zlib__error__truncated_input[];
// ---------------- Public Consts
@@ -9400,6 +9468,7 @@ struct wuffs_zlib__decoder__struct {
uint32_t f_dict_id_want;
uint32_t p_transform_io[1];
uint32_t p_do_transform_io[1];
} private_impl;
struct {
@@ -9410,7 +9479,7 @@ struct wuffs_zlib__decoder__struct {
struct {
uint32_t v_checksum_got;
uint64_t scratch;
} s_transform_io[1];
} s_do_transform_io[1];
} private_data;
#ifdef __cplusplus
@@ -9511,6 +9580,10 @@ struct wuffs_zlib__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ZLIB) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_png__error__bad_animation_sequence_number[];
@@ -9520,6 +9593,7 @@ extern const char wuffs_png__error__bad_filter[];
extern const char wuffs_png__error__bad_header[];
extern const char wuffs_png__error__bad_text_chunk_not_latin_1[];
extern const char wuffs_png__error__missing_palette[];
extern const char wuffs_png__error__truncated_input[];
extern const char wuffs_png__error__unsupported_cgbi_extension[];
extern const char wuffs_png__error__unsupported_png_compression_method[];
extern const char wuffs_png__error__unsupported_png_file[];
@@ -9756,6 +9830,7 @@ struct wuffs_png__decoder__struct {
wuffs_base__slice_u8 a_curr,
wuffs_base__slice_u8 a_prev);
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_ihdr[1];
uint32_t p_decode_other_chunk[1];
uint32_t p_decode_actl[1];
@@ -9767,10 +9842,13 @@ struct wuffs_png__decoder__struct {
uint32_t p_decode_srgb[1];
uint32_t p_decode_trns[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_skip_frame[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
uint32_t p_decode_pass[1];
uint32_t p_tell_me_more[1];
uint32_t p_do_tell_me_more[1];
wuffs_base__status (*choosy_filter_and_swizzle)(
wuffs_png__decoder* self,
wuffs_base__pixel_buffer* a_dst,
@@ -9786,7 +9864,7 @@ struct wuffs_png__decoder__struct {
struct {
uint32_t v_checksum_have;
uint64_t scratch;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
struct {
uint64_t scratch;
} s_decode_ihdr[1];
@@ -9820,20 +9898,20 @@ struct wuffs_png__decoder__struct {
} s_decode_trns[1];
struct {
uint64_t scratch;
} s_decode_frame_config[1];
} s_do_decode_frame_config[1];
struct {
uint64_t scratch;
} s_skip_frame[1];
struct {
uint64_t scratch;
} s_decode_frame[1];
} s_do_decode_frame[1];
struct {
uint64_t scratch;
} s_decode_pass[1];
struct {
wuffs_base__status v_zlib_status;
uint64_t scratch;
} s_tell_me_more[1];
} s_do_tell_me_more[1];
} private_data;
#ifdef __cplusplus
@@ -9981,10 +10059,15 @@ struct wuffs_png__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_tga__error__bad_header[];
extern const char wuffs_tga__error__bad_run_length_encoding[];
extern const char wuffs_tga__error__truncated_input[];
extern const char wuffs_tga__error__unsupported_tga_file[];
// ---------------- Public Consts
@@ -10155,8 +10238,11 @@ struct wuffs_tga__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
} private_impl;
struct {
@@ -10167,7 +10253,7 @@ struct wuffs_tga__decoder__struct {
struct {
uint32_t v_i;
uint64_t scratch;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
struct {
uint64_t v_dst_bytes_per_pixel;
uint32_t v_dst_x;
@@ -10178,7 +10264,7 @@ struct wuffs_tga__decoder__struct {
uint32_t v_run_length;
uint64_t v_num_dst_bytes;
uint64_t scratch;
} s_decode_frame[1];
} s_do_decode_frame[1];
} private_data;
#ifdef __cplusplus
@@ -10326,9 +10412,14 @@ struct wuffs_tga__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_wbmp__error__bad_header[];
extern const char wuffs_wbmp__error__truncated_input[];
// ---------------- Public Consts
@@ -10486,22 +10577,25 @@ struct wuffs_wbmp__decoder__struct {
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config[1];
uint32_t p_do_decode_image_config[1];
uint32_t p_decode_frame_config[1];
uint32_t p_do_decode_frame_config[1];
uint32_t p_decode_frame[1];
uint32_t p_do_decode_frame[1];
} private_impl;
struct {
struct {
uint32_t v_i;
uint32_t v_x32;
} s_decode_image_config[1];
} s_do_decode_image_config[1];
struct {
uint64_t v_dst_bytes_per_pixel;
uint32_t v_dst_x;
uint32_t v_dst_y;
uint8_t v_src[1];
uint8_t v_c;
} s_decode_frame[1];
} s_do_decode_frame[1];
} private_data;
#ifdef __cplusplus
@@ -10649,6 +10743,8 @@ struct wuffs_wbmp__decoder__struct {
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP) || defined(WUFFS_NONMONOLITHIC)
#if defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
// ---------------- Auxiliary - Base
@@ -13698,14 +13794,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
uint8_t* q = s.ptr + s.len;
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
// Parse sign.
do {
@@ -13718,14 +13812,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
break;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
} while (0);
// Parse digits, up to (and including) a '.', 'E' or 'e'. Examples for each
@@ -13777,9 +13869,12 @@ wuffs_base__private_implementation__high_prec_dec__parse(
if (nd < WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__DIGITS_PRECISION) {
h->digits[nd++] = (uint8_t)(*p - '0');
dp = (int32_t)nd;
} else if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
} else {
dp++;
if ('0' != *p) {
// Long-tail non-zeroes set the truncated bit.
h->truncated = true;
}
}
} else if (*p ==
((options &
@@ -13839,14 +13934,12 @@ after_sep:
after_exp:
do {
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {
for (;; p++) {
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
} else if (*p != '_') {
break;
}
for (; (p < q) && (*p == '_'); p++) {
}
}
if (p >= q) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
int32_t exp_sign = +1;
if (*p == '+') {
@@ -14686,6 +14779,27 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// powers converts decimal powers of 10 to binary powers of 2. For example,
// (10000 >> 13) is 1. It stops before the elements exceed 60, also known
// as WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
//
// This rounds down (1<<13 is a lower bound for 1e4). Adding 1 to the array
// element value rounds up (1<<14 is an upper bound for 1e4) while staying
// at or below WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL.
//
// When starting in the range [1e+1 .. 1e+2] (i.e. h->decimal_point == +2),
// powers[2] == 6 and so:
// - Right shifting by 6+0 produces the range [10/64 .. 100/64] =
// [0.156250 .. 1.56250]. The resultant h->decimal_point is +0 or +1.
// - Right shifting by 6+1 produces the range [10/128 .. 100/128] =
// [0.078125 .. 0.78125]. The resultant h->decimal_point is -1 or -0.
//
// When starting in the range [1e-3 .. 1e-2] (i.e. h->decimal_point == -2),
// powers[2] == 6 and so:
// - Left shifting by 6+0 produces the range [0.001*64 .. 0.01*64] =
// [0.064 .. 0.64]. The resultant h->decimal_point is -1 or -0.
// - Left shifting by 6+1 produces the range [0.001*128 .. 0.01*128] =
// [0.128 .. 1.28]. The resultant h->decimal_point is +0 or +1.
//
// Thus, when targeting h->decimal_point being +0 or +1, use (powers[n]+0)
// when right shifting but (powers[n]+1) when left shifting.
static const uint32_t num_powers = 19;
static const uint8_t powers[19] = {
0, 3, 6, 9, 13, 16, 19, 23, 26, 29, //
@@ -14705,36 +14819,54 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
// approach taken in wuffs_base__parse_number_f64. The latter is optimized
// for the common cases (e.g. assuming no underscores or a leading '+'
// sign) rather than the full set of cases allowed by the Wuffs API.
if (h->num_digits <= 19) {
//
// When we have 19 or fewer mantissa digits, run Eisel-Lemire once (trying
// for an exact result). When we have more than 19 mantissa digits, run it
// twice to get a lower and upper bound. We still have an exact result
// (within f64's rounding margin) if both bounds are equal (and valid).
uint32_t i_max = h->num_digits;
if (i_max > 19) {
i_max = 19;
}
int32_t exp10 = h->decimal_point - ((int32_t)i_max);
if ((-307 <= exp10) && (exp10 <= 288)) {
uint64_t man = 0;
uint32_t i;
for (i = 0; i < h->num_digits; i++) {
for (i = 0; i < i_max; i++) {
man = (10 * man) + h->digits[i];
}
int32_t exp10 = h->decimal_point - ((int32_t)(h->num_digits));
if ((man != 0) && (-307 <= exp10) && (exp10 <= 288)) {
int64_t r =
while (man != 0) { // The 'while' is just an 'if' that we can 'break'.
int64_t r0 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man, exp10);
if (r >= 0) {
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r) | (((uint64_t)(h->negative)) << 63));
return ret;
man + 0, exp10);
if (r0 < 0) {
break;
} else if (h->num_digits > 19) {
int64_t r1 =
wuffs_base__private_implementation__parse_number_f64_eisel_lemire(
man + 1, exp10);
if (r1 != r0) {
break;
}
}
wuffs_base__result_f64 ret;
ret.status.repr = NULL;
ret.value = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
((uint64_t)r0) | (((uint64_t)(h->negative)) << 63));
return ret;
}
}
// When Eisel-Lemire fails, fall back to Simple Decimal Conversion. See
// https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html
//
// Scale by powers of 2 until we're in the range [½ .. 1], which gives us
// our exponent (in base-2). First we shift right, possibly a little too
// far, ending with a value certainly below 1 and possibly below ½...
// Scale by powers of 2 until we're in the range [0.1 .. 10]. Equivalently,
// that h->decimal_point is +0 or +1.
//
// First we shift right while at or above 10...
const int32_t f64_bias = -1023;
int32_t exp2 = 0;
while (h->decimal_point > 0) {
while (h->decimal_point > 1) {
uint32_t n = (uint32_t)(+h->decimal_point);
uint32_t shift =
(n < num_powers)
@@ -14748,20 +14880,15 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
}
exp2 += (int32_t)shift;
}
// ...then we shift left, putting us in [½ .. 1].
while (h->decimal_point <= 0) {
// ...then we shift left while below 0.1.
while (h->decimal_point < 0) {
uint32_t shift;
if (h->decimal_point == 0) {
if (h->digits[0] >= 5) {
break;
}
shift = (h->digits[0] < 2) ? 2 : 1;
} else {
uint32_t n = (uint32_t)(-h->decimal_point);
shift = (n < num_powers)
? powers[n]
: WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
}
uint32_t n = (uint32_t)(-h->decimal_point);
shift = (n < num_powers)
// The +1 is per "when targeting h->decimal_point being +0 or
// +1... when left shifting" in the powers comment above.
? (powers[n] + 1)
: WUFFS_BASE__PRIVATE_IMPLEMENTATION__HPD__SHIFT__MAX_INCL;
wuffs_base__private_implementation__high_prec_dec__small_lshift(h, shift);
if (h->decimal_point >
@@ -14771,8 +14898,37 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
exp2 -= (int32_t)shift;
}
// We're in the range [½ .. 1] but f64 uses [1 .. 2].
exp2--;
// To get from "in the range [0.1 .. 10]" to "in the range [1 .. 2]" (which
// will give us our exponent in base-2), the mantissa's first 3 digits will
// determine the final left shift, equal to 52 (the number of explicit f64
// bits) plus an additional adjustment.
int man3 = (100 * h->digits[0]) +
((h->num_digits > 1) ? (10 * h->digits[1]) : 0) +
((h->num_digits > 2) ? h->digits[2] : 0);
int32_t additional_lshift = 0;
if (h->decimal_point == 0) { // The value is in [0.1 .. 1].
if (man3 < 125) {
additional_lshift = +4;
} else if (man3 < 250) {
additional_lshift = +3;
} else if (man3 < 500) {
additional_lshift = +2;
} else {
additional_lshift = +1;
}
} else { // The value is in [1 .. 10].
if (man3 < 200) {
additional_lshift = -0;
} else if (man3 < 400) {
additional_lshift = -1;
} else if (man3 < 800) {
additional_lshift = -2;
} else {
additional_lshift = -3;
}
}
exp2 -= additional_lshift;
uint32_t final_lshift = (uint32_t)(52 + additional_lshift);
// The minimum normal exponent is (f64_bias + 1).
while ((f64_bias + 1) > exp2) {
@@ -14790,7 +14946,8 @@ wuffs_base__private_implementation__high_prec_dec__to_f64(
}
// Extract 53 bits for the mantissa (in base-2).
wuffs_base__private_implementation__high_prec_dec__small_lshift(h, 53);
wuffs_base__private_implementation__high_prec_dec__small_lshift(
h, final_lshift);
uint64_t man2 =
wuffs_base__private_implementation__high_prec_dec__rounded_integer(h);
@@ -15591,6 +15748,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto hexadecimal;
}
goto fail_bad_argument;
} else if ((*p == 'd') || (*p == 'D')) {
p++;
@@ -15601,6 +15759,7 @@ wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (p < q) {
goto decimal;
}
goto fail_bad_argument;
}
if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {
@@ -22473,6 +22632,7 @@ wuffs_adler32__hasher__up_x86_sse42(
const char wuffs_bmp__error__bad_header[] = "#bmp: bad header";
const char wuffs_bmp__error__bad_rle_compression[] = "#bmp: bad RLE compression";
const char wuffs_bmp__error__truncated_input[] = "#bmp: truncated input";
const char wuffs_bmp__error__unsupported_bmp_file[] = "#bmp: unsupported BMP file";
const char wuffs_bmp__note__internal_note_short_read[] = "@bmp: internal note: short read";
@@ -22510,6 +22670,27 @@ const char wuffs_bmp__note__internal_note_short_read[] = "@bmp: internal note: s
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_bmp__decoder__do_decode_image_config(
wuffs_bmp__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bmp__decoder__do_decode_frame_config(
wuffs_bmp__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bmp__decoder__do_decode_frame(
wuffs_bmp__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
static wuffs_base__status
wuffs_bmp__decoder__swizzle_none(
wuffs_bmp__decoder* self,
@@ -22534,6 +22715,13 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bmp__decoder__do_tell_me_more(
wuffs_bmp__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bmp__decoder__read_palette(
wuffs_bmp__decoder* self,
@@ -22688,6 +22876,52 @@ wuffs_bmp__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bmp__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bmp.decoder.do_decode_image_config
static wuffs_base__status
wuffs_bmp__decoder__do_decode_image_config(
wuffs_bmp__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_magic = 0;
uint32_t v_width = 0;
uint32_t v_height = 0;
@@ -22699,14 +22933,14 @@ wuffs_bmp__decoder__decode_image_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -22724,14 +22958,14 @@ wuffs_bmp__decoder__decode_image_config(
t_0 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22750,15 +22984,15 @@ wuffs_bmp__decoder__decode_image_config(
status = wuffs_base__make_status(wuffs_bmp__error__bad_header);
goto exit;
}
self->private_data.s_decode_image_config[0].scratch = 8;
self->private_data.s_do_decode_image_config[0].scratch = 8;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
uint32_t t_1;
@@ -22766,14 +23000,14 @@ wuffs_bmp__decoder__decode_image_config(
t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22801,14 +23035,14 @@ wuffs_bmp__decoder__decode_image_config(
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22836,14 +23070,14 @@ wuffs_bmp__decoder__decode_image_config(
t_3 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22865,14 +23099,14 @@ wuffs_bmp__decoder__decode_image_config(
t_4 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22894,14 +23128,14 @@ wuffs_bmp__decoder__decode_image_config(
t_5 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22927,14 +23161,14 @@ wuffs_bmp__decoder__decode_image_config(
t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_6 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22957,14 +23191,14 @@ wuffs_bmp__decoder__decode_image_config(
t_7 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_7 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -22991,14 +23225,14 @@ wuffs_bmp__decoder__decode_image_config(
t_8 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_8 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23025,14 +23259,14 @@ wuffs_bmp__decoder__decode_image_config(
t_9 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(21);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_9 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23058,14 +23292,14 @@ wuffs_bmp__decoder__decode_image_config(
t_10 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(23);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_10 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23088,14 +23322,14 @@ wuffs_bmp__decoder__decode_image_config(
t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(25);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_11 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23122,14 +23356,14 @@ wuffs_bmp__decoder__decode_image_config(
t_12 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(27);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_12 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23160,14 +23394,14 @@ wuffs_bmp__decoder__decode_image_config(
t_13 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(29);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_13 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23193,14 +23427,14 @@ wuffs_bmp__decoder__decode_image_config(
t_14 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(31);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_14 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23222,14 +23456,14 @@ wuffs_bmp__decoder__decode_image_config(
t_15 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(33);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_15 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23257,15 +23491,15 @@ wuffs_bmp__decoder__decode_image_config(
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
self->private_data.s_decode_image_config[0].scratch = 20;
self->private_data.s_do_decode_image_config[0].scratch = 20;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(34);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
if (self->private_impl.f_bitmap_info_len == 40) {
if (self->private_impl.f_bits_per_pixel >= 16) {
if (self->private_impl.f_padding >= 16) {
@@ -23296,14 +23530,14 @@ wuffs_bmp__decoder__decode_image_config(
t_16 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(36);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_16 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23325,14 +23559,14 @@ wuffs_bmp__decoder__decode_image_config(
t_17 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(38);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_17 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23354,14 +23588,14 @@ wuffs_bmp__decoder__decode_image_config(
t_18 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(40);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_18 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23384,14 +23618,14 @@ wuffs_bmp__decoder__decode_image_config(
t_19 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(42);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_19 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -23406,15 +23640,15 @@ wuffs_bmp__decoder__decode_image_config(
}
self->private_impl.f_channel_masks[3] = t_19;
}
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_bitmap_info_len - 56));
self->private_data.s_do_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_bitmap_info_len - 56));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(43);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
}
if ((self->private_impl.f_channel_masks[0] == 255) && (self->private_impl.f_channel_masks[1] == 65280) && (self->private_impl.f_channel_masks[2] == 16711680)) {
if (self->private_impl.f_bits_per_pixel == 24) {
@@ -23432,15 +23666,15 @@ wuffs_bmp__decoder__decode_image_config(
}
}
} else if (self->private_impl.f_bitmap_info_len >= 40) {
self->private_data.s_decode_image_config[0].scratch = (self->private_impl.f_bitmap_info_len - 40);
self->private_data.s_do_decode_image_config[0].scratch = (self->private_impl.f_bitmap_info_len - 40);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(45);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
} else {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
@@ -23563,24 +23797,20 @@ wuffs_bmp__decoder__decode_image_config(
self->private_impl.f_call_sequence = 32;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -23612,18 +23842,64 @@ wuffs_bmp__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bmp__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bmp.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_bmp__decoder__do_decode_frame_config(
wuffs_bmp__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -23633,7 +23909,7 @@ wuffs_bmp__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_bmp__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_bmp__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -23672,24 +23948,20 @@ wuffs_bmp__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -23726,18 +23998,72 @@ wuffs_bmp__decoder__decode_frame(
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bmp__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bmp.decoder.do_decode_frame
static wuffs_base__status
wuffs_bmp__decoder__do_decode_frame(
wuffs_bmp__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -23747,7 +24073,7 @@ wuffs_bmp__decoder__decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_bmp__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_bmp__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -23758,15 +24084,15 @@ wuffs_bmp__decoder__decode_frame(
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
self->private_data.s_decode_frame[0].scratch = self->private_impl.f_padding;
self->private_data.s_do_decode_frame[0].scratch = self->private_impl.f_padding;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame[0].scratch;
if ((self->private_impl.f_width > 0) && (self->private_impl.f_height > 0)) {
self->private_impl.f_dst_x = 0;
if (self->private_impl.f_top_down) {
@@ -23842,38 +24168,34 @@ wuffs_bmp__decoder__decode_frame(
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
}
label__0__break:;
self->private_data.s_decode_frame[0].scratch = self->private_impl.f_pending_pad;
self->private_data.s_do_decode_frame[0].scratch = self->private_impl.f_pending_pad;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame[0].scratch;
self->private_impl.f_pending_pad = 0;
}
self->private_impl.f_call_sequence = 96;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -23890,17 +24212,19 @@ wuffs_bmp__decoder__swizzle_none(
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint32_t v_src_bytes_per_pixel = 0;
wuffs_base__slice_u8 v_dst_palette = {0};
wuffs_base__table_u8 v_tab = {0};
wuffs_base__slice_u8 v_dst = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
uint64_t v_n = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -23927,7 +24251,6 @@ wuffs_bmp__decoder__swizzle_none(
self->private_impl.f_pending_pad -= 1;
iop_a_src += 1;
}
label__inner__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -23948,14 +24271,38 @@ wuffs_bmp__decoder__swizzle_none(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__inner__continue;
if (self->private_impl.f_bits_per_pixel > 32) {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
v_src_bytes_per_pixel = (self->private_impl.f_bits_per_pixel / 8);
if (v_src_bytes_per_pixel == 0) {
status = wuffs_base__make_status(wuffs_bmp__error__unsupported_bmp_file);
goto exit;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
v_j = v_n;
while (v_j >= 8) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
iop_a_src += (v_src_bytes_per_pixel * 8);
}
v_j -= 8;
}
while (v_j > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
iop_a_src += (v_src_bytes_per_pixel * 1);
}
v_j -= 1;
}
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
v_dst_palette,
&iop_a_src,
io2_a_src);
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
v_dst_palette,
&iop_a_src,
io2_a_src);
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
@@ -23970,7 +24317,7 @@ wuffs_bmp__decoder__swizzle_none(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24007,7 +24354,7 @@ wuffs_bmp__decoder__swizzle_rle(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -24232,7 +24579,7 @@ wuffs_bmp__decoder__swizzle_rle(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24269,7 +24616,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -24296,7 +24643,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
self->private_impl.f_pending_pad -= 1;
iop_a_src += 1;
}
label__inner__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -24355,9 +24701,10 @@ wuffs_bmp__decoder__swizzle_bitfields(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__inner__continue;
v_n = ((uint64_t)(v_p0));
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, (8 * v_p0)));
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
@@ -24372,7 +24719,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24400,12 +24747,13 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
uint32_t v_p0 = 0;
uint32_t v_chunk_bits = 0;
uint32_t v_chunk_count = 0;
uint32_t v_pixels_per_chunk = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -24437,6 +24785,35 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
if (self->private_impl.f_bits_per_pixel == 1) {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 31) / 32);
v_pixels_per_chunk = 32;
} else if (self->private_impl.f_bits_per_pixel == 2) {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 15) / 16);
v_pixels_per_chunk = 16;
} else {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
v_pixels_per_chunk = 8;
}
while ((v_chunk_count >= 64) && (((uint64_t)(io2_a_src - iop_a_src)) >= 256)) {
iop_a_src += 256;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 64))));
v_chunk_count -= 64;
}
while ((v_chunk_count >= 8) && (((uint64_t)(io2_a_src - iop_a_src)) >= 32)) {
iop_a_src += 32;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 8))));
v_chunk_count -= 8;
}
while (v_chunk_count > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
status = wuffs_base__make_status(wuffs_bmp__note__internal_note_short_read);
goto ok;
}
iop_a_src += 4;
self->private_impl.f_dst_x = wuffs_base__u32__min(self->private_impl.f_width, ((uint32_t)(self->private_impl.f_dst_x + (v_pixels_per_chunk * 1))));
v_chunk_count -= 1;
}
goto label__loop__continue;
}
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i);
@@ -24507,7 +24884,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
v_p0 = ((v_p0 & 511) + 16);
v_chunk_count -= 1;
}
} else if (self->private_impl.f_bits_per_pixel == 4) {
} else {
v_chunk_count = ((wuffs_base__u32__sat_sub(self->private_impl.f_width, self->private_impl.f_dst_x) + 7) / 8);
v_chunk_count = wuffs_base__u32__min(v_chunk_count, 64);
while ((v_chunk_count > 0) && (((uint64_t)(io2_a_src - iop_a_src)) >= 4)) {
@@ -24540,7 +24917,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24688,6 +25065,53 @@ wuffs_bmp__decoder__tell_me_more(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bmp__decoder__do_tell_me_more(self, a_dst, a_minfo, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bmp.decoder.do_tell_me_more
static wuffs_base__status
wuffs_bmp__decoder__do_tell_me_more(
wuffs_bmp__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
if (self->private_impl.f_io_redirect_fourcc <= 1) {
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
@@ -24706,9 +25130,6 @@ wuffs_bmp__decoder__tell_me_more(
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -24743,7 +25164,7 @@ wuffs_bmp__decoder__read_palette(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -24857,7 +25278,7 @@ wuffs_bmp__decoder__read_palette(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -24921,6 +25342,7 @@ const char wuffs_bzip2__error__bad_block_length[] = "#bzip2: bad block length";
const char wuffs_bzip2__error__bad_checksum[] = "#bzip2: bad checksum";
const char wuffs_bzip2__error__bad_header[] = "#bzip2: bad header";
const char wuffs_bzip2__error__bad_number_of_sections[] = "#bzip2: bad number of sections";
const char wuffs_bzip2__error__truncated_input[] = "#bzip2: truncated input";
const char wuffs_bzip2__error__unsupported_block_randomization[] = "#bzip2: unsupported block randomization";
const char wuffs_bzip2__error__internal_error_inconsistent_huffman_decoder_state[] = "#bzip2: internal error: inconsistent Huffman decoder state";
@@ -24971,6 +25393,13 @@ WUFFS_BZIP2__REV_CRC32_TABLE[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_bzip2__decoder__do_transform_io(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
static wuffs_base__status
wuffs_bzip2__decoder__prepare_block(
wuffs_bzip2__decoder* self,
@@ -25165,6 +25594,53 @@ wuffs_bzip2__decoder__transform_io(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_bzip2__decoder__do_transform_io(self, a_dst, a_src, a_workbuf);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_bzip2__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func bzip2.decoder.do_transform_io
static wuffs_base__status
wuffs_bzip2__decoder__do_transform_io(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint32_t v_i = 0;
uint64_t v_tag = 0;
@@ -25175,18 +25651,18 @@ wuffs_bzip2__decoder__transform_io(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
uint32_t coro_susp_point = self->private_impl.p_do_transform_io[0];
if (coro_susp_point) {
v_i = self->private_data.s_transform_io[0].v_i;
v_tag = self->private_data.s_transform_io[0].v_tag;
v_final_checksum_want = self->private_data.s_transform_io[0].v_final_checksum_want;
v_i = self->private_data.s_do_transform_io[0].v_i;
v_tag = self->private_data.s_do_transform_io[0].v_tag;
v_final_checksum_want = self->private_data.s_do_transform_io[0].v_final_checksum_want;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -25375,27 +25851,23 @@ wuffs_bzip2__decoder__transform_io(
goto ok;
ok:
self->private_impl.p_transform_io[0] = 0;
self->private_impl.p_do_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_transform_io[0].v_i = v_i;
self->private_data.s_transform_io[0].v_tag = v_tag;
self->private_data.s_transform_io[0].v_final_checksum_want = v_final_checksum_want;
self->private_impl.p_do_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_transform_io[0].v_i = v_i;
self->private_data.s_do_transform_io[0].v_tag = v_tag;
self->private_data.s_do_transform_io[0].v_final_checksum_want = v_final_checksum_want;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -25419,7 +25891,7 @@ wuffs_bzip2__decoder__prepare_block(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -25713,7 +26185,7 @@ wuffs_bzip2__decoder__prepare_block(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -25736,7 +26208,7 @@ wuffs_bzip2__decoder__read_code_lengths(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -25841,7 +26313,7 @@ wuffs_bzip2__decoder__read_code_lengths(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -26014,7 +26486,7 @@ wuffs_bzip2__decoder__flush_fast(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -26067,7 +26539,7 @@ wuffs_bzip2__decoder__flush_fast(
if (v_block_size <= 900000) {
self->private_impl.f_block_size = v_block_size;
}
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
@@ -26094,7 +26566,7 @@ wuffs_bzip2__decoder__flush_slow(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -26188,7 +26660,7 @@ wuffs_bzip2__decoder__flush_slow(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
@@ -26223,7 +26695,7 @@ wuffs_bzip2__decoder__decode_huffman_fast(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -26318,7 +26790,7 @@ wuffs_bzip2__decoder__decode_huffman_fast(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -26347,7 +26819,7 @@ wuffs_bzip2__decoder__decode_huffman_slow(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -26451,7 +26923,7 @@ wuffs_bzip2__decoder__decode_huffman_slow(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -26648,7 +27120,7 @@ wuffs_cbor__decoder__decode_tokens(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -26661,7 +27133,7 @@ wuffs_cbor__decoder__decode_tokens(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -27185,10 +27657,10 @@ wuffs_cbor__decoder__decode_tokens(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -28358,6 +28830,7 @@ const char wuffs_deflate__error__bad_literal_length_code_count[] = "#deflate: ba
const char wuffs_deflate__error__inconsistent_stored_block_length[] = "#deflate: inconsistent stored block length";
const char wuffs_deflate__error__missing_end_of_block_code[] = "#deflate: missing end-of-block code";
const char wuffs_deflate__error__no_huffman_codes[] = "#deflate: no Huffman codes";
const char wuffs_deflate__error__truncated_input[] = "#deflate: truncated input";
const char wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state[] = "#deflate: internal error: inconsistent Huffman decoder state";
const char wuffs_deflate__error__internal_error_inconsistent_i_o[] = "#deflate: internal error: inconsistent I/O";
const char wuffs_deflate__error__internal_error_inconsistent_distance[] = "#deflate: internal error: inconsistent distance";
@@ -28432,6 +28905,13 @@ WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[32] WUFFS_BASE__POTENTIALLY_UNUSED = {
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_deflate__decoder__do_transform_io(
wuffs_deflate__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
static wuffs_base__status
wuffs_deflate__decoder__decode_blocks(
wuffs_deflate__decoder* self,
@@ -28675,6 +29155,53 @@ wuffs_deflate__decoder__transform_io(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_deflate__decoder__do_transform_io(self, a_dst, a_src, a_workbuf);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_deflate__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func deflate.decoder.do_transform_io
static wuffs_base__status
wuffs_deflate__decoder__do_transform_io(
wuffs_deflate__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint64_t v_mark = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
@@ -28682,7 +29209,7 @@ wuffs_deflate__decoder__transform_io(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -28692,7 +29219,7 @@ wuffs_deflate__decoder__transform_io(
}
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
uint32_t coro_susp_point = self->private_impl.p_do_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -28730,24 +29257,20 @@ wuffs_deflate__decoder__transform_io(
}
ok:
self->private_impl.p_transform_io[0] = 0;
self->private_impl.p_do_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_impl.p_do_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -28769,7 +29292,7 @@ wuffs_deflate__decoder__decode_blocks(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -28898,7 +29421,7 @@ wuffs_deflate__decoder__decode_blocks(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -28921,7 +29444,7 @@ wuffs_deflate__decoder__decode_uncompressed(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -28934,7 +29457,7 @@ wuffs_deflate__decoder__decode_uncompressed(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -29017,10 +29540,10 @@ wuffs_deflate__decoder__decode_uncompressed(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -29104,7 +29627,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -29325,7 +29848,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -29618,7 +30141,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -29631,7 +30154,7 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -29792,10 +30315,10 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
}
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -29831,7 +30354,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -29844,7 +30367,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -30050,10 +30573,10 @@ wuffs_deflate__decoder__decode_huffman_fast32(
}
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -30095,7 +30618,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -30108,7 +30631,7 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -30269,10 +30792,10 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
}
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -30312,7 +30835,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -30325,7 +30848,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -30604,10 +31127,10 @@ wuffs_deflate__decoder__decode_huffman_slow(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -30621,6 +31144,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
// ---------------- Status Codes Implementations
const char wuffs_lzw__error__bad_code[] = "#lzw: bad code";
const char wuffs_lzw__error__truncated_input[] = "#lzw: truncated input";
const char wuffs_lzw__error__internal_error_inconsistent_i_o[] = "#lzw: internal error: inconsistent I/O";
// ---------------- Private Consts
@@ -30843,6 +31367,9 @@ wuffs_lzw__decoder__transform_io(
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
} else if (self->private_impl.f_read_from_return_value == 3) {
status = wuffs_base__make_status(wuffs_lzw__error__truncated_input);
goto exit;
} else if (self->private_impl.f_read_from_return_value == 4) {
status = wuffs_base__make_status(wuffs_lzw__error__bad_code);
goto exit;
} else {
@@ -30896,7 +31423,7 @@ wuffs_lzw__decoder__read_from(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -30918,7 +31445,11 @@ wuffs_lzw__decoder__read_from(
iop_a_src += ((31 - v_n_bits) >> 3);
v_n_bits |= 24;
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
self->private_impl.f_read_from_return_value = 2;
if (a_src && a_src->meta.closed) {
self->private_impl.f_read_from_return_value = 3;
} else {
self->private_impl.f_read_from_return_value = 2;
}
goto label__0__break;
} else {
v_bits |= (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) << v_n_bits);
@@ -30926,14 +31457,18 @@ wuffs_lzw__decoder__read_from(
v_n_bits += 8;
if (v_n_bits >= v_width) {
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
self->private_impl.f_read_from_return_value = 2;
if (a_src && a_src->meta.closed) {
self->private_impl.f_read_from_return_value = 3;
} else {
self->private_impl.f_read_from_return_value = 2;
}
goto label__0__break;
} else {
v_bits |= (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) << v_n_bits);
iop_a_src += 1;
v_n_bits += 8;
if (v_n_bits < v_width) {
self->private_impl.f_read_from_return_value = 4;
self->private_impl.f_read_from_return_value = 5;
goto label__0__break;
}
}
@@ -31011,7 +31546,7 @@ wuffs_lzw__decoder__read_from(
v_prev_code = v_code;
}
} else {
self->private_impl.f_read_from_return_value = 3;
self->private_impl.f_read_from_return_value = 4;
goto label__0__break;
}
if (v_output_wi > 4095) {
@@ -31026,7 +31561,7 @@ wuffs_lzw__decoder__read_from(
if (iop_a_src > io1_a_src) {
iop_a_src--;
} else {
self->private_impl.f_read_from_return_value = 4;
self->private_impl.f_read_from_return_value = 5;
goto label__2__break;
}
}
@@ -31038,7 +31573,7 @@ wuffs_lzw__decoder__read_from(
self->private_impl.f_bits = v_bits;
self->private_impl.f_n_bits = v_n_bits;
self->private_impl.f_output_wi = v_output_wi;
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -31060,7 +31595,7 @@ wuffs_lzw__decoder__write_to(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -31105,7 +31640,7 @@ wuffs_lzw__decoder__write_to(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
@@ -31148,6 +31683,7 @@ const char wuffs_gif__error__bad_graphic_control[] = "#gif: bad graphic control"
const char wuffs_gif__error__bad_header[] = "#gif: bad header";
const char wuffs_gif__error__bad_literal_width[] = "#gif: bad literal width";
const char wuffs_gif__error__bad_palette[] = "#gif: bad palette";
const char wuffs_gif__error__truncated_input[] = "#gif: truncated input";
const char wuffs_gif__error__internal_error_inconsistent_ri_wi[] = "#gif: internal error: inconsistent ri/wi";
// ---------------- Private Consts
@@ -31199,11 +31735,39 @@ WUFFS_GIF__XMPDATAXMP[11] WUFFS_BASE__POTENTIALLY_UNUSED = {
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_gif__decoder__do_decode_image_config(
wuffs_gif__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_gif__decoder__do_tell_me_more(
wuffs_gif__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_gif__decoder__do_decode_frame_config(
wuffs_gif__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_gif__decoder__skip_frame(
wuffs_gif__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_gif__decoder__do_decode_frame(
wuffs_gif__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
static wuffs_base__empty_struct
wuffs_gif__decoder__reset_gc(
wuffs_gif__decoder* self);
@@ -31433,12 +31997,58 @@ wuffs_gif__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
bool v_ffio = false;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gif__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gif__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gif.decoder.do_decode_image_config
static wuffs_base__status
wuffs_gif__decoder__do_decode_image_config(
wuffs_gif__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
bool v_ffio = false;
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
@@ -31489,20 +32099,16 @@ wuffs_gif__decoder__decode_image_config(
goto ok;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -31557,20 +32163,67 @@ wuffs_gif__decoder__tell_me_more(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gif__decoder__do_tell_me_more(self, a_dst, a_minfo, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gif__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gif.decoder.do_tell_me_more
static wuffs_base__status
wuffs_gif__decoder__do_tell_me_more(
wuffs_gif__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint64_t v_chunk_length = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
uint32_t coro_susp_point = self->private_impl.p_do_tell_me_more[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -31652,24 +32305,20 @@ wuffs_gif__decoder__tell_me_more(
goto ok;
ok:
self->private_impl.p_tell_me_more[0] = 0;
self->private_impl.p_do_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -31822,6 +32471,52 @@ wuffs_gif__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gif__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gif__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gif.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_gif__decoder__do_decode_frame_config(
wuffs_gif__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_background_color = 0;
uint8_t v_flags = 0;
@@ -31829,16 +32524,16 @@ wuffs_gif__decoder__decode_frame_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
if (coro_susp_point) {
v_background_color = self->private_data.s_decode_frame_config[0].v_background_color;
v_background_color = self->private_data.s_do_decode_frame_config[0].v_background_color;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -31853,7 +32548,7 @@ wuffs_gif__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_gif__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_gif__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -31936,25 +32631,21 @@ wuffs_gif__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_data.s_decode_frame_config[0].v_background_color = v_background_color;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_frame_config[0].v_background_color = v_background_color;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -31973,7 +32664,7 @@ wuffs_gif__decoder__skip_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32048,7 +32739,7 @@ wuffs_gif__decoder__skip_frame(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32086,14 +32777,68 @@ wuffs_gif__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gif__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gif__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gif.decoder.do_decode_frame
static wuffs_base__status
wuffs_gif__decoder__do_decode_frame(
wuffs_gif__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64) {
} else if (self->private_impl.f_call_sequence < 64) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_gif__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_gif__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
@@ -32120,20 +32865,16 @@ wuffs_gif__decoder__decode_frame(
self->private_impl.f_call_sequence = 32;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -32163,7 +32904,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32239,7 +32980,7 @@ wuffs_gif__decoder__decode_up_to_id_part1(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32261,7 +33002,7 @@ wuffs_gif__decoder__decode_header(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32312,7 +33053,7 @@ wuffs_gif__decoder__decode_header(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32338,7 +33079,7 @@ wuffs_gif__decoder__decode_lsd(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32514,7 +33255,7 @@ wuffs_gif__decoder__decode_lsd(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32535,7 +33276,7 @@ wuffs_gif__decoder__decode_extension(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32607,7 +33348,7 @@ wuffs_gif__decoder__decode_extension(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32628,7 +33369,7 @@ wuffs_gif__decoder__skip_blocks(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32675,7 +33416,7 @@ wuffs_gif__decoder__skip_blocks(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32701,7 +33442,7 @@ wuffs_gif__decoder__decode_ae(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -32898,7 +33639,7 @@ wuffs_gif__decoder__decode_ae(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -32921,7 +33662,7 @@ wuffs_gif__decoder__decode_gc(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -33028,7 +33769,7 @@ wuffs_gif__decoder__decode_gc(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -33047,7 +33788,7 @@ wuffs_gif__decoder__decode_id_part0(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -33195,7 +33936,7 @@ wuffs_gif__decoder__decode_id_part0(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -33224,7 +33965,7 @@ wuffs_gif__decoder__decode_id_part1(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -33366,7 +34107,7 @@ wuffs_gif__decoder__decode_id_part1(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -33404,7 +34145,7 @@ wuffs_gif__decoder__decode_id_part2(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -33594,7 +34335,7 @@ wuffs_gif__decoder__decode_id_part2(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -33736,6 +34477,7 @@ const char wuffs_gzip__error__bad_checksum[] = "#gzip: bad checksum";
const char wuffs_gzip__error__bad_compression_method[] = "#gzip: bad compression method";
const char wuffs_gzip__error__bad_encoding_flags[] = "#gzip: bad encoding flags";
const char wuffs_gzip__error__bad_header[] = "#gzip: bad header";
const char wuffs_gzip__error__truncated_input[] = "#gzip: truncated input";
// ---------------- Private Consts
@@ -33743,6 +34485,13 @@ const char wuffs_gzip__error__bad_header[] = "#gzip: bad header";
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_gzip__decoder__do_transform_io(
wuffs_gzip__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
// ---------------- VTables
const wuffs_base__io_transformer__func_ptrs
@@ -33907,6 +34656,53 @@ wuffs_gzip__decoder__transform_io(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_gzip__decoder__do_transform_io(self, a_dst, a_src, a_workbuf);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_gzip__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func gzip.decoder.do_transform_io
static wuffs_base__status
wuffs_gzip__decoder__do_transform_io(
wuffs_gzip__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint8_t v_flags = 0;
uint16_t v_xlen = 0;
@@ -33921,7 +34717,7 @@ wuffs_gzip__decoder__transform_io(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -33934,19 +34730,19 @@ wuffs_gzip__decoder__transform_io(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
uint32_t coro_susp_point = self->private_impl.p_do_transform_io[0];
if (coro_susp_point) {
v_flags = self->private_data.s_transform_io[0].v_flags;
v_checksum_got = self->private_data.s_transform_io[0].v_checksum_got;
v_decoded_length_got = self->private_data.s_transform_io[0].v_decoded_length_got;
v_checksum_want = self->private_data.s_transform_io[0].v_checksum_want;
v_flags = self->private_data.s_do_transform_io[0].v_flags;
v_checksum_got = self->private_data.s_do_transform_io[0].v_checksum_got;
v_decoded_length_got = self->private_data.s_do_transform_io[0].v_decoded_length_got;
v_checksum_want = self->private_data.s_do_transform_io[0].v_checksum_want;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -33999,15 +34795,15 @@ wuffs_gzip__decoder__transform_io(
uint8_t t_3 = *iop_a_src++;
v_flags = t_3;
}
self->private_data.s_transform_io[0].scratch = 6;
self->private_data.s_do_transform_io[0].scratch = 6;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (self->private_data.s_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_transform_io[0].scratch;
iop_a_src += self->private_data.s_do_transform_io[0].scratch;
if ((v_flags & 4) != 0) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
@@ -34016,14 +34812,14 @@ wuffs_gzip__decoder__transform_io(
t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -34038,15 +34834,15 @@ wuffs_gzip__decoder__transform_io(
}
v_xlen = t_4;
}
self->private_data.s_transform_io[0].scratch = ((uint32_t)(v_xlen));
self->private_data.s_do_transform_io[0].scratch = ((uint32_t)(v_xlen));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (self->private_data.s_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_transform_io[0].scratch;
iop_a_src += self->private_data.s_do_transform_io[0].scratch;
}
if ((v_flags & 8) != 0) {
while (true) {
@@ -34083,15 +34879,15 @@ wuffs_gzip__decoder__transform_io(
label__1__break:;
}
if ((v_flags & 2) != 0) {
self->private_data.s_transform_io[0].scratch = 2;
self->private_data.s_do_transform_io[0].scratch = 2;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
if (self->private_data.s_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_transform_io[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_transform_io[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_transform_io[0].scratch;
iop_a_src += self->private_data.s_do_transform_io[0].scratch;
}
if ((v_flags & 224) != 0) {
status = wuffs_base__make_status(wuffs_gzip__error__bad_encoding_flags);
@@ -34133,14 +34929,14 @@ wuffs_gzip__decoder__transform_io(
t_8 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_8 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -34162,14 +34958,14 @@ wuffs_gzip__decoder__transform_io(
t_9 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_9 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -34190,31 +34986,27 @@ wuffs_gzip__decoder__transform_io(
}
ok:
self->private_impl.p_transform_io[0] = 0;
self->private_impl.p_do_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_transform_io[0].v_flags = v_flags;
self->private_data.s_transform_io[0].v_checksum_got = v_checksum_got;
self->private_data.s_transform_io[0].v_decoded_length_got = v_decoded_length_got;
self->private_data.s_transform_io[0].v_checksum_want = v_checksum_want;
self->private_impl.p_do_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_transform_io[0].v_flags = v_flags;
self->private_data.s_do_transform_io[0].v_checksum_got = v_checksum_got;
self->private_data.s_do_transform_io[0].v_decoded_length_got = v_decoded_length_got;
self->private_data.s_do_transform_io[0].v_checksum_want = v_checksum_want;
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -34698,7 +35490,7 @@ wuffs_json__decoder__decode_tokens(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -34711,7 +35503,7 @@ wuffs_json__decoder__decode_tokens(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -35641,10 +36433,10 @@ wuffs_json__decoder__decode_tokens(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -35668,7 +36460,7 @@ wuffs_json__decoder__decode_number(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -35783,7 +36575,7 @@ wuffs_json__decoder__decode_number(
goto label__goto_done__break;
}
label__goto_done__break:;
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return (v_n | v_floating_point);
@@ -35803,7 +36595,7 @@ wuffs_json__decoder__decode_digits(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -35833,7 +36625,7 @@ wuffs_json__decoder__decode_digits(
if (v_n == a_n) {
v_n |= 256;
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return v_n;
@@ -35855,7 +36647,7 @@ wuffs_json__decoder__decode_leading(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -35868,7 +36660,7 @@ wuffs_json__decoder__decode_leading(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -35938,10 +36730,10 @@ wuffs_json__decoder__decode_leading(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -35965,7 +36757,7 @@ wuffs_json__decoder__decode_comment(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -35978,7 +36770,7 @@ wuffs_json__decoder__decode_comment(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -36120,10 +36912,10 @@ wuffs_json__decoder__decode_comment(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -36146,7 +36938,7 @@ wuffs_json__decoder__decode_inf_nan(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -36159,7 +36951,7 @@ wuffs_json__decoder__decode_inf_nan(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -36277,10 +37069,10 @@ wuffs_json__decoder__decode_inf_nan(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -36303,7 +37095,7 @@ wuffs_json__decoder__decode_trailer(
wuffs_base__token* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__token* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -36316,7 +37108,7 @@ wuffs_json__decoder__decode_trailer(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -36415,10 +37207,10 @@ wuffs_json__decoder__decode_trailer(
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -36432,6 +37224,7 @@ wuffs_json__decoder__decode_trailer(
// ---------------- Status Codes Implementations
const char wuffs_nie__error__bad_header[] = "#nie: bad header";
const char wuffs_nie__error__truncated_input[] = "#nie: truncated input";
const char wuffs_nie__error__unsupported_nie_file[] = "#nie: unsupported NIE file";
const char wuffs_nie__note__internal_note_short_read[] = "@nie: internal note: short read";
@@ -36441,6 +37234,27 @@ const char wuffs_nie__note__internal_note_short_read[] = "@nie: internal note: s
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_nie__decoder__do_decode_image_config(
wuffs_nie__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_nie__decoder__do_decode_frame_config(
wuffs_nie__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_nie__decoder__do_decode_frame(
wuffs_nie__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
static wuffs_base__status
wuffs_nie__decoder__swizzle(
wuffs_nie__decoder* self,
@@ -36592,20 +37406,66 @@ wuffs_nie__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_nie__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_nie__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func nie.decoder.do_decode_image_config
static wuffs_base__status
wuffs_nie__decoder__do_decode_image_config(
wuffs_nie__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_a = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -36620,14 +37480,14 @@ wuffs_nie__decoder__decode_image_config(
t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -36653,14 +37513,14 @@ wuffs_nie__decoder__decode_image_config(
t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -36696,14 +37556,14 @@ wuffs_nie__decoder__decode_image_config(
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -36730,14 +37590,14 @@ wuffs_nie__decoder__decode_image_config(
t_3 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -36771,24 +37631,20 @@ wuffs_nie__decoder__decode_image_config(
goto ok;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -36820,18 +37676,64 @@ wuffs_nie__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_nie__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_nie__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func nie.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_nie__decoder__do_decode_frame_config(
wuffs_nie__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -36841,7 +37743,7 @@ wuffs_nie__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_nie__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_nie__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -36880,24 +37782,20 @@ wuffs_nie__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -36938,10 +37836,64 @@ wuffs_nie__decoder__decode_frame(
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_nie__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_nie__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func nie.decoder.do_decode_frame
static wuffs_base__status
wuffs_nie__decoder__do_decode_frame(
wuffs_nie__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64) {
} else if (self->private_impl.f_call_sequence < 64) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_nie__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_nie__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
@@ -36988,20 +37940,16 @@ wuffs_nie__decoder__decode_frame(
self->private_impl.f_call_sequence = 96;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -37018,16 +37966,18 @@ wuffs_nie__decoder__swizzle(
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint32_t v_src_bytes_per_pixel = 0;
wuffs_base__table_u8 v_tab = {0};
wuffs_base__slice_u8 v_dst = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
uint64_t v_n = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -37043,7 +37993,6 @@ wuffs_nie__decoder__swizzle(
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
label__0__continue:;
while (true) {
if (self->private_impl.f_dst_x == self->private_impl.f_width) {
self->private_impl.f_dst_x = 0;
@@ -37058,14 +38007,33 @@ wuffs_nie__decoder__swizzle(
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * v_dst_bytes_per_pixel);
if (v_i >= ((uint64_t)(v_dst.len))) {
goto label__0__continue;
v_src_bytes_per_pixel = 4;
if (self->private_impl.f_pixfmt == 2164308923) {
v_src_bytes_per_pixel = 8;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
v_n = wuffs_base__u64__min(v_n, ((uint64_t)(((uint32_t)(self->private_impl.f_width - self->private_impl.f_dst_x)))));
v_j = v_n;
while (v_j >= 8) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 8)))) {
iop_a_src += (v_src_bytes_per_pixel * 8);
}
v_j -= 8;
}
while (v_j > 0) {
if (((uint64_t)(io2_a_src - iop_a_src)) >= ((uint64_t)((v_src_bytes_per_pixel * 1)))) {
iop_a_src += (v_src_bytes_per_pixel * 1);
}
v_j -= 1;
}
} else {
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
wuffs_base__pixel_buffer__palette(a_dst),
&iop_a_src,
io2_a_src);
}
v_n = wuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(
&self->private_impl.f_swizzler,
wuffs_base__slice_u8__subslice_i(v_dst, v_i),
wuffs_base__pixel_buffer__palette(a_dst),
&iop_a_src,
io2_a_src);
if (v_n == 0) {
status = wuffs_base__make_status(wuffs_nie__note__internal_note_short_read);
goto ok;
@@ -37079,7 +38047,7 @@ wuffs_nie__decoder__swizzle(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -37267,6 +38235,7 @@ const char wuffs_zlib__error__bad_compression_method[] = "#zlib: bad compression
const char wuffs_zlib__error__bad_compression_window_size[] = "#zlib: bad compression window size";
const char wuffs_zlib__error__bad_parity_check[] = "#zlib: bad parity check";
const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect dictionary";
const char wuffs_zlib__error__truncated_input[] = "#zlib: truncated input";
// ---------------- Private Consts
@@ -37278,6 +38247,13 @@ const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect diction
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_zlib__decoder__do_transform_io(
wuffs_zlib__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
// ---------------- VTables
const wuffs_base__io_transformer__func_ptrs
@@ -37495,6 +38471,53 @@ wuffs_zlib__decoder__transform_io(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_zlib__decoder__do_transform_io(self, a_dst, a_src, a_workbuf);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_zlib__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func zlib.decoder.do_transform_io
static wuffs_base__status
wuffs_zlib__decoder__do_transform_io(
wuffs_zlib__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint16_t v_x = 0;
uint32_t v_checksum_got = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
@@ -37505,7 +38528,7 @@ wuffs_zlib__decoder__transform_io(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -37518,16 +38541,16 @@ wuffs_zlib__decoder__transform_io(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_transform_io[0];
uint32_t coro_susp_point = self->private_impl.p_do_transform_io[0];
if (coro_susp_point) {
v_checksum_got = self->private_data.s_transform_io[0].v_checksum_got;
v_checksum_got = self->private_data.s_do_transform_io[0].v_checksum_got;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -37544,14 +38567,14 @@ wuffs_zlib__decoder__transform_io(
t_0 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -37588,14 +38611,14 @@ wuffs_zlib__decoder__transform_io(
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -37661,14 +38684,14 @@ wuffs_zlib__decoder__transform_io(
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
self->private_data.s_do_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint64_t* scratch = &self->private_data.s_do_transform_io[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -37690,28 +38713,24 @@ wuffs_zlib__decoder__transform_io(
}
ok:
self->private_impl.p_transform_io[0] = 0;
self->private_impl.p_do_transform_io[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_transform_io[0].v_checksum_got = v_checksum_got;
self->private_impl.p_do_transform_io[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_transform_io[0].v_checksum_got = v_checksum_got;
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -37728,6 +38747,7 @@ const char wuffs_png__error__bad_filter[] = "#png: bad filter";
const char wuffs_png__error__bad_header[] = "#png: bad header";
const char wuffs_png__error__bad_text_chunk_not_latin_1[] = "#png: bad text chunk (not Latin-1)";
const char wuffs_png__error__missing_palette[] = "#png: missing palette";
const char wuffs_png__error__truncated_input[] = "#png: truncated input";
const char wuffs_png__error__unsupported_cgbi_extension[] = "#png: unsupported CgBI extension";
const char wuffs_png__error__unsupported_png_compression_method[] = "#png: unsupported PNG compression method";
const char wuffs_png__error__unsupported_png_file[] = "#png: unsupported PNG file";
@@ -37953,6 +38973,12 @@ wuffs_png__decoder__filter_4_distance_4_x86_sse42(
wuffs_base__slice_u8 a_prev);
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_FAMILY)
static wuffs_base__status
wuffs_png__decoder__do_decode_image_config(
wuffs_png__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_ihdr(
wuffs_png__decoder* self,
@@ -38022,17 +39048,39 @@ wuffs_png__decoder__decode_trns(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__do_decode_frame_config(
wuffs_png__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__skip_frame(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__do_decode_frame(
wuffs_png__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
static wuffs_base__status
wuffs_png__decoder__decode_pass(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src,
wuffs_base__slice_u8 a_workbuf);
static wuffs_base__status
wuffs_png__decoder__do_tell_me_more(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__filter_and_swizzle(
wuffs_png__decoder* self,
@@ -39627,6 +40675,52 @@ wuffs_png__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_png__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func png.decoder.do_decode_image_config
static wuffs_base__status
wuffs_png__decoder__do_decode_image_config(
wuffs_png__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint64_t v_magic = 0;
uint64_t v_mark = 0;
uint32_t v_checksum_have = 0;
@@ -39637,16 +40731,16 @@ wuffs_png__decoder__decode_image_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
if (coro_susp_point) {
v_checksum_have = self->private_data.s_decode_image_config[0].v_checksum_have;
v_checksum_have = self->private_data.s_do_decode_image_config[0].v_checksum_have;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -39662,14 +40756,14 @@ wuffs_png__decoder__decode_image_config(
t_0 = wuffs_base__peek_u64le__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -39695,14 +40789,14 @@ wuffs_png__decoder__decode_image_config(
t_1 = wuffs_base__peek_u64le__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -39761,14 +40855,14 @@ wuffs_png__decoder__decode_image_config(
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -39793,14 +40887,12 @@ wuffs_png__decoder__decode_image_config(
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
label__1__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
goto label__1__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -39860,14 +40952,14 @@ wuffs_png__decoder__decode_image_config(
t_5 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -39917,25 +41009,21 @@ wuffs_png__decoder__decode_image_config(
self->private_impl.f_call_sequence = 32;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_decode_image_config[0].v_checksum_have = v_checksum_have;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_image_config[0].v_checksum_have = v_checksum_have;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -39954,7 +41042,7 @@ wuffs_png__decoder__decode_ihdr(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40133,7 +41221,7 @@ wuffs_png__decoder__decode_ihdr(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40302,7 +41390,7 @@ wuffs_png__decoder__decode_other_chunk(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40480,20 +41568,22 @@ wuffs_png__decoder__decode_other_chunk(
self->private_impl.f_seen_srgb = true;
}
} else if (self->private_impl.f_chunk_type == 1397641844) {
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
if (self->private_impl.f_seen_trns || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_png__decoder__decode_trns(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
} else if (self->private_impl.f_color_type > 3) {
} else {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_png__decoder__decode_trns(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
}
self->private_impl.f_seen_trns = true;
}
@@ -40522,7 +41612,7 @@ wuffs_png__decoder__decode_other_chunk(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40541,7 +41631,7 @@ wuffs_png__decoder__decode_actl(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40635,7 +41725,7 @@ wuffs_png__decoder__decode_actl(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40656,7 +41746,7 @@ wuffs_png__decoder__decode_chrm(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40932,7 +42022,7 @@ wuffs_png__decoder__decode_chrm(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40951,7 +42041,7 @@ wuffs_png__decoder__decode_exif(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -40973,7 +42063,7 @@ wuffs_png__decoder__decode_exif(
ok:
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -40997,7 +42087,7 @@ wuffs_png__decoder__decode_fctl(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41310,7 +42400,7 @@ wuffs_png__decoder__decode_fctl(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41329,7 +42419,7 @@ wuffs_png__decoder__decode_gama(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41391,7 +42481,7 @@ wuffs_png__decoder__decode_gama(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41412,7 +42502,7 @@ wuffs_png__decoder__decode_iccp(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41480,7 +42570,7 @@ wuffs_png__decoder__decode_iccp(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41503,7 +42593,7 @@ wuffs_png__decoder__decode_plte(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41583,7 +42673,7 @@ wuffs_png__decoder__decode_plte(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41602,7 +42692,7 @@ wuffs_png__decoder__decode_srgb(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41644,7 +42734,7 @@ wuffs_png__decoder__decode_srgb(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41667,7 +42757,7 @@ wuffs_png__decoder__decode_trns(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -41829,7 +42919,7 @@ wuffs_png__decoder__decode_trns(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -41864,20 +42954,66 @@ wuffs_png__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_png__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func png.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_png__decoder__do_decode_frame_config(
wuffs_png__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_checksum_have = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -41890,7 +43026,7 @@ wuffs_png__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_png__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -41941,14 +43077,14 @@ wuffs_png__decoder__decode_frame_config(
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_frame_config[0].scratch = 0;
self->private_data.s_do_decode_frame_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_frame_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_frame_config[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -41970,14 +43106,14 @@ wuffs_png__decoder__decode_frame_config(
t_1 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_frame_config[0].scratch = 0;
self->private_data.s_do_decode_frame_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_frame_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_frame_config[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -42004,14 +43140,14 @@ wuffs_png__decoder__decode_frame_config(
t_2 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_frame_config[0].scratch = 0;
self->private_data.s_do_decode_frame_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_frame_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_frame_config[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -42049,15 +43185,15 @@ wuffs_png__decoder__decode_frame_config(
if (status.repr) {
goto suspend;
}
self->private_data.s_decode_frame_config[0].scratch = 4;
self->private_data.s_do_decode_frame_config[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame_config[0].scratch;
goto label__0__break;
}
if (a_src) {
@@ -42076,15 +43212,15 @@ wuffs_png__decoder__decode_frame_config(
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
self->private_data.s_decode_frame_config[0].scratch = 4;
self->private_data.s_do_decode_frame_config[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame_config[0].scratch;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
@@ -42109,24 +43245,20 @@ wuffs_png__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -42144,7 +43276,7 @@ wuffs_png__decoder__skip_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -42161,13 +43293,10 @@ wuffs_png__decoder__skip_frame(
self->private_impl.f_chunk_type_array[3] = 0;
label__0__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
goto label__0__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -42275,7 +43404,7 @@ wuffs_png__decoder__skip_frame(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -42313,6 +43442,60 @@ wuffs_png__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_png__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func png.decoder.do_decode_frame
static wuffs_base__status
wuffs_png__decoder__do_decode_frame(
wuffs_png__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_seq_num = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t v_pass_width = 0;
@@ -42322,14 +43505,14 @@ wuffs_png__decoder__decode_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -42344,7 +43527,7 @@ wuffs_png__decoder__decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_png__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -42352,14 +43535,12 @@ wuffs_png__decoder__decode_frame(
goto suspend;
}
}
label__0__continue:;
while (true) {
while (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
if (a_src && a_src->meta.closed) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (((uint64_t)(io2_a_src - iop_a_src)) < 8) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
goto label__0__continue;
}
self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32)));
@@ -42393,14 +43574,14 @@ wuffs_png__decoder__decode_frame(
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_frame[0].scratch = 0;
self->private_data.s_do_decode_frame[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_frame[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_frame[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
@@ -42428,15 +43609,15 @@ wuffs_png__decoder__decode_frame(
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_data.s_decode_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12);
self->private_data.s_do_decode_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame[0].scratch;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
@@ -42494,14 +43675,12 @@ wuffs_png__decoder__decode_frame(
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
}
if (v_status.repr == wuffs_base__suspension__short_read) {
while (true) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
label__1__break:;
v_status = wuffs_png__decoder__filter_and_swizzle(self, a_dst, a_workbuf);
@@ -42534,24 +43713,20 @@ wuffs_png__decoder__decode_frame(
self->private_impl.f_call_sequence = 32;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -42581,7 +43756,7 @@ wuffs_png__decoder__decode_pass(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
@@ -42616,11 +43791,14 @@ wuffs_png__decoder__decode_pass(
self->private_impl.f_pass_workbuf_length),
((uint64_t)(self->private_impl.f_workbuf_hist_pos_base + self->private_impl.f_workbuf_wi)));
{
const bool o_1_closed_a_src = a_src->meta.closed;
const uint8_t *o_1_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
a_src->meta.wi = n;
}
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
@@ -42643,6 +43821,7 @@ wuffs_png__decoder__decode_pass(
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_workbuf_wi, wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w))));
io2_a_src = o_1_io2_a_src;
if (a_src) {
a_src->meta.closed = o_1_closed_a_src;
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
@@ -42887,7 +44066,7 @@ wuffs_png__decoder__decode_pass(
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -43053,6 +44232,53 @@ wuffs_png__decoder__tell_me_more(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_png__decoder__do_tell_me_more(self, a_dst, a_minfo, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_png__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func png.decoder.do_tell_me_more
static wuffs_base__status
wuffs_png__decoder__do_tell_me_more(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint16_t v_c2 = 0;
wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer();
@@ -43070,7 +44296,7 @@ wuffs_png__decoder__tell_me_more(
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
@@ -43083,16 +44309,16 @@ wuffs_png__decoder__tell_me_more(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
uint32_t coro_susp_point = self->private_impl.p_do_tell_me_more[0];
if (coro_susp_point) {
v_zlib_status = self->private_data.s_tell_me_more[0].v_zlib_status;
v_zlib_status = self->private_data.s_do_tell_me_more[0].v_zlib_status;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -43154,11 +44380,14 @@ wuffs_png__decoder__tell_me_more(
if (self->private_impl.f_metadata_is_zlib_compressed) {
if (self->private_impl.f_chunk_type == 1346585449) {
{
const bool o_0_closed_a_src = a_src->meta.closed;
const uint8_t *o_0_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
a_src->meta.wi = n;
}
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
@@ -43180,6 +44409,7 @@ wuffs_png__decoder__tell_me_more(
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
io2_a_src = o_0_io2_a_src;
if (a_src) {
a_src->meta.closed = o_0_closed_a_src;
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
@@ -43200,11 +44430,14 @@ wuffs_png__decoder__tell_me_more(
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
} else if (self->private_impl.f_chunk_type == 1951945833) {
{
const bool o_1_closed_a_src = a_src->meta.closed;
const uint8_t *o_1_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
a_src->meta.wi = n;
}
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
@@ -43226,6 +44459,7 @@ wuffs_png__decoder__tell_me_more(
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
io2_a_src = o_1_io2_a_src;
if (a_src) {
a_src->meta.closed = o_1_closed_a_src;
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
@@ -43261,11 +44495,14 @@ wuffs_png__decoder__tell_me_more(
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
self->private_impl.f_ztxt_hist_pos);
{
const bool o_3_closed_a_src = a_src->meta.closed;
const uint8_t *o_3_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
a_src->meta.wi = n;
}
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
@@ -43285,6 +44522,7 @@ wuffs_png__decoder__tell_me_more(
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
io2_a_src = o_3_io2_a_src;
if (a_src) {
a_src->meta.closed = o_3_closed_a_src;
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
@@ -43503,15 +44741,15 @@ wuffs_png__decoder__tell_me_more(
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_data.s_tell_me_more[0].scratch = 4;
self->private_data.s_do_tell_me_more[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
iop_a_src += self->private_data.s_do_tell_me_more[0].scratch;
self->private_impl.f_metadata_flavor = 0;
self->private_impl.f_metadata_fourcc = 0;
self->private_impl.f_metadata_x = 0;
@@ -43522,28 +44760,24 @@ wuffs_png__decoder__tell_me_more(
goto ok;
ok:
self->private_impl.p_tell_me_more[0] = 0;
self->private_impl.p_do_tell_me_more[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 4 : 0;
self->private_data.s_tell_me_more[0].v_zlib_status = v_zlib_status;
self->private_impl.p_do_tell_me_more[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_tell_me_more[0].v_zlib_status = v_zlib_status;
goto exit;
exit:
if (a_dst) {
if (a_dst && a_dst->data.ptr) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -43934,6 +45168,7 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding";
const char wuffs_tga__error__truncated_input[] = "#tga: truncated input";
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
// ---------------- Private Consts
@@ -43942,6 +45177,27 @@ const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA fil
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_tga__decoder__do_decode_image_config(
wuffs_tga__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame_config(
wuffs_tga__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame(
wuffs_tga__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
@@ -44087,6 +45343,52 @@ wuffs_tga__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func tga.decoder.do_decode_image_config
static wuffs_base__status
wuffs_tga__decoder__do_decode_image_config(
wuffs_tga__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_c = 0;
uint32_t v_c5 = 0;
uint32_t v_i = 0;
@@ -44095,16 +45397,16 @@ wuffs_tga__decoder__decode_image_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
if (coro_susp_point) {
v_i = self->private_data.s_decode_image_config[0].v_i;
v_i = self->private_data.s_do_decode_image_config[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -44161,14 +45463,14 @@ wuffs_tga__decoder__decode_image_config(
t_3 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44190,14 +45492,14 @@ wuffs_tga__decoder__decode_image_config(
t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44238,15 +45540,15 @@ wuffs_tga__decoder__decode_image_config(
goto exit;
}
}
self->private_data.s_decode_image_config[0].scratch = 4;
self->private_data.s_do_decode_image_config[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
uint32_t t_6;
@@ -44254,14 +45556,14 @@ wuffs_tga__decoder__decode_image_config(
t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_6 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44283,14 +45585,14 @@ wuffs_tga__decoder__decode_image_config(
t_7 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_7 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44370,15 +45672,15 @@ wuffs_tga__decoder__decode_image_config(
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
goto exit;
}
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
self->private_data.s_do_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
iop_a_src += self->private_data.s_do_decode_image_config[0].scratch;
if (self->private_impl.f_header_color_map_type != 0) {
while (v_i < ((uint32_t)(self->private_impl.f_header_color_map_length))) {
if (self->private_impl.f_header_color_map_entry_size == 24) {
@@ -44389,14 +45691,14 @@ wuffs_tga__decoder__decode_image_config(
t_10 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
iop_a_src += 3;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(18);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_10 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44423,14 +45725,14 @@ wuffs_tga__decoder__decode_image_config(
t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(20);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_11 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44457,14 +45759,14 @@ wuffs_tga__decoder__decode_image_config(
t_12 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
self->private_data.s_do_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(22);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint64_t* scratch = &self->private_data.s_do_decode_image_config[0].scratch;
uint32_t num_bits_12 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
@@ -44512,25 +45814,21 @@ wuffs_tga__decoder__decode_image_config(
goto ok;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_decode_image_config[0].v_i = v_i;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_image_config[0].v_i = v_i;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -44562,18 +45860,64 @@ wuffs_tga__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func tga.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame_config(
wuffs_tga__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -44583,7 +45927,7 @@ wuffs_tga__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_tga__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_tga__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -44622,24 +45966,20 @@ wuffs_tga__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -44674,6 +46014,60 @@ wuffs_tga__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func tga.decoder.do_decode_frame
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame(
wuffs_tga__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
@@ -44699,23 +46093,23 @@ wuffs_tga__decoder__decode_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
if (coro_susp_point) {
v_dst_bytes_per_pixel = self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel;
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
v_mark = self->private_data.s_decode_frame[0].v_mark;
v_num_pixels32 = self->private_data.s_decode_frame[0].v_num_pixels32;
v_lit_length = self->private_data.s_decode_frame[0].v_lit_length;
v_run_length = self->private_data.s_decode_frame[0].v_run_length;
v_num_dst_bytes = self->private_data.s_decode_frame[0].v_num_dst_bytes;
v_dst_bytes_per_pixel = self->private_data.s_do_decode_frame[0].v_dst_bytes_per_pixel;
v_dst_x = self->private_data.s_do_decode_frame[0].v_dst_x;
v_dst_y = self->private_data.s_do_decode_frame[0].v_dst_y;
v_mark = self->private_data.s_do_decode_frame[0].v_mark;
v_num_pixels32 = self->private_data.s_do_decode_frame[0].v_num_pixels32;
v_lit_length = self->private_data.s_do_decode_frame[0].v_lit_length;
v_run_length = self->private_data.s_do_decode_frame[0].v_run_length;
v_num_dst_bytes = self->private_data.s_do_decode_frame[0].v_num_dst_bytes;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -44726,7 +46120,7 @@ wuffs_tga__decoder__decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_tga__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_tga__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -44789,15 +46183,15 @@ wuffs_tga__decoder__decode_frame(
v_num_pixels32 = ((uint32_t)(wuffs_base__u64__min(v_num_pixels64, ((uint64_t)(v_lit_length)))));
v_num_dst_bytes = (((uint64_t)(v_num_pixels32)) * v_dst_bytes_per_pixel);
v_num_src_bytes = (v_num_pixels32 * self->private_impl.f_src_bytes_per_pixel);
self->private_data.s_decode_frame[0].scratch = v_num_src_bytes;
self->private_data.s_do_decode_frame[0].scratch = v_num_src_bytes;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
if (self->private_data.s_do_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame[0].scratch;
iop_a_src += self->private_data.s_do_decode_frame[0].scratch;
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
if (v_num_dst_bytes <= ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_num_dst_bytes);
@@ -44962,32 +46356,28 @@ wuffs_tga__decoder__decode_frame(
self->private_impl.f_call_sequence = 96;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
self->private_data.s_decode_frame[0].v_dst_x = v_dst_x;
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
self->private_data.s_decode_frame[0].v_mark = v_mark;
self->private_data.s_decode_frame[0].v_num_pixels32 = v_num_pixels32;
self->private_data.s_decode_frame[0].v_lit_length = v_lit_length;
self->private_data.s_decode_frame[0].v_run_length = v_run_length;
self->private_data.s_decode_frame[0].v_num_dst_bytes = v_num_dst_bytes;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
self->private_data.s_do_decode_frame[0].v_dst_x = v_dst_x;
self->private_data.s_do_decode_frame[0].v_dst_y = v_dst_y;
self->private_data.s_do_decode_frame[0].v_mark = v_mark;
self->private_data.s_do_decode_frame[0].v_num_pixels32 = v_num_pixels32;
self->private_data.s_do_decode_frame[0].v_lit_length = v_lit_length;
self->private_data.s_do_decode_frame[0].v_run_length = v_run_length;
self->private_data.s_do_decode_frame[0].v_num_dst_bytes = v_num_dst_bytes;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -45168,6 +46558,7 @@ wuffs_tga__decoder__workbuf_len(
// ---------------- Status Codes Implementations
const char wuffs_wbmp__error__bad_header[] = "#wbmp: bad header";
const char wuffs_wbmp__error__truncated_input[] = "#wbmp: truncated input";
// ---------------- Private Consts
@@ -45175,6 +46566,27 @@ const char wuffs_wbmp__error__bad_header[] = "#wbmp: bad header";
// ---------------- Private Function Prototypes
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_image_config(
wuffs_wbmp__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_frame_config(
wuffs_wbmp__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_frame(
wuffs_wbmp__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
@@ -45320,6 +46732,52 @@ wuffs_wbmp__decoder__decode_image_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_wbmp__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_wbmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func wbmp.decoder.do_decode_image_config
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_image_config(
wuffs_wbmp__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
uint32_t v_i = 0;
uint32_t v_x32 = 0;
@@ -45329,17 +46787,17 @@ wuffs_wbmp__decoder__decode_image_config(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config[0];
if (coro_susp_point) {
v_i = self->private_data.s_decode_image_config[0].v_i;
v_x32 = self->private_data.s_decode_image_config[0].v_x32;
v_i = self->private_data.s_do_decode_image_config[0].v_i;
v_x32 = self->private_data.s_do_decode_image_config[0].v_x32;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -45412,26 +46870,22 @@ wuffs_wbmp__decoder__decode_image_config(
goto ok;
ok:
self->private_impl.p_decode_image_config[0] = 0;
self->private_impl.p_do_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
self->private_data.s_decode_image_config[0].v_i = v_i;
self->private_data.s_decode_image_config[0].v_x32 = v_x32;
self->private_impl.p_do_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_image_config[0].v_i = v_i;
self->private_data.s_do_decode_image_config[0].v_x32 = v_x32;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -45463,18 +46917,64 @@ wuffs_wbmp__decoder__decode_frame_config(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_wbmp__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_wbmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func wbmp.decoder.do_decode_frame_config
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_frame_config(
wuffs_wbmp__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -45484,7 +46984,7 @@ wuffs_wbmp__decoder__decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_wbmp__decoder__decode_image_config(self, NULL, a_src);
status = wuffs_wbmp__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -45523,24 +47023,20 @@ wuffs_wbmp__decoder__decode_frame_config(
self->private_impl.f_call_sequence = 64;
ok:
self->private_impl.p_decode_frame_config[0] = 0;
self->private_impl.p_do_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
self->private_impl.p_do_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
@@ -45575,6 +47071,60 @@ wuffs_wbmp__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_wbmp__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_wbmp__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func wbmp.decoder.do_decode_frame
static wuffs_base__status
wuffs_wbmp__decoder__do_decode_frame(
wuffs_wbmp__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
@@ -45591,20 +47141,20 @@ wuffs_wbmp__decoder__decode_frame(
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame[0];
if (coro_susp_point) {
v_dst_bytes_per_pixel = self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel;
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
memcpy(v_src, self->private_data.s_decode_frame[0].v_src, sizeof(v_src));
v_c = self->private_data.s_decode_frame[0].v_c;
v_dst_bytes_per_pixel = self->private_data.s_do_decode_frame[0].v_dst_bytes_per_pixel;
v_dst_x = self->private_data.s_do_decode_frame[0].v_dst_x;
v_dst_y = self->private_data.s_do_decode_frame[0].v_dst_y;
memcpy(v_src, self->private_data.s_do_decode_frame[0].v_src, sizeof(v_src));
v_c = self->private_data.s_do_decode_frame[0].v_c;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -45615,7 +47165,7 @@ wuffs_wbmp__decoder__decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_wbmp__decoder__decode_frame_config(self, NULL, a_src);
status = wuffs_wbmp__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -45687,29 +47237,25 @@ wuffs_wbmp__decoder__decode_frame(
self->private_impl.f_call_sequence = 96;
ok:
self->private_impl.p_decode_frame[0] = 0;
self->private_impl.p_do_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
self->private_data.s_decode_frame[0].v_dst_x = v_dst_x;
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
memcpy(self->private_data.s_decode_frame[0].v_src, v_src, sizeof(v_src));
self->private_data.s_decode_frame[0].v_c = v_c;
self->private_impl.p_do_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
self->private_data.s_do_decode_frame[0].v_dst_x = v_dst_x;
self->private_data.s_do_decode_frame[0].v_dst_y = v_dst_y;
memcpy(self->private_data.s_do_decode_frame[0].v_src, v_src, sizeof(v_src));
self->private_data.s_do_decode_frame[0].v_c = v_c;
goto exit;
exit:
if (a_src) {
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
+441
View File
@@ -0,0 +1,441 @@
// 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.
// ----------------
// manual-test-truncated-input tests that decoding truncated versions of
// well-formed files produces a "truncated input" error.
//
// It tests every M-byte prefix of a valid N-byte file, for every positive M
// that satisfies (M < 65536) or ((N - M) <= 1024). The truncation point is
// either within 64 KiB of the start or 1 KiB of the end. It does not test
// every potential M in between, as that would take O(N**2) time.
#include <dirent.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
//
// This can help the compiler ignore or discard unused code, which can produce
// faster compiles and smaller binaries. Other motivations are discussed in the
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__ADLER32
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__BMP
#define WUFFS_CONFIG__MODULE__BZIP2
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__GZIP
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__ZLIB
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../release/c/wuffs-unsupported-snapshot.c"
// ----
#ifndef DST_BUFFER_ARRAY_SIZE
#define DST_BUFFER_ARRAY_SIZE (64 * 1024 * 1024)
#endif
#ifndef WORKBUF_ARRAY_SIZE
#define WORKBUF_ARRAY_SIZE (256 * 1024 * 1024)
#endif
uint8_t g_dst_buffer_array[DST_BUFFER_ARRAY_SIZE] = {0};
uint8_t g_workbuf_array[WORKBUF_ARRAY_SIZE] = {0};
static int g_num_files_processed;
static struct {
char buf[PATH_MAX];
size_t len;
} g_relative_cwd;
// ----
static const char skipped[] = "skipped";
static const char unsupported_file_format[] = "unsupported file format";
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);
switch (fourcc) {
case WUFFS_BASE__FOURCC__BMP:
dec = wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__GIF:
dec = wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__NIE:
dec = wuffs_nie__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__PNG:
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TGA:
dec = wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__WBMP:
dec = wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
break;
default:
return unsupported_file_format;
}
if (!full_decode) {
while (true) {
auto dfc_status = dec->decode_frame_config(nullptr, &src);
if (dfc_status.is_ok()) {
// No-op.
} else if (dfc_status.repr == wuffs_base__note__end_of_data) {
break;
} else {
return dfc_status.message();
}
}
return nullptr;
}
wuffs_base__pixel_config pixcfg = {0};
pixcfg.set(WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL,
WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, 0, 0);
wuffs_base__pixel_buffer pixbuf = {0};
auto sfs_status =
pixbuf.set_from_slice(&pixcfg, wuffs_base__make_slice_u8(nullptr, 0));
if (!sfs_status.is_ok()) {
return sfs_status.message();
}
while (true) {
auto df_status = dec->decode_frame(
&pixbuf, &src, WUFFS_BASE__PIXEL_BLEND__SRC,
wuffs_base__make_slice_u8(g_workbuf_array, WORKBUF_ARRAY_SIZE),
nullptr);
if (df_status.is_ok()) {
// No-op.
} else if (df_status.repr == wuffs_base__note__end_of_data) {
break;
} else {
return df_status.message();
}
}
if (src.meta.ri != src.meta.wi) {
return skipped;
}
return nullptr;
}
static const char* //
handle_io_transformer(wuffs_base__io_buffer src, int32_t fourcc) {
wuffs_base__io_transformer::unique_ptr dec(nullptr, &free);
switch (fourcc) {
case WUFFS_BASE__FOURCC__BZ2:
dec = wuffs_bzip2__decoder::alloc_as__wuffs_base__io_transformer();
break;
case WUFFS_BASE__FOURCC__GZ:
dec = wuffs_gzip__decoder::alloc_as__wuffs_base__io_transformer();
break;
case WUFFS_BASE__FOURCC__ZLIB:
dec = wuffs_zlib__decoder::alloc_as__wuffs_base__io_transformer();
break;
default:
return unsupported_file_format;
}
while (true) {
auto dst = wuffs_base__ptr_u8__writer(&g_dst_buffer_array[0],
DST_BUFFER_ARRAY_SIZE);
auto df_status = dec->transform_io(
&dst, &src,
wuffs_base__make_slice_u8(g_workbuf_array, WORKBUF_ARRAY_SIZE));
if (df_status.is_ok()) {
break;
} else if (df_status.repr == wuffs_base__suspension__short_write) {
// No-op.
} else {
return df_status.message();
}
}
return nullptr;
}
static const char* //
handle_various(wuffs_base__io_buffer src, int32_t fourcc) {
const char* status_msg;
status_msg = handle_image_decoder(src, fourcc, false);
if (status_msg != unsupported_file_format) {
if ((status_msg != nullptr) && !strstr(status_msg, "truncated input")) {
return status_msg;
}
return handle_image_decoder(src, fourcc, true);
}
status_msg = handle_io_transformer(src, fourcc);
if (status_msg != unsupported_file_format) {
return status_msg;
}
return unsupported_file_format;
}
static const char* //
handle_range(wuffs_base__io_buffer src,
int32_t fourcc,
size_t wi_min_incl,
size_t wi_max_excl) {
for (size_t wi = wi_min_incl; wi < wi_max_excl; wi++) {
src.meta.wi = wi;
const char* status_msg = handle_various(src, fourcc);
if ((status_msg != nullptr) && strstr(status_msg, "truncated input")) {
continue;
}
printf("when truncated to %zu bytes: ", wi);
if (status_msg) {
return status_msg;
}
return "have ok; want \"truncated input\"";
}
return nullptr;
}
static const char* //
handle(const uint8_t* ptr, size_t len) {
auto src = wuffs_base__ptr_u8__reader(const_cast<uint8_t*>(ptr), len, true);
int32_t fourcc = wuffs_base__magic_number_guess_fourcc(src.reader_slice(),
src.meta.closed);
if (fourcc <= 0) {
return skipped;
}
// Skip any invalid or unsupported input (when decoded in its entirety).
//
// Unsupported includes ignoring wuffs_base__note__i_o_redirect. We don't
// bother testing truncated PNGs-embedded-in-BMPs because we presumably
// already test truncated PNGs.
const char* status_msg = handle_various(src, fourcc);
if (status_msg) {
return skipped;
}
size_t file_len = src.meta.wi;
if (file_len <= (65536 + 1024)) {
return handle_range(src, fourcc, 1, file_len);
}
status_msg = handle_range(src, fourcc, 1, 65536);
if (status_msg) {
return status_msg;
}
return handle_range(src, fourcc, file_len - 1024, file_len);
}
// ----
static int //
visit(char* filename);
static int //
visit_dir(int fd) {
int cwd_fd = open(".", O_RDONLY, 0);
if (fchdir(fd)) {
printf("failed\n");
fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
return 1;
}
DIR* d = fdopendir(fd);
if (!d) {
printf("failed\n");
fprintf(stderr, "FAIL: fdopendir: %s\n", strerror(errno));
return 1;
}
printf("dir\n");
while (true) {
struct dirent* e = readdir(d);
if (!e) {
break;
}
if ((e->d_name[0] == '\x00') || (e->d_name[0] == '.')) {
continue;
}
int v = visit(e->d_name);
if (v) {
return v;
}
}
if (closedir(d)) {
fprintf(stderr, "FAIL: closedir: %s\n", strerror(errno));
return 1;
}
if (fchdir(cwd_fd)) {
fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
return 1;
}
if (close(cwd_fd)) {
fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
return 1;
}
return 0;
}
static int //
visit_reg(int fd, off_t size) {
if ((size < 0) || (0x7FFFFFFF < size)) {
printf("failed\n");
fprintf(stderr, "FAIL: file size out of bounds");
return 1;
}
void* data = NULL;
if (size > 0) {
data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
printf("failed\n");
fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
return 1;
}
}
const char* msg = handle((const uint8_t*)(data), size);
if (msg) {
printf("%s\n", msg);
} else {
printf("ok\n");
}
if ((size > 0) && munmap(data, size)) {
fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
return 1;
}
if (close(fd)) {
fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
return 1;
}
return (msg && (msg != skipped)) ? 1 : 0;
}
static int //
visit(char* filename) {
g_num_files_processed++;
if (!filename || (filename[0] == '\x00')) {
fprintf(stderr, "FAIL: invalid filename\n");
return 1;
}
int n = printf("- %s%s", g_relative_cwd.buf, filename);
printf("%*s", (60 > n) ? (60 - n) : 1, "");
fflush(stdout);
struct stat z;
int fd = open(filename, O_RDONLY, 0);
if (fd == -1) {
printf("failed\n");
fprintf(stderr, "FAIL: open: %s\n", strerror(errno));
return 1;
}
if (fstat(fd, &z)) {
printf("failed\n");
fprintf(stderr, "FAIL: fstat: %s\n", strerror(errno));
return 1;
}
if (S_ISREG(z.st_mode)) {
return visit_reg(fd, z.st_size);
} else if (!S_ISDIR(z.st_mode)) {
printf("skipped\n");
return 0;
}
size_t old_len = g_relative_cwd.len;
size_t filename_len = strlen(filename);
size_t new_len = old_len + strlen(filename);
bool slash = filename[filename_len - 1] != '/';
if (slash) {
new_len++;
}
if ((filename_len >= PATH_MAX) || (new_len >= PATH_MAX)) {
printf("failed\n");
fprintf(stderr, "FAIL: path is too long\n");
return 1;
}
memcpy(g_relative_cwd.buf + old_len, filename, filename_len);
if (slash) {
g_relative_cwd.buf[new_len - 1] = '/';
}
g_relative_cwd.buf[new_len] = '\x00';
g_relative_cwd.len = new_len;
int v = visit_dir(fd);
g_relative_cwd.buf[old_len] = '\x00';
g_relative_cwd.len = old_len;
return v;
}
int //
main(int argc, char** argv) {
g_num_files_processed = 0;
g_relative_cwd.len = 0;
for (int i = 1; i < argc; i++) {
int v = visit(argv[i]);
if (v) {
return v;
}
}
printf("PASS: %d files processed\n", g_num_files_processed);
return 0;
}
+1 -1
View File
@@ -365,7 +365,7 @@ type bitVector []uint8
// zig packs a pair of non-negative integers (i, j) into a single unique
// non-negative integer, in a zig-zagging pattern:
//
// i=0 i=1 i=2 i=3 i=4 etc
// . i=0 i=1 i=2 i=3 i=4 etc
// j=0: 0 1 3 6 10 ...
// j=1: 2 4 7 11 16 ...
// j=2: 5 8 12 17 23 ...
+4
View File
@@ -229,6 +229,10 @@ print_raw_passthrough(wuffs_base__io_buffer* src,
break;
}
uint64_t n1 = src->reader_length();
while (n1 == 0) {
TRY(read_buffer_from_file(src, f));
n1 = src->reader_length();
}
uint64_t n = wuffs_base__u64__min(n0, n1);
print_hex_dump(src->reader_pointer(), n);
src->meta.ri += n;
+1
View File
@@ -182,6 +182,7 @@ var u64TestCases = []uint64{
0x44B52D02C7E14AF6,
0x46293E5939A08CEA,
0x54B249AD2594C37D,
0x54B2987670ADB613,
0x7BBA44DF832B8D46,
0x7BF06B0BB1FB384C,
0x7C2485CE9E7A065F,
+123 -23
View File
@@ -14,6 +14,7 @@
pub status "#bad header"
pub status "#bad RLE compression"
pub status "#truncated input"
pub status "#unsupported BMP file"
pri status "@internal note: short read"
@@ -49,7 +50,7 @@ pub struct decoder? implements base.image_decoder(
bitmap_info_len : base.u32,
padding : base.u32,
bits_per_pixel : base.u32,
bits_per_pixel : base.u32[..= 0xFFFF],
compression : base.u32,
// channel_etc's indexes are: B, G, R, A. This is in Wuffs' default order,
@@ -85,6 +86,18 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var 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 magic : base.u32
var width : base.u32
var height : base.u32
@@ -370,10 +383,22 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
}
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.decode_image_config?(dst: nullptr, src: args.src)
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"
@@ -406,10 +431,22 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
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.decode_frame_config?(dst: nullptr, src: args.src)
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
@@ -467,10 +504,12 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_row : base.u64
var src_bytes_per_pixel : base.u32[..= 4]
var dst_palette : slice base.u8
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
@@ -515,14 +554,38 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
if i >= dst.length() {
// TODO: advance args.src if the dst pixel_buffer bounds is
// smaller than this BMP's image bounds?
continue.inner
if this.bits_per_pixel > 32 {
return "#unsupported BMP file"
}
src_bytes_per_pixel = this.bits_per_pixel / 8
if src_bytes_per_pixel == 0 {
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)
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: dst_palette,
src: args.src)
}
n = this.swizzler.swizzle_interleaved_from_reader!(
dst: dst[i ..],
dst_palette: dst_palette,
src: args.src)
if n == 0 {
return "@internal note: short read"
}
@@ -906,15 +969,13 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
if i >= dst.length() {
// TODO: advance args.src if the dst pixel_buffer bounds is
// smaller than this BMP's image bounds?
continue.inner
n = p0 as base.u64
} else {
n = this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: this.scratch[.. 8 * p0])
}
n = this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: this.scratch[.. 8 * p0])
if n == 0 {
return "@internal note: short read"
}
@@ -938,8 +999,9 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
var p0 : base.u32[..= 543]
var chunk_bits : base.u32
var chunk_count : base.u32
var chunk_bits : base.u32
var chunk_count : base.u32
var pixels_per_chunk : base.u32[..= 32]
// 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()".
@@ -968,8 +1030,34 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
if i >= dst.length() {
// TODO: advance args.src if the dst pixel_buffer bounds is
// smaller than this BMP's image bounds?
if this.bits_per_pixel == 1 {
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
pixels_per_chunk = 32
} else if this.bits_per_pixel == 2 {
chunk_count = ((this.width ~sat- this.dst_x) + 15) / 16
pixels_per_chunk = 16
} else {
chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8
pixels_per_chunk = 8
}
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))
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))
chunk_count -= 8
} endwhile
while chunk_count > 0 {
if args.src.length() < 4 {
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))
chunk_count -= 1
} endwhile
continue.loop
}
dst = dst[i ..]
@@ -1047,7 +1135,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
chunk_count -= 1
} endwhile
} else if this.bits_per_pixel == 4 {
} else {
// 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
@@ -1125,6 +1213,18 @@ pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_tell_me_more?(dst: args.dst, minfo: args.minfo, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
} endwhile
}
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
if this.io_redirect_fourcc <= 1 {
return base."#no more information"
}
+13
View File
@@ -19,6 +19,7 @@ pub status "#bad block length"
pub status "#bad checksum"
pub status "#bad header"
pub status "#bad number of sections"
pub status "#truncated input"
pub status "#unsupported block randomization"
pri status "#internal error: inconsistent Huffman decoder state"
@@ -121,6 +122,18 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
}
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
var status : base.status
while true {
status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
} endwhile
}
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
var c : base.u8
var i : base.u32
var tag : base.u64
+13
View File
@@ -25,6 +25,7 @@ pub status "#bad literal/length code count"
pub status "#inconsistent stored block length"
pub status "#missing end-of-block code"
pub status "#no Huffman codes"
pub status "#truncated input"
pri status "#internal error: inconsistent Huffman decoder state"
pri status "#internal error: inconsistent I/O"
@@ -208,6 +209,18 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
}
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
var status : base.status
while true {
status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
} endwhile
}
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
var mark : base.u64
var status : base.status
+1
View File
@@ -20,6 +20,7 @@ pub status "#bad graphic control"
pub status "#bad header"
pub status "#bad literal width"
pub status "#bad palette"
pub status "#truncated input"
pri status "#internal error: inconsistent ri/wi"
+51 -3
View File
@@ -98,6 +98,18 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var 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 ffio : base.bool
if this.call_sequence <> 0x00 {
@@ -150,6 +162,18 @@ pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_tell_me_more?(dst: args.dst, minfo: args.minfo, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
} endwhile
}
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
var chunk_length : base.u64
if (this.call_sequence & 0x10) == 0 {
@@ -296,6 +320,18 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
}
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) {
var background_color : base.u32
var flags : base.u8
@@ -306,7 +342,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
} else if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
this.decode_image_config?(dst: nullptr, src: args.src)
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"
@@ -397,12 +433,24 @@ pri func decoder.skip_frame?(src: base.io_reader) {
this.call_sequence = 0x20
}
// TODO: honor args.opts.
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
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
}
// TODO: honor args.opts.
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) {
if this.call_sequence == 0x40 {
// No-op.
} else if this.call_sequence < 0x40 {
this.decode_frame_config?(dst: nullptr, src: args.src)
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
+13
View File
@@ -19,6 +19,7 @@ pub status "#bad checksum"
pub status "#bad compression method"
pub status "#bad encoding flags"
pub status "#bad header"
pub status "#truncated input"
// TODO: reference deflate.DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE.
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
@@ -45,6 +46,18 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
}
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
var status : base.status
while true {
status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
} endwhile
}
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
var c : base.u8
var flags : base.u8
var xlen : base.u16
+16 -5
View File
@@ -13,6 +13,7 @@
// limitations under the License.
pub status "#bad code"
pub status "#truncated input"
pri status "#internal error: inconsistent I/O"
@@ -119,6 +120,8 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
} else if this.read_from_return_value == 2 {
yield? base."$short read"
} else if this.read_from_return_value == 3 {
return "#truncated input"
} else if this.read_from_return_value == 4 {
return "#bad code"
} else {
return "#internal error: inconsistent I/O"
@@ -167,7 +170,11 @@ pri func decoder.read_from!(src: base.io_reader) {
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 {
this.read_from_return_value = 2
if args.src.is_closed() {
this.read_from_return_value = 3
} else {
this.read_from_return_value = 2
}
break
} else {
bits |= args.src.peek_u8_as_u32() << n_bits
@@ -176,7 +183,11 @@ pri func decoder.read_from!(src: base.io_reader) {
if n_bits >= width {
// No-op.
} else if args.src.length() <= 0 {
this.read_from_return_value = 2
if args.src.is_closed() {
this.read_from_return_value = 3
} else {
this.read_from_return_value = 2
}
break
} else {
bits |= args.src.peek_u8_as_u32() << n_bits
@@ -188,7 +199,7 @@ pri func decoder.read_from!(src: base.io_reader) {
// This if condition is always false, but for some unknown
// reason, removing it worsens the benchmarks slightly.
if n_bits < width {
this.read_from_return_value = 4
this.read_from_return_value = 5
break
}
}
@@ -297,7 +308,7 @@ pri func decoder.read_from!(src: base.io_reader) {
}
} else {
this.read_from_return_value = 3
this.read_from_return_value = 4
break
}
@@ -319,7 +330,7 @@ pri func decoder.read_from!(src: base.io_reader) {
if args.src.can_undo_byte() {
args.src.undo_byte!()
} else {
this.read_from_return_value = 4
this.read_from_return_value = 5
break
}
} endwhile
+71 -9
View File
@@ -13,6 +13,7 @@
// limitations under the License.
pub status "#bad header"
pub status "#truncated input"
pub status "#unsupported NIE file"
pri status "@internal note: short read"
@@ -39,6 +40,18 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var 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 a : base.u32
if this.call_sequence <> 0x00 {
@@ -89,10 +102,22 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
}
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.decode_image_config?(dst: nullptr, src: args.src)
this.do_decode_image_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 0x28 {
if 16 <> args.src.position() {
return base."#bad restart"
@@ -125,10 +150,22 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
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.decode_frame_config?(dst: nullptr, src: args.src)
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
@@ -164,9 +201,11 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 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
@@ -195,14 +234,37 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
}
i = (this.dst_x as base.u64) * dst_bytes_per_pixel
if i >= dst.length() {
// TODO: advance args.src if the dst pixel_buffer bounds is
// smaller than this NIE's image bounds?
continue
src_bytes_per_pixel = 4
assert src_bytes_per_pixel > 0
if this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE {
src_bytes_per_pixel = 8
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)
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)
}
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"
}
+1
View File
@@ -19,6 +19,7 @@ pub status "#bad filter"
pub status "#bad header"
pub status "#bad text chunk (not Latin-1)"
pub status "#missing palette"
pub status "#truncated input"
pub status "#unsupported CgBI extension"
pub status "#unsupported PNG compression method"
pub status "#unsupported PNG file"
+73 -31
View File
@@ -163,6 +163,18 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var 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 magic : base.u64
var mark : base.u64
var checksum_have : base.u32
@@ -229,14 +241,10 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
// IDAT chunk breaks the loop. The only other possible critical chunk is a
// PLTE chunk. We verify PLTE checksums here but ignore other checksums.
while true {
while args.src.length() < 8,
post args.src.length() >= 8,
{
if args.src.is_closed() {
return "#bad chunk"
}
if args.src.length() < 8 {
yield? base."$short read"
} endwhile
continue
}
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
@@ -607,11 +615,20 @@ pri func decoder.decode_other_chunk?(src: base.io_reader, framy: base.bool) {
}
} else if this.chunk_type == 'tRNS'le {
if this.seen_trns or (this.color_type > 3) or
if this.seen_trns or
((this.color_type == 3) and (not this.seen_plte)) {
return "#bad chunk"
} else if this.color_type > 3 {
// No-op, ignoring the chunk. The PNG spec section "11.3.2.1
// tRNS Transparency" says that "A tRNS chunk shall not appear
// for colour types 4 and 6, since a full alpha channel is
// already present in those cases." However, some real-world
// PNG images (incorrectly) have these. libpng treats this as a
// "benign error", not a fatal one. See
// https://github.com/google/wuffs/issues/146
} else {
this.decode_trns?(src: args.src)
}
this.decode_trns?(src: args.src)
this.seen_trns = true
}
}
@@ -934,6 +951,18 @@ pri func decoder.decode_trns?(src: base.io_reader) {
}
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) {
var checksum_have : base.u32
if (this.call_sequence & 0x10) <> 0 {
@@ -941,7 +970,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
} else if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
this.decode_image_config?(dst: nullptr, src: args.src)
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"
@@ -1029,14 +1058,10 @@ pri func decoder.skip_frame?(src: base.io_reader) {
this.chunk_type_array[3] = 0
while true {
while args.src.length() < 8,
post args.src.length() >= 8,
{
if args.src.is_closed() {
return "#bad chunk"
}
if args.src.length() < 8 {
yield? base."$short read"
} endwhile
continue
}
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
@@ -1091,6 +1116,18 @@ pri func decoder.skip_frame?(src: base.io_reader) {
}
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 seq_num : base.u32
var status : base.status
var pass_width : base.u32[..= 0x00FF_FFFF]
@@ -1101,18 +1138,14 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
} else if this.call_sequence >= 0x60 {
return base."@end of data"
} else if this.call_sequence <> 0x40 {
this.decode_frame_config?(dst: nullptr, src: args.src)
this.do_decode_frame_config?(dst: nullptr, src: args.src)
}
while true {
while args.src.length() < 8,
post args.src.length() >= 8,
{
if args.src.is_closed() {
return "#bad chunk"
}
if args.src.length() < 8 {
yield? base."$short read"
} endwhile
continue
}
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
@@ -1198,9 +1231,8 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
break
} else if status.is_error() or
((status == base."$short read") and args.src.is_closed()) {
// The input was truncated or invalid. Produce whatever
// pixels we can and then, if truncated, generate "$short
// read" forever.
// The input was invalid or truncated. Produce whatever
// pixels we can.
if this.workbuf_wi <= args.workbuf.length() {
// This might return "#internal error: inconsistent
// workbuf length" because of the ".. this.workbuf_wi".
@@ -1208,9 +1240,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf[.. this.workbuf_wi])
}
if status == base."$short read" {
while true {
yield? base."$short read"
} endwhile
return "#truncated input"
}
}
yield? status
@@ -1390,6 +1420,18 @@ pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_tell_me_more?(dst: args.dst, minfo: args.minfo, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
} endwhile
}
pri func decoder.do_tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
var c : base.u8
var c2 : base.u16
var w : base.io_writer
+39 -2
View File
@@ -14,6 +14,7 @@
pub status "#bad header"
pub status "#bad run length encoding"
pub status "#truncated input"
pub status "#unsupported TGA file"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
@@ -55,6 +56,18 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var 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.u32
var c5 : base.u32[..= 0x1F]
var i : base.u32
@@ -226,10 +239,22 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
}
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.decode_image_config?(dst: nullptr, src: args.src)
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"
@@ -260,6 +285,18 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
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
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
@@ -284,7 +321,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
if this.call_sequence == 0x40 {
// No-op.
} else if this.call_sequence < 0x40 {
this.decode_frame_config?(dst: nullptr, src: args.src)
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
+39 -2
View File
@@ -13,6 +13,7 @@
// limitations under the License.
pub status "#bad header"
pub status "#truncated input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
@@ -34,6 +35,18 @@ pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var 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 i : base.u32
var x32 : base.u32
@@ -97,10 +110,22 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
}
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.decode_image_config?(dst: nullptr, src: args.src)
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"
@@ -131,6 +156,18 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
}
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
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
@@ -146,7 +183,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
if this.call_sequence == 0x40 {
// No-op.
} else if this.call_sequence < 0x40 {
this.decode_frame_config?(dst: nullptr, src: args.src)
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
+13
View File
@@ -22,6 +22,7 @@ pub status "#bad compression method"
pub status "#bad compression window size"
pub status "#bad parity check"
pub status "#incorrect dictionary"
pub status "#truncated input"
// TODO: reference deflate.DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE.
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
@@ -81,6 +82,18 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
}
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
var status : base.status
while true {
status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
} endwhile
}
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
var x : base.u16
var checksum_got : base.u32
var status : base.status
+3
View File
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <limits.h>
#include <stdint.h>
#include "bzlib.h"
const char* //
+3
View File
@@ -23,6 +23,9 @@
// #define WUFFS_MIMICLIB_USE_LIBDEFLATE_INSTEAD_OF_ZLIB 1
// #define WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB 1
#include <limits.h>
#include <stdint.h>
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_ZLIB
#if defined(WUFFS_MIMICLIB_USE_LIBDEFLATE_INSTEAD_OF_ZLIB)
#include "libdeflate.h"
+3
View File
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <limits.h>
#include <stdint.h>
#include "gif_lib.h"
int //
+3
View File
@@ -24,6 +24,9 @@
// #define WUFFS_MIMICLIB_USE_LODEPNG_INSTEAD_OF_LIBPNG 1
// #define WUFFS_MIMICLIB_USE_STB_IMAGE_INSTEAD_OF_LIBPNG 1
#include <limits.h>
#include <stdint.h>
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_LIBPNG
#if defined(WUFFS_MIMICLIB_USE_LIBSPNG_INSTEAD_OF_LIBPNG)
+29
View File
@@ -101,6 +101,34 @@ test_wuffs_bmp_decode_interface() {
"test/data/hippopotamus.bmp", 0, SIZE_MAX, 36, 28, 0xFFF5F5F5);
}
const char* //
test_wuffs_bmp_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_bmp__decoder dec;
CHECK_STATUS("initialize",
wuffs_bmp__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_bmp__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_bmp__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_bmp__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_bmp__error__truncated_input);
}
return NULL;
}
const char* //
test_wuffs_bmp_decode_frame_config() {
CHECK_FOCUS(__func__);
@@ -213,6 +241,7 @@ proc g_tests[] = {
test_wuffs_bmp_decode_frame_config,
test_wuffs_bmp_decode_interface,
test_wuffs_bmp_decode_io_redirect,
test_wuffs_bmp_decode_truncated_input,
#ifdef WUFFS_MIMIC
+31
View File
@@ -109,6 +109,36 @@ test_wuffs_bzip2_decode_interface() {
"test/data/romeo.txt.bz2", 0, SIZE_MAX, 942, 0x0A);
}
const char* //
test_wuffs_bzip2_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer have = wuffs_base__ptr_u8__writer(g_have_array_u8, 1);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_bzip2__decoder dec;
CHECK_STATUS("initialize",
wuffs_bzip2__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_bzip2__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
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_bzip2__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
if (status.repr != wuffs_bzip2__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_bzip2__error__truncated_input);
}
return NULL;
}
const char* //
wuffs_bzip2_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
@@ -262,6 +292,7 @@ proc g_tests[] = {
test_wuffs_bzip2_decode_interface,
test_wuffs_bzip2_decode_midsummer,
test_wuffs_bzip2_decode_pi,
test_wuffs_bzip2_decode_truncated_input,
#ifdef WUFFS_MIMIC
+32
View File
@@ -92,6 +92,37 @@ test_wuffs_cbor_decode_interface() {
return NULL;
}
const char* //
test_wuffs_cbor_decode_empty_input() {
CHECK_FOCUS(__func__);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_cbor__decoder dec;
CHECK_STATUS("initialize",
wuffs_cbor__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_cbor__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8);
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_cbor__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8);
if (status.repr != wuffs_cbor__error__bad_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_cbor__error__bad_input);
}
return NULL;
}
const char* //
test_wuffs_cbor_decode_invalid() {
CHECK_FOCUS(__func__);
@@ -208,6 +239,7 @@ test_wuffs_cbor_decode_valid() {
proc g_tests[] = {
test_wuffs_cbor_decode_empty_input,
test_wuffs_cbor_decode_interface,
test_wuffs_cbor_decode_invalid,
test_wuffs_cbor_decode_valid,
+31
View File
@@ -166,6 +166,36 @@ test_wuffs_deflate_decode_interface() {
"test/data/romeo.txt.deflate", 0, SIZE_MAX, 942, 0x0A);
}
const char* //
test_wuffs_deflate_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer have = wuffs_base__ptr_u8__writer(g_have_array_u8, 1);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_deflate__decoder dec;
CHECK_STATUS("initialize",
wuffs_deflate__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_deflate__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
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_deflate__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
if (status.repr != wuffs_deflate__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_deflate__error__truncated_input);
}
return NULL;
}
const char* //
wuffs_deflate_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
@@ -903,6 +933,7 @@ proc g_tests[] = {
test_wuffs_deflate_decode_romeo,
test_wuffs_deflate_decode_romeo_fixed,
test_wuffs_deflate_decode_split_src,
test_wuffs_deflate_decode_truncated_input,
test_wuffs_deflate_history_full,
test_wuffs_deflate_history_partial,
test_wuffs_deflate_table_redirect,
+32 -3
View File
@@ -182,6 +182,34 @@ test_wuffs_gif_decode_interface_image_decoder() {
"test/data/bricks-nodither.gif", 0, SIZE_MAX, 160, 120, 0xFF012463);
}
const char* //
test_wuffs_gif_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_gif__decoder dec;
CHECK_STATUS("initialize",
wuffs_gif__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_gif__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_gif__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_gif__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_gif__error__truncated_input);
}
return NULL;
}
const char* //
wuffs_gif_decode(uint64_t* n_bytes_out,
wuffs_base__io_buffer* dst,
@@ -1238,9 +1266,9 @@ test_wuffs_gif_decode_interlaced_truncated() {
wuffs_base__status status = wuffs_gif__decoder__decode_frame(
&dec, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, g_work_slice_u8, NULL);
if (status.repr != wuffs_base__suspension__short_read) {
if (status.repr != wuffs_gif__error__truncated_input) {
RETURN_FAIL("decode_frame: have \"%s\", want \"%s\"", status.repr,
wuffs_base__suspension__short_read);
wuffs_gif__error__truncated_input);
}
// Even though the source GIF data was truncated, replicating the interlaced
@@ -1462,7 +1490,7 @@ test_wuffs_gif_decode_missing_two_src_bytes() {
src.meta.wi -= 2;
return do_test_wuffs_gif_decode_expecting(
src, 0, wuffs_base__suspension__short_read, false);
src, 0, wuffs_gif__error__truncated_input, false);
}
const char* //
@@ -2356,6 +2384,7 @@ proc g_tests[] = {
test_wuffs_gif_decode_pixfmt_bgra_nonpremul,
test_wuffs_gif_decode_pixfmt_rgb,
test_wuffs_gif_decode_pixfmt_rgba_nonpremul,
test_wuffs_gif_decode_truncated_input,
test_wuffs_gif_decode_zero_width_frame,
test_wuffs_gif_frame_dirty_rect,
test_wuffs_gif_num_decoded_frame_configs,
+32
View File
@@ -96,6 +96,36 @@ test_wuffs_gzip_decode_interface() {
"test/data/romeo.txt.gz", 0, SIZE_MAX, 942, 0x0A);
}
const char* //
test_wuffs_gzip_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer have = wuffs_base__ptr_u8__writer(g_have_array_u8, 1);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_gzip__decoder dec;
CHECK_STATUS("initialize",
wuffs_gzip__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_gzip__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
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_gzip__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
if (status.repr != wuffs_gzip__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_gzip__error__truncated_input);
}
return NULL;
}
const char* //
wuffs_gzip_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
@@ -255,6 +285,7 @@ test_wuffs_gzip_decode_infrequent_compaction() {
// Decode 5 source bytes at a time. Compact every 15 source bytes.
for (size_t i = 0; i < src.data.len; i += 5) {
src.meta.wi = i;
src.meta.closed = false;
wuffs_base__status status =
wuffs_gzip__decoder__transform_io(&dec, &dst, &src, g_work_slice_u8);
if (status.repr != wuffs_base__suspension__short_read) {
@@ -361,6 +392,7 @@ proc g_tests[] = {
test_wuffs_gzip_decode_interface,
test_wuffs_gzip_decode_midsummer,
test_wuffs_gzip_decode_pi,
test_wuffs_gzip_decode_truncated_input,
#ifdef WUFFS_MIMIC
+46
View File
@@ -1026,6 +1026,7 @@ test_wuffs_strconv_parse_number_f64_regular() {
{.want = 0x46293E5939A08CEA, .str = "1e30"},
{.want = 0x54B249AD2594C37D, .str = "+1E+100"},
{.want = 0x54B249AD2594C37D, .str = "+_1_E_+_1_0_0_"},
{.want = 0x54B2987670ADB613, .str = "1.0168286519992372611942638e+100"},
{.want = 0x7BBA44DF832B8D46, .str = "1e+288"},
{.want = 0x7BF06B0BB1FB384C, .str = "1e+289"},
{.want = 0x7C2485CE9E7A065F, .str = "1e+290"},
@@ -1943,6 +1944,19 @@ test_wuffs_strconv_render_number_f64() {
"4.000",
.want_4g = "1e+100",
},
{
.x = 0x54B2987670ADB613,
.want__e = "1.0168286519992373e+100",
.want__f = "10168286519992373000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000"
"0",
.want_0g = "1e+100",
.want_2e = "1.02e+100",
.want_3f = "10168286519992372611942638135241625267907715220891"
"31363562982164291689352904657807934098133246961254"
"4.000",
.want_4g = "1.017e+100",
},
{
.x = 0x7BBA44DF832B8D46,
.want__e = "1e+288",
@@ -2579,6 +2593,37 @@ test_wuffs_json_decode_interface() {
return NULL;
}
const char* //
test_wuffs_json_decode_empty_input() {
CHECK_FOCUS(__func__);
wuffs_base__token_buffer tok =
wuffs_base__slice_token__writer(g_have_slice_token);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_json__decoder dec;
CHECK_STATUS("initialize",
wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8);
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_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8);
if (status.repr != wuffs_json__error__bad_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_json__error__bad_input);
}
return NULL;
}
const char* //
wuffs_json_decode(wuffs_base__token_buffer* tok,
wuffs_base__io_buffer* src,
@@ -4198,6 +4243,7 @@ proc g_tests[] = {
test_wuffs_strconv_render_number_u64,
test_wuffs_strconv_utf_8_next,
test_wuffs_json_decode_empty_input,
test_wuffs_json_decode_end_of_data,
test_wuffs_json_decode_interface,
test_wuffs_json_decode_long_numbers,
+30
View File
@@ -79,6 +79,35 @@ test_wuffs_lzw_decode_interface() {
"test/data/bricks-nodither.indexes.giflzw", 1, SIZE_MAX, 19200, 0x4F);
}
const char* //
test_wuffs_lzw_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer have = wuffs_base__ptr_u8__writer(g_have_array_u8, 1);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_lzw__decoder dec;
CHECK_STATUS("initialize",
wuffs_lzw__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_lzw__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
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_lzw__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
if (status.repr != wuffs_lzw__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_lzw__error__truncated_input);
}
return NULL;
}
const char* //
do_test_wuffs_lzw_decode(const char* src_filename,
uint64_t src_size,
@@ -444,6 +473,7 @@ proc g_tests[] = {
test_wuffs_lzw_decode_output_bad,
test_wuffs_lzw_decode_output_empty,
test_wuffs_lzw_decode_pi,
test_wuffs_lzw_decode_truncated_input,
test_wuffs_lzw_decode_width_0,
test_wuffs_lzw_decode_width_1,
+29
View File
@@ -82,6 +82,34 @@ test_wuffs_nie_decode_interface() {
"test/data/hippopotamus.nie", 0, SIZE_MAX, 36, 28, 0xFFF5F5F5);
}
const char* //
test_wuffs_nie_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_nie__decoder dec;
CHECK_STATUS("initialize",
wuffs_nie__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_nie__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_nie__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_nie__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_nie__error__truncated_input);
}
return NULL;
}
const char* //
test_wuffs_nie_decode_frame_config() {
CHECK_FOCUS(__func__);
@@ -134,6 +162,7 @@ proc g_tests[] = {
test_wuffs_nie_decode_frame_config,
test_wuffs_nie_decode_interface,
test_wuffs_nie_decode_truncated_input,
#ifdef WUFFS_MIMIC
+43
View File
@@ -194,6 +194,47 @@ test_wuffs_png_decode_interface() {
"test/data/bricks-gray.png", 0, SIZE_MAX, 160, 120, 0xFF060606);
}
const char* //
test_wuffs_png_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_png__decoder dec;
CHECK_STATUS("initialize",
wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_png__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_png__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_png__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_png__error__truncated_input);
}
return NULL;
}
const char* //
test_wuffs_png_decode_multiple_idats() {
CHECK_FOCUS(__func__);
wuffs_png__decoder dec;
CHECK_STATUS("initialize",
wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_png__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-color.png", 0, SIZE_MAX, 160, 120, 0xFF022460);
}
const char* //
test_wuffs_png_decode_bad_crc32_checksum_critical() {
CHECK_FOCUS(__func__);
@@ -1273,7 +1314,9 @@ proc g_tests[] = {
test_wuffs_png_decode_metadata_exif,
test_wuffs_png_decode_metadata_iccp,
test_wuffs_png_decode_metadata_kvp,
test_wuffs_png_decode_multiple_idats,
test_wuffs_png_decode_restart_frame,
test_wuffs_png_decode_truncated_input,
#ifdef WUFFS_MIMIC
+29
View File
@@ -99,6 +99,34 @@ test_wuffs_tga_decode_interface() {
"test/data/bricks-color.tga", 0, SIZE_MAX, 160, 120, 0xFF022460);
}
const char* //
test_wuffs_tga_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_tga__decoder dec;
CHECK_STATUS("initialize",
wuffs_tga__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_tga__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_tga__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_tga__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_tga__error__truncated_input);
}
return NULL;
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
@@ -141,6 +169,7 @@ bench_wuffs_tga_decode_77k_24bpp() {
proc g_tests[] = {
test_wuffs_tga_decode_interface,
test_wuffs_tga_decode_truncated_input,
#ifdef WUFFS_MIMIC
+29
View File
@@ -436,6 +436,34 @@ test_wuffs_wbmp_decode_interface() {
"test/data/muybridge-frame-000.wbmp", 0, SIZE_MAX, 30, 20, 0xFFFFFFFF);
}
const char* //
test_wuffs_wbmp_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_wbmp__decoder dec;
CHECK_STATUS("initialize",
wuffs_wbmp__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_wbmp__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_wbmp__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_wbmp__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_wbmp__error__truncated_input);
}
return NULL;
}
const char* //
test_wuffs_wbmp_decode_frame_config() {
CHECK_FOCUS(__func__);
@@ -653,6 +681,7 @@ proc g_tests[] = {
test_wuffs_wbmp_decode_frame_config,
test_wuffs_wbmp_decode_image_config,
test_wuffs_wbmp_decode_interface,
test_wuffs_wbmp_decode_truncated_input,
#ifdef WUFFS_MIMIC
+31
View File
@@ -112,6 +112,36 @@ test_wuffs_zlib_decode_interface() {
"test/data/romeo.txt.zlib", 0, SIZE_MAX, 942, 0x0A);
}
const char* //
test_wuffs_zlib_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer have = wuffs_base__ptr_u8__writer(g_have_array_u8, 1);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_zlib__decoder dec;
CHECK_STATUS("initialize",
wuffs_zlib__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_zlib__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
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_zlib__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
if (status.repr != wuffs_zlib__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_zlib__error__truncated_input);
}
return NULL;
}
const char* //
wuffs_raw_deflate_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
@@ -426,6 +456,7 @@ proc g_tests[] = {
test_wuffs_zlib_decode_pi,
test_wuffs_zlib_decode_raw_deflate_romeo,
test_wuffs_zlib_decode_sheep,
test_wuffs_zlib_decode_truncated_input,
#ifdef WUFFS_MIMIC
+7
View File
@@ -0,0 +1,7 @@
𝔸 U+1D538 MATHEMATICAL DOUBLE-STRUCK CAPITAL A. UTF-8: [F0 9D 94 B8].
This code point is outside of the Unicode BMP (Basic Multilingual Plane), but
its Unicode Category is Lu (Letter, uppercase), so it is still a valid file
path in terms of pkg.go.dev and its golang.org/x/mod/module package:
https://github.com/golang/mod/blob/dc121ce20ffab6bb810a0f231cfa9c24d3e51b29/module/module.go#L293
File renamed without changes.
-3
View File
@@ -1,3 +0,0 @@
😻 U+1F63B SMILING CAT FACE WITH HEART-SHAPED EYES. UTF-8: [F0 9F 98 BB].
This code point is outside of the Unicode BMP (Basic Multilingual Plane).