Compare commits

..
Author SHA1 Message Date
Nigel Tao 58608c4ee5 wuffs gen -version=0.3.0-beta.13 2022-01-08 14:07:40 +11:00
Nigel Tao 4aa672af48 Drop "unused" in degenerate-huffman-unused tests 2022-01-08 13:59:53 +11:00
Nigel Tao f86c80e425 Fix std/deflate degenerate H-D Huffman table
RFC 1951 section 3.2.7. "Compression with dynamic Huffman codes
(BTYPE=10)" says, "If only one distance code is used, it is encoded
using one bit, not zero bits; in this case there is a single code length
of one, with one unused code."

I had previously mis-read that excerpt to also require that the sole
distance code was the shortest distance (code 0, a distance of 1).

Fixes #66
2022-01-08 13:57:34 +11:00
Nigel Tao dda01f1a77 Add WUFFS_BASE__FOURCC__QOI definition 2022-01-02 09:10:51 +11:00
Nigel Tao f3a7288357 Add more hello-wuffs-c commentary 2022-01-01 16:36:33 +11:00
Nigel Tao 0a8bded7f3 Add Magnus Anderson to A+C 2022-01-01 15:49:40 +11:00
Nigel Tao 918b4e4535 Merge pull request #65 from magnus-ISU/improve-hello
Improve hello-wuffs-c example
2022-01-01 15:47:24 +11:00
magnus 92f74e91a7 Add documentation about when and why wuffs_base__status might not be ok 2021-12-31 12:56:59 -06:00
magnus bcecdef66b Update README to accurately reflect new code 2021-12-31 12:33:50 -06:00
magnus 2f1b1a5311 Remove #ifdefs for readability 2021-12-31 12:27:43 -06:00
Nigel Tao 425eefeb35 Replace "go get" advice with "go install"
Fixes #62
2021-12-30 22:58:12 +11:00
Nigel Tao e1a6a7cd8c Add "wuffs help foo" for the command line tool
Updates #62
2021-12-30 22:34:27 +11:00
Nigel Tao 4e85543d9c Change default -ccompilers to "clang,gcc"
Updates #62
2021-12-30 19:29:44 +11:00
Nigel Tao 4c04ac1127 Replace FOURCC__{WP8,WP8L} with FOURCC__WEBP
Fixes #61
2021-12-15 15:53:14 +11:00
Nigel Tao 8ef4c062d9 Add zlib QUIRK_JUST_RAW_DEFLATE 2021-11-26 23:13:57 +11:00
Nigel Tao 38b101d170 Push std/png decoder.tell_me_more goto_done later 2021-11-26 19:46:36 +11:00
Nigel Tao 5d1473a2ca Refactor std/png decoder.tell_me_more 2021-11-26 19:45:42 +11:00
Nigel Tao 72d4a9e769 Have std/png pass through EXIF data
Fixes #59
2021-11-26 19:14:30 +11:00
Nigel Tao 5f6a522563 Add a "while.goto_done" no-op to std/png 2021-11-26 17:26:12 +11:00
Nigel Tao 4dedbedbbc Remove unnecessary std/nie struct parentheses 2021-11-26 17:24:57 +11:00
Nigel Tao a1aa15cacf Update NIE spec's "Updated on $DATE" line 2021-11-25 18:21:27 +11:00
Nigel Tao ae6b366edb Fix NIE spec's obsolete RGBA byte order config 2021-11-25 18:10:30 +11:00
Nigel Tao 6acb5a4fdd Fix example/convert-to-nia comment typo 2021-11-24 09:30:33 +11:00
Nigel Tao 3a9933f2a0 Canonicalize stills' NIA conversion's loops to 0 2021-11-23 21:39:29 +11:00
Nigel Tao c2eb4f5b93 Have convert-to-nia emit final frame's loop count 2021-11-23 19:30:48 +11:00
Nigel Tao 8397a35a50 Have convert-to-nia emit 'best effort' bad frames 2021-11-23 15:38:35 +11:00
Nigel Tao e53497abe3 Have convert-to-nia output valid NIA on bad frames 2021-11-23 15:24:58 +11:00
Nigel Tao 15285a6ab9 Refactor example/convert-to-nia 2021-11-23 15:14:57 +11:00
Nigel Tao ac4d3e6420 Use 0 (not 1) num_animation_loops for still GIFs
For example, the crc32 checksums in test/nia-checksums-of-data.txt for
test/data/pjw-thumbnail.{bmp,gif,png} now all match.
2021-11-23 15:06:55 +11:00
Nigel Tao 8bd52a8791 Embiggen example/convert-to-nia WORKBUF_ARRAY_SIZE 2021-11-23 13:22:34 +11:00
Nigel Tao 1d8fb411ba Let bench-history.sh handle compile/bench failures 2021-11-22 13:12:57 +11:00
Nigel Tao ccbec18330 Re-order pixconv "Extract... components" variables 2021-11-21 21:20:59 +11:00
Nigel Tao 55cad41d6c Have nonpremul SRC_OVER keep transparent red/blue 2021-11-21 21:16:10 +11:00
Nigel Tao f5c68a13cb Fix std/png for depth-16 grayscale interlaced 2021-11-20 22:54:21 +11:00
Nigel Tao f5d6ce3797 Have etc__limited_copy_etc args match call sites 2021-11-20 22:34:25 +11:00
Nigel Tao 5e8b448c12 Drop std/deflate's "Re-purpose the hdist variable" 2021-11-20 22:03:29 +11:00
Nigel Tao 49a431f98d Fix std/deflate decode_huffman_slow suspends
Unlike the other decode_huffman_etc! methods, decode_huffman_slow? (with
a ?) can suspend. The (hlen, hdist) and the remainder (length, distance)
pairs might not be stable across a suspension, as the args.dst io_writer
might change its history length. We have to re-calculate those pairs
after a short write.

The test/3pdata/nia-checksums-of-pngsuite.txt for interlaced and
non-interlaced flavors of the same image now match.
2021-11-20 21:31:40 +11:00
Nigel Tao ede0590ead Add while label to std/deflate decode_huffman_slow 2021-11-20 20:14:37 +11:00
Nigel Tao bb8623b472 Have deflate slow-Huffman use extended ringbuffer
This is the same optimization as commit e65c8612 "Extend std/deflate
ringbuffer to simplify copies", applied to decoder.decode_huffman_slow.
2021-11-20 20:10:10 +11:00
Nigel Tao 010e0a69f4 Fix fuzz seed_corpora for test filename rename
Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=41167
2021-11-20 17:58:08 +11:00
Nigel Tao a684928240 Let std/png allow PLTE for RGB, RGBA color types 2021-11-20 15:39:07 +11:00
Nigel Tao cdf3bbfb26 Add test/3pdata/pngsuite 2021-11-20 14:49:10 +11:00
Nigel Tao fe15c471df Use LANG=C sort for test/nia-checksums-of-data.txt 2021-11-19 17:09:10 +11:00
Nigel Tao 3b3331bbb3 wuffs gen -version=0.3.0-beta.12 2021-11-19 14:03:31 +11:00
Nigel Tao e44920d382 Let gif "ignore too much" quirk skip lzw errors
The modified test/data/*/*.gif files differ by only one byte:
 00000000  47 49 46 38 39 61 02 00  02 00 81 00 00 00 00 ff  |GIF89a..........|
 00000010  11 00 ff 22 00 ff 33 00  ff 2c 00 00 00 00 02 00  |..."..3..,......|
-00000020  02 00 00 02 02 84 f1 00  3b                       |........;|
+00000020  02 00 00 02 02 84 5d 00  3b                       |......].;|

The etc-good-lzw.gif bits have changed, even though the
etc-good-lzw.etc.txt file only had comments added, due to a Go standard
library change: "compress/lzw: output a Clear code first, per GIF spec"
https://github.com/golang/go/commit/9c1dbdf60edbffeff10f58af21fa055eb0fdd29f

Updates PR #57
Updates https://crbug.com/1270631
2021-11-19 13:30:23 +11:00
Nigel Tao 3b882be500 Rename test/.../pixel-data-too-much.gif* 2021-11-19 11:54:39 +11:00
Nigel Tao 6a8ee57ac0 Loosen test_wuffs_png_decode_metadata_kvp bound 2021-11-19 09:48:47 +11:00
Nigel Tao 66cfd3e02f wuffs gen -version=0.3.0-beta.11 2021-11-18 19:19:02 +11:00
Nigel Tao 161e4730d8 Tweak default WUFFS_VERSION_PRE_RELEASE_LABEL 2021-11-18 19:18:34 +11:00
Nigel Tao d5066c1aae Add wuffs_aux::private_impl::ErrorMessages type 2021-11-18 17:30:11 +11:00
Nigel Tao 8562375fd9 Update test/nia-checksums-of-data.txt 2021-11-18 08:11:06 +11:00
Nigel Tao bb028ae764 Update tests for artificial/* filename rename 2021-11-18 08:10:12 +11:00
Nigel Tao 29560a336b Convert std/png text from Latin-1 to UTF-8
Fixes #55
2021-11-17 23:04:49 +11:00
Nigel Tao e0cdaeb54f Fix std/png tell_me_more minfo with suspensions 2021-11-17 13:04:04 +11:00
Nigel Tao e7ed1dd43e Add std/png tell_me_more while.loop name 2021-11-17 13:01:05 +11:00
Nigel Tao bfce0e0a16 Let wuffs_aux::DecodeImage re-use raw metadata buf 2021-11-17 12:44:21 +11:00
Nigel Tao 417b03a0ad Add std/png "#unsupported PNG compression method" 2021-11-17 12:07:44 +11:00
Nigel Tao 7dd0dd264b Delete superfluous "// --------" comment 2021-11-17 12:03:43 +11:00
Nigel Tao 0d37acd6f6 Factor out std/png/common_consts.wuffs 2021-11-17 12:01:37 +11:00
Nigel Tao 6737565c20 Let std/png decode iTXt, tEXt and zTXt chunks
Updates #55
2021-11-17 11:56:49 +11:00
Nigel Tao 3642d73714 Factor test/data/artificial into many directories 2021-11-16 15:37:57 +11:00
Nigel Tao 37ac4def8e Move some test/data/artificial files up one dir 2021-11-16 15:12:29 +11:00
Nigel Tao 07c053af6f Have reset! LEAVE_INTERNAL_BUFFERS_UNINITIALIZED 2021-11-16 13:16:43 +11:00
Nigel Tao f0c2a40d66 Resize std/png chunk_length field from u64 to u32 2021-11-16 13:06:30 +11:00
Nigel Tao ce9ab13ecd Let std/png decode first fcTL after the last IDAT 2021-11-16 12:55:43 +11:00
Nigel Tao 6c2a591e84 Let script/make-artificial.go generate PNG files 2021-11-16 11:08:04 +11:00
Nigel Tao d40bf000a9 Rename wuffs_base__table_u8__row as etc__row_u32 2021-11-15 17:26:51 +11:00
Nigel Tao 0045ce49f3 Rename table.row as table.row_u32 2021-11-15 10:49:42 +11:00
Nigel Tao fa56d92410 Clip std/png frame_dirty_rect to frame rect 2021-11-15 10:46:28 +11:00
Nigel Tao 8f1adea523 Hoist subslice out of std/png filter_and_swizzle
On an Intel NUC (Comet Lake, BXNUC10i5FNKPA):

name                                                      old speed      new speed      delta

wuffs_png_decode_image_19k_8bpp/clang9                     274MB/s ± 0%   273MB/s ± 0%  -0.25%  (p=0.008 n=5+5)
wuffs_png_decode_image_40k_24bpp/clang9                    309MB/s ± 0%   308MB/s ± 0%  -0.22%  (p=0.008 n=5+5)
wuffs_png_decode_image_77k_8bpp/clang9                     985MB/s ± 0%   982MB/s ± 0%  -0.29%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_ignore_checksum/clang9   846MB/s ± 0%   841MB/s ± 0%  -0.56%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_verify_checksum/clang9   812MB/s ± 0%   808MB/s ± 0%  -0.55%  (p=0.008 n=5+5)
wuffs_png_decode_image_4002k_24bpp/clang9                  320MB/s ± 0%   320MB/s ± 0%  -0.15%  (p=0.008 n=5+5)

wuffs_png_decode_image_19k_8bpp/gcc10                      263MB/s ± 0%   276MB/s ± 0%  +5.00%  (p=0.008 n=5+5)
wuffs_png_decode_image_40k_24bpp/gcc10                     328MB/s ± 0%   333MB/s ± 0%  +1.49%  (p=0.016 n=5+4)
wuffs_png_decode_image_77k_8bpp/gcc10                      950MB/s ± 0%   976MB/s ± 0%  +2.78%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_ignore_checksum/gcc10    865MB/s ± 0%   912MB/s ± 0%  +5.45%  (p=0.008 n=5+5)
wuffs_png_decode_image_552k_32bpp_verify_checksum/gcc10    825MB/s ± 0%   868MB/s ± 0%  +5.19%  (p=0.008 n=5+5)
wuffs_png_decode_image_4002k_24bpp/gcc10                   336MB/s ± 0%   341MB/s ± 0%  +1.37%  (p=0.008 n=5+5)
2021-11-15 10:43:55 +11:00
Nigel Tao 962a515dd2 Add wuffs_base__table_u8__subtable_ij 2021-11-15 09:58:02 +11:00
Nigel Tao 8025bf1bd7 Fix std/png filter benches 2021-11-14 21:20:05 +11:00
Nigel Tao 4d64aff554 Rename std/png/decode_swizzle_fallback.wuffs 2021-11-14 19:58:23 +11:00
Nigel Tao 54bdcc1b57 Update wuffs_aux::DecodeImageArgFlags comment 2021-11-14 19:57:18 +11:00
Nigel Tao a4fa6a2554 Let std/png decode (animated) APNG
The test/nia-checksums-of-data.txt checksums for the *.apng files now
match the (multiple frame) *.gif files. Previously, they matched the
(single frame) *.000000.nie files.

Fixes #41
2021-11-14 18:20:15 +11:00
Nigel Tao 22eed1fd8d Let example/convert-to-nia decode NIE 2021-11-13 11:21:35 +11:00
Nigel Tao c19e3b1cab Add script/extract-nia-frames.go 2021-11-11 11:47:08 +11:00
Nigel Tao 9af2666aec Move std/png first_frame_io_position earlier 2021-11-10 16:52:59 +11:00
Nigel Tao 9c3d27fb43 Fix std/png decode_other_chunk skipping chunks 2021-11-09 22:10:00 +11:00
Nigel Tao 2373340f83 Add base.ANIMATION_DISPOSAL__ETC constants 2021-11-09 09:53:29 +11:00
Nigel Tao e847766b02 Tweak std/png decode_other_chunk if-else chain 2021-11-09 09:05:11 +11:00
Nigel Tao 74c1dfce96 Rename std/gif num_loops field 2021-11-09 08:55:15 +11:00
Nigel Tao f4c2d4652e Fix test/data/animated-red-blue.apng loop count
The diff of the "hd" hex dump shows that the acTL chunk's nominal loop
count changed from 2 to 3. The 4-byte CRC-32 checksum was also updated.
 00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|
 00000010  00 00 00 40 00 00 00 30  08 02 00 00 00 2e 29 eb  |...@...0......).|
 00000020  48 00 00 00 08 61 63 54  4c 00 00 00 04 00 00 00  |H....acTL.......|
-00000030  02 92 c3 07 fc 00 00 00  06 74 52 4e 53 00 00 00  |.........tRNS...|
+00000030  03 e5 c4 37 6a 00 00 00  06 74 52 4e 53 00 00 00  |...7j....tRNS...|
 00000040  00 00 10 73 11 17 f5 00  00 00 1a 66 63 54 4c 00  |...s.......fcTL.|
 00000050  00 00 00 00 00 00 40 00  00 00 30 00 00 00 00 00  |......@...0.....|
 00000060  00 00 00 00 0a 00 64 00  00 80 50 f1 a2 00 00 03  |......d...P.....|
2021-11-07 10:43:32 +11:00
Nigel Tao ca76a01ac2 Have std/png support remapped transparency 2021-11-07 09:51:04 +11:00
Nigel Tao 00b329872a Tighten png.INTERLACING type refinement 2021-11-06 09:54:56 +11:00
Nigel Tao 0a7168fd64 Add test/data/*.apng 2021-11-05 22:28:08 +11:00
Nigel Tao f854646586 Fix -Wshadow warnings 2021-11-05 17:51:22 +11:00
Nigel Tao f148f5c5b3 Make "// - etc" bullet point comments consistent 2021-11-05 16:50:38 +11:00
Nigel Tao 750df217dd Rename deprecated ETC__FLAVOR__METADATA 2021-11-05 16:48:58 +11:00
Nigel Tao 744fbdd732 Have std/png decode iCCP chunks
Updates #39
2021-11-05 16:29:11 +11:00
Nigel Tao 0854344580 Add wuffs_aux::sync_io::DynIOBuffer 2021-11-04 22:58:45 +11:00
Nigel Tao d5075c7e94 Push "int i" into "for (int i = etc; etc; etc)" 2021-11-02 14:07:58 +11:00
Nigel Tao 16b51dd2a4 Fix -Wshadow warnings 2021-10-31 16:27:47 +11:00
Nigel Tao badce3ffa4 Tweak magic_number_guess_fourcc negative codes 2021-10-31 16:27:17 +11:00
Nigel Tao f40ef01244 Have make-red-blue-gradient use iCCP profile name 2021-10-31 15:35:14 +11:00
Nigel Tao 8f9a4f40c2 Rename METADATA_RAW as METADATA_RAW_PASSTHROUGH 2021-10-31 15:17:46 +11:00
Nigel Tao c754f81634 Have wuffs_aux::DecodeImage report ICCP, XMP 2021-10-31 15:09:55 +11:00
Nigel Tao a9a6332be2 Have etc__magic_number_guess_fourcc find ICO 2021-10-22 15:51:44 +11:00
Nigel Tao d557bc3836 Embiggen test/data/red-blue-gradient.*.png 2021-10-22 09:23:49 +11:00
Nigel Tao 01a5b8842b Update test/nia-checksums-of-data.txt 2021-10-20 19:38:43 +11:00
Nigel Tao 35cb4df973 Rename test/data/red-blue-gradient.dcip3d65.png 2021-10-20 19:38:24 +11:00
Nigel Tao 15b6285d1c Add example/imageviewer -screen_gamma=N.N flag 2021-10-20 15:42:26 +11:00
Nigel Tao 6ea3144379 Add test/data/checkerboard.*.png 2021-10-20 09:58:42 +11:00
Nigel Tao b003f9fe65 Let wuffs_aux::DecodeImage handle metadata
Updates #39
2021-10-19 22:09:21 +11:00
Nigel Tao d259f7a579 Fix json_fuzzer for wuffs_aux::FooArgBar types 2021-10-18 00:46:50 +11:00
Nigel Tao 2b7b6e12ea Add wuffs_aux::DecodeImageArgQuirks 2021-10-18 00:40:11 +11:00
Nigel Tao ca33506c01 Add wuffs_aux::FooArgBar types for optional args
Prior to this commit, with a "wuffs_aux::Foo(x, y, 0, 0, 4, 5)" call,
with arguments after "y" optional, it was not a compile-time error to
give the wrong number of "0"s or to transpose "4" and "5".
2021-10-18 00:25:13 +11:00
Nigel Tao 0460bfcd7a Add FourCC comment 2021-10-17 23:18:58 +11:00
Nigel Tao 9437d1a265 Tighten magic number guessing for WBMP 2021-10-17 22:57:42 +11:00
Nigel Tao 2e821791a9 Update test/nia-checksums-of-data.txt 2021-10-17 13:08:24 +11:00
Nigel Tao e317f04bfd Add defined(__clang__) to defined(__GNUC__) checks 2021-10-17 12:14:54 +11:00
Nigel Tao db5a407bab Have std/png decode sRGB chunks
Updates #39
2021-10-16 09:27:30 +11:00
Nigel Tao 9323549eeb Update doc/changelog.md 2021-10-15 16:34:04 +11:00
Nigel Tao 911049e9f9 Have std/png decode cHRM and gAMA chunks
Updates #39
2021-10-15 15:08:47 +11:00
Nigel Tao ae9ca94501 Fix etc__more_information__metadata_parsed__chrm 2021-10-15 14:15:39 +11:00
Nigel Tao d8ad363ef5 Tweak png.decoder.decode_image_config indentation 2021-10-15 13:35:15 +11:00
Nigel Tao e6733aec19 Add test/data/red-blue-gradient.dcip3d65.png 2021-10-15 11:29:26 +11:00
Nigel Tao ad1d983698 Add ETC__MORE_INFORMATION__FLAVOR__METADATA_PARSED 2021-10-14 17:17:11 +11:00
Nigel Tao dbc209dd7e Add test/data/red-blue-gradient.*.png 2021-10-14 15:58:03 +11:00
Nigel Tao 1a94a6f1b3 Choose fuzzer's static-ness on program vs library
Some sanitizers don't work well with static functions.

Updates https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=39767
2021-10-10 10:46:05 +11:00
192 changed files with 13202 additions and 2567 deletions

No files matched your search

+1
View File
@@ -13,6 +13,7 @@
Andrew Dassonville <dassonville.andrew@gmail.com>
Google Inc.
Jimmy Casey <casey.jimmy@gmail.com>
Magnus Anderson <magnus@iastate.edu>
Mike Kaufman <mkaufman@microsoft.com>
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
Přemysl Eric Janouch <p@janouch.name>
+1
View File
@@ -36,6 +36,7 @@ Andrew Dassonville <dassonville.andrew@gmail.com>
Chris Palmer <chris@noncombatant.org>
Jimmy Casey <casey.jimmy@gmail.com>
Leo Neat <lneat@google.com>
Magnus Anderson <magnus@iastate.edu>
Mike Kaufman <mkaufman@microsoft.com>
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
Nigel Tao <nigeltao@golang.org>
+1 -1
View File
@@ -27,7 +27,7 @@ import (
)
const (
CcompilersDefault = "clang-9,gcc"
CcompilersDefault = "clang,gcc"
CcompilersUsage = `comma-separated list of C compilers`
FocusDefault = ""
+1 -1
View File
@@ -124,7 +124,7 @@ Installation:
Like any other implemented-in-Go program, to install the ractool program:
go get github.com/google/wuffs/cmd/ractool
go install github.com/google/wuffs/cmd/ractool
Extended Example:
+1 -1
View File
@@ -125,7 +125,7 @@ Installation:
Like any other implemented-in-Go program, to install the ractool program:
go get github.com/google/wuffs/cmd/ractool
go install github.com/google/wuffs/cmd/ractool
Extended Example:
+6 -1
View File
@@ -37,7 +37,12 @@ func doGen(wuffsRoot string, args []string) error { return doGenGenlib(wuffsR
func doGenlib(wuffsRoot string, args []string) error { return doGenGenlib(wuffsRoot, args, true) }
func doGenGenlib(wuffsRoot string, args []string, genlib bool) error {
flags := flag.NewFlagSet("gen", flag.ExitOnError)
flagSetName := `"wuffs gen <flags> std/pkg1 std/pkg2 etc"`
if genlib {
flagSetName = `"wuffs genlib <flags> std/pkg1 std/pkg2 etc"`
}
flags := flag.NewFlagSet(flagSetName, flag.ExitOnError)
genlinenumFlag := flags.Bool("genlinenum", cf.GenlinenumDefault, cf.GenlinenumUsage)
langsFlag := flags.String("langs", langsDefault, langsUsage)
skipgendepsFlag := flags.Bool("skipgendeps", skipgendepsDefault, skipgendepsUsage)
+9
View File
@@ -52,6 +52,8 @@ The commands are:
gen generate code for packages and dependencies
genlib generate software libraries
test test packages
Use "wuffs help <command>" for more information about a command.
`)
}
@@ -76,6 +78,13 @@ func main1() error {
return c.do(wuffsRoot, args[1:])
}
}
if (len(args) == 2) && (args[0] == "help") {
for _, c := range commands {
if args[1] == c.name {
return c.do(wuffsRoot, []string{"-help"})
}
}
}
}
usage()
os.Exit(1)
+22 -10
View File
@@ -29,16 +29,26 @@ func doBench(wuffsRoot string, args []string) error { return doBenchTest(wuffsRo
func doTest(wuffsRoot string, args []string) error { return doBenchTest(wuffsRoot, args, false) }
func doBenchTest(wuffsRoot string, args []string, bench bool) error {
flags := flag.NewFlagSet("test", flag.ExitOnError)
flagSetName := `"wuffs test <flags> std/pkg1 std/pkg2 etc"`
if bench {
flagSetName = `"wuffs bench <flags> std/pkg1 std/pkg2 etc"`
}
flags := flag.NewFlagSet(flagSetName, flag.ExitOnError)
ccompilersFlag := flags.String("ccompilers", cf.CcompilersDefault, cf.CcompilersUsage)
focusFlag := flags.String("focus", cf.FocusDefault, cf.FocusUsage)
iterscaleFlag := flags.Int("iterscale", cf.IterscaleDefault, cf.IterscaleUsage)
langsFlag := flags.String("langs", langsDefault, langsUsage)
mimicFlag := flags.Bool("mimic", cf.MimicDefault, cf.MimicUsage)
repsFlag := flags.Int("reps", cf.RepsDefault, cf.RepsUsage)
skipgenFlag := flags.Bool("skipgen", skipgenDefault, skipgenUsage)
skipgendepsFlag := flags.Bool("skipgendeps", skipgendepsDefault, skipgendepsUsage)
iterscaleFlag := (*int)(nil)
repsFlag := (*int)(nil)
if bench {
iterscaleFlag = flags.Int("iterscale", cf.IterscaleDefault, cf.IterscaleUsage)
repsFlag = flags.Int("reps", cf.RepsDefault, cf.RepsUsage)
}
if err := flags.Parse(args); err != nil {
return err
}
@@ -53,13 +63,15 @@ func doBenchTest(wuffsRoot string, args []string, bench bool) error {
if !cf.IsAlphaNumericIsh(*focusFlag) {
return fmt.Errorf("bad -focus flag value %q", *focusFlag)
}
if *iterscaleFlag < cf.IterscaleMin || cf.IterscaleMax < *iterscaleFlag {
return fmt.Errorf("bad -iterscale flag value %d, outside the range [%d ..= %d]",
*iterscaleFlag, cf.IterscaleMin, cf.IterscaleMax)
}
if *repsFlag < cf.RepsMin || cf.RepsMax < *repsFlag {
return fmt.Errorf("bad -reps flag value %d, outside the range [%d ..= %d]",
*repsFlag, cf.RepsMin, cf.RepsMax)
if bench {
if *iterscaleFlag < cf.IterscaleMin || cf.IterscaleMax < *iterscaleFlag {
return fmt.Errorf("bad -iterscale flag value %d, outside the range [%d ..= %d]",
*iterscaleFlag, cf.IterscaleMin, cf.IterscaleMax)
}
if *repsFlag < cf.RepsMin || cf.RepsMax < *repsFlag {
return fmt.Errorf("bad -reps flag value %d, outside the range [%d ..= %d]",
*repsFlag, cf.RepsMin, cf.RepsMax)
}
}
args = flags.Args()
+1 -1
View File
@@ -38,7 +38,7 @@ The output of those benchmark programs is compatible with the
[benchstat](https://godoc.org/golang.org/x/perf/cmd/benchstat) tool. For
example, that tool can calculate confidence intervals based on multiple
benchmark runs, or calculate p-values when comparing numbers before and after a
code change. To install it, first install Go, then run `go get
code change. To install it, first install Go, then run `go install
golang.org/x/perf/cmd/benchstat`.
+2 -2
View File
@@ -20,10 +20,10 @@
- Added `example/json-to-cbor`.
- Added `example/jsonfindptrs`.
- Added `example/jsonptr`.
- Added `example/sdl-imageviewer`.
- Added `slice base.u8 peek/poke` methods.
- Added `std/bmp`.
- Added `std/cbor`.
- Added `std/gif.config_decoder`.
- Added `std/json`.
- Added `std/nie`.
- Added `std/png`.
@@ -40,7 +40,7 @@
- Added slice `uintptr_low_12_bits` method.
- Added tokens.
- Changed `gif.decoder_workbuf_len_max_incl_worst_case` from 1 to 0.
- Changed default C compilers from `clang-5.0,gcc` to `clang-9,gcc`.
- Changed default C compilers from `clang-5.0,gcc` to `clang,gcc`.
- Changed the C formatting style; removed the `-cformatter` flag.
- Changed what the `std/gif` benchmarks actually measure.
- Made `wuffs_base__pixel_format` a struct.
+16 -6
View File
@@ -22,15 +22,25 @@ test suite, you might also have to install C compilers like clang and gcc, as
well as C libraries (and their .h files) like libjpeg and libpng, as some tests
compare that Wuffs produces exactly the same output as these other libraries.
Running `go get -v github.com/google/wuffs/cmd/...` will download and install
the Wuffs tools. Change `get` to `install` to re-install those programs without
downloading, e.g. after you've modified their source code, or after a manually
issued `git pull`. The Wuffs tools that you'll most often use are `wuffsfmt`
Run `git clone https://github.com/google/wuffs.git` to get the latest Wuffs
code, `cd` into its directory and run `go install -v ./cmd/wuffs*` to install
the Wuffs tools. The Wuffs tools that you'll most often use are `wuffsfmt`
(analogous to `clang-format`, `gofmt` or `rustfmt`) and `wuffs` (roughly
analogous to `make`, `go` or `cargo`).
You should now be able to run `wuffs test`. If all goes well, you should see
some output containing the word "PASS" multiple times.
You should now be able to run `wuffs test`. If you only have the `gcc` C
compiler installed, but not `clang`, then you can run `wuffs
test -ccompilers=gcc` instead. If all goes well, you should see some output
containing the word "PASS" multiple times.
Remember to re-run `go install etc` whenever you've modified the Wuffs *tools'*
source code (i.e. `*.go` files) or after a manually issued `git pull`. If
you're only modifying the Wuffs *standard library's* source code (i.e.
`*.wuffs` files), re-running `go install etc` is unnecessary.
If you're modifying just one particular codec in the standard library, such as
the `std/png/*.wuffs` files, then you can exclude unrelated tests by running
`wuffs test std/png`.
## Poking Around
+1
View File
@@ -61,3 +61,4 @@ Package-specific quirks:
- [GIF image decoder quirks](/std/gif/decode_quirks.wuffs)
- [JSON decoder quirks](/std/json/decode_quirks.wuffs)
- [ZLIB decoder quirks](/std/zlib/decode_quirks.wuffs)
+5 -4
View File
@@ -1,6 +1,6 @@
# Naïve Image Formats: NIE, NII, NIA
Status: Draft (as of December 2020). There is no compatibility guarantee yet.
Status: Draft (as of November 2021). There is no compatibility guarantee yet.
A companion document has further discussion of [NIE related
work](/doc/spec/nie-related-work.md).
@@ -18,13 +18,14 @@ images. The 16 byte header:
is not valid UTF-8) denotes version 1. There are no other valid versions at
this time.
- The second byte must be an ASCII 'b'. This denotes that the payload is in
BGRA order (in terms of the wire format, independent of CPU endianness).
BGRA order (not RGBA), in terms of the wire format, independent of CPU
endianness.
- The third byte, either an ASCII 'n' or an ASCII 'p', denotes whether the
payload contains non-premultiplied or premultiplied alpha.
- The fourth byte, either an ASCII '4' or an ASCII '8', denotes whether there
are 4 or 8 bytes per pixel.
- Future format versions may allow other byte values, but in version 1, it
must be '\xFF', then 'b' or 'r', then 'n' or 'p', then '4' or '8'.
must be '\xFF', then 'b', then 'n' or 'p', then '4' or '8'.
- 4 bytes little-endian `uint32` width. The high bit must not be set.
- 4 bytes little-endian `uint32` height. The high bit must not be set.
@@ -369,4 +370,4 @@ in a long "E", "I" or "A" sound. It's definitely a hard "N", not a soft one.
---
Updated on December 2020.
Updated on November 2021.
+1 -1
View File
@@ -661,7 +661,7 @@ Go programming language libraries:
- [RAC](https://godoc.org/github.com/google/wuffs/lib/rac)
- [RAC + Zlib](https://godoc.org/github.com/google/wuffs/lib/raczlib)
Command line tool, installable via `go get
Command line tool, installable via `go install
github.com/google/wuffs/cmd/ractool`:
- [ractool](https://godoc.org/github.com/google/wuffs/cmd/ractool)
+102 -35
View File
@@ -64,6 +64,7 @@ https://skia-review.googlesource.com/c/skia/+/290618
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__LZW
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__ZLIB
@@ -128,11 +129,14 @@ wuffs_base__frame_config g_frame_config = {0};
int32_t g_fourcc = 0;
uint32_t g_width = 0;
uint32_t g_height = 0;
uint32_t g_num_animation_loops = 0;
uint64_t g_num_printed_frames = 0;
wuffs_base__image_decoder* g_image_decoder = NULL;
union {
wuffs_bmp__decoder bmp;
wuffs_gif__decoder gif;
wuffs_nie__decoder nie;
wuffs_png__decoder png;
wuffs_wbmp__decoder wbmp;
} g_potential_decoders;
@@ -150,7 +154,7 @@ union {
#endif
#ifndef WORKBUF_ARRAY_SIZE
#define WORKBUF_ARRAY_SIZE (1024 * 1024)
#define WORKBUF_ARRAY_SIZE (256 * 1024 * 1024)
#endif
#ifndef PIXBUF_ARRAY_SIZE
@@ -276,6 +280,16 @@ initialize_image_decoder() {
&g_potential_decoders.gif);
return NULL;
case WUFFS_BASE__FOURCC__NIE:
status = wuffs_nie__decoder__initialize(
&g_potential_decoders.nie, sizeof g_potential_decoders.nie,
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
TRY(wuffs_base__status__message(&status));
g_image_decoder =
wuffs_nie__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.nie);
return NULL;
case WUFFS_BASE__FOURCC__PNG:
status = wuffs_png__decoder__initialize(
&g_potential_decoders.png, sizeof g_potential_decoders.png,
@@ -424,12 +438,10 @@ fill_rectangle(wuffs_base__rect_ie_u32 rect,
wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul(color);
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(&g_pixbuf, 0);
uint32_t y;
for (y = rect.min_incl_y; y < rect.max_excl_y; y++) {
for (uint32_t y = rect.min_incl_y; y < rect.max_excl_y; y++) {
uint8_t* p =
tab.ptr + (y * tab.stride) + (rect.min_incl_x * BYTES_PER_PIXEL);
uint32_t x;
for (x = rect.min_incl_x; x < rect.max_excl_x; x++) {
for (uint32_t x = rect.min_incl_x; x < rect.max_excl_x; x++) {
wuffs_base__poke_u32le__no_bounds_check(p, nonpremul);
p += BYTES_PER_PIXEL;
}
@@ -456,13 +468,13 @@ print_nia_duration(wuffs_base__flicks duration) {
void //
print_nie_frame() {
g_num_printed_frames++;
print_nix_header(0x45AFC36E); // "nïE" as a u32le.
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(&g_pixbuf, 0);
if (tab.width == tab.stride) {
ignore_return_value(write(STDOUT_FD, tab.ptr, tab.width * tab.height));
} else {
size_t y;
for (y = 0; y < tab.height; y++) {
for (size_t y = 0; y < tab.height; y++) {
ignore_return_value(
write(STDOUT_FD, tab.ptr + (y * tab.stride), tab.width));
break;
@@ -481,30 +493,29 @@ print_nia_padding() {
void //
print_nia_footer() {
// For still (non-animated) images, the number of animation loops has no
// practical effect: the pixels on screen do not change over time regardless
// of its value. In the wire format encoding, there might be no explicit
// "number of animation loops" value listed in the source bytes. Various
// codec implementations may therefore choose an implicit default of 0 ("loop
// forever") or 1 ("loop exactly once"). Either is equally valid.
//
// However, when comparing the output of this convert-to-NIA program (backed
// by Wuffs' image codecs) with other convert-to-NIA programs, it is useful
// to canonicalize still images' "number of animation loops" to 0.
uint32_t n = g_num_animation_loops;
if (g_num_printed_frames <= 1) {
n = 0;
}
uint8_t data[8];
wuffs_base__poke_u32le__no_bounds_check(
data + 0x00,
wuffs_base__image_decoder__num_animation_loops(g_image_decoder));
wuffs_base__poke_u32le__no_bounds_check(data + 0x00, n);
wuffs_base__poke_u32le__no_bounds_check(data + 0x04, 0x80000000);
ignore_return_value(write(STDOUT_FD, &data[0], 8));
}
const char* //
main1(int argc, char** argv) {
TRY(parse_flags(argc, argv));
if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
return "main: unsandboxed";
}
g_src.data.ptr = g_src_buffer_array;
g_src.data.len = SRC_BUFFER_ARRAY_SIZE;
TRY(load_image_type());
TRY(load_image_config());
if (!g_flags.first_frame_only) {
print_nix_header(0x41AFC36E); // "nïA" as a u32le.
}
convert_frames() {
wuffs_base__flicks total_duration = 0;
while (true) {
// Decode the wuffs_base__frame_config.
@@ -515,7 +526,7 @@ main1(int argc, char** argv) {
if (dfc_status.repr == NULL) {
break;
} else if (dfc_status.repr == wuffs_base__note__end_of_data) {
goto done;
return NULL;
} else if (dfc_status.repr != wuffs_base__suspension__short_read) {
return wuffs_base__status__message(&dfc_status);
}
@@ -530,9 +541,6 @@ main1(int argc, char** argv) {
return "main: animation frame duration overflow";
}
total_duration += duration;
if (!g_flags.first_frame_only) {
print_nia_duration(total_duration);
}
if (wuffs_base__frame_config__index(&g_frame_config) == 0) {
fill_rectangle(
@@ -553,6 +561,7 @@ main1(int argc, char** argv) {
// Decode the frame (the pixels).
wuffs_base__status df_status;
const char* decode_frame_io_error_message = NULL;
while (true) {
df_status = wuffs_base__image_decoder__decode_frame(
g_image_decoder, &g_pixbuf, &g_src,
@@ -563,18 +572,57 @@ main1(int argc, char** argv) {
if (df_status.repr != wuffs_base__suspension__short_read) {
break;
}
TRY(read_more_src());
decode_frame_io_error_message = read_more_src();
if (decode_frame_io_error_message != NULL) {
// Neuter the "short read" df_status so that convert_frames returns the
// I/O error message instead.
df_status.repr = NULL;
break;
}
}
print_nie_frame();
// Update g_num_animation_loops. It's rare in practice, but the animation
// loop count can change over the course of decoding an image file.
//
// This program updates the global once per frame (even though the Wuffs
// API also lets you call wuffs_base__image_decoder__num_animation_loops
// just once, after the decoding is complete) to more closely match the
// Chromium web browser. This program emits (via print_nia_footer) the
// value from the final animation frame's update.
//
// Chromium image decoding uses two passes. (Wuffs' API lets you use a
// single pass but Chromium also wraps other libraries). Its first pass
// counts the number of animation frames (call it N). The second pass
// decodes exactly N frames. In particular, if the animation loop count
// would change between the end of frame N and the end of the file then
// Chromium's design will not pick up that change, even if it's a valid
// change in terms of the image file format.
//
// Specifically, for the test/data/artificial-gif/multiple-loop-counts.gif
// file this program emits 31 (0x1F) to match Chromium, even though the
// file arguably has a 41 (0x29) loop count after a complete decode.
g_num_animation_loops =
wuffs_base__image_decoder__num_animation_loops(g_image_decoder);
// Print a complete NIE frame (and surrounding bytes, for NIA).
if (!g_flags.first_frame_only) {
print_nia_duration(total_duration);
}
print_nie_frame();
if (!g_flags.first_frame_only) {
print_nia_padding();
}
// Return early if there was an error decoding the frame.
if (df_status.repr != NULL) {
return wuffs_base__status__message(&df_status);
} else if (decode_frame_io_error_message != NULL) {
return decode_frame_io_error_message;
} else if (g_flags.first_frame_only) {
return NULL;
}
print_nia_padding();
// Dispose the frame.
switch (wuffs_base__frame_config__disposal(&g_frame_config)) {
case WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND: {
fill_rectangle(
@@ -592,10 +640,29 @@ main1(int argc, char** argv) {
}
}
}
return "main: unreachable";
}
done:
print_nia_footer();
return NULL;
const char* //
main1(int argc, char** argv) {
TRY(parse_flags(argc, argv));
if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
return "main: unsandboxed";
}
g_src.data.ptr = g_src_buffer_array;
g_src.data.len = SRC_BUFFER_ARRAY_SIZE;
TRY(load_image_type());
TRY(load_image_config());
if (!g_flags.first_frame_only) {
print_nix_header(0x41AFC36E); // "nïA" as a u32le.
}
const char* ret = convert_frames();
if (!g_flags.first_frame_only) {
print_nia_footer();
}
return ret;
}
int //
+7 -14
View File
@@ -215,11 +215,9 @@ restore_background(wuffs_base__pixel_buffer* pb,
wuffs_base__rect_ie_u32 bounds,
wuffs_base__color_u32_argb_premul background_color) {
size_t width4 = (size_t)(wuffs_base__pixel_config__width(&pb->pixcfg)) * 4;
size_t y;
for (y = bounds.min_incl_y; y < bounds.max_excl_y; y++) {
size_t x;
for (size_t y = bounds.min_incl_y; y < bounds.max_excl_y; y++) {
uint8_t* d = g_curr_dst_buffer + (y * width4) + (bounds.min_incl_x * 4);
for (x = bounds.min_incl_x; x < bounds.max_excl_x; x++) {
for (size_t x = bounds.min_incl_x; x < bounds.max_excl_x; x++) {
wuffs_base__poke_u32le__no_bounds_check(d, background_color);
d += sizeof(wuffs_base__color_u32_argb_premul);
}
@@ -234,10 +232,8 @@ print_ascii_art(wuffs_base__pixel_buffer* pb) {
uint8_t* d = g_curr_dst_buffer;
uint8_t* p = g_printbuf.ptr;
*p++ = '\n';
uint32_t y;
for (y = 0; y < height; y++) {
uint32_t x;
for (x = 0; x < width; x++) {
for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) {
wuffs_base__color_u32_argb_premul c =
wuffs_base__peek_u32le__no_bounds_check(d);
d += sizeof(wuffs_base__color_u32_argb_premul);
@@ -265,10 +261,8 @@ print_color_art(wuffs_base__pixel_buffer* pb) {
uint8_t* p = g_printbuf.ptr;
*p++ = '\n';
p += sprintf((char*)p, "%s", g_reset_color);
uint32_t y;
for (y = 0; y < height; y++) {
uint32_t x;
for (x = 0; x < width; x++) {
for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) {
wuffs_base__color_u32_argb_premul c =
wuffs_base__peek_u32le__no_bounds_check(d);
d += sizeof(wuffs_base__color_u32_argb_premul);
@@ -416,10 +410,9 @@ play() {
if (wuffs_base__frame_config__index(&fc) == 0) {
wuffs_base__color_u32_argb_premul background_color =
wuffs_base__frame_config__background_color(&fc);
size_t i;
size_t n = g_dst_len / sizeof(wuffs_base__color_u32_argb_premul);
uint8_t* p = g_curr_dst_buffer;
for (i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
wuffs_base__poke_u32le__no_bounds_check(p, background_color);
p += sizeof(wuffs_base__color_u32_argb_premul);
}
+141 -12
View File
@@ -39,6 +39,7 @@ The Escape key quits.
*/
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -108,6 +109,119 @@ uint32_t g_background_color_index = 0;
int32_t g_zoom = 0;
bool g_filter = false;
struct {
int remaining_argc;
char** remaining_argv;
double screen_gamma;
} g_flags = {0};
static const char* g_usage =
"Usage: imageviewer -flags input0.gif input1.png\n"
"\n"
"Flags:\n"
" -screen_gamma=N.N (default 2.2; 0 disables gamma correction)";
const char* //
parse_flags(int argc, char** argv) {
g_flags.screen_gamma = 2.2;
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
for (; c < argc; c++) {
char* arg = argv[c];
if (*arg++ != '-') {
break;
}
// A double-dash "--foo" is equivalent to a single-dash "-foo". As special
// cases, a bare "-" is not a flag (some programs may interpret it as
// stdin) and a bare "--" means to stop parsing flags.
if (*arg == '\x00') {
break;
} else if (*arg == '-') {
arg++;
if (*arg == '\x00') {
c++;
break;
}
}
if (!strncmp(arg, "screen_gamma=", 13)) {
g_flags.screen_gamma = atof(arg + 13);
continue;
}
return g_usage;
}
g_flags.remaining_argc = argc - c;
g_flags.remaining_argv = argv + c;
return NULL;
}
class MyDecodeImageCallbacks : public wuffs_aux::DecodeImageCallbacks {
public:
MyDecodeImageCallbacks() : m_combined_gamma(1.0) {}
private:
std::string //
HandleMetadata(const wuffs_base__more_information& minfo,
wuffs_base__slice_u8 raw) override {
if (minfo.flavor == WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED) {
switch (minfo.metadata__fourcc()) {
case WUFFS_BASE__FOURCC__GAMA:
// metadata_parsed__gama returns the inverse gamma scaled by 1e5.
m_combined_gamma =
1e5 / (g_flags.screen_gamma * minfo.metadata_parsed__gama());
break;
}
}
return wuffs_aux::DecodeImageCallbacks::HandleMetadata(minfo, raw);
}
void //
Done(wuffs_aux::DecodeImageResult& result,
wuffs_aux::sync_io::Input& input,
wuffs_aux::IOBuffer& buffer,
wuffs_base__image_decoder::unique_ptr image_decoder) override {
// Apply basic color correction - gamma correction. Proper color correction
// should also involve considering any CHRM, ICCP and SRGB metadata but
// that requires a non-trivial amount of code (such as skcms, Skia's Color
// Management System). To keep this example program simple, we only
// consider GAMA metadata (and 8-bit color channels) here.
//
// This code also assumes that wuffs_aux::DecodeImageCallbacks defaults to
// producing a WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL pixel buffer.
if ((result.pixbuf.pixel_format().repr ==
WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL) &&
((m_combined_gamma < 0.9999) || (1.0001 < m_combined_gamma))) {
uint8_t lut[256];
lut[0x00] = 0x00;
lut[0xFF] = 0xFF;
for (uint32_t i = 1; i < 0xFF; i++) {
lut[i] =
(uint8_t)(floor(255.0 * pow(i / 255.0, m_combined_gamma) + 0.5));
}
wuffs_base__table_u8 t = result.pixbuf.plane(0);
size_t w4 = t.width / 4;
for (size_t y = 0; y < t.height; y++) {
uint8_t* ptr = t.ptr + (y * t.stride);
for (size_t x = 0; x < w4; x++) {
ptr[0] = lut[ptr[0]];
ptr[1] = lut[ptr[1]];
ptr[2] = lut[ptr[2]];
ptr += 4;
}
}
}
}
// m_combined_gamma holds the product of the screen gamma and the image
// file's inverse gamma.
double m_combined_gamma;
};
bool //
load_image(const char* filename) {
FILE* file = stdin;
@@ -127,14 +241,22 @@ load_image(const char* filename) {
g_pixbuf_mem_owner.reset();
g_pixbuf = wuffs_base__null_pixel_buffer();
wuffs_aux::DecodeImageCallbacks callbacks;
uint64_t dia_flags = 0;
if (g_flags.screen_gamma > 0) {
dia_flags |= wuffs_aux::DecodeImageArgFlags::REPORT_METADATA_GAMA;
}
MyDecodeImageCallbacks callbacks;
wuffs_aux::sync_io::FileInput input(file);
wuffs_aux::DecodeImageResult res = wuffs_aux::DecodeImage(
callbacks, input,
callbacks, input, wuffs_aux::DecodeImageArgQuirks::DefaultValue(),
wuffs_aux::DecodeImageArgFlags(dia_flags),
// Use PIXEL_BLEND__SRC_OVER, not the default PIXEL_BLEND__SRC, because
// we also pass a background color.
WUFFS_BASE__PIXEL_BLEND__SRC_OVER,
g_background_colors[g_background_color_index], MAX_INCL_DIMENSION);
wuffs_aux::DecodeImageArgPixelBlend(WUFFS_BASE__PIXEL_BLEND__SRC_OVER),
wuffs_aux::DecodeImageArgBackgroundColor(
g_background_colors[g_background_color_index]),
wuffs_aux::DecodeImageArgMaxInclDimension(MAX_INCL_DIMENSION));
if (filename) {
fclose(file);
}
@@ -348,6 +470,12 @@ load(xcb_connection_t* c, xcb_window_t w, const char* filename) {
int //
main(int argc, char** argv) {
const char* status = parse_flags(argc, argv);
if (status) {
fprintf(stderr, "%s\n", status);
return 1;
}
xcb_connection_t* c = xcb_connect(NULL, NULL);
g_maximum_request_length = xcb_get_maximum_request_length(c);
@@ -403,8 +531,9 @@ main(int argc, char** argv) {
g_pixmap_gc = xcb_generate_id(c);
g_pixmap_picture = xcb_generate_id(c);
bool loaded = load(c, w, (argc > 1) ? argv[1] : NULL);
int arg = 1;
bool loaded = load(
c, w, (g_flags.remaining_argc > 0) ? g_flags.remaining_argv[0] : NULL);
int arg = 0;
while (true) {
xcb_generic_event_t* event = xcb_wait_for_event(c);
@@ -439,14 +568,14 @@ main(int argc, char** argv) {
case ' ':
case XK_BackSpace:
case XK_Return:
if (argc <= 2) {
if (g_flags.remaining_argc <= 1) {
break;
}
arg += (i != XK_BackSpace) ? +1 : -1;
if (arg == 0) {
arg = argc - 1;
} else if (arg == argc) {
arg = 1;
if (arg < 0) {
arg = g_flags.remaining_argc - 1;
} else if (arg == g_flags.remaining_argc) {
arg = 0;
}
reload = true;
break;
@@ -501,7 +630,7 @@ main(int argc, char** argv) {
free(event);
if (reload) {
loaded = load(c, w, argv[arg]);
loaded = load(c, w, g_flags.remaining_argv[arg]);
xcb_clear_area(c, 1, w, 0, 0, 0xFFFF, 0xFFFF);
xcb_flush(c);
}
+1 -1
View File
@@ -359,7 +359,7 @@ main1(int argc, char** argv) {
wuffs_aux::sync_io::FileInput input(in);
return wuffs_aux::DecodeJson(
callbacks, input,
wuffs_base__make_slice_u32(g_quirks.data(), g_quirks.size()))
wuffs_aux::DecodeJsonArgQuirks(g_quirks.data(), g_quirks.size()))
.error_message;
}
+3 -2
View File
@@ -568,8 +568,9 @@ main1(int argc, char** argv) {
wuffs_aux::sync_io::FileInput input(in);
return wuffs_aux::DecodeJson(
callbacks, input,
wuffs_base__make_slice_u32(g_quirks.data(), g_quirks.size()),
(g_flags.query_c_string ? g_flags.query_c_string : ""))
wuffs_aux::DecodeJsonArgQuirks(g_quirks.data(), g_quirks.size()),
wuffs_aux::DecodeJsonArgJsonPointer(
g_flags.query_c_string ? g_flags.query_c_string : ""))
.error_message;
}
+1 -2
View File
@@ -1460,8 +1460,7 @@ main(int argc, char** argv) {
// Flags start with "-", unless it comes after a bare "--" arg.
{
bool dash_dash = false;
int a;
for (a = 1; a < argc; a++) {
for (int a = 1; a < argc; a++) {
char* arg = argv[a];
if ((arg[0] == '-') && !dash_dash) {
dash_dash = (arg[1] == '-') && (arg[2] == '\x00');
+1 -2
View File
@@ -337,8 +337,7 @@ main(int argc, char** argv) {
fprintf(stderr, "FAIL: %s\n", z);
return 1;
}
int i;
for (i = 0; i < g_flags.remaining_argc; i++) {
for (int i = 0; i < g_flags.remaining_argc; i++) {
int v = visit(g_flags.remaining_argv[i]);
if (v) {
return v;
+2
View File
@@ -42,6 +42,7 @@ It should print "PASS", amongst other information, and exit(0).
// compiling it.
#define WUFFS_IMPLEMENTATION
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
@@ -51,6 +52,7 @@ It should print "PASS", amongst other information, and exit(0).
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
+2
View File
@@ -42,6 +42,7 @@ It should print "PASS", amongst other information, and exit(0).
// compiling it.
#define WUFFS_IMPLEMENTATION
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
@@ -51,6 +52,7 @@ It should print "PASS", amongst other information, and exit(0).
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
+3 -2
View File
@@ -42,6 +42,7 @@ It should print "PASS", amongst other information, and exit(0).
// compiling it.
#define WUFFS_IMPLEMENTATION
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
@@ -51,6 +52,7 @@ It should print "PASS", amongst other information, and exit(0).
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
@@ -83,8 +85,7 @@ void set_quirks(wuffs_gif__decoder* dec, uint64_t hash) {
0,
};
uint32_t i;
for (i = 0; quirks[i]; i++) {
for (uint32_t i = 0; quirks[i]; i++) {
uint64_t bit = 1 << (i & 63);
if (hash & bit) {
wuffs_gif__decoder__set_quirk_enabled(dec, quirks[i], true);
+5 -3
View File
@@ -42,6 +42,7 @@ It should print "PASS", amongst other information, and exit(0).
// compiling it.
#define WUFFS_IMPLEMENTATION
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
@@ -51,6 +52,7 @@ It should print "PASS", amongst other information, and exit(0).
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
@@ -259,8 +261,7 @@ uint32_t g_quirks[] = {
};
void set_quirks(wuffs_json__decoder* dec, uint64_t hash) {
uint32_t i;
for (i = 0; g_quirks[i]; i++) {
for (uint32_t i = 0; g_quirks[i]; i++) {
uint64_t bit = 1 << (i & 63);
if (hash & bit) {
wuffs_json__decoder__set_quirk_enabled(dec, g_quirks[i], true);
@@ -513,7 +514,8 @@ fuzz_cpp(const uint8_t* in_ptr, size_t in_len, uint64_t hash) {
wuffs_aux::sync_io::MemoryInput input(in_ptr, in_len);
wuffs_aux::DecodeJson(
callbacks, input,
wuffs_base__make_slice_u32(quirks.data(), quirks.size()), json_pointer);
wuffs_aux::DecodeJsonArgQuirks(quirks.data(), quirks.size()),
wuffs_aux::DecodeJsonArgJsonPointer(json_pointer));
}
#endif // defined(__cplusplus)
+2
View File
@@ -42,6 +42,7 @@ It should print "PASS", amongst other information, and exit(0).
// compiling it.
#define WUFFS_IMPLEMENTATION
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
@@ -51,6 +52,7 @@ It should print "PASS", amongst other information, and exit(0).
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
+2
View File
@@ -42,6 +42,7 @@ It should print "PASS", amongst other information, and exit(0).
// compiling it.
#define WUFFS_IMPLEMENTATION
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
@@ -51,6 +52,7 @@ It should print "PASS", amongst other information, and exit(0).
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
+3 -3
View File
@@ -16,10 +16,10 @@
bmp: test/data/*.bmp ../bmpsuite_corpus/*.bmp
cbor: test/data/*.cbor
gif: test/data/*.gif test/data/artificial/*.gif
gzip: test/data/*.gz test/data/artificial/*.gz
gif: test/data/*.gif test/data/artificial-gif/*.gif
gzip: test/data/*.gz
json: test/data/*.json ../rapidjson_corpus/* ../simdjson_corpus/* ../JSONTestSuite/test_*/*.json
png: test/data/*.png ../pngsuite_corpus/*.png
png: test/data/*.png test/data/artificial-png/*.png ../pngsuite_corpus/*.png
wbmp: test/data/*.wbmp
zlib: test/data/*.zlib
+2
View File
@@ -42,6 +42,7 @@ It should print "PASS", amongst other information, and exit(0).
// compiling it.
#define WUFFS_IMPLEMENTATION
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
@@ -51,6 +52,7 @@ It should print "PASS", amongst other information, and exit(0).
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
+2 -1
View File
@@ -20,13 +20,14 @@ pointer. Anyway, here's what the output should look like:
```
$ ./run.sh
--- C Implementation Prints ---
0
12
56789
4294967295
0
3197704724
--------
------ Wuffs Impl Prints ------
0
12
56789
+2 -57
View File
@@ -12,67 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef USE_WUFFS
uint32_t parse(char* p, size_t n) {
uint32_t ret = 0;
for (size_t i = 0; (i < n) && p[i]; i++) {
ret = (10 * ret) + (p[i] - '0');
}
return ret;
}
#else // #ifndef USE_WUFFS
// TODO: this 'rough edge' shouldn't be necessary. See
// https://github.com/google/wuffs/issues/24
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_IMPLEMENTATION
#include "./parse.c"
uint32_t parse(char* p, size_t n) {
wuffs_base__status status;
wuffs_demo__parser* parser =
(wuffs_demo__parser*)(malloc(sizeof__wuffs_demo__parser()));
if (!parser) {
printf("malloc failed\n");
return 0;
}
status = wuffs_demo__parser__initialize(parser, sizeof__wuffs_demo__parser(),
WUFFS_VERSION, 0);
if (!wuffs_base__status__is_ok(&status)) {
printf("initialize: %s\n", wuffs_base__status__message(&status));
free(parser);
return 0;
}
wuffs_base__io_buffer iobuf;
iobuf.data.ptr = (uint8_t*)p;
iobuf.data.len = n;
iobuf.meta.wi = n;
iobuf.meta.ri = 0;
iobuf.meta.pos = 0;
iobuf.meta.closed = true;
status = wuffs_demo__parser__parse(parser, &iobuf);
if (!wuffs_base__status__is_ok(&status)) {
printf("parse: %s\n", wuffs_base__status__message(&status));
free(parser);
return 0;
}
uint32_t ret = wuffs_demo__parser__value(parser);
free(parser);
return ret;
}
#endif // #ifndef USE_WUFFS
// See naive-parse.c and wuffs-parse.c for implementations of this function.
uint32_t parse(char*, size_t);
void run(char* p) {
size_t n = strlen(p) + 1; // +1 for the trailing NUL that ends a C string.
+24
View File
@@ -0,0 +1,24 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <inttypes.h>
#include <stdlib.h>
uint32_t parse(char* p, size_t n) {
uint32_t ret = 0;
for (size_t i = 0; (i < n) && p[i]; i++) {
ret = (10 * ret) + (p[i] - '0');
}
return ret;
}
+7 -9
View File
@@ -18,16 +18,14 @@
CC=${CC:-gcc}
# You may need to run
# go get github.com/google/wuffs/cmd/wuffs-c
# go install github.com/google/wuffs/cmd/wuffs-c
# beforehand, to install the wuffs-c compiler.
wuffs-c gen -package_name demo < parse.wuffs > parse.c
$CC main.c
./a.out
echo --- C Implementation Prints ---
$CC main.c naive-parse.c -o n.out
./n.out
echo --------
$CC main.c -DUSE_WUFFS
./a.out
rm a.out parse.c
echo ------ Wuffs Impl Prints ------
$CC main.c wuffs-parse.c -o w.out
./w.out
+87
View File
@@ -0,0 +1,87 @@
// Copyright 2019 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
// TODO: this 'rough edge' shouldn't be necessary. See
// https://github.com/google/wuffs/issues/24
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_IMPLEMENTATION
#include "./parse.c"
uint32_t parse(char* p, size_t n) {
wuffs_base__status status;
// This next line of code allocates a wuffs_demo__parser on the stack. Stack
// allocation in C means uninitialized memory, so we need to call
// wuffs_demo__parser__initialize afterwards.
//
// An alternative, allocating on the heap and initializing in a single
// function call, is to say:
//
// wuffs_demo__parser* parser = wuffs_demo__parser__alloc();
// if (!parser) {
// // Out of memory.
// return 0;
// }
// // No need to call wuffs_demo__parser__initialize, but don't forget to
// // free(parser) before this function returns, taking extra care if this
// // function has multiple return points. Wuffs has no destructor functions
// // and Wuffs types never hold or own any resources in the RAII sense.
// // Just free the memory.
//
// For stack allocation, the C compiler needs to know
// sizeof(wuffs_demo__parser), but that compile-time value isn't guaranteed
// to be stable across Wuffs versions. Stack allocation is therefore only
// valid when the C file also #define's WUFFS_IMPLEMENTATION. When linking
// against a separately built Wuffs library (and the Wuffs types in this
// compilation are incomplete types), you'll have to use heap allocation.
wuffs_demo__parser parser;
// Initialize (and check status). An error here means that bad arguments were
// passed to wuffs_demo__parser__initialize.
//
// There are two other categories of not-OK status values, notes and
// suspensions, but they won't be encountered in this example.
status = wuffs_demo__parser__initialize(&parser, sizeof__wuffs_demo__parser(),
WUFFS_VERSION, 0);
if (!wuffs_base__status__is_ok(&status)) {
printf("initialize: %s\n", wuffs_base__status__message(&status));
return 0;
}
// True means that the wuffs_base__io_buffer is closed - we are at the end of
// the input. False would mean that there might be additional data in the
// byte stream (that this buffer is not large enough to hold all at once).
//
// In general, Wuffs' coroutine and suspension status mechanisms let it parse
// arbitrarily large data streams using fixed sized buffers, but that won't
// be encountered in this example.
wuffs_base__io_buffer iobuf =
wuffs_base__ptr_u8__reader((uint8_t*)p, n, true);
// Parse (and check status). An error here means that we had invalid input
// (i.e. "#not a digit" or "#too large").
//
// There are two other categories of not-OK status values, notes and
// suspensions, but they won't be encountered in this example.
status = wuffs_demo__parser__parse(&parser, &iobuf);
if (!wuffs_base__status__is_ok(&status)) {
printf("parse: %s\n", wuffs_base__status__message(&status));
return 0;
}
return wuffs_demo__parser__value(&parser);
}
+223
View File
@@ -25,6 +25,71 @@ namespace sync_io {
// --------
DynIOBuffer::DynIOBuffer(uint64_t max_incl)
: m_buf(wuffs_base__empty_io_buffer()), m_max_incl(max_incl) {}
DynIOBuffer::~DynIOBuffer() {
if (m_buf.data.ptr) {
free(m_buf.data.ptr);
}
}
void //
DynIOBuffer::drop() {
if (m_buf.data.ptr) {
free(m_buf.data.ptr);
}
m_buf = wuffs_base__empty_io_buffer();
}
DynIOBuffer::GrowResult //
DynIOBuffer::grow(uint64_t min_incl) {
uint64_t n = round_up(min_incl, m_max_incl);
if (n == 0) {
return ((min_incl == 0) && (m_max_incl == 0))
? DynIOBuffer::GrowResult::OK
: DynIOBuffer::GrowResult::FailedMaxInclExceeded;
} else if (n > m_buf.data.len) {
uint8_t* ptr = static_cast<uint8_t*>(realloc(m_buf.data.ptr, n));
if (!ptr) {
return DynIOBuffer::GrowResult::FailedOutOfMemory;
}
m_buf.data.ptr = ptr;
m_buf.data.len = n;
}
return DynIOBuffer::GrowResult::OK;
}
// round_up rounds min_incl up, returning the smallest value x satisfying
// (min_incl <= x) and (x <= max_incl) and some other constraints. It returns 0
// if there is no such x.
//
// When max_incl <= 4096, the other constraints are:
// - (x == max_incl)
//
// When max_incl > 4096, the other constraints are:
// - (x == max_incl) or (x is a power of 2)
// - (x >= 4096)
uint64_t //
DynIOBuffer::round_up(uint64_t min_incl, uint64_t max_incl) {
if (min_incl > max_incl) {
return 0;
}
uint64_t n = 4096;
if (n >= max_incl) {
return max_incl;
}
while (n < min_incl) {
if (n >= (max_incl / 2)) {
return max_incl;
}
n *= 2;
}
return n;
}
// --------
Input::~Input() {}
IOBuffer* //
@@ -99,6 +164,164 @@ MemoryInput::CopyIn(IOBuffer* dst) {
} // namespace sync_io
namespace private_impl {
struct ErrorMessages {
const char* max_incl_metadata_length_exceeded;
const char* out_of_memory;
const char* unexpected_end_of_file;
const char* unsupported_metadata;
const char* unsupported_negative_advance;
// If adding new "const char*" typed fields to this struct, either add them
// after existing fields or, if re-ordering fields, make sure that you update
// all of the "const private_impl::ErrorMessages FooBarErrorMessages" values
// in all of the sibling *.cc files.
static inline const char* resolve(const char* s) {
return s ? s : "wuffs_aux::private_impl: unknown error";
};
};
std::string //
AdvanceIOBufferTo(const ErrorMessages& error_messages,
sync_io::Input& input,
IOBuffer& io_buf,
uint64_t absolute_position) {
if (absolute_position < io_buf.reader_position()) {
return error_messages.resolve(error_messages.unsupported_negative_advance);
}
while (true) {
uint64_t relative_position = absolute_position - io_buf.reader_position();
if (relative_position <= io_buf.reader_length()) {
io_buf.meta.ri += (size_t)relative_position;
break;
} else if (io_buf.meta.closed) {
return error_messages.resolve(error_messages.unexpected_end_of_file);
}
io_buf.meta.ri = io_buf.meta.wi;
if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
return "";
}
std::string //
HandleMetadata(
const ErrorMessages& error_messages,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
sync_io::DynIOBuffer& raw,
wuffs_base__status (*tell_me_more_func)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*),
void* tell_me_more_receiver,
std::string (*handle_metadata_func)(void*,
const wuffs_base__more_information*,
wuffs_base__slice_u8),
void* handle_metadata_receiver) {
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
// Reset raw but keep its backing array (the raw.m_buf.data slice).
raw.m_buf.meta = wuffs_base__empty_io_buffer_meta();
while (true) {
minfo = wuffs_base__empty_more_information();
wuffs_base__status status = (*tell_me_more_func)(
tell_me_more_receiver, &raw.m_buf, &minfo, &io_buf);
switch (minfo.flavor) {
case 0:
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM:
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED:
break;
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH: {
wuffs_base__range_ie_u64 r = minfo.metadata_raw_passthrough__range();
if (r.is_empty()) {
break;
}
uint64_t num_to_copy = r.length();
if (num_to_copy > (raw.m_max_incl - raw.m_buf.meta.wi)) {
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
} else if (num_to_copy > (raw.m_buf.data.len - raw.m_buf.meta.wi)) {
switch (raw.grow(num_to_copy + raw.m_buf.meta.wi)) {
case sync_io::DynIOBuffer::GrowResult::OK:
break;
case sync_io::DynIOBuffer::GrowResult::FailedMaxInclExceeded:
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
case sync_io::DynIOBuffer::GrowResult::FailedOutOfMemory:
return error_messages.resolve(error_messages.out_of_memory);
}
}
if (io_buf.reader_position() > r.min_incl) {
return error_messages.resolve(error_messages.unsupported_metadata);
} else {
std::string error_message =
AdvanceIOBufferTo(error_messages, input, io_buf, r.min_incl);
if (!error_message.empty()) {
return error_message;
}
}
while (true) {
uint64_t n =
wuffs_base__u64__min(num_to_copy, io_buf.reader_length());
memcpy(raw.m_buf.writer_pointer(), io_buf.reader_pointer(), n);
raw.m_buf.meta.wi += n;
io_buf.meta.ri += n;
num_to_copy -= n;
if (num_to_copy == 0) {
break;
} else if (io_buf.meta.closed) {
return error_messages.resolve(
error_messages.unexpected_end_of_file);
} else if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
break;
}
default:
return error_messages.resolve(error_messages.unsupported_metadata);
}
if (status.repr == nullptr) {
break;
} else if (status.repr != wuffs_base__suspension__even_more_information) {
if (status.repr != wuffs_base__suspension__short_write) {
return status.message();
}
switch (raw.grow(wuffs_base__u64__sat_add(raw.m_buf.data.len, 1))) {
case sync_io::DynIOBuffer::GrowResult::OK:
break;
case sync_io::DynIOBuffer::GrowResult::FailedMaxInclExceeded:
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
case sync_io::DynIOBuffer::GrowResult::FailedOutOfMemory:
return error_messages.resolve(error_messages.out_of_memory);
}
}
}
return (*handle_metadata_func)(handle_metadata_receiver, &minfo,
raw.m_buf.reader_slice());
}
} // namespace private_impl
} // namespace wuffs_aux
#endif // !defined(WUFFS_CONFIG__MODULES) ||
+57
View File
@@ -36,6 +36,63 @@ namespace sync_io {
// --------
// DynIOBuffer is an IOBuffer that is backed by a dynamically sized byte array.
// It owns that backing array and will free it in its destructor.
//
// The array size can be explicitly extended (by calling the grow method) but,
// unlike a C++ std::vector, there is no implicit extension (e.g. by calling
// std::vector::insert) and its maximum size is capped by the max_incl
// constructor argument.
//
// It contains an IOBuffer-typed field whose reader side provides access to
// previously written bytes and whose writer side provides access to the
// allocated but not-yet-written-to slack space. For Go programmers, this slack
// space is roughly analogous to the s[len(s):cap(s)] space of a slice s.
class DynIOBuffer {
public:
enum GrowResult {
OK = 0,
FailedMaxInclExceeded = 1,
FailedOutOfMemory = 2,
};
// m_buf holds the dynamically sized byte array and its read/write indexes:
// - m_buf.meta.wi is roughly analogous to a Go slice's length.
// - m_buf.data.len is roughly analogous to a Go slice's capacity. It is
// also equal to the m_buf.data.ptr malloc/realloc size.
//
// Users should not modify the m_buf.data.ptr or m_buf.data.len fields (as
// they are conceptually private to this class), but they can modify the
// bytes referenced by that pointer-length pair (e.g. compactions).
IOBuffer m_buf;
// m_max_incl is an inclusive upper bound on the backing array size.
const uint64_t m_max_incl;
// Constructor and destructor.
explicit DynIOBuffer(uint64_t max_incl);
~DynIOBuffer();
// Drop frees the byte array and resets m_buf. The DynIOBuffer can still be
// used after a drop call. It just restarts from zero.
void drop();
// grow ensures that the byte array size is at least min_incl and at most
// max_incl. It returns FailedMaxInclExceeded if that would require
// allocating more than max_incl bytes, including the case where (min_incl >
// max_incl). It returns FailedOutOfMemory if memory allocation failed.
GrowResult grow(uint64_t min_incl);
private:
// Delete the copy and assign constructors.
DynIOBuffer(const DynIOBuffer&) = delete;
DynIOBuffer& operator=(const DynIOBuffer&) = delete;
static uint64_t round_up(uint64_t min_incl, uint64_t max_incl);
};
// --------
class Input {
public:
virtual ~Input();
+14 -3
View File
@@ -32,10 +32,21 @@ DecodeCborCallbacks::Done(DecodeCborResult& result,
sync_io::Input& input,
IOBuffer& buffer) {}
DecodeCborArgQuirks::DecodeCborArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeCborArgQuirks::DecodeCborArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeCborArgQuirks //
DecodeCborArgQuirks::DefaultValue() {
return DecodeCborArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeCborResult //
DecodeCbor(DecodeCborCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks) {
DecodeCborArgQuirks quirks) {
// Prepare the wuffs_base__io_buffer and the resultant error_message.
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
@@ -58,8 +69,8 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
ret_error_message = "wuffs_aux::DecodeCbor: out of memory";
goto done;
}
for (size_t i = 0; i < quirks.len; i++) {
dec->set_quirk_enabled(quirks.ptr[i], true);
for (size_t i = 0; i < quirks.repr.len; i++) {
dec->set_quirk_enabled(quirks.repr.ptr[i], true);
}
// Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.
+21 -1
View File
@@ -68,6 +68,26 @@ class DecodeCborCallbacks {
Done(DecodeCborResult& result, sync_io::Input& input, IOBuffer& buffer);
};
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeCborArgQuirks wraps an optional argument to DecodeCbor.
struct DecodeCborArgQuirks {
explicit DecodeCborArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeCborArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeCborArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeCbor calls callbacks based on the CBOR-formatted data in input.
//
// On success, the returned error_message is empty and cursor_position counts
@@ -77,6 +97,6 @@ class DecodeCborCallbacks {
DecodeCborResult //
DecodeCbor(DecodeCborCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32());
DecodeCborArgQuirks quirks = DecodeCborArgQuirks::DefaultValue());
} // namespace wuffs_aux
+161 -35
View File
@@ -93,6 +93,12 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_base__image_decoder::unique_ptr(nullptr, &free);
}
std::string //
DecodeImageCallbacks::HandleMetadata(const wuffs_base__more_information& minfo,
wuffs_base__slice_u8 raw) {
return "";
}
wuffs_base__pixel_format //
DecodeImageCallbacks::SelectPixfmt(
const wuffs_base__image_config& image_config) {
@@ -157,12 +163,16 @@ const char DecodeImage_BufferIsTooShort[] = //
"wuffs_aux::DecodeImage: buffer is too short";
const char DecodeImage_MaxInclDimensionExceeded[] = //
"wuffs_aux::DecodeImage: max_incl_dimension exceeded";
const char DecodeImage_MaxInclMetadataLengthExceeded[] = //
"wuffs_aux::DecodeImage: max_incl_metadata_length exceeded";
const char DecodeImage_OutOfMemory[] = //
"wuffs_aux::DecodeImage: out of memory";
const char DecodeImage_UnexpectedEndOfFile[] = //
"wuffs_aux::DecodeImage: unexpected end of file";
const char DecodeImage_UnsupportedImageFormat[] = //
"wuffs_aux::DecodeImage: unsupported image format";
const char DecodeImage_UnsupportedMetadata[] = //
"wuffs_aux::DecodeImage: unsupported metadata";
const char DecodeImage_UnsupportedPixelBlend[] = //
"wuffs_aux::DecodeImage: unsupported pixel blend";
const char DecodeImage_UnsupportedPixelConfiguration[] = //
@@ -170,38 +180,105 @@ const char DecodeImage_UnsupportedPixelConfiguration[] = //
const char DecodeImage_UnsupportedPixelFormat[] = //
"wuffs_aux::DecodeImage: unsupported pixel format";
DecodeImageArgQuirks::DecodeImageArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeImageArgQuirks::DecodeImageArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeImageArgQuirks //
DecodeImageArgQuirks::DefaultValue() {
return DecodeImageArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeImageArgFlags::DecodeImageArgFlags(uint64_t repr0) : repr(repr0) {}
DecodeImageArgFlags //
DecodeImageArgFlags::DefaultValue() {
return DecodeImageArgFlags(0);
}
DecodeImageArgPixelBlend::DecodeImageArgPixelBlend(
wuffs_base__pixel_blend repr0)
: repr(repr0) {}
DecodeImageArgPixelBlend //
DecodeImageArgPixelBlend::DefaultValue() {
return DecodeImageArgPixelBlend(WUFFS_BASE__PIXEL_BLEND__SRC);
}
DecodeImageArgBackgroundColor::DecodeImageArgBackgroundColor(
wuffs_base__color_u32_argb_premul repr0)
: repr(repr0) {}
DecodeImageArgBackgroundColor //
DecodeImageArgBackgroundColor::DefaultValue() {
return DecodeImageArgBackgroundColor(1);
}
DecodeImageArgMaxInclDimension::DecodeImageArgMaxInclDimension(uint32_t repr0)
: repr(repr0) {}
DecodeImageArgMaxInclDimension //
DecodeImageArgMaxInclDimension::DefaultValue() {
return DecodeImageArgMaxInclDimension(1048575);
}
DecodeImageArgMaxInclMetadataLength::DecodeImageArgMaxInclMetadataLength(
uint64_t repr0)
: repr(repr0) {}
DecodeImageArgMaxInclMetadataLength //
DecodeImageArgMaxInclMetadataLength::DefaultValue() {
return DecodeImageArgMaxInclMetadataLength(16777215);
}
// --------
namespace {
const private_impl::ErrorMessages DecodeImageErrorMessages = {
DecodeImage_MaxInclMetadataLengthExceeded, //
DecodeImage_OutOfMemory, //
DecodeImage_UnexpectedEndOfFile, //
DecodeImage_UnsupportedMetadata, //
DecodeImage_UnsupportedImageFormat, //
};
std::string //
DecodeImageAdvanceIOBuf(sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
bool compactable,
uint64_t min_excl_pos,
uint64_t pos) {
if ((pos <= min_excl_pos) || (pos < io_buf.reader_position())) {
// Redirects must go forward.
return DecodeImage_UnsupportedImageFormat;
}
while (true) {
uint64_t relative_pos = pos - io_buf.reader_position();
if (relative_pos <= io_buf.reader_length()) {
io_buf.meta.ri += (size_t)relative_pos;
break;
} else if (io_buf.meta.closed) {
return DecodeImage_UnexpectedEndOfFile;
}
io_buf.meta.ri = io_buf.meta.wi;
if (compactable) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
return "";
DecodeImageAdvanceIOBufferTo(sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
uint64_t absolute_position) {
return private_impl::AdvanceIOBufferTo(DecodeImageErrorMessages, input,
io_buf, absolute_position);
}
wuffs_base__status //
DIHM0(void* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_base__image_decoder__tell_me_more(
static_cast<wuffs_base__image_decoder*>(self), a_dst, a_minfo, a_src);
}
std::string //
DIHM1(void* self,
const wuffs_base__more_information* minfo,
wuffs_base__slice_u8 raw) {
return static_cast<DecodeImageCallbacks*>(self)->HandleMetadata(*minfo, raw);
}
std::string //
DecodeImageHandleMetadata(wuffs_base__image_decoder::unique_ptr& image_decoder,
DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
sync_io::DynIOBuffer& raw_metadata_buf) {
return private_impl::HandleMetadata(DecodeImageErrorMessages, input, io_buf,
raw_metadata_buf, DIHM0,
static_cast<void*>(image_decoder.get()),
DIHM1, static_cast<void*>(&callbacks));
}
DecodeImageResult //
@@ -209,9 +286,12 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
wuffs_base__slice_u32 quirks,
uint64_t flags,
wuffs_base__pixel_blend pixel_blend,
wuffs_base__color_u32_argb_premul background_color,
uint32_t max_incl_dimension) {
uint32_t max_incl_dimension,
uint64_t max_incl_metadata_length) {
// Check args.
switch (pixel_blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -222,6 +302,7 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
}
wuffs_base__image_config image_config = wuffs_base__null_image_config();
sync_io::DynIOBuffer raw_metadata_buf(max_incl_metadata_length);
uint64_t start_pos = io_buf.reader_position();
bool redirected = false;
int32_t fourcc = 0;
@@ -256,8 +337,12 @@ redirect:
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
uint64_t pos = minfo.io_redirect__range().min_incl;
std::string error_message = DecodeImageAdvanceIOBuf(
input, io_buf, !input.BringsItsOwnIOBuffer(), start_pos, pos);
if (pos <= start_pos) {
// Redirects must go forward.
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
std::string error_message =
DecodeImageAdvanceIOBufferTo(input, io_buf, pos);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -276,6 +361,36 @@ redirect:
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
// Apply quirks.
for (size_t i = 0; i < quirks.len; i++) {
image_decoder->set_quirk_enabled(quirks.ptr[i], true);
}
// Apply flags.
if (flags != 0) {
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_ICCP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_KVP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_SRGB) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_XMP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__XMP, true);
}
}
// Decode the image config.
while (true) {
wuffs_base__status id_dic_status =
@@ -288,6 +403,12 @@ redirect:
}
redirected = true;
goto redirect;
} else if (id_dic_status.repr == wuffs_base__note__metadata_reported) {
std::string error_message = DecodeImageHandleMetadata(
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
} else if (id_dic_status.repr != wuffs_base__suspension__short_read) {
return DecodeImageResult(id_dic_status.message());
} else if (io_buf.meta.closed) {
@@ -300,6 +421,7 @@ redirect:
}
}
} while (false);
raw_metadata_buf.drop();
// Select the pixel format.
uint32_t w = image_config.pixcfg.width();
@@ -410,9 +532,12 @@ redirect:
DecodeImageResult //
DecodeImage(DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__pixel_blend pixel_blend,
wuffs_base__color_u32_argb_premul background_color,
uint32_t max_incl_dimension) {
DecodeImageArgQuirks quirks,
DecodeImageArgFlags flags,
DecodeImageArgPixelBlend pixel_blend,
DecodeImageArgBackgroundColor background_color,
DecodeImageArgMaxInclDimension max_incl_dimension,
DecodeImageArgMaxInclMetadataLength max_incl_metadata_length) {
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
std::unique_ptr<uint8_t[]> fallback_io_array(nullptr);
@@ -425,8 +550,9 @@ DecodeImage(DecodeImageCallbacks& callbacks,
wuffs_base__image_decoder::unique_ptr image_decoder(nullptr, &free);
DecodeImageResult result =
DecodeImage0(image_decoder, callbacks, input, *io_buf, pixel_blend,
background_color, max_incl_dimension);
DecodeImage0(image_decoder, callbacks, input, *io_buf, quirks.repr,
flags.repr, pixel_blend.repr, background_color.repr,
max_incl_dimension.repr, max_incl_metadata_length.repr);
callbacks.Done(result, input, *io_buf, std::move(image_decoder));
return result;
}
+136 -8
View File
@@ -30,10 +30,11 @@ struct DecodeImageResult {
// DecodeImageCallbacks are the callbacks given to DecodeImage. They are always
// called in this order:
// 1. SelectDecoder
// 2. SelectPixfmt
// 3. AllocPixbuf
// 4. AllocWorkbuf
// 5. Done
// 2. HandleMetadata
// 3. SelectPixfmt
// 4. AllocPixbuf
// 5. AllocWorkbuf
// 6. Done
//
// It may return early - the third callback might not be invoked if the second
// one fails - but the final callback (Done) is always invoked.
@@ -90,6 +91,22 @@ class DecodeImageCallbacks {
virtual wuffs_base__image_decoder::unique_ptr //
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED
// If it is ETC__METADATA_RAW_ETC then raw contains the metadata bytes. Those
// bytes should not be retained beyond the the HandleMetadata call.
//
// minfo.metadata__fourcc() will typically match one of the
// DecodeImageArgFlags bits. For example, if (REPORT_METADATA_CHRM |
// REPORT_METADATA_GAMA) was passed to DecodeImage then the metadata FourCC
// will be either WUFFS_BASE__FOURCC__CHRM or WUFFS_BASE__FOURCC__GAMA.
//
// It returns an error message, or an empty string on success.
virtual std::string //
HandleMetadata(const wuffs_base__more_information& minfo,
wuffs_base__slice_u8 raw);
// SelectPixfmt returns the destination pixel format for AllocPixbuf. It
// should return wuffs_base__make_pixel_format(etc) called with one of:
// - WUFFS_BASE__PIXEL_FORMAT__BGR_565
@@ -156,13 +173,116 @@ class DecodeImageCallbacks {
extern const char DecodeImage_BufferIsTooShort[];
extern const char DecodeImage_MaxInclDimensionExceeded[];
extern const char DecodeImage_MaxInclMetadataLengthExceeded[];
extern const char DecodeImage_OutOfMemory[];
extern const char DecodeImage_UnexpectedEndOfFile[];
extern const char DecodeImage_UnsupportedImageFormat[];
extern const char DecodeImage_UnsupportedMetadata[];
extern const char DecodeImage_UnsupportedPixelBlend[];
extern const char DecodeImage_UnsupportedPixelConfiguration[];
extern const char DecodeImage_UnsupportedPixelFormat[];
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeImageArgQuirks wraps an optional argument to DecodeImage.
struct DecodeImageArgQuirks {
explicit DecodeImageArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeImageArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeImageArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeImageArgFlags wraps an optional argument to DecodeImage.
struct DecodeImageArgFlags {
explicit DecodeImageArgFlags(uint64_t repr0);
// DefaultValue returns 0.
static DecodeImageArgFlags DefaultValue();
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
// GAMA, ICCP, KVP, SRGB and XMP.
// Background Color.
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
// Primary Chromaticities and White Point.
static constexpr uint64_t REPORT_METADATA_CHRM = 0x0002;
// Exchangeable Image File Format.
static constexpr uint64_t REPORT_METADATA_EXIF = 0x0004;
// Gamma Correction.
static constexpr uint64_t REPORT_METADATA_GAMA = 0x0008;
// International Color Consortium Profile.
static constexpr uint64_t REPORT_METADATA_ICCP = 0x0010;
// Key-Value Pair.
//
// For PNG files, this includes iTXt, tEXt and zTXt chunks. In the
// HandleMetadata callback, the raw argument contains UTF-8 strings.
static constexpr uint64_t REPORT_METADATA_KVP = 0x0020;
// Modification Time.
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0040;
// Offset (2-Dimensional).
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0080;
// Physical Dimensions.
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0100;
// Standard Red Green Blue (Rendering Intent).
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0200;
// Extensible Metadata Platform.
static constexpr uint64_t REPORT_METADATA_XMP = 0x0400;
uint64_t repr;
};
// DecodeImageArgPixelBlend wraps an optional argument to DecodeImage.
struct DecodeImageArgPixelBlend {
explicit DecodeImageArgPixelBlend(wuffs_base__pixel_blend repr0);
// DefaultValue returns WUFFS_BASE__PIXEL_BLEND__SRC.
static DecodeImageArgPixelBlend DefaultValue();
wuffs_base__pixel_blend repr;
};
// DecodeImageArgBackgroundColor wraps an optional argument to DecodeImage.
struct DecodeImageArgBackgroundColor {
explicit DecodeImageArgBackgroundColor(
wuffs_base__color_u32_argb_premul repr0);
// DefaultValue returns 1, an invalid wuffs_base__color_u32_argb_premul.
static DecodeImageArgBackgroundColor DefaultValue();
wuffs_base__color_u32_argb_premul repr;
};
// DecodeImageArgMaxInclDimension wraps an optional argument to DecodeImage.
struct DecodeImageArgMaxInclDimension {
explicit DecodeImageArgMaxInclDimension(uint32_t repr0);
// DefaultValue returns 1048575 = 0x000F_FFFF, more than 1 million pixels.
static DecodeImageArgMaxInclDimension DefaultValue();
uint32_t repr;
};
// DecodeImageArgMaxInclMetadataLength wraps an optional argument to
// DecodeImage.
struct DecodeImageArgMaxInclMetadataLength {
explicit DecodeImageArgMaxInclMetadataLength(uint64_t repr0);
// DefaultValue returns 16777215 = 0x00FF_FFFF, one less than 16 MiB.
static DecodeImageArgMaxInclMetadataLength DefaultValue();
uint64_t repr;
};
// DecodeImage decodes the image data in input. A variety of image file formats
// can be decoded, depending on what callbacks.SelectDecoder returns.
//
@@ -205,12 +325,20 @@ extern const char DecodeImage_UnsupportedPixelFormat[];
// WUFFS_BASE__PIXEL_BLEND__SRC_OVER and the decoded image is not fully opaque.
//
// Decoding fails (with DecodeImage_MaxInclDimensionExceeded) if the image's
// width or height is greater than max_incl_dimension.
// width or height is greater than max_incl_dimension or if any opted-in (via
// flags bits) metadata is longer than max_incl_metadata_length.
DecodeImageResult //
DecodeImage(DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__pixel_blend pixel_blend = WUFFS_BASE__PIXEL_BLEND__SRC,
wuffs_base__color_u32_argb_premul background_color = 1, // Invalid.
uint32_t max_incl_dimension = 1048575); // 0x000F_FFFF
DecodeImageArgQuirks quirks = DecodeImageArgQuirks::DefaultValue(),
DecodeImageArgFlags flags = DecodeImageArgFlags::DefaultValue(),
DecodeImageArgPixelBlend pixel_blend =
DecodeImageArgPixelBlend::DefaultValue(),
DecodeImageArgBackgroundColor background_color =
DecodeImageArgBackgroundColor::DefaultValue(),
DecodeImageArgMaxInclDimension max_incl_dimension =
DecodeImageArgMaxInclDimension::DefaultValue(),
DecodeImageArgMaxInclMetadataLength max_incl_metadata_length =
DecodeImageArgMaxInclMetadataLength::DefaultValue());
} // namespace wuffs_aux
+28 -9
View File
@@ -37,6 +37,25 @@ const char DecodeJson_BadJsonPointer[] = //
const char DecodeJson_NoMatch[] = //
"wuffs_aux::DecodeJson: no match";
DecodeJsonArgQuirks::DecodeJsonArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeJsonArgQuirks::DecodeJsonArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeJsonArgQuirks //
DecodeJsonArgQuirks::DefaultValue() {
return DecodeJsonArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeJsonArgJsonPointer::DecodeJsonArgJsonPointer(std::string repr0)
: repr(repr0) {}
DecodeJsonArgJsonPointer //
DecodeJsonArgJsonPointer::DefaultValue() {
return DecodeJsonArgJsonPointer(std::string());
}
// --------
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
@@ -342,8 +361,8 @@ done:
DecodeJsonResult //
DecodeJson(DecodeJsonCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks,
std::string json_pointer) {
DecodeJsonArgQuirks quirks,
DecodeJsonArgJsonPointer json_pointer) {
// Prepare the wuffs_base__io_buffer and the resultant error_message.
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
@@ -371,9 +390,9 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
goto done;
}
bool allow_tilde_n_tilde_r_tilde_t = false;
for (size_t i = 0; i < quirks.len; i++) {
dec->set_quirk_enabled(quirks.ptr[i], true);
if (quirks.ptr[i] ==
for (size_t i = 0; i < quirks.repr.len; i++) {
dec->set_quirk_enabled(quirks.repr.ptr[i], true);
if (quirks.repr.ptr[i] ==
WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {
allow_tilde_n_tilde_r_tilde_t = true;
}
@@ -392,13 +411,13 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
std::string str;
// Walk the (optional) JSON Pointer.
for (size_t i = 0; i < json_pointer.size();) {
if (json_pointer[i] != '/') {
for (size_t i = 0; i < json_pointer.repr.size();) {
if (json_pointer.repr[i] != '/') {
ret_error_message = DecodeJson_BadJsonPointer;
goto done;
}
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
json_pointer.repr, i + 1, allow_tilde_n_tilde_r_tilde_t);
i = split.second;
if (i == 0) {
ret_error_message = DecodeJson_BadJsonPointer;
@@ -559,7 +578,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
// decode_tokens returns an ok status.
if (!ret_error_message.empty() ||
((depth == 0) && !json_pointer.empty())) {
((depth == 0) && !json_pointer.repr.empty())) {
goto done;
}
}
+33 -2
View File
@@ -69,6 +69,36 @@ class DecodeJsonCallbacks {
extern const char DecodeJson_BadJsonPointer[];
extern const char DecodeJson_NoMatch[];
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeJsonArgQuirks wraps an optional argument to DecodeJson.
struct DecodeJsonArgQuirks {
explicit DecodeJsonArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeJsonArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeJsonArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeJsonArgJsonPointer wraps an optional argument to DecodeJson.
struct DecodeJsonArgJsonPointer {
explicit DecodeJsonArgJsonPointer(std::string repr0);
// DefaultValue returns an empty string.
static DecodeJsonArgJsonPointer DefaultValue();
std::string repr;
};
// DecodeJson calls callbacks based on the JSON-formatted data in input.
//
// On success, the returned error_message is empty and cursor_position counts
@@ -86,7 +116,8 @@ extern const char DecodeJson_NoMatch[];
DecodeJsonResult //
DecodeJson(DecodeJsonCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32(),
std::string json_pointer = std::string());
DecodeJsonArgQuirks quirks = DecodeJsonArgQuirks::DefaultValue(),
DecodeJsonArgJsonPointer json_pointer =
DecodeJsonArgJsonPointer::DefaultValue());
} // namespace wuffs_aux
+3 -2
View File
@@ -29,13 +29,14 @@
#include <stdlib.h>
#include <string.h>
// Note that Clang also defines __GNUC__.
#ifdef __cplusplus
#if (__cplusplus >= 201103L) || defined(_MSC_VER)
#include <memory>
#define WUFFS_BASE__HAVE_EQ_DELETE
#define WUFFS_BASE__HAVE_UNIQUE_PTR
#elif defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#elif defined(__GNUC__) || defined(__clang__)
#warning "Wuffs' C++ code expects -std=c++11 or later"
#endif
+12 -12
View File
@@ -175,14 +175,14 @@ wuffs_base__ieee_754_bit_representation__from_f64_to_u32_truncate(double f) {
// padded with implicit zeroes.
//
// For example, if num_digits is 3 and digits is "\x07\x08\x09":
// - A decimal_point of -2 means ".00789"
// - A decimal_point of -1 means ".0789"
// - A decimal_point of +0 means ".789"
// - A decimal_point of +1 means "7.89"
// - A decimal_point of +2 means "78.9"
// - A decimal_point of +3 means "789."
// - A decimal_point of +4 means "7890."
// - A decimal_point of +5 means "78900."
// - A decimal_point of -2 means ".00789"
// - A decimal_point of -1 means ".0789"
// - A decimal_point of +0 means ".789"
// - A decimal_point of +1 means "7.89"
// - A decimal_point of +2 means "78.9"
// - A decimal_point of +3 means "789."
// - A decimal_point of +4 means "7890."
// - A decimal_point of +5 means "78900."
//
// As above, a decimal_point higher than +2047 means that the overall value is
// infinity, lower than -2047 means zero.
@@ -527,10 +527,10 @@ wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits(
// wuffs_base__private_implementation__high_prec_dec__rounded_integer returns
// the integral (non-fractional) part of h, provided that it is 18 or fewer
// decimal digits. For 19 or more digits, it returns UINT64_MAX. Note that:
// - (1 << 53) is 9007199254740992, which has 16 decimal digits.
// - (1 << 56) is 72057594037927936, which has 17 decimal digits.
// - (1 << 59) is 576460752303423488, which has 18 decimal digits.
// - (1 << 63) is 9223372036854775808, which has 19 decimal digits.
// - (1 << 53) is 9007199254740992, which has 16 decimal digits.
// - (1 << 56) is 72057594037927936, which has 17 decimal digits.
// - (1 << 59) is 576460752303423488, which has 18 decimal digits.
// - (1 << 63) is 9223372036854775808, which has 19 decimal digits.
// and that IEEE 754 double precision has 52 mantissa bits.
//
// That integral part is rounded-to-even: rounding 7.5 or 8.5 both give 8.
+4 -3
View File
@@ -49,8 +49,9 @@
goto suspend; \
case n:;
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__) || defined(__clang__)
#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
#else
@@ -208,7 +209,7 @@ wuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,
// --------
static inline wuffs_base__slice_u8 //
wuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) {
wuffs_base__table_u8__row_u32(wuffs_base__table_u8 t, uint32_t y) {
if (y < t.height) {
return wuffs_base__make_slice_u8(t.ptr + (t.stride * y), t.width);
}
+38 -6
View File
@@ -33,7 +33,7 @@
#define WUFFS_VERSION_MAJOR 0
#define WUFFS_VERSION_MINOR 0
#define WUFFS_VERSION_PATCH 0
#define WUFFS_VERSION_PRE_RELEASE_LABEL "work.in.progress"
#define WUFFS_VERSION_PRE_RELEASE_LABEL "unsupported.snapshot"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 0
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0
#define WUFFS_VERSION_STRING "0.0.0+0.00000000"
@@ -274,8 +274,9 @@ wuffs_base__cpu_arch__have_x86_sse42() {
#endif
#endif
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__) || defined(__clang__)
#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))
#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
@@ -473,7 +474,17 @@ typedef struct wuffs_base__transform__output__struct {
// --------
// FourCC constants.
// FourCC constants. Four Character Codes are literally four ASCII characters
// (sometimes padded with ' ' spaces) that pack neatly into a signed or
// unsigned 32-bit integer. ASCII letters are conventionally upper case.
//
// They are often used to identify video codecs (e.g. "H265") and pixel formats
// (e.g. "YV12"). Wuffs uses them for that but also generally for naming
// various things: compression formats (e.g. "BZ2 "), image metadata (e.g.
// "EXIF"), file formats (e.g. "HTML"), etc.
//
// Wuffs' u32 values are big-endian ("JPEG" is 0x4A504547 not 0x4745504A) to
// preserve ordering: "JPEG" < "MP3 " and 0x4A504547 < 0x4D503320.
// ¡ INSERT FourCCs.
@@ -736,7 +747,9 @@ wuffs_base__multiply_u64(uint64_t x, uint64_t y) {
// --------
#if defined(__GNUC__) && (__SIZEOF_LONG__ == 8)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if (defined(__GNUC__) || defined(__clang__)) && (__SIZEOF_LONG__ == 8)
static inline uint32_t //
wuffs_base__count_leading_zeroes_u64(uint64_t u) {
@@ -780,7 +793,7 @@ wuffs_base__count_leading_zeroes_u64(uint64_t u) {
return n;
}
#endif // defined(__GNUC__) && (__SIZEOF_LONG__ == 8)
#endif // (defined(__GNUC__) || defined(__clang__)) && (__SIZEOF_LONG__ == 8)
// --------
@@ -1344,6 +1357,25 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__table_u8__subtable_ij returns t[ix:jx, iy:jy].
//
// It returns an empty table if i or j is out of bounds.
static inline wuffs_base__table_u8 //
wuffs_base__table_u8__subtable_ij(wuffs_base__table_u8 t,
uint64_t ix,
uint64_t iy,
uint64_t jx,
uint64_t jy) {
if ((ix <= jx) && (jx <= SIZE_MAX) && (jx <= t.width) && //
(iy <= jy) && (jy <= SIZE_MAX) && (jy <= t.height)) {
return wuffs_base__make_table_u8(t.ptr + ix + (iy * t.stride), //
((size_t)(jx - ix)), //
((size_t)(jy - iy)), //
t.stride); //
}
return wuffs_base__make_table_u8(NULL, 0, 0, 0);
}
// wuffs_base__table__flattened_length returns the number of elements covered
// by the 1-dimensional span that backs a 2-dimensional table. This counts the
// elements inside the table and, when width != stride, the elements outside
+8 -8
View File
@@ -160,7 +160,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -168,7 +168,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
return 0;
}
uint8_t* p = *ptr_iop_w;
if ((size_t)(p - io1_w) < (size_t)(distance)) {
if ((size_t)(p - io0_w) < (size_t)(distance)) {
return 0;
}
uint8_t* q = p - distance;
@@ -205,10 +205,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
// The caller needs to prove that:
// - length <= (io2_w - *ptr_iop_w)
// - distance >= 1
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -240,11 +240,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
// The caller needs to prove that:
// - (length + 8) <= (io2_w - *ptr_iop_w)
// - distance == 1
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -280,11 +280,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
// The caller needs to prove that:
// - (length + 8) <= (io2_w - *ptr_iop_w)
// - distance >= 8
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
+39 -21
View File
@@ -22,19 +22,23 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
//
// Keep it sorted by magic[1], then magic[0] descending and finally by
// magic[2:]. When multiple entries match, the longest one wins.
//
// The fourcc field might be negated, in which case there's further
// specialization (see § below).
static struct {
int32_t fourcc;
const char* magic;
} table[] = {
{0x57424D50, "\x01\x00\x00"}, // WBMP
{0x424D5020, "\x01\x42\x4D"}, // BMP
{0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF (see § below)
{0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{0x4A504547, "\x01\xFF\xD8"}, // JPEG
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
};
static const size_t table_len = sizeof(table) / sizeof(table[0]);
@@ -75,19 +79,33 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
return 0;
match:
// Some FourCC values (see § above) are further specialized.
if (fourcc == 0x52494646) { // 'RIFF'be
if (prefix.len < 16) {
return -1;
}
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
if (x == 0x57454250) { // 'WEBP'be
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
if (y == 0x56503820) { // 'VP8 'be
return 0x57503820; // 'WP8 'be
} else if (y == 0x5650384C) { // 'VP8L'be
return 0x5750384C; // 'WP8L'be
// Negative FourCC values (see § above) are further specialized.
if (fourcc < 0) {
fourcc = -fourcc;
if (fourcc == 0x52494646) { // 'RIFF'be
if (prefix.len < 12) {
return -1;
}
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
if (x == 0x57454250) { // 'WEBP'be
return 0x57454250; // 'WEBP'be
}
} else if (fourcc == 0x30302020) { // '00 'be
// Binary data starting with multiple 0x00 NUL bytes is quite common.
if (prefix.len < 4) {
return -1;
} else if ((prefix.ptr[2] != 0x00) &&
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
// Roughly speaking, this could be a non-degenerate (non-0-width and
// non-0-height) WBMP image.
return 0x57424D50; // 'WBMP'be
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
(prefix.ptr[3] == 0x00)) {
return 0x49434F20; // 'ICO 'be
}
return 0;
}
}
return fourcc;
+61 -43
View File
@@ -501,14 +501,23 @@ static inline uint32_t //
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
uint32_t src_nonpremul) {
// Extract 16-bit color components.
//
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
// return src_nonpremul. This isn't just an optimization (skipping the rest
// of the function's computation). It also preserves the nonpremul
// distinction between e.g. transparent red and transparent blue that would
// otherwise be lost by converting from nonpremul to premul and back.
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
if (da == 0) {
return src_nonpremul;
}
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -545,14 +554,23 @@ static inline uint64_t //
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
uint64_t src_nonpremul) {
// Extract components.
//
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
// return src_nonpremul. This isn't just an optimization (skipping the rest
// of the function's computation). It also preserves the nonpremul
// distinction between e.g. transparent red and transparent blue that would
// otherwise be lost by converting from nonpremul to premul and back.
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
if (da == 0) {
return src_nonpremul;
}
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -583,14 +601,14 @@ static inline uint32_t //
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
uint32_t src_premul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -627,14 +645,14 @@ static inline uint64_t //
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
uint64_t src_premul) {
// Extract components.
uint64_t sa = 0xFFFF & (src_premul >> 48);
uint64_t sr = 0xFFFF & (src_premul >> 32);
uint64_t sg = 0xFFFF & (src_premul >> 16);
uint64_t sb = 0xFFFF & (src_premul >> 0);
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
uint64_t sa = 0xFFFF & (src_premul >> 48);
uint64_t sr = 0xFFFF & (src_premul >> 32);
uint64_t sg = 0xFFFF & (src_premul >> 16);
uint64_t sb = 0xFFFF & (src_premul >> 0);
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -665,14 +683,14 @@ static inline uint32_t //
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
uint32_t src_nonpremul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -697,14 +715,14 @@ static inline uint64_t //
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
uint64_t src_nonpremul) {
// Extract components.
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
uint64_t da = 0xFFFF & (dst_premul >> 48);
uint64_t dr = 0xFFFF & (dst_premul >> 32);
uint64_t dg = 0xFFFF & (dst_premul >> 16);
uint64_t db = 0xFFFF & (dst_premul >> 0);
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint64_t ia = 0xFFFF - sa;
@@ -723,14 +741,14 @@ static inline uint32_t //
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
uint32_t src_premul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -1790,13 +1808,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sr = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sb = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -1838,13 +1856,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -1913,13 +1931,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sr = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sb = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -1991,13 +2009,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sb = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sr = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -2066,13 +2084,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sb = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sr = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
+129
View File
@@ -829,14 +829,24 @@ typedef struct wuffs_base__more_information__struct {
inline wuffs_base__range_ie_u64 io_redirect__range() const;
inline uint64_t io_seek__position() const;
inline uint32_t metadata__fourcc() const;
// Deprecated: use metadata_raw_passthrough__range.
inline wuffs_base__range_ie_u64 metadata__range() const;
inline wuffs_base__range_ie_u64 metadata_raw_passthrough__range() const;
inline int32_t metadata_parsed__chrm(uint32_t component) const;
inline uint32_t metadata_parsed__gama() const;
inline uint32_t metadata_parsed__srgb() const;
#endif // __cplusplus
} wuffs_base__more_information;
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_REDIRECT 1
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_SEEK 2
// Deprecated: use
// WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH.
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA 3
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH 3
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM 4
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED 5
static inline wuffs_base__more_information //
wuffs_base__empty_more_information() {
@@ -893,6 +903,8 @@ wuffs_base__more_information__metadata__fourcc(
return m->w;
}
// Deprecated: use
// wuffs_base__more_information__metadata_raw_passthrough__range.
static inline wuffs_base__range_ie_u64 //
wuffs_base__more_information__metadata__range(
const wuffs_base__more_information* m) {
@@ -902,6 +914,103 @@ wuffs_base__more_information__metadata__range(
return ret;
}
static inline wuffs_base__range_ie_u64 //
wuffs_base__more_information__metadata_raw_passthrough__range(
const wuffs_base__more_information* m) {
wuffs_base__range_ie_u64 ret;
ret.min_incl = m->y;
ret.max_excl = m->z;
return ret;
}
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__WHITE_X 0
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__WHITE_Y 1
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__RED_X 2
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__RED_Y 3
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__GREEN_X 4
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__GREEN_Y 5
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__BLUE_X 6
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__BLUE_Y 7
// wuffs_base__more_information__metadata_parsed__chrm returns chromaticity
// values (scaled by 100000) like the PNG "cHRM" chunk. For example, the sRGB
// color space corresponds to:
// - ETC__CHRM__WHITE_X 31270
// - ETC__CHRM__WHITE_Y 32900
// - ETC__CHRM__RED_X 64000
// - ETC__CHRM__RED_Y 33000
// - ETC__CHRM__GREEN_X 30000
// - ETC__CHRM__GREEN_Y 60000
// - ETC__CHRM__BLUE_X 15000
// - ETC__CHRM__BLUE_Y 6000
//
// See
// https://ciechanow.ski/color-spaces/#chromaticity-and-white-point-coordinates
static inline int32_t //
wuffs_base__more_information__metadata_parsed__chrm(
const wuffs_base__more_information* m,
uint32_t component) {
// After the flavor and the w field (holding a FourCC), a
// wuffs_base__more_information holds 24 bytes of data in three uint64_t
// typed fields (x, y and z). We pack the eight chromaticity values (wx, wy,
// rx, ..., by), basically int24_t values, into 24 bytes like this:
// - LSB MSB
// - x: wx wx wx wy wy wy rx rx
// - y: rx ry ry ry gx gx gx gy
// - z: gy gy bx bx bx by by by
uint32_t u = 0;
switch (component & 7) {
case 0:
u = ((uint32_t)(m->x >> 0));
break;
case 1:
u = ((uint32_t)(m->x >> 24));
break;
case 2:
u = ((uint32_t)((m->x >> 48) | (m->y << 16)));
break;
case 3:
u = ((uint32_t)(m->y >> 8));
break;
case 4:
u = ((uint32_t)(m->y >> 32));
break;
case 5:
u = ((uint32_t)((m->y >> 56) | (m->z << 8)));
break;
case 6:
u = ((uint32_t)(m->z >> 16));
break;
case 7:
u = ((uint32_t)(m->z >> 40));
break;
}
// The left-right shifts sign-extend from 24-bit to 32-bit integers.
return ((int32_t)(u << 8)) >> 8;
}
// wuffs_base__more_information__metadata_parsed__gama returns inverse gamma
// correction values (scaled by 100000) like the PNG "gAMA" chunk. For example,
// for gamma = 2.2, this returns 45455 (approximating 100000 / 2.2).
static inline uint32_t //
wuffs_base__more_information__metadata_parsed__gama(
const wuffs_base__more_information* m) {
return ((uint32_t)(m->x));
}
#define WUFFS_BASE__SRGB_RENDERING_INTENT__PERCEPTUAL 0
#define WUFFS_BASE__SRGB_RENDERING_INTENT__RELATIVE_COLORIMETRIC 1
#define WUFFS_BASE__SRGB_RENDERING_INTENT__SATURATION 2
#define WUFFS_BASE__SRGB_RENDERING_INTENT__ABSOLUTE_COLORIMETRIC 3
// wuffs_base__more_information__metadata_parsed__srgb returns the sRGB
// rendering intent like the PNG "sRGB" chunk.
static inline uint32_t //
wuffs_base__more_information__metadata_parsed__srgb(
const wuffs_base__more_information* m) {
return m->x & 3;
}
#ifdef __cplusplus
inline void //
@@ -939,4 +1048,24 @@ wuffs_base__more_information::metadata__range() const {
return wuffs_base__more_information__metadata__range(this);
}
inline wuffs_base__range_ie_u64 //
wuffs_base__more_information::metadata_raw_passthrough__range() const {
return wuffs_base__more_information__metadata_raw_passthrough__range(this);
}
inline int32_t //
wuffs_base__more_information::metadata_parsed__chrm(uint32_t component) const {
return wuffs_base__more_information__metadata_parsed__chrm(this, component);
}
inline uint32_t //
wuffs_base__more_information::metadata_parsed__gama() const {
return wuffs_base__more_information__metadata_parsed__gama(this);
}
inline uint32_t //
wuffs_base__more_information::metadata_parsed__srgb() const {
return wuffs_base__more_information__metadata_parsed__srgb(this);
}
#endif // __cplusplus
+3 -3
View File
@@ -96,9 +96,9 @@
// wuffs_base__ieee_754_bit_representation__etc converts between a double
// precision numerical value and its IEEE 754 representations:
// - 16-bit: 1 sign bit, 5 exponent bits, 10 explicit significand bits.
// - 32-bit: 1 sign bit, 8 exponent bits, 23 explicit significand bits.
// - 64-bit: 1 sign bit, 11 exponent bits, 52 explicit significand bits.
// - 16-bit: 1 sign bit, 5 exponent bits, 10 explicit significand bits.
// - 32-bit: 1 sign bit, 8 exponent bits, 23 explicit significand bits.
// - 64-bit: 1 sign bit, 11 exponent bits, 52 explicit significand bits.
//
// For example, it converts between:
// - +1.0 and 0x3C00, 0x3F80_0000 or 0x3FF0_0000_0000_0000.
+11 -2
View File
@@ -1026,9 +1026,18 @@ func (g *gen) writeBuiltinTable(b *buffer, recv *a.Expr, method t.ID, args []*a.
case t.IDWidth:
field = "width"
case t.IDRow:
case t.IDRowU32:
// TODO: don't assume that the table is a table of base.u8.
b.writes("wuffs_base__table_u8__row(")
b.writes("wuffs_base__table_u8__row_u32(")
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
b.writes(", ")
return g.writeArgs(b, args, depth)
case t.IDSubtable:
// TODO: don't assume that the table is a table of base.u8.
b.writes("wuffs_base__table_u8__subtable_ij(")
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
+6 -1
View File
@@ -123,7 +123,12 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, sideEffectsOnly bool, depth u
if err := g.writeExpr(b, recv, false, depth); err != nil {
return err
}
b.printf(", sizeof (%s%s), WUFFS_VERSION, 0))", g.packagePrefix(qid), qid[1].Str(g.tm))
b.printf(",\nsizeof (%s%s), WUFFS_VERSION, ", g.packagePrefix(qid), qid[1].Str(g.tm))
if recv.IsThisDotFoo() != 0 {
b.writes("WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED))")
} else {
b.writes("0))")
}
return nil
}
+9 -4
View File
@@ -386,10 +386,15 @@ func (n *Expr) SetMBounds(x interval.IntRange) { n.mBounds = x }
func (n *Expr) SetMType(x *TypeExpr) { n.mType = x }
func (n *Expr) IsArgsDotFoo() (foo t.ID) {
if n.id0 == t.IDDot {
if (n.lhs.id0 == 0) && (n.lhs.id2 == t.IDArgs) {
return n.id2
}
if (n.id0 == t.IDDot) && (n.lhs.id0 == 0) && (n.lhs.id2 == t.IDArgs) {
return n.id2
}
return 0
}
func (n *Expr) IsThisDotFoo() (foo t.ID) {
if (n.id0 == t.IDDot) && (n.lhs.id0 == 0) && (n.lhs.id2 == t.IDThis) {
return n.id2
}
return 0
}
+31 -3
View File
@@ -28,13 +28,17 @@ import (
)
var FourCCs = [...][2]string{
{"BGCL", "Background Color"},
{"BMP ", "Bitmap"},
{"BRTL", "Brotli"},
{"BZ2 ", "Bzip2"},
{"CBOR", "Concise Binary Object Representation"},
{"CHRM", "Primary Chromaticities and White Point"},
{"CSS ", "Cascading Style Sheets"},
{"EPS ", "Encapsulated PostScript"},
{"EXIF", "Exchangeable Image File Format"},
{"FLAC", "Free Lossless Audio Codec"},
{"GAMA", "Gamma Correction"},
{"GIF ", "Graphics Interchange Format"},
{"GZ ", "GNU Zip"},
{"HEIF", "High Efficiency Image File"},
@@ -47,29 +51,37 @@ var FourCCs = [...][2]string{
{"JS ", "JavaScript"},
{"JSON", "JavaScript Object Notation"},
{"JWCC", "JSON With Commas and Comments"},
{"KVP ", "Key-Value Pair"},
{"KVPK", "Key-Value Pair (Key)"},
{"KVPV", "Key-Value Pair (Value)"},
{"LZ4 ", "Lempel–Ziv 4"},
{"MD ", "Markdown"},
{"MTIM", "Modification Time"},
{"MP3 ", "MPEG-1 Audio Layer III"},
{"NIE ", "Naive Image"},
{"OFS2", "Offset (2-Dimensional)"},
{"OTF ", "Open Type Format"},
{"PDF ", "Portable Document Format"},
{"PHYD", "Physical Dimensions"},
{"PNG ", "Portable Network Graphics"},
{"PNM ", "Portable Anymap"},
{"PS ", "PostScript"},
{"QOI ", "Quite OK Image"},
{"RAC ", "Random Access Compression"},
{"RAW ", "Raw"},
{"RIFF", "Resource Interchange File Format"},
{"RIGL", "Riegeli Records"},
{"SNPY", "Snappy"},
{"SRGB", "Standard Red Green Blue (Rendering Intent)"},
{"SVG ", "Scalable Vector Graphics"},
{"TAR ", "Tape Archive"},
{"TEXT", "Text"},
{"TIFF", "Tagged Image File Format"},
{"TOML", "Tom's Obvious Minimal Language"},
{"WAVE", "Waveform"},
{"WBMP", "Wireless Bitmap"},
{"WEBP", "Web Picture"},
{"WOFF", "Web Open Font Format"},
{"WP8 ", "Web Picture (VP8)"},
{"WP8L", "Web Picture (VP8 Lossless)"},
{"XML ", "Extensible Markup Language"},
{"XMP ", "Extensible Metadata Platform"},
{"XZ ", "Xz"},
@@ -85,6 +97,20 @@ var Consts = [...]struct {
}{
// ----
{t.IDU8, "0", "ANIMATION_DISPOSAL__NONE"},
{t.IDU8, "1", "ANIMATION_DISPOSAL__RESTORE_BACKGROUND"},
{t.IDU8, "2", "ANIMATION_DISPOSAL__RESTORE_PREVIOUS"},
// ----
{t.IDU32, "1", "MORE_INFORMATION__FLAVOR__IO_REDIRECT"},
{t.IDU32, "2", "MORE_INFORMATION__FLAVOR__IO_SEEK"},
{t.IDU32, "3", "MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH"},
{t.IDU32, "4", "MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM"},
{t.IDU32, "5", "MORE_INFORMATION__FLAVOR__METADATA_PARSED"},
// ----
{t.IDU32, "0x02000008", "PIXEL_FORMAT__A"},
{t.IDU32, "0x20000008", "PIXEL_FORMAT__Y"},
@@ -940,7 +966,9 @@ var TableFuncs = []string{
"GENERIC T2.stride() u64",
"GENERIC T2.width() u64",
"GENERIC T2.row(y: u32) T1",
"GENERIC T2.row_u32(y: u32) T1",
"GENERIC T2.subtable(" +
"min_incl_x: u64, min_incl_y: u64, max_incl_x: u64, max_incl_y: u64) T2",
}
func ParseFuncs(tm *t.Map, ss []string, callback func(*a.Func) error) error {
+4
View File
@@ -135,6 +135,10 @@ func Check(tm *t.Map, files []*a.File, resolveUse func(usePath string) ([]byte,
}
xType := (*a.TypeExpr)(nil)
switch z.Type {
case t.IDU8:
xType = typeExprU8
case t.IDU16:
xType = typeExprU16
case t.IDU32:
xType = typeExprU32
case t.IDU64:
+10 -6
View File
@@ -668,12 +668,14 @@ const (
IDIO = ID(0x242)
IDLimit = ID(0x243)
IDPrefix = ID(0x244)
IDRow = ID(0x245)
IDRowU32 = ID(0x245)
IDStride = ID(0x246)
IDSuffix = ID(0x247)
IDUintptrLow12Bits = ID(0x248)
IDValidUTF8Length = ID(0x249)
IDWidth = ID(0x24A)
IDSubslice = ID(0x247)
IDSubtable = ID(0x248)
IDSuffix = ID(0x249)
IDUintptrLow12Bits = ID(0x24A)
IDValidUTF8Length = ID(0x24B)
IDWidth = ID(0x24C)
IDLimitedSwizzleU32InterleavedFromReader = ID(0x280)
IDSwizzleInterleavedFromReader = ID(0x281)
@@ -1092,8 +1094,10 @@ var builtInsByID = [nBuiltInIDs]string{
IDIO: "io",
IDLimit: "limit",
IDPrefix: "prefix",
IDRow: "row",
IDRowU32: "row_u32",
IDStride: "stride",
IDSubslice: "subslice",
IDSubtable: "subtable",
IDSuffix: "suffix",
IDUintptrLow12Bits: "uintptr_low_12_bits",
IDValidUTF8Length: "valid_utf_8_length",
+2 -2
View File
@@ -25,8 +25,8 @@ import (
func TestCut(tt *testing.T) {
testcut.Test(tt, SmallestValidMaxEncodedLen, Cut, newReader, []string{
"artificial/deflate-backref-crosses-blocks.deflate",
"artificial/deflate-distance-32768.deflate",
"artificial-deflate/backref-crosses-blocks.deflate",
"artificial-deflate/distance-32768.deflate",
"romeo.txt.deflate",
"romeo.txt.fixed-huff.deflate",
})
+4016 -656
View File
@@ -54,13 +54,14 @@
#include <stdlib.h>
#include <string.h>
// Note that Clang also defines __GNUC__.
#ifdef __cplusplus
#if (__cplusplus >= 201103L) || defined(_MSC_VER)
#include <memory>
#define WUFFS_BASE__HAVE_EQ_DELETE
#define WUFFS_BASE__HAVE_UNIQUE_PTR
#elif defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#elif defined(__GNUC__) || defined(__clang__)
#warning "Wuffs' C++ code expects -std=c++11 or later"
#endif
@@ -88,7 +89,7 @@ extern "C" {
#define WUFFS_VERSION_MAJOR 0
#define WUFFS_VERSION_MINOR 0
#define WUFFS_VERSION_PATCH 0
#define WUFFS_VERSION_PRE_RELEASE_LABEL "work.in.progress"
#define WUFFS_VERSION_PRE_RELEASE_LABEL "unsupported.snapshot"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 0
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0
#define WUFFS_VERSION_STRING "0.0.0+0.00000000"
@@ -329,8 +330,9 @@ wuffs_base__cpu_arch__have_x86_sse42() {
#endif
#endif
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__) || defined(__clang__)
#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))
#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
@@ -558,7 +560,20 @@ typedef struct wuffs_base__transform__output__struct {
// --------
// FourCC constants.
// FourCC constants. Four Character Codes are literally four ASCII characters
// (sometimes padded with ' ' spaces) that pack neatly into a signed or
// unsigned 32-bit integer. ASCII letters are conventionally upper case.
//
// They are often used to identify video codecs (e.g. "H265") and pixel formats
// (e.g. "YV12"). Wuffs uses them for that but also generally for naming
// various things: compression formats (e.g. "BZ2 "), image metadata (e.g.
// "EXIF"), file formats (e.g. "HTML"), etc.
//
// Wuffs' u32 values are big-endian ("JPEG" is 0x4A504547 not 0x4745504A) to
// preserve ordering: "JPEG" < "MP3 " and 0x4A504547 < 0x4D503320.
// Background Color.
#define WUFFS_BASE__FOURCC__BGCL 0x4247434C
// Bitmap.
#define WUFFS_BASE__FOURCC__BMP 0x424D5020
@@ -572,15 +587,24 @@ typedef struct wuffs_base__transform__output__struct {
// Concise Binary Object Representation.
#define WUFFS_BASE__FOURCC__CBOR 0x43424F52
// Primary Chromaticities and White Point.
#define WUFFS_BASE__FOURCC__CHRM 0x4348524D
// Cascading Style Sheets.
#define WUFFS_BASE__FOURCC__CSS 0x43535320
// Encapsulated PostScript.
#define WUFFS_BASE__FOURCC__EPS 0x45505320
// Exchangeable Image File Format.
#define WUFFS_BASE__FOURCC__EXIF 0x45584946
// Free Lossless Audio Codec.
#define WUFFS_BASE__FOURCC__FLAC 0x464C4143
// Gamma Correction.
#define WUFFS_BASE__FOURCC__GAMA 0x47414D41
// Graphics Interchange Format.
#define WUFFS_BASE__FOURCC__GIF 0x47494620
@@ -617,24 +641,42 @@ typedef struct wuffs_base__transform__output__struct {
// JSON With Commas and Comments.
#define WUFFS_BASE__FOURCC__JWCC 0x4A574343
// Key-Value Pair.
#define WUFFS_BASE__FOURCC__KVP 0x4B565020
// Key-Value Pair (Key).
#define WUFFS_BASE__FOURCC__KVPK 0x4B56504B
// Key-Value Pair (Value).
#define WUFFS_BASE__FOURCC__KVPV 0x4B565056
// Lempel–Ziv 4.
#define WUFFS_BASE__FOURCC__LZ4 0x4C5A3420
// Markdown.
#define WUFFS_BASE__FOURCC__MD 0x4D442020
// Modification Time.
#define WUFFS_BASE__FOURCC__MTIM 0x4D54494D
// MPEG-1 Audio Layer III.
#define WUFFS_BASE__FOURCC__MP3 0x4D503320
// Naive Image.
#define WUFFS_BASE__FOURCC__NIE 0x4E494520
// Offset (2-Dimensional).
#define WUFFS_BASE__FOURCC__OFS2 0x4F465332
// Open Type Format.
#define WUFFS_BASE__FOURCC__OTF 0x4F544620
// Portable Document Format.
#define WUFFS_BASE__FOURCC__PDF 0x50444620
// Physical Dimensions.
#define WUFFS_BASE__FOURCC__PHYD 0x50485944
// Portable Network Graphics.
#define WUFFS_BASE__FOURCC__PNG 0x504E4720
@@ -644,6 +686,9 @@ typedef struct wuffs_base__transform__output__struct {
// PostScript.
#define WUFFS_BASE__FOURCC__PS 0x50532020
// Quite OK Image.
#define WUFFS_BASE__FOURCC__QOI 0x514F4920
// Random Access Compression.
#define WUFFS_BASE__FOURCC__RAC 0x52414320
@@ -659,12 +704,18 @@ typedef struct wuffs_base__transform__output__struct {
// Snappy.
#define WUFFS_BASE__FOURCC__SNPY 0x534E5059
// Standard Red Green Blue (Rendering Intent).
#define WUFFS_BASE__FOURCC__SRGB 0x53524742
// Scalable Vector Graphics.
#define WUFFS_BASE__FOURCC__SVG 0x53564720
// Tape Archive.
#define WUFFS_BASE__FOURCC__TAR 0x54415220
// Text.
#define WUFFS_BASE__FOURCC__TEXT 0x54455854
// Tagged Image File Format.
#define WUFFS_BASE__FOURCC__TIFF 0x54494646
@@ -677,15 +728,12 @@ typedef struct wuffs_base__transform__output__struct {
// Wireless Bitmap.
#define WUFFS_BASE__FOURCC__WBMP 0x57424D50
// Web Picture.
#define WUFFS_BASE__FOURCC__WEBP 0x57454250
// Web Open Font Format.
#define WUFFS_BASE__FOURCC__WOFF 0x574F4646
// Web Picture (VP8).
#define WUFFS_BASE__FOURCC__WP8 0x57503820
// Web Picture (VP8 Lossless).
#define WUFFS_BASE__FOURCC__WP8L 0x5750384C
// Extensible Markup Language.
#define WUFFS_BASE__FOURCC__XML 0x584D4C20
@@ -963,7 +1011,9 @@ wuffs_base__multiply_u64(uint64_t x, uint64_t y) {
// --------
#if defined(__GNUC__) && (__SIZEOF_LONG__ == 8)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if (defined(__GNUC__) || defined(__clang__)) && (__SIZEOF_LONG__ == 8)
static inline uint32_t //
wuffs_base__count_leading_zeroes_u64(uint64_t u) {
@@ -1007,7 +1057,7 @@ wuffs_base__count_leading_zeroes_u64(uint64_t u) {
return n;
}
#endif // defined(__GNUC__) && (__SIZEOF_LONG__ == 8)
#endif // (defined(__GNUC__) || defined(__clang__)) && (__SIZEOF_LONG__ == 8)
// --------
@@ -1571,6 +1621,25 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__table_u8__subtable_ij returns t[ix:jx, iy:jy].
//
// It returns an empty table if i or j is out of bounds.
static inline wuffs_base__table_u8 //
wuffs_base__table_u8__subtable_ij(wuffs_base__table_u8 t,
uint64_t ix,
uint64_t iy,
uint64_t jx,
uint64_t jy) {
if ((ix <= jx) && (jx <= SIZE_MAX) && (jx <= t.width) && //
(iy <= jy) && (jy <= SIZE_MAX) && (jy <= t.height)) {
return wuffs_base__make_table_u8(t.ptr + ix + (iy * t.stride), //
((size_t)(jx - ix)), //
((size_t)(jy - iy)), //
t.stride); //
}
return wuffs_base__make_table_u8(NULL, 0, 0, 0);
}
// wuffs_base__table__flattened_length returns the number of elements covered
// by the 1-dimensional span that backs a 2-dimensional table. This counts the
// elements inside the table and, when width != stride, the elements outside
@@ -2453,14 +2522,24 @@ typedef struct wuffs_base__more_information__struct {
inline wuffs_base__range_ie_u64 io_redirect__range() const;
inline uint64_t io_seek__position() const;
inline uint32_t metadata__fourcc() const;
// Deprecated: use metadata_raw_passthrough__range.
inline wuffs_base__range_ie_u64 metadata__range() const;
inline wuffs_base__range_ie_u64 metadata_raw_passthrough__range() const;
inline int32_t metadata_parsed__chrm(uint32_t component) const;
inline uint32_t metadata_parsed__gama() const;
inline uint32_t metadata_parsed__srgb() const;
#endif // __cplusplus
} wuffs_base__more_information;
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_REDIRECT 1
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_SEEK 2
// Deprecated: use
// WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH.
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA 3
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH 3
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM 4
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED 5
static inline wuffs_base__more_information //
wuffs_base__empty_more_information() {
@@ -2517,6 +2596,8 @@ wuffs_base__more_information__metadata__fourcc(
return m->w;
}
// Deprecated: use
// wuffs_base__more_information__metadata_raw_passthrough__range.
static inline wuffs_base__range_ie_u64 //
wuffs_base__more_information__metadata__range(
const wuffs_base__more_information* m) {
@@ -2526,6 +2607,103 @@ wuffs_base__more_information__metadata__range(
return ret;
}
static inline wuffs_base__range_ie_u64 //
wuffs_base__more_information__metadata_raw_passthrough__range(
const wuffs_base__more_information* m) {
wuffs_base__range_ie_u64 ret;
ret.min_incl = m->y;
ret.max_excl = m->z;
return ret;
}
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__WHITE_X 0
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__WHITE_Y 1
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__RED_X 2
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__RED_Y 3
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__GREEN_X 4
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__GREEN_Y 5
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__BLUE_X 6
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__BLUE_Y 7
// wuffs_base__more_information__metadata_parsed__chrm returns chromaticity
// values (scaled by 100000) like the PNG "cHRM" chunk. For example, the sRGB
// color space corresponds to:
// - ETC__CHRM__WHITE_X 31270
// - ETC__CHRM__WHITE_Y 32900
// - ETC__CHRM__RED_X 64000
// - ETC__CHRM__RED_Y 33000
// - ETC__CHRM__GREEN_X 30000
// - ETC__CHRM__GREEN_Y 60000
// - ETC__CHRM__BLUE_X 15000
// - ETC__CHRM__BLUE_Y 6000
//
// See
// https://ciechanow.ski/color-spaces/#chromaticity-and-white-point-coordinates
static inline int32_t //
wuffs_base__more_information__metadata_parsed__chrm(
const wuffs_base__more_information* m,
uint32_t component) {
// After the flavor and the w field (holding a FourCC), a
// wuffs_base__more_information holds 24 bytes of data in three uint64_t
// typed fields (x, y and z). We pack the eight chromaticity values (wx, wy,
// rx, ..., by), basically int24_t values, into 24 bytes like this:
// - LSB MSB
// - x: wx wx wx wy wy wy rx rx
// - y: rx ry ry ry gx gx gx gy
// - z: gy gy bx bx bx by by by
uint32_t u = 0;
switch (component & 7) {
case 0:
u = ((uint32_t)(m->x >> 0));
break;
case 1:
u = ((uint32_t)(m->x >> 24));
break;
case 2:
u = ((uint32_t)((m->x >> 48) | (m->y << 16)));
break;
case 3:
u = ((uint32_t)(m->y >> 8));
break;
case 4:
u = ((uint32_t)(m->y >> 32));
break;
case 5:
u = ((uint32_t)((m->y >> 56) | (m->z << 8)));
break;
case 6:
u = ((uint32_t)(m->z >> 16));
break;
case 7:
u = ((uint32_t)(m->z >> 40));
break;
}
// The left-right shifts sign-extend from 24-bit to 32-bit integers.
return ((int32_t)(u << 8)) >> 8;
}
// wuffs_base__more_information__metadata_parsed__gama returns inverse gamma
// correction values (scaled by 100000) like the PNG "gAMA" chunk. For example,
// for gamma = 2.2, this returns 45455 (approximating 100000 / 2.2).
static inline uint32_t //
wuffs_base__more_information__metadata_parsed__gama(
const wuffs_base__more_information* m) {
return ((uint32_t)(m->x));
}
#define WUFFS_BASE__SRGB_RENDERING_INTENT__PERCEPTUAL 0
#define WUFFS_BASE__SRGB_RENDERING_INTENT__RELATIVE_COLORIMETRIC 1
#define WUFFS_BASE__SRGB_RENDERING_INTENT__SATURATION 2
#define WUFFS_BASE__SRGB_RENDERING_INTENT__ABSOLUTE_COLORIMETRIC 3
// wuffs_base__more_information__metadata_parsed__srgb returns the sRGB
// rendering intent like the PNG "sRGB" chunk.
static inline uint32_t //
wuffs_base__more_information__metadata_parsed__srgb(
const wuffs_base__more_information* m) {
return m->x & 3;
}
#ifdef __cplusplus
inline void //
@@ -2563,6 +2741,26 @@ wuffs_base__more_information::metadata__range() const {
return wuffs_base__more_information__metadata__range(this);
}
inline wuffs_base__range_ie_u64 //
wuffs_base__more_information::metadata_raw_passthrough__range() const {
return wuffs_base__more_information__metadata_raw_passthrough__range(this);
}
inline int32_t //
wuffs_base__more_information::metadata_parsed__chrm(uint32_t component) const {
return wuffs_base__more_information__metadata_parsed__chrm(this, component);
}
inline uint32_t //
wuffs_base__more_information::metadata_parsed__gama() const {
return wuffs_base__more_information__metadata_parsed__gama(this);
}
inline uint32_t //
wuffs_base__more_information::metadata_parsed__srgb() const {
return wuffs_base__more_information__metadata_parsed__srgb(this);
}
#endif // __cplusplus
// ---------------- I/O
@@ -5069,9 +5267,9 @@ wuffs_base__pixel_swizzler::swizzle_interleaved_from_slice(
// wuffs_base__ieee_754_bit_representation__etc converts between a double
// precision numerical value and its IEEE 754 representations:
// - 16-bit: 1 sign bit, 5 exponent bits, 10 explicit significand bits.
// - 32-bit: 1 sign bit, 8 exponent bits, 23 explicit significand bits.
// - 64-bit: 1 sign bit, 11 exponent bits, 52 explicit significand bits.
// - 16-bit: 1 sign bit, 5 exponent bits, 10 explicit significand bits.
// - 32-bit: 1 sign bit, 8 exponent bits, 23 explicit significand bits.
// - 64-bit: 1 sign bit, 11 exponent bits, 52 explicit significand bits.
//
// For example, it converts between:
// - +1.0 and 0x3C00, 0x3F80_0000 or 0x3FF0_0000_0000_0000.
@@ -7163,7 +7361,6 @@ struct wuffs_deflate__decoder__struct {
uint32_t v_length;
uint32_t v_dist_minus_1;
uint32_t v_hlen;
uint32_t v_hdist;
uint64_t scratch;
} s_decode_huffman_slow[1];
} private_data;
@@ -7683,8 +7880,8 @@ struct wuffs_gif__decoder__struct {
bool f_previous_lzw_decode_ended_abruptly;
bool f_has_global_palette;
uint8_t f_interlace;
bool f_seen_num_loops;
uint32_t f_num_loops;
bool f_seen_num_animation_loops_value;
uint32_t f_num_animation_loops_value;
uint32_t f_background_color_u32_argb_premul;
uint32_t f_black_color_u32_argb_premul;
bool f_gc_has_transparent_index;
@@ -8733,6 +8930,8 @@ extern const char wuffs_zlib__error__incorrect_dictionary[];
// ---------------- Public Consts
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976
#define WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
// ---------------- Struct Declarations
@@ -8844,6 +9043,7 @@ struct wuffs_zlib__decoder__struct {
bool f_header_complete;
bool f_got_dictionary;
bool f_want_dictionary;
bool f_quirks[1];
bool f_ignore_checksum;
uint32_t f_dict_id_got;
uint32_t f_dict_id_want;
@@ -8962,17 +9162,22 @@ struct wuffs_zlib__decoder__struct {
// ---------------- Status Codes
extern const char wuffs_png__error__bad_animation_sequence_number[];
extern const char wuffs_png__error__bad_checksum[];
extern const char wuffs_png__error__bad_chunk[];
extern const char wuffs_png__error__bad_filter[];
extern const char wuffs_png__error__bad_header[];
extern const char wuffs_png__error__bad_text_chunk_not_latin_1[];
extern const char wuffs_png__error__missing_palette[];
extern const char wuffs_png__error__unsupported_png_compression_method[];
extern const char wuffs_png__error__unsupported_png_file[];
// ---------------- Public Consts
#define WUFFS_PNG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
#define WUFFS_PNG__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 8
// ---------------- Struct Declarations
typedef struct wuffs_png__decoder__struct wuffs_png__decoder;
@@ -9126,19 +9331,64 @@ struct wuffs_png__decoder__struct {
uint64_t f_overall_workbuf_length;
uint64_t f_pass_workbuf_length;
uint8_t f_call_sequence;
bool f_report_metadata_chrm;
bool f_report_metadata_exif;
bool f_report_metadata_gama;
bool f_report_metadata_iccp;
bool f_report_metadata_kvp;
bool f_report_metadata_srgb;
bool f_ignore_checksum;
uint8_t f_depth;
uint8_t f_color_type;
uint8_t f_filter_distance;
uint8_t f_interlace_pass;
bool f_seen_actl;
bool f_seen_chrm;
bool f_seen_fctl;
bool f_seen_exif;
bool f_seen_gama;
bool f_seen_iccp;
bool f_seen_idat;
bool f_seen_plte;
bool f_seen_srgb;
bool f_seen_trns;
uint32_t f_dst_pixfmt;
uint32_t f_src_pixfmt;
bool f_metadata_is_zlib_compressed;
bool f_zlib_is_dirty;
uint32_t f_chunk_type;
uint8_t f_chunk_type_array[4];
uint64_t f_chunk_length;
uint32_t f_chunk_length;
uint64_t f_remap_transparency;
uint32_t f_dst_pixfmt;
uint32_t f_src_pixfmt;
uint32_t f_num_animation_frames_value;
uint32_t f_num_animation_loops_value;
uint32_t f_num_decoded_frame_configs_value;
uint32_t f_num_decoded_frames_value;
uint32_t f_frame_rect_x0;
uint32_t f_frame_rect_y0;
uint32_t f_frame_rect_x1;
uint32_t f_frame_rect_y1;
uint32_t f_first_rect_x0;
uint32_t f_first_rect_y0;
uint32_t f_first_rect_x1;
uint32_t f_first_rect_y1;
uint64_t f_frame_config_io_position;
uint64_t f_first_config_io_position;
uint64_t f_frame_duration;
uint64_t f_first_duration;
uint8_t f_frame_disposal;
uint8_t f_first_disposal;
bool f_frame_overwrite_instead_of_blend;
bool f_first_overwrite_instead_of_blend;
uint32_t f_next_animation_seq_num;
uint32_t f_metadata_flavor;
uint32_t f_metadata_fourcc;
uint64_t f_metadata_x;
uint64_t f_metadata_y;
uint64_t f_metadata_z;
uint32_t f_ztxt_ri;
uint32_t f_ztxt_wi;
uint64_t f_ztxt_hist_pos;
wuffs_base__pixel_swizzler f_swizzler;
wuffs_base__empty_struct (*choosy_filter_1)(
@@ -9155,11 +9405,19 @@ struct wuffs_png__decoder__struct {
uint32_t p_decode_image_config[1];
uint32_t p_decode_ihdr[1];
uint32_t p_decode_other_chunk[1];
uint32_t p_decode_actl[1];
uint32_t p_decode_chrm[1];
uint32_t p_decode_fctl[1];
uint32_t p_decode_gama[1];
uint32_t p_decode_iccp[1];
uint32_t p_decode_plte[1];
uint32_t p_decode_srgb[1];
uint32_t p_decode_trns[1];
uint32_t p_decode_frame_config[1];
uint32_t p_skip_frame[1];
uint32_t p_decode_frame[1];
uint32_t p_decode_pass[1];
uint32_t p_tell_me_more[1];
wuffs_base__status (*choosy_filter_and_swizzle)(
wuffs_png__decoder* self,
wuffs_base__pixel_buffer* a_dst,
@@ -9182,19 +9440,47 @@ struct wuffs_png__decoder__struct {
struct {
uint64_t scratch;
} s_decode_other_chunk[1];
struct {
uint64_t scratch;
} s_decode_actl[1];
struct {
uint64_t scratch;
} s_decode_chrm[1];
struct {
uint32_t v_x0;
uint32_t v_x1;
uint32_t v_y1;
uint64_t scratch;
} s_decode_fctl[1];
struct {
uint64_t scratch;
} s_decode_gama[1];
struct {
uint32_t v_num_entries;
uint32_t v_i;
uint64_t scratch;
} s_decode_plte[1];
struct {
uint32_t v_num_entries;
uint32_t v_i;
uint32_t v_n;
uint64_t scratch;
} s_decode_trns[1];
struct {
uint32_t v_checksum_have;
uint64_t scratch;
} s_decode_frame_config[1];
struct {
uint64_t scratch;
} s_skip_frame[1];
struct {
uint64_t scratch;
} s_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];
} private_data;
#ifdef __cplusplus
@@ -9691,6 +9977,63 @@ namespace sync_io {
// --------
// DynIOBuffer is an IOBuffer that is backed by a dynamically sized byte array.
// It owns that backing array and will free it in its destructor.
//
// The array size can be explicitly extended (by calling the grow method) but,
// unlike a C++ std::vector, there is no implicit extension (e.g. by calling
// std::vector::insert) and its maximum size is capped by the max_incl
// constructor argument.
//
// It contains an IOBuffer-typed field whose reader side provides access to
// previously written bytes and whose writer side provides access to the
// allocated but not-yet-written-to slack space. For Go programmers, this slack
// space is roughly analogous to the s[len(s):cap(s)] space of a slice s.
class DynIOBuffer {
public:
enum GrowResult {
OK = 0,
FailedMaxInclExceeded = 1,
FailedOutOfMemory = 2,
};
// m_buf holds the dynamically sized byte array and its read/write indexes:
// - m_buf.meta.wi is roughly analogous to a Go slice's length.
// - m_buf.data.len is roughly analogous to a Go slice's capacity. It is
// also equal to the m_buf.data.ptr malloc/realloc size.
//
// Users should not modify the m_buf.data.ptr or m_buf.data.len fields (as
// they are conceptually private to this class), but they can modify the
// bytes referenced by that pointer-length pair (e.g. compactions).
IOBuffer m_buf;
// m_max_incl is an inclusive upper bound on the backing array size.
const uint64_t m_max_incl;
// Constructor and destructor.
explicit DynIOBuffer(uint64_t max_incl);
~DynIOBuffer();
// Drop frees the byte array and resets m_buf. The DynIOBuffer can still be
// used after a drop call. It just restarts from zero.
void drop();
// grow ensures that the byte array size is at least min_incl and at most
// max_incl. It returns FailedMaxInclExceeded if that would require
// allocating more than max_incl bytes, including the case where (min_incl >
// max_incl). It returns FailedOutOfMemory if memory allocation failed.
GrowResult grow(uint64_t min_incl);
private:
// Delete the copy and assign constructors.
DynIOBuffer(const DynIOBuffer&) = delete;
DynIOBuffer& operator=(const DynIOBuffer&) = delete;
static uint64_t round_up(uint64_t min_incl, uint64_t max_incl);
};
// --------
class Input {
public:
virtual ~Input();
@@ -9801,6 +10144,26 @@ class DecodeCborCallbacks {
Done(DecodeCborResult& result, sync_io::Input& input, IOBuffer& buffer);
};
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeCborArgQuirks wraps an optional argument to DecodeCbor.
struct DecodeCborArgQuirks {
explicit DecodeCborArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeCborArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeCborArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeCbor calls callbacks based on the CBOR-formatted data in input.
//
// On success, the returned error_message is empty and cursor_position counts
@@ -9810,7 +10173,7 @@ class DecodeCborCallbacks {
DecodeCborResult //
DecodeCbor(DecodeCborCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32());
DecodeCborArgQuirks quirks = DecodeCborArgQuirks::DefaultValue());
} // namespace wuffs_aux
@@ -9832,10 +10195,11 @@ struct DecodeImageResult {
// DecodeImageCallbacks are the callbacks given to DecodeImage. They are always
// called in this order:
// 1. SelectDecoder
// 2. SelectPixfmt
// 3. AllocPixbuf
// 4. AllocWorkbuf
// 5. Done
// 2. HandleMetadata
// 3. SelectPixfmt
// 4. AllocPixbuf
// 5. AllocWorkbuf
// 6. Done
//
// It may return early - the third callback might not be invoked if the second
// one fails - but the final callback (Done) is always invoked.
@@ -9892,6 +10256,22 @@ class DecodeImageCallbacks {
virtual wuffs_base__image_decoder::unique_ptr //
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED
// If it is ETC__METADATA_RAW_ETC then raw contains the metadata bytes. Those
// bytes should not be retained beyond the the HandleMetadata call.
//
// minfo.metadata__fourcc() will typically match one of the
// DecodeImageArgFlags bits. For example, if (REPORT_METADATA_CHRM |
// REPORT_METADATA_GAMA) was passed to DecodeImage then the metadata FourCC
// will be either WUFFS_BASE__FOURCC__CHRM or WUFFS_BASE__FOURCC__GAMA.
//
// It returns an error message, or an empty string on success.
virtual std::string //
HandleMetadata(const wuffs_base__more_information& minfo,
wuffs_base__slice_u8 raw);
// SelectPixfmt returns the destination pixel format for AllocPixbuf. It
// should return wuffs_base__make_pixel_format(etc) called with one of:
// - WUFFS_BASE__PIXEL_FORMAT__BGR_565
@@ -9958,13 +10338,116 @@ class DecodeImageCallbacks {
extern const char DecodeImage_BufferIsTooShort[];
extern const char DecodeImage_MaxInclDimensionExceeded[];
extern const char DecodeImage_MaxInclMetadataLengthExceeded[];
extern const char DecodeImage_OutOfMemory[];
extern const char DecodeImage_UnexpectedEndOfFile[];
extern const char DecodeImage_UnsupportedImageFormat[];
extern const char DecodeImage_UnsupportedMetadata[];
extern const char DecodeImage_UnsupportedPixelBlend[];
extern const char DecodeImage_UnsupportedPixelConfiguration[];
extern const char DecodeImage_UnsupportedPixelFormat[];
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeImageArgQuirks wraps an optional argument to DecodeImage.
struct DecodeImageArgQuirks {
explicit DecodeImageArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeImageArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeImageArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeImageArgFlags wraps an optional argument to DecodeImage.
struct DecodeImageArgFlags {
explicit DecodeImageArgFlags(uint64_t repr0);
// DefaultValue returns 0.
static DecodeImageArgFlags DefaultValue();
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
// GAMA, ICCP, KVP, SRGB and XMP.
// Background Color.
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
// Primary Chromaticities and White Point.
static constexpr uint64_t REPORT_METADATA_CHRM = 0x0002;
// Exchangeable Image File Format.
static constexpr uint64_t REPORT_METADATA_EXIF = 0x0004;
// Gamma Correction.
static constexpr uint64_t REPORT_METADATA_GAMA = 0x0008;
// International Color Consortium Profile.
static constexpr uint64_t REPORT_METADATA_ICCP = 0x0010;
// Key-Value Pair.
//
// For PNG files, this includes iTXt, tEXt and zTXt chunks. In the
// HandleMetadata callback, the raw argument contains UTF-8 strings.
static constexpr uint64_t REPORT_METADATA_KVP = 0x0020;
// Modification Time.
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0040;
// Offset (2-Dimensional).
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0080;
// Physical Dimensions.
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0100;
// Standard Red Green Blue (Rendering Intent).
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0200;
// Extensible Metadata Platform.
static constexpr uint64_t REPORT_METADATA_XMP = 0x0400;
uint64_t repr;
};
// DecodeImageArgPixelBlend wraps an optional argument to DecodeImage.
struct DecodeImageArgPixelBlend {
explicit DecodeImageArgPixelBlend(wuffs_base__pixel_blend repr0);
// DefaultValue returns WUFFS_BASE__PIXEL_BLEND__SRC.
static DecodeImageArgPixelBlend DefaultValue();
wuffs_base__pixel_blend repr;
};
// DecodeImageArgBackgroundColor wraps an optional argument to DecodeImage.
struct DecodeImageArgBackgroundColor {
explicit DecodeImageArgBackgroundColor(
wuffs_base__color_u32_argb_premul repr0);
// DefaultValue returns 1, an invalid wuffs_base__color_u32_argb_premul.
static DecodeImageArgBackgroundColor DefaultValue();
wuffs_base__color_u32_argb_premul repr;
};
// DecodeImageArgMaxInclDimension wraps an optional argument to DecodeImage.
struct DecodeImageArgMaxInclDimension {
explicit DecodeImageArgMaxInclDimension(uint32_t repr0);
// DefaultValue returns 1048575 = 0x000F_FFFF, more than 1 million pixels.
static DecodeImageArgMaxInclDimension DefaultValue();
uint32_t repr;
};
// DecodeImageArgMaxInclMetadataLength wraps an optional argument to
// DecodeImage.
struct DecodeImageArgMaxInclMetadataLength {
explicit DecodeImageArgMaxInclMetadataLength(uint64_t repr0);
// DefaultValue returns 16777215 = 0x00FF_FFFF, one less than 16 MiB.
static DecodeImageArgMaxInclMetadataLength DefaultValue();
uint64_t repr;
};
// DecodeImage decodes the image data in input. A variety of image file formats
// can be decoded, depending on what callbacks.SelectDecoder returns.
//
@@ -10007,13 +10490,21 @@ extern const char DecodeImage_UnsupportedPixelFormat[];
// WUFFS_BASE__PIXEL_BLEND__SRC_OVER and the decoded image is not fully opaque.
//
// Decoding fails (with DecodeImage_MaxInclDimensionExceeded) if the image's
// width or height is greater than max_incl_dimension.
// width or height is greater than max_incl_dimension or if any opted-in (via
// flags bits) metadata is longer than max_incl_metadata_length.
DecodeImageResult //
DecodeImage(DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__pixel_blend pixel_blend = WUFFS_BASE__PIXEL_BLEND__SRC,
wuffs_base__color_u32_argb_premul background_color = 1, // Invalid.
uint32_t max_incl_dimension = 1048575); // 0x000F_FFFF
DecodeImageArgQuirks quirks = DecodeImageArgQuirks::DefaultValue(),
DecodeImageArgFlags flags = DecodeImageArgFlags::DefaultValue(),
DecodeImageArgPixelBlend pixel_blend =
DecodeImageArgPixelBlend::DefaultValue(),
DecodeImageArgBackgroundColor background_color =
DecodeImageArgBackgroundColor::DefaultValue(),
DecodeImageArgMaxInclDimension max_incl_dimension =
DecodeImageArgMaxInclDimension::DefaultValue(),
DecodeImageArgMaxInclMetadataLength max_incl_metadata_length =
DecodeImageArgMaxInclMetadataLength::DefaultValue());
} // namespace wuffs_aux
@@ -10074,6 +10565,36 @@ class DecodeJsonCallbacks {
extern const char DecodeJson_BadJsonPointer[];
extern const char DecodeJson_NoMatch[];
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeJsonArgQuirks wraps an optional argument to DecodeJson.
struct DecodeJsonArgQuirks {
explicit DecodeJsonArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeJsonArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeJsonArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeJsonArgJsonPointer wraps an optional argument to DecodeJson.
struct DecodeJsonArgJsonPointer {
explicit DecodeJsonArgJsonPointer(std::string repr0);
// DefaultValue returns an empty string.
static DecodeJsonArgJsonPointer DefaultValue();
std::string repr;
};
// DecodeJson calls callbacks based on the JSON-formatted data in input.
//
// On success, the returned error_message is empty and cursor_position counts
@@ -10091,8 +10612,9 @@ extern const char DecodeJson_NoMatch[];
DecodeJsonResult //
DecodeJson(DecodeJsonCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32(),
std::string json_pointer = std::string());
DecodeJsonArgQuirks quirks = DecodeJsonArgQuirks::DefaultValue(),
DecodeJsonArgJsonPointer json_pointer =
DecodeJsonArgJsonPointer::DefaultValue());
} // namespace wuffs_aux
@@ -10142,8 +10664,9 @@ extern "C" {
goto suspend; \
case n:;
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__) || defined(__clang__)
#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
#else
@@ -10301,7 +10824,7 @@ wuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,
// --------
static inline wuffs_base__slice_u8 //
wuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) {
wuffs_base__table_u8__row_u32(wuffs_base__table_u8 t, uint32_t y) {
if (y < t.height) {
return wuffs_base__make_slice_u8(t.ptr + (t.stride * y), t.width);
}
@@ -10517,7 +11040,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -10525,7 +11048,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
return 0;
}
uint8_t* p = *ptr_iop_w;
if ((size_t)(p - io1_w) < (size_t)(distance)) {
if ((size_t)(p - io0_w) < (size_t)(distance)) {
return 0;
}
uint8_t* q = p - distance;
@@ -10562,10 +11085,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
// The caller needs to prove that:
// - length <= (io2_w - *ptr_iop_w)
// - distance >= 1
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -10597,11 +11120,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
// The caller needs to prove that:
// - (length + 8) <= (io2_w - *ptr_iop_w)
// - distance == 1
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -10637,11 +11160,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
// The caller needs to prove that:
// - (length + 8) <= (io2_w - *ptr_iop_w)
// - distance >= 8
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -12369,14 +12892,14 @@ wuffs_base__ieee_754_bit_representation__from_f64_to_u32_truncate(double f) {
// padded with implicit zeroes.
//
// For example, if num_digits is 3 and digits is "\x07\x08\x09":
// - A decimal_point of -2 means ".00789"
// - A decimal_point of -1 means ".0789"
// - A decimal_point of +0 means ".789"
// - A decimal_point of +1 means "7.89"
// - A decimal_point of +2 means "78.9"
// - A decimal_point of +3 means "789."
// - A decimal_point of +4 means "7890."
// - A decimal_point of +5 means "78900."
// - A decimal_point of -2 means ".00789"
// - A decimal_point of -1 means ".0789"
// - A decimal_point of +0 means ".789"
// - A decimal_point of +1 means "7.89"
// - A decimal_point of +2 means "78.9"
// - A decimal_point of +3 means "789."
// - A decimal_point of +4 means "7890."
// - A decimal_point of +5 means "78900."
//
// As above, a decimal_point higher than +2047 means that the overall value is
// infinity, lower than -2047 means zero.
@@ -12721,10 +13244,10 @@ wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits(
// wuffs_base__private_implementation__high_prec_dec__rounded_integer returns
// the integral (non-fractional) part of h, provided that it is 18 or fewer
// decimal digits. For 19 or more digits, it returns UINT64_MAX. Note that:
// - (1 << 53) is 9007199254740992, which has 16 decimal digits.
// - (1 << 56) is 72057594037927936, which has 17 decimal digits.
// - (1 << 59) is 576460752303423488, which has 18 decimal digits.
// - (1 << 63) is 9223372036854775808, which has 19 decimal digits.
// - (1 << 53) is 9007199254740992, which has 16 decimal digits.
// - (1 << 56) is 72057594037927936, which has 17 decimal digits.
// - (1 << 59) is 576460752303423488, which has 18 decimal digits.
// - (1 << 63) is 9223372036854775808, which has 19 decimal digits.
// and that IEEE 754 double precision has 52 mantissa bits.
//
// That integral part is rounded-to-even: rounding 7.5 or 8.5 both give 8.
@@ -15057,19 +15580,23 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
//
// Keep it sorted by magic[1], then magic[0] descending and finally by
// magic[2:]. When multiple entries match, the longest one wins.
//
// The fourcc field might be negated, in which case there's further
// specialization (see § below).
static struct {
int32_t fourcc;
const char* magic;
} table[] = {
{0x57424D50, "\x01\x00\x00"}, // WBMP
{0x424D5020, "\x01\x42\x4D"}, // BMP
{0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF (see § below)
{0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{0x4A504547, "\x01\xFF\xD8"}, // JPEG
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
};
static const size_t table_len = sizeof(table) / sizeof(table[0]);
@@ -15110,19 +15637,33 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
return 0;
match:
// Some FourCC values (see § above) are further specialized.
if (fourcc == 0x52494646) { // 'RIFF'be
if (prefix.len < 16) {
return -1;
}
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
if (x == 0x57454250) { // 'WEBP'be
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
if (y == 0x56503820) { // 'VP8 'be
return 0x57503820; // 'WP8 'be
} else if (y == 0x5650384C) { // 'VP8L'be
return 0x5750384C; // 'WP8L'be
// Negative FourCC values (see § above) are further specialized.
if (fourcc < 0) {
fourcc = -fourcc;
if (fourcc == 0x52494646) { // 'RIFF'be
if (prefix.len < 12) {
return -1;
}
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
if (x == 0x57454250) { // 'WEBP'be
return 0x57454250; // 'WEBP'be
}
} else if (fourcc == 0x30302020) { // '00 'be
// Binary data starting with multiple 0x00 NUL bytes is quite common.
if (prefix.len < 4) {
return -1;
} else if ((prefix.ptr[2] != 0x00) &&
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
// Roughly speaking, this could be a non-degenerate (non-0-width and
// non-0-height) WBMP image.
return 0x57424D50; // 'WBMP'be
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
(prefix.ptr[3] == 0x00)) {
return 0x49434F20; // 'ICO 'be
}
return 0;
}
}
return fourcc;
@@ -15624,14 +16165,23 @@ static inline uint32_t //
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
uint32_t src_nonpremul) {
// Extract 16-bit color components.
//
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
// return src_nonpremul. This isn't just an optimization (skipping the rest
// of the function's computation). It also preserves the nonpremul
// distinction between e.g. transparent red and transparent blue that would
// otherwise be lost by converting from nonpremul to premul and back.
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
if (da == 0) {
return src_nonpremul;
}
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -15668,14 +16218,23 @@ static inline uint64_t //
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
uint64_t src_nonpremul) {
// Extract components.
//
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
// return src_nonpremul. This isn't just an optimization (skipping the rest
// of the function's computation). It also preserves the nonpremul
// distinction between e.g. transparent red and transparent blue that would
// otherwise be lost by converting from nonpremul to premul and back.
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
if (da == 0) {
return src_nonpremul;
}
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -15706,14 +16265,14 @@ static inline uint32_t //
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
uint32_t src_premul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -15750,14 +16309,14 @@ static inline uint64_t //
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
uint64_t src_premul) {
// Extract components.
uint64_t sa = 0xFFFF & (src_premul >> 48);
uint64_t sr = 0xFFFF & (src_premul >> 32);
uint64_t sg = 0xFFFF & (src_premul >> 16);
uint64_t sb = 0xFFFF & (src_premul >> 0);
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
uint64_t sa = 0xFFFF & (src_premul >> 48);
uint64_t sr = 0xFFFF & (src_premul >> 32);
uint64_t sg = 0xFFFF & (src_premul >> 16);
uint64_t sb = 0xFFFF & (src_premul >> 0);
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -15788,14 +16347,14 @@ static inline uint32_t //
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
uint32_t src_nonpremul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -15820,14 +16379,14 @@ static inline uint64_t //
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
uint64_t src_nonpremul) {
// Extract components.
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
uint64_t da = 0xFFFF & (dst_premul >> 48);
uint64_t dr = 0xFFFF & (dst_premul >> 32);
uint64_t dg = 0xFFFF & (dst_premul >> 16);
uint64_t db = 0xFFFF & (dst_premul >> 0);
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint64_t ia = 0xFFFF - sa;
@@ -15846,14 +16405,14 @@ static inline uint32_t //
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
uint32_t src_premul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -16913,13 +17472,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sr = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sb = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -16961,13 +17520,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -17036,13 +17595,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sr = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sb = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -17114,13 +17673,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sb = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sr = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -17189,13 +17748,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sb = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sr = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -22537,7 +23096,7 @@ wuffs_bmp__decoder__swizzle_none(
goto label__outer__continue;
}
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
@@ -22622,7 +23181,7 @@ wuffs_bmp__decoder__swizzle_rle(
v_rle_state = self->private_impl.f_rle_state;
label__outer__continue:;
while (true) {
v_row = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_row = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_row.len))) {
v_row = wuffs_base__slice_u8__subslice_j(v_row, v_dst_bytes_per_row);
}
@@ -22782,7 +23341,7 @@ wuffs_bmp__decoder__swizzle_rle(
status = wuffs_base__make_status(wuffs_bmp__error__bad_rle_compression);
goto exit;
}
v_row = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_row = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_row.len))) {
v_row = wuffs_base__slice_u8__subslice_j(v_row, v_dst_bytes_per_row);
}
@@ -22814,7 +23373,7 @@ wuffs_bmp__decoder__swizzle_rle(
}
label__outer__break:;
while (self->private_impl.f_dst_y < self->private_impl.f_height) {
v_row = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_row = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_row.len))) {
v_row = wuffs_base__slice_u8__subslice_j(v_row, v_dst_bytes_per_row);
}
@@ -22944,7 +23503,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
v_p0 += 1;
}
label__0__break:;
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
@@ -23026,7 +23585,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
goto label__loop__break;
}
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
@@ -26449,14 +27008,17 @@ wuffs_deflate__decoder__init_huff(
v_i += 1;
}
if (v_remaining != 0) {
if ((a_which == 1) &&
(v_counts[1] == 1) &&
(self->private_data.f_code_lengths[a_n_codes0] == 1) &&
((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
self->private_impl.f_n_huffs_bits[1] = 1;
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[0] | 1);
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
return wuffs_base__make_status(NULL);
if ((a_which == 1) && (v_counts[1] == 1) && ((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
v_i = 0;
while (v_i <= 29) {
if (self->private_data.f_code_lengths[(a_n_codes0 + v_i)] == 1) {
self->private_impl.f_n_huffs_bits[1] = 1;
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[v_i] | 1);
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
return wuffs_base__make_status(NULL);
}
v_i += 1;
}
}
return wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code_under_subscribed);
}
@@ -26794,9 +27356,8 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
goto exit;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
if (v_length == 0) {
goto label__loop__continue;
}
@@ -27060,9 +27621,8 @@ wuffs_deflate__decoder__decode_huffman_fast32(
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
goto exit;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
if (v_length == 0) {
goto label__loop__continue;
}
@@ -27273,9 +27833,8 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
goto exit;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
if (v_length == 0) {
goto label__loop__continue;
}
@@ -27396,7 +27955,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
v_length = self->private_data.s_decode_huffman_slow[0].v_length;
v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
v_hdist = self->private_data.s_decode_huffman_slow[0].v_hdist;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -27593,55 +28151,29 @@ wuffs_deflate__decoder__decode_huffman_slow(
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
}
label__inner__continue:;
while (true) {
if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) {
v_hdist = ((uint32_t)((((uint64_t)((v_dist_minus_1 + 1))) - ((uint64_t)(iop_a_dst - io0_a_dst)))));
if (v_length > v_hdist) {
v_length -= v_hdist;
if (v_hdist < v_length) {
v_hlen = v_hdist;
} else {
v_hlen = v_length;
v_length = 0;
}
v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295)));
if (self->private_impl.f_history_index < v_hdist) {
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
goto exit;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
while (true) {
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
goto label__4__break;
}
if (v_n_copied > 0) {
v_hlen -= v_n_copied;
v_hdist = (((uint32_t)(v_hdist + v_n_copied)) & 32767);
if (v_hdist == 0) {
goto label__4__break;
}
}
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
if (v_n_copied < v_hlen) {
v_length -= v_n_copied;
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
goto label__inner__continue;
}
label__4__break:;
if (v_hlen > 0) {
while (true) {
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
goto label__5__break;
}
v_hlen -= v_n_copied;
v_hdist += v_n_copied;
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
}
label__5__break:;
}
v_length -= v_hlen;
if (v_length == 0) {
goto label__loop__continue;
}
@@ -27649,14 +28181,12 @@ wuffs_deflate__decoder__decode_huffman_slow(
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_history(
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
if (v_length <= v_n_copied) {
v_length = 0;
goto label__6__break;
goto label__loop__continue;
}
v_length -= v_n_copied;
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
}
label__6__break:;
}
label__loop__break:;
self->private_impl.f_bits = v_bits;
@@ -27685,7 +28215,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
self->private_data.s_decode_huffman_slow[0].v_length = v_length;
self->private_data.s_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
self->private_data.s_decode_huffman_slow[0].v_hlen = v_hlen;
self->private_data.s_decode_huffman_slow[0].v_hdist = v_hdist;
goto exit;
exit:
@@ -28770,10 +29299,13 @@ wuffs_gif__decoder__num_animation_loops(
return 0;
}
if (self->private_impl.f_seen_num_loops) {
return self->private_impl.f_num_loops;
if (self->private_impl.f_seen_num_animation_loops_value) {
return self->private_impl.f_num_animation_loops_value;
}
return 1;
if (self->private_impl.f_num_decoded_frame_configs_value > 1) {
return 1;
}
return 0;
}
// -------- func gif.decoder.num_decoded_frame_configs
@@ -29918,11 +30450,11 @@ wuffs_gif__decoder__decode_ae(
*scratch |= ((uint64_t)(num_bits_4)) << 56;
}
}
self->private_impl.f_num_loops = t_4;
self->private_impl.f_num_animation_loops_value = t_4;
}
self->private_impl.f_seen_num_loops = true;
if ((0 < self->private_impl.f_num_loops) && (self->private_impl.f_num_loops <= 65535)) {
self->private_impl.f_num_loops += 1;
self->private_impl.f_seen_num_animation_loops_value = true;
if ((0 < self->private_impl.f_num_animation_loops_value) && (self->private_impl.f_num_animation_loops_value <= 65535)) {
self->private_impl.f_num_animation_loops_value += 1;
}
} else if (self->private_impl.f_ignore_metadata) {
} else if (v_is_iccp && self->private_impl.f_report_metadata_iccp) {
@@ -30404,7 +30936,8 @@ wuffs_gif__decoder__decode_id_part1(
goto ok;
}
if (self->private_impl.f_previous_lzw_decode_ended_abruptly) {
wuffs_base__ignore_status(wuffs_lzw__decoder__initialize(&self->private_data.f_lzw, sizeof (wuffs_lzw__decoder), WUFFS_VERSION, 0));
wuffs_base__ignore_status(wuffs_lzw__decoder__initialize(&self->private_data.f_lzw,
sizeof (wuffs_lzw__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
@@ -30610,6 +31143,30 @@ wuffs_gif__decoder__decode_id_part2(
goto label__outer__continue;
} else if (v_lzw_status.repr == wuffs_base__suspension__short_write) {
goto label__inner__continue;
} else if (self->private_impl.f_quirks[3] && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) && (self->private_impl.f_interlace == 0)) {
if (v_need_block_size || (v_block_size > 0)) {
self->private_data.s_decode_id_part2[0].scratch = ((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (self->private_data.s_decode_id_part2[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_id_part2[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_id_part2[0].scratch;
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
}
goto label__outer__break;
}
status = v_lzw_status;
if (wuffs_base__status__is_error(&status)) {
@@ -30690,7 +31247,7 @@ wuffs_gif__decoder__copy_to_image_buffer(
}
return wuffs_base__make_status(wuffs_base__error__too_much_data);
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (self->private_impl.f_dst_y >= self->private_impl.f_height) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, 0);
} else if (v_width_in_bytes < ((uint64_t)(v_dst.len))) {
@@ -30716,12 +31273,12 @@ wuffs_gif__decoder__copy_to_image_buffer(
goto label__0__continue;
}
if ((self->private_impl.f_num_decoded_frames_value == 0) && ! self->private_impl.f_gc_has_transparent_index && (self->private_impl.f_interlace > 1)) {
v_replicate_src = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_replicate_src = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
v_replicate_y0 = wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1);
v_replicate_y1 = wuffs_base__u32__sat_add(self->private_impl.f_dst_y, ((uint32_t)(WUFFS_GIF__INTERLACE_COUNT[self->private_impl.f_interlace])));
v_replicate_y1 = wuffs_base__u32__min(v_replicate_y1, self->private_impl.f_frame_rect_y1);
while (v_replicate_y0 < v_replicate_y1) {
v_replicate_dst = wuffs_base__table_u8__row(v_tab, v_replicate_y0);
v_replicate_dst = wuffs_base__table_u8__row_u32(v_tab, v_replicate_y0);
wuffs_base__slice_u8__copy_from_slice(v_replicate_dst, v_replicate_src);
v_replicate_y0 += 1;
}
@@ -34129,7 +34686,7 @@ wuffs_nie__decoder__swizzle(
goto label__0__break;
}
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
@@ -34347,6 +34904,10 @@ const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect diction
// ---------------- Private Consts
#define WUFFS_ZLIB__QUIRKS_BASE 2113790976
#define WUFFS_ZLIB__QUIRKS_COUNT 1
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
@@ -34510,8 +35071,15 @@ wuffs_zlib__decoder__set_quirk_enabled(
return wuffs_base__make_empty_struct();
}
if (a_quirk == 1) {
if (self->private_impl.f_header_complete) {
self->private_impl.f_bad_call_sequence = true;
} else if (a_quirk == 1) {
self->private_impl.f_ignore_checksum = a_enabled;
} else if (a_quirk >= 2113790976) {
a_quirk -= 2113790976;
if (a_quirk < 1) {
self->private_impl.f_quirks[a_quirk] = a_enabled;
}
}
return wuffs_base__make_empty_struct();
}
@@ -34601,6 +35169,7 @@ wuffs_zlib__decoder__transform_io(
if (self->private_impl.f_bad_call_sequence) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
} else if (self->private_impl.f_quirks[0]) {
} else if ( ! self->private_impl.f_want_dictionary) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
@@ -34708,7 +35277,7 @@ wuffs_zlib__decoder__transform_io(
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum) {
if ( ! self->private_impl.f_ignore_checksum && ! self->private_impl.f_quirks[0]) {
v_checksum_got = wuffs_adler32__hasher__update_u32(&self->private_data.f_checksum, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst));
}
if (wuffs_base__status__is_ok(&v_status)) {
@@ -34718,38 +35287,40 @@ wuffs_zlib__decoder__transform_io(
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
}
label__0__break:;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
if ( ! self->private_impl.f_quirks[0]) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
v_checksum_want = t_3;
}
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
goto exit;
}
v_checksum_want = t_3;
}
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
goto exit;
}
ok:
@@ -34784,17 +35355,25 @@ wuffs_zlib__decoder__transform_io(
// ---------------- Status Codes Implementations
const char wuffs_png__error__bad_animation_sequence_number[] = "#png: bad animation sequence number";
const char wuffs_png__error__bad_checksum[] = "#png: bad checksum";
const char wuffs_png__error__bad_chunk[] = "#png: bad chunk";
const char wuffs_png__error__bad_filter[] = "#png: bad filter";
const char wuffs_png__error__bad_header[] = "#png: bad header";
const char wuffs_png__error__bad_text_chunk_not_latin_1[] = "#png: bad text chunk (not Latin-1)";
const char wuffs_png__error__missing_palette[] = "#png: missing palette";
const char wuffs_png__error__unsupported_png_compression_method[] = "#png: unsupported PNG compression method";
const char wuffs_png__error__unsupported_png_file[] = "#png: unsupported PNG file";
const char wuffs_png__error__internal_error_inconsistent_i_o[] = "#png: internal error: inconsistent I/O";
const char wuffs_png__error__internal_error_inconsistent_chunk_type[] = "#png: internal error: inconsistent chunk type";
const char wuffs_png__error__internal_error_inconsistent_frame_bounds[] = "#png: internal error: inconsistent frame bounds";
const char wuffs_png__error__internal_error_inconsistent_workbuf_length[] = "#png: internal error: inconsistent workbuf length";
const char wuffs_png__error__internal_error_zlib_decoder_did_not_exhaust_its_input[] = "#png: internal error: zlib decoder did not exhaust its input";
// ---------------- Private Consts
#define WUFFS_PNG__ANCILLARY_BIT 32
static const uint8_t
WUFFS_PNG__INTERLACING[8][6] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
@@ -34831,6 +35410,42 @@ WUFFS_PNG__NUM_CHANNELS[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
1, 0, 3, 1, 2, 0, 4, 0,
};
static const uint16_t
WUFFS_PNG__LATIN_1[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 41410, 41666, 41922, 42178, 42434, 42690, 42946,
43202, 43458, 43714, 43970, 44226, 44482, 44738, 44994,
45250, 45506, 45762, 46018, 46274, 46530, 46786, 47042,
47298, 47554, 47810, 48066, 48322, 48578, 48834, 49090,
32963, 33219, 33475, 33731, 33987, 34243, 34499, 34755,
35011, 35267, 35523, 35779, 36035, 36291, 36547, 36803,
37059, 37315, 37571, 37827, 38083, 38339, 38595, 38851,
39107, 39363, 39619, 39875, 40131, 40387, 40643, 40899,
41155, 41411, 41667, 41923, 42179, 42435, 42691, 42947,
43203, 43459, 43715, 43971, 44227, 44483, 44739, 44995,
45251, 45507, 45763, 46019, 46275, 46531, 46787, 47043,
47299, 47555, 47811, 48067, 48323, 48579, 48835, 49091,
};
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
@@ -34994,16 +35609,56 @@ wuffs_png__decoder__decode_other_chunk(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_actl(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_chrm(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_exif(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_fctl(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_gama(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_iccp(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_plte(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_srgb(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_trns(
wuffs_png__decoder* self,
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__decode_pass(
wuffs_png__decoder* self,
@@ -36628,172 +37283,210 @@ wuffs_png__decoder__decode_image_config(
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0) {
if (self->private_impl.f_call_sequence == 2) {
if (self->private_impl.f_metadata_fourcc != 0) {
self->private_impl.f_call_sequence = 1;
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
} else if (self->private_impl.f_call_sequence != 0) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
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;
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;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
if (num_bits_0 == 56) {
t_0 = ((uint64_t)(*scratch));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_magic = t_0;
}
if (v_magic != 727905341920923785) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
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;
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;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
if (num_bits_1 == 56) {
t_1 = ((uint64_t)(*scratch));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
v_magic = t_1;
}
if (v_magic != 5927942488114331648) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, 0));
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 72;
self->private_impl.f_chunk_type_array[2] = 68;
self->private_impl.f_chunk_type_array[3] = 82;
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
while (true) {
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
} else {
{
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_2 = wuffs_png__decoder__decode_ihdr(self, a_src);
v_status = t_2;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
if (wuffs_base__status__is_ok(&v_status)) {
goto label__0__break;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
}
label__0__break:;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_checksum_want = t_3;
}
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
goto exit;
}
while (true) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
uint64_t t_4;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_4 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
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;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
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;
uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4);
if (num_bits_4 == 24) {
t_4 = ((uint64_t)(*scratch >> 32));
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
if (num_bits_0 == 56) {
t_0 = ((uint64_t)(*scratch));
break;
}
num_bits_4 += 8;
*scratch |= ((uint64_t)(num_bits_4));
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
self->private_impl.f_chunk_length = t_4;
v_magic = t_0;
}
if (v_magic != 727905341920923785) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
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;
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;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
if (num_bits_1 == 56) {
t_1 = ((uint64_t)(*scratch));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
v_magic = t_1;
}
if (v_magic != 5927942488114331648) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 72;
self->private_impl.f_chunk_type_array[2] = 68;
self->private_impl.f_chunk_type_array[3] = 82;
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32,
sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
while (true) {
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_2 = wuffs_png__decoder__decode_ihdr(self, a_src);
v_status = t_2;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
if (wuffs_base__status__is_ok(&v_status)) {
goto label__0__break;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
}
label__0__break:;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_checksum_want = t_3;
}
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
goto exit;
}
}
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;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
}
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)));
if (self->private_impl.f_chunk_type == 1413563465) {
if ( ! self->private_impl.f_seen_actl || self->private_impl.f_seen_fctl) {
goto label__1__break;
}
self->private_impl.f_seen_idat = true;
} else if (self->private_impl.f_chunk_type == 1413571686) {
if (self->private_impl.f_seen_idat && self->private_impl.f_seen_fctl) {
goto label__1__break;
}
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
iop_a_src += 8;
if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32) == 0)) {
self->private_impl.f_chunk_type_array[0] = ((uint8_t)(((self->private_impl.f_chunk_type >> 0) & 255)));
self->private_impl.f_chunk_type_array[1] = ((uint8_t)(((self->private_impl.f_chunk_type >> 8) & 255)));
self->private_impl.f_chunk_type_array[2] = ((uint8_t)(((self->private_impl.f_chunk_type >> 16) & 255)));
self->private_impl.f_chunk_type_array[3] = ((uint8_t)(((self->private_impl.f_chunk_type >> 24) & 255)));
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32,
sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
}
while (true) {
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_4 = wuffs_png__decoder__decode_other_chunk(self, a_src);
v_status = t_4;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32) == 0)) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
if (wuffs_base__status__is_ok(&v_status)) {
goto label__2__break;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
}
label__2__break:;
if (self->private_impl.f_metadata_fourcc != 0) {
self->private_impl.f_call_sequence = 1;
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
uint32_t t_5;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_5 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
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;
@@ -36804,83 +37497,21 @@ wuffs_png__decoder__decode_image_config(
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_5;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5);
if (num_bits_5 == 24) {
t_5 = ((uint32_t)(*scratch));
t_5 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_5 += 8;
*scratch |= ((uint64_t)(num_bits_5)) << 56;
*scratch |= ((uint64_t)(num_bits_5));
}
}
self->private_impl.f_chunk_type = t_5;
v_checksum_want = t_5;
}
if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type == 1413563465) || (self->private_impl.f_chunk_type == 1163152464))) {
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, 0));
self->private_impl.f_chunk_type_array[0] = ((uint8_t)(((self->private_impl.f_chunk_type >> 0) & 255)));
self->private_impl.f_chunk_type_array[1] = ((uint8_t)(((self->private_impl.f_chunk_type >> 8) & 255)));
self->private_impl.f_chunk_type_array[2] = ((uint8_t)(((self->private_impl.f_chunk_type >> 16) & 255)));
self->private_impl.f_chunk_type_array[3] = ((uint8_t)(((self->private_impl.f_chunk_type >> 24) & 255)));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
}
if (self->private_impl.f_chunk_type == 1413563465) {
goto label__1__break;
}
while (true) {
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_6 = wuffs_png__decoder__decode_other_chunk(self, a_src);
v_status = t_6;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type == 1163152464)) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
if (wuffs_base__status__is_ok(&v_status)) {
goto label__2__break;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12);
}
label__2__break:;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
uint32_t t_7;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_7 = 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;
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_decode_image_config[0].scratch;
uint32_t num_bits_7 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_7);
if (num_bits_7 == 24) {
t_7 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_7 += 8;
*scratch |= ((uint64_t)(num_bits_7));
}
}
v_checksum_want = t_7;
}
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type == 1163152464) && (v_checksum_have != v_checksum_want)) {
if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32) == 0) && (v_checksum_have != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
goto exit;
}
@@ -36891,6 +37522,7 @@ wuffs_png__decoder__decode_image_config(
goto exit;
}
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
self->private_impl.f_first_config_io_position = self->private_impl.f_frame_config_io_position;
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
@@ -36898,9 +37530,19 @@ wuffs_png__decoder__decode_image_config(
0,
self->private_impl.f_width,
self->private_impl.f_height,
self->private_impl.f_frame_config_io_position,
self->private_impl.f_first_config_io_position,
((self->private_impl.f_color_type <= 3) && ! self->private_impl.f_seen_trns));
}
if ( ! self->private_impl.f_seen_actl) {
self->private_impl.f_num_animation_frames_value = 1;
self->private_impl.f_first_rect_x0 = 0;
self->private_impl.f_first_rect_y0 = 0;
self->private_impl.f_first_rect_x1 = self->private_impl.f_width;
self->private_impl.f_first_rect_y1 = self->private_impl.f_height;
self->private_impl.f_first_duration = 0;
self->private_impl.f_first_disposal = 0;
self->private_impl.f_first_overwrite_instead_of_blend = false;
}
self->private_impl.f_call_sequence = 3;
ok:
@@ -37064,7 +37706,7 @@ wuffs_png__decoder__decode_ihdr(
v_a8 = t_4;
}
if (v_a8 != 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
goto exit;
}
{
@@ -37102,7 +37744,7 @@ wuffs_png__decoder__decode_ihdr(
self->private_impl.f_filter_distance = 0;
wuffs_png__decoder__assign_filter_distance(self);
if (self->private_impl.f_filter_distance == 0) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
self->private_impl.f_overall_workbuf_length = (((uint64_t)(self->private_impl.f_height)) * (1 + wuffs_png__decoder__calculate_bytes_per_row(self, self->private_impl.f_width)));
@@ -37133,7 +37775,9 @@ static wuffs_base__empty_struct
wuffs_png__decoder__assign_filter_distance(
wuffs_png__decoder* self) {
if (self->private_impl.f_depth < 8) {
if (self->private_impl.f_color_type == 0) {
if ((self->private_impl.f_depth != 1) && (self->private_impl.f_depth != 2) && (self->private_impl.f_depth != 4)) {
return wuffs_base__make_empty_struct();
} else if (self->private_impl.f_color_type == 0) {
self->private_impl.f_dst_pixfmt = 536870920;
self->private_impl.f_src_pixfmt = 536870920;
} else if (self->private_impl.f_color_type == 3) {
@@ -37151,8 +37795,13 @@ wuffs_png__decoder__assign_filter_distance(
self->private_impl.f_src_pixfmt = 536870920;
self->private_impl.f_filter_distance = 1;
} else if (self->private_impl.f_depth == 16) {
self->private_impl.f_dst_pixfmt = 536870923;
self->private_impl.f_src_pixfmt = 537919499;
if (self->private_impl.f_interlace_pass == 0) {
self->private_impl.f_dst_pixfmt = 536870923;
self->private_impl.f_src_pixfmt = 537919499;
} else {
self->private_impl.f_dst_pixfmt = 2164308923;
self->private_impl.f_src_pixfmt = 2164308923;
}
self->private_impl.f_filter_distance = 2;
}
} else if (self->private_impl.f_color_type == 2) {
@@ -37293,22 +37942,161 @@ wuffs_png__decoder__decode_other_chunk(
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_type == 1163152464) {
if (self->private_impl.f_seen_plte || (self->private_impl.f_color_type != 3)) {
if (self->private_impl.f_seen_plte) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
} else if (self->private_impl.f_color_type == 3) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_plte(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if ((self->private_impl.f_color_type == 2) || (self->private_impl.f_color_type == 6)) {
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_seen_plte = true;
} else if ((self->private_impl.f_chunk_type & 32) == 0) {
if (self->private_impl.f_chunk_type != 1413563465) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
} else if (self->private_impl.f_chunk_type == 1280598881) {
if (self->private_impl.f_seen_actl) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_plte(self, a_src);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_png__decoder__decode_actl(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_plte = true;
self->private_impl.f_seen_actl = true;
} else if (self->private_impl.f_chunk_type == 1297238115) {
if (self->private_impl.f_report_metadata_chrm) {
if (self->private_impl.f_seen_chrm) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_png__decoder__decode_chrm(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_chrm = true;
}
} else if (self->private_impl.f_chunk_type == 1716082789) {
if (self->private_impl.f_report_metadata_exif) {
if (self->private_impl.f_seen_exif) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_png__decoder__decode_exif(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_exif = true;
}
} else if (self->private_impl.f_chunk_type == 1280598886) {
if (self->private_impl.f_seen_fctl) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
status = wuffs_png__decoder__decode_fctl(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_fctl = true;
} else if (self->private_impl.f_chunk_type == 1095582055) {
if (self->private_impl.f_report_metadata_gama) {
if (self->private_impl.f_seen_gama) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
status = wuffs_png__decoder__decode_gama(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_gama = true;
}
} else if (self->private_impl.f_chunk_type == 1346585449) {
if (self->private_impl.f_report_metadata_iccp) {
if (self->private_impl.f_seen_iccp) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
status = wuffs_png__decoder__decode_iccp(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_iccp = true;
}
} else if (self->private_impl.f_chunk_type == 1111970419) {
if (self->private_impl.f_report_metadata_srgb) {
if (self->private_impl.f_seen_srgb) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
status = wuffs_png__decoder__decode_srgb(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_srgb = true;
}
} else if (self->private_impl.f_chunk_type == 1397641844) {
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
@@ -37317,7 +38105,7 @@ wuffs_png__decoder__decode_other_chunk(
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
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;
@@ -37326,9 +38114,18 @@ wuffs_png__decoder__decode_other_chunk(
goto suspend;
}
self->private_impl.f_seen_trns = true;
} else {
} else if ((self->private_impl.f_chunk_type == 1951945833) || (self->private_impl.f_chunk_type == 1951942004) || (self->private_impl.f_chunk_type == 1951945850)) {
if (self->private_impl.f_report_metadata_kvp) {
self->private_impl.f_metadata_flavor = 4;
self->private_impl.f_metadata_fourcc = 1263947851;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
}
}
if (self->private_impl.f_metadata_fourcc == 0) {
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
if (self->private_data.s_decode_other_chunk[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_other_chunk[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
@@ -37357,6 +38154,964 @@ wuffs_png__decoder__decode_other_chunk(
return status;
}
// -------- func png.decoder.decode_actl
static wuffs_base__status
wuffs_png__decoder__decode_actl(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_actl[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 8) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
} else if (self->private_impl.f_interlace_pass > 0) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_chunk_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_actl[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_actl[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_impl.f_num_animation_frames_value = t_0;
}
if (self->private_impl.f_num_animation_frames_value == 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_actl[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_actl[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
}
self->private_impl.f_num_animation_loops_value = t_1;
}
goto ok;
ok:
self->private_impl.p_decode_actl[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_actl[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_chrm
static wuffs_base__status
wuffs_png__decoder__decode_chrm(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint64_t v_u = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_chrm[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 32) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
self->private_impl.f_metadata_flavor = 5;
self->private_impl.f_metadata_fourcc = 1128813133;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_chrm[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_u = t_0;
}
self->private_impl.f_metadata_x |= ((16777215 & v_u) << 0);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_chrm[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
}
v_u = t_1;
}
self->private_impl.f_metadata_x |= ((16777215 & v_u) << 24);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint64_t t_2;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_2 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_chrm[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2);
if (num_bits_2 == 24) {
t_2 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_2 += 8;
*scratch |= ((uint64_t)(num_bits_2));
}
}
v_u = t_2;
}
self->private_impl.f_metadata_x |= ((uint64_t)((16777215 & v_u) << 48));
self->private_impl.f_metadata_y |= ((16777215 & v_u) >> 16);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
uint64_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_chrm[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_u = t_3;
}
self->private_impl.f_metadata_y |= ((16777215 & v_u) << 8);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
uint64_t t_4;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_4 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
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_chrm[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4);
if (num_bits_4 == 24) {
t_4 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_4 += 8;
*scratch |= ((uint64_t)(num_bits_4));
}
}
v_u = t_4;
}
self->private_impl.f_metadata_y |= ((16777215 & v_u) << 32);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
uint64_t t_5;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_5 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
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_chrm[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5);
if (num_bits_5 == 24) {
t_5 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_5 += 8;
*scratch |= ((uint64_t)(num_bits_5));
}
}
v_u = t_5;
}
self->private_impl.f_metadata_y |= ((uint64_t)((16777215 & v_u) << 56));
self->private_impl.f_metadata_z |= ((16777215 & v_u) >> 8);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
uint64_t t_6;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_6 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_decode_chrm[0].scratch;
uint32_t num_bits_6 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_6);
if (num_bits_6 == 24) {
t_6 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_6 += 8;
*scratch |= ((uint64_t)(num_bits_6));
}
}
v_u = t_6;
}
self->private_impl.f_metadata_z |= ((16777215 & v_u) << 16);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
uint64_t t_7;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_7 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_decode_chrm[0].scratch;
uint32_t num_bits_7 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_7);
if (num_bits_7 == 24) {
t_7 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_7 += 8;
*scratch |= ((uint64_t)(num_bits_7));
}
}
v_u = t_7;
}
self->private_impl.f_metadata_z |= ((16777215 & v_u) << 40);
goto ok;
ok:
self->private_impl.p_decode_chrm[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_chrm[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_exif
static wuffs_base__status
wuffs_png__decoder__decode_exif(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
if (self->private_impl.f_chunk_length < 4) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_metadata_flavor = 3;
self->private_impl.f_metadata_fourcc = 1163413830;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
self->private_impl.f_metadata_z = wuffs_base__u64__sat_add(self->private_impl.f_metadata_y, ((uint64_t)(self->private_impl.f_chunk_length)));
self->private_impl.f_chunk_length = 0;
goto ok;
ok:
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_fctl
static wuffs_base__status
wuffs_png__decoder__decode_fctl(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_x0 = 0;
uint32_t v_y0 = 0;
uint32_t v_x1 = 0;
uint32_t v_y1 = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_fctl[0];
if (coro_susp_point) {
v_x0 = self->private_data.s_decode_fctl[0].v_x0;
v_x1 = self->private_data.s_decode_fctl[0].v_x1;
v_y1 = self->private_data.s_decode_fctl[0].v_y1;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 26) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[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_fctl[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_x0 = t_0;
}
if (v_x0 != self->private_impl.f_next_animation_seq_num) {
status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number);
goto exit;
} else if (self->private_impl.f_next_animation_seq_num >= 4294967295) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_next_animation_seq_num += 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[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_fctl[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
}
v_x1 = t_1;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint32_t t_2;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_2 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[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_fctl[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2);
if (num_bits_2 == 24) {
t_2 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_2 += 8;
*scratch |= ((uint64_t)(num_bits_2));
}
}
v_y1 = t_2;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[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_fctl[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_x0 = t_3;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
uint32_t t_4;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_4 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
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_fctl[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4);
if (num_bits_4 == 24) {
t_4 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_4 += 8;
*scratch |= ((uint64_t)(num_bits_4));
}
}
v_y0 = t_4;
}
v_x1 += v_x0;
v_y1 += v_y0;
if ((v_x0 >= v_x1) ||
(v_x0 > self->private_impl.f_width) ||
(v_x1 > self->private_impl.f_width) ||
(v_y0 >= v_y1) ||
(v_y0 > self->private_impl.f_height) ||
(v_y1 > self->private_impl.f_height)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_frame_rect_x0 = v_x0;
self->private_impl.f_frame_rect_y0 = v_y0;
self->private_impl.f_frame_rect_x1 = v_x1;
self->private_impl.f_frame_rect_y1 = v_y1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
uint32_t t_5;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_5 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_fctl[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
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_fctl[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5);
if (num_bits_5 == 8) {
t_5 = ((uint32_t)(*scratch >> 48));
break;
}
num_bits_5 += 8;
*scratch |= ((uint64_t)(num_bits_5));
}
}
v_x0 = t_5;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
uint32_t t_6;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_6 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_fctl[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_decode_fctl[0].scratch;
uint32_t num_bits_6 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_6);
if (num_bits_6 == 8) {
t_6 = ((uint32_t)(*scratch >> 48));
break;
}
num_bits_6 += 8;
*scratch |= ((uint64_t)(num_bits_6));
}
}
v_x1 = t_6;
}
if (v_x1 <= 0) {
self->private_impl.f_frame_duration = (((uint64_t)(v_x0)) * 7056000);
} else {
self->private_impl.f_frame_duration = ((((uint64_t)(v_x0)) * 705600000) / ((uint64_t)(v_x1)));
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint32_t t_7 = *iop_a_src++;
v_x0 = t_7;
}
if (v_x0 == 0) {
self->private_impl.f_frame_disposal = 0;
} else if (v_x0 == 1) {
self->private_impl.f_frame_disposal = 1;
} else if (v_x0 == 2) {
self->private_impl.f_frame_disposal = 2;
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint32_t t_8 = *iop_a_src++;
v_x0 = t_8;
}
if (v_x0 == 0) {
self->private_impl.f_frame_overwrite_instead_of_blend = true;
} else if (v_x0 == 1) {
self->private_impl.f_frame_overwrite_instead_of_blend = false;
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (self->private_impl.f_num_decoded_frame_configs_value == 0) {
self->private_impl.f_first_rect_x0 = self->private_impl.f_frame_rect_x0;
self->private_impl.f_first_rect_y0 = self->private_impl.f_frame_rect_y0;
self->private_impl.f_first_rect_x1 = self->private_impl.f_frame_rect_x1;
self->private_impl.f_first_rect_y1 = self->private_impl.f_frame_rect_y1;
self->private_impl.f_first_duration = self->private_impl.f_frame_duration;
self->private_impl.f_first_disposal = self->private_impl.f_frame_disposal;
self->private_impl.f_first_overwrite_instead_of_blend = self->private_impl.f_frame_overwrite_instead_of_blend;
}
goto ok;
ok:
self->private_impl.p_decode_fctl[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_fctl[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_fctl[0].v_x0 = v_x0;
self->private_data.s_decode_fctl[0].v_x1 = v_x1;
self->private_data.s_decode_fctl[0].v_y1 = v_y1;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_gama
static wuffs_base__status
wuffs_png__decoder__decode_gama(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_gama[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 4) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
self->private_impl.f_metadata_flavor = 5;
self->private_impl.f_metadata_fourcc = 1195461953;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_gama[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_gama[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_impl.f_metadata_x = t_0;
}
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
goto ok;
ok:
self->private_impl.p_decode_gama[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_gama[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_iccp
static wuffs_base__status
wuffs_png__decoder__decode_iccp(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_iccp[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
if (self->private_impl.f_chunk_length <= 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_0 = *iop_a_src++;
v_c = t_0;
}
if (v_c == 0) {
goto label__0__break;
}
}
label__0__break:;
if (self->private_impl.f_chunk_length <= 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_1 = *iop_a_src++;
v_c = t_1;
}
if (v_c != 0) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
goto exit;
}
self->private_impl.f_metadata_is_zlib_compressed = true;
self->private_impl.f_metadata_flavor = 4;
self->private_impl.f_metadata_fourcc = 1229144912;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
goto ok;
ok:
self->private_impl.p_decode_iccp[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_iccp[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_plte
static wuffs_base__status
@@ -37393,6 +39148,7 @@ wuffs_png__decoder__decode_plte(
goto exit;
}
v_num_entries = (((uint32_t)(self->private_impl.f_chunk_length)) / 3);
self->private_impl.f_chunk_length = 0;
while (v_i < v_num_entries) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
@@ -37459,6 +39215,67 @@ wuffs_png__decoder__decode_plte(
return status;
}
// -------- func png.decoder.decode_srgb
static wuffs_base__status
wuffs_png__decoder__decode_srgb(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_srgb[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 1) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
self->private_impl.f_metadata_flavor = 5;
self->private_impl.f_metadata_fourcc = 1397901122;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t t_0 = *iop_a_src++;
self->private_impl.f_metadata_x = t_0;
}
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
goto ok;
ok:
self->private_impl.p_decode_srgb[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_srgb[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_trns
static wuffs_base__status
@@ -37467,8 +39284,9 @@ wuffs_png__decoder__decode_trns(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_num_entries = 0;
uint32_t v_i = 0;
uint32_t v_n = 0;
uint64_t v_u = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -37483,42 +39301,143 @@ wuffs_png__decoder__decode_trns(
uint32_t coro_susp_point = self->private_impl.p_decode_trns[0];
if (coro_susp_point) {
v_num_entries = self->private_data.s_decode_trns[0].v_num_entries;
v_i = self->private_data.s_decode_trns[0].v_i;
v_n = self->private_data.s_decode_trns[0].v_n;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length > 256) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
v_num_entries = ((uint32_t)(self->private_impl.f_chunk_length));
while (v_i < v_num_entries) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_0 = *iop_a_src++;
self->private_data.f_src_palette[((4 * v_i) + 3)] = t_0;
}
v_i += 1;
}
if (self->private_impl.f_color_type == 3) {
self->private_impl.f_dst_pixfmt = 2164523016;
self->private_impl.f_src_pixfmt = 2164523016;
} else {
if (self->private_impl.f_color_type == 0) {
self->private_impl.choosy_filter_and_swizzle = (
&wuffs_png__decoder__filter_and_swizzle_tricky);
if (self->private_impl.f_color_type == 0) {
self->private_impl.f_dst_pixfmt = 2164295816;
self->private_impl.f_src_pixfmt = 2164308923;
} else if (self->private_impl.f_color_type == 2) {
if (self->private_impl.f_depth <= 8) {
self->private_impl.f_dst_pixfmt = 2164295816;
self->private_impl.f_src_pixfmt = 2164295816;
} else {
self->private_impl.f_dst_pixfmt = 2164308923;
self->private_impl.f_src_pixfmt = 2164308923;
}
if (self->private_impl.f_chunk_length != 2) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_0 = ((uint64_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_trns[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_trns[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 8) {
t_0 = ((uint64_t)(*scratch >> 48));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_u = t_0;
}
if (self->private_impl.f_depth <= 1) {
self->private_impl.f_remap_transparency = (((v_u & 1) * 16777215) | 4278190080);
} else if (self->private_impl.f_depth <= 2) {
self->private_impl.f_remap_transparency = (((v_u & 3) * 5592405) | 4278190080);
} else if (self->private_impl.f_depth <= 4) {
self->private_impl.f_remap_transparency = (((v_u & 15) * 1118481) | 4278190080);
} else if (self->private_impl.f_depth <= 8) {
self->private_impl.f_remap_transparency = (((v_u & 255) * 65793) | 4278190080);
} else {
self->private_impl.f_remap_transparency = ((v_u * 4295032833) | 18446462598732840960u);
}
} else if (self->private_impl.f_color_type == 2) {
self->private_impl.choosy_filter_and_swizzle = (
&wuffs_png__decoder__filter_and_swizzle_tricky);
if (self->private_impl.f_depth <= 8) {
self->private_impl.f_dst_pixfmt = 2164295816;
self->private_impl.f_src_pixfmt = 2164295816;
} else {
self->private_impl.f_dst_pixfmt = 2164308923;
self->private_impl.f_src_pixfmt = 2164308923;
}
if (self->private_impl.f_chunk_length != 6) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 6)) {
t_1 = ((uint64_t)(wuffs_base__peek_u48be__no_bounds_check(iop_a_src)));
iop_a_src += 6;
} else {
self->private_data.s_decode_trns[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_trns[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 40) {
t_1 = ((uint64_t)(*scratch >> 16));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
}
v_u = t_1;
}
if (self->private_impl.f_depth <= 8) {
self->private_impl.f_remap_transparency = ((255 & (v_u >> 0)) |
(65280 & (v_u >> 8)) |
(16711680 & (v_u >> 16)) |
4278190080);
} else {
self->private_impl.f_remap_transparency = (v_u | 18446462598732840960u);
}
} else if (self->private_impl.f_color_type == 3) {
self->private_impl.f_dst_pixfmt = 2164523016;
self->private_impl.f_src_pixfmt = 2164523016;
if (self->private_impl.f_chunk_length > 256) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
v_n = ((uint32_t)(self->private_impl.f_chunk_length));
self->private_impl.f_chunk_length = 0;
while (v_i < v_n) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_2 = *iop_a_src++;
self->private_data.f_src_palette[((4 * v_i) + 3)] = t_2;
}
v_i += 1;
}
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
goto ok;
@@ -37530,8 +39449,8 @@ wuffs_png__decoder__decode_trns(
goto suspend;
suspend:
self->private_impl.p_decode_trns[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_trns[0].v_num_entries = v_num_entries;
self->private_data.s_decode_trns[0].v_i = v_i;
self->private_data.s_decode_trns[0].v_n = v_n;
goto exit;
exit:
@@ -37585,7 +39504,10 @@ wuffs_png__decoder__decode_frame_config(
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence < 3) {
if (self->private_impl.f_call_sequence == 255) {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else if (self->private_impl.f_call_sequence < 3) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -37603,29 +39525,148 @@ wuffs_png__decoder__decode_frame_config(
goto exit;
}
} else if (self->private_impl.f_call_sequence == 4) {
self->private_impl.f_call_sequence = 255;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_png__decoder__skip_frame(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
if (self->private_impl.f_call_sequence == 255) {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
}
if (self->private_impl.f_num_decoded_frame_configs_value == 0) {
self->private_impl.f_frame_rect_x0 = self->private_impl.f_first_rect_x0;
self->private_impl.f_frame_rect_y0 = self->private_impl.f_first_rect_y0;
self->private_impl.f_frame_rect_x1 = self->private_impl.f_first_rect_x1;
self->private_impl.f_frame_rect_y1 = self->private_impl.f_first_rect_y1;
self->private_impl.f_frame_config_io_position = self->private_impl.f_first_config_io_position;
self->private_impl.f_frame_duration = self->private_impl.f_first_duration;
self->private_impl.f_frame_disposal = self->private_impl.f_first_disposal;
self->private_impl.f_frame_overwrite_instead_of_blend = self->private_impl.f_first_overwrite_instead_of_blend;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
while (true) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
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;
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;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_impl.f_chunk_length = t_0;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
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;
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;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
self->private_impl.f_chunk_type = t_1;
}
if (self->private_impl.f_chunk_type == 1413571686) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
} else if (self->private_impl.f_chunk_type == 1280598886) {
self->private_impl.f_frame_config_io_position = ((uint64_t)(wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) - 8));
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
status = wuffs_png__decoder__decode_fctl(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_data.s_decode_frame_config[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
goto label__0__break;
}
self->private_data.s_decode_frame_config[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0,
0,
self->private_impl.f_width,
self->private_impl.f_height),
((wuffs_base__flicks)(0)),
0,
self->private_impl.f_frame_rect_x0,
self->private_impl.f_frame_rect_y0,
self->private_impl.f_frame_rect_x1,
self->private_impl.f_frame_rect_y1),
((wuffs_base__flicks)(self->private_impl.f_frame_duration)),
((uint64_t)(self->private_impl.f_num_decoded_frame_configs_value)),
self->private_impl.f_frame_config_io_position,
0,
false,
false,
self->private_impl.f_frame_disposal,
((self->private_impl.f_color_type <= 3) && ! self->private_impl.f_seen_trns),
self->private_impl.f_frame_overwrite_instead_of_blend,
0);
}
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
self->private_impl.f_call_sequence = 4;
ok:
@@ -37650,6 +39691,162 @@ wuffs_png__decoder__decode_frame_config(
return status;
}
// -------- func png.decoder.skip_frame
static wuffs_base__status
wuffs_png__decoder__skip_frame(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_seq_num = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_skip_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
self->private_impl.f_chunk_type_array[0] = 0;
self->private_impl.f_chunk_type_array[1] = 0;
self->private_impl.f_chunk_type_array[2] = 0;
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;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
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)));
if (self->private_impl.f_chunk_type == 1413563465) {
if (self->private_impl.f_chunk_type_array[0] == 102) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 68;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
} else if (self->private_impl.f_chunk_type == 1413571686) {
if (self->private_impl.f_chunk_type_array[0] == 73) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_type_array[0] = 102;
self->private_impl.f_chunk_type_array[1] = 100;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
if (self->private_impl.f_chunk_length < 4) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 4;
iop_a_src += 8;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_skip_frame[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
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_skip_frame[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_seq_num = t_0;
}
if (v_seq_num != self->private_impl.f_next_animation_seq_num) {
status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number);
goto exit;
} else if (self->private_impl.f_next_animation_seq_num >= 4294967295) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_next_animation_seq_num += 1;
self->private_data.s_skip_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (self->private_data.s_skip_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_skip_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_skip_frame[0].scratch;
self->private_impl.f_chunk_length = 0;
goto label__0__continue;
} else if (self->private_impl.f_chunk_type_array[0] != 0) {
goto label__0__break;
} else if (self->private_impl.f_chunk_type == 1280598886) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_data.s_skip_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (self->private_data.s_skip_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_skip_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_skip_frame[0].scratch;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
if (self->private_impl.f_num_decoded_frames_value < self->private_impl.f_num_animation_frames_value) {
self->private_impl.f_call_sequence = 5;
} else {
self->private_impl.f_call_sequence = 255;
}
ok:
self->private_impl.p_skip_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_skip_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_frame
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
@@ -37681,25 +39878,138 @@ wuffs_png__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
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;
uint32_t v_pass_height = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence < 4) {
if (self->private_impl.f_call_sequence == 255) {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else if (self->private_impl.f_call_sequence != 4) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 4) {
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
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;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
}
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)));
if (self->private_impl.f_chunk_type == 1413563465) {
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 68;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
iop_a_src += 8;
if ( ! self->private_impl.f_ignore_checksum) {
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32,
sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
}
goto label__0__break;
} else if (self->private_impl.f_chunk_type == 1413571686) {
self->private_impl.f_chunk_type_array[0] = 102;
self->private_impl.f_chunk_type_array[1] = 100;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
if (self->private_impl.f_chunk_length < 4) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 4;
iop_a_src += 8;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
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;
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;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_seq_num = t_0;
}
if (v_seq_num != self->private_impl.f_next_animation_seq_num) {
status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number);
goto exit;
} else if (self->private_impl.f_next_animation_seq_num >= 4294967295) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_next_animation_seq_num += 1;
goto label__0__break;
} else if (self->private_impl.f_chunk_type == 1280598886) {
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);
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));
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;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
if (self->private_impl.f_zlib_is_dirty) {
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
if (self->private_impl.f_ignore_checksum) {
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
}
}
self->private_impl.f_zlib_is_dirty = true;
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
wuffs_base__pixel_buffer__pixel_format(a_dst),
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)),
@@ -37718,13 +40028,24 @@ wuffs_png__decoder__decode_frame(
}
self->private_impl.f_workbuf_hist_pos_base = 0;
while (true) {
v_pass_width = (16777215 & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][1])) + self->private_impl.f_width) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]));
v_pass_height = (16777215 & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][4])) + self->private_impl.f_height) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3]));
if (self->private_impl.f_chunk_type_array[0] == 73) {
v_pass_width = (16777215 & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][1])) + self->private_impl.f_width) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]));
v_pass_height = (16777215 & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][4])) + self->private_impl.f_height) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3]));
} else {
v_pass_width = (16777215 & ((uint32_t)(self->private_impl.f_frame_rect_x1 - self->private_impl.f_frame_rect_x0)));
v_pass_height = (16777215 & ((uint32_t)(self->private_impl.f_frame_rect_y1 - self->private_impl.f_frame_rect_y0)));
}
if ((v_pass_width > 0) && (v_pass_height > 0)) {
self->private_impl.f_pass_bytes_per_row = wuffs_png__decoder__calculate_bytes_per_row(self, v_pass_width);
self->private_impl.f_pass_workbuf_length = (((uint64_t)(v_pass_height)) * (1 + self->private_impl.f_pass_bytes_per_row));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
status = wuffs_png__decoder__decode_pass(self, a_src, a_workbuf);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
@@ -37742,7 +40063,7 @@ wuffs_png__decoder__decode_frame(
self->private_impl.f_workbuf_hist_pos_base += self->private_impl.f_pass_workbuf_length;
}
if ((self->private_impl.f_interlace_pass == 0) || (self->private_impl.f_interlace_pass >= 7)) {
goto label__0__break;
goto label__1__break;
}
#if defined(__GNUC__)
#pragma GCC diagnostic push
@@ -37753,8 +40074,13 @@ wuffs_png__decoder__decode_frame(
#pragma GCC diagnostic pop
#endif
}
label__0__break:;
self->private_impl.f_call_sequence = 255;
label__1__break:;
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
if (self->private_impl.f_num_decoded_frames_value < self->private_impl.f_num_animation_frames_value) {
self->private_impl.f_call_sequence = 5;
} else {
self->private_impl.f_call_sequence = 255;
}
ok:
self->private_impl.p_decode_frame[0] = 0;
@@ -37768,6 +40094,10 @@ wuffs_png__decoder__decode_frame(
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
@@ -37794,6 +40124,7 @@ wuffs_png__decoder__decode_pass(
wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL);
uint32_t v_checksum_have = 0;
uint32_t v_checksum_want = 0;
uint32_t v_seq_num = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -37807,9 +40138,6 @@ wuffs_png__decoder__decode_pass(
}
uint32_t coro_susp_point = self->private_impl.p_decode_pass[0];
if (coro_susp_point) {
v_checksum_have = self->private_data.s_decode_pass[0].v_checksum_have;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -37839,7 +40167,7 @@ wuffs_png__decoder__decode_pass(
{
const uint8_t *o_1_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
self->private_impl.f_chunk_length);
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
@@ -37860,7 +40188,7 @@ wuffs_png__decoder__decode_pass(
if ( ! self->private_impl.f_ignore_checksum) {
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
wuffs_base__u64__sat_sub_indirect(&self->private_impl.f_chunk_length, wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))));
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))));
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) {
@@ -37874,41 +40202,41 @@ wuffs_png__decoder__decode_pass(
io2_v_w = o_0_io2_v_w;
}
if (wuffs_base__status__is_ok(&v_zlib_status)) {
if ( ! self->private_impl.f_ignore_checksum) {
if (self->private_impl.f_chunk_length > 0) {
status = wuffs_base__make_status(wuffs_base__error__too_much_data);
goto exit;
}
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8());
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_pass[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_pass[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
if (self->private_impl.f_chunk_length > 0) {
status = wuffs_base__make_status(wuffs_base__error__too_much_data);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_pass[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_pass[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
v_checksum_want = t_1;
}
v_checksum_want = t_1;
}
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type_array[0] == 73)) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8());
if (v_checksum_have != v_checksum_want) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
goto exit;
@@ -37960,7 +40288,7 @@ wuffs_png__decoder__decode_pass(
}
v_checksum_want = t_2;
}
if ( ! self->private_impl.f_ignore_checksum) {
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type_array[0] == 73)) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8());
if (v_checksum_have != v_checksum_want) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
@@ -37969,9 +40297,9 @@ wuffs_png__decoder__decode_pass(
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint64_t t_3;
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_pass[0].scratch = 0;
@@ -37987,7 +40315,7 @@ wuffs_png__decoder__decode_pass(
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint64_t)(*scratch >> 32));
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
@@ -38025,17 +40353,59 @@ wuffs_png__decoder__decode_pass(
}
self->private_impl.f_chunk_type = t_4;
}
if (self->private_impl.f_chunk_type != 1413563465) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if ( ! self->private_impl.f_ignore_checksum) {
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, 0));
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 68;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
if (self->private_impl.f_chunk_type_array[0] == 73) {
if (self->private_impl.f_chunk_type != 1413563465) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if ( ! self->private_impl.f_ignore_checksum) {
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32,
sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
}
} else {
if ((self->private_impl.f_chunk_type != 1413571686) || (self->private_impl.f_chunk_length < 4)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 4;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
uint32_t t_5;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_5 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_pass[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
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_pass[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5);
if (num_bits_5 == 24) {
t_5 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_5 += 8;
*scratch |= ((uint64_t)(num_bits_5));
}
}
v_seq_num = t_5;
}
if (v_seq_num != self->private_impl.f_next_animation_seq_num) {
status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number);
goto exit;
} else if (self->private_impl.f_next_animation_seq_num >= 4294967295) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_next_animation_seq_num += 1;
}
goto label__0__continue;
} else if (((uint64_t)(io2_a_src - iop_a_src)) > 0) {
@@ -38043,7 +40413,7 @@ wuffs_png__decoder__decode_pass(
goto exit;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
}
label__0__break:;
if (self->private_impl.f_workbuf_wi != self->private_impl.f_pass_workbuf_length) {
@@ -38063,7 +40433,6 @@ wuffs_png__decoder__decode_pass(
goto suspend;
suspend:
self->private_impl.p_decode_pass[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_pass[0].v_checksum_have = v_checksum_have;
goto exit;
exit:
@@ -38088,10 +40457,10 @@ wuffs_png__decoder__frame_dirty_rect(
}
return wuffs_base__utility__make_rect_ie_u32(
0,
0,
self->private_impl.f_width,
self->private_impl.f_height);
self->private_impl.f_frame_rect_x0,
self->private_impl.f_frame_rect_y0,
self->private_impl.f_frame_rect_x1,
self->private_impl.f_frame_rect_y1);
}
// -------- func png.decoder.num_animation_loops
@@ -38107,7 +40476,7 @@ wuffs_png__decoder__num_animation_loops(
return 0;
}
return 0;
return self->private_impl.f_num_animation_loops_value;
}
// -------- func png.decoder.num_decoded_frame_configs
@@ -38123,10 +40492,7 @@ wuffs_png__decoder__num_decoded_frame_configs(
return 0;
}
if (self->private_impl.f_call_sequence > 3) {
return 1;
}
return 0;
return ((uint64_t)(self->private_impl.f_num_decoded_frame_configs_value));
}
// -------- func png.decoder.num_decoded_frames
@@ -38142,10 +40508,7 @@ wuffs_png__decoder__num_decoded_frames(
return 0;
}
if (self->private_impl.f_call_sequence > 4) {
return 1;
}
return 0;
return ((uint64_t)(self->private_impl.f_num_decoded_frames_value));
}
// -------- func png.decoder.restart_frame
@@ -38167,8 +40530,7 @@ wuffs_png__decoder__restart_frame(
if (self->private_impl.f_call_sequence < 3) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if (a_index != 0) {
} else if ((a_index >= ((uint64_t)(self->private_impl.f_num_animation_frames_value))) || ((a_index == 0) && (a_io_position != self->private_impl.f_first_config_io_position))) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 3;
@@ -38176,6 +40538,8 @@ wuffs_png__decoder__restart_frame(
self->private_impl.f_interlace_pass = 1;
}
self->private_impl.f_frame_config_io_position = a_io_position;
self->private_impl.f_num_decoded_frame_configs_value = ((uint32_t)((a_index & 4294967295)));
self->private_impl.f_num_decoded_frames_value = self->private_impl.f_num_decoded_frame_configs_value;
return wuffs_base__make_status(NULL);
}
@@ -38186,6 +40550,26 @@ wuffs_png__decoder__set_report_metadata(
wuffs_png__decoder* self,
uint32_t a_fourcc,
bool a_report) {
if (!self) {
return wuffs_base__make_empty_struct();
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_empty_struct();
}
if (a_fourcc == 1128813133) {
self->private_impl.f_report_metadata_chrm = a_report;
} else if (a_fourcc == 1163413830) {
self->private_impl.f_report_metadata_exif = a_report;
} else if (a_fourcc == 1195461953) {
self->private_impl.f_report_metadata_gama = a_report;
} else if (a_fourcc == 1229144912) {
self->private_impl.f_report_metadata_iccp = a_report;
} else if (a_fourcc == 1263947808) {
self->private_impl.f_report_metadata_kvp = a_report;
} else if (a_fourcc == 1397901122) {
self->private_impl.f_report_metadata_srgb = a_report;
}
return wuffs_base__make_empty_struct();
}
@@ -38218,13 +40602,498 @@ wuffs_png__decoder__tell_me_more(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
uint8_t v_c = 0;
uint16_t v_c2 = 0;
wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer();
wuffs_base__io_buffer* v_w = &u_w;
uint8_t* iop_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io0_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint64_t v_num_written = 0;
uint64_t v_w_mark = 0;
uint64_t v_r_mark = 0;
wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL);
uint8_t* iop_a_dst = NULL;
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
io2_a_dst = io0_a_dst + a_dst->data.len;
if (a_dst->meta.closed) {
io2_a_dst = iop_a_dst;
}
}
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
if (coro_susp_point) {
v_zlib_status = self->private_data.s_tell_me_more[0].v_zlib_status;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 1) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
if (self->private_impl.f_metadata_fourcc == 0) {
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
}
while (true) {
if (self->private_impl.f_metadata_flavor == 3) {
while (true) {
if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_y) {
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
goto exit;
} else if (a_minfo != NULL) {
wuffs_base__more_information__set(a_minfo,
self->private_impl.f_metadata_flavor,
self->private_impl.f_metadata_fourcc,
self->private_impl.f_metadata_x,
self->private_impl.f_metadata_y,
self->private_impl.f_metadata_z);
}
if (self->private_impl.f_metadata_y >= self->private_impl.f_metadata_z) {
goto label__goto_done__break;
}
self->private_impl.f_metadata_y = self->private_impl.f_metadata_z;
status = wuffs_base__make_status(wuffs_base__suspension__even_more_information);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
}
if (self->private_impl.f_metadata_is_zlib_compressed) {
if (self->private_impl.f_zlib_is_dirty) {
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
if (self->private_impl.f_ignore_checksum) {
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
}
}
self->private_impl.f_zlib_is_dirty = true;
self->private_impl.f_ztxt_hist_pos = 0;
}
label__loop__continue:;
while (true) {
if (a_minfo != NULL) {
wuffs_base__more_information__set(a_minfo,
self->private_impl.f_metadata_flavor,
self->private_impl.f_metadata_fourcc,
self->private_impl.f_metadata_x,
self->private_impl.f_metadata_y,
self->private_impl.f_metadata_z);
}
if (self->private_impl.f_metadata_flavor != 4) {
goto label__loop__break;
}
if (self->private_impl.f_metadata_is_zlib_compressed) {
if (self->private_impl.f_chunk_type == 1346585449) {
{
const uint8_t *o_0_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_dst) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
v_zlib_status = t_0;
if (a_dst) {
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
}
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
io2_a_src = o_0_io2_a_src;
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
if (wuffs_base__status__is_ok(&v_zlib_status)) {
self->private_impl.f_metadata_is_zlib_compressed = false;
goto label__loop__break;
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
status = v_zlib_status;
if (wuffs_base__status__is_error(&status)) {
goto exit;
} else if (wuffs_base__status__is_suspension(&status)) {
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
goto exit;
}
goto ok;
}
status = v_zlib_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
} else if (self->private_impl.f_chunk_type == 1951945833) {
{
const uint8_t *o_1_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_dst) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
v_zlib_status = t_1;
if (a_dst) {
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
}
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
io2_a_src = o_1_io2_a_src;
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
if (wuffs_base__status__is_ok(&v_zlib_status)) {
self->private_impl.f_metadata_is_zlib_compressed = false;
goto label__loop__break;
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
status = v_zlib_status;
if (wuffs_base__status__is_error(&status)) {
goto exit;
} else if (wuffs_base__status__is_suspension(&status)) {
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
goto exit;
}
goto ok;
}
status = v_zlib_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
} else if (self->private_impl.f_chunk_type == 1951945850) {
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
{
wuffs_base__io_buffer* o_2_v_w = v_w;
uint8_t *o_2_iop_v_w = iop_v_w;
uint8_t *o_2_io0_v_w = io0_v_w;
uint8_t *o_2_io1_v_w = io1_v_w;
uint8_t *o_2_io2_v_w = io2_v_w;
v_w = wuffs_base__io_writer__set(
&u_w,
&iop_v_w,
&io0_v_w,
&io1_v_w,
&io2_v_w,
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
self->private_impl.f_ztxt_hist_pos);
{
const uint8_t *o_3_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
v_zlib_status = t_2;
iop_v_w = u_w.data.ptr + u_w.meta.wi;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
io2_a_src = o_3_io2_a_src;
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
v_w = o_2_v_w;
iop_v_w = o_2_iop_v_w;
io0_v_w = o_2_io0_v_w;
io1_v_w = o_2_io1_v_w;
io2_v_w = o_2_io2_v_w;
}
if (v_num_written > 1024) {
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
goto exit;
}
self->private_impl.f_ztxt_ri = 0;
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
}
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
if (v_c2 == 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
goto exit;
} else if (v_c2 <= 127) {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
v_c2 = 0;
goto label__loop__continue;
}
self->private_impl.f_ztxt_ri += 1;
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
} else {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
v_c2 = 0;
goto label__loop__continue;
}
self->private_impl.f_ztxt_ri += 1;
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
}
}
if (wuffs_base__status__is_ok(&v_zlib_status)) {
self->private_impl.f_metadata_is_zlib_compressed = false;
goto label__loop__break;
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
status = v_zlib_status;
if (wuffs_base__status__is_error(&status)) {
goto exit;
} else if (wuffs_base__status__is_suspension(&status)) {
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
goto exit;
}
goto ok;
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
status = v_zlib_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
} else {
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
goto exit;
}
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
while (true) {
if (self->private_impl.f_chunk_length <= 0) {
goto label__loop__break;
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
goto label__loop__continue;
} else if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
goto label__loop__continue;
}
self->private_impl.f_chunk_length -= 1;
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
iop_a_src += 1;
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
}
} else {
while (true) {
if (self->private_impl.f_chunk_length <= 0) {
if (self->private_impl.f_metadata_fourcc == 1263947851) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
goto label__loop__break;
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
goto label__loop__continue;
}
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
if (v_c == 0) {
self->private_impl.f_chunk_length -= 1;
iop_a_src += 1;
goto label__loop__break;
}
v_c2 = WUFFS_PNG__LATIN_1[v_c];
if (v_c2 == 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
goto exit;
} else if (v_c2 <= 127) {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
v_c2 = 0;
goto label__loop__continue;
}
self->private_impl.f_chunk_length -= 1;
iop_a_src += 1;
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
} else {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
v_c2 = 0;
goto label__loop__continue;
}
self->private_impl.f_chunk_length -= 1;
iop_a_src += 1;
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
}
}
}
}
label__loop__break:;
if (self->private_impl.f_metadata_fourcc == 1263947851) {
self->private_impl.f_metadata_fourcc = 1263947862;
if (self->private_impl.f_chunk_type == 1951945833) {
if (self->private_impl.f_chunk_length <= 1) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 2;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_3 = *iop_a_src++;
v_c = t_3;
}
if (v_c == 0) {
self->private_impl.f_metadata_is_zlib_compressed = false;
} else if (v_c == 1) {
self->private_impl.f_metadata_is_zlib_compressed = true;
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_4 = *iop_a_src++;
v_c = t_4;
}
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
goto exit;
}
self->private_impl.f_metadata_fourcc -= 2;
while (self->private_impl.f_metadata_fourcc != 1263947862) {
self->private_impl.f_metadata_fourcc += 1;
while (true) {
if (self->private_impl.f_chunk_length <= 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_5 = *iop_a_src++;
v_c = t_5;
}
if (v_c == 0) {
goto label__0__break;
}
}
label__0__break:;
}
} else if (self->private_impl.f_chunk_type == 1951945850) {
if (self->private_impl.f_chunk_length <= 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_6 = *iop_a_src++;
v_c = t_6;
}
if (v_c != 0) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
goto exit;
}
self->private_impl.f_metadata_is_zlib_compressed = true;
}
self->private_impl.f_call_sequence = 2;
status = wuffs_base__make_status(NULL);
goto ok;
}
goto label__goto_done__break;
}
label__goto_done__break:;
if (self->private_impl.f_chunk_length != 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_data.s_tell_me_more[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
self->private_impl.f_metadata_flavor = 0;
self->private_impl.f_metadata_fourcc = 0;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
self->private_impl.f_call_sequence = 2;
status = wuffs_base__make_status(NULL);
goto ok;
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;
self->private_data.s_tell_me_more[0].v_zlib_status = v_zlib_status;
goto ok;
ok:
goto exit;
exit:
if (a_dst) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
@@ -38265,7 +41134,8 @@ wuffs_png__decoder__filter_and_swizzle__choosy_default(
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint64_t v_dst_bytes_per_row0 = 0;
uint64_t v_dst_bytes_per_row1 = 0;
wuffs_base__slice_u8 v_dst_palette = {0};
wuffs_base__table_u8 v_tab = {0};
uint32_t v_y = 0;
@@ -38280,14 +41150,33 @@ wuffs_png__decoder__filter_and_swizzle__choosy_default(
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
v_dst_bytes_per_row0 = (((uint64_t)(self->private_impl.f_frame_rect_x0)) * v_dst_bytes_per_pixel);
v_dst_bytes_per_row1 = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * v_dst_bytes_per_pixel);
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
while (v_y < self->private_impl.f_height) {
v_dst = wuffs_base__table_u8__row(v_tab, v_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
if (v_dst_bytes_per_row1 < ((uint64_t)(v_tab.width))) {
v_tab = wuffs_base__table_u8__subtable_ij(v_tab,
0,
0,
v_dst_bytes_per_row1,
((uint64_t)(v_tab.height)));
}
if (v_dst_bytes_per_row0 < ((uint64_t)(v_tab.width))) {
v_tab = wuffs_base__table_u8__subtable_ij(v_tab,
v_dst_bytes_per_row0,
0,
((uint64_t)(v_tab.width)),
((uint64_t)(v_tab.height)));
} else {
v_tab = wuffs_base__table_u8__subtable_ij(v_tab,
0,
0,
0,
0);
}
v_y = self->private_impl.f_frame_rect_y0;
while (v_y < self->private_impl.f_frame_rect_y1) {
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_y);
if (1 > ((uint64_t)(a_workbuf.len))) {
return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length);
}
@@ -38327,7 +41216,7 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint64_t v_dst_bytes_per_row1 = 0;
wuffs_base__slice_u8 v_dst_palette = {0};
wuffs_base__table_u8 v_tab = {0};
uint64_t v_src_bytes_per_pixel = 0;
@@ -38351,26 +41240,22 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
v_dst_bytes_per_row1 = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * v_dst_bytes_per_pixel);
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
v_src_bytes_per_pixel = 1;
if (self->private_impl.f_depth >= 8) {
v_src_bytes_per_pixel = (((uint64_t)(WUFFS_PNG__NUM_CHANNELS[self->private_impl.f_color_type])) * ((uint64_t)((self->private_impl.f_depth >> 3))));
}
v_bits_unpacked[0] = 255;
v_bits_unpacked[1] = 255;
v_bits_unpacked[2] = 255;
v_bits_unpacked[3] = 255;
v_bits_unpacked[4] = 255;
v_bits_unpacked[5] = 255;
v_bits_unpacked[6] = 255;
v_bits_unpacked[7] = 255;
v_y = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][5]));
while (v_y < self->private_impl.f_height) {
v_dst = wuffs_base__table_u8__row(v_tab, v_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
if (self->private_impl.f_chunk_type_array[0] == 73) {
v_y = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][5]));
} else {
v_y = self->private_impl.f_frame_rect_y0;
}
while (v_y < self->private_impl.f_frame_rect_y1) {
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_y);
if (v_dst_bytes_per_row1 < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row1);
}
if (1 > ((uint64_t)(a_workbuf.len))) {
return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length);
@@ -38395,9 +41280,13 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
return wuffs_base__make_status(wuffs_png__error__bad_filter);
}
v_s = v_curr_row;
v_x = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][2]));
if (self->private_impl.f_chunk_type_array[0] == 73) {
v_x = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][2]));
} else {
v_x = self->private_impl.f_frame_rect_x0;
}
if (self->private_impl.f_depth == 8) {
while (v_x < self->private_impl.f_width) {
while (v_x < self->private_impl.f_frame_rect_x1) {
v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel);
if (v_i <= ((uint64_t)(v_dst.len))) {
if (self->private_impl.f_color_type == 4) {
@@ -38409,6 +41298,44 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
v_s = wuffs_base__slice_u8__subslice_i(v_s, 2);
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(v_bits_unpacked, 4));
}
} else if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) != 0) {
if (self->private_impl.f_color_type == 0) {
if (1 <= ((uint64_t)(v_s.len))) {
v_bits_unpacked[0] = v_s.ptr[0];
v_bits_unpacked[1] = v_s.ptr[0];
v_bits_unpacked[2] = v_s.ptr[0];
v_bits_unpacked[3] = 255;
v_s = wuffs_base__slice_u8__subslice_i(v_s, 1);
if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) == ((((uint32_t)(v_bits_unpacked[0])) << 0) |
(((uint32_t)(v_bits_unpacked[1])) << 8) |
(((uint32_t)(v_bits_unpacked[2])) << 16) |
(((uint32_t)(v_bits_unpacked[3])) << 24))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
}
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(v_bits_unpacked, 4));
}
} else {
if (3 <= ((uint64_t)(v_s.len))) {
v_bits_unpacked[0] = v_s.ptr[2];
v_bits_unpacked[1] = v_s.ptr[1];
v_bits_unpacked[2] = v_s.ptr[0];
v_bits_unpacked[3] = 255;
v_s = wuffs_base__slice_u8__subslice_i(v_s, 3);
if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) == ((((uint32_t)(v_bits_unpacked[0])) << 0) |
(((uint32_t)(v_bits_unpacked[1])) << 8) |
(((uint32_t)(v_bits_unpacked[2])) << 16) |
(((uint32_t)(v_bits_unpacked[3])) << 24))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
}
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(v_bits_unpacked, 4));
}
}
} else if (v_src_bytes_per_pixel <= ((uint64_t)(v_s.len))) {
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__slice_u8__subslice_j(v_s, v_src_bytes_per_pixel));
v_s = wuffs_base__slice_u8__subslice_i(v_s, v_src_bytes_per_pixel);
@@ -38423,7 +41350,7 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
}
v_shift = ((8 - self->private_impl.f_depth) & 7);
v_packs_remaining = 0;
while (v_x < self->private_impl.f_width) {
while (v_x < self->private_impl.f_frame_rect_x1) {
v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel);
if (v_i <= ((uint64_t)(v_dst.len))) {
if ((v_packs_remaining == 0) && (1 <= ((uint64_t)(v_s.len)))) {
@@ -38434,12 +41361,28 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
v_bits_unpacked[0] = ((uint8_t)((v_bits_packed >> v_shift) * v_multiplier));
v_bits_packed = ((uint8_t)(v_bits_packed << self->private_impl.f_depth));
v_packs_remaining = ((uint8_t)(v_packs_remaining - 1));
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(v_bits_unpacked, 1));
if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) != 0) {
v_bits_unpacked[1] = v_bits_unpacked[0];
v_bits_unpacked[2] = v_bits_unpacked[0];
v_bits_unpacked[3] = 255;
if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) == ((((uint32_t)(v_bits_unpacked[0])) << 0) |
(((uint32_t)(v_bits_unpacked[1])) << 8) |
(((uint32_t)(v_bits_unpacked[2])) << 16) |
(((uint32_t)(v_bits_unpacked[3])) << 24))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
}
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(v_bits_unpacked, 4));
} else {
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(v_bits_unpacked, 1));
}
}
v_x += (((uint32_t)(1)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]);
}
} else {
while (v_x < self->private_impl.f_width) {
while (v_x < self->private_impl.f_frame_rect_x1) {
v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel);
if (v_i <= ((uint64_t)(v_dst.len))) {
if (self->private_impl.f_color_type == 0) {
@@ -38450,7 +41393,26 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
v_bits_unpacked[3] = v_s.ptr[0];
v_bits_unpacked[4] = v_s.ptr[1];
v_bits_unpacked[5] = v_s.ptr[0];
v_bits_unpacked[6] = 255;
v_bits_unpacked[7] = 255;
v_s = wuffs_base__slice_u8__subslice_i(v_s, 2);
if (self->private_impl.f_remap_transparency == ((((uint64_t)(v_bits_unpacked[0])) << 0) |
(((uint64_t)(v_bits_unpacked[1])) << 8) |
(((uint64_t)(v_bits_unpacked[2])) << 16) |
(((uint64_t)(v_bits_unpacked[3])) << 24) |
(((uint64_t)(v_bits_unpacked[4])) << 32) |
(((uint64_t)(v_bits_unpacked[5])) << 40) |
(((uint64_t)(v_bits_unpacked[6])) << 48) |
(((uint64_t)(v_bits_unpacked[7])) << 56))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
v_bits_unpacked[4] = 0;
v_bits_unpacked[5] = 0;
v_bits_unpacked[6] = 0;
v_bits_unpacked[7] = 0;
}
}
} else if (self->private_impl.f_color_type == 2) {
if (6 <= ((uint64_t)(v_s.len))) {
@@ -38460,7 +41422,26 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
v_bits_unpacked[3] = v_s.ptr[2];
v_bits_unpacked[4] = v_s.ptr[1];
v_bits_unpacked[5] = v_s.ptr[0];
v_bits_unpacked[6] = 255;
v_bits_unpacked[7] = 255;
v_s = wuffs_base__slice_u8__subslice_i(v_s, 6);
if (self->private_impl.f_remap_transparency == ((((uint64_t)(v_bits_unpacked[0])) << 0) |
(((uint64_t)(v_bits_unpacked[1])) << 8) |
(((uint64_t)(v_bits_unpacked[2])) << 16) |
(((uint64_t)(v_bits_unpacked[3])) << 24) |
(((uint64_t)(v_bits_unpacked[4])) << 32) |
(((uint64_t)(v_bits_unpacked[5])) << 40) |
(((uint64_t)(v_bits_unpacked[6])) << 48) |
(((uint64_t)(v_bits_unpacked[7])) << 56))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
v_bits_unpacked[4] = 0;
v_bits_unpacked[5] = 0;
v_bits_unpacked[6] = 0;
v_bits_unpacked[7] = 0;
}
}
} else if (self->private_impl.f_color_type == 4) {
if (4 <= ((uint64_t)(v_s.len))) {
@@ -38988,7 +41969,7 @@ wuffs_wbmp__decoder__decode_frame(
if (self->private_impl.f_width > 0) {
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
while (v_dst_y < self->private_impl.f_height) {
v_dst = wuffs_base__table_u8__row(v_tab, v_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
v_dst_x = 0;
while (v_dst_x < self->private_impl.f_width) {
if ((v_dst_x & 7) == 0) {
@@ -38996,7 +41977,7 @@ wuffs_wbmp__decoder__decode_frame(
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
v_dst = wuffs_base__table_u8__row(v_tab, v_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
v_dst_x_in_bytes = (((uint64_t)(v_dst_x)) * v_dst_bytes_per_pixel);
if (v_dst_x_in_bytes <= ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_x_in_bytes);
@@ -39236,6 +42217,71 @@ namespace sync_io {
// --------
DynIOBuffer::DynIOBuffer(uint64_t max_incl)
: m_buf(wuffs_base__empty_io_buffer()), m_max_incl(max_incl) {}
DynIOBuffer::~DynIOBuffer() {
if (m_buf.data.ptr) {
free(m_buf.data.ptr);
}
}
void //
DynIOBuffer::drop() {
if (m_buf.data.ptr) {
free(m_buf.data.ptr);
}
m_buf = wuffs_base__empty_io_buffer();
}
DynIOBuffer::GrowResult //
DynIOBuffer::grow(uint64_t min_incl) {
uint64_t n = round_up(min_incl, m_max_incl);
if (n == 0) {
return ((min_incl == 0) && (m_max_incl == 0))
? DynIOBuffer::GrowResult::OK
: DynIOBuffer::GrowResult::FailedMaxInclExceeded;
} else if (n > m_buf.data.len) {
uint8_t* ptr = static_cast<uint8_t*>(realloc(m_buf.data.ptr, n));
if (!ptr) {
return DynIOBuffer::GrowResult::FailedOutOfMemory;
}
m_buf.data.ptr = ptr;
m_buf.data.len = n;
}
return DynIOBuffer::GrowResult::OK;
}
// round_up rounds min_incl up, returning the smallest value x satisfying
// (min_incl <= x) and (x <= max_incl) and some other constraints. It returns 0
// if there is no such x.
//
// When max_incl <= 4096, the other constraints are:
// - (x == max_incl)
//
// When max_incl > 4096, the other constraints are:
// - (x == max_incl) or (x is a power of 2)
// - (x >= 4096)
uint64_t //
DynIOBuffer::round_up(uint64_t min_incl, uint64_t max_incl) {
if (min_incl > max_incl) {
return 0;
}
uint64_t n = 4096;
if (n >= max_incl) {
return max_incl;
}
while (n < min_incl) {
if (n >= (max_incl / 2)) {
return max_incl;
}
n *= 2;
}
return n;
}
// --------
Input::~Input() {}
IOBuffer* //
@@ -39310,6 +42356,164 @@ MemoryInput::CopyIn(IOBuffer* dst) {
} // namespace sync_io
namespace private_impl {
struct ErrorMessages {
const char* max_incl_metadata_length_exceeded;
const char* out_of_memory;
const char* unexpected_end_of_file;
const char* unsupported_metadata;
const char* unsupported_negative_advance;
// If adding new "const char*" typed fields to this struct, either add them
// after existing fields or, if re-ordering fields, make sure that you update
// all of the "const private_impl::ErrorMessages FooBarErrorMessages" values
// in all of the sibling *.cc files.
static inline const char* resolve(const char* s) {
return s ? s : "wuffs_aux::private_impl: unknown error";
};
};
std::string //
AdvanceIOBufferTo(const ErrorMessages& error_messages,
sync_io::Input& input,
IOBuffer& io_buf,
uint64_t absolute_position) {
if (absolute_position < io_buf.reader_position()) {
return error_messages.resolve(error_messages.unsupported_negative_advance);
}
while (true) {
uint64_t relative_position = absolute_position - io_buf.reader_position();
if (relative_position <= io_buf.reader_length()) {
io_buf.meta.ri += (size_t)relative_position;
break;
} else if (io_buf.meta.closed) {
return error_messages.resolve(error_messages.unexpected_end_of_file);
}
io_buf.meta.ri = io_buf.meta.wi;
if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
return "";
}
std::string //
HandleMetadata(
const ErrorMessages& error_messages,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
sync_io::DynIOBuffer& raw,
wuffs_base__status (*tell_me_more_func)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*),
void* tell_me_more_receiver,
std::string (*handle_metadata_func)(void*,
const wuffs_base__more_information*,
wuffs_base__slice_u8),
void* handle_metadata_receiver) {
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
// Reset raw but keep its backing array (the raw.m_buf.data slice).
raw.m_buf.meta = wuffs_base__empty_io_buffer_meta();
while (true) {
minfo = wuffs_base__empty_more_information();
wuffs_base__status status = (*tell_me_more_func)(
tell_me_more_receiver, &raw.m_buf, &minfo, &io_buf);
switch (minfo.flavor) {
case 0:
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM:
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED:
break;
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH: {
wuffs_base__range_ie_u64 r = minfo.metadata_raw_passthrough__range();
if (r.is_empty()) {
break;
}
uint64_t num_to_copy = r.length();
if (num_to_copy > (raw.m_max_incl - raw.m_buf.meta.wi)) {
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
} else if (num_to_copy > (raw.m_buf.data.len - raw.m_buf.meta.wi)) {
switch (raw.grow(num_to_copy + raw.m_buf.meta.wi)) {
case sync_io::DynIOBuffer::GrowResult::OK:
break;
case sync_io::DynIOBuffer::GrowResult::FailedMaxInclExceeded:
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
case sync_io::DynIOBuffer::GrowResult::FailedOutOfMemory:
return error_messages.resolve(error_messages.out_of_memory);
}
}
if (io_buf.reader_position() > r.min_incl) {
return error_messages.resolve(error_messages.unsupported_metadata);
} else {
std::string error_message =
AdvanceIOBufferTo(error_messages, input, io_buf, r.min_incl);
if (!error_message.empty()) {
return error_message;
}
}
while (true) {
uint64_t n =
wuffs_base__u64__min(num_to_copy, io_buf.reader_length());
memcpy(raw.m_buf.writer_pointer(), io_buf.reader_pointer(), n);
raw.m_buf.meta.wi += n;
io_buf.meta.ri += n;
num_to_copy -= n;
if (num_to_copy == 0) {
break;
} else if (io_buf.meta.closed) {
return error_messages.resolve(
error_messages.unexpected_end_of_file);
} else if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
break;
}
default:
return error_messages.resolve(error_messages.unsupported_metadata);
}
if (status.repr == nullptr) {
break;
} else if (status.repr != wuffs_base__suspension__even_more_information) {
if (status.repr != wuffs_base__suspension__short_write) {
return status.message();
}
switch (raw.grow(wuffs_base__u64__sat_add(raw.m_buf.data.len, 1))) {
case sync_io::DynIOBuffer::GrowResult::OK:
break;
case sync_io::DynIOBuffer::GrowResult::FailedMaxInclExceeded:
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
case sync_io::DynIOBuffer::GrowResult::FailedOutOfMemory:
return error_messages.resolve(error_messages.out_of_memory);
}
}
}
return (*handle_metadata_func)(handle_metadata_receiver, &minfo,
raw.m_buf.reader_slice());
}
} // namespace private_impl
} // namespace wuffs_aux
#endif // !defined(WUFFS_CONFIG__MODULES) ||
@@ -39335,10 +42539,21 @@ DecodeCborCallbacks::Done(DecodeCborResult& result,
sync_io::Input& input,
IOBuffer& buffer) {}
DecodeCborArgQuirks::DecodeCborArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeCborArgQuirks::DecodeCborArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeCborArgQuirks //
DecodeCborArgQuirks::DefaultValue() {
return DecodeCborArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeCborResult //
DecodeCbor(DecodeCborCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks) {
DecodeCborArgQuirks quirks) {
// Prepare the wuffs_base__io_buffer and the resultant error_message.
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
@@ -39361,8 +42576,8 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
ret_error_message = "wuffs_aux::DecodeCbor: out of memory";
goto done;
}
for (size_t i = 0; i < quirks.len; i++) {
dec->set_quirk_enabled(quirks.ptr[i], true);
for (size_t i = 0; i < quirks.repr.len; i++) {
dec->set_quirk_enabled(quirks.repr.ptr[i], true);
}
// Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.
@@ -39747,6 +42962,12 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_base__image_decoder::unique_ptr(nullptr, &free);
}
std::string //
DecodeImageCallbacks::HandleMetadata(const wuffs_base__more_information& minfo,
wuffs_base__slice_u8 raw) {
return "";
}
wuffs_base__pixel_format //
DecodeImageCallbacks::SelectPixfmt(
const wuffs_base__image_config& image_config) {
@@ -39811,12 +43032,16 @@ const char DecodeImage_BufferIsTooShort[] = //
"wuffs_aux::DecodeImage: buffer is too short";
const char DecodeImage_MaxInclDimensionExceeded[] = //
"wuffs_aux::DecodeImage: max_incl_dimension exceeded";
const char DecodeImage_MaxInclMetadataLengthExceeded[] = //
"wuffs_aux::DecodeImage: max_incl_metadata_length exceeded";
const char DecodeImage_OutOfMemory[] = //
"wuffs_aux::DecodeImage: out of memory";
const char DecodeImage_UnexpectedEndOfFile[] = //
"wuffs_aux::DecodeImage: unexpected end of file";
const char DecodeImage_UnsupportedImageFormat[] = //
"wuffs_aux::DecodeImage: unsupported image format";
const char DecodeImage_UnsupportedMetadata[] = //
"wuffs_aux::DecodeImage: unsupported metadata";
const char DecodeImage_UnsupportedPixelBlend[] = //
"wuffs_aux::DecodeImage: unsupported pixel blend";
const char DecodeImage_UnsupportedPixelConfiguration[] = //
@@ -39824,38 +43049,105 @@ const char DecodeImage_UnsupportedPixelConfiguration[] = //
const char DecodeImage_UnsupportedPixelFormat[] = //
"wuffs_aux::DecodeImage: unsupported pixel format";
DecodeImageArgQuirks::DecodeImageArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeImageArgQuirks::DecodeImageArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeImageArgQuirks //
DecodeImageArgQuirks::DefaultValue() {
return DecodeImageArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeImageArgFlags::DecodeImageArgFlags(uint64_t repr0) : repr(repr0) {}
DecodeImageArgFlags //
DecodeImageArgFlags::DefaultValue() {
return DecodeImageArgFlags(0);
}
DecodeImageArgPixelBlend::DecodeImageArgPixelBlend(
wuffs_base__pixel_blend repr0)
: repr(repr0) {}
DecodeImageArgPixelBlend //
DecodeImageArgPixelBlend::DefaultValue() {
return DecodeImageArgPixelBlend(WUFFS_BASE__PIXEL_BLEND__SRC);
}
DecodeImageArgBackgroundColor::DecodeImageArgBackgroundColor(
wuffs_base__color_u32_argb_premul repr0)
: repr(repr0) {}
DecodeImageArgBackgroundColor //
DecodeImageArgBackgroundColor::DefaultValue() {
return DecodeImageArgBackgroundColor(1);
}
DecodeImageArgMaxInclDimension::DecodeImageArgMaxInclDimension(uint32_t repr0)
: repr(repr0) {}
DecodeImageArgMaxInclDimension //
DecodeImageArgMaxInclDimension::DefaultValue() {
return DecodeImageArgMaxInclDimension(1048575);
}
DecodeImageArgMaxInclMetadataLength::DecodeImageArgMaxInclMetadataLength(
uint64_t repr0)
: repr(repr0) {}
DecodeImageArgMaxInclMetadataLength //
DecodeImageArgMaxInclMetadataLength::DefaultValue() {
return DecodeImageArgMaxInclMetadataLength(16777215);
}
// --------
namespace {
const private_impl::ErrorMessages DecodeImageErrorMessages = {
DecodeImage_MaxInclMetadataLengthExceeded, //
DecodeImage_OutOfMemory, //
DecodeImage_UnexpectedEndOfFile, //
DecodeImage_UnsupportedMetadata, //
DecodeImage_UnsupportedImageFormat, //
};
std::string //
DecodeImageAdvanceIOBuf(sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
bool compactable,
uint64_t min_excl_pos,
uint64_t pos) {
if ((pos <= min_excl_pos) || (pos < io_buf.reader_position())) {
// Redirects must go forward.
return DecodeImage_UnsupportedImageFormat;
}
while (true) {
uint64_t relative_pos = pos - io_buf.reader_position();
if (relative_pos <= io_buf.reader_length()) {
io_buf.meta.ri += (size_t)relative_pos;
break;
} else if (io_buf.meta.closed) {
return DecodeImage_UnexpectedEndOfFile;
}
io_buf.meta.ri = io_buf.meta.wi;
if (compactable) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
return "";
DecodeImageAdvanceIOBufferTo(sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
uint64_t absolute_position) {
return private_impl::AdvanceIOBufferTo(DecodeImageErrorMessages, input,
io_buf, absolute_position);
}
wuffs_base__status //
DIHM0(void* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_base__image_decoder__tell_me_more(
static_cast<wuffs_base__image_decoder*>(self), a_dst, a_minfo, a_src);
}
std::string //
DIHM1(void* self,
const wuffs_base__more_information* minfo,
wuffs_base__slice_u8 raw) {
return static_cast<DecodeImageCallbacks*>(self)->HandleMetadata(*minfo, raw);
}
std::string //
DecodeImageHandleMetadata(wuffs_base__image_decoder::unique_ptr& image_decoder,
DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
sync_io::DynIOBuffer& raw_metadata_buf) {
return private_impl::HandleMetadata(DecodeImageErrorMessages, input, io_buf,
raw_metadata_buf, DIHM0,
static_cast<void*>(image_decoder.get()),
DIHM1, static_cast<void*>(&callbacks));
}
DecodeImageResult //
@@ -39863,9 +43155,12 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
wuffs_base__slice_u32 quirks,
uint64_t flags,
wuffs_base__pixel_blend pixel_blend,
wuffs_base__color_u32_argb_premul background_color,
uint32_t max_incl_dimension) {
uint32_t max_incl_dimension,
uint64_t max_incl_metadata_length) {
// Check args.
switch (pixel_blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -39876,6 +43171,7 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
}
wuffs_base__image_config image_config = wuffs_base__null_image_config();
sync_io::DynIOBuffer raw_metadata_buf(max_incl_metadata_length);
uint64_t start_pos = io_buf.reader_position();
bool redirected = false;
int32_t fourcc = 0;
@@ -39910,8 +43206,12 @@ redirect:
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
uint64_t pos = minfo.io_redirect__range().min_incl;
std::string error_message = DecodeImageAdvanceIOBuf(
input, io_buf, !input.BringsItsOwnIOBuffer(), start_pos, pos);
if (pos <= start_pos) {
// Redirects must go forward.
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
std::string error_message =
DecodeImageAdvanceIOBufferTo(input, io_buf, pos);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -39930,6 +43230,36 @@ redirect:
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
// Apply quirks.
for (size_t i = 0; i < quirks.len; i++) {
image_decoder->set_quirk_enabled(quirks.ptr[i], true);
}
// Apply flags.
if (flags != 0) {
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_ICCP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_KVP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_SRGB) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_XMP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__XMP, true);
}
}
// Decode the image config.
while (true) {
wuffs_base__status id_dic_status =
@@ -39942,6 +43272,12 @@ redirect:
}
redirected = true;
goto redirect;
} else if (id_dic_status.repr == wuffs_base__note__metadata_reported) {
std::string error_message = DecodeImageHandleMetadata(
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
} else if (id_dic_status.repr != wuffs_base__suspension__short_read) {
return DecodeImageResult(id_dic_status.message());
} else if (io_buf.meta.closed) {
@@ -39954,6 +43290,7 @@ redirect:
}
}
} while (false);
raw_metadata_buf.drop();
// Select the pixel format.
uint32_t w = image_config.pixcfg.width();
@@ -40064,9 +43401,12 @@ redirect:
DecodeImageResult //
DecodeImage(DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__pixel_blend pixel_blend,
wuffs_base__color_u32_argb_premul background_color,
uint32_t max_incl_dimension) {
DecodeImageArgQuirks quirks,
DecodeImageArgFlags flags,
DecodeImageArgPixelBlend pixel_blend,
DecodeImageArgBackgroundColor background_color,
DecodeImageArgMaxInclDimension max_incl_dimension,
DecodeImageArgMaxInclMetadataLength max_incl_metadata_length) {
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
std::unique_ptr<uint8_t[]> fallback_io_array(nullptr);
@@ -40079,8 +43419,9 @@ DecodeImage(DecodeImageCallbacks& callbacks,
wuffs_base__image_decoder::unique_ptr image_decoder(nullptr, &free);
DecodeImageResult result =
DecodeImage0(image_decoder, callbacks, input, *io_buf, pixel_blend,
background_color, max_incl_dimension);
DecodeImage0(image_decoder, callbacks, input, *io_buf, quirks.repr,
flags.repr, pixel_blend.repr, background_color.repr,
max_incl_dimension.repr, max_incl_metadata_length.repr);
callbacks.Done(result, input, *io_buf, std::move(image_decoder));
return result;
}
@@ -40115,6 +43456,25 @@ const char DecodeJson_BadJsonPointer[] = //
const char DecodeJson_NoMatch[] = //
"wuffs_aux::DecodeJson: no match";
DecodeJsonArgQuirks::DecodeJsonArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeJsonArgQuirks::DecodeJsonArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeJsonArgQuirks //
DecodeJsonArgQuirks::DefaultValue() {
return DecodeJsonArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeJsonArgJsonPointer::DecodeJsonArgJsonPointer(std::string repr0)
: repr(repr0) {}
DecodeJsonArgJsonPointer //
DecodeJsonArgJsonPointer::DefaultValue() {
return DecodeJsonArgJsonPointer(std::string());
}
// --------
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
@@ -40420,8 +43780,8 @@ done:
DecodeJsonResult //
DecodeJson(DecodeJsonCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks,
std::string json_pointer) {
DecodeJsonArgQuirks quirks,
DecodeJsonArgJsonPointer json_pointer) {
// Prepare the wuffs_base__io_buffer and the resultant error_message.
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
@@ -40449,9 +43809,9 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
goto done;
}
bool allow_tilde_n_tilde_r_tilde_t = false;
for (size_t i = 0; i < quirks.len; i++) {
dec->set_quirk_enabled(quirks.ptr[i], true);
if (quirks.ptr[i] ==
for (size_t i = 0; i < quirks.repr.len; i++) {
dec->set_quirk_enabled(quirks.repr.ptr[i], true);
if (quirks.repr.ptr[i] ==
WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {
allow_tilde_n_tilde_r_tilde_t = true;
}
@@ -40470,13 +43830,13 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
std::string str;
// Walk the (optional) JSON Pointer.
for (size_t i = 0; i < json_pointer.size();) {
if (json_pointer[i] != '/') {
for (size_t i = 0; i < json_pointer.repr.size();) {
if (json_pointer.repr[i] != '/') {
ret_error_message = DecodeJson_BadJsonPointer;
goto done;
}
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
json_pointer.repr, i + 1, allow_tilde_n_tilde_r_tilde_t);
i = split.second;
if (i == 0) {
ret_error_message = DecodeJson_BadJsonPointer;
@@ -40637,7 +43997,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
// decode_tokens returns an ok status.
if (!ret_error_message.empty() ||
((depth == 0) && !json_pointer.empty())) {
((depth == 0) && !json_pointer.repr.empty())) {
goto done;
}
}
+4020 -660
View File
@@ -54,13 +54,14 @@
#include <stdlib.h>
#include <string.h>
// Note that Clang also defines __GNUC__.
#ifdef __cplusplus
#if (__cplusplus >= 201103L) || defined(_MSC_VER)
#include <memory>
#define WUFFS_BASE__HAVE_EQ_DELETE
#define WUFFS_BASE__HAVE_UNIQUE_PTR
#elif defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#elif defined(__GNUC__) || defined(__clang__)
#warning "Wuffs' C++ code expects -std=c++11 or later"
#endif
@@ -84,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
// 5a4dd303f0b2f3566173461b2243405d83fe5f14 committed on 2021-10-07.
// 4aa672af48fd5c11ab4c0b704a4ccf8d90eb5662 committed on 2022-01-08.
#define WUFFS_VERSION 0x000030000
#define WUFFS_VERSION_MAJOR 0
#define WUFFS_VERSION_MINOR 3
#define WUFFS_VERSION_PATCH 0
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.10"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3125
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20211007
#define WUFFS_VERSION_STRING "0.3.0-beta.10+3125.20211007"
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.13"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3245
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20220108
#define WUFFS_VERSION_STRING "0.3.0-beta.13+3245.20220108"
// ---------------- Configuration
@@ -330,8 +331,9 @@ wuffs_base__cpu_arch__have_x86_sse42() {
#endif
#endif
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__) || defined(__clang__)
#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))
#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
@@ -559,7 +561,20 @@ typedef struct wuffs_base__transform__output__struct {
// --------
// FourCC constants.
// FourCC constants. Four Character Codes are literally four ASCII characters
// (sometimes padded with ' ' spaces) that pack neatly into a signed or
// unsigned 32-bit integer. ASCII letters are conventionally upper case.
//
// They are often used to identify video codecs (e.g. "H265") and pixel formats
// (e.g. "YV12"). Wuffs uses them for that but also generally for naming
// various things: compression formats (e.g. "BZ2 "), image metadata (e.g.
// "EXIF"), file formats (e.g. "HTML"), etc.
//
// Wuffs' u32 values are big-endian ("JPEG" is 0x4A504547 not 0x4745504A) to
// preserve ordering: "JPEG" < "MP3 " and 0x4A504547 < 0x4D503320.
// Background Color.
#define WUFFS_BASE__FOURCC__BGCL 0x4247434C
// Bitmap.
#define WUFFS_BASE__FOURCC__BMP 0x424D5020
@@ -573,15 +588,24 @@ typedef struct wuffs_base__transform__output__struct {
// Concise Binary Object Representation.
#define WUFFS_BASE__FOURCC__CBOR 0x43424F52
// Primary Chromaticities and White Point.
#define WUFFS_BASE__FOURCC__CHRM 0x4348524D
// Cascading Style Sheets.
#define WUFFS_BASE__FOURCC__CSS 0x43535320
// Encapsulated PostScript.
#define WUFFS_BASE__FOURCC__EPS 0x45505320
// Exchangeable Image File Format.
#define WUFFS_BASE__FOURCC__EXIF 0x45584946
// Free Lossless Audio Codec.
#define WUFFS_BASE__FOURCC__FLAC 0x464C4143
// Gamma Correction.
#define WUFFS_BASE__FOURCC__GAMA 0x47414D41
// Graphics Interchange Format.
#define WUFFS_BASE__FOURCC__GIF 0x47494620
@@ -618,24 +642,42 @@ typedef struct wuffs_base__transform__output__struct {
// JSON With Commas and Comments.
#define WUFFS_BASE__FOURCC__JWCC 0x4A574343
// Key-Value Pair.
#define WUFFS_BASE__FOURCC__KVP 0x4B565020
// Key-Value Pair (Key).
#define WUFFS_BASE__FOURCC__KVPK 0x4B56504B
// Key-Value Pair (Value).
#define WUFFS_BASE__FOURCC__KVPV 0x4B565056
// Lempel–Ziv 4.
#define WUFFS_BASE__FOURCC__LZ4 0x4C5A3420
// Markdown.
#define WUFFS_BASE__FOURCC__MD 0x4D442020
// Modification Time.
#define WUFFS_BASE__FOURCC__MTIM 0x4D54494D
// MPEG-1 Audio Layer III.
#define WUFFS_BASE__FOURCC__MP3 0x4D503320
// Naive Image.
#define WUFFS_BASE__FOURCC__NIE 0x4E494520
// Offset (2-Dimensional).
#define WUFFS_BASE__FOURCC__OFS2 0x4F465332
// Open Type Format.
#define WUFFS_BASE__FOURCC__OTF 0x4F544620
// Portable Document Format.
#define WUFFS_BASE__FOURCC__PDF 0x50444620
// Physical Dimensions.
#define WUFFS_BASE__FOURCC__PHYD 0x50485944
// Portable Network Graphics.
#define WUFFS_BASE__FOURCC__PNG 0x504E4720
@@ -645,6 +687,9 @@ typedef struct wuffs_base__transform__output__struct {
// PostScript.
#define WUFFS_BASE__FOURCC__PS 0x50532020
// Quite OK Image.
#define WUFFS_BASE__FOURCC__QOI 0x514F4920
// Random Access Compression.
#define WUFFS_BASE__FOURCC__RAC 0x52414320
@@ -660,12 +705,18 @@ typedef struct wuffs_base__transform__output__struct {
// Snappy.
#define WUFFS_BASE__FOURCC__SNPY 0x534E5059
// Standard Red Green Blue (Rendering Intent).
#define WUFFS_BASE__FOURCC__SRGB 0x53524742
// Scalable Vector Graphics.
#define WUFFS_BASE__FOURCC__SVG 0x53564720
// Tape Archive.
#define WUFFS_BASE__FOURCC__TAR 0x54415220
// Text.
#define WUFFS_BASE__FOURCC__TEXT 0x54455854
// Tagged Image File Format.
#define WUFFS_BASE__FOURCC__TIFF 0x54494646
@@ -678,15 +729,12 @@ typedef struct wuffs_base__transform__output__struct {
// Wireless Bitmap.
#define WUFFS_BASE__FOURCC__WBMP 0x57424D50
// Web Picture.
#define WUFFS_BASE__FOURCC__WEBP 0x57454250
// Web Open Font Format.
#define WUFFS_BASE__FOURCC__WOFF 0x574F4646
// Web Picture (VP8).
#define WUFFS_BASE__FOURCC__WP8 0x57503820
// Web Picture (VP8 Lossless).
#define WUFFS_BASE__FOURCC__WP8L 0x5750384C
// Extensible Markup Language.
#define WUFFS_BASE__FOURCC__XML 0x584D4C20
@@ -964,7 +1012,9 @@ wuffs_base__multiply_u64(uint64_t x, uint64_t y) {
// --------
#if defined(__GNUC__) && (__SIZEOF_LONG__ == 8)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if (defined(__GNUC__) || defined(__clang__)) && (__SIZEOF_LONG__ == 8)
static inline uint32_t //
wuffs_base__count_leading_zeroes_u64(uint64_t u) {
@@ -1008,7 +1058,7 @@ wuffs_base__count_leading_zeroes_u64(uint64_t u) {
return n;
}
#endif // defined(__GNUC__) && (__SIZEOF_LONG__ == 8)
#endif // (defined(__GNUC__) || defined(__clang__)) && (__SIZEOF_LONG__ == 8)
// --------
@@ -1572,6 +1622,25 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__table_u8__subtable_ij returns t[ix:jx, iy:jy].
//
// It returns an empty table if i or j is out of bounds.
static inline wuffs_base__table_u8 //
wuffs_base__table_u8__subtable_ij(wuffs_base__table_u8 t,
uint64_t ix,
uint64_t iy,
uint64_t jx,
uint64_t jy) {
if ((ix <= jx) && (jx <= SIZE_MAX) && (jx <= t.width) && //
(iy <= jy) && (jy <= SIZE_MAX) && (jy <= t.height)) {
return wuffs_base__make_table_u8(t.ptr + ix + (iy * t.stride), //
((size_t)(jx - ix)), //
((size_t)(jy - iy)), //
t.stride); //
}
return wuffs_base__make_table_u8(NULL, 0, 0, 0);
}
// wuffs_base__table__flattened_length returns the number of elements covered
// by the 1-dimensional span that backs a 2-dimensional table. This counts the
// elements inside the table and, when width != stride, the elements outside
@@ -2454,14 +2523,24 @@ typedef struct wuffs_base__more_information__struct {
inline wuffs_base__range_ie_u64 io_redirect__range() const;
inline uint64_t io_seek__position() const;
inline uint32_t metadata__fourcc() const;
// Deprecated: use metadata_raw_passthrough__range.
inline wuffs_base__range_ie_u64 metadata__range() const;
inline wuffs_base__range_ie_u64 metadata_raw_passthrough__range() const;
inline int32_t metadata_parsed__chrm(uint32_t component) const;
inline uint32_t metadata_parsed__gama() const;
inline uint32_t metadata_parsed__srgb() const;
#endif // __cplusplus
} wuffs_base__more_information;
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_REDIRECT 1
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_SEEK 2
// Deprecated: use
// WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH.
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA 3
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH 3
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM 4
#define WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED 5
static inline wuffs_base__more_information //
wuffs_base__empty_more_information() {
@@ -2518,6 +2597,8 @@ wuffs_base__more_information__metadata__fourcc(
return m->w;
}
// Deprecated: use
// wuffs_base__more_information__metadata_raw_passthrough__range.
static inline wuffs_base__range_ie_u64 //
wuffs_base__more_information__metadata__range(
const wuffs_base__more_information* m) {
@@ -2527,6 +2608,103 @@ wuffs_base__more_information__metadata__range(
return ret;
}
static inline wuffs_base__range_ie_u64 //
wuffs_base__more_information__metadata_raw_passthrough__range(
const wuffs_base__more_information* m) {
wuffs_base__range_ie_u64 ret;
ret.min_incl = m->y;
ret.max_excl = m->z;
return ret;
}
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__WHITE_X 0
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__WHITE_Y 1
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__RED_X 2
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__RED_Y 3
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__GREEN_X 4
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__GREEN_Y 5
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__BLUE_X 6
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CHRM__BLUE_Y 7
// wuffs_base__more_information__metadata_parsed__chrm returns chromaticity
// values (scaled by 100000) like the PNG "cHRM" chunk. For example, the sRGB
// color space corresponds to:
// - ETC__CHRM__WHITE_X 31270
// - ETC__CHRM__WHITE_Y 32900
// - ETC__CHRM__RED_X 64000
// - ETC__CHRM__RED_Y 33000
// - ETC__CHRM__GREEN_X 30000
// - ETC__CHRM__GREEN_Y 60000
// - ETC__CHRM__BLUE_X 15000
// - ETC__CHRM__BLUE_Y 6000
//
// See
// https://ciechanow.ski/color-spaces/#chromaticity-and-white-point-coordinates
static inline int32_t //
wuffs_base__more_information__metadata_parsed__chrm(
const wuffs_base__more_information* m,
uint32_t component) {
// After the flavor and the w field (holding a FourCC), a
// wuffs_base__more_information holds 24 bytes of data in three uint64_t
// typed fields (x, y and z). We pack the eight chromaticity values (wx, wy,
// rx, ..., by), basically int24_t values, into 24 bytes like this:
// - LSB MSB
// - x: wx wx wx wy wy wy rx rx
// - y: rx ry ry ry gx gx gx gy
// - z: gy gy bx bx bx by by by
uint32_t u = 0;
switch (component & 7) {
case 0:
u = ((uint32_t)(m->x >> 0));
break;
case 1:
u = ((uint32_t)(m->x >> 24));
break;
case 2:
u = ((uint32_t)((m->x >> 48) | (m->y << 16)));
break;
case 3:
u = ((uint32_t)(m->y >> 8));
break;
case 4:
u = ((uint32_t)(m->y >> 32));
break;
case 5:
u = ((uint32_t)((m->y >> 56) | (m->z << 8)));
break;
case 6:
u = ((uint32_t)(m->z >> 16));
break;
case 7:
u = ((uint32_t)(m->z >> 40));
break;
}
// The left-right shifts sign-extend from 24-bit to 32-bit integers.
return ((int32_t)(u << 8)) >> 8;
}
// wuffs_base__more_information__metadata_parsed__gama returns inverse gamma
// correction values (scaled by 100000) like the PNG "gAMA" chunk. For example,
// for gamma = 2.2, this returns 45455 (approximating 100000 / 2.2).
static inline uint32_t //
wuffs_base__more_information__metadata_parsed__gama(
const wuffs_base__more_information* m) {
return ((uint32_t)(m->x));
}
#define WUFFS_BASE__SRGB_RENDERING_INTENT__PERCEPTUAL 0
#define WUFFS_BASE__SRGB_RENDERING_INTENT__RELATIVE_COLORIMETRIC 1
#define WUFFS_BASE__SRGB_RENDERING_INTENT__SATURATION 2
#define WUFFS_BASE__SRGB_RENDERING_INTENT__ABSOLUTE_COLORIMETRIC 3
// wuffs_base__more_information__metadata_parsed__srgb returns the sRGB
// rendering intent like the PNG "sRGB" chunk.
static inline uint32_t //
wuffs_base__more_information__metadata_parsed__srgb(
const wuffs_base__more_information* m) {
return m->x & 3;
}
#ifdef __cplusplus
inline void //
@@ -2564,6 +2742,26 @@ wuffs_base__more_information::metadata__range() const {
return wuffs_base__more_information__metadata__range(this);
}
inline wuffs_base__range_ie_u64 //
wuffs_base__more_information::metadata_raw_passthrough__range() const {
return wuffs_base__more_information__metadata_raw_passthrough__range(this);
}
inline int32_t //
wuffs_base__more_information::metadata_parsed__chrm(uint32_t component) const {
return wuffs_base__more_information__metadata_parsed__chrm(this, component);
}
inline uint32_t //
wuffs_base__more_information::metadata_parsed__gama() const {
return wuffs_base__more_information__metadata_parsed__gama(this);
}
inline uint32_t //
wuffs_base__more_information::metadata_parsed__srgb() const {
return wuffs_base__more_information__metadata_parsed__srgb(this);
}
#endif // __cplusplus
// ---------------- I/O
@@ -5070,9 +5268,9 @@ wuffs_base__pixel_swizzler::swizzle_interleaved_from_slice(
// wuffs_base__ieee_754_bit_representation__etc converts between a double
// precision numerical value and its IEEE 754 representations:
// - 16-bit: 1 sign bit, 5 exponent bits, 10 explicit significand bits.
// - 32-bit: 1 sign bit, 8 exponent bits, 23 explicit significand bits.
// - 64-bit: 1 sign bit, 11 exponent bits, 52 explicit significand bits.
// - 16-bit: 1 sign bit, 5 exponent bits, 10 explicit significand bits.
// - 32-bit: 1 sign bit, 8 exponent bits, 23 explicit significand bits.
// - 64-bit: 1 sign bit, 11 exponent bits, 52 explicit significand bits.
//
// For example, it converts between:
// - +1.0 and 0x3C00, 0x3F80_0000 or 0x3FF0_0000_0000_0000.
@@ -7164,7 +7362,6 @@ struct wuffs_deflate__decoder__struct {
uint32_t v_length;
uint32_t v_dist_minus_1;
uint32_t v_hlen;
uint32_t v_hdist;
uint64_t scratch;
} s_decode_huffman_slow[1];
} private_data;
@@ -7684,8 +7881,8 @@ struct wuffs_gif__decoder__struct {
bool f_previous_lzw_decode_ended_abruptly;
bool f_has_global_palette;
uint8_t f_interlace;
bool f_seen_num_loops;
uint32_t f_num_loops;
bool f_seen_num_animation_loops_value;
uint32_t f_num_animation_loops_value;
uint32_t f_background_color_u32_argb_premul;
uint32_t f_black_color_u32_argb_premul;
bool f_gc_has_transparent_index;
@@ -8734,6 +8931,8 @@ extern const char wuffs_zlib__error__incorrect_dictionary[];
// ---------------- Public Consts
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976
#define WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
// ---------------- Struct Declarations
@@ -8845,6 +9044,7 @@ struct wuffs_zlib__decoder__struct {
bool f_header_complete;
bool f_got_dictionary;
bool f_want_dictionary;
bool f_quirks[1];
bool f_ignore_checksum;
uint32_t f_dict_id_got;
uint32_t f_dict_id_want;
@@ -8963,17 +9163,22 @@ struct wuffs_zlib__decoder__struct {
// ---------------- Status Codes
extern const char wuffs_png__error__bad_animation_sequence_number[];
extern const char wuffs_png__error__bad_checksum[];
extern const char wuffs_png__error__bad_chunk[];
extern const char wuffs_png__error__bad_filter[];
extern const char wuffs_png__error__bad_header[];
extern const char wuffs_png__error__bad_text_chunk_not_latin_1[];
extern const char wuffs_png__error__missing_palette[];
extern const char wuffs_png__error__unsupported_png_compression_method[];
extern const char wuffs_png__error__unsupported_png_file[];
// ---------------- Public Consts
#define WUFFS_PNG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
#define WUFFS_PNG__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 8
// ---------------- Struct Declarations
typedef struct wuffs_png__decoder__struct wuffs_png__decoder;
@@ -9127,19 +9332,64 @@ struct wuffs_png__decoder__struct {
uint64_t f_overall_workbuf_length;
uint64_t f_pass_workbuf_length;
uint8_t f_call_sequence;
bool f_report_metadata_chrm;
bool f_report_metadata_exif;
bool f_report_metadata_gama;
bool f_report_metadata_iccp;
bool f_report_metadata_kvp;
bool f_report_metadata_srgb;
bool f_ignore_checksum;
uint8_t f_depth;
uint8_t f_color_type;
uint8_t f_filter_distance;
uint8_t f_interlace_pass;
bool f_seen_actl;
bool f_seen_chrm;
bool f_seen_fctl;
bool f_seen_exif;
bool f_seen_gama;
bool f_seen_iccp;
bool f_seen_idat;
bool f_seen_plte;
bool f_seen_srgb;
bool f_seen_trns;
uint32_t f_dst_pixfmt;
uint32_t f_src_pixfmt;
bool f_metadata_is_zlib_compressed;
bool f_zlib_is_dirty;
uint32_t f_chunk_type;
uint8_t f_chunk_type_array[4];
uint64_t f_chunk_length;
uint32_t f_chunk_length;
uint64_t f_remap_transparency;
uint32_t f_dst_pixfmt;
uint32_t f_src_pixfmt;
uint32_t f_num_animation_frames_value;
uint32_t f_num_animation_loops_value;
uint32_t f_num_decoded_frame_configs_value;
uint32_t f_num_decoded_frames_value;
uint32_t f_frame_rect_x0;
uint32_t f_frame_rect_y0;
uint32_t f_frame_rect_x1;
uint32_t f_frame_rect_y1;
uint32_t f_first_rect_x0;
uint32_t f_first_rect_y0;
uint32_t f_first_rect_x1;
uint32_t f_first_rect_y1;
uint64_t f_frame_config_io_position;
uint64_t f_first_config_io_position;
uint64_t f_frame_duration;
uint64_t f_first_duration;
uint8_t f_frame_disposal;
uint8_t f_first_disposal;
bool f_frame_overwrite_instead_of_blend;
bool f_first_overwrite_instead_of_blend;
uint32_t f_next_animation_seq_num;
uint32_t f_metadata_flavor;
uint32_t f_metadata_fourcc;
uint64_t f_metadata_x;
uint64_t f_metadata_y;
uint64_t f_metadata_z;
uint32_t f_ztxt_ri;
uint32_t f_ztxt_wi;
uint64_t f_ztxt_hist_pos;
wuffs_base__pixel_swizzler f_swizzler;
wuffs_base__empty_struct (*choosy_filter_1)(
@@ -9156,11 +9406,19 @@ struct wuffs_png__decoder__struct {
uint32_t p_decode_image_config[1];
uint32_t p_decode_ihdr[1];
uint32_t p_decode_other_chunk[1];
uint32_t p_decode_actl[1];
uint32_t p_decode_chrm[1];
uint32_t p_decode_fctl[1];
uint32_t p_decode_gama[1];
uint32_t p_decode_iccp[1];
uint32_t p_decode_plte[1];
uint32_t p_decode_srgb[1];
uint32_t p_decode_trns[1];
uint32_t p_decode_frame_config[1];
uint32_t p_skip_frame[1];
uint32_t p_decode_frame[1];
uint32_t p_decode_pass[1];
uint32_t p_tell_me_more[1];
wuffs_base__status (*choosy_filter_and_swizzle)(
wuffs_png__decoder* self,
wuffs_base__pixel_buffer* a_dst,
@@ -9183,19 +9441,47 @@ struct wuffs_png__decoder__struct {
struct {
uint64_t scratch;
} s_decode_other_chunk[1];
struct {
uint64_t scratch;
} s_decode_actl[1];
struct {
uint64_t scratch;
} s_decode_chrm[1];
struct {
uint32_t v_x0;
uint32_t v_x1;
uint32_t v_y1;
uint64_t scratch;
} s_decode_fctl[1];
struct {
uint64_t scratch;
} s_decode_gama[1];
struct {
uint32_t v_num_entries;
uint32_t v_i;
uint64_t scratch;
} s_decode_plte[1];
struct {
uint32_t v_num_entries;
uint32_t v_i;
uint32_t v_n;
uint64_t scratch;
} s_decode_trns[1];
struct {
uint32_t v_checksum_have;
uint64_t scratch;
} s_decode_frame_config[1];
struct {
uint64_t scratch;
} s_skip_frame[1];
struct {
uint64_t scratch;
} s_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];
} private_data;
#ifdef __cplusplus
@@ -9692,6 +9978,63 @@ namespace sync_io {
// --------
// DynIOBuffer is an IOBuffer that is backed by a dynamically sized byte array.
// It owns that backing array and will free it in its destructor.
//
// The array size can be explicitly extended (by calling the grow method) but,
// unlike a C++ std::vector, there is no implicit extension (e.g. by calling
// std::vector::insert) and its maximum size is capped by the max_incl
// constructor argument.
//
// It contains an IOBuffer-typed field whose reader side provides access to
// previously written bytes and whose writer side provides access to the
// allocated but not-yet-written-to slack space. For Go programmers, this slack
// space is roughly analogous to the s[len(s):cap(s)] space of a slice s.
class DynIOBuffer {
public:
enum GrowResult {
OK = 0,
FailedMaxInclExceeded = 1,
FailedOutOfMemory = 2,
};
// m_buf holds the dynamically sized byte array and its read/write indexes:
// - m_buf.meta.wi is roughly analogous to a Go slice's length.
// - m_buf.data.len is roughly analogous to a Go slice's capacity. It is
// also equal to the m_buf.data.ptr malloc/realloc size.
//
// Users should not modify the m_buf.data.ptr or m_buf.data.len fields (as
// they are conceptually private to this class), but they can modify the
// bytes referenced by that pointer-length pair (e.g. compactions).
IOBuffer m_buf;
// m_max_incl is an inclusive upper bound on the backing array size.
const uint64_t m_max_incl;
// Constructor and destructor.
explicit DynIOBuffer(uint64_t max_incl);
~DynIOBuffer();
// Drop frees the byte array and resets m_buf. The DynIOBuffer can still be
// used after a drop call. It just restarts from zero.
void drop();
// grow ensures that the byte array size is at least min_incl and at most
// max_incl. It returns FailedMaxInclExceeded if that would require
// allocating more than max_incl bytes, including the case where (min_incl >
// max_incl). It returns FailedOutOfMemory if memory allocation failed.
GrowResult grow(uint64_t min_incl);
private:
// Delete the copy and assign constructors.
DynIOBuffer(const DynIOBuffer&) = delete;
DynIOBuffer& operator=(const DynIOBuffer&) = delete;
static uint64_t round_up(uint64_t min_incl, uint64_t max_incl);
};
// --------
class Input {
public:
virtual ~Input();
@@ -9802,6 +10145,26 @@ class DecodeCborCallbacks {
Done(DecodeCborResult& result, sync_io::Input& input, IOBuffer& buffer);
};
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeCborArgQuirks wraps an optional argument to DecodeCbor.
struct DecodeCborArgQuirks {
explicit DecodeCborArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeCborArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeCborArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeCbor calls callbacks based on the CBOR-formatted data in input.
//
// On success, the returned error_message is empty and cursor_position counts
@@ -9811,7 +10174,7 @@ class DecodeCborCallbacks {
DecodeCborResult //
DecodeCbor(DecodeCborCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32());
DecodeCborArgQuirks quirks = DecodeCborArgQuirks::DefaultValue());
} // namespace wuffs_aux
@@ -9833,10 +10196,11 @@ struct DecodeImageResult {
// DecodeImageCallbacks are the callbacks given to DecodeImage. They are always
// called in this order:
// 1. SelectDecoder
// 2. SelectPixfmt
// 3. AllocPixbuf
// 4. AllocWorkbuf
// 5. Done
// 2. HandleMetadata
// 3. SelectPixfmt
// 4. AllocPixbuf
// 5. AllocWorkbuf
// 6. Done
//
// It may return early - the third callback might not be invoked if the second
// one fails - but the final callback (Done) is always invoked.
@@ -9893,6 +10257,22 @@ class DecodeImageCallbacks {
virtual wuffs_base__image_decoder::unique_ptr //
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED
// If it is ETC__METADATA_RAW_ETC then raw contains the metadata bytes. Those
// bytes should not be retained beyond the the HandleMetadata call.
//
// minfo.metadata__fourcc() will typically match one of the
// DecodeImageArgFlags bits. For example, if (REPORT_METADATA_CHRM |
// REPORT_METADATA_GAMA) was passed to DecodeImage then the metadata FourCC
// will be either WUFFS_BASE__FOURCC__CHRM or WUFFS_BASE__FOURCC__GAMA.
//
// It returns an error message, or an empty string on success.
virtual std::string //
HandleMetadata(const wuffs_base__more_information& minfo,
wuffs_base__slice_u8 raw);
// SelectPixfmt returns the destination pixel format for AllocPixbuf. It
// should return wuffs_base__make_pixel_format(etc) called with one of:
// - WUFFS_BASE__PIXEL_FORMAT__BGR_565
@@ -9959,13 +10339,116 @@ class DecodeImageCallbacks {
extern const char DecodeImage_BufferIsTooShort[];
extern const char DecodeImage_MaxInclDimensionExceeded[];
extern const char DecodeImage_MaxInclMetadataLengthExceeded[];
extern const char DecodeImage_OutOfMemory[];
extern const char DecodeImage_UnexpectedEndOfFile[];
extern const char DecodeImage_UnsupportedImageFormat[];
extern const char DecodeImage_UnsupportedMetadata[];
extern const char DecodeImage_UnsupportedPixelBlend[];
extern const char DecodeImage_UnsupportedPixelConfiguration[];
extern const char DecodeImage_UnsupportedPixelFormat[];
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeImageArgQuirks wraps an optional argument to DecodeImage.
struct DecodeImageArgQuirks {
explicit DecodeImageArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeImageArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeImageArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeImageArgFlags wraps an optional argument to DecodeImage.
struct DecodeImageArgFlags {
explicit DecodeImageArgFlags(uint64_t repr0);
// DefaultValue returns 0.
static DecodeImageArgFlags DefaultValue();
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
// GAMA, ICCP, KVP, SRGB and XMP.
// Background Color.
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
// Primary Chromaticities and White Point.
static constexpr uint64_t REPORT_METADATA_CHRM = 0x0002;
// Exchangeable Image File Format.
static constexpr uint64_t REPORT_METADATA_EXIF = 0x0004;
// Gamma Correction.
static constexpr uint64_t REPORT_METADATA_GAMA = 0x0008;
// International Color Consortium Profile.
static constexpr uint64_t REPORT_METADATA_ICCP = 0x0010;
// Key-Value Pair.
//
// For PNG files, this includes iTXt, tEXt and zTXt chunks. In the
// HandleMetadata callback, the raw argument contains UTF-8 strings.
static constexpr uint64_t REPORT_METADATA_KVP = 0x0020;
// Modification Time.
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0040;
// Offset (2-Dimensional).
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0080;
// Physical Dimensions.
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0100;
// Standard Red Green Blue (Rendering Intent).
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0200;
// Extensible Metadata Platform.
static constexpr uint64_t REPORT_METADATA_XMP = 0x0400;
uint64_t repr;
};
// DecodeImageArgPixelBlend wraps an optional argument to DecodeImage.
struct DecodeImageArgPixelBlend {
explicit DecodeImageArgPixelBlend(wuffs_base__pixel_blend repr0);
// DefaultValue returns WUFFS_BASE__PIXEL_BLEND__SRC.
static DecodeImageArgPixelBlend DefaultValue();
wuffs_base__pixel_blend repr;
};
// DecodeImageArgBackgroundColor wraps an optional argument to DecodeImage.
struct DecodeImageArgBackgroundColor {
explicit DecodeImageArgBackgroundColor(
wuffs_base__color_u32_argb_premul repr0);
// DefaultValue returns 1, an invalid wuffs_base__color_u32_argb_premul.
static DecodeImageArgBackgroundColor DefaultValue();
wuffs_base__color_u32_argb_premul repr;
};
// DecodeImageArgMaxInclDimension wraps an optional argument to DecodeImage.
struct DecodeImageArgMaxInclDimension {
explicit DecodeImageArgMaxInclDimension(uint32_t repr0);
// DefaultValue returns 1048575 = 0x000F_FFFF, more than 1 million pixels.
static DecodeImageArgMaxInclDimension DefaultValue();
uint32_t repr;
};
// DecodeImageArgMaxInclMetadataLength wraps an optional argument to
// DecodeImage.
struct DecodeImageArgMaxInclMetadataLength {
explicit DecodeImageArgMaxInclMetadataLength(uint64_t repr0);
// DefaultValue returns 16777215 = 0x00FF_FFFF, one less than 16 MiB.
static DecodeImageArgMaxInclMetadataLength DefaultValue();
uint64_t repr;
};
// DecodeImage decodes the image data in input. A variety of image file formats
// can be decoded, depending on what callbacks.SelectDecoder returns.
//
@@ -10008,13 +10491,21 @@ extern const char DecodeImage_UnsupportedPixelFormat[];
// WUFFS_BASE__PIXEL_BLEND__SRC_OVER and the decoded image is not fully opaque.
//
// Decoding fails (with DecodeImage_MaxInclDimensionExceeded) if the image's
// width or height is greater than max_incl_dimension.
// width or height is greater than max_incl_dimension or if any opted-in (via
// flags bits) metadata is longer than max_incl_metadata_length.
DecodeImageResult //
DecodeImage(DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__pixel_blend pixel_blend = WUFFS_BASE__PIXEL_BLEND__SRC,
wuffs_base__color_u32_argb_premul background_color = 1, // Invalid.
uint32_t max_incl_dimension = 1048575); // 0x000F_FFFF
DecodeImageArgQuirks quirks = DecodeImageArgQuirks::DefaultValue(),
DecodeImageArgFlags flags = DecodeImageArgFlags::DefaultValue(),
DecodeImageArgPixelBlend pixel_blend =
DecodeImageArgPixelBlend::DefaultValue(),
DecodeImageArgBackgroundColor background_color =
DecodeImageArgBackgroundColor::DefaultValue(),
DecodeImageArgMaxInclDimension max_incl_dimension =
DecodeImageArgMaxInclDimension::DefaultValue(),
DecodeImageArgMaxInclMetadataLength max_incl_metadata_length =
DecodeImageArgMaxInclMetadataLength::DefaultValue());
} // namespace wuffs_aux
@@ -10075,6 +10566,36 @@ class DecodeJsonCallbacks {
extern const char DecodeJson_BadJsonPointer[];
extern const char DecodeJson_NoMatch[];
// The FooArgBar types add structure to Foo's optional arguments. They wrap
// inner representations for several reasons:
// - It provides a home for the DefaultValue static method, for Foo callers
// that want to override some but not all optional arguments.
// - It provides the "Bar" name at Foo call sites, which can help self-
// document Foo calls with many arguemnts.
// - It provides some type safety against accidentally transposing or omitting
// adjacent fundamentally-numeric-typed optional arguments.
// DecodeJsonArgQuirks wraps an optional argument to DecodeJson.
struct DecodeJsonArgQuirks {
explicit DecodeJsonArgQuirks(wuffs_base__slice_u32 repr0);
explicit DecodeJsonArgQuirks(uint32_t* ptr, size_t len);
// DefaultValue returns an empty slice.
static DecodeJsonArgQuirks DefaultValue();
wuffs_base__slice_u32 repr;
};
// DecodeJsonArgJsonPointer wraps an optional argument to DecodeJson.
struct DecodeJsonArgJsonPointer {
explicit DecodeJsonArgJsonPointer(std::string repr0);
// DefaultValue returns an empty string.
static DecodeJsonArgJsonPointer DefaultValue();
std::string repr;
};
// DecodeJson calls callbacks based on the JSON-formatted data in input.
//
// On success, the returned error_message is empty and cursor_position counts
@@ -10092,8 +10613,9 @@ extern const char DecodeJson_NoMatch[];
DecodeJsonResult //
DecodeJson(DecodeJsonCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks = wuffs_base__empty_slice_u32(),
std::string json_pointer = std::string());
DecodeJsonArgQuirks quirks = DecodeJsonArgQuirks::DefaultValue(),
DecodeJsonArgJsonPointer json_pointer =
DecodeJsonArgJsonPointer::DefaultValue());
} // namespace wuffs_aux
@@ -10143,8 +10665,9 @@ extern "C" {
goto suspend; \
case n:;
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
#if defined(__GNUC__) || defined(__clang__)
#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
#else
@@ -10302,7 +10825,7 @@ wuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,
// --------
static inline wuffs_base__slice_u8 //
wuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) {
wuffs_base__table_u8__row_u32(wuffs_base__table_u8 t, uint32_t y) {
if (y < t.height) {
return wuffs_base__make_slice_u8(t.ptr + (t.stride * y), t.width);
}
@@ -10518,7 +11041,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -10526,7 +11049,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
return 0;
}
uint8_t* p = *ptr_iop_w;
if ((size_t)(p - io1_w) < (size_t)(distance)) {
if ((size_t)(p - io0_w) < (size_t)(distance)) {
return 0;
}
uint8_t* q = p - distance;
@@ -10563,10 +11086,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
// The caller needs to prove that:
// - length <= (io2_w - *ptr_iop_w)
// - distance >= 1
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -10598,11 +11121,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
// The caller needs to prove that:
// - (length + 8) <= (io2_w - *ptr_iop_w)
// - distance == 1
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -10638,11 +11161,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
// The caller needs to prove that:
// - (length + 8) <= (io2_w - *ptr_iop_w)
// - distance >= 8
// - distance <= (*ptr_iop_w - io1_w)
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
uint8_t** ptr_iop_w,
uint8_t* io1_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
@@ -12370,14 +12893,14 @@ wuffs_base__ieee_754_bit_representation__from_f64_to_u32_truncate(double f) {
// padded with implicit zeroes.
//
// For example, if num_digits is 3 and digits is "\x07\x08\x09":
// - A decimal_point of -2 means ".00789"
// - A decimal_point of -1 means ".0789"
// - A decimal_point of +0 means ".789"
// - A decimal_point of +1 means "7.89"
// - A decimal_point of +2 means "78.9"
// - A decimal_point of +3 means "789."
// - A decimal_point of +4 means "7890."
// - A decimal_point of +5 means "78900."
// - A decimal_point of -2 means ".00789"
// - A decimal_point of -1 means ".0789"
// - A decimal_point of +0 means ".789"
// - A decimal_point of +1 means "7.89"
// - A decimal_point of +2 means "78.9"
// - A decimal_point of +3 means "789."
// - A decimal_point of +4 means "7890."
// - A decimal_point of +5 means "78900."
//
// As above, a decimal_point higher than +2047 means that the overall value is
// infinity, lower than -2047 means zero.
@@ -12722,10 +13245,10 @@ wuffs_base__private_implementation__high_prec_dec__lshift_num_new_digits(
// wuffs_base__private_implementation__high_prec_dec__rounded_integer returns
// the integral (non-fractional) part of h, provided that it is 18 or fewer
// decimal digits. For 19 or more digits, it returns UINT64_MAX. Note that:
// - (1 << 53) is 9007199254740992, which has 16 decimal digits.
// - (1 << 56) is 72057594037927936, which has 17 decimal digits.
// - (1 << 59) is 576460752303423488, which has 18 decimal digits.
// - (1 << 63) is 9223372036854775808, which has 19 decimal digits.
// - (1 << 53) is 9007199254740992, which has 16 decimal digits.
// - (1 << 56) is 72057594037927936, which has 17 decimal digits.
// - (1 << 59) is 576460752303423488, which has 18 decimal digits.
// - (1 << 63) is 9223372036854775808, which has 19 decimal digits.
// and that IEEE 754 double precision has 52 mantissa bits.
//
// That integral part is rounded-to-even: rounding 7.5 or 8.5 both give 8.
@@ -15058,19 +15581,23 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
//
// Keep it sorted by magic[1], then magic[0] descending and finally by
// magic[2:]. When multiple entries match, the longest one wins.
//
// The fourcc field might be negated, in which case there's further
// specialization (see § below).
static struct {
int32_t fourcc;
const char* magic;
} table[] = {
{0x57424D50, "\x01\x00\x00"}, // WBMP
{0x424D5020, "\x01\x42\x4D"}, // BMP
{0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF (see § below)
{0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{0x4A504547, "\x01\xFF\xD8"}, // JPEG
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
};
static const size_t table_len = sizeof(table) / sizeof(table[0]);
@@ -15111,19 +15638,33 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
return 0;
match:
// Some FourCC values (see § above) are further specialized.
if (fourcc == 0x52494646) { // 'RIFF'be
if (prefix.len < 16) {
return -1;
}
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
if (x == 0x57454250) { // 'WEBP'be
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
if (y == 0x56503820) { // 'VP8 'be
return 0x57503820; // 'WP8 'be
} else if (y == 0x5650384C) { // 'VP8L'be
return 0x5750384C; // 'WP8L'be
// Negative FourCC values (see § above) are further specialized.
if (fourcc < 0) {
fourcc = -fourcc;
if (fourcc == 0x52494646) { // 'RIFF'be
if (prefix.len < 12) {
return -1;
}
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
if (x == 0x57454250) { // 'WEBP'be
return 0x57454250; // 'WEBP'be
}
} else if (fourcc == 0x30302020) { // '00 'be
// Binary data starting with multiple 0x00 NUL bytes is quite common.
if (prefix.len < 4) {
return -1;
} else if ((prefix.ptr[2] != 0x00) &&
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
// Roughly speaking, this could be a non-degenerate (non-0-width and
// non-0-height) WBMP image.
return 0x57424D50; // 'WBMP'be
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
(prefix.ptr[3] == 0x00)) {
return 0x49434F20; // 'ICO 'be
}
return 0;
}
}
return fourcc;
@@ -15625,14 +16166,23 @@ static inline uint32_t //
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
uint32_t src_nonpremul) {
// Extract 16-bit color components.
//
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
// return src_nonpremul. This isn't just an optimization (skipping the rest
// of the function's computation). It also preserves the nonpremul
// distinction between e.g. transparent red and transparent blue that would
// otherwise be lost by converting from nonpremul to premul and back.
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
if (da == 0) {
return src_nonpremul;
}
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -15669,14 +16219,23 @@ static inline uint64_t //
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
uint64_t src_nonpremul) {
// Extract components.
//
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
// return src_nonpremul. This isn't just an optimization (skipping the rest
// of the function's computation). It also preserves the nonpremul
// distinction between e.g. transparent red and transparent blue that would
// otherwise be lost by converting from nonpremul to premul and back.
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
if (da == 0) {
return src_nonpremul;
}
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -15707,14 +16266,14 @@ static inline uint32_t //
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
uint32_t src_premul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -15751,14 +16310,14 @@ static inline uint64_t //
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
uint64_t src_premul) {
// Extract components.
uint64_t sa = 0xFFFF & (src_premul >> 48);
uint64_t sr = 0xFFFF & (src_premul >> 32);
uint64_t sg = 0xFFFF & (src_premul >> 16);
uint64_t sb = 0xFFFF & (src_premul >> 0);
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
uint64_t sa = 0xFFFF & (src_premul >> 48);
uint64_t sr = 0xFFFF & (src_premul >> 32);
uint64_t sg = 0xFFFF & (src_premul >> 16);
uint64_t sb = 0xFFFF & (src_premul >> 0);
// Convert dst from nonpremul to premul.
dr = (dr * da) / 0xFFFF;
@@ -15789,14 +16348,14 @@ static inline uint32_t //
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
uint32_t src_nonpremul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -15821,14 +16380,14 @@ static inline uint64_t //
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
uint64_t src_nonpremul) {
// Extract components.
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
uint64_t da = 0xFFFF & (dst_premul >> 48);
uint64_t dr = 0xFFFF & (dst_premul >> 32);
uint64_t dg = 0xFFFF & (dst_premul >> 16);
uint64_t db = 0xFFFF & (dst_premul >> 0);
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint64_t ia = 0xFFFF - sa;
@@ -15847,14 +16406,14 @@ static inline uint32_t //
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
uint32_t src_premul) {
// Extract 16-bit color components.
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -16914,13 +17473,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sr = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sb = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -16962,13 +17521,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -17037,13 +17596,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sr = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sb = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -17115,13 +17674,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sb = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sr = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -17190,13 +17749,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
uint32_t sa = 0x101 * ((uint32_t)s[3]);
uint32_t sb = 0x101 * ((uint32_t)s[2]);
uint32_t sg = 0x101 * ((uint32_t)s[1]);
uint32_t sr = 0x101 * ((uint32_t)s[0]);
uint32_t dr = 0x101 * ((uint32_t)d[2]);
uint32_t dg = 0x101 * ((uint32_t)d[1]);
uint32_t db = 0x101 * ((uint32_t)d[0]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
@@ -22538,7 +23097,7 @@ wuffs_bmp__decoder__swizzle_none(
goto label__outer__continue;
}
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
@@ -22623,7 +23182,7 @@ wuffs_bmp__decoder__swizzle_rle(
v_rle_state = self->private_impl.f_rle_state;
label__outer__continue:;
while (true) {
v_row = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_row = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_row.len))) {
v_row = wuffs_base__slice_u8__subslice_j(v_row, v_dst_bytes_per_row);
}
@@ -22783,7 +23342,7 @@ wuffs_bmp__decoder__swizzle_rle(
status = wuffs_base__make_status(wuffs_bmp__error__bad_rle_compression);
goto exit;
}
v_row = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_row = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_row.len))) {
v_row = wuffs_base__slice_u8__subslice_j(v_row, v_dst_bytes_per_row);
}
@@ -22815,7 +23374,7 @@ wuffs_bmp__decoder__swizzle_rle(
}
label__outer__break:;
while (self->private_impl.f_dst_y < self->private_impl.f_height) {
v_row = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_row = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_row.len))) {
v_row = wuffs_base__slice_u8__subslice_j(v_row, v_dst_bytes_per_row);
}
@@ -22945,7 +23504,7 @@ wuffs_bmp__decoder__swizzle_bitfields(
v_p0 += 1;
}
label__0__break:;
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
@@ -23027,7 +23586,7 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
goto label__loop__break;
}
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
@@ -26450,14 +27009,17 @@ wuffs_deflate__decoder__init_huff(
v_i += 1;
}
if (v_remaining != 0) {
if ((a_which == 1) &&
(v_counts[1] == 1) &&
(self->private_data.f_code_lengths[a_n_codes0] == 1) &&
((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
self->private_impl.f_n_huffs_bits[1] = 1;
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[0] | 1);
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
return wuffs_base__make_status(NULL);
if ((a_which == 1) && (v_counts[1] == 1) && ((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
v_i = 0;
while (v_i <= 29) {
if (self->private_data.f_code_lengths[(a_n_codes0 + v_i)] == 1) {
self->private_impl.f_n_huffs_bits[1] = 1;
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[v_i] | 1);
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
return wuffs_base__make_status(NULL);
}
v_i += 1;
}
}
return wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code_under_subscribed);
}
@@ -26795,9 +27357,8 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
goto exit;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
if (v_length == 0) {
goto label__loop__continue;
}
@@ -27061,9 +27622,8 @@ wuffs_deflate__decoder__decode_huffman_fast32(
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
goto exit;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
if (v_length == 0) {
goto label__loop__continue;
}
@@ -27274,9 +27834,8 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
goto exit;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
if (v_length == 0) {
goto label__loop__continue;
}
@@ -27397,7 +27956,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
v_length = self->private_data.s_decode_huffman_slow[0].v_length;
v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
v_hdist = self->private_data.s_decode_huffman_slow[0].v_hdist;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -27594,55 +28152,29 @@ wuffs_deflate__decoder__decode_huffman_slow(
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
}
label__inner__continue:;
while (true) {
if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) {
v_hdist = ((uint32_t)((((uint64_t)((v_dist_minus_1 + 1))) - ((uint64_t)(iop_a_dst - io0_a_dst)))));
if (v_length > v_hdist) {
v_length -= v_hdist;
if (v_hdist < v_length) {
v_hlen = v_hdist;
} else {
v_hlen = v_length;
v_length = 0;
}
v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295)));
if (self->private_impl.f_history_index < v_hdist) {
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
goto exit;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
while (true) {
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
goto label__4__break;
}
if (v_n_copied > 0) {
v_hlen -= v_n_copied;
v_hdist = (((uint32_t)(v_hdist + v_n_copied)) & 32767);
if (v_hdist == 0) {
goto label__4__break;
}
}
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
if (v_n_copied < v_hlen) {
v_length -= v_n_copied;
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
goto label__inner__continue;
}
label__4__break:;
if (v_hlen > 0) {
while (true) {
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
goto label__5__break;
}
v_hlen -= v_n_copied;
v_hdist += v_n_copied;
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
}
label__5__break:;
}
v_length -= v_hlen;
if (v_length == 0) {
goto label__loop__continue;
}
@@ -27650,14 +28182,12 @@ wuffs_deflate__decoder__decode_huffman_slow(
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_history(
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
if (v_length <= v_n_copied) {
v_length = 0;
goto label__6__break;
goto label__loop__continue;
}
v_length -= v_n_copied;
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
}
label__6__break:;
}
label__loop__break:;
self->private_impl.f_bits = v_bits;
@@ -27686,7 +28216,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
self->private_data.s_decode_huffman_slow[0].v_length = v_length;
self->private_data.s_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
self->private_data.s_decode_huffman_slow[0].v_hlen = v_hlen;
self->private_data.s_decode_huffman_slow[0].v_hdist = v_hdist;
goto exit;
exit:
@@ -28771,10 +29300,13 @@ wuffs_gif__decoder__num_animation_loops(
return 0;
}
if (self->private_impl.f_seen_num_loops) {
return self->private_impl.f_num_loops;
if (self->private_impl.f_seen_num_animation_loops_value) {
return self->private_impl.f_num_animation_loops_value;
}
return 1;
if (self->private_impl.f_num_decoded_frame_configs_value > 1) {
return 1;
}
return 0;
}
// -------- func gif.decoder.num_decoded_frame_configs
@@ -29919,11 +30451,11 @@ wuffs_gif__decoder__decode_ae(
*scratch |= ((uint64_t)(num_bits_4)) << 56;
}
}
self->private_impl.f_num_loops = t_4;
self->private_impl.f_num_animation_loops_value = t_4;
}
self->private_impl.f_seen_num_loops = true;
if ((0 < self->private_impl.f_num_loops) && (self->private_impl.f_num_loops <= 65535)) {
self->private_impl.f_num_loops += 1;
self->private_impl.f_seen_num_animation_loops_value = true;
if ((0 < self->private_impl.f_num_animation_loops_value) && (self->private_impl.f_num_animation_loops_value <= 65535)) {
self->private_impl.f_num_animation_loops_value += 1;
}
} else if (self->private_impl.f_ignore_metadata) {
} else if (v_is_iccp && self->private_impl.f_report_metadata_iccp) {
@@ -30405,7 +30937,8 @@ wuffs_gif__decoder__decode_id_part1(
goto ok;
}
if (self->private_impl.f_previous_lzw_decode_ended_abruptly) {
wuffs_base__ignore_status(wuffs_lzw__decoder__initialize(&self->private_data.f_lzw, sizeof (wuffs_lzw__decoder), WUFFS_VERSION, 0));
wuffs_base__ignore_status(wuffs_lzw__decoder__initialize(&self->private_data.f_lzw,
sizeof (wuffs_lzw__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
@@ -30611,6 +31144,30 @@ wuffs_gif__decoder__decode_id_part2(
goto label__outer__continue;
} else if (v_lzw_status.repr == wuffs_base__suspension__short_write) {
goto label__inner__continue;
} else if (self->private_impl.f_quirks[3] && (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) && (self->private_impl.f_interlace == 0)) {
if (v_need_block_size || (v_block_size > 0)) {
self->private_data.s_decode_id_part2[0].scratch = ((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (self->private_data.s_decode_id_part2[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_id_part2[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_id_part2[0].scratch;
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
}
goto label__outer__break;
}
status = v_lzw_status;
if (wuffs_base__status__is_error(&status)) {
@@ -30691,7 +31248,7 @@ wuffs_gif__decoder__copy_to_image_buffer(
}
return wuffs_base__make_status(wuffs_base__error__too_much_data);
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (self->private_impl.f_dst_y >= self->private_impl.f_height) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, 0);
} else if (v_width_in_bytes < ((uint64_t)(v_dst.len))) {
@@ -30717,12 +31274,12 @@ wuffs_gif__decoder__copy_to_image_buffer(
goto label__0__continue;
}
if ((self->private_impl.f_num_decoded_frames_value == 0) && ! self->private_impl.f_gc_has_transparent_index && (self->private_impl.f_interlace > 1)) {
v_replicate_src = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_replicate_src = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
v_replicate_y0 = wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1);
v_replicate_y1 = wuffs_base__u32__sat_add(self->private_impl.f_dst_y, ((uint32_t)(WUFFS_GIF__INTERLACE_COUNT[self->private_impl.f_interlace])));
v_replicate_y1 = wuffs_base__u32__min(v_replicate_y1, self->private_impl.f_frame_rect_y1);
while (v_replicate_y0 < v_replicate_y1) {
v_replicate_dst = wuffs_base__table_u8__row(v_tab, v_replicate_y0);
v_replicate_dst = wuffs_base__table_u8__row_u32(v_tab, v_replicate_y0);
wuffs_base__slice_u8__copy_from_slice(v_replicate_dst, v_replicate_src);
v_replicate_y0 += 1;
}
@@ -34130,7 +34687,7 @@ wuffs_nie__decoder__swizzle(
goto label__0__break;
}
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, self->private_impl.f_dst_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
@@ -34348,6 +34905,10 @@ const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect diction
// ---------------- Private Consts
#define WUFFS_ZLIB__QUIRKS_BASE 2113790976
#define WUFFS_ZLIB__QUIRKS_COUNT 1
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
@@ -34511,8 +35072,15 @@ wuffs_zlib__decoder__set_quirk_enabled(
return wuffs_base__make_empty_struct();
}
if (a_quirk == 1) {
if (self->private_impl.f_header_complete) {
self->private_impl.f_bad_call_sequence = true;
} else if (a_quirk == 1) {
self->private_impl.f_ignore_checksum = a_enabled;
} else if (a_quirk >= 2113790976) {
a_quirk -= 2113790976;
if (a_quirk < 1) {
self->private_impl.f_quirks[a_quirk] = a_enabled;
}
}
return wuffs_base__make_empty_struct();
}
@@ -34602,6 +35170,7 @@ wuffs_zlib__decoder__transform_io(
if (self->private_impl.f_bad_call_sequence) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
} else if (self->private_impl.f_quirks[0]) {
} else if ( ! self->private_impl.f_want_dictionary) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
@@ -34709,7 +35278,7 @@ wuffs_zlib__decoder__transform_io(
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum) {
if ( ! self->private_impl.f_ignore_checksum && ! self->private_impl.f_quirks[0]) {
v_checksum_got = wuffs_adler32__hasher__update_u32(&self->private_data.f_checksum, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst));
}
if (wuffs_base__status__is_ok(&v_status)) {
@@ -34719,38 +35288,40 @@ wuffs_zlib__decoder__transform_io(
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
}
label__0__break:;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
if ( ! self->private_impl.f_quirks[0]) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_transform_io[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
v_checksum_want = t_3;
}
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
goto exit;
}
v_checksum_want = t_3;
}
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
goto exit;
}
ok:
@@ -34785,17 +35356,25 @@ wuffs_zlib__decoder__transform_io(
// ---------------- Status Codes Implementations
const char wuffs_png__error__bad_animation_sequence_number[] = "#png: bad animation sequence number";
const char wuffs_png__error__bad_checksum[] = "#png: bad checksum";
const char wuffs_png__error__bad_chunk[] = "#png: bad chunk";
const char wuffs_png__error__bad_filter[] = "#png: bad filter";
const char wuffs_png__error__bad_header[] = "#png: bad header";
const char wuffs_png__error__bad_text_chunk_not_latin_1[] = "#png: bad text chunk (not Latin-1)";
const char wuffs_png__error__missing_palette[] = "#png: missing palette";
const char wuffs_png__error__unsupported_png_compression_method[] = "#png: unsupported PNG compression method";
const char wuffs_png__error__unsupported_png_file[] = "#png: unsupported PNG file";
const char wuffs_png__error__internal_error_inconsistent_i_o[] = "#png: internal error: inconsistent I/O";
const char wuffs_png__error__internal_error_inconsistent_chunk_type[] = "#png: internal error: inconsistent chunk type";
const char wuffs_png__error__internal_error_inconsistent_frame_bounds[] = "#png: internal error: inconsistent frame bounds";
const char wuffs_png__error__internal_error_inconsistent_workbuf_length[] = "#png: internal error: inconsistent workbuf length";
const char wuffs_png__error__internal_error_zlib_decoder_did_not_exhaust_its_input[] = "#png: internal error: zlib decoder did not exhaust its input";
// ---------------- Private Consts
#define WUFFS_PNG__ANCILLARY_BIT 32
static const uint8_t
WUFFS_PNG__INTERLACING[8][6] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
@@ -34832,6 +35411,42 @@ WUFFS_PNG__NUM_CHANNELS[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
1, 0, 3, 1, 2, 0, 4, 0,
};
static const uint16_t
WUFFS_PNG__LATIN_1[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 41410, 41666, 41922, 42178, 42434, 42690, 42946,
43202, 43458, 43714, 43970, 44226, 44482, 44738, 44994,
45250, 45506, 45762, 46018, 46274, 46530, 46786, 47042,
47298, 47554, 47810, 48066, 48322, 48578, 48834, 49090,
32963, 33219, 33475, 33731, 33987, 34243, 34499, 34755,
35011, 35267, 35523, 35779, 36035, 36291, 36547, 36803,
37059, 37315, 37571, 37827, 38083, 38339, 38595, 38851,
39107, 39363, 39619, 39875, 40131, 40387, 40643, 40899,
41155, 41411, 41667, 41923, 42179, 42435, 42691, 42947,
43203, 43459, 43715, 43971, 44227, 44483, 44739, 44995,
45251, 45507, 45763, 46019, 46275, 46531, 46787, 47043,
47299, 47555, 47811, 48067, 48323, 48579, 48835, 49091,
};
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
@@ -34995,16 +35610,56 @@ wuffs_png__decoder__decode_other_chunk(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_actl(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_chrm(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_exif(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_fctl(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_gama(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_iccp(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_plte(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_srgb(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_png__decoder__decode_trns(
wuffs_png__decoder* self,
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__decode_pass(
wuffs_png__decoder* self,
@@ -36629,172 +37284,210 @@ wuffs_png__decoder__decode_image_config(
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0) {
if (self->private_impl.f_call_sequence == 2) {
if (self->private_impl.f_metadata_fourcc != 0) {
self->private_impl.f_call_sequence = 1;
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
} else if (self->private_impl.f_call_sequence != 0) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
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;
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;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
if (num_bits_0 == 56) {
t_0 = ((uint64_t)(*scratch));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_magic = t_0;
}
if (v_magic != 727905341920923785) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
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;
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;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
if (num_bits_1 == 56) {
t_1 = ((uint64_t)(*scratch));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
v_magic = t_1;
}
if (v_magic != 5927942488114331648) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, 0));
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 72;
self->private_impl.f_chunk_type_array[2] = 68;
self->private_impl.f_chunk_type_array[3] = 82;
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
while (true) {
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
} else {
{
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_2 = wuffs_png__decoder__decode_ihdr(self, a_src);
v_status = t_2;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
if (wuffs_base__status__is_ok(&v_status)) {
goto label__0__break;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
}
label__0__break:;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_checksum_want = t_3;
}
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
goto exit;
}
while (true) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
uint64_t t_4;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_4 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
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;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
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;
uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4);
if (num_bits_4 == 24) {
t_4 = ((uint64_t)(*scratch >> 32));
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
if (num_bits_0 == 56) {
t_0 = ((uint64_t)(*scratch));
break;
}
num_bits_4 += 8;
*scratch |= ((uint64_t)(num_bits_4));
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
self->private_impl.f_chunk_length = t_4;
v_magic = t_0;
}
if (v_magic != 727905341920923785) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
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;
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;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
if (num_bits_1 == 56) {
t_1 = ((uint64_t)(*scratch));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
v_magic = t_1;
}
if (v_magic != 5927942488114331648) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 72;
self->private_impl.f_chunk_type_array[2] = 68;
self->private_impl.f_chunk_type_array[3] = 82;
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32,
sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
while (true) {
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_2 = wuffs_png__decoder__decode_ihdr(self, a_src);
v_status = t_2;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
if (wuffs_base__status__is_ok(&v_status)) {
goto label__0__break;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
}
label__0__break:;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_image_config[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_checksum_want = t_3;
}
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_have != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
goto exit;
}
}
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;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
}
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)));
if (self->private_impl.f_chunk_type == 1413563465) {
if ( ! self->private_impl.f_seen_actl || self->private_impl.f_seen_fctl) {
goto label__1__break;
}
self->private_impl.f_seen_idat = true;
} else if (self->private_impl.f_chunk_type == 1413571686) {
if (self->private_impl.f_seen_idat && self->private_impl.f_seen_fctl) {
goto label__1__break;
}
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
iop_a_src += 8;
if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32) == 0)) {
self->private_impl.f_chunk_type_array[0] = ((uint8_t)(((self->private_impl.f_chunk_type >> 0) & 255)));
self->private_impl.f_chunk_type_array[1] = ((uint8_t)(((self->private_impl.f_chunk_type >> 8) & 255)));
self->private_impl.f_chunk_type_array[2] = ((uint8_t)(((self->private_impl.f_chunk_type >> 16) & 255)));
self->private_impl.f_chunk_type_array[3] = ((uint8_t)(((self->private_impl.f_chunk_type >> 24) & 255)));
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32,
sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
}
while (true) {
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_4 = wuffs_png__decoder__decode_other_chunk(self, a_src);
v_status = t_4;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32) == 0)) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
if (wuffs_base__status__is_ok(&v_status)) {
goto label__2__break;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
}
label__2__break:;
if (self->private_impl.f_metadata_fourcc != 0) {
self->private_impl.f_call_sequence = 1;
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
goto ok;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
uint32_t t_5;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_5 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
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;
@@ -36805,83 +37498,21 @@ wuffs_png__decoder__decode_image_config(
goto suspend;
}
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_5;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5);
if (num_bits_5 == 24) {
t_5 = ((uint32_t)(*scratch));
t_5 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_5 += 8;
*scratch |= ((uint64_t)(num_bits_5)) << 56;
*scratch |= ((uint64_t)(num_bits_5));
}
}
self->private_impl.f_chunk_type = t_5;
v_checksum_want = t_5;
}
if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type == 1413563465) || (self->private_impl.f_chunk_type == 1163152464))) {
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, 0));
self->private_impl.f_chunk_type_array[0] = ((uint8_t)(((self->private_impl.f_chunk_type >> 0) & 255)));
self->private_impl.f_chunk_type_array[1] = ((uint8_t)(((self->private_impl.f_chunk_type >> 8) & 255)));
self->private_impl.f_chunk_type_array[2] = ((uint8_t)(((self->private_impl.f_chunk_type >> 16) & 255)));
self->private_impl.f_chunk_type_array[3] = ((uint8_t)(((self->private_impl.f_chunk_type >> 24) & 255)));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
}
if (self->private_impl.f_chunk_type == 1413563465) {
goto label__1__break;
}
while (true) {
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_6 = wuffs_png__decoder__decode_other_chunk(self, a_src);
v_status = t_6;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type == 1163152464)) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
if (wuffs_base__status__is_ok(&v_status)) {
goto label__2__break;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(12);
}
label__2__break:;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
uint32_t t_7;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_7 = 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;
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_decode_image_config[0].scratch;
uint32_t num_bits_7 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_7);
if (num_bits_7 == 24) {
t_7 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_7 += 8;
*scratch |= ((uint64_t)(num_bits_7));
}
}
v_checksum_want = t_7;
}
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type == 1163152464) && (v_checksum_have != v_checksum_want)) {
if ( ! self->private_impl.f_ignore_checksum && ((self->private_impl.f_chunk_type & 32) == 0) && (v_checksum_have != v_checksum_want)) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
goto exit;
}
@@ -36892,6 +37523,7 @@ wuffs_png__decoder__decode_image_config(
goto exit;
}
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
self->private_impl.f_first_config_io_position = self->private_impl.f_frame_config_io_position;
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
@@ -36899,9 +37531,19 @@ wuffs_png__decoder__decode_image_config(
0,
self->private_impl.f_width,
self->private_impl.f_height,
self->private_impl.f_frame_config_io_position,
self->private_impl.f_first_config_io_position,
((self->private_impl.f_color_type <= 3) && ! self->private_impl.f_seen_trns));
}
if ( ! self->private_impl.f_seen_actl) {
self->private_impl.f_num_animation_frames_value = 1;
self->private_impl.f_first_rect_x0 = 0;
self->private_impl.f_first_rect_y0 = 0;
self->private_impl.f_first_rect_x1 = self->private_impl.f_width;
self->private_impl.f_first_rect_y1 = self->private_impl.f_height;
self->private_impl.f_first_duration = 0;
self->private_impl.f_first_disposal = 0;
self->private_impl.f_first_overwrite_instead_of_blend = false;
}
self->private_impl.f_call_sequence = 3;
ok:
@@ -37065,7 +37707,7 @@ wuffs_png__decoder__decode_ihdr(
v_a8 = t_4;
}
if (v_a8 != 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_header);
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
goto exit;
}
{
@@ -37103,7 +37745,7 @@ wuffs_png__decoder__decode_ihdr(
self->private_impl.f_filter_distance = 0;
wuffs_png__decoder__assign_filter_distance(self);
if (self->private_impl.f_filter_distance == 0) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
status = wuffs_base__make_status(wuffs_png__error__bad_header);
goto exit;
}
self->private_impl.f_overall_workbuf_length = (((uint64_t)(self->private_impl.f_height)) * (1 + wuffs_png__decoder__calculate_bytes_per_row(self, self->private_impl.f_width)));
@@ -37134,7 +37776,9 @@ static wuffs_base__empty_struct
wuffs_png__decoder__assign_filter_distance(
wuffs_png__decoder* self) {
if (self->private_impl.f_depth < 8) {
if (self->private_impl.f_color_type == 0) {
if ((self->private_impl.f_depth != 1) && (self->private_impl.f_depth != 2) && (self->private_impl.f_depth != 4)) {
return wuffs_base__make_empty_struct();
} else if (self->private_impl.f_color_type == 0) {
self->private_impl.f_dst_pixfmt = 536870920;
self->private_impl.f_src_pixfmt = 536870920;
} else if (self->private_impl.f_color_type == 3) {
@@ -37152,8 +37796,13 @@ wuffs_png__decoder__assign_filter_distance(
self->private_impl.f_src_pixfmt = 536870920;
self->private_impl.f_filter_distance = 1;
} else if (self->private_impl.f_depth == 16) {
self->private_impl.f_dst_pixfmt = 536870923;
self->private_impl.f_src_pixfmt = 537919499;
if (self->private_impl.f_interlace_pass == 0) {
self->private_impl.f_dst_pixfmt = 536870923;
self->private_impl.f_src_pixfmt = 537919499;
} else {
self->private_impl.f_dst_pixfmt = 2164308923;
self->private_impl.f_src_pixfmt = 2164308923;
}
self->private_impl.f_filter_distance = 2;
}
} else if (self->private_impl.f_color_type == 2) {
@@ -37294,22 +37943,161 @@ wuffs_png__decoder__decode_other_chunk(
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_type == 1163152464) {
if (self->private_impl.f_seen_plte || (self->private_impl.f_color_type != 3)) {
if (self->private_impl.f_seen_plte) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
} else if (self->private_impl.f_color_type == 3) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_plte(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if ((self->private_impl.f_color_type == 2) || (self->private_impl.f_color_type == 6)) {
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_seen_plte = true;
} else if ((self->private_impl.f_chunk_type & 32) == 0) {
if (self->private_impl.f_chunk_type != 1413563465) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
} else if (self->private_impl.f_chunk_type == 1280598881) {
if (self->private_impl.f_seen_actl) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_plte(self, a_src);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_png__decoder__decode_actl(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_plte = true;
self->private_impl.f_seen_actl = true;
} else if (self->private_impl.f_chunk_type == 1297238115) {
if (self->private_impl.f_report_metadata_chrm) {
if (self->private_impl.f_seen_chrm) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_png__decoder__decode_chrm(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_chrm = true;
}
} else if (self->private_impl.f_chunk_type == 1716082789) {
if (self->private_impl.f_report_metadata_exif) {
if (self->private_impl.f_seen_exif) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_png__decoder__decode_exif(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_exif = true;
}
} else if (self->private_impl.f_chunk_type == 1280598886) {
if (self->private_impl.f_seen_fctl) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
status = wuffs_png__decoder__decode_fctl(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_fctl = true;
} else if (self->private_impl.f_chunk_type == 1095582055) {
if (self->private_impl.f_report_metadata_gama) {
if (self->private_impl.f_seen_gama) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
status = wuffs_png__decoder__decode_gama(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_gama = true;
}
} else if (self->private_impl.f_chunk_type == 1346585449) {
if (self->private_impl.f_report_metadata_iccp) {
if (self->private_impl.f_seen_iccp) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
status = wuffs_png__decoder__decode_iccp(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_iccp = true;
}
} else if (self->private_impl.f_chunk_type == 1111970419) {
if (self->private_impl.f_report_metadata_srgb) {
if (self->private_impl.f_seen_srgb) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
status = wuffs_png__decoder__decode_srgb(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_srgb = true;
}
} else if (self->private_impl.f_chunk_type == 1397641844) {
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
@@ -37318,7 +38106,7 @@ wuffs_png__decoder__decode_other_chunk(
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
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;
@@ -37327,9 +38115,18 @@ wuffs_png__decoder__decode_other_chunk(
goto suspend;
}
self->private_impl.f_seen_trns = true;
} else {
} else if ((self->private_impl.f_chunk_type == 1951945833) || (self->private_impl.f_chunk_type == 1951942004) || (self->private_impl.f_chunk_type == 1951945850)) {
if (self->private_impl.f_report_metadata_kvp) {
self->private_impl.f_metadata_flavor = 4;
self->private_impl.f_metadata_fourcc = 1263947851;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
}
}
if (self->private_impl.f_metadata_fourcc == 0) {
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
if (self->private_data.s_decode_other_chunk[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_other_chunk[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
@@ -37358,6 +38155,964 @@ wuffs_png__decoder__decode_other_chunk(
return status;
}
// -------- func png.decoder.decode_actl
static wuffs_base__status
wuffs_png__decoder__decode_actl(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_actl[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 8) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
} else if (self->private_impl.f_interlace_pass > 0) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_chunk_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_actl[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_actl[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_impl.f_num_animation_frames_value = t_0;
}
if (self->private_impl.f_num_animation_frames_value == 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_actl[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_actl[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
}
self->private_impl.f_num_animation_loops_value = t_1;
}
goto ok;
ok:
self->private_impl.p_decode_actl[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_actl[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_chrm
static wuffs_base__status
wuffs_png__decoder__decode_chrm(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint64_t v_u = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_chrm[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 32) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
self->private_impl.f_metadata_flavor = 5;
self->private_impl.f_metadata_fourcc = 1128813133;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_chrm[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_u = t_0;
}
self->private_impl.f_metadata_x |= ((16777215 & v_u) << 0);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_chrm[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
}
v_u = t_1;
}
self->private_impl.f_metadata_x |= ((16777215 & v_u) << 24);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint64_t t_2;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_2 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_chrm[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2);
if (num_bits_2 == 24) {
t_2 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_2 += 8;
*scratch |= ((uint64_t)(num_bits_2));
}
}
v_u = t_2;
}
self->private_impl.f_metadata_x |= ((uint64_t)((16777215 & v_u) << 48));
self->private_impl.f_metadata_y |= ((16777215 & v_u) >> 16);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
uint64_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_chrm[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_u = t_3;
}
self->private_impl.f_metadata_y |= ((16777215 & v_u) << 8);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
uint64_t t_4;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_4 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
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_chrm[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4);
if (num_bits_4 == 24) {
t_4 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_4 += 8;
*scratch |= ((uint64_t)(num_bits_4));
}
}
v_u = t_4;
}
self->private_impl.f_metadata_y |= ((16777215 & v_u) << 32);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
uint64_t t_5;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_5 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
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_chrm[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5);
if (num_bits_5 == 24) {
t_5 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_5 += 8;
*scratch |= ((uint64_t)(num_bits_5));
}
}
v_u = t_5;
}
self->private_impl.f_metadata_y |= ((uint64_t)((16777215 & v_u) << 56));
self->private_impl.f_metadata_z |= ((16777215 & v_u) >> 8);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
uint64_t t_6;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_6 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_decode_chrm[0].scratch;
uint32_t num_bits_6 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_6);
if (num_bits_6 == 24) {
t_6 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_6 += 8;
*scratch |= ((uint64_t)(num_bits_6));
}
}
v_u = t_6;
}
self->private_impl.f_metadata_z |= ((16777215 & v_u) << 16);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
uint64_t t_7;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_7 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_chrm[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_decode_chrm[0].scratch;
uint32_t num_bits_7 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_7);
if (num_bits_7 == 24) {
t_7 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_7 += 8;
*scratch |= ((uint64_t)(num_bits_7));
}
}
v_u = t_7;
}
self->private_impl.f_metadata_z |= ((16777215 & v_u) << 40);
goto ok;
ok:
self->private_impl.p_decode_chrm[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_chrm[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_exif
static wuffs_base__status
wuffs_png__decoder__decode_exif(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
if (self->private_impl.f_chunk_length < 4) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_metadata_flavor = 3;
self->private_impl.f_metadata_fourcc = 1163413830;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
self->private_impl.f_metadata_z = wuffs_base__u64__sat_add(self->private_impl.f_metadata_y, ((uint64_t)(self->private_impl.f_chunk_length)));
self->private_impl.f_chunk_length = 0;
goto ok;
ok:
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_fctl
static wuffs_base__status
wuffs_png__decoder__decode_fctl(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_x0 = 0;
uint32_t v_y0 = 0;
uint32_t v_x1 = 0;
uint32_t v_y1 = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_fctl[0];
if (coro_susp_point) {
v_x0 = self->private_data.s_decode_fctl[0].v_x0;
v_x1 = self->private_data.s_decode_fctl[0].v_x1;
v_y1 = self->private_data.s_decode_fctl[0].v_y1;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 26) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[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_fctl[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_x0 = t_0;
}
if (v_x0 != self->private_impl.f_next_animation_seq_num) {
status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number);
goto exit;
} else if (self->private_impl.f_next_animation_seq_num >= 4294967295) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_next_animation_seq_num += 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[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_fctl[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
}
v_x1 = t_1;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint32_t t_2;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_2 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[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_fctl[0].scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2);
if (num_bits_2 == 24) {
t_2 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_2 += 8;
*scratch |= ((uint64_t)(num_bits_2));
}
}
v_y1 = t_2;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[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_fctl[0].scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_x0 = t_3;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
uint32_t t_4;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_4 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_fctl[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
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_fctl[0].scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4);
if (num_bits_4 == 24) {
t_4 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_4 += 8;
*scratch |= ((uint64_t)(num_bits_4));
}
}
v_y0 = t_4;
}
v_x1 += v_x0;
v_y1 += v_y0;
if ((v_x0 >= v_x1) ||
(v_x0 > self->private_impl.f_width) ||
(v_x1 > self->private_impl.f_width) ||
(v_y0 >= v_y1) ||
(v_y0 > self->private_impl.f_height) ||
(v_y1 > self->private_impl.f_height)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_frame_rect_x0 = v_x0;
self->private_impl.f_frame_rect_y0 = v_y0;
self->private_impl.f_frame_rect_x1 = v_x1;
self->private_impl.f_frame_rect_y1 = v_y1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
uint32_t t_5;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_5 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_fctl[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
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_fctl[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5);
if (num_bits_5 == 8) {
t_5 = ((uint32_t)(*scratch >> 48));
break;
}
num_bits_5 += 8;
*scratch |= ((uint64_t)(num_bits_5));
}
}
v_x0 = t_5;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
uint32_t t_6;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_6 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_fctl[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_decode_fctl[0].scratch;
uint32_t num_bits_6 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_6);
if (num_bits_6 == 8) {
t_6 = ((uint32_t)(*scratch >> 48));
break;
}
num_bits_6 += 8;
*scratch |= ((uint64_t)(num_bits_6));
}
}
v_x1 = t_6;
}
if (v_x1 <= 0) {
self->private_impl.f_frame_duration = (((uint64_t)(v_x0)) * 7056000);
} else {
self->private_impl.f_frame_duration = ((((uint64_t)(v_x0)) * 705600000) / ((uint64_t)(v_x1)));
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint32_t t_7 = *iop_a_src++;
v_x0 = t_7;
}
if (v_x0 == 0) {
self->private_impl.f_frame_disposal = 0;
} else if (v_x0 == 1) {
self->private_impl.f_frame_disposal = 1;
} else if (v_x0 == 2) {
self->private_impl.f_frame_disposal = 2;
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint32_t t_8 = *iop_a_src++;
v_x0 = t_8;
}
if (v_x0 == 0) {
self->private_impl.f_frame_overwrite_instead_of_blend = true;
} else if (v_x0 == 1) {
self->private_impl.f_frame_overwrite_instead_of_blend = false;
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (self->private_impl.f_num_decoded_frame_configs_value == 0) {
self->private_impl.f_first_rect_x0 = self->private_impl.f_frame_rect_x0;
self->private_impl.f_first_rect_y0 = self->private_impl.f_frame_rect_y0;
self->private_impl.f_first_rect_x1 = self->private_impl.f_frame_rect_x1;
self->private_impl.f_first_rect_y1 = self->private_impl.f_frame_rect_y1;
self->private_impl.f_first_duration = self->private_impl.f_frame_duration;
self->private_impl.f_first_disposal = self->private_impl.f_frame_disposal;
self->private_impl.f_first_overwrite_instead_of_blend = self->private_impl.f_frame_overwrite_instead_of_blend;
}
goto ok;
ok:
self->private_impl.p_decode_fctl[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_fctl[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_fctl[0].v_x0 = v_x0;
self->private_data.s_decode_fctl[0].v_x1 = v_x1;
self->private_data.s_decode_fctl[0].v_y1 = v_y1;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_gama
static wuffs_base__status
wuffs_png__decoder__decode_gama(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_gama[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 4) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
self->private_impl.f_metadata_flavor = 5;
self->private_impl.f_metadata_fourcc = 1195461953;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
iop_a_src += 4;
} else {
self->private_data.s_decode_gama[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_gama[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint64_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_impl.f_metadata_x = t_0;
}
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
goto ok;
ok:
self->private_impl.p_decode_gama[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_gama[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_iccp
static wuffs_base__status
wuffs_png__decoder__decode_iccp(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_iccp[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
if (self->private_impl.f_chunk_length <= 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_0 = *iop_a_src++;
v_c = t_0;
}
if (v_c == 0) {
goto label__0__break;
}
}
label__0__break:;
if (self->private_impl.f_chunk_length <= 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_1 = *iop_a_src++;
v_c = t_1;
}
if (v_c != 0) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
goto exit;
}
self->private_impl.f_metadata_is_zlib_compressed = true;
self->private_impl.f_metadata_flavor = 4;
self->private_impl.f_metadata_fourcc = 1229144912;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
goto ok;
ok:
self->private_impl.p_decode_iccp[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_iccp[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_plte
static wuffs_base__status
@@ -37394,6 +39149,7 @@ wuffs_png__decoder__decode_plte(
goto exit;
}
v_num_entries = (((uint32_t)(self->private_impl.f_chunk_length)) / 3);
self->private_impl.f_chunk_length = 0;
while (v_i < v_num_entries) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
@@ -37460,6 +39216,67 @@ wuffs_png__decoder__decode_plte(
return status;
}
// -------- func png.decoder.decode_srgb
static wuffs_base__status
wuffs_png__decoder__decode_srgb(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_srgb[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length != 1) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
self->private_impl.f_metadata_flavor = 5;
self->private_impl.f_metadata_fourcc = 1397901122;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint64_t t_0 = *iop_a_src++;
self->private_impl.f_metadata_x = t_0;
}
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
goto ok;
ok:
self->private_impl.p_decode_srgb[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_srgb[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_trns
static wuffs_base__status
@@ -37468,8 +39285,9 @@ wuffs_png__decoder__decode_trns(
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_num_entries = 0;
uint32_t v_i = 0;
uint32_t v_n = 0;
uint64_t v_u = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -37484,42 +39302,143 @@ wuffs_png__decoder__decode_trns(
uint32_t coro_susp_point = self->private_impl.p_decode_trns[0];
if (coro_susp_point) {
v_num_entries = self->private_data.s_decode_trns[0].v_num_entries;
v_i = self->private_data.s_decode_trns[0].v_i;
v_n = self->private_data.s_decode_trns[0].v_n;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_chunk_length > 256) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
v_num_entries = ((uint32_t)(self->private_impl.f_chunk_length));
while (v_i < v_num_entries) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_0 = *iop_a_src++;
self->private_data.f_src_palette[((4 * v_i) + 3)] = t_0;
}
v_i += 1;
}
if (self->private_impl.f_color_type == 3) {
self->private_impl.f_dst_pixfmt = 2164523016;
self->private_impl.f_src_pixfmt = 2164523016;
} else {
if (self->private_impl.f_color_type == 0) {
self->private_impl.choosy_filter_and_swizzle = (
&wuffs_png__decoder__filter_and_swizzle_tricky);
if (self->private_impl.f_color_type == 0) {
self->private_impl.f_dst_pixfmt = 2164295816;
self->private_impl.f_src_pixfmt = 2164308923;
} else if (self->private_impl.f_color_type == 2) {
if (self->private_impl.f_depth <= 8) {
self->private_impl.f_dst_pixfmt = 2164295816;
self->private_impl.f_src_pixfmt = 2164295816;
} else {
self->private_impl.f_dst_pixfmt = 2164308923;
self->private_impl.f_src_pixfmt = 2164308923;
}
if (self->private_impl.f_chunk_length != 2) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_0 = ((uint64_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_decode_trns[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_trns[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 8) {
t_0 = ((uint64_t)(*scratch >> 48));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_u = t_0;
}
if (self->private_impl.f_depth <= 1) {
self->private_impl.f_remap_transparency = (((v_u & 1) * 16777215) | 4278190080);
} else if (self->private_impl.f_depth <= 2) {
self->private_impl.f_remap_transparency = (((v_u & 3) * 5592405) | 4278190080);
} else if (self->private_impl.f_depth <= 4) {
self->private_impl.f_remap_transparency = (((v_u & 15) * 1118481) | 4278190080);
} else if (self->private_impl.f_depth <= 8) {
self->private_impl.f_remap_transparency = (((v_u & 255) * 65793) | 4278190080);
} else {
self->private_impl.f_remap_transparency = ((v_u * 4295032833) | 18446462598732840960u);
}
} else if (self->private_impl.f_color_type == 2) {
self->private_impl.choosy_filter_and_swizzle = (
&wuffs_png__decoder__filter_and_swizzle_tricky);
if (self->private_impl.f_depth <= 8) {
self->private_impl.f_dst_pixfmt = 2164295816;
self->private_impl.f_src_pixfmt = 2164295816;
} else {
self->private_impl.f_dst_pixfmt = 2164308923;
self->private_impl.f_src_pixfmt = 2164308923;
}
if (self->private_impl.f_chunk_length != 6) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length = 0;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 6)) {
t_1 = ((uint64_t)(wuffs_base__peek_u48be__no_bounds_check(iop_a_src)));
iop_a_src += 6;
} else {
self->private_data.s_decode_trns[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_trns[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 40) {
t_1 = ((uint64_t)(*scratch >> 16));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
}
v_u = t_1;
}
if (self->private_impl.f_depth <= 8) {
self->private_impl.f_remap_transparency = ((255 & (v_u >> 0)) |
(65280 & (v_u >> 8)) |
(16711680 & (v_u >> 16)) |
4278190080);
} else {
self->private_impl.f_remap_transparency = (v_u | 18446462598732840960u);
}
} else if (self->private_impl.f_color_type == 3) {
self->private_impl.f_dst_pixfmt = 2164523016;
self->private_impl.f_src_pixfmt = 2164523016;
if (self->private_impl.f_chunk_length > 256) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
v_n = ((uint32_t)(self->private_impl.f_chunk_length));
self->private_impl.f_chunk_length = 0;
while (v_i < v_n) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_2 = *iop_a_src++;
self->private_data.f_src_palette[((4 * v_i) + 3)] = t_2;
}
v_i += 1;
}
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
goto ok;
@@ -37531,8 +39450,8 @@ wuffs_png__decoder__decode_trns(
goto suspend;
suspend:
self->private_impl.p_decode_trns[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_trns[0].v_num_entries = v_num_entries;
self->private_data.s_decode_trns[0].v_i = v_i;
self->private_data.s_decode_trns[0].v_n = v_n;
goto exit;
exit:
@@ -37586,7 +39505,10 @@ wuffs_png__decoder__decode_frame_config(
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence < 3) {
if (self->private_impl.f_call_sequence == 255) {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else if (self->private_impl.f_call_sequence < 3) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
@@ -37604,29 +39526,148 @@ wuffs_png__decoder__decode_frame_config(
goto exit;
}
} else if (self->private_impl.f_call_sequence == 4) {
self->private_impl.f_call_sequence = 255;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_png__decoder__skip_frame(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
if (self->private_impl.f_call_sequence == 255) {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
}
if (self->private_impl.f_num_decoded_frame_configs_value == 0) {
self->private_impl.f_frame_rect_x0 = self->private_impl.f_first_rect_x0;
self->private_impl.f_frame_rect_y0 = self->private_impl.f_first_rect_y0;
self->private_impl.f_frame_rect_x1 = self->private_impl.f_first_rect_x1;
self->private_impl.f_frame_rect_y1 = self->private_impl.f_first_rect_y1;
self->private_impl.f_frame_config_io_position = self->private_impl.f_first_config_io_position;
self->private_impl.f_frame_duration = self->private_impl.f_first_duration;
self->private_impl.f_frame_disposal = self->private_impl.f_first_disposal;
self->private_impl.f_frame_overwrite_instead_of_blend = self->private_impl.f_first_overwrite_instead_of_blend;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
while (true) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
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;
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;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_impl.f_chunk_length = t_0;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
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;
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;
uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
self->private_impl.f_chunk_type = t_1;
}
if (self->private_impl.f_chunk_type == 1413571686) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
} else if (self->private_impl.f_chunk_type == 1280598886) {
self->private_impl.f_frame_config_io_position = ((uint64_t)(wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) - 8));
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
status = wuffs_png__decoder__decode_fctl(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_data.s_decode_frame_config[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
goto label__0__break;
}
self->private_data.s_decode_frame_config[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_decode_frame_config[0].scratch;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0,
0,
self->private_impl.f_width,
self->private_impl.f_height),
((wuffs_base__flicks)(0)),
0,
self->private_impl.f_frame_rect_x0,
self->private_impl.f_frame_rect_y0,
self->private_impl.f_frame_rect_x1,
self->private_impl.f_frame_rect_y1),
((wuffs_base__flicks)(self->private_impl.f_frame_duration)),
((uint64_t)(self->private_impl.f_num_decoded_frame_configs_value)),
self->private_impl.f_frame_config_io_position,
0,
false,
false,
self->private_impl.f_frame_disposal,
((self->private_impl.f_color_type <= 3) && ! self->private_impl.f_seen_trns),
self->private_impl.f_frame_overwrite_instead_of_blend,
0);
}
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
self->private_impl.f_call_sequence = 4;
ok:
@@ -37651,6 +39692,162 @@ wuffs_png__decoder__decode_frame_config(
return status;
}
// -------- func png.decoder.skip_frame
static wuffs_base__status
wuffs_png__decoder__skip_frame(
wuffs_png__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_seq_num = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_skip_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
self->private_impl.f_chunk_type_array[0] = 0;
self->private_impl.f_chunk_type_array[1] = 0;
self->private_impl.f_chunk_type_array[2] = 0;
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;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
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)));
if (self->private_impl.f_chunk_type == 1413563465) {
if (self->private_impl.f_chunk_type_array[0] == 102) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 68;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
} else if (self->private_impl.f_chunk_type == 1413571686) {
if (self->private_impl.f_chunk_type_array[0] == 73) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_type_array[0] = 102;
self->private_impl.f_chunk_type_array[1] = 100;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
if (self->private_impl.f_chunk_length < 4) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 4;
iop_a_src += 8;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_skip_frame[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
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_skip_frame[0].scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_seq_num = t_0;
}
if (v_seq_num != self->private_impl.f_next_animation_seq_num) {
status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number);
goto exit;
} else if (self->private_impl.f_next_animation_seq_num >= 4294967295) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_next_animation_seq_num += 1;
self->private_data.s_skip_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (self->private_data.s_skip_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_skip_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_skip_frame[0].scratch;
self->private_impl.f_chunk_length = 0;
goto label__0__continue;
} else if (self->private_impl.f_chunk_type_array[0] != 0) {
goto label__0__break;
} else if (self->private_impl.f_chunk_type == 1280598886) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_data.s_skip_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (self->private_data.s_skip_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_skip_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_skip_frame[0].scratch;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
if (self->private_impl.f_num_decoded_frames_value < self->private_impl.f_num_animation_frames_value) {
self->private_impl.f_call_sequence = 5;
} else {
self->private_impl.f_call_sequence = 255;
}
ok:
self->private_impl.p_skip_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_skip_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func png.decoder.decode_frame
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
@@ -37682,25 +39879,138 @@ wuffs_png__decoder__decode_frame(
self->private_impl.active_coroutine = 0;
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;
uint32_t v_pass_height = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence < 4) {
if (self->private_impl.f_call_sequence == 255) {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else if (self->private_impl.f_call_sequence != 4) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_png__decoder__decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 4) {
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
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;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
}
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)));
if (self->private_impl.f_chunk_type == 1413563465) {
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 68;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
iop_a_src += 8;
if ( ! self->private_impl.f_ignore_checksum) {
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32,
sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
}
goto label__0__break;
} else if (self->private_impl.f_chunk_type == 1413571686) {
self->private_impl.f_chunk_type_array[0] = 102;
self->private_impl.f_chunk_type_array[1] = 100;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
if (self->private_impl.f_chunk_length < 4) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 4;
iop_a_src += 8;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
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;
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;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 24) {
t_0 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_0 += 8;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_seq_num = t_0;
}
if (v_seq_num != self->private_impl.f_next_animation_seq_num) {
status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number);
goto exit;
} else if (self->private_impl.f_next_animation_seq_num >= 4294967295) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_next_animation_seq_num += 1;
goto label__0__break;
} else if (self->private_impl.f_chunk_type == 1280598886) {
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);
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));
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;
self->private_impl.f_chunk_length = 0;
}
label__0__break:;
if (self->private_impl.f_zlib_is_dirty) {
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
if (self->private_impl.f_ignore_checksum) {
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
}
}
self->private_impl.f_zlib_is_dirty = true;
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
wuffs_base__pixel_buffer__pixel_format(a_dst),
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)),
@@ -37719,13 +40029,24 @@ wuffs_png__decoder__decode_frame(
}
self->private_impl.f_workbuf_hist_pos_base = 0;
while (true) {
v_pass_width = (16777215 & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][1])) + self->private_impl.f_width) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]));
v_pass_height = (16777215 & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][4])) + self->private_impl.f_height) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3]));
if (self->private_impl.f_chunk_type_array[0] == 73) {
v_pass_width = (16777215 & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][1])) + self->private_impl.f_width) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]));
v_pass_height = (16777215 & ((((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][4])) + self->private_impl.f_height) >> WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3]));
} else {
v_pass_width = (16777215 & ((uint32_t)(self->private_impl.f_frame_rect_x1 - self->private_impl.f_frame_rect_x0)));
v_pass_height = (16777215 & ((uint32_t)(self->private_impl.f_frame_rect_y1 - self->private_impl.f_frame_rect_y0)));
}
if ((v_pass_width > 0) && (v_pass_height > 0)) {
self->private_impl.f_pass_bytes_per_row = wuffs_png__decoder__calculate_bytes_per_row(self, v_pass_width);
self->private_impl.f_pass_workbuf_length = (((uint64_t)(v_pass_height)) * (1 + self->private_impl.f_pass_bytes_per_row));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
status = wuffs_png__decoder__decode_pass(self, a_src, a_workbuf);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
@@ -37743,7 +40064,7 @@ wuffs_png__decoder__decode_frame(
self->private_impl.f_workbuf_hist_pos_base += self->private_impl.f_pass_workbuf_length;
}
if ((self->private_impl.f_interlace_pass == 0) || (self->private_impl.f_interlace_pass >= 7)) {
goto label__0__break;
goto label__1__break;
}
#if defined(__GNUC__)
#pragma GCC diagnostic push
@@ -37754,8 +40075,13 @@ wuffs_png__decoder__decode_frame(
#pragma GCC diagnostic pop
#endif
}
label__0__break:;
self->private_impl.f_call_sequence = 255;
label__1__break:;
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_num_decoded_frames_value, 1);
if (self->private_impl.f_num_decoded_frames_value < self->private_impl.f_num_animation_frames_value) {
self->private_impl.f_call_sequence = 5;
} else {
self->private_impl.f_call_sequence = 255;
}
ok:
self->private_impl.p_decode_frame[0] = 0;
@@ -37769,6 +40095,10 @@ wuffs_png__decoder__decode_frame(
goto exit;
exit:
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
@@ -37795,6 +40125,7 @@ wuffs_png__decoder__decode_pass(
wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL);
uint32_t v_checksum_have = 0;
uint32_t v_checksum_want = 0;
uint32_t v_seq_num = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
@@ -37808,9 +40139,6 @@ wuffs_png__decoder__decode_pass(
}
uint32_t coro_susp_point = self->private_impl.p_decode_pass[0];
if (coro_susp_point) {
v_checksum_have = self->private_data.s_decode_pass[0].v_checksum_have;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -37840,7 +40168,7 @@ wuffs_png__decoder__decode_pass(
{
const uint8_t *o_1_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
self->private_impl.f_chunk_length);
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
@@ -37861,7 +40189,7 @@ wuffs_png__decoder__decode_pass(
if ( ! self->private_impl.f_ignore_checksum) {
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
}
wuffs_base__u64__sat_sub_indirect(&self->private_impl.f_chunk_length, wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))));
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))));
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) {
@@ -37875,41 +40203,41 @@ wuffs_png__decoder__decode_pass(
io2_v_w = o_0_io2_v_w;
}
if (wuffs_base__status__is_ok(&v_zlib_status)) {
if ( ! self->private_impl.f_ignore_checksum) {
if (self->private_impl.f_chunk_length > 0) {
status = wuffs_base__make_status(wuffs_base__error__too_much_data);
goto exit;
}
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8());
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_pass[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_pass[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
if (self->private_impl.f_chunk_length > 0) {
status = wuffs_base__make_status(wuffs_base__error__too_much_data);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_1 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_pass[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_pass[0].scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 24) {
t_1 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_1 += 8;
*scratch |= ((uint64_t)(num_bits_1));
}
v_checksum_want = t_1;
}
v_checksum_want = t_1;
}
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type_array[0] == 73)) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8());
if (v_checksum_have != v_checksum_want) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
goto exit;
@@ -37961,7 +40289,7 @@ wuffs_png__decoder__decode_pass(
}
v_checksum_want = t_2;
}
if ( ! self->private_impl.f_ignore_checksum) {
if ( ! self->private_impl.f_ignore_checksum && (self->private_impl.f_chunk_type_array[0] == 73)) {
v_checksum_have = wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__utility__empty_slice_u8());
if (v_checksum_have != v_checksum_want) {
status = wuffs_base__make_status(wuffs_png__error__bad_checksum);
@@ -37970,9 +40298,9 @@ wuffs_png__decoder__decode_pass(
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint64_t t_3;
uint32_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_3 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src)));
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_pass[0].scratch = 0;
@@ -37988,7 +40316,7 @@ wuffs_png__decoder__decode_pass(
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 24) {
t_3 = ((uint64_t)(*scratch >> 32));
t_3 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_3 += 8;
@@ -38026,17 +40354,59 @@ wuffs_png__decoder__decode_pass(
}
self->private_impl.f_chunk_type = t_4;
}
if (self->private_impl.f_chunk_type != 1413563465) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if ( ! self->private_impl.f_ignore_checksum) {
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32, sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, 0));
self->private_impl.f_chunk_type_array[0] = 73;
self->private_impl.f_chunk_type_array[1] = 68;
self->private_impl.f_chunk_type_array[2] = 65;
self->private_impl.f_chunk_type_array[3] = 84;
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
if (self->private_impl.f_chunk_type_array[0] == 73) {
if (self->private_impl.f_chunk_type != 1413563465) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if ( ! self->private_impl.f_ignore_checksum) {
wuffs_base__ignore_status(wuffs_crc32__ieee_hasher__initialize(&self->private_data.f_crc32,
sizeof (wuffs_crc32__ieee_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__make_slice_u8(self->private_impl.f_chunk_type_array, 4));
}
} else {
if ((self->private_impl.f_chunk_type != 1413571686) || (self->private_impl.f_chunk_length < 4)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 4;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
uint32_t t_5;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
t_5 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_decode_pass[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
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_pass[0].scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_5);
if (num_bits_5 == 24) {
t_5 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_5 += 8;
*scratch |= ((uint64_t)(num_bits_5));
}
}
v_seq_num = t_5;
}
if (v_seq_num != self->private_impl.f_next_animation_seq_num) {
status = wuffs_base__make_status(wuffs_png__error__bad_animation_sequence_number);
goto exit;
} else if (self->private_impl.f_next_animation_seq_num >= 4294967295) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_file);
goto exit;
}
self->private_impl.f_next_animation_seq_num += 1;
}
goto label__0__continue;
} else if (((uint64_t)(io2_a_src - iop_a_src)) > 0) {
@@ -38044,7 +40414,7 @@ wuffs_png__decoder__decode_pass(
goto exit;
}
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
}
label__0__break:;
if (self->private_impl.f_workbuf_wi != self->private_impl.f_pass_workbuf_length) {
@@ -38064,7 +40434,6 @@ wuffs_png__decoder__decode_pass(
goto suspend;
suspend:
self->private_impl.p_decode_pass[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_pass[0].v_checksum_have = v_checksum_have;
goto exit;
exit:
@@ -38089,10 +40458,10 @@ wuffs_png__decoder__frame_dirty_rect(
}
return wuffs_base__utility__make_rect_ie_u32(
0,
0,
self->private_impl.f_width,
self->private_impl.f_height);
self->private_impl.f_frame_rect_x0,
self->private_impl.f_frame_rect_y0,
self->private_impl.f_frame_rect_x1,
self->private_impl.f_frame_rect_y1);
}
// -------- func png.decoder.num_animation_loops
@@ -38108,7 +40477,7 @@ wuffs_png__decoder__num_animation_loops(
return 0;
}
return 0;
return self->private_impl.f_num_animation_loops_value;
}
// -------- func png.decoder.num_decoded_frame_configs
@@ -38124,10 +40493,7 @@ wuffs_png__decoder__num_decoded_frame_configs(
return 0;
}
if (self->private_impl.f_call_sequence > 3) {
return 1;
}
return 0;
return ((uint64_t)(self->private_impl.f_num_decoded_frame_configs_value));
}
// -------- func png.decoder.num_decoded_frames
@@ -38143,10 +40509,7 @@ wuffs_png__decoder__num_decoded_frames(
return 0;
}
if (self->private_impl.f_call_sequence > 4) {
return 1;
}
return 0;
return ((uint64_t)(self->private_impl.f_num_decoded_frames_value));
}
// -------- func png.decoder.restart_frame
@@ -38168,8 +40531,7 @@ wuffs_png__decoder__restart_frame(
if (self->private_impl.f_call_sequence < 3) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if (a_index != 0) {
} else if ((a_index >= ((uint64_t)(self->private_impl.f_num_animation_frames_value))) || ((a_index == 0) && (a_io_position != self->private_impl.f_first_config_io_position))) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 3;
@@ -38177,6 +40539,8 @@ wuffs_png__decoder__restart_frame(
self->private_impl.f_interlace_pass = 1;
}
self->private_impl.f_frame_config_io_position = a_io_position;
self->private_impl.f_num_decoded_frame_configs_value = ((uint32_t)((a_index & 4294967295)));
self->private_impl.f_num_decoded_frames_value = self->private_impl.f_num_decoded_frame_configs_value;
return wuffs_base__make_status(NULL);
}
@@ -38187,6 +40551,26 @@ wuffs_png__decoder__set_report_metadata(
wuffs_png__decoder* self,
uint32_t a_fourcc,
bool a_report) {
if (!self) {
return wuffs_base__make_empty_struct();
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_empty_struct();
}
if (a_fourcc == 1128813133) {
self->private_impl.f_report_metadata_chrm = a_report;
} else if (a_fourcc == 1163413830) {
self->private_impl.f_report_metadata_exif = a_report;
} else if (a_fourcc == 1195461953) {
self->private_impl.f_report_metadata_gama = a_report;
} else if (a_fourcc == 1229144912) {
self->private_impl.f_report_metadata_iccp = a_report;
} else if (a_fourcc == 1263947808) {
self->private_impl.f_report_metadata_kvp = a_report;
} else if (a_fourcc == 1397901122) {
self->private_impl.f_report_metadata_srgb = a_report;
}
return wuffs_base__make_empty_struct();
}
@@ -38219,13 +40603,498 @@ wuffs_png__decoder__tell_me_more(
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
uint8_t v_c = 0;
uint16_t v_c2 = 0;
wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer();
wuffs_base__io_buffer* v_w = &u_w;
uint8_t* iop_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io0_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint64_t v_num_written = 0;
uint64_t v_w_mark = 0;
uint64_t v_r_mark = 0;
wuffs_base__status v_zlib_status = wuffs_base__make_status(NULL);
uint8_t* iop_a_dst = NULL;
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst) {
io0_a_dst = a_dst->data.ptr;
io1_a_dst = io0_a_dst + a_dst->meta.wi;
iop_a_dst = io1_a_dst;
io2_a_dst = io0_a_dst + a_dst->data.len;
if (a_dst->meta.closed) {
io2_a_dst = iop_a_dst;
}
}
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_tell_me_more[0];
if (coro_susp_point) {
v_zlib_status = self->private_data.s_tell_me_more[0].v_zlib_status;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 1) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
if (self->private_impl.f_metadata_fourcc == 0) {
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
}
while (true) {
if (self->private_impl.f_metadata_flavor == 3) {
while (true) {
if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_y) {
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
goto exit;
} else if (a_minfo != NULL) {
wuffs_base__more_information__set(a_minfo,
self->private_impl.f_metadata_flavor,
self->private_impl.f_metadata_fourcc,
self->private_impl.f_metadata_x,
self->private_impl.f_metadata_y,
self->private_impl.f_metadata_z);
}
if (self->private_impl.f_metadata_y >= self->private_impl.f_metadata_z) {
goto label__goto_done__break;
}
self->private_impl.f_metadata_y = self->private_impl.f_metadata_z;
status = wuffs_base__make_status(wuffs_base__suspension__even_more_information);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
}
if (self->private_impl.f_metadata_is_zlib_compressed) {
if (self->private_impl.f_zlib_is_dirty) {
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
if (self->private_impl.f_ignore_checksum) {
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
}
}
self->private_impl.f_zlib_is_dirty = true;
self->private_impl.f_ztxt_hist_pos = 0;
}
label__loop__continue:;
while (true) {
if (a_minfo != NULL) {
wuffs_base__more_information__set(a_minfo,
self->private_impl.f_metadata_flavor,
self->private_impl.f_metadata_fourcc,
self->private_impl.f_metadata_x,
self->private_impl.f_metadata_y,
self->private_impl.f_metadata_z);
}
if (self->private_impl.f_metadata_flavor != 4) {
goto label__loop__break;
}
if (self->private_impl.f_metadata_is_zlib_compressed) {
if (self->private_impl.f_chunk_type == 1346585449) {
{
const uint8_t *o_0_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_dst) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
v_zlib_status = t_0;
if (a_dst) {
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
}
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
io2_a_src = o_0_io2_a_src;
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
if (wuffs_base__status__is_ok(&v_zlib_status)) {
self->private_impl.f_metadata_is_zlib_compressed = false;
goto label__loop__break;
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
status = v_zlib_status;
if (wuffs_base__status__is_error(&status)) {
goto exit;
} else if (wuffs_base__status__is_suspension(&status)) {
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
goto exit;
}
goto ok;
}
status = v_zlib_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
} else if (self->private_impl.f_chunk_type == 1951945833) {
{
const uint8_t *o_1_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
if (a_dst) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
v_zlib_status = t_1;
if (a_dst) {
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
}
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
io2_a_src = o_1_io2_a_src;
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
if (wuffs_base__status__is_ok(&v_zlib_status)) {
self->private_impl.f_metadata_is_zlib_compressed = false;
goto label__loop__break;
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
status = v_zlib_status;
if (wuffs_base__status__is_error(&status)) {
goto exit;
} else if (wuffs_base__status__is_suspension(&status)) {
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
goto exit;
}
goto ok;
}
status = v_zlib_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
} else if (self->private_impl.f_chunk_type == 1951945850) {
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
{
wuffs_base__io_buffer* o_2_v_w = v_w;
uint8_t *o_2_iop_v_w = iop_v_w;
uint8_t *o_2_io0_v_w = io0_v_w;
uint8_t *o_2_io1_v_w = io1_v_w;
uint8_t *o_2_io2_v_w = io2_v_w;
v_w = wuffs_base__io_writer__set(
&u_w,
&iop_v_w,
&io0_v_w,
&io1_v_w,
&io2_v_w,
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
self->private_impl.f_ztxt_hist_pos);
{
const uint8_t *o_3_io2_a_src = io2_a_src;
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
((uint64_t)(self->private_impl.f_chunk_length)));
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
{
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
v_zlib_status = t_2;
iop_v_w = u_w.data.ptr + u_w.meta.wi;
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
}
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
io2_a_src = o_3_io2_a_src;
if (a_src) {
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
}
}
v_w = o_2_v_w;
iop_v_w = o_2_iop_v_w;
io0_v_w = o_2_io0_v_w;
io1_v_w = o_2_io1_v_w;
io2_v_w = o_2_io2_v_w;
}
if (v_num_written > 1024) {
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
goto exit;
}
self->private_impl.f_ztxt_ri = 0;
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
}
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
if (v_c2 == 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
goto exit;
} else if (v_c2 <= 127) {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
v_c2 = 0;
goto label__loop__continue;
}
self->private_impl.f_ztxt_ri += 1;
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
} else {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
v_c2 = 0;
goto label__loop__continue;
}
self->private_impl.f_ztxt_ri += 1;
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
}
}
if (wuffs_base__status__is_ok(&v_zlib_status)) {
self->private_impl.f_metadata_is_zlib_compressed = false;
goto label__loop__break;
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
status = v_zlib_status;
if (wuffs_base__status__is_error(&status)) {
goto exit;
} else if (wuffs_base__status__is_suspension(&status)) {
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
goto exit;
}
goto ok;
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
status = v_zlib_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
} else {
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
goto exit;
}
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
while (true) {
if (self->private_impl.f_chunk_length <= 0) {
goto label__loop__break;
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
goto label__loop__continue;
} else if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
goto label__loop__continue;
}
self->private_impl.f_chunk_length -= 1;
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
iop_a_src += 1;
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
}
} else {
while (true) {
if (self->private_impl.f_chunk_length <= 0) {
if (self->private_impl.f_metadata_fourcc == 1263947851) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
goto label__loop__break;
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
goto label__loop__continue;
}
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
if (v_c == 0) {
self->private_impl.f_chunk_length -= 1;
iop_a_src += 1;
goto label__loop__break;
}
v_c2 = WUFFS_PNG__LATIN_1[v_c];
if (v_c2 == 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
goto exit;
} else if (v_c2 <= 127) {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
v_c2 = 0;
goto label__loop__continue;
}
self->private_impl.f_chunk_length -= 1;
iop_a_src += 1;
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
} else {
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
v_c2 = 0;
goto label__loop__continue;
}
self->private_impl.f_chunk_length -= 1;
iop_a_src += 1;
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
}
}
}
}
label__loop__break:;
if (self->private_impl.f_metadata_fourcc == 1263947851) {
self->private_impl.f_metadata_fourcc = 1263947862;
if (self->private_impl.f_chunk_type == 1951945833) {
if (self->private_impl.f_chunk_length <= 1) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 2;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_3 = *iop_a_src++;
v_c = t_3;
}
if (v_c == 0) {
self->private_impl.f_metadata_is_zlib_compressed = false;
} else if (v_c == 1) {
self->private_impl.f_metadata_is_zlib_compressed = true;
} else {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_4 = *iop_a_src++;
v_c = t_4;
}
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
goto exit;
}
self->private_impl.f_metadata_fourcc -= 2;
while (self->private_impl.f_metadata_fourcc != 1263947862) {
self->private_impl.f_metadata_fourcc += 1;
while (true) {
if (self->private_impl.f_chunk_length <= 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_5 = *iop_a_src++;
v_c = t_5;
}
if (v_c == 0) {
goto label__0__break;
}
}
label__0__break:;
}
} else if (self->private_impl.f_chunk_type == 1951945850) {
if (self->private_impl.f_chunk_length <= 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_impl.f_chunk_length -= 1;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_6 = *iop_a_src++;
v_c = t_6;
}
if (v_c != 0) {
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
goto exit;
}
self->private_impl.f_metadata_is_zlib_compressed = true;
}
self->private_impl.f_call_sequence = 2;
status = wuffs_base__make_status(NULL);
goto ok;
}
goto label__goto_done__break;
}
label__goto_done__break:;
if (self->private_impl.f_chunk_length != 0) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
self->private_data.s_tell_me_more[0].scratch = 4;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
self->private_impl.f_metadata_flavor = 0;
self->private_impl.f_metadata_fourcc = 0;
self->private_impl.f_metadata_x = 0;
self->private_impl.f_metadata_y = 0;
self->private_impl.f_metadata_z = 0;
self->private_impl.f_call_sequence = 2;
status = wuffs_base__make_status(NULL);
goto ok;
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;
self->private_data.s_tell_me_more[0].v_zlib_status = v_zlib_status;
goto ok;
ok:
goto exit;
exit:
if (a_dst) {
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
@@ -38266,7 +41135,8 @@ wuffs_png__decoder__filter_and_swizzle__choosy_default(
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint64_t v_dst_bytes_per_row0 = 0;
uint64_t v_dst_bytes_per_row1 = 0;
wuffs_base__slice_u8 v_dst_palette = {0};
wuffs_base__table_u8 v_tab = {0};
uint32_t v_y = 0;
@@ -38281,14 +41151,33 @@ wuffs_png__decoder__filter_and_swizzle__choosy_default(
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
v_dst_bytes_per_row0 = (((uint64_t)(self->private_impl.f_frame_rect_x0)) * v_dst_bytes_per_pixel);
v_dst_bytes_per_row1 = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * v_dst_bytes_per_pixel);
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
while (v_y < self->private_impl.f_height) {
v_dst = wuffs_base__table_u8__row(v_tab, v_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
}
if (v_dst_bytes_per_row1 < ((uint64_t)(v_tab.width))) {
v_tab = wuffs_base__table_u8__subtable_ij(v_tab,
0,
0,
v_dst_bytes_per_row1,
((uint64_t)(v_tab.height)));
}
if (v_dst_bytes_per_row0 < ((uint64_t)(v_tab.width))) {
v_tab = wuffs_base__table_u8__subtable_ij(v_tab,
v_dst_bytes_per_row0,
0,
((uint64_t)(v_tab.width)),
((uint64_t)(v_tab.height)));
} else {
v_tab = wuffs_base__table_u8__subtable_ij(v_tab,
0,
0,
0,
0);
}
v_y = self->private_impl.f_frame_rect_y0;
while (v_y < self->private_impl.f_frame_rect_y1) {
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_y);
if (1 > ((uint64_t)(a_workbuf.len))) {
return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length);
}
@@ -38328,7 +41217,7 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint64_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
uint64_t v_dst_bytes_per_row1 = 0;
wuffs_base__slice_u8 v_dst_palette = {0};
wuffs_base__table_u8 v_tab = {0};
uint64_t v_src_bytes_per_pixel = 0;
@@ -38352,26 +41241,22 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
v_dst_bytes_per_row = (((uint64_t)(self->private_impl.f_width)) * v_dst_bytes_per_pixel);
v_dst_bytes_per_row1 = (((uint64_t)(self->private_impl.f_frame_rect_x1)) * v_dst_bytes_per_pixel);
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
v_src_bytes_per_pixel = 1;
if (self->private_impl.f_depth >= 8) {
v_src_bytes_per_pixel = (((uint64_t)(WUFFS_PNG__NUM_CHANNELS[self->private_impl.f_color_type])) * ((uint64_t)((self->private_impl.f_depth >> 3))));
}
v_bits_unpacked[0] = 255;
v_bits_unpacked[1] = 255;
v_bits_unpacked[2] = 255;
v_bits_unpacked[3] = 255;
v_bits_unpacked[4] = 255;
v_bits_unpacked[5] = 255;
v_bits_unpacked[6] = 255;
v_bits_unpacked[7] = 255;
v_y = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][5]));
while (v_y < self->private_impl.f_height) {
v_dst = wuffs_base__table_u8__row(v_tab, v_y);
if (v_dst_bytes_per_row < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row);
if (self->private_impl.f_chunk_type_array[0] == 73) {
v_y = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][5]));
} else {
v_y = self->private_impl.f_frame_rect_y0;
}
while (v_y < self->private_impl.f_frame_rect_y1) {
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_y);
if (v_dst_bytes_per_row1 < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_dst_bytes_per_row1);
}
if (1 > ((uint64_t)(a_workbuf.len))) {
return wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_workbuf_length);
@@ -38396,9 +41281,13 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
return wuffs_base__make_status(wuffs_png__error__bad_filter);
}
v_s = v_curr_row;
v_x = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][2]));
if (self->private_impl.f_chunk_type_array[0] == 73) {
v_x = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][2]));
} else {
v_x = self->private_impl.f_frame_rect_x0;
}
if (self->private_impl.f_depth == 8) {
while (v_x < self->private_impl.f_width) {
while (v_x < self->private_impl.f_frame_rect_x1) {
v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel);
if (v_i <= ((uint64_t)(v_dst.len))) {
if (self->private_impl.f_color_type == 4) {
@@ -38410,6 +41299,44 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
v_s = wuffs_base__slice_u8__subslice_i(v_s, 2);
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(v_bits_unpacked, 4));
}
} else if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) != 0) {
if (self->private_impl.f_color_type == 0) {
if (1 <= ((uint64_t)(v_s.len))) {
v_bits_unpacked[0] = v_s.ptr[0];
v_bits_unpacked[1] = v_s.ptr[0];
v_bits_unpacked[2] = v_s.ptr[0];
v_bits_unpacked[3] = 255;
v_s = wuffs_base__slice_u8__subslice_i(v_s, 1);
if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) == ((((uint32_t)(v_bits_unpacked[0])) << 0) |
(((uint32_t)(v_bits_unpacked[1])) << 8) |
(((uint32_t)(v_bits_unpacked[2])) << 16) |
(((uint32_t)(v_bits_unpacked[3])) << 24))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
}
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(v_bits_unpacked, 4));
}
} else {
if (3 <= ((uint64_t)(v_s.len))) {
v_bits_unpacked[0] = v_s.ptr[2];
v_bits_unpacked[1] = v_s.ptr[1];
v_bits_unpacked[2] = v_s.ptr[0];
v_bits_unpacked[3] = 255;
v_s = wuffs_base__slice_u8__subslice_i(v_s, 3);
if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) == ((((uint32_t)(v_bits_unpacked[0])) << 0) |
(((uint32_t)(v_bits_unpacked[1])) << 8) |
(((uint32_t)(v_bits_unpacked[2])) << 16) |
(((uint32_t)(v_bits_unpacked[3])) << 24))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
}
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(v_bits_unpacked, 4));
}
}
} else if (v_src_bytes_per_pixel <= ((uint64_t)(v_s.len))) {
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__slice_u8__subslice_j(v_s, v_src_bytes_per_pixel));
v_s = wuffs_base__slice_u8__subslice_i(v_s, v_src_bytes_per_pixel);
@@ -38424,7 +41351,7 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
}
v_shift = ((8 - self->private_impl.f_depth) & 7);
v_packs_remaining = 0;
while (v_x < self->private_impl.f_width) {
while (v_x < self->private_impl.f_frame_rect_x1) {
v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel);
if (v_i <= ((uint64_t)(v_dst.len))) {
if ((v_packs_remaining == 0) && (1 <= ((uint64_t)(v_s.len)))) {
@@ -38435,12 +41362,28 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
v_bits_unpacked[0] = ((uint8_t)((v_bits_packed >> v_shift) * v_multiplier));
v_bits_packed = ((uint8_t)(v_bits_packed << self->private_impl.f_depth));
v_packs_remaining = ((uint8_t)(v_packs_remaining - 1));
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(v_bits_unpacked, 1));
if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) != 0) {
v_bits_unpacked[1] = v_bits_unpacked[0];
v_bits_unpacked[2] = v_bits_unpacked[0];
v_bits_unpacked[3] = 255;
if (((uint32_t)((self->private_impl.f_remap_transparency & 4294967295))) == ((((uint32_t)(v_bits_unpacked[0])) << 0) |
(((uint32_t)(v_bits_unpacked[1])) << 8) |
(((uint32_t)(v_bits_unpacked[2])) << 16) |
(((uint32_t)(v_bits_unpacked[3])) << 24))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
}
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(v_bits_unpacked, 4));
} else {
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(v_bits_unpacked, 1));
}
}
v_x += (((uint32_t)(1)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]);
}
} else {
while (v_x < self->private_impl.f_width) {
while (v_x < self->private_impl.f_frame_rect_x1) {
v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel);
if (v_i <= ((uint64_t)(v_dst.len))) {
if (self->private_impl.f_color_type == 0) {
@@ -38451,7 +41394,26 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
v_bits_unpacked[3] = v_s.ptr[0];
v_bits_unpacked[4] = v_s.ptr[1];
v_bits_unpacked[5] = v_s.ptr[0];
v_bits_unpacked[6] = 255;
v_bits_unpacked[7] = 255;
v_s = wuffs_base__slice_u8__subslice_i(v_s, 2);
if (self->private_impl.f_remap_transparency == ((((uint64_t)(v_bits_unpacked[0])) << 0) |
(((uint64_t)(v_bits_unpacked[1])) << 8) |
(((uint64_t)(v_bits_unpacked[2])) << 16) |
(((uint64_t)(v_bits_unpacked[3])) << 24) |
(((uint64_t)(v_bits_unpacked[4])) << 32) |
(((uint64_t)(v_bits_unpacked[5])) << 40) |
(((uint64_t)(v_bits_unpacked[6])) << 48) |
(((uint64_t)(v_bits_unpacked[7])) << 56))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
v_bits_unpacked[4] = 0;
v_bits_unpacked[5] = 0;
v_bits_unpacked[6] = 0;
v_bits_unpacked[7] = 0;
}
}
} else if (self->private_impl.f_color_type == 2) {
if (6 <= ((uint64_t)(v_s.len))) {
@@ -38461,7 +41423,26 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
v_bits_unpacked[3] = v_s.ptr[2];
v_bits_unpacked[4] = v_s.ptr[1];
v_bits_unpacked[5] = v_s.ptr[0];
v_bits_unpacked[6] = 255;
v_bits_unpacked[7] = 255;
v_s = wuffs_base__slice_u8__subslice_i(v_s, 6);
if (self->private_impl.f_remap_transparency == ((((uint64_t)(v_bits_unpacked[0])) << 0) |
(((uint64_t)(v_bits_unpacked[1])) << 8) |
(((uint64_t)(v_bits_unpacked[2])) << 16) |
(((uint64_t)(v_bits_unpacked[3])) << 24) |
(((uint64_t)(v_bits_unpacked[4])) << 32) |
(((uint64_t)(v_bits_unpacked[5])) << 40) |
(((uint64_t)(v_bits_unpacked[6])) << 48) |
(((uint64_t)(v_bits_unpacked[7])) << 56))) {
v_bits_unpacked[0] = 0;
v_bits_unpacked[1] = 0;
v_bits_unpacked[2] = 0;
v_bits_unpacked[3] = 0;
v_bits_unpacked[4] = 0;
v_bits_unpacked[5] = 0;
v_bits_unpacked[6] = 0;
v_bits_unpacked[7] = 0;
}
}
} else if (self->private_impl.f_color_type == 4) {
if (4 <= ((uint64_t)(v_s.len))) {
@@ -38989,7 +41970,7 @@ wuffs_wbmp__decoder__decode_frame(
if (self->private_impl.f_width > 0) {
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
while (v_dst_y < self->private_impl.f_height) {
v_dst = wuffs_base__table_u8__row(v_tab, v_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
v_dst_x = 0;
while (v_dst_x < self->private_impl.f_width) {
if ((v_dst_x & 7) == 0) {
@@ -38997,7 +41978,7 @@ wuffs_wbmp__decoder__decode_frame(
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
v_dst = wuffs_base__table_u8__row(v_tab, v_dst_y);
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
v_dst_x_in_bytes = (((uint64_t)(v_dst_x)) * v_dst_bytes_per_pixel);
if (v_dst_x_in_bytes <= ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_x_in_bytes);
@@ -39237,6 +42218,71 @@ namespace sync_io {
// --------
DynIOBuffer::DynIOBuffer(uint64_t max_incl)
: m_buf(wuffs_base__empty_io_buffer()), m_max_incl(max_incl) {}
DynIOBuffer::~DynIOBuffer() {
if (m_buf.data.ptr) {
free(m_buf.data.ptr);
}
}
void //
DynIOBuffer::drop() {
if (m_buf.data.ptr) {
free(m_buf.data.ptr);
}
m_buf = wuffs_base__empty_io_buffer();
}
DynIOBuffer::GrowResult //
DynIOBuffer::grow(uint64_t min_incl) {
uint64_t n = round_up(min_incl, m_max_incl);
if (n == 0) {
return ((min_incl == 0) && (m_max_incl == 0))
? DynIOBuffer::GrowResult::OK
: DynIOBuffer::GrowResult::FailedMaxInclExceeded;
} else if (n > m_buf.data.len) {
uint8_t* ptr = static_cast<uint8_t*>(realloc(m_buf.data.ptr, n));
if (!ptr) {
return DynIOBuffer::GrowResult::FailedOutOfMemory;
}
m_buf.data.ptr = ptr;
m_buf.data.len = n;
}
return DynIOBuffer::GrowResult::OK;
}
// round_up rounds min_incl up, returning the smallest value x satisfying
// (min_incl <= x) and (x <= max_incl) and some other constraints. It returns 0
// if there is no such x.
//
// When max_incl <= 4096, the other constraints are:
// - (x == max_incl)
//
// When max_incl > 4096, the other constraints are:
// - (x == max_incl) or (x is a power of 2)
// - (x >= 4096)
uint64_t //
DynIOBuffer::round_up(uint64_t min_incl, uint64_t max_incl) {
if (min_incl > max_incl) {
return 0;
}
uint64_t n = 4096;
if (n >= max_incl) {
return max_incl;
}
while (n < min_incl) {
if (n >= (max_incl / 2)) {
return max_incl;
}
n *= 2;
}
return n;
}
// --------
Input::~Input() {}
IOBuffer* //
@@ -39311,6 +42357,164 @@ MemoryInput::CopyIn(IOBuffer* dst) {
} // namespace sync_io
namespace private_impl {
struct ErrorMessages {
const char* max_incl_metadata_length_exceeded;
const char* out_of_memory;
const char* unexpected_end_of_file;
const char* unsupported_metadata;
const char* unsupported_negative_advance;
// If adding new "const char*" typed fields to this struct, either add them
// after existing fields or, if re-ordering fields, make sure that you update
// all of the "const private_impl::ErrorMessages FooBarErrorMessages" values
// in all of the sibling *.cc files.
static inline const char* resolve(const char* s) {
return s ? s : "wuffs_aux::private_impl: unknown error";
};
};
std::string //
AdvanceIOBufferTo(const ErrorMessages& error_messages,
sync_io::Input& input,
IOBuffer& io_buf,
uint64_t absolute_position) {
if (absolute_position < io_buf.reader_position()) {
return error_messages.resolve(error_messages.unsupported_negative_advance);
}
while (true) {
uint64_t relative_position = absolute_position - io_buf.reader_position();
if (relative_position <= io_buf.reader_length()) {
io_buf.meta.ri += (size_t)relative_position;
break;
} else if (io_buf.meta.closed) {
return error_messages.resolve(error_messages.unexpected_end_of_file);
}
io_buf.meta.ri = io_buf.meta.wi;
if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
return "";
}
std::string //
HandleMetadata(
const ErrorMessages& error_messages,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
sync_io::DynIOBuffer& raw,
wuffs_base__status (*tell_me_more_func)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*),
void* tell_me_more_receiver,
std::string (*handle_metadata_func)(void*,
const wuffs_base__more_information*,
wuffs_base__slice_u8),
void* handle_metadata_receiver) {
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
// Reset raw but keep its backing array (the raw.m_buf.data slice).
raw.m_buf.meta = wuffs_base__empty_io_buffer_meta();
while (true) {
minfo = wuffs_base__empty_more_information();
wuffs_base__status status = (*tell_me_more_func)(
tell_me_more_receiver, &raw.m_buf, &minfo, &io_buf);
switch (minfo.flavor) {
case 0:
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM:
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED:
break;
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH: {
wuffs_base__range_ie_u64 r = minfo.metadata_raw_passthrough__range();
if (r.is_empty()) {
break;
}
uint64_t num_to_copy = r.length();
if (num_to_copy > (raw.m_max_incl - raw.m_buf.meta.wi)) {
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
} else if (num_to_copy > (raw.m_buf.data.len - raw.m_buf.meta.wi)) {
switch (raw.grow(num_to_copy + raw.m_buf.meta.wi)) {
case sync_io::DynIOBuffer::GrowResult::OK:
break;
case sync_io::DynIOBuffer::GrowResult::FailedMaxInclExceeded:
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
case sync_io::DynIOBuffer::GrowResult::FailedOutOfMemory:
return error_messages.resolve(error_messages.out_of_memory);
}
}
if (io_buf.reader_position() > r.min_incl) {
return error_messages.resolve(error_messages.unsupported_metadata);
} else {
std::string error_message =
AdvanceIOBufferTo(error_messages, input, io_buf, r.min_incl);
if (!error_message.empty()) {
return error_message;
}
}
while (true) {
uint64_t n =
wuffs_base__u64__min(num_to_copy, io_buf.reader_length());
memcpy(raw.m_buf.writer_pointer(), io_buf.reader_pointer(), n);
raw.m_buf.meta.wi += n;
io_buf.meta.ri += n;
num_to_copy -= n;
if (num_to_copy == 0) {
break;
} else if (io_buf.meta.closed) {
return error_messages.resolve(
error_messages.unexpected_end_of_file);
} else if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
break;
}
default:
return error_messages.resolve(error_messages.unsupported_metadata);
}
if (status.repr == nullptr) {
break;
} else if (status.repr != wuffs_base__suspension__even_more_information) {
if (status.repr != wuffs_base__suspension__short_write) {
return status.message();
}
switch (raw.grow(wuffs_base__u64__sat_add(raw.m_buf.data.len, 1))) {
case sync_io::DynIOBuffer::GrowResult::OK:
break;
case sync_io::DynIOBuffer::GrowResult::FailedMaxInclExceeded:
return error_messages.resolve(
error_messages.max_incl_metadata_length_exceeded);
case sync_io::DynIOBuffer::GrowResult::FailedOutOfMemory:
return error_messages.resolve(error_messages.out_of_memory);
}
}
}
return (*handle_metadata_func)(handle_metadata_receiver, &minfo,
raw.m_buf.reader_slice());
}
} // namespace private_impl
} // namespace wuffs_aux
#endif // !defined(WUFFS_CONFIG__MODULES) ||
@@ -39336,10 +42540,21 @@ DecodeCborCallbacks::Done(DecodeCborResult& result,
sync_io::Input& input,
IOBuffer& buffer) {}
DecodeCborArgQuirks::DecodeCborArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeCborArgQuirks::DecodeCborArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeCborArgQuirks //
DecodeCborArgQuirks::DefaultValue() {
return DecodeCborArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeCborResult //
DecodeCbor(DecodeCborCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks) {
DecodeCborArgQuirks quirks) {
// Prepare the wuffs_base__io_buffer and the resultant error_message.
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
@@ -39362,8 +42577,8 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
ret_error_message = "wuffs_aux::DecodeCbor: out of memory";
goto done;
}
for (size_t i = 0; i < quirks.len; i++) {
dec->set_quirk_enabled(quirks.ptr[i], true);
for (size_t i = 0; i < quirks.repr.len; i++) {
dec->set_quirk_enabled(quirks.repr.ptr[i], true);
}
// Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.
@@ -39748,6 +42963,12 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_base__image_decoder::unique_ptr(nullptr, &free);
}
std::string //
DecodeImageCallbacks::HandleMetadata(const wuffs_base__more_information& minfo,
wuffs_base__slice_u8 raw) {
return "";
}
wuffs_base__pixel_format //
DecodeImageCallbacks::SelectPixfmt(
const wuffs_base__image_config& image_config) {
@@ -39812,12 +43033,16 @@ const char DecodeImage_BufferIsTooShort[] = //
"wuffs_aux::DecodeImage: buffer is too short";
const char DecodeImage_MaxInclDimensionExceeded[] = //
"wuffs_aux::DecodeImage: max_incl_dimension exceeded";
const char DecodeImage_MaxInclMetadataLengthExceeded[] = //
"wuffs_aux::DecodeImage: max_incl_metadata_length exceeded";
const char DecodeImage_OutOfMemory[] = //
"wuffs_aux::DecodeImage: out of memory";
const char DecodeImage_UnexpectedEndOfFile[] = //
"wuffs_aux::DecodeImage: unexpected end of file";
const char DecodeImage_UnsupportedImageFormat[] = //
"wuffs_aux::DecodeImage: unsupported image format";
const char DecodeImage_UnsupportedMetadata[] = //
"wuffs_aux::DecodeImage: unsupported metadata";
const char DecodeImage_UnsupportedPixelBlend[] = //
"wuffs_aux::DecodeImage: unsupported pixel blend";
const char DecodeImage_UnsupportedPixelConfiguration[] = //
@@ -39825,38 +43050,105 @@ const char DecodeImage_UnsupportedPixelConfiguration[] = //
const char DecodeImage_UnsupportedPixelFormat[] = //
"wuffs_aux::DecodeImage: unsupported pixel format";
DecodeImageArgQuirks::DecodeImageArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeImageArgQuirks::DecodeImageArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeImageArgQuirks //
DecodeImageArgQuirks::DefaultValue() {
return DecodeImageArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeImageArgFlags::DecodeImageArgFlags(uint64_t repr0) : repr(repr0) {}
DecodeImageArgFlags //
DecodeImageArgFlags::DefaultValue() {
return DecodeImageArgFlags(0);
}
DecodeImageArgPixelBlend::DecodeImageArgPixelBlend(
wuffs_base__pixel_blend repr0)
: repr(repr0) {}
DecodeImageArgPixelBlend //
DecodeImageArgPixelBlend::DefaultValue() {
return DecodeImageArgPixelBlend(WUFFS_BASE__PIXEL_BLEND__SRC);
}
DecodeImageArgBackgroundColor::DecodeImageArgBackgroundColor(
wuffs_base__color_u32_argb_premul repr0)
: repr(repr0) {}
DecodeImageArgBackgroundColor //
DecodeImageArgBackgroundColor::DefaultValue() {
return DecodeImageArgBackgroundColor(1);
}
DecodeImageArgMaxInclDimension::DecodeImageArgMaxInclDimension(uint32_t repr0)
: repr(repr0) {}
DecodeImageArgMaxInclDimension //
DecodeImageArgMaxInclDimension::DefaultValue() {
return DecodeImageArgMaxInclDimension(1048575);
}
DecodeImageArgMaxInclMetadataLength::DecodeImageArgMaxInclMetadataLength(
uint64_t repr0)
: repr(repr0) {}
DecodeImageArgMaxInclMetadataLength //
DecodeImageArgMaxInclMetadataLength::DefaultValue() {
return DecodeImageArgMaxInclMetadataLength(16777215);
}
// --------
namespace {
const private_impl::ErrorMessages DecodeImageErrorMessages = {
DecodeImage_MaxInclMetadataLengthExceeded, //
DecodeImage_OutOfMemory, //
DecodeImage_UnexpectedEndOfFile, //
DecodeImage_UnsupportedMetadata, //
DecodeImage_UnsupportedImageFormat, //
};
std::string //
DecodeImageAdvanceIOBuf(sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
bool compactable,
uint64_t min_excl_pos,
uint64_t pos) {
if ((pos <= min_excl_pos) || (pos < io_buf.reader_position())) {
// Redirects must go forward.
return DecodeImage_UnsupportedImageFormat;
}
while (true) {
uint64_t relative_pos = pos - io_buf.reader_position();
if (relative_pos <= io_buf.reader_length()) {
io_buf.meta.ri += (size_t)relative_pos;
break;
} else if (io_buf.meta.closed) {
return DecodeImage_UnexpectedEndOfFile;
}
io_buf.meta.ri = io_buf.meta.wi;
if (compactable) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
}
return "";
DecodeImageAdvanceIOBufferTo(sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
uint64_t absolute_position) {
return private_impl::AdvanceIOBufferTo(DecodeImageErrorMessages, input,
io_buf, absolute_position);
}
wuffs_base__status //
DIHM0(void* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_base__image_decoder__tell_me_more(
static_cast<wuffs_base__image_decoder*>(self), a_dst, a_minfo, a_src);
}
std::string //
DIHM1(void* self,
const wuffs_base__more_information* minfo,
wuffs_base__slice_u8 raw) {
return static_cast<DecodeImageCallbacks*>(self)->HandleMetadata(*minfo, raw);
}
std::string //
DecodeImageHandleMetadata(wuffs_base__image_decoder::unique_ptr& image_decoder,
DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
sync_io::DynIOBuffer& raw_metadata_buf) {
return private_impl::HandleMetadata(DecodeImageErrorMessages, input, io_buf,
raw_metadata_buf, DIHM0,
static_cast<void*>(image_decoder.get()),
DIHM1, static_cast<void*>(&callbacks));
}
DecodeImageResult //
@@ -39864,9 +43156,12 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__io_buffer& io_buf,
wuffs_base__slice_u32 quirks,
uint64_t flags,
wuffs_base__pixel_blend pixel_blend,
wuffs_base__color_u32_argb_premul background_color,
uint32_t max_incl_dimension) {
uint32_t max_incl_dimension,
uint64_t max_incl_metadata_length) {
// Check args.
switch (pixel_blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -39877,6 +43172,7 @@ DecodeImage0(wuffs_base__image_decoder::unique_ptr& image_decoder,
}
wuffs_base__image_config image_config = wuffs_base__null_image_config();
sync_io::DynIOBuffer raw_metadata_buf(max_incl_metadata_length);
uint64_t start_pos = io_buf.reader_position();
bool redirected = false;
int32_t fourcc = 0;
@@ -39911,8 +43207,12 @@ redirect:
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
uint64_t pos = minfo.io_redirect__range().min_incl;
std::string error_message = DecodeImageAdvanceIOBuf(
input, io_buf, !input.BringsItsOwnIOBuffer(), start_pos, pos);
if (pos <= start_pos) {
// Redirects must go forward.
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
std::string error_message =
DecodeImageAdvanceIOBufferTo(input, io_buf, pos);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -39931,6 +43231,36 @@ redirect:
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
}
// Apply quirks.
for (size_t i = 0; i < quirks.len; i++) {
image_decoder->set_quirk_enabled(quirks.ptr[i], true);
}
// Apply flags.
if (flags != 0) {
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_ICCP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__ICCP, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_KVP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__KVP, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_SRGB) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__SRGB, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_XMP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__XMP, true);
}
}
// Decode the image config.
while (true) {
wuffs_base__status id_dic_status =
@@ -39943,6 +43273,12 @@ redirect:
}
redirected = true;
goto redirect;
} else if (id_dic_status.repr == wuffs_base__note__metadata_reported) {
std::string error_message = DecodeImageHandleMetadata(
image_decoder, callbacks, input, io_buf, raw_metadata_buf);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
} else if (id_dic_status.repr != wuffs_base__suspension__short_read) {
return DecodeImageResult(id_dic_status.message());
} else if (io_buf.meta.closed) {
@@ -39955,6 +43291,7 @@ redirect:
}
}
} while (false);
raw_metadata_buf.drop();
// Select the pixel format.
uint32_t w = image_config.pixcfg.width();
@@ -40065,9 +43402,12 @@ redirect:
DecodeImageResult //
DecodeImage(DecodeImageCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__pixel_blend pixel_blend,
wuffs_base__color_u32_argb_premul background_color,
uint32_t max_incl_dimension) {
DecodeImageArgQuirks quirks,
DecodeImageArgFlags flags,
DecodeImageArgPixelBlend pixel_blend,
DecodeImageArgBackgroundColor background_color,
DecodeImageArgMaxInclDimension max_incl_dimension,
DecodeImageArgMaxInclMetadataLength max_incl_metadata_length) {
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
std::unique_ptr<uint8_t[]> fallback_io_array(nullptr);
@@ -40080,8 +43420,9 @@ DecodeImage(DecodeImageCallbacks& callbacks,
wuffs_base__image_decoder::unique_ptr image_decoder(nullptr, &free);
DecodeImageResult result =
DecodeImage0(image_decoder, callbacks, input, *io_buf, pixel_blend,
background_color, max_incl_dimension);
DecodeImage0(image_decoder, callbacks, input, *io_buf, quirks.repr,
flags.repr, pixel_blend.repr, background_color.repr,
max_incl_dimension.repr, max_incl_metadata_length.repr);
callbacks.Done(result, input, *io_buf, std::move(image_decoder));
return result;
}
@@ -40116,6 +43457,25 @@ const char DecodeJson_BadJsonPointer[] = //
const char DecodeJson_NoMatch[] = //
"wuffs_aux::DecodeJson: no match";
DecodeJsonArgQuirks::DecodeJsonArgQuirks(wuffs_base__slice_u32 repr0)
: repr(repr0) {}
DecodeJsonArgQuirks::DecodeJsonArgQuirks(uint32_t* ptr0, size_t len0)
: repr(wuffs_base__make_slice_u32(ptr0, len0)) {}
DecodeJsonArgQuirks //
DecodeJsonArgQuirks::DefaultValue() {
return DecodeJsonArgQuirks(wuffs_base__empty_slice_u32());
}
DecodeJsonArgJsonPointer::DecodeJsonArgJsonPointer(std::string repr0)
: repr(repr0) {}
DecodeJsonArgJsonPointer //
DecodeJsonArgJsonPointer::DefaultValue() {
return DecodeJsonArgJsonPointer(std::string());
}
// --------
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
@@ -40421,8 +43781,8 @@ done:
DecodeJsonResult //
DecodeJson(DecodeJsonCallbacks& callbacks,
sync_io::Input& input,
wuffs_base__slice_u32 quirks,
std::string json_pointer) {
DecodeJsonArgQuirks quirks,
DecodeJsonArgJsonPointer json_pointer) {
// Prepare the wuffs_base__io_buffer and the resultant error_message.
wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();
wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();
@@ -40450,9 +43810,9 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
goto done;
}
bool allow_tilde_n_tilde_r_tilde_t = false;
for (size_t i = 0; i < quirks.len; i++) {
dec->set_quirk_enabled(quirks.ptr[i], true);
if (quirks.ptr[i] ==
for (size_t i = 0; i < quirks.repr.len; i++) {
dec->set_quirk_enabled(quirks.repr.ptr[i], true);
if (quirks.repr.ptr[i] ==
WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {
allow_tilde_n_tilde_r_tilde_t = true;
}
@@ -40471,13 +43831,13 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
std::string str;
// Walk the (optional) JSON Pointer.
for (size_t i = 0; i < json_pointer.size();) {
if (json_pointer[i] != '/') {
for (size_t i = 0; i < json_pointer.repr.size();) {
if (json_pointer.repr[i] != '/') {
ret_error_message = DecodeJson_BadJsonPointer;
goto done;
}
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
json_pointer.repr, i + 1, allow_tilde_n_tilde_r_tilde_t);
i = split.second;
if (i == 0) {
ret_error_message = DecodeJson_BadJsonPointer;
@@ -40638,7 +43998,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
// decode_tokens returns an ok status.
if (!ret_error_message.empty() ||
((depth == 0) && !json_pointer.empty())) {
((depth == 0) && !json_pointer.repr.empty())) {
goto done;
}
}
+1 -2
View File
@@ -175,9 +175,8 @@ main(int argc, char** argv) {
// https://play.golang.org/p/IU2T58P00C
const uint32_t expected_hash_of_1mib_of_zeroes = 0x00f00001UL;
int i;
int num_bad = 0;
for (i = 0; i < num_reps; i++) {
for (int i = 0; i < num_reps; i++) {
uint32_t actual_hash = calculate_hash(g_buffer, BUFFER_SIZE);
if (!g_flags.no_check && (actual_hash != expected_hash_of_1mib_of_zeroes)) {
num_bad++;
+3 -5
View File
@@ -330,8 +330,7 @@ decode(bool frag_dst, bool frag_idat) {
struct timeval bench_start_tv;
gettimeofday(&bench_start_tv, NULL);
int i;
for (i = 0; i < reps; i++) {
for (int i = 0; i < reps; i++) {
const char* msg = decode_once(frag_dst, frag_idat);
if (msg) {
return msg;
@@ -397,10 +396,9 @@ main(int argc, char** argv) {
"compatible with the\n"
"# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install "
"it, first\n"
"# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
"# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
int i;
for (i = 0; i < 5; i++) {
for (int i = 0; i < 5; i++) {
msg = decode(true, true);
if (msg) {
return fail(msg);
+1 -1
View File
@@ -81,7 +81,7 @@ func main1() error {
fmt.Printf("#\n")
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
for i := -1; i < reps; i++ {
for _, tc := range testCases {
+1 -1
View File
@@ -106,7 +106,7 @@ func main1() error {
fmt.Printf("#\n")
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
for i := -1; i < reps; i++ {
for _, tc := range testCases {
+1 -1
View File
@@ -90,7 +90,7 @@ func main1() error {
fmt.Printf("#\n")
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
for i := -1; i < reps; i++ {
for _, tc := range testCases {
+12 -2
View File
@@ -32,9 +32,19 @@ save=`git log -1 --pretty=format:"%H"`
i=0
while [ $i -lt $num_commits ]; do
this_hash=`git log -1 --pretty=format:"%h"`
set +e
$cc -O3 -o bench-history.out test/c/std/$package.c
this_metric=`./bench-history.out -bench -focus=$focus -iterscale=$iterscale -reps=$reps | benchstat /dev/stdin | sed -ne '/^name.*speed$/,$ p' | grep $focus`
if [ $? -ne 0 ]; then
this_metric='compile_failed'
else
this_metric=`./bench-history.out -bench -focus=$focus -iterscale=$iterscale -reps=$reps | benchstat /dev/stdin | sed -ne '/^name.*speed$/,$ p' | grep $focus`
if [ $? -ne 0 ]; then
this_metric='bench_failed'
fi
fi
set -e
this_hash=`git log -1 --pretty=format:"%h"`
echo $this_hash $this_metric
git checkout --quiet HEAD^
i=$((i + 1))
+1 -1
View File
@@ -47,7 +47,7 @@ fn main() {
print!("#\n");
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
let mut dst = vec![0u8; 64 * 1024 * 1024];
+1 -1
View File
@@ -52,7 +52,7 @@ fn main() {
print!("#\n");
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
let mut dst = vec![0u8; 64 * 1024 * 1024];
+1 -1
View File
@@ -45,7 +45,7 @@ fn main() {
print!("#\n");
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
let mut dst0 = vec![0u8; 64 * 1024 * 1024];
let mut dst1 = vec![0u8; 64 * 1024 * 1024];
+192
View File
@@ -0,0 +1,192 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build ignore
// +build ignore
package main
// extract-nia-frames.go extracts the individual frames from a NIA animation,
// writing them out as NIE images.
//
// Usage: go run extract-nia-frames.go foo.nia bar/baz.nia
//
// This will write new files:
// - foo.000000.nie
// - foo.000001.nie
// - foo.000002.nie
// - foo.000003.nie
// - etc
// - bar/baz.000000.nie
// - bar/baz.000001.nie
// - etc
import (
"bufio"
"errors"
"flag"
"fmt"
"io"
"os"
"path/filepath"
)
var (
dryRun = flag.Bool("dry-run", false, "just print metadata; don't write NIE files")
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
flag.Parse()
for _, a := range flag.Args() {
if err := extract(a); err != nil {
return err
}
}
return nil
}
func extract(srcFilename string) error {
fmt.Printf("Extract %s\n", srcFilename)
f, err := os.Open(srcFilename)
if err != nil {
return err
}
defer f.Close()
r := bufio.NewReader(f)
dstFilenamePrefix := srcFilename[:len(srcFilename)-len(filepath.Ext(srcFilename))]
buf := [16]byte{}
if _, err := io.ReadFull(r, buf[:16]); err != nil {
return err
}
depth8 := buf[7] == '8'
width := u32le(buf[8:])
height := u32le(buf[12:])
padded := !depth8 && ((width & 1) != 0) && ((height & 1) != 0)
if (u32le(buf[:]) != 0x41AF_C36E) || // 0x41AF_C36E is 'nïA'le.
(buf[4] != 0xFF) ||
(buf[5] != 'b') ||
((buf[6] != 'n') && (buf[6] != 'p')) ||
((buf[7] != '4') && (buf[7] != '8')) ||
(width >= 0x8000_0000) ||
(height >= 0x8000_0000) {
return errors.New("bad NIA header")
}
fmt.Printf(" Config v1-b%c%c\n", buf[6], buf[7])
fmt.Printf(" Width %d\n", width)
fmt.Printf(" Height %d\n", height)
nieSize := calculateNIESize(depth8, width, height)
if nieSize < 0 {
return errors.New("unsupported NIA (image dimensions are too large)")
}
prevCDD := uint64(0)
for frameIndex := uint64(0); ; frameIndex++ {
if _, err := io.ReadFull(r, buf[:8]); err != nil {
return err
}
cdd := u64le(buf[:])
if (cdd >> 32) == 0x8000_0000 {
fmt.Printf(" LoopCount %d\n", uint32(cdd))
break
} else if ((cdd >> 32) > 0x8000_0000) || (cdd < prevCDD) {
return errors.New("bad CDD (Cumulative Display Duration)")
}
fmt.Printf(" CDD %16d flicks = %8g seconds; delta = %8g seconds\n",
cdd,
float64(cdd)/705_600000,
float64(cdd-prevCDD)/705_600000,
)
prevCDD = cdd
dstFilename := fmt.Sprintf("%s.%06d.nie", dstFilenamePrefix, frameIndex)
if err := extract1(dstFilename, r, int64(nieSize)); err != nil {
return err
}
if padded {
if _, err := io.ReadFull(r, buf[:4]); err != nil {
return err
} else if u32le(buf[:]) != 0 {
return errors.New("bad padding")
}
}
}
return nil
}
func calculateNIESize(depth8 bool, width uint32, height uint32) int64 {
const maxInt64 = (1 << 63) - 1
const maxUint64 = (1 << 64) - 1
n := uint64(width) * uint64(height) * 4
if depth8 {
if n > (maxUint64 / 2) {
return -1
}
n *= 2
}
if n > (maxInt64 - 16) {
return -1
}
return int64(n + 16)
}
func extract1(dstFilename string, r *bufio.Reader, nieSize int64) error {
if *dryRun {
fmt.Printf(" DryRun %s\n", dstFilename)
_, err := io.CopyN(io.Discard, r, nieSize)
return err
}
fmt.Printf(" Write %s\n", dstFilename)
f, err := os.Create(dstFilename)
if err != nil {
return err
}
_, err1 := io.CopyN(f, r, nieSize)
err2 := f.Close()
if err1 != nil {
return err1
}
return err2
}
func u32le(b []byte) uint32 {
return (uint32(b[0]) << 0) |
(uint32(b[1]) << 8) |
(uint32(b[2]) << 16) |
(uint32(b[3]) << 24)
}
func u64le(b []byte) uint64 {
return (uint64(b[0]) << 0) |
(uint64(b[1]) << 8) |
(uint64(b[2]) << 16) |
(uint64(b[3]) << 24) |
(uint64(b[4]) << 32) |
(uint64(b[5]) << 40) |
(uint64(b[6]) << 48) |
(uint64(b[7]) << 56)
}
+117 -8
View File
@@ -26,7 +26,9 @@ package main
import (
"bytes"
"compress/lzw"
"compress/zlib"
"fmt"
"hash/crc32"
"io"
"os"
"strconv"
@@ -138,6 +140,10 @@ func appendU16LE(b []byte, u uint16) []byte {
return append(b, uint8(u), uint8(u>>8))
}
func appendU32BE(b []byte, u uint32) []byte {
return append(b, uint8(u>>24), uint8(u>>16), uint8(u>>8), uint8(u))
}
func log2(u uint32) (i int32) {
for i, pow := uint32(0), uint32(1); i < 32; i, pow = i+1, pow<<1 {
if u == pow {
@@ -581,20 +587,20 @@ func stateDeflateDynamicHuffman(line string) (stateFunc, error) {
return stateDeflateDynamicHuffman, nil
} else if l, d, ok := deflateParseLenDist(line); ok {
if (l != 3) || (d != 2) {
return nil, fmt.Errorf("TODO: support len/dist pairs for dynamic Huffman blocks")
if (l > 10) || (d > 4) {
return nil, fmt.Errorf("TODO: support len/dist ExtraBits > 0 for dynamic Huffman blocks")
}
// len 3 is code 257, with no extra bits.
if s := g.huffmans[2][257]; s != "" {
// len 3 is code 257, len 4 is code 258, etc. All with no ExtraBits.
if s := g.huffmans[2][l+254]; s != "" {
deflateGlobalsWriteDynamicHuffmanBits(s)
} else {
return nil, fmt.Errorf("no code for literal/length symbol 257")
return nil, fmt.Errorf("no code for literal/length symbol %d", l+254)
}
// dist 2 is code 1, with no extra bits.
if s := g.huffmans[3][1]; s != "" {
// dist 1 is code 0, dist 2 is code 1, etc. All with no ExtraBits.
if s := g.huffmans[3][d-1]; s != "" {
deflateGlobalsWriteDynamicHuffmanBits(s)
} else {
return nil, fmt.Errorf("no code for distance symbol 2")
return nil, fmt.Errorf("no code for distance symbol %d", d-1)
}
return stateDeflateDynamicHuffman, nil
@@ -1220,3 +1226,106 @@ func stateGifFramePalette(line string) (stateFunc, error) {
return nil, fmt.Errorf("bad stateGifFramePalette command: %q", line)
}
// ----
func init() {
formats["png"] = statePng
}
var pngGlobals struct {
scratch [4]byte
animSeqNum uint32
chunkData bytes.Buffer
chunkType string
zlibWriter *zlib.Writer
}
func statePng(line string) (stateFunc, error) {
g := &pngGlobals
switch {
case line == "":
return statePng, nil
case line == "magic":
out = append(out, "\x89PNG\x0D\x0A\x1A\x0A"...)
return statePng, nil
case (len(line) == 6) && (line[4] == ' ') && (line[5] == '{'):
g.chunkData.Reset()
g.chunkType = line[:4]
return statePngChunk, nil
}
return nil, fmt.Errorf("bad statePng command: %q", line)
}
func statePngChunk(line string) (stateFunc, error) {
g := &pngGlobals
if line == "}" {
if n := g.chunkData.Len(); n > 0xFFFF_FFFF {
return nil, fmt.Errorf("chunkData is too long")
}
out = appendU32BE(out, uint32(g.chunkData.Len()))
n := len(out)
out = append(out, g.chunkType...)
out = append(out, g.chunkData.Bytes()...)
out = appendU32BE(out, crc32.ChecksumIEEE(out[n:]))
return statePng, nil
}
switch {
case line == "animSeqNum++":
g.chunkData.Write(appendU32BE(g.scratch[:0], g.animSeqNum))
g.animSeqNum++
return statePngChunk, nil
case line == "raw {":
return statePngRaw, nil
case line == "zlib {":
g.zlibWriter = zlib.NewWriter(&g.chunkData)
return statePngZlib, nil
}
return nil, fmt.Errorf("bad statePngChunk command: %q", line)
}
func statePngRaw(line string) (stateFunc, error) {
g := &pngGlobals
if line == "}" {
return statePngChunk, nil
}
for s := line; s != ""; {
if x, remaining, ok := parseHex(s); ok {
g.chunkData.WriteByte(byte(x))
s = remaining
} else {
return nil, fmt.Errorf("bad statePngRaw command: %q", line)
}
}
return statePngRaw, nil
}
func statePngZlib(line string) (stateFunc, error) {
g := &pngGlobals
if line == "}" {
if err := g.zlibWriter.Close(); err != nil {
return nil, fmt.Errorf("statePngZlib: %w", err)
}
return statePngChunk, nil
}
for s := line; s != ""; {
if x, remaining, ok := parseHex(s); ok {
g.scratch[0] = byte(x)
g.zlibWriter.Write(g.scratch[:1])
s = remaining
} else {
return nil, fmt.Errorf("bad statePngZlib command: %q", line)
}
}
return statePngZlib, nil
}
+181
View File
@@ -0,0 +1,181 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build ignore
// +build ignore
package main
// make-red-blue-gradient.go makes a simple PNG image with optional color
// correction chunks.
//
// Usage: go run make-red-blue-gradient.go > foo.png
import (
"bytes"
"compress/zlib"
"errors"
"flag"
"hash/crc32"
"image"
"image/color"
"image/png"
"math"
"os"
"path/filepath"
"strings"
)
var (
checkerboard = flag.Bool("checkerboard", false, "Create a checkerboard pattern instead")
gama = flag.Float64("gama", 0, "Gamma correction value (e.g. 2.2)")
iccp = flag.String("iccp", "", "ICC filename (e.g. foo/bar.icc)")
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
flag.Parse()
// Make a checkerboard or red-blue gradient.
src := image.Image(nil)
if *checkerboard {
// With -gama=1.0 (or -gama=2.2), the two halves of this image should
// have roughly equal (or un-equal) brightness.
m := image.NewGray(image.Rect(0, 0, 256, 256))
for y := 0; y < 256; y++ {
for x := 0; x < 256; x++ {
if x < 128 {
m.SetGray(x, y, color.Gray{0x80})
} else if ((x ^ y) & 1) == 1 {
m.SetGray(x, y, color.Gray{0xFF})
} else {
m.SetGray(x, y, color.Gray{0x00})
}
}
}
src = m
} else {
m := image.NewRGBA(image.Rect(0, 0, 256, 256))
for y := 0; y < 256; y++ {
for x := 0; x < 256; x++ {
m.SetRGBA(x, y, color.RGBA{
R: uint8(x),
G: 0x00,
B: uint8(y),
A: 0xFF,
})
}
}
src = m
}
// Encode to PNG.
buf := &bytes.Buffer{}
png.Encode(buf, src)
original := buf.Bytes()
// Split the encoding into a magic+IHDR prefix and an IDAT+IEND suffix. The
// starting magic number is 8 bytes long. The IHDR chunk is 25 bytes long.
prefix, suffix := original[:33], original[33:]
out := []byte(nil)
out = append(out, prefix...)
// Insert the optional chunks between the prefix and suffix.
if *gama > 0 {
g := uint32(math.Round(100000 / *gama))
out = appendPNGChunk(out, "gAMA",
byte(g>>24),
byte(g>>16),
byte(g>>8),
byte(g>>0),
)
}
if *iccp != "" {
raw, err := os.ReadFile(*iccp)
if err != nil {
return err
}
name, err := iccpName(*iccp)
if err != nil {
return err
}
data := &bytes.Buffer{}
data.WriteString(name)
data.WriteByte(0x00) // The name is NUL terminated.
data.WriteByte(0x00) // 0x00 means zlib compression.
w := zlib.NewWriter(data)
w.Write(raw)
w.Close()
out = appendPNGChunk(out, "iCCP", data.Bytes()...)
}
// Append the suffix and write to stdout.
out = append(out, suffix...)
_, err := os.Stdout.Write(out)
return err
}
func appendPNGChunk(b []byte, name string, chunk ...byte) []byte {
n := uint32(len(chunk))
b = append(b,
byte(n>>24),
byte(n>>16),
byte(n>>8),
byte(n>>0),
)
b = append(b, name...)
b = append(b, chunk...)
hasher := crc32.NewIEEE()
hasher.Write([]byte(name))
hasher.Write(chunk)
c := hasher.Sum32()
return append(b,
byte(c>>24),
byte(c>>16),
byte(c>>8),
byte(c>>0),
)
}
// iccpName determines a "bar" iCCP profile name (that satisifes the PNG
// specification re the iCCP chunk) based on the "foo/bar.icc" filename.
func iccpName(filename string) (string, error) {
s := filepath.Base(filename)
if i := strings.IndexByte(s, '.'); i >= 0 {
s = s[:i]
}
s = strings.TrimSpace(s)
if strings.Index(s, " ") >= 0 {
return "", errors.New("ICCP name cannot contain consecutive spaces")
} else if (len(s) < 1) || (79 < len(s)) {
return "", errors.New("ICCP name has invalid length.")
}
for i := 0; i < len(s); i++ {
if (s[i] < ' ') || ('~' < s[i]) {
// Strictly speaking, the PNG specification allows the iCCP name to
// be printable Latin-1, not just printable ASCII, but printable
// ASCII is easier and avoids any later Latin-1 vs UTF-8 ambiguity.
return "", errors.New("ICCP name is not printable ASCII")
}
}
return s, nil
}
+1 -2
View File
@@ -312,8 +312,7 @@ main1(int argc, char** argv) {
WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE,
0,
};
uint32_t i;
for (i = 0; quirks[i]; i++) {
for (uint32_t i = 0; quirks[i]; i++) {
wuffs_base__token_decoder__set_quirk_enabled(g_dec, quirks[i], true);
}
}
+1 -1
View File
@@ -64,7 +64,7 @@ for f in $sources; do
if [ -f $f ]; then
handle $f
elif [ -d $f ]; then
for g in `find $f -type f | sort`; do
for g in `find $f -type f | LANG=C sort`; do
handle $g
done
else
+57
View File
@@ -0,0 +1,57 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build ignore
// +build ignore
package main
// print-png-latin-1.go prints the UTF-8 encoding of the std/png Latin-1 table.
//
// Usage: go run print-png-latin-1.go
import (
"fmt"
"os"
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
// The PNG spec (https://www.w3.org/TR/PNG/) says "*printable* [emphasis
// added] Latin-1 characters and spaces (only character codes 32-126 and
// 161-255 decimal are allowed)".
//
// See also https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt
for r := rune(0); r <= 0xFF; r++ {
if (r < 32) || ((126 < r) && (r < 161)) {
fmt.Printf(" 0x0000,")
} else if r < 128 {
fmt.Printf(" 0x%04X,", r)
} else {
s := fmt.Sprintf("%c", r)
fmt.Printf(" 0x%02X%02X,", s[1], s[0]) // UTF-8 as little-endian uint16.
}
if r%8 == 7 {
fmt.Println()
}
}
return nil
}
+7 -7
View File
@@ -530,7 +530,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
}
}
dst = tab.row(y: this.dst_y)
dst = tab.row_u32(y: this.dst_y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
@@ -597,7 +597,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
rle_state = this.rle_state
while.outer true {
row = tab.row(y: this.dst_y)
row = tab.row_u32(y: this.dst_y)
if dst_bytes_per_row < row.length() {
row = row[.. dst_bytes_per_row]
}
@@ -771,7 +771,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
if this.dst_y >= this.height {
return "#bad RLE compression"
}
row = tab.row(y: this.dst_y)
row = tab.row_u32(y: this.dst_y)
if dst_bytes_per_row < row.length() {
row = row[.. dst_bytes_per_row]
}
@@ -801,7 +801,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
} endwhile.outer
while this.dst_y < this.height {
row = tab.row(y: this.dst_y)
row = tab.row_u32(y: this.dst_y)
if dst_bytes_per_row < row.length() {
row = row[.. dst_bytes_per_row]
}
@@ -921,7 +921,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
} endwhile
// -------- END convert to PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE.
dst = tab.row(y: this.dst_y)
dst = tab.row_u32(y: this.dst_y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
@@ -983,7 +983,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
}
}
dst = tab.row(y: this.dst_y)
dst = tab.row_u32(y: this.dst_y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
@@ -1151,7 +1151,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
}
if args.minfo <> nullptr {
args.minfo.set!(
flavor: 1, // WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_REDIRECT
flavor: base.MORE_INFORMATION__FLAVOR__IO_REDIRECT,
w: this.io_redirect_fourcc,
x: 0,
y: this.io_redirect_pos,
+11 -7
View File
@@ -628,17 +628,21 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
} endwhile
if remaining <> 0 {
// As a special case, allow a degenerate H-D Huffman table, with only
// one 1-bit code, for the smallest possible distance.
// one 1-bit code.
if (args.which == 1) and (counts[1] == 1) and
(this.code_lengths[args.n_codes0] == 1) and
(((counts[0] as base.u32) + args.n_codes0 + 1) == args.n_codes1) {
this.n_huffs_bits[1] = 1
this.huffs[1][0] = DCODE_MAGIC_NUMBERS[0] | 1
this.huffs[1][1] = DCODE_MAGIC_NUMBERS[31] | 1
return ok
i = 0
while i <= 29 {
if this.code_lengths[args.n_codes0 + i] == 1 {
this.n_huffs_bits[1] = 1
this.huffs[1][0] = DCODE_MAGIC_NUMBERS[i] | 1
this.huffs[1][1] = DCODE_MAGIC_NUMBERS[31] | 1
return ok
}
i += 1
} endwhile
}
return "#bad Huffman code (under-subscribed)"
}
+2 -6
View File
@@ -219,18 +219,14 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
if this.history_index < hdist {
return "#bad distance"
}
// Re-purpose the hdist variable as the this.history index to
// start copying from.
hdist = this.history_index - hdist
// Copy from hdist to the end of this.history.
// Copy from this.history[(this.history_index - hdist) ..].
//
// This copying is simpler than the decode_huffman_slow version
// because it cannot yield. We have already checked that
// args.dst.length() is large enough.
args.dst.limited_copy_u32_from_slice!(
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
if length == 0 {
// No need to copy from args.dst.
continue.loop
+2 -6
View File
@@ -324,18 +324,14 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
if this.history_index < hdist {
return "#bad distance"
}
// Re-purpose the hdist variable as the this.history index to
// start copying from.
hdist = this.history_index - hdist
// Copy from hdist to the end of this.history.
// Copy from this.history[(this.history_index - hdist) ..].
//
// This copying is simpler than the decode_huffman_slow version
// because it cannot yield. We have already checked that
// args.dst.length() is large enough.
args.dst.limited_copy_u32_from_slice!(
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
if length == 0 {
// No need to copy from args.dst.
continue.loop
+2 -6
View File
@@ -218,18 +218,14 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
if this.history_index < hdist {
return "#bad distance"
}
// Re-purpose the hdist variable as the this.history index to
// start copying from.
hdist = this.history_index - hdist
// Copy from hdist to the end of this.history.
// Copy from this.history[(this.history_index - hdist) ..].
//
// This copying is simpler than the decode_huffman_slow version
// because it cannot yield. We have already checked that
// args.dst.length() is large enough.
args.dst.limited_copy_u32_from_slice!(
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
if length == 0 {
// No need to copy from args.dst.
continue.loop
+18 -44
View File
@@ -201,63 +201,38 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
n_bits -= table_entry_n_bits
}
while true {
while.inner true {
// Copy from this.history.
if ((dist_minus_1 + 1) as base.u64) > args.dst.history_length() {
// Set (hlen, hdist) to be the length-distance pair to copy
// from this.history, and (length, distance) to be the
// remaining length-distance pair to copy from args.dst.
// from this.history.
hdist = (((dist_minus_1 + 1) as base.u64) - args.dst.history_length()) as base.u32
if length > hdist {
assert hdist < length via "a < b: b > a"()
if hdist < length {
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c: length)
length -= hdist
hlen = hdist
assert hlen <= length via "a <= b: a == c; c <= b"(c: hdist)
} else {
hlen = length
length = 0
assert hlen <= length via "a <= b: a == b"()
}
hdist ~mod+= ((this.transformed_history_count ~mod- args.dst.history_position()) & 0xFFFF_FFFF) as base.u32
if this.history_index < hdist {
return "#bad distance"
}
// Re-purpose the hdist variable as the this.history index to
// start copying from.
hdist = this.history_index - hdist
// Copy from hdist to the end of this.history.
while true {
n_copied = args.dst.limited_copy_u32_from_slice!(
up_to: hlen, s: this.history[hdist & 0x7FFF .. 0x8000])
if hlen <= n_copied {
hlen = 0
break
}
if n_copied > 0 {
hlen -= n_copied
hdist = (hdist ~mod+ n_copied) & 0x7FFF
if hdist == 0 {
// Wrap around the this.history ringbuffer.
break
}
}
// Copy from this.history[(this.history_index - hdist) ..].
n_copied = args.dst.limited_copy_u32_from_slice!(
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
if n_copied < hlen {
assert n_copied < length via "a < b: a < c; c <= b"(c: hlen)
assert length > n_copied via "a > b: b < a"()
length -= n_copied
yield? base."$short write"
} endwhile
// Copy from the start of this.history, if we wrapped around.
if hlen > 0 {
while true {
n_copied = args.dst.limited_copy_u32_from_slice!(
up_to: hlen, s: this.history[hdist & 0x7FFF .. 0x8000])
if hlen <= n_copied {
hlen = 0
break
}
hlen -= n_copied
hdist ~mod+= n_copied
yield? base."$short write"
} endwhile
continue.inner
}
assert length >= hlen via "a >= b: b <= a"()
length -= hlen
if length == 0 {
// No need to copy from args.dst.
continue.loop
@@ -268,12 +243,11 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
n_copied = args.dst.limited_copy_u32_from_history!(
up_to: length, distance: (dist_minus_1 + 1))
if length <= n_copied {
length = 0
break
continue.loop
}
length -= n_copied
yield? base."$short write"
} endwhile
} endwhile.inner
} endwhile.loop
// TODO: "assert n_bits < 8"? What about (bits >> n_bits)?
+47 -26
View File
@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// --------
pub struct decoder? implements base.image_decoder(
width : base.u32,
height : base.u32,
@@ -40,7 +38,7 @@ pub struct decoder? implements base.image_decoder(
// - 0x00 -> 0x04: via DFC with implicit DIC
// - 0x00 -> 0x05: via DF with implicit DIC and DFC
//
// - 0x01 -> 0x02: via AMC
// - 0x01 -> 0x02: via TMM
//
// - 0x02 -> 0x01: via DIC (metadata reported)
// - 0x02 -> 0x03: via DIC (metadata not reported)
@@ -57,11 +55,11 @@ pub struct decoder? implements base.image_decoder(
// - ???? -> 0x05: via RF for ???? > 0x00
//
// Where:
// - AMC is ack_metadata_chunk
// - DF is decode_frame, implicit means skip_frame
// - DFC is decode_frame_config, implicit means nullptr args.dst
// - DIC is decode_image_config, implicit means nullptr args.dst
// - RF is restart_frame
// - TMM is tell_me_more
call_sequence : base.u8,
ignore_metadata : base.bool,
@@ -84,8 +82,8 @@ pub struct decoder? implements base.image_decoder(
// Absent an ANIMEXTS1.0 or NETSCAPE2.0 extension, the implicit number of
// animation loops is 1.
seen_num_loops : base.bool,
num_loops : base.u32,
seen_num_animation_loops_value : base.bool,
num_animation_loops_value : base.u32,
background_color_u32_argb_premul : base.u32,
black_color_u32_argb_premul : base.u32,
@@ -96,7 +94,8 @@ pub struct decoder? implements base.image_decoder(
// There are 7_056000 flicks per centisecond.
gc_duration : base.u64[..= 0xFFFF * 7_056000],
frame_config_io_position : base.u64,
frame_config_io_position : base.u64,
num_decoded_frame_configs_value : base.u64,
num_decoded_frames_value : base.u64,
@@ -205,7 +204,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
if args.src.position() <> this.metadata_io_position {
if args.minfo <> nullptr {
args.minfo.set!(
flavor: 2, // WUFFS_BASE__MORE_INFORMATION__FLAVOR__IO_SEEK
flavor: base.MORE_INFORMATION__FLAVOR__IO_SEEK,
w: 0,
x: this.metadata_io_position,
y: 0,
@@ -250,7 +249,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
if args.minfo <> nullptr {
args.minfo.set!(
flavor: 3, // WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA
flavor: base.MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH,
w: this.metadata_fourcc,
x: 0,
y: args.src.position(),
@@ -262,7 +261,7 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
if args.minfo <> nullptr {
args.minfo.set!(
flavor: 3, // WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA
flavor: base.MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH,
w: this.metadata_fourcc,
x: 0,
y: this.metadata_io_position,
@@ -275,10 +274,24 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
}
pub func decoder.num_animation_loops() base.u32 {
if this.seen_num_loops {
return this.num_loops
if this.seen_num_animation_loops_value {
return this.num_animation_loops_value
}
return 1
// Absent an explicit animation loop count, default to 1 meaning "play each
// frame exactly once" for animated GIFs and 0 meaning "loop forever" for
// still (non-animated) GIFs.
//
// In practice, returning 1 or 0 has no difference for still GIFs, in that
// either way, the pixels on screen do not change over time. However,
// returning 0 here matches other Wuffs image decoders (e.g. BMP, PNG)
// returning 0 for their still images.
//
// As a consequence, if a still GIF is losslessly converted to a still BMP
// and both of those are then converted to NIA, the two NIA outputs match.
if this.num_decoded_frame_configs_value > 1 {
return 1
}
return 0
}
pub func decoder.num_decoded_frame_configs() base.u64 {
@@ -662,8 +675,8 @@ pri func decoder.decode_ae?(src: base.io_reader) {
args.src.skip_u32?(n: 2)
break.goto_done
}
this.num_loops = args.src.read_u16le_as_u32?()
this.seen_num_loops = true
this.num_animation_loops_value = args.src.read_u16le_as_u32?()
this.seen_num_animation_loops_value = true
// A loop count of N, in the wire format, actually means "repeat N
// times after the first play", if N is positive. A zero N means to
@@ -675,8 +688,8 @@ pri func decoder.decode_ae?(src: base.io_reader) {
//
// Thus, we increment N if it is positive. The comparison against
// 0xFFFF will never fail, but is necessary for the overflow checker.
if (0 < this.num_loops) and (this.num_loops <= 0xFFFF) {
this.num_loops += 1
if (0 < this.num_animation_loops_value) and (this.num_animation_loops_value <= 0xFFFF) {
this.num_animation_loops_value += 1
}
} else if this.ignore_metadata {
@@ -721,16 +734,13 @@ pri func decoder.decode_gc?(src: base.io_reader) {
// in the range [4 ..= 7] are "to be defined". In practice, some encoders also
// use 4 for "restore previous". See
// https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/image-decoders/gif/gif_image_reader.cc?rcl=5161173c43324da2b13e1aa45bbe69901daa1279&l=625
//
// TODO: named constants instead of assigning 1 for
// WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND, etc.
flags = (flags >> 2) & 0x07
if flags == 2 {
this.gc_disposal = 1 // 1 is WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND
this.gc_disposal = base.ANIMATION_DISPOSAL__RESTORE_BACKGROUND
} else if (flags == 3) or (flags == 4) {
this.gc_disposal = 2 // 2 is WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS
this.gc_disposal = base.ANIMATION_DISPOSAL__RESTORE_PREVIOUS
} else {
this.gc_disposal = 0
this.gc_disposal = base.ANIMATION_DISPOSAL__NONE
}
// There are 7_056000 flicks per centisecond.
@@ -958,6 +968,17 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
continue.outer
} else if lzw_status == base."$short write" {
continue.inner
} else if this.quirks[QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA - QUIRKS_BASE] and
(this.dst_y >= this.frame_rect_y1) and (this.interlace == 0) {
// It's invalid LZW-compressed data, but we still have a full
// frame and have opted in to QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA,
// so treat it like the lzw_status.is_ok() case, other than not
// clearing this.previous_lzw_decode_ended_abruptly.
if need_block_size or (block_size > 0) {
args.src.skip_u32?(n: block_size as base.u32)
this.skip_blocks?(src: args.src)
}
break.outer
}
return lzw_status
} endwhile.inner
@@ -1015,7 +1036,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
// First, copy from src to that part of the frame rect that is inside
// args.pb's bounds (clipped to the image bounds).
dst = tab.row(y: this.dst_y)
dst = tab.row_u32(y: this.dst_y)
if this.dst_y >= this.height {
dst = dst[.. 0]
} else if width_in_bytes < dst.length() {
@@ -1057,13 +1078,13 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
(not this.gc_has_transparent_index) and
(this.interlace > 1) {
replicate_src = tab.row(y: this.dst_y)
replicate_src = tab.row_u32(y: this.dst_y)
replicate_y0 = this.dst_y ~sat+ 1
replicate_y1 = this.dst_y ~sat+ (INTERLACE_COUNT[this.interlace] as base.u32)
replicate_y1 = replicate_y1.min(a: this.frame_rect_y1)
while replicate_y0 < replicate_y1 {
assert replicate_y0 < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: replicate_y1)
replicate_dst = tab.row(y: replicate_y0)
replicate_dst = tab.row_u32(y: replicate_y0)
replicate_dst.copy_from_slice!(s: replicate_src)
replicate_y0 += 1
} endwhile
+1 -2
View File
@@ -56,7 +56,6 @@ pub struct decoder? implements base.image_decoder(
swizzler : base.pixel_swizzler,
util : base.utility,
)(
)
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
@@ -211,7 +210,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
}
}
dst = tab.row(y: this.dst_y)
dst = tab.row_u32(y: this.dst_y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
+142
View File
@@ -0,0 +1,142 @@
// Copyright 2020 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub status "#bad animation sequence number"
pub status "#bad checksum"
pub status "#bad chunk"
pub status "#bad filter"
pub status "#bad header"
pub status "#bad text chunk (not Latin-1)"
pub status "#missing palette"
pub status "#unsupported PNG compression method"
pub status "#unsupported PNG file"
pri status "#internal error: inconsistent I/O"
pri status "#internal error: inconsistent chunk type"
pri status "#internal error: inconsistent frame bounds"
pri status "#internal error: inconsistent workbuf length"
pri status "#internal error: zlib decoder did not exhaust its input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
// DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL is the minimum length of the src
// wuffs_base__io_buffer passed to the decoder.
pub const DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL : base.u64 = 8
// ANCILLARY_BIT is the upper/lower case bit on the chunk type's first byte (in
// little-endian order).
pri const ANCILLARY_BIT : base.u32 = 0x0000_0020
// INTERLACING holds the Adam7 interlacing pattern, involving 7 passes:
// 1 6 4 6 2 6 4 6
// 7 7 7 7 7 7 7 7
// 5 6 5 6 5 6 5 6
// 7 7 7 7 7 7 7 7
// 3 6 4 6 3 6 4 6
// 7 7 7 7 7 7 7 7
// 5 6 5 6 5 6 5 6
// 7 7 7 7 7 7 7 7
//
// The six elements of each inner array are:
// 0: log2(x_stride)
// 1: x_stride - x_offset - 1
// 2: x_offset
// 3: log2(y_stride)
// 4: y_stride - y_offset - 1
// 5: y_offset
pri const INTERLACING : array[8] array[6] base.u8[..= 7] = [
[0, 0, 0, 0, 0, 0], // non-interlaced; xy_stride=1, xy_offset=0
[3, 7, 0, 3, 7, 0], // interlace_pass == 1
[3, 3, 4, 3, 7, 0], // interlace_pass == 2
[2, 3, 0, 3, 3, 4], // interlace_pass == 3
[2, 1, 2, 2, 3, 0], // interlace_pass == 4
[1, 1, 0, 2, 1, 2], // interlace_pass == 5
[1, 0, 1, 1, 1, 0], // interlace_pass == 6
[0, 0, 0, 1, 0, 1], // interlace_pass == 7
]
// LOW_BIT_DEPTH_MULTIPLIERS holds multipliers that convert D-bit values into
// 8-bit values, for depth D.
pri const LOW_BIT_DEPTH_MULTIPLIERS : array[8] base.u8 = [
0,
0b1111_1111, // depth == 1
0b0101_0101, // depth == 2
0,
0b0001_0001, // depth == 4
0,
0,
0,
]
// LOW_BIT_DEPTH_NUM_PACKS holds the number of smaller-than-1-byte units that
// are packed into each byte.
pri const LOW_BIT_DEPTH_NUM_PACKS : array[8] base.u8 = [
0,
8, // depth == 1
4, // depth == 2
0,
2, // depth == 4
0,
0,
0,
]
// NUM_CHANNELS holds the number of channels for each valid color type.
pri const NUM_CHANNELS : array[8] base.u8[..= 4] = [
1, // color_type == 0: Y
0,
3, // color_type == 2: RGB
1, // color_type == 3: indexed
2, // color_type == 4: YA
0,
4, // color_type == 6: RGBA
0,
]
// LATIN_1 converts from printable Latin-1 (ISO/IEC 8859-1) to UTF-8 (encoded
// as little-endian u16). It was created by script/print-png-latin-1.go.
pri const LATIN_1 : array[256] base.u16 = [
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0xA1C2, 0xA2C2, 0xA3C2, 0xA4C2, 0xA5C2, 0xA6C2, 0xA7C2,
0xA8C2, 0xA9C2, 0xAAC2, 0xABC2, 0xACC2, 0xADC2, 0xAEC2, 0xAFC2,
0xB0C2, 0xB1C2, 0xB2C2, 0xB3C2, 0xB4C2, 0xB5C2, 0xB6C2, 0xB7C2,
0xB8C2, 0xB9C2, 0xBAC2, 0xBBC2, 0xBCC2, 0xBDC2, 0xBEC2, 0xBFC2,
0x80C3, 0x81C3, 0x82C3, 0x83C3, 0x84C3, 0x85C3, 0x86C3, 0x87C3,
0x88C3, 0x89C3, 0x8AC3, 0x8BC3, 0x8CC3, 0x8DC3, 0x8EC3, 0x8FC3,
0x90C3, 0x91C3, 0x92C3, 0x93C3, 0x94C3, 0x95C3, 0x96C3, 0x97C3,
0x98C3, 0x99C3, 0x9AC3, 0x9BC3, 0x9CC3, 0x9DC3, 0x9EC3, 0x9FC3,
0xA0C3, 0xA1C3, 0xA2C3, 0xA3C3, 0xA4C3, 0xA5C3, 0xA6C3, 0xA7C3,
0xA8C3, 0xA9C3, 0xAAC3, 0xABC3, 0xACC3, 0xADC3, 0xAEC3, 0xAFC3,
0xB0C3, 0xB1C3, 0xB2C3, 0xB3C3, 0xB4C3, 0xB5C3, 0xB6C3, 0xB7C3,
0xB8C3, 0xB9C3, 0xBAC3, 0xBBC3, 0xBCC3, 0xBDC3, 0xBEC3, 0xBFC3,
]
+1125 -225
View File
@@ -15,18 +15,6 @@
use "std/crc32"
use "std/zlib"
pub status "#bad checksum"
pub status "#bad chunk"
pub status "#bad filter"
pub status "#bad header"
pub status "#missing palette"
pub status "#unsupported PNG file"
pri status "#internal error: inconsistent workbuf length"
pri status "#internal error: zlib decoder did not exhaust its input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.image_decoder(
// The 0x00FF_FFFF limit is arbitrary (the PNG spec says 0x7FFF_FFFF) but
// it means that (width * height * bytes_per_pixel) doesn't overflow.
@@ -43,31 +31,56 @@ pub struct decoder? implements base.image_decoder(
// Call sequence states:
// - 0x00: initial state.
// - 0x01: metadata reported; image config decode is in progress.
// - 0x02: metadata finished; image config decode is in progress.
// - 0x03: image config decoded.
// - 0x04: frame config decoded.
// - 0xFF: end-of-data, usually after (the non-animated) frame decoded.
// - 0x05: frame decoded.
// - 0xFF: end-of-data, after the final frame decoded.
//
// State transitions:
//
// - 0x00 -> 0x03: via DIC
// - 0x00 -> 0x01: via DIC (metadata reported)
// - 0x00 -> 0x03: via DIC (metadata not reported)
// - 0x00 -> 0x04: via DFC with implicit DIC
// - 0x00 -> 0x05: via DF with implicit DIC and DFC
// - 0x00 -> 0xFF: via DF with implicit DIC and DFC
//
// - 0x01 -> 0x02: via TMM
//
// - 0x02 -> 0x01: via DIC (metadata reported)
// - 0x02 -> 0x03: via DIC (metadata not reported)
//
// - 0x03 -> 0x04: via DFC
// - 0x03 -> 0x05: via DF with implicit DFC
// - 0x03 -> 0xFF: via DF with implicit DFC
//
// - 0x04 -> 0xFF: via DFC
// - 0x04 -> 0x04: via DFC with implicit DF
// - 0x04 -> 0x05: via DF
// - 0x04 -> 0xFF: via DFC with implicit DF
// - 0x04 -> 0xFF: via DF
//
// - 0x05 -> 0x04: via DFC
// - 0x05 -> 0x05: via DF with implicit DFC
// - 0x05 -> 0xFF: via DF with implicit DFC
//
// - ???? -> 0x03: via RF for ???? > 0x00
//
// Where:
// - DF is decode_frame
// - DF is decode_frame, implicit means skip_frame
// - DFC is decode_frame_config, implicit means nullptr args.dst
// - DIC is decode_image_config, implicit means nullptr args.dst
// - RF is restart_frame
// - TMM is tell_me_more
call_sequence : base.u8,
report_metadata_chrm : base.bool,
report_metadata_exif : base.bool,
report_metadata_gama : base.bool,
report_metadata_iccp : base.bool,
report_metadata_kvp : base.bool,
report_metadata_srgb : base.bool,
ignore_checksum : base.bool,
depth : base.u8[..= 16],
@@ -75,17 +88,94 @@ pub struct decoder? implements base.image_decoder(
filter_distance : base.u8[..= 8],
interlace_pass : base.u8[..= 7],
seen_actl : base.bool,
seen_chrm : base.bool,
seen_fctl : base.bool,
seen_exif : base.bool,
seen_gama : base.bool,
seen_iccp : base.bool,
seen_idat : base.bool,
seen_plte : base.bool,
seen_srgb : base.bool,
seen_trns : base.bool,
metadata_is_zlib_compressed : base.bool,
zlib_is_dirty : base.bool,
chunk_type : base.u32,
chunk_type_array : array[4] base.u8,
chunk_length : base.u32,
// remap_transparency, if non-zero, is the 32-bit or 64-bit (depending on
// this.depth) argb_nonpremul color that is nominally opaque but remapped
// to transparent black.
//
// "Remapped" is an unofficial term. This is where the IHDR color type is 0
// (Y) or 2 (RGB) but there's also a tRNS chunk.
//
// PNG transparency that isn't "remapped" is color type 3 (indexed) with
// tRNS, color type 4 (YA) or color type 6 (RGBA).
remap_transparency : base.u64,
dst_pixfmt : base.u32,
src_pixfmt : base.u32,
chunk_type : base.u32,
chunk_type_array : array[4] base.u8,
chunk_length : base.u64,
num_animation_frames_value : base.u32,
num_animation_loops_value : base.u32,
num_decoded_frame_configs_value : base.u32,
num_decoded_frames_value : base.u32,
frame_config_io_position : base.u64,
// The frame_etc fields correspond to the base.frame_config argument passed
// to decode_frame_config. For animated APNG, these are explicitly given in
// the file's fcTL chunks. For still PNG, these are implicitly given in the
// file's IHDR chunk.
//
// Either way, decode_image_config has to read all the way to the start of
// the first IDAT / fdAT chunk (e.g. to see if there's a PLTE chunk). While
// later frame's restart io_positions are located just before fcTL chunks,
// the first frame's restart io_position is located just before the IDAT /
// fdAT chunk, so we also have to cache the first frame's configuration as
// we cannot re-read the first fcTL. Hence, there are first_etc fields for
// every frame_etc field.
//
// For the etc_duration fields, there are 705_600000 flicks per second and
// the maximum frame duration is 65535 seconds.
//
// The fields are ordered to minimize alignment wastage.
frame_rect_x0 : base.u32[..= 0x00FF_FFFF],
frame_rect_y0 : base.u32[..= 0x00FF_FFFF],
frame_rect_x1 : base.u32[..= 0x00FF_FFFF],
frame_rect_y1 : base.u32[..= 0x00FF_FFFF],
first_rect_x0 : base.u32[..= 0x00FF_FFFF],
first_rect_y0 : base.u32[..= 0x00FF_FFFF],
first_rect_x1 : base.u32[..= 0x00FF_FFFF],
first_rect_y1 : base.u32[..= 0x00FF_FFFF],
frame_config_io_position : base.u64,
first_config_io_position : base.u64,
frame_duration : base.u64[..= 0x2A0E_6FF1_6600],
first_duration : base.u64[..= 0x2A0E_6FF1_6600],
frame_disposal : base.u8,
first_disposal : base.u8,
frame_overwrite_instead_of_blend : base.bool,
first_overwrite_instead_of_blend : base.bool,
next_animation_seq_num : base.u32,
metadata_flavor : base.u32,
metadata_fourcc : base.u32,
metadata_x : base.u64,
metadata_y : base.u64,
metadata_z : base.u64,
// ztxt_ri and ztxt_wi are read and write indexes into the dst_palette
// buffer, re-purposed as a zlib uncompression buffer for zTXt chunks. The
// upper bound, 1024, is the same as the dst_palette length.
ztxt_ri : base.u32[..= 1024],
ztxt_wi : base.u32[..= 1024],
// ztxt_hist_pos is the history position: how many uncompressed bytes have
// been generated.
ztxt_hist_pos : base.u64,
swizzler : base.pixel_swizzler,
util : base.utility,
@@ -93,6 +183,10 @@ pub struct decoder? implements base.image_decoder(
crc32 : crc32.ieee_hasher,
zlib : zlib.decoder,
// dst_palette and src_palette are used by the swizzler, during
// decode_frame. src_palette is initialized by processing the PLTE chunk.
// dst_palette is also re-purposed as a zlib uncompression buffer for zTXt
// chunks, during decode_image_config.
dst_palette : array[4 * 256] base.u8,
src_palette : array[4 * 256] base.u8,
)
@@ -111,44 +205,49 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
var checksum_want : base.u32
var status : base.status
if this.call_sequence <> 0 {
if this.call_sequence == 2 {
if this.metadata_fourcc <> 0 {
this.call_sequence = 1
return base."@metadata reported"
}
} else if this.call_sequence <> 0 {
return base."#bad call sequence"
}
magic = args.src.read_u64le?()
if magic <> '\x89PNG\x0D\x0A\x1A\x0A'le {
return "#bad header"
}
magic = args.src.read_u64le?()
if magic <> '\x00\x00\x00\x0DIHDR'le {
return "#bad header"
}
this.crc32.reset!()
this.chunk_type_array[0] = 'I'
this.chunk_type_array[1] = 'H'
this.chunk_type_array[2] = 'D'
this.chunk_type_array[3] = 'R'
this.crc32.update_u32!(x: this.chunk_type_array[..])
while true {
mark = args.src.mark()
status =? this.decode_ihdr?(src: args.src)
if not this.ignore_checksum {
checksum_have = this.crc32.update_u32!(x: args.src.since(mark: mark))
} else {
magic = args.src.read_u64le?()
if magic <> '\x89PNG\x0D\x0A\x1A\x0A'le {
return "#bad header"
}
if status.is_ok() {
break
magic = args.src.read_u64le?()
if magic <> '\x00\x00\x00\x0DIHDR'le {
return "#bad header"
}
yield? status
} endwhile
this.chunk_type_array[0] = 'I'
this.chunk_type_array[1] = 'H'
this.chunk_type_array[2] = 'D'
this.chunk_type_array[3] = 'R'
this.crc32.reset!()
this.crc32.update_u32!(x: this.chunk_type_array[..])
// Verify CRC-32 checksum.
checksum_want = args.src.read_u32be?()
if (not this.ignore_checksum) and (checksum_have <> checksum_want) {
return "#bad checksum"
while true {
mark = args.src.mark()
status =? this.decode_ihdr?(src: args.src)
if not this.ignore_checksum {
checksum_have = this.crc32.update_u32!(x: args.src.since(mark: mark))
}
if status.is_ok() {
break
}
yield? status
} endwhile
// Verify CRC-32 checksum.
checksum_want = args.src.read_u32be?()
if (not this.ignore_checksum) and (checksum_have <> checksum_want) {
return "#bad checksum"
}
}
// Read up until an IDAT chunk.
// Read up until an IDAT or fdAT chunk.
//
// By default, libpng "warns and discards" when seeing ancillary chunk
// checksum failures (as opposed to critical chunk checksum failures) but
@@ -161,26 +260,43 @@ 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 {
this.chunk_length = args.src.read_u32be_as_u64?()
this.chunk_type = args.src.read_u32le?()
if (not this.ignore_checksum) and
((this.chunk_type == 'IDAT'le) or (this.chunk_type == 'PLTE'le)) {
this.crc32.reset!()
while args.src.length() < 8,
post args.src.length() >= 8,
{
if args.src.is_closed() {
return "#bad chunk"
}
yield? base."$short read"
} endwhile
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
if this.chunk_type == 'IDAT'le {
if (not this.seen_actl) or this.seen_fctl {
break
}
this.seen_idat = true
} else if this.chunk_type == 'fdAT'le {
if this.seen_idat and this.seen_fctl {
break
}
return "#bad chunk"
}
args.src.skip_u32_fast!(actual: 8, worst_case: 8)
if (not this.ignore_checksum) and ((this.chunk_type & ANCILLARY_BIT) == 0) {
this.chunk_type_array[0] = ((this.chunk_type >> 0) & 0xFF) as base.u8
this.chunk_type_array[1] = ((this.chunk_type >> 8) & 0xFF) as base.u8
this.chunk_type_array[2] = ((this.chunk_type >> 16) & 0xFF) as base.u8
this.chunk_type_array[3] = ((this.chunk_type >> 24) & 0xFF) as base.u8
this.crc32.reset!()
this.crc32.update_u32!(x: this.chunk_type_array[..])
}
if this.chunk_type == 'IDAT'le {
break
}
while true {
mark = args.src.mark()
status =? this.decode_other_chunk?(src: args.src)
if (not this.ignore_checksum) and (this.chunk_type == 'PLTE'le) {
if (not this.ignore_checksum) and ((this.chunk_type & ANCILLARY_BIT) == 0) {
checksum_have = this.crc32.update_u32!(x: args.src.since(mark: mark))
}
if status.is_ok() {
@@ -188,12 +304,19 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
}
yield? status
} endwhile
// If we have metadata, delay reading (skipping) the ancillary chunk's
// CRC-32 checksum until the end of tell_me_more.
if this.metadata_fourcc <> 0 {
this.call_sequence = 1
return base."@metadata reported"
}
checksum_want = args.src.read_u32be?()
if (not this.ignore_checksum) and (this.chunk_type == 'PLTE'le) and
if (not this.ignore_checksum) and ((this.chunk_type & ANCILLARY_BIT) == 0) and
(checksum_have <> checksum_want) {
return "#bad checksum"
}
} endwhile
if (this.color_type == 3) and (not this.seen_plte) {
@@ -201,6 +324,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
}
this.frame_config_io_position = args.src.position()
this.first_config_io_position = this.frame_config_io_position
if args.dst <> nullptr {
args.dst.set!(
@@ -208,10 +332,23 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_
pixsub: 0,
width: this.width,
height: this.height,
first_frame_io_position: this.frame_config_io_position,
first_frame_io_position: this.first_config_io_position,
first_frame_is_opaque: (this.color_type <= 3) and (not this.seen_trns))
}
// For still (non-animated) PNGs, the first and only frame's configuration
// is implied by the IHDR chunk instead of an explicit fcTL chunk.
if not this.seen_actl {
this.num_animation_frames_value = 1
this.first_rect_x0 = 0
this.first_rect_y0 = 0
this.first_rect_x1 = this.width
this.first_rect_y1 = this.height
this.first_duration = 0
this.first_disposal = base.ANIMATION_DISPOSAL__NONE
this.first_overwrite_instead_of_blend = false
}
this.call_sequence = 3
}
@@ -252,7 +389,7 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
// Compression.
a8 = args.src.read_u8?()
if a8 <> 0 {
return "#bad header"
return "#unsupported PNG compression method"
}
// Filter.
@@ -276,7 +413,7 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
this.filter_distance = 0
this.assign_filter_distance!()
if this.filter_distance == 0 {
return "#unsupported PNG file"
return "#bad header"
}
this.overall_workbuf_length = (this.height as base.u64) *
(1 + this.calculate_bytes_per_row(width: this.width))
@@ -285,7 +422,9 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
pri func decoder.assign_filter_distance!() {
if this.depth < 8 {
if this.color_type == 0 {
if (this.depth <> 1) and (this.depth <> 2) and (this.depth <> 4) {
return nothing
} else if this.color_type == 0 {
this.dst_pixfmt = base.PIXEL_FORMAT__Y
this.src_pixfmt = base.PIXEL_FORMAT__Y
} else if this.color_type == 3 {
@@ -304,8 +443,14 @@ pri func decoder.assign_filter_distance!() {
this.src_pixfmt = base.PIXEL_FORMAT__Y
this.filter_distance = 1
} else if this.depth == 16 {
this.dst_pixfmt = base.PIXEL_FORMAT__Y_16LE
this.src_pixfmt = base.PIXEL_FORMAT__Y_16BE
if this.interlace_pass == 0 {
this.dst_pixfmt = base.PIXEL_FORMAT__Y_16LE
this.src_pixfmt = base.PIXEL_FORMAT__Y_16BE
} else {
// Interlaced means choosing filter_and_swizzle_tricky.
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
}
this.filter_distance = 2
}
@@ -398,11 +543,84 @@ pri func decoder.choose_filter_implementations!() {
pri func decoder.decode_other_chunk?(src: base.io_reader) {
if this.chunk_type == 'PLTE'le {
if this.seen_plte or (this.color_type <> 3) {
if this.seen_plte {
return "#bad chunk"
} else if this.color_type == 3 {
// Color type 3 means paletted.
this.decode_plte?(src: args.src)
} else if (this.color_type == 2) or (this.color_type == 6) {
// Color types 2 and 6 means RGB and RGBA. In these cases, the PLTE
// chunk is merely a hint, like a sPLT "suggested palette" chunk.
// We ignore it.
} else {
return "#bad chunk"
}
this.decode_plte?(src: args.src)
this.seen_plte = true
} else if (this.chunk_type & ANCILLARY_BIT) == 0 {
if this.chunk_type <> 'IDAT'le {
return "#bad chunk"
}
} else if this.chunk_type == 'acTL'le {
if this.seen_actl {
return "#bad chunk"
}
this.decode_actl?(src: args.src)
this.seen_actl = true
} else if this.chunk_type == 'cHRM'le {
if this.report_metadata_chrm {
if this.seen_chrm {
return "#bad chunk"
}
this.decode_chrm?(src: args.src)
this.seen_chrm = true
}
} else if this.chunk_type == 'eXIf'le {
if this.report_metadata_exif {
if this.seen_exif {
return "#bad chunk"
}
this.decode_exif?(src: args.src)
this.seen_exif = true
}
} else if this.chunk_type == 'fcTL'le {
if this.seen_fctl {
return "#bad chunk"
}
this.decode_fctl?(src: args.src)
this.seen_fctl = true
} else if this.chunk_type == 'gAMA'le {
if this.report_metadata_gama {
if this.seen_gama {
return "#bad chunk"
}
this.decode_gama?(src: args.src)
this.seen_gama = true
}
} else if this.chunk_type == 'iCCP'le {
if this.report_metadata_iccp {
if this.seen_iccp {
return "#bad chunk"
}
this.decode_iccp?(src: args.src)
this.seen_iccp = true
}
} else if this.chunk_type == 'sRGB'le {
if this.report_metadata_srgb {
if this.seen_srgb {
return "#bad chunk"
}
this.decode_srgb?(src: args.src)
this.seen_srgb = true
}
} else if this.chunk_type == 'tRNS'le {
if this.seen_trns or (this.color_type > 3) or
((this.color_type == 3) and (not this.seen_plte)) {
@@ -410,9 +628,212 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
}
this.decode_trns?(src: args.src)
this.seen_trns = true
} else {
args.src.skip?(n: this.chunk_length)
} else if (this.chunk_type == 'iTXt'le) or
(this.chunk_type == 'tEXt'le) or
(this.chunk_type == 'zTXt'le) {
if this.report_metadata_kvp {
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM
this.metadata_fourcc = 'KVPK'be
this.metadata_x = 0
this.metadata_y = 0
this.metadata_z = 0
}
}
if this.metadata_fourcc == 0 {
args.src.skip_u32?(n: this.chunk_length)
}
}
pri func decoder.decode_actl?(src: base.io_reader) {
if this.chunk_length <> 8 {
return "#bad chunk"
} else if this.interlace_pass > 0 {
// https://wiki.mozilla.org/APNG_Specification doesn't say whether the
// interlace pattern starts at the image or frame top-left corner. We
// avoid the question by returning "unsupported" for now.
return "#unsupported PNG file"
}
this.chunk_length = 0
this.num_animation_frames_value = args.src.read_u32be?()
if this.num_animation_frames_value == 0 {
return "#bad chunk"
}
this.num_animation_loops_value = args.src.read_u32be?()
}
pri func decoder.decode_chrm?(src: base.io_reader) {
var u : base.u64
if this.chunk_length <> 32 {
return "#bad chunk"
}
this.chunk_length = 0
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
this.metadata_fourcc = 'CHRM'be
this.metadata_x = 0
this.metadata_y = 0
this.metadata_z = 0
// See the wuffs_base__more_information__metadata_parsed__chrm comments for
// how we pack the eight chromaticity values into three u64 fields. This
// admittedly truncates chromaticity values from 32 to 24 bits, but in
// practice they only range between 0 and 100000 (which is 0x01_86A0).
u = args.src.read_u32be_as_u64?()
this.metadata_x |= (0xFF_FFFF & u) << 0
u = args.src.read_u32be_as_u64?()
this.metadata_x |= (0xFF_FFFF & u) << 24
u = args.src.read_u32be_as_u64?()
this.metadata_x |= (0xFF_FFFF & u) ~mod<< 48
this.metadata_y |= (0xFF_FFFF & u) >> 16
u = args.src.read_u32be_as_u64?()
this.metadata_y |= (0xFF_FFFF & u) << 8
u = args.src.read_u32be_as_u64?()
this.metadata_y |= (0xFF_FFFF & u) << 32
u = args.src.read_u32be_as_u64?()
this.metadata_y |= (0xFF_FFFF & u) ~mod<< 56
this.metadata_z |= (0xFF_FFFF & u) >> 8
u = args.src.read_u32be_as_u64?()
this.metadata_z |= (0xFF_FFFF & u) << 16
u = args.src.read_u32be_as_u64?()
this.metadata_z |= (0xFF_FFFF & u) << 40
}
pri func decoder.decode_exif?(src: base.io_reader) {
if this.chunk_length < 4 {
return "#bad chunk"
}
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
this.metadata_fourcc = 'EXIF'be
this.metadata_x = 0
this.metadata_y = args.src.position()
this.metadata_z = this.metadata_y ~sat+ (this.chunk_length as base.u64)
this.chunk_length = 0
}
pri func decoder.decode_fctl?(src: base.io_reader) {
var x0 : base.u32
var y0 : base.u32
var x1 : base.u32
var y1 : base.u32
if this.chunk_length <> 26 {
return "#bad chunk"
}
this.chunk_length = 0
x0 = args.src.read_u32be?()
if x0 <> this.next_animation_seq_num {
return "#bad animation sequence number"
} else if this.next_animation_seq_num >= 0xFFFF_FFFF {
return "#unsupported PNG file"
}
this.next_animation_seq_num += 1
x1 = args.src.read_u32be?()
y1 = args.src.read_u32be?()
x0 = args.src.read_u32be?()
y0 = args.src.read_u32be?()
x1 ~mod+= x0
y1 ~mod+= y0
if (x0 >= x1) or (x0 > this.width) or (x1 > this.width) or
(y0 >= y1) or (y0 > this.height) or (y1 > this.height) {
return "#bad chunk"
}
assert x1 <= 0x00FF_FFFF via "a <= b: a <= c; c <= b"(c: this.width)
assert y1 <= 0x00FF_FFFF via "a <= b: a <= c; c <= b"(c: this.height)
assert x0 <= 0x00FF_FFFF via "a <= b: a <= c; c <= b"(c: x1)
assert y0 <= 0x00FF_FFFF via "a <= b: a <= c; c <= b"(c: y1)
this.frame_rect_x0 = x0
this.frame_rect_y0 = y0
this.frame_rect_x1 = x1
this.frame_rect_y1 = y1
// There are 705_600000 flicks per second. A nominally zero denominator
// means to use 100 instead (the units are centiseconds, the same as GIF).
x0 = args.src.read_u16be_as_u32?()
x1 = args.src.read_u16be_as_u32?()
if x1 <= 0 {
this.frame_duration = (x0 as base.u64) * 7_056000
} else {
this.frame_duration = ((x0 as base.u64) * 705_600000) / (x1 as base.u64)
}
x0 = args.src.read_u8_as_u32?()
if x0 == 0 {
this.frame_disposal = base.ANIMATION_DISPOSAL__NONE
} else if x0 == 1 {
this.frame_disposal = base.ANIMATION_DISPOSAL__RESTORE_BACKGROUND
} else if x0 == 2 {
this.frame_disposal = base.ANIMATION_DISPOSAL__RESTORE_PREVIOUS
} else {
return "#bad chunk"
}
x0 = args.src.read_u8_as_u32?()
if x0 == 0 {
this.frame_overwrite_instead_of_blend = true
} else if x0 == 1 {
this.frame_overwrite_instead_of_blend = false
} else {
return "#bad chunk"
}
if this.num_decoded_frame_configs_value == 0 {
this.first_rect_x0 = this.frame_rect_x0
this.first_rect_y0 = this.frame_rect_y0
this.first_rect_x1 = this.frame_rect_x1
this.first_rect_y1 = this.frame_rect_y1
this.first_duration = this.frame_duration
this.first_disposal = this.frame_disposal
this.first_overwrite_instead_of_blend = this.frame_overwrite_instead_of_blend
}
}
pri func decoder.decode_gama?(src: base.io_reader) {
if this.chunk_length <> 4 {
return "#bad chunk"
}
this.chunk_length = 0
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
this.metadata_fourcc = 'GAMA'be
this.metadata_x = args.src.read_u32be_as_u64?()
this.metadata_y = 0
this.metadata_z = 0
}
pri func decoder.decode_iccp?(src: base.io_reader) {
var c : base.u8
// Skip the NUL-terminated color profile name.
while true {
if this.chunk_length <= 0 {
return "#bad chunk"
}
this.chunk_length -= 1
c = args.src.read_u8?()
if c == 0 {
break
}
} endwhile
// Compression method.
if this.chunk_length <= 0 {
return "#bad chunk"
}
this.chunk_length -= 1
c = args.src.read_u8?()
if c <> 0 {
return "#unsupported PNG compression method"
}
this.metadata_is_zlib_compressed = true
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM
this.metadata_fourcc = 'ICCP'be
this.metadata_x = 0
this.metadata_y = 0
this.metadata_z = 0
}
pri func decoder.decode_plte?(src: base.io_reader) {
@@ -424,6 +845,7 @@ pri func decoder.decode_plte?(src: base.io_reader) {
return "#bad chunk"
}
num_entries = (this.chunk_length as base.u32) / 3
this.chunk_length = 0
while i < num_entries {
assert i < 256 via "a < b: a < c; c <= b"(c: num_entries)
@@ -448,82 +870,304 @@ pri func decoder.decode_plte?(src: base.io_reader) {
} endwhile
}
pri func decoder.decode_trns?(src: base.io_reader) {
var num_entries : base.u32[..= 256]
var i : base.u32
if this.chunk_length > 256 {
pri func decoder.decode_srgb?(src: base.io_reader) {
if this.chunk_length <> 1 {
return "#bad chunk"
}
num_entries = this.chunk_length as base.u32
this.chunk_length = 0
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_PARSED
this.metadata_fourcc = 'SRGB'be
this.metadata_x = args.src.read_u8_as_u64?()
this.metadata_y = 0
this.metadata_z = 0
}
while i < num_entries {
assert i < 256 via "a < b: a < c; c <= b"(c: num_entries)
this.src_palette[(4 * i) + 3] = args.src.read_u8?()
i += 1
} endwhile
pri func decoder.decode_trns?(src: base.io_reader) {
var i : base.u32
var n : base.u32[..= 256]
var u : base.u64
if this.color_type == 3 {
this.dst_pixfmt = base.PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL
this.src_pixfmt = base.PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL
} else {
if this.color_type == 0 {
choose filter_and_swizzle = [filter_and_swizzle_tricky]
if this.color_type == 0 {
// TODO: PIXEL_FORMAT__YA_NONPREMUL
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
} else if this.color_type == 2 {
if this.depth <= 8 {
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
} else {
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
}
if this.chunk_length <> 2 {
return "#bad chunk"
}
this.chunk_length = 0
u = args.src.read_u16be_as_u64?()
if this.depth <= 1 {
this.remap_transparency = ((u & 0x01) * 0xFF_FFFF) | 0xFF00_0000
} else if this.depth <= 2 {
this.remap_transparency = ((u & 0x03) * 0x55_5555) | 0xFF00_0000
} else if this.depth <= 4 {
this.remap_transparency = ((u & 0x0F) * 0x11_1111) | 0xFF00_0000
} else if this.depth <= 8 {
this.remap_transparency = ((u & 0xFF) * 0x01_0101) | 0xFF00_0000
} else {
this.remap_transparency = (u * 0x0001_0001_0001) | 0xFFFF_0000_0000_0000
}
} else if this.color_type == 2 {
choose filter_and_swizzle = [filter_and_swizzle_tricky]
if this.depth <= 8 {
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
} else {
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
}
if this.chunk_length <> 6 {
return "#bad chunk"
}
this.chunk_length = 0
u = args.src.read_u48be_as_u64?()
if this.depth <= 8 {
this.remap_transparency =
(0x0000_00FF & (u >> 0)) |
(0x0000_FF00 & (u >> 8)) |
(0x00FF_0000 & (u >> 16)) |
0xFF00_0000
} else {
this.remap_transparency = u | 0xFFFF_0000_0000_0000
}
} else if this.color_type == 3 {
this.dst_pixfmt = base.PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL
this.src_pixfmt = base.PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL
if this.chunk_length > 256 {
return "#bad chunk"
}
n = this.chunk_length as base.u32
this.chunk_length = 0
while i < n {
assert i < 256 via "a < b: a < c; c <= b"(c: n)
this.src_palette[(4 * i) + 3] = args.src.read_u8?()
i += 1
} endwhile
} else {
return "#bad chunk"
}
}
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
if this.call_sequence < 3 {
if this.call_sequence == 0xFF {
return base."@end of data"
} else if this.call_sequence < 3 {
this.decode_image_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 3 {
if this.frame_config_io_position <> args.src.position() {
return base."#bad restart"
}
} else if this.call_sequence == 4 {
this.call_sequence = 0xFF
return base."@end of data"
this.skip_frame?(src: args.src)
if this.call_sequence == 0xFF {
return base."@end of data"
}
}
if this.num_decoded_frame_configs_value == 0 {
this.frame_rect_x0 = this.first_rect_x0
this.frame_rect_y0 = this.first_rect_y0
this.frame_rect_x1 = this.first_rect_x1
this.frame_rect_y1 = this.first_rect_y1
this.frame_config_io_position = this.first_config_io_position
this.frame_duration = this.first_duration
this.frame_disposal = this.first_disposal
this.frame_overwrite_instead_of_blend = this.first_overwrite_instead_of_blend
} else {
return base."@end of data"
// Decode the next fcTL chunk.
while true {
this.chunk_length = args.src.read_u32be?()
this.chunk_type = args.src.read_u32le?()
if this.chunk_type == 'fdAT'le {
return "#bad chunk"
} else if this.chunk_type == 'fcTL'le {
this.frame_config_io_position = args.src.position() ~mod- 8
this.decode_fctl?(src: args.src)
args.src.skip?(n: 4) // Skip the checksum.
break
}
args.src.skip?(n: (this.chunk_length as base.u64) + 4) // +4 for the checksum.
this.chunk_length = 0
} endwhile
}
if args.dst <> nullptr {
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: this.width,
max_excl_y: this.height),
duration: 0,
index: 0,
min_incl_x: this.frame_rect_x0,
min_incl_y: this.frame_rect_y0,
max_excl_x: this.frame_rect_x1,
max_excl_y: this.frame_rect_y1),
duration: this.frame_duration,
index: this.num_decoded_frame_configs_value as base.u64,
io_position: this.frame_config_io_position,
disposal: 0,
opaque_within_bounds: false,
overwrite_instead_of_blend: false,
disposal: this.frame_disposal,
opaque_within_bounds: (this.color_type <= 3) and (not this.seen_trns),
overwrite_instead_of_blend: this.frame_overwrite_instead_of_blend,
background_color: 0x0000_0000)
}
this.num_decoded_frame_configs_value ~sat+= 1
this.call_sequence = 4
}
pri func decoder.skip_frame?(src: base.io_reader) {
var seq_num : base.u32
this.chunk_type_array[0] = 0
this.chunk_type_array[1] = 0
this.chunk_type_array[2] = 0
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"
}
yield? base."$short read"
} endwhile
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
if this.chunk_type == 'IDAT'le {
if this.chunk_type_array[0] == 'f' {
return "#bad chunk"
}
this.chunk_type_array[0] = 'I'
this.chunk_type_array[1] = 'D'
this.chunk_type_array[2] = 'A'
this.chunk_type_array[3] = 'T'
} else if this.chunk_type == 'fdAT'le {
if this.chunk_type_array[0] == 'I' {
return "#bad chunk"
}
this.chunk_type_array[0] = 'f'
this.chunk_type_array[1] = 'd'
this.chunk_type_array[2] = 'A'
this.chunk_type_array[3] = 'T'
if this.chunk_length < 4 {
return "#bad chunk"
}
this.chunk_length -= 4
args.src.skip_u32_fast!(actual: 8, worst_case: 8)
seq_num = args.src.read_u32be?()
if seq_num <> this.next_animation_seq_num {
return "#bad animation sequence number"
} else if this.next_animation_seq_num >= 0xFFFF_FFFF {
return "#unsupported PNG file"
}
this.next_animation_seq_num += 1
args.src.skip?(n: (this.chunk_length as base.u64) + 4) // +4 for the checksum.
this.chunk_length = 0
continue
} else if this.chunk_type_array[0] <> 0 {
break
} else if this.chunk_type == 'fcTL'le {
return "#bad chunk"
}
// +12 for chunk length, chunk type and checksum.
args.src.skip?(n: (this.chunk_length as base.u64) + 12)
this.chunk_length = 0
} endwhile
this.num_decoded_frames_value ~sat+= 1
if this.num_decoded_frames_value < this.num_animation_frames_value {
this.call_sequence = 5
} else {
this.call_sequence = 0xFF
}
}
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 seq_num : base.u32
var status : base.status
var pass_width : base.u32[..= 0x00FF_FFFF]
var pass_height : base.u32[..= 0x00FF_FFFF]
if this.call_sequence < 4 {
this.decode_frame_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 4 {
// No-op.
} else {
if this.call_sequence == 0xFF {
return base."@end of data"
} else if this.call_sequence <> 4 {
this.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"
}
yield? base."$short read"
} endwhile
this.chunk_length = args.src.peek_u32be()
this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32
if this.chunk_type == 'IDAT'le {
this.chunk_type_array[0] = 'I'
this.chunk_type_array[1] = 'D'
this.chunk_type_array[2] = 'A'
this.chunk_type_array[3] = 'T'
args.src.skip_u32_fast!(actual: 8, worst_case: 8)
if not this.ignore_checksum {
this.crc32.reset!()
this.crc32.update_u32!(x: this.chunk_type_array[..])
}
break
} else if this.chunk_type == 'fdAT'le {
this.chunk_type_array[0] = 'f'
this.chunk_type_array[1] = 'd'
this.chunk_type_array[2] = 'A'
this.chunk_type_array[3] = 'T'
if this.chunk_length < 4 {
return "#bad chunk"
}
this.chunk_length -= 4
args.src.skip_u32_fast!(actual: 8, worst_case: 8)
seq_num = args.src.read_u32be?()
if seq_num <> this.next_animation_seq_num {
return "#bad animation sequence number"
} else if this.next_animation_seq_num >= 0xFFFF_FFFF {
return "#unsupported PNG file"
}
this.next_animation_seq_num += 1
break
} else if this.chunk_type == 'fcTL'le {
return "#bad chunk"
}
// +12 for chunk length, chunk type and checksum.
args.src.skip?(n: (this.chunk_length as base.u64) + 12)
this.chunk_length = 0
} endwhile
if this.zlib_is_dirty {
this.zlib.reset!()
if this.ignore_checksum {
this.zlib.set_quirk_enabled!(quirk: base.QUIRK_IGNORE_CHECKSUM, enabled: true)
}
}
this.zlib_is_dirty = true
status = this.swizzler.prepare!(
dst_pixfmt: args.dst.pixel_format(),
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),
@@ -536,12 +1180,17 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
this.workbuf_hist_pos_base = 0
while true {
pass_width = 0x00FF_FFFF &
(((INTERLACING[this.interlace_pass][1] as base.u32) + this.width) >>
INTERLACING[this.interlace_pass][0])
pass_height = 0x00FF_FFFF &
(((INTERLACING[this.interlace_pass][4] as base.u32) + this.height) >>
INTERLACING[this.interlace_pass][3])
if (this.chunk_type_array[0] == 'I') {
pass_width = 0x00FF_FFFF &
(((INTERLACING[this.interlace_pass][1] as base.u32) + this.width) >>
INTERLACING[this.interlace_pass][0])
pass_height = 0x00FF_FFFF &
(((INTERLACING[this.interlace_pass][4] as base.u32) + this.height) >>
INTERLACING[this.interlace_pass][3])
} else {
pass_width = 0x00FF_FFFF & (this.frame_rect_x1 ~mod- this.frame_rect_x0)
pass_height = 0x00FF_FFFF & (this.frame_rect_y1 ~mod- this.frame_rect_y0)
}
if (pass_width > 0) and (pass_height > 0) {
this.pass_bytes_per_row = this.calculate_bytes_per_row(width: pass_width)
@@ -560,7 +1209,12 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
this.interlace_pass += 1
} endwhile
this.call_sequence = 0xFF
this.num_decoded_frames_value ~sat+= 1
if this.num_decoded_frames_value < this.num_animation_frames_value {
this.call_sequence = 5
} else {
this.call_sequence = 0xFF
}
}
pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
@@ -570,6 +1224,7 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
var zlib_status : base.status
var checksum_have : base.u32
var checksum_want : base.u32
var seq_num : base.u32
this.workbuf_wi = 0
while true {
@@ -578,7 +1233,7 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
return base."#bad workbuf length"
}
io_bind (io: w, data: args.workbuf[this.workbuf_wi .. this.pass_workbuf_length], history_position: this.workbuf_hist_pos_base ~mod+ this.workbuf_wi) {
io_limit (io: args.src, limit: this.chunk_length) {
io_limit (io: args.src, limit: (this.chunk_length as base.u64)) {
w_mark = w.mark()
r_mark = args.src.mark()
zlib_status =? this.zlib.transform_io?(
@@ -586,20 +1241,20 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
if not this.ignore_checksum {
this.crc32.update_u32!(x: args.src.since(mark: r_mark))
}
this.chunk_length ~sat-= args.src.count_since(mark: r_mark)
this.chunk_length ~sat-= (args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
this.workbuf_wi ~sat+= w.count_since(mark: w_mark)
}
}
if zlib_status.is_ok() {
if this.chunk_length > 0 {
// TODO: should this really be a fatal error?
return base."#too much data"
}
checksum_want = args.src.read_u32be?()
// Verify the final IDAT chunk's CRC-32 checksum.
if not this.ignore_checksum {
if this.chunk_length > 0 {
// TODO: should this really be a fatal error?
return base."#too much data"
}
if (not this.ignore_checksum) and (this.chunk_type_array[0] == 'I') {
checksum_have = this.crc32.update_u32!(x: this.util.empty_slice_u8())
checksum_want = args.src.read_u32be?()
if checksum_have <> checksum_want {
return "#bad checksum"
}
@@ -615,28 +1270,37 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
} else if this.chunk_length == 0 {
// Verify the non-final IDAT chunk's CRC-32 checksum.
checksum_want = args.src.read_u32be?()
if not this.ignore_checksum {
if (not this.ignore_checksum) and (this.chunk_type_array[0] == 'I') {
checksum_have = this.crc32.update_u32!(x: this.util.empty_slice_u8())
if checksum_have <> checksum_want {
return "#bad checksum"
}
}
// The next chunk should be another IDAT.
this.chunk_length = args.src.read_u32be_as_u64?()
// The next chunk should be another IDAT or fdAT.
this.chunk_length = args.src.read_u32be?()
this.chunk_type = args.src.read_u32le?()
if this.chunk_type <> 'IDAT'le {
return "#bad chunk"
}
// The 'IDAT'be is part of the next CRC-32 checksum's input.
if not this.ignore_checksum {
this.crc32.reset!()
this.chunk_type_array[0] = 'I'
this.chunk_type_array[1] = 'D'
this.chunk_type_array[2] = 'A'
this.chunk_type_array[3] = 'T'
this.crc32.update_u32!(x: this.chunk_type_array[..])
if (this.chunk_type_array[0] == 'I') {
if this.chunk_type <> 'IDAT'le {
return "#bad chunk"
}
// The IDAT is part of the next CRC-32 checksum's input.
if not this.ignore_checksum {
this.crc32.reset!()
this.crc32.update_u32!(x: this.chunk_type_array[..])
}
} else {
if (this.chunk_type <> 'fdAT'le) or (this.chunk_length < 4) {
return "#bad chunk"
}
this.chunk_length -= 4
seq_num = args.src.read_u32be?()
if seq_num <> this.next_animation_seq_num {
return "#bad animation sequence number"
} else if this.next_animation_seq_num >= 0xFFFF_FFFF {
return "#unsupported PNG file"
}
this.next_animation_seq_num += 1
}
continue
} else if args.src.length() > 0 {
@@ -659,35 +1323,29 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
return this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: this.width,
max_excl_y: this.height)
min_incl_x: this.frame_rect_x0,
min_incl_y: this.frame_rect_y0,
max_excl_x: this.frame_rect_x1,
max_excl_y: this.frame_rect_y1)
}
pub func decoder.num_animation_loops() base.u32 {
return 0
return this.num_animation_loops_value
}
pub func decoder.num_decoded_frame_configs() base.u64 {
if this.call_sequence > 3 {
return 1
}
return 0
return this.num_decoded_frame_configs_value as base.u64
}
pub func decoder.num_decoded_frames() base.u64 {
if this.call_sequence > 4 {
return 1
}
return 0
return this.num_decoded_frames_value as base.u64
}
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
if this.call_sequence < 3 {
return base."#bad call sequence"
}
if args.index <> 0 {
} else if (args.index >= (this.num_animation_frames_value as base.u64)) or
((args.index == 0) and (args.io_position <> this.first_config_io_position)) {
return base."#bad argument"
}
this.call_sequence = 3
@@ -695,15 +1353,323 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
this.interlace_pass = 1
}
this.frame_config_io_position = args.io_position
this.num_decoded_frame_configs_value = (args.index & 0xFFFF_FFFF) as base.u32
this.num_decoded_frames_value = this.num_decoded_frame_configs_value
return ok
}
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
// TODO.
if args.fourcc == 'CHRM'be {
this.report_metadata_chrm = args.report
} else if args.fourcc == 'EXIF'be {
this.report_metadata_exif = args.report
} else if args.fourcc == 'GAMA'be {
this.report_metadata_gama = args.report
} else if args.fourcc == 'ICCP'be {
this.report_metadata_iccp = args.report
} else if args.fourcc == 'KVP 'be {
this.report_metadata_kvp = args.report
} else if args.fourcc == 'SRGB'be {
this.report_metadata_srgb = args.report
}
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
return base."#no more information"
var c : base.u8
var c2 : base.u16
var w : base.io_writer
var num_written : base.u64
var w_mark : base.u64
var r_mark : base.u64
var zlib_status : base.status
if this.call_sequence <> 1 {
return base."#bad call sequence"
}
if this.metadata_fourcc == 0 {
return base."#no more information"
}
while.goto_done true {{
if this.metadata_flavor == base.MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH {
while true {
if args.src.position() <> this.metadata_y {
return base."#bad I/O position"
} else if args.minfo <> nullptr {
args.minfo.set!(
flavor: this.metadata_flavor,
w: this.metadata_fourcc,
x: this.metadata_x,
y: this.metadata_y,
z: this.metadata_z)
}
if this.metadata_y >= this.metadata_z {
break.goto_done
}
this.metadata_y = this.metadata_z
yield? base."$even more information"
} endwhile
}
if this.metadata_is_zlib_compressed {
if this.zlib_is_dirty {
this.zlib.reset!()
if this.ignore_checksum {
this.zlib.set_quirk_enabled!(quirk: base.QUIRK_IGNORE_CHECKSUM, enabled: true)
}
}
this.zlib_is_dirty = true
this.ztxt_hist_pos = 0
}
while.loop true {
if args.minfo <> nullptr {
args.minfo.set!(
flavor: this.metadata_flavor,
w: this.metadata_fourcc,
x: this.metadata_x,
y: this.metadata_y,
z: this.metadata_z)
}
if this.metadata_flavor <> base.MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM {
break.loop
}
if this.metadata_is_zlib_compressed {
if this.chunk_type == 'iCCP'le {
io_limit (io: args.src, limit: this.chunk_length as base.u64) {
r_mark = args.src.mark()
zlib_status =? this.zlib.transform_io?(
dst: args.dst, src: args.src, workbuf: this.util.empty_slice_u8())
this.chunk_length ~sat-=
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
}
if zlib_status.is_ok() {
this.metadata_is_zlib_compressed = false
break.loop
} else if not zlib_status.is_suspension() {
return zlib_status
}
yield? zlib_status
} else if this.chunk_type == 'iTXt'le {
// TODO: verify uncompressed data is UTF-8.
io_limit (io: args.src, limit: this.chunk_length as base.u64) {
r_mark = args.src.mark()
zlib_status =? this.zlib.transform_io?(
dst: args.dst, src: args.src, workbuf: this.util.empty_slice_u8())
this.chunk_length ~sat-=
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
}
if zlib_status.is_ok() {
this.metadata_is_zlib_compressed = false
break.loop
} else if not zlib_status.is_suspension() {
return zlib_status
}
yield? zlib_status
} else if this.chunk_type == 'zTXt'le {
// Fill this.dst_palette, zlib-uncompressing producing Latin-1.
if this.ztxt_ri == this.ztxt_wi {
io_bind (io: w, data: this.dst_palette[..], history_position: this.ztxt_hist_pos) {
io_limit (io: args.src, limit: this.chunk_length as base.u64) {
w_mark = w.mark()
r_mark = args.src.mark()
zlib_status =? this.zlib.transform_io?(
dst: w, src: args.src, workbuf: this.util.empty_slice_u8())
this.chunk_length ~sat-=
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
num_written = w.count_since(mark: w_mark)
}
}
if num_written > 1024 {
return "#internal error: inconsistent I/O"
}
this.ztxt_ri = 0
this.ztxt_wi = num_written as base.u32
this.ztxt_hist_pos ~sat+= num_written
}
// Drain this.dst_palette, converting from Latin-1 to UTF-8.
while this.ztxt_ri < this.ztxt_wi {
assert this.ztxt_ri < 1024 via "a < b: a < c; c <= b"(c: this.ztxt_wi)
c2 = LATIN_1[this.dst_palette[this.ztxt_ri]]
if c2 == 0 {
return "#bad text chunk (not Latin-1)"
} else if c2 <= 0x7F {
if args.dst.length() <= 0 {
yield? base."$short write"
c2 = 0
continue.loop
}
this.ztxt_ri += 1
args.dst.write_u8_fast!(a: c2 as base.u8)
} else {
if args.dst.length() <= 1 {
yield? base."$short write"
c2 = 0
continue.loop
}
this.ztxt_ri += 1
args.dst.write_u16le_fast!(a: c2)
}
} endwhile
if zlib_status.is_ok() {
this.metadata_is_zlib_compressed = false
break.loop
} else if not zlib_status.is_suspension() {
return zlib_status
} else if zlib_status <> base."$short write" {
yield? zlib_status
}
} else {
return "#internal error: inconsistent chunk type"
}
} else if (this.chunk_type == 'iTXt'le) and (this.metadata_fourcc == 'KVPV'be) {
// iTXt value is UTF-8.
//
// TODO: verify data is UTF-8.
while true {
if this.chunk_length <= 0 {
break.loop
} else if args.src.length() <= 0 {
yield? base."$short read"
continue.loop
} else if args.dst.length() <= 0 {
yield? base."$short write"
continue.loop
}
this.chunk_length -= 1
c = args.src.peek_u8()
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
args.dst.write_u8_fast!(a: c)
} endwhile
} else {
// Other uncompressed keys and values are Latin-1.
while true {
if this.chunk_length <= 0 {
// Keys are NUL-terminated but values are not.
if this.metadata_fourcc == 'KVPK'be {
return "#bad chunk"
}
break.loop
} else if args.src.length() <= 0 {
yield? base."$short read"
continue.loop
}
c = args.src.peek_u8()
if c == 0 {
this.chunk_length -= 1
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
break.loop
}
c2 = LATIN_1[c]
if c2 == 0 {
return "#bad text chunk (not Latin-1)"
} else if c2 <= 0x7F {
if args.dst.length() <= 0 {
yield? base."$short write"
c2 = 0
continue.loop
}
this.chunk_length -= 1
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
args.dst.write_u8_fast!(a: c2 as base.u8)
} else {
if args.dst.length() <= 1 {
yield? base."$short write"
c2 = 0
continue.loop
}
this.chunk_length -= 1
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
args.dst.write_u16le_fast!(a: c2)
}
} endwhile
}
} endwhile.loop
// Key-value pairs come in... pairs.
if this.metadata_fourcc == 'KVPK'be {
this.metadata_fourcc = 'KVPV'be
if this.chunk_type == 'iTXt'le {
// Compression flag, compression method.
if this.chunk_length <= 1 {
return "#bad chunk"
}
this.chunk_length -= 2
c = args.src.read_u8?()
if c == 0 {
this.metadata_is_zlib_compressed = false
} else if c == 1 {
this.metadata_is_zlib_compressed = true
} else {
return "#bad chunk"
}
c = args.src.read_u8?()
if (c <> 0) and this.metadata_is_zlib_compressed {
return "#unsupported PNG compression method"
}
// Skip the language tag and translated keyword: two iterations
// looking for a NUL terminator.
this.metadata_fourcc ~mod-= 2
while this.metadata_fourcc <> 'KVPV'be {
this.metadata_fourcc ~mod+= 1
while true {
if this.chunk_length <= 0 {
return "#bad chunk"
}
this.chunk_length -= 1
c = args.src.read_u8?()
if c == 0 {
break
}
} endwhile
} endwhile
} else if this.chunk_type == 'zTXt'le {
// Compression method.
if this.chunk_length <= 0 {
return "#bad chunk"
}
this.chunk_length -= 1
c = args.src.read_u8?()
if c <> 0 {
return "#unsupported PNG compression method"
}
this.metadata_is_zlib_compressed = true
}
this.call_sequence = 2
return ok
}
break.goto_done
}} endwhile.goto_done
if this.chunk_length <> 0 {
return "#bad chunk"
}
// Skip the ancillary chunk's CRC-32 checksum.
args.src.skip?(n: 4)
this.metadata_flavor = 0
this.metadata_fourcc = 0
this.metadata_x = 0
this.metadata_y = 0
this.metadata_z = 0
this.call_sequence = 2
return ok
}
pub func decoder.workbuf_len() base.range_ii_u64 {
@@ -711,69 +1677,3 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
min_incl: this.overall_workbuf_length,
max_incl: this.overall_workbuf_length)
}
// INTERLACING holds the Adam7 interlacing pattern, involving 7 passes:
// 1 6 4 6 2 6 4 6
// 7 7 7 7 7 7 7 7
// 5 6 5 6 5 6 5 6
// 7 7 7 7 7 7 7 7
// 3 6 4 6 3 6 4 6
// 7 7 7 7 7 7 7 7
// 5 6 5 6 5 6 5 6
// 7 7 7 7 7 7 7 7
//
// The six elements of each inner array are:
// 0: log2(x_stride)
// 1: x_stride - x_offset - 1
// 2: x_offset
// 3: log2(y_stride)
// 4: y_stride - y_offset - 1
// 5: y_offset
pri const INTERLACING : array[8] array[6] base.u8[..= 8] = [
[0, 0, 0, 0, 0, 0], // non-interlaced; xy_stride=1, xy_offset=0
[3, 7, 0, 3, 7, 0], // interlace_pass == 1
[3, 3, 4, 3, 7, 0], // interlace_pass == 2
[2, 3, 0, 3, 3, 4], // interlace_pass == 3
[2, 1, 2, 2, 3, 0], // interlace_pass == 4
[1, 1, 0, 2, 1, 2], // interlace_pass == 5
[1, 0, 1, 1, 1, 0], // interlace_pass == 6
[0, 0, 0, 1, 0, 1], // interlace_pass == 7
]
// LOW_BIT_DEPTH_MULTIPLIERS holds multipliers that convert D-bit values into
// 8-bit values, for depth D.
pri const LOW_BIT_DEPTH_MULTIPLIERS : array[8] base.u8 = [
0,
0b1111_1111, // depth == 1
0b0101_0101, // depth == 2
0,
0b0001_0001, // depth == 4
0,
0,
0,
]
// LOW_BIT_DEPTH_NUM_PACKS holds the number of smaller-than-1-byte units that
// are packed into each byte.
pri const LOW_BIT_DEPTH_NUM_PACKS : array[8] base.u8 = [
0,
8, // depth == 1
4, // depth == 2
0,
2, // depth == 4
0,
0,
0,
]
// NUM_CHANNELS holds the number of channels for each valid color type.
pri const NUM_CHANNELS : array[8] base.u8[..= 4] = [
1, // color_type == 0: Y
0,
3, // color_type == 2: RGB
1, // color_type == 3: indexed
2, // color_type == 4: YA
0,
4, // color_type == 6: RGBA
0,
]
@@ -18,7 +18,8 @@ pri func decoder.filter_and_swizzle!(dst: ptr base.pixel_buffer, workbuf: slice
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_row : base.u64
var dst_bytes_per_row0 : base.u64
var dst_bytes_per_row1 : base.u64
var dst_palette : slice base.u8
var tab : table base.u8
@@ -36,16 +37,37 @@ pri func decoder.filter_and_swizzle!(dst: ptr base.pixel_buffer, workbuf: slice
return base."#unsupported option"
}
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
dst_bytes_per_row0 = (this.frame_rect_x0 as base.u64) * dst_bytes_per_pixel
dst_bytes_per_row1 = (this.frame_rect_x1 as base.u64) * dst_bytes_per_pixel
dst_palette = args.dst.palette_or_else(fallback: this.dst_palette[..])
tab = args.dst.plane(p: 0)
while y < this.height {
assert y < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.height)
dst = tab.row(y: y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
if dst_bytes_per_row1 < tab.width() {
tab = tab.subtable(
min_incl_x: 0,
min_incl_y: 0,
max_incl_x: dst_bytes_per_row1,
max_incl_y: tab.height())
}
if dst_bytes_per_row0 < tab.width() {
tab = tab.subtable(
min_incl_x: dst_bytes_per_row0,
min_incl_y: 0,
max_incl_x: tab.width(),
max_incl_y: tab.height())
} else {
tab = tab.subtable(
min_incl_x: 0,
min_incl_y: 0,
max_incl_x: 0,
max_incl_y: 0)
}
y = this.frame_rect_y0
while y < this.frame_rect_y1 {
assert y < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.frame_rect_y1)
dst = tab.row_u32(y: y)
if 1 > args.workbuf.length() {
return "#internal error: inconsistent workbuf length"
+139 -28
View File
@@ -16,7 +16,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u64[..= 32]
var dst_bytes_per_row : base.u64
var dst_bytes_per_row1 : base.u64
var dst_palette : slice base.u8
var tab : table base.u8
@@ -45,7 +45,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
return base."#unsupported option"
}
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
dst_bytes_per_row1 = (this.frame_rect_x1 as base.u64) * dst_bytes_per_pixel
dst_palette = args.dst.palette_or_else(fallback: this.dst_palette[..])
tab = args.dst.plane(p: 0)
@@ -55,21 +55,16 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
((this.depth >> 3) as base.u64)
}
bits_unpacked[0] = 0xFF
bits_unpacked[1] = 0xFF
bits_unpacked[2] = 0xFF
bits_unpacked[3] = 0xFF
bits_unpacked[4] = 0xFF
bits_unpacked[5] = 0xFF
bits_unpacked[6] = 0xFF
bits_unpacked[7] = 0xFF
y = INTERLACING[this.interlace_pass][5] as base.u32
while y < this.height {
assert y < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.height)
dst = tab.row(y: y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
if (this.chunk_type_array[0] == 'I') {
y = INTERLACING[this.interlace_pass][5] as base.u32
} else {
y = this.frame_rect_y0
}
while y < this.frame_rect_y1 {
assert y < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.frame_rect_y1)
dst = tab.row_u32(y: y)
if dst_bytes_per_row1 < dst.length() {
dst = dst[.. dst_bytes_per_row1]
}
if 1 > args.workbuf.length() {
@@ -98,12 +93,16 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
}
s = curr_row
x = INTERLACING[this.interlace_pass][2] as base.u32
if (this.chunk_type_array[0] == 'I') {
x = INTERLACING[this.interlace_pass][2] as base.u32
} else {
x = this.frame_rect_x0
}
if this.depth == 8 {
while x < this.width,
while x < this.frame_rect_x1,
inv y < 0x00FF_FFFF,
{
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.width)
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.frame_rect_x1)
i = (x as base.u64) * dst_bytes_per_pixel
if i <= dst.length() {
if this.color_type == 4 {
@@ -118,6 +117,54 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
dst_palette: dst_palette,
src: bits_unpacked[.. 4])
}
} else if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) <> 0 {
if this.color_type == 0 {
if 1 <= s.length() {
bits_unpacked[0] = s[0]
bits_unpacked[1] = s[0]
bits_unpacked[2] = s[0]
bits_unpacked[3] = 0xFF
s = s[1 ..]
if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) == (
((bits_unpacked[0] as base.u32) << 0) |
((bits_unpacked[1] as base.u32) << 8) |
((bits_unpacked[2] as base.u32) << 16) |
((bits_unpacked[3] as base.u32) << 24)) {
bits_unpacked[0] = 0
bits_unpacked[1] = 0
bits_unpacked[2] = 0
bits_unpacked[3] = 0
}
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: bits_unpacked[.. 4])
}
} else {
if 3 <= s.length() {
bits_unpacked[0] = s[2]
bits_unpacked[1] = s[1]
bits_unpacked[2] = s[0]
bits_unpacked[3] = 0xFF
s = s[3 ..]
if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) == (
((bits_unpacked[0] as base.u32) << 0) |
((bits_unpacked[1] as base.u32) << 8) |
((bits_unpacked[2] as base.u32) << 16) |
((bits_unpacked[3] as base.u32) << 24)) {
bits_unpacked[0] = 0
bits_unpacked[1] = 0
bits_unpacked[2] = 0
bits_unpacked[3] = 0
}
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: bits_unpacked[.. 4])
}
}
} else if src_bytes_per_pixel <= s.length() {
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
@@ -137,11 +184,11 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
shift = (8 - this.depth) & 7
packs_remaining = 0
while x < this.width,
while x < this.frame_rect_x1,
inv y < 0x00FF_FFFF,
inv this.depth < 8,
{
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.width)
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.frame_rect_x1)
i = (x as base.u64) * dst_bytes_per_pixel
if i <= dst.length() {
if (packs_remaining == 0) and (1 <= s.length()) {
@@ -153,19 +200,40 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
bits_packed = bits_packed ~mod<< this.depth
packs_remaining = packs_remaining ~mod- 1
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: bits_unpacked[.. 1])
if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) <> 0 {
bits_unpacked[1] = bits_unpacked[0]
bits_unpacked[2] = bits_unpacked[0]
bits_unpacked[3] = 0xFF
if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) == (
((bits_unpacked[0] as base.u32) << 0) |
((bits_unpacked[1] as base.u32) << 8) |
((bits_unpacked[2] as base.u32) << 16) |
((bits_unpacked[3] as base.u32) << 24)) {
bits_unpacked[0] = 0
bits_unpacked[1] = 0
bits_unpacked[2] = 0
bits_unpacked[3] = 0
}
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: bits_unpacked[.. 4])
} else {
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: dst_palette,
src: bits_unpacked[.. 1])
}
}
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
} endwhile
} else {
while x < this.width,
while x < this.frame_rect_x1,
inv y < 0x00FF_FFFF,
{
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.width)
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.frame_rect_x1)
i = (x as base.u64) * dst_bytes_per_pixel
if i <= dst.length() {
if this.color_type == 0 {
@@ -176,8 +244,29 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
bits_unpacked[3] = s[0]
bits_unpacked[4] = s[1]
bits_unpacked[5] = s[0]
bits_unpacked[6] = 0xFF
bits_unpacked[7] = 0xFF
s = s[2 ..]
if this.remap_transparency == (
((bits_unpacked[0] as base.u64) << 0) |
((bits_unpacked[1] as base.u64) << 8) |
((bits_unpacked[2] as base.u64) << 16) |
((bits_unpacked[3] as base.u64) << 24) |
((bits_unpacked[4] as base.u64) << 32) |
((bits_unpacked[5] as base.u64) << 40) |
((bits_unpacked[6] as base.u64) << 48) |
((bits_unpacked[7] as base.u64) << 56)) {
bits_unpacked[0] = 0
bits_unpacked[1] = 0
bits_unpacked[2] = 0
bits_unpacked[3] = 0
bits_unpacked[4] = 0
bits_unpacked[5] = 0
bits_unpacked[6] = 0
bits_unpacked[7] = 0
}
}
} else if this.color_type == 2 {
if 6 <= s.length() {
bits_unpacked[0] = s[5]
@@ -186,8 +275,29 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
bits_unpacked[3] = s[2]
bits_unpacked[4] = s[1]
bits_unpacked[5] = s[0]
bits_unpacked[6] = 0xFF
bits_unpacked[7] = 0xFF
s = s[6 ..]
if this.remap_transparency == (
((bits_unpacked[0] as base.u64) << 0) |
((bits_unpacked[1] as base.u64) << 8) |
((bits_unpacked[2] as base.u64) << 16) |
((bits_unpacked[3] as base.u64) << 24) |
((bits_unpacked[4] as base.u64) << 32) |
((bits_unpacked[5] as base.u64) << 40) |
((bits_unpacked[6] as base.u64) << 48) |
((bits_unpacked[7] as base.u64) << 56)) {
bits_unpacked[0] = 0
bits_unpacked[1] = 0
bits_unpacked[2] = 0
bits_unpacked[3] = 0
bits_unpacked[4] = 0
bits_unpacked[5] = 0
bits_unpacked[6] = 0
bits_unpacked[7] = 0
}
}
} else if this.color_type == 4 {
if 4 <= s.length() {
bits_unpacked[0] = s[1]
@@ -200,6 +310,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
bits_unpacked[7] = s[2]
s = s[4 ..]
}
} else {
if 8 <= s.length() {
bits_unpacked[0] = s[5]
+2 -2
View File
@@ -196,7 +196,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
tab = args.dst.plane(p: 0)
while dst_y < this.height {
assert dst_y < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: this.height)
dst = tab.row(y: dst_y)
dst = tab.row_u32(y: dst_y)
dst_x = 0
while dst_x < this.width,
@@ -212,7 +212,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
{
yield? base."$short read"
tab = args.dst.plane(p: 0)
dst = tab.row(y: dst_y)
dst = tab.row_u32(y: dst_y)
dst_x_in_bytes = (dst_x as base.u64) * dst_bytes_per_pixel
if dst_x_in_bytes <= dst.length() {
dst = dst[dst_x_in_bytes ..]
+33
View File
@@ -0,0 +1,33 @@
// Copyright 2021 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// --------
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "zlib" is 0x1F_7F79. Left shifting by 10 gives
// 0x7DFD_E400.
pri const QUIRKS_BASE : base.u32 = 0x7DFD_E400
// --------
// When this quirk is enabled, the decoder speaks just raw deflate, without
// zlib's configuration prefix and checksum suffix wrapped around that.
//
// A zlib.decoder basically becomes a deflate.decoder. This is useful when the
// caller might want to choose between the two related-but-slightly-different
// formats at run time but would rather not allocate two separate decoders.
pub const QUIRK_JUST_RAW_DEFLATE : base.u32 = 0x7DFD_E400 | 0x00
pri const QUIRKS_COUNT : base.u32 = 0x01
+19 -5
View File
@@ -33,6 +33,8 @@ pub struct decoder? implements base.io_transformer(
got_dictionary : base.bool,
want_dictionary : base.bool,
quirks : array[QUIRKS_COUNT] base.bool,
ignore_checksum : base.bool,
checksum : adler32.hasher,
@@ -60,8 +62,15 @@ pub func decoder.add_dictionary!(dict: slice base.u8) {
}
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
if this.header_complete {
this.bad_call_sequence = true
} else if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
this.ignore_checksum = args.enabled
} else if args.quirk >= QUIRKS_BASE {
args.quirk -= QUIRKS_BASE
if args.quirk < QUIRKS_COUNT {
this.quirks[args.quirk] = args.enabled
}
}
}
@@ -80,6 +89,8 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
if this.bad_call_sequence {
return base."#bad call sequence"
} else if this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE] {
// No-op.
} else if not this.want_dictionary {
x = args.src.read_u16be?()
if ((x >> 8) & 0x0F) <> 0x08 {
@@ -112,7 +123,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
while true {
mark = args.dst.mark()
status =? this.flate.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
if not this.ignore_checksum {
if (not this.ignore_checksum) and (not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE]) {
checksum_got = this.checksum.update_u32!(x: args.dst.since(mark: mark))
}
if status.is_ok() {
@@ -120,9 +131,12 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
}
yield? status
} endwhile
checksum_want = args.src.read_u32be?()
if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
return "#bad checksum"
if not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE] {
checksum_want = args.src.read_u32be?()
if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
return "#bad checksum"
}
}
// TODO: reset state (e.g. want_dictionary), so that we can read concat'ed
+5
View File
@@ -0,0 +1,5 @@
# Ignore everything without a dot.
#
# This ignores "pngsuite" but not "fetch-pngsuite.sh".
*
!*.*
+5
View File
@@ -0,0 +1,5 @@
This directory contains third party test data, not checked into the repository
directly for download size and copyright reasons.
It also contains derived summary data files (such as `nia-checksums-of-*.txt`)
which *are* checked into the repository, for regression testing.
+26
View File
@@ -0,0 +1,26 @@
#!/bin/bash -eu
# Copyright 2021 The Wuffs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------
# This script fetches the PngSuite collection of PNG images.
if [ ! -e ../../wuffs-root-directory.txt ]; then
echo "$0 should be run from the Wuffs test/3pdata directory."
exit 1
fi
mkdir -p pngsuite
curl --silent http://www.schaik.com/pngsuite/PngSuite-2017jul19.tgz | tar -xzf /dev/stdin -C pngsuite
@@ -0,0 +1,29 @@
As per [the PngSuite page](http://www.schaik.com/pngsuite/#corrupted), every
`x*.png` file in the test suite is invalid PNG.
Nonetheless, `nia-checksums-of-pngsuite.txt` contains an entry for
`xcsn0g01.png`, meaning that `convert-to-nia` decoded *some* pixels for it.
This is working as intended, because the `xcsn0g01.png` invalidity is in its
`IDAT` chunk's checksum (compared to `xhdn0g08.png`'s corruption in its `IHDR`
chunk's checksum).
The `convert-to-nia` semantics are that, provided that it can decode a complete
image configuration (width, height, pixel format, etc which, for PNG, comes
from the `IHDR` chunk), it outputs *as many pixels as possible* (even if that's
zero pixels) so that it gives a 'best effort' decoding for truncated images.
Indeed, the NIA conversion for `xcsn0g01.png` holds all-zero pixels (and a
"png: bad checksum" error message on stderr) but also a zero exit code.
```
$ gen/bin/example-convert-to-nia < test/3pdata/pngsuite/xcsn0g01.png | hd
00000000 6e c3 af 41 ff 62 6e 34 20 00 00 00 20 00 00 00 |n..A.bn4 ... ...|
00000010 00 00 00 00 00 00 00 00 6e c3 af 45 ff 62 6e 34 |........n..E.bn4|
00000020 20 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 | ... ...........|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001020 00 00 00 00 00 00 00 00 |........|
00001028
png: bad checksum
$ echo $?
0
```
+164
View File
@@ -0,0 +1,164 @@
# Generated by script/print-nia-checksums.sh
aac44167 test/3pdata/pngsuite/PngSuite.png
926d3aa2 test/3pdata/pngsuite/basi0g01.png
8f50bdc6 test/3pdata/pngsuite/basi0g02.png
6d612626 test/3pdata/pngsuite/basi0g04.png
024cf410 test/3pdata/pngsuite/basi0g08.png
bb956205 test/3pdata/pngsuite/basi0g16.png
d1ae61d3 test/3pdata/pngsuite/basi2c08.png
84bc9be8 test/3pdata/pngsuite/basi2c16.png
49bc6b98 test/3pdata/pngsuite/basi3p01.png
ad12897b test/3pdata/pngsuite/basi3p02.png
81c22b59 test/3pdata/pngsuite/basi3p04.png
e59ecea5 test/3pdata/pngsuite/basi3p08.png
1b468494 test/3pdata/pngsuite/basi4a08.png
8a6dd244 test/3pdata/pngsuite/basi4a16.png
2b1044ce test/3pdata/pngsuite/basi6a08.png
b039babf test/3pdata/pngsuite/basi6a16.png
926d3aa2 test/3pdata/pngsuite/basn0g01.png
8f50bdc6 test/3pdata/pngsuite/basn0g02.png
6d612626 test/3pdata/pngsuite/basn0g04.png
024cf410 test/3pdata/pngsuite/basn0g08.png
bb956205 test/3pdata/pngsuite/basn0g16.png
d1ae61d3 test/3pdata/pngsuite/basn2c08.png
84bc9be8 test/3pdata/pngsuite/basn2c16.png
49bc6b98 test/3pdata/pngsuite/basn3p01.png
ad12897b test/3pdata/pngsuite/basn3p02.png
81c22b59 test/3pdata/pngsuite/basn3p04.png
e59ecea5 test/3pdata/pngsuite/basn3p08.png
1b468494 test/3pdata/pngsuite/basn4a08.png
8a6dd244 test/3pdata/pngsuite/basn4a16.png
2b1044ce test/3pdata/pngsuite/basn6a08.png
b039babf test/3pdata/pngsuite/basn6a16.png
1b468494 test/3pdata/pngsuite/bgai4a08.png
8a6dd244 test/3pdata/pngsuite/bgai4a16.png
2b1044ce test/3pdata/pngsuite/bgan6a08.png
b039babf test/3pdata/pngsuite/bgan6a16.png
1b468494 test/3pdata/pngsuite/bgbn4a08.png
8a6dd244 test/3pdata/pngsuite/bggn4a16.png
2b1044ce test/3pdata/pngsuite/bgwn6a08.png
b039babf test/3pdata/pngsuite/bgyn6a16.png
b58985e2 test/3pdata/pngsuite/ccwn2c08.png
b7f7127d test/3pdata/pngsuite/ccwn3p08.png
c7b4c0fa test/3pdata/pngsuite/cdfn2c08.png
dabf7a40 test/3pdata/pngsuite/cdhn2c08.png
8491ddf5 test/3pdata/pngsuite/cdsn2c08.png
d9282a90 test/3pdata/pngsuite/cdun2c08.png
81c22b59 test/3pdata/pngsuite/ch1n3p04.png
e59ecea5 test/3pdata/pngsuite/ch2n3p08.png
b3334ede test/3pdata/pngsuite/cm0n0g04.png
b3334ede test/3pdata/pngsuite/cm7n0g04.png
b3334ede test/3pdata/pngsuite/cm9n0g04.png
8ce6e28c test/3pdata/pngsuite/cs3n2c16.png
d565507c test/3pdata/pngsuite/cs3n3p08.png
2f5a21b9 test/3pdata/pngsuite/cs5n2c08.png
2f5a21b9 test/3pdata/pngsuite/cs5n3p08.png
8ce6e28c test/3pdata/pngsuite/cs8n2c08.png
8ce6e28c test/3pdata/pngsuite/cs8n3p08.png
b3334ede test/3pdata/pngsuite/ct0n0g04.png
b3334ede test/3pdata/pngsuite/ct1n0g04.png
1bfcb6e6 test/3pdata/pngsuite/cten0g04.png
8e493daf test/3pdata/pngsuite/ctfn0g04.png
417a539e test/3pdata/pngsuite/ctgn0g04.png
28033324 test/3pdata/pngsuite/cthn0g04.png
71a82501 test/3pdata/pngsuite/ctjn0g04.png
b3334ede test/3pdata/pngsuite/ctzn0g04.png
aa5328d3 test/3pdata/pngsuite/exif2c08.png
b81f03cc test/3pdata/pngsuite/f00n0g08.png
4a12368c test/3pdata/pngsuite/f00n2c08.png
7fe4a9d8 test/3pdata/pngsuite/f01n0g08.png
36758edc test/3pdata/pngsuite/f01n2c08.png
e0ab5774 test/3pdata/pngsuite/f02n0g08.png
5e613513 test/3pdata/pngsuite/f02n2c08.png
0719e3fa test/3pdata/pngsuite/f03n0g08.png
c4709cc1 test/3pdata/pngsuite/f03n2c08.png
457f1dab test/3pdata/pngsuite/f04n0g08.png
7ec3c986 test/3pdata/pngsuite/f04n2c08.png
1f319e46 test/3pdata/pngsuite/f99n0g04.png
6000bb5b test/3pdata/pngsuite/g03n0g16.png
aa019a24 test/3pdata/pngsuite/g03n2c08.png
8f0a3383 test/3pdata/pngsuite/g03n3p04.png
f3a44153 test/3pdata/pngsuite/g04n0g16.png
3e852c56 test/3pdata/pngsuite/g04n2c08.png
edb3555b test/3pdata/pngsuite/g04n3p04.png
6b105de1 test/3pdata/pngsuite/g05n0g16.png
938803a0 test/3pdata/pngsuite/g05n2c08.png
9f7ad612 test/3pdata/pngsuite/g05n3p04.png
28816978 test/3pdata/pngsuite/g07n0g16.png
fedb8920 test/3pdata/pngsuite/g07n2c08.png
9373010e test/3pdata/pngsuite/g07n3p04.png
58eb5aca test/3pdata/pngsuite/g10n0g16.png
8c5550d0 test/3pdata/pngsuite/g10n2c08.png
a6120550 test/3pdata/pngsuite/g10n3p04.png
14cc7e1c test/3pdata/pngsuite/g25n0g16.png
fd0f349f test/3pdata/pngsuite/g25n2c08.png
eb13812a test/3pdata/pngsuite/g25n3p04.png
bb956205 test/3pdata/pngsuite/oi1n0g16.png
84bc9be8 test/3pdata/pngsuite/oi1n2c16.png
bb956205 test/3pdata/pngsuite/oi2n0g16.png
84bc9be8 test/3pdata/pngsuite/oi2n2c16.png
bb956205 test/3pdata/pngsuite/oi4n0g16.png
84bc9be8 test/3pdata/pngsuite/oi4n2c16.png
bb956205 test/3pdata/pngsuite/oi9n0g16.png
84bc9be8 test/3pdata/pngsuite/oi9n2c16.png
84bc9be8 test/3pdata/pngsuite/pp0n2c16.png
8ed1f246 test/3pdata/pngsuite/pp0n6a08.png
024cf410 test/3pdata/pngsuite/ps1n0g08.png
84bc9be8 test/3pdata/pngsuite/ps1n2c16.png
024cf410 test/3pdata/pngsuite/ps2n0g08.png
84bc9be8 test/3pdata/pngsuite/ps2n2c16.png
7cf2b7b2 test/3pdata/pngsuite/s01i3p01.png
7cf2b7b2 test/3pdata/pngsuite/s01n3p01.png
ffa30c78 test/3pdata/pngsuite/s02i3p01.png
ffa30c78 test/3pdata/pngsuite/s02n3p01.png
ad298c62 test/3pdata/pngsuite/s03i3p01.png
ad298c62 test/3pdata/pngsuite/s03n3p01.png
2c30132c test/3pdata/pngsuite/s04i3p01.png
2c30132c test/3pdata/pngsuite/s04n3p01.png
5fb20358 test/3pdata/pngsuite/s05i3p02.png
5fb20358 test/3pdata/pngsuite/s05n3p02.png
764e90bd test/3pdata/pngsuite/s06i3p02.png
764e90bd test/3pdata/pngsuite/s06n3p02.png
9eebca92 test/3pdata/pngsuite/s07i3p02.png
9eebca92 test/3pdata/pngsuite/s07n3p02.png
d57f2e84 test/3pdata/pngsuite/s08i3p02.png
d57f2e84 test/3pdata/pngsuite/s08n3p02.png
7585127f test/3pdata/pngsuite/s09i3p02.png
7585127f test/3pdata/pngsuite/s09n3p02.png
034051a8 test/3pdata/pngsuite/s32i3p04.png
034051a8 test/3pdata/pngsuite/s32n3p04.png
a377dcdd test/3pdata/pngsuite/s33i3p04.png
a377dcdd test/3pdata/pngsuite/s33n3p04.png
5bcd998d test/3pdata/pngsuite/s34i3p04.png
5bcd998d test/3pdata/pngsuite/s34n3p04.png
1cefbbe2 test/3pdata/pngsuite/s35i3p04.png
1cefbbe2 test/3pdata/pngsuite/s35n3p04.png
97c763a3 test/3pdata/pngsuite/s36i3p04.png
97c763a3 test/3pdata/pngsuite/s36n3p04.png
2d6bd687 test/3pdata/pngsuite/s37i3p04.png
2d6bd687 test/3pdata/pngsuite/s37n3p04.png
169951e5 test/3pdata/pngsuite/s38i3p04.png
169951e5 test/3pdata/pngsuite/s38n3p04.png
17a92eb2 test/3pdata/pngsuite/s39i3p04.png
17a92eb2 test/3pdata/pngsuite/s39n3p04.png
8cc6b93d test/3pdata/pngsuite/s40i3p04.png
8cc6b93d test/3pdata/pngsuite/s40n3p04.png
4e406947 test/3pdata/pngsuite/tbbn0g04.png
c6e83019 test/3pdata/pngsuite/tbbn2c16.png
46deef3b test/3pdata/pngsuite/tbbn3p08.png
c6e83019 test/3pdata/pngsuite/tbgn2c16.png
46deef3b test/3pdata/pngsuite/tbgn3p08.png
c6e83019 test/3pdata/pngsuite/tbrn2c08.png
2289ed1e test/3pdata/pngsuite/tbwn0g16.png
46deef3b test/3pdata/pngsuite/tbwn3p08.png
46deef3b test/3pdata/pngsuite/tbyn3p08.png
59b23555 test/3pdata/pngsuite/tm3n3p02.png
f2457b64 test/3pdata/pngsuite/tp0n0g08.png
05846c5f test/3pdata/pngsuite/tp0n2c08.png
3d7708a8 test/3pdata/pngsuite/tp0n3p08.png
46deef3b test/3pdata/pngsuite/tp1n3p08.png
f286cbfc test/3pdata/pngsuite/xcsn0g01.png
9098c4d8 test/3pdata/pngsuite/z00n2c08.png
9098c4d8 test/3pdata/pngsuite/z03n2c08.png
9098c4d8 test/3pdata/pngsuite/z06n2c08.png
9098c4d8 test/3pdata/pngsuite/z09n2c08.png
+1 -2
View File
@@ -62,8 +62,7 @@ mimic_gif_decode(uint64_t* n_bytes_out,
goto cleanup1;
}
int i;
for (i = 0; i < f->ImageCount; i++) {
for (int i = 0; i < f->ImageCount; i++) {
// Copy the pixel data from the GifFileType* f to the dst buffer, since the
// former is free'd at the end of this function.
//
+2 -4
View File
@@ -64,8 +64,7 @@ mimic_png_decode(uint64_t* n_bytes_out,
spng_ctx* ctx = spng_ctx_new(0);
size_t i;
for (i = 0; i < quirks_len; i++) {
for (size_t i = 0; i < quirks_len; i++) {
uint32_t q = quirks_ptr[i];
if (q == WUFFS_BASE__QUIRK_IGNORE_CHECKSUM) {
spng_set_crc_action(ctx, SPNG_CRC_USE, SPNG_CRC_USE);
@@ -358,8 +357,7 @@ mimic_png_decode(uint64_t* n_bytes_out,
goto cleanup0;
}
size_t i;
for (i = 0; i < quirks_len; i++) {
for (size_t i = 0; i < quirks_len; i++) {
uint32_t q = quirks_ptr[i];
if (q == WUFFS_BASE__QUIRK_IGNORE_CHECKSUM) {
// TODO: configure libpng to ignore Adler-32 and CRC-32 checksums.
+4 -7
View File
@@ -131,15 +131,13 @@ test_wuffs_adler32_golden() {
},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, test_cases[tc].filename));
int j;
for (j = 0; j < 2; j++) {
for (int j = 0; j < 2; j++) {
wuffs_adler32__hasher checksum;
CHECK_STATUS("initialize",
wuffs_adler32__hasher__initialize(
@@ -164,7 +162,7 @@ test_wuffs_adler32_golden() {
} while (num_bytes < src.meta.wi);
if (have != test_cases[tc].want) {
RETURN_FAIL("tc=%d, j=%d, filename=\"%s\": have 0x%08" PRIX32
RETURN_FAIL("tc=%zu, j=%d, filename=\"%s\": have 0x%08" PRIX32
", want 0x%08" PRIX32 "\n",
tc, j, test_cases[tc].filename, have, test_cases[tc].want);
}
@@ -208,8 +206,7 @@ test_wuffs_adler32_pi() {
0xBEAA13C1, 0xD29C13F2, 0xE6C51429, 0xFB1E1459,
};
int i;
for (i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++) {
wuffs_adler32__hasher checksum;
CHECK_STATUS("initialize",
wuffs_adler32__hasher__initialize(
+4 -6
View File
@@ -117,8 +117,7 @@ test_wuffs_cbor_decode_invalid() {
"\xFE",
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__token tok_array[256];
wuffs_base__token_buffer tok_buf =
wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
@@ -138,7 +137,7 @@ test_wuffs_cbor_decode_invalid() {
wuffs_base__status status = wuffs_cbor__decoder__decode_tokens(
&dec, &tok_buf, &io_buf, g_work_slice_u8);
if (!wuffs_base__status__is_error(&status)) {
RETURN_FAIL("tc=%d: have \"%s\", want an error", tc, status.repr);
RETURN_FAIL("tc=%zu: have \"%s\", want an error", tc, status.repr);
}
}
return NULL;
@@ -159,8 +158,7 @@ test_wuffs_cbor_decode_valid() {
"\xD0\xBF\xFF",
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__token tok_array[256];
wuffs_base__token_buffer tok_buf =
wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
@@ -180,7 +178,7 @@ test_wuffs_cbor_decode_valid() {
wuffs_base__status status = wuffs_cbor__decoder__decode_tokens(
&dec, &tok_buf, &io_buf, g_work_slice_u8);
if (!wuffs_base__status__is_ok(&status)) {
RETURN_FAIL("tc=%d: have \"%s\", want no error", tc, status.repr);
RETURN_FAIL("tc=%zu: have \"%s\", want no error", tc, status.repr);
}
}
return NULL;
+4 -7
View File
@@ -131,15 +131,13 @@ test_wuffs_crc32_ieee_golden() {
},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, test_cases[tc].filename));
int j;
for (j = 0; j < 2; j++) {
for (int j = 0; j < 2; j++) {
wuffs_crc32__ieee_hasher checksum;
CHECK_STATUS("initialize",
wuffs_crc32__ieee_hasher__initialize(
@@ -164,7 +162,7 @@ test_wuffs_crc32_ieee_golden() {
} while (num_bytes < src.meta.wi);
if (have != test_cases[tc].want) {
RETURN_FAIL("tc=%d, j=%d, filename=\"%s\": have 0x%08" PRIX32
RETURN_FAIL("tc=%zu, j=%d, filename=\"%s\": have 0x%08" PRIX32
", want 0x%08" PRIX32,
tc, j, test_cases[tc].filename, have, test_cases[tc].want);
}
@@ -206,8 +204,7 @@ do_test_xxxxx_crc32_ieee_pi(bool mimic) {
0x4D9D54B7, 0xD69454CC, 0xF8BB504D, 0xFC4E595C,
};
int i;
for (i = 0; i < 100; i++) {
for (int i = 0; i < 100; i++) {
uint32_t have;
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
.ptr = (uint8_t*)(digits),
+37 -43
View File
@@ -74,55 +74,55 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// go run script/extract-flate-offsets.go test/data/*.gz
golden_test g_deflate_256_bytes_gt = {
.want_filename = "test/data/artificial/256.bytes",
.src_filename = "test/data/artificial/256.bytes.gz",
.want_filename = "test/data/256.bytes",
.src_filename = "test/data/256.bytes.gz",
.src_offset0 = 20,
.src_offset1 = 281,
};
golden_test g_deflate_deflate_backref_crosses_blocks_gt = {
.want_filename =
"test/data/artificial/"
"deflate-backref-crosses-blocks.deflate.decompressed",
"test/data/artificial-deflate/"
"backref-crosses-blocks.deflate.decompressed",
.src_filename =
"test/data/artificial/"
"deflate-backref-crosses-blocks.deflate",
"test/data/artificial-deflate/"
"backref-crosses-blocks.deflate",
};
golden_test g_deflate_deflate_degenerate_huffman_unused_gt = {
golden_test g_deflate_deflate_degenerate_huffman_gt = {
.want_filename =
"test/data/artificial/"
"deflate-degenerate-huffman-unused.deflate.decompressed",
"test/data/artificial-deflate/"
"degenerate-huffman.deflate.decompressed",
.src_filename =
"test/data/artificial/"
"deflate-degenerate-huffman-unused.deflate",
"test/data/artificial-deflate/"
"degenerate-huffman.deflate",
};
golden_test g_deflate_deflate_distance_32768_gt = {
.want_filename =
"test/data/artificial/"
"deflate-distance-32768.deflate.decompressed",
"test/data/artificial-deflate/"
"distance-32768.deflate.decompressed",
.src_filename =
"test/data/artificial/"
"deflate-distance-32768.deflate",
"test/data/artificial-deflate/"
"distance-32768.deflate",
};
golden_test g_deflate_deflate_distance_code_31_gt = {
.want_filename =
"test/data/artificial/"
"qdeflate-distance-code-31.deflate.decompressed",
"test/data/artificial-deflate/"
"qdistance-code-31.deflate.decompressed",
.src_filename =
"test/data/artificial/"
"deflate-distance-code-31.deflate",
"test/data/artificial-deflate/"
"distance-code-31.deflate",
};
golden_test g_deflate_deflate_huffman_primlen_9_gt = {
.want_filename =
"test/data/artificial/"
"deflate-huffman-primlen-9.deflate.decompressed",
"test/data/artificial-deflate/"
"huffman-primlen-9.deflate.decompressed",
.src_filename =
"test/data/artificial/"
"deflate-huffman-primlen-9.deflate",
"test/data/artificial-deflate/"
"huffman-primlen-9.deflate",
};
golden_test g_deflate_midsummer_gt = {
@@ -213,10 +213,10 @@ test_wuffs_deflate_decode_deflate_backref_crosses_blocks() {
}
const char* //
test_wuffs_deflate_decode_deflate_degenerate_huffman_unused() {
test_wuffs_deflate_decode_deflate_degenerate_huffman() {
CHECK_FOCUS(__func__);
return do_test_io_buffers(wuffs_deflate_decode,
&g_deflate_deflate_degenerate_huffman_unused_gt,
&g_deflate_deflate_degenerate_huffman_gt,
UINT64_MAX, UINT64_MAX);
}
@@ -269,8 +269,7 @@ test_wuffs_deflate_decode_deflate_huffman_primlen_9() {
CHECK_STATUS("transform_io", wuffs_deflate__decoder__transform_io(
&dec, &have, &src, g_work_slice_u8));
int i;
for (i = 0; i < 2; i++) {
for (int i = 0; i < 2; i++) {
// Find the first unused (i.e. zero) entry in the i'th huffs table.
int have = WUFFS_DEFLATE__HUFFS_TABLE_SIZE;
while ((have > 0) && (dec.private_data.f_huffs[i][have - 1] == 0)) {
@@ -354,8 +353,7 @@ test_wuffs_deflate_decode_split_src() {
CHECK_STRING(read_file(&src, gt->src_filename));
CHECK_STRING(read_file(&want, gt->want_filename));
int i;
for (i = 1; i < 32; i++) {
for (int i = 1; i < 32; i++) {
size_t split = gt->src_offset0 + i;
if (split >= gt->src_offset1) {
RETURN_FAIL("i=%d: split was not an interior split", i);
@@ -468,8 +466,7 @@ test_wuffs_deflate_history_full() {
CHECK_STRING(read_file(&want, gt->want_filename));
const int full_history_size = 0x8000;
int i;
for (i = -2; i <= +2; i++) {
for (int i = -2; i <= +2; i++) {
wuffs_deflate__decoder dec;
CHECK_STATUS("initialize",
wuffs_deflate__decoder__initialize(
@@ -531,8 +528,7 @@ test_wuffs_deflate_history_partial() {
0x8000, 0x8001, 0x9234, 0xFFFB, 0xFFFC, 0xFFFD, 0xFFFE, 0xFFFF,
};
int i;
for (i = 0; i < WUFFS_TESTLIB_ARRAY_SIZE(starting_history_indexes); i++) {
for (int i = 0; i < WUFFS_TESTLIB_ARRAY_SIZE(starting_history_indexes); i++) {
uint32_t starting_history_index = starting_history_indexes[i];
// The flate_pi_gt golden test file decodes to the digits of pi.
@@ -564,8 +560,7 @@ test_wuffs_deflate_history_partial() {
have_history_index, (int)(want_full), want_history_index);
}
int j;
for (j = -2; j < (int)(fragment_length) + 2; j++) {
for (int j = -2; j < (int)(fragment_length) + 2; j++) {
uint32_t index = (starting_history_index + j) & 0x7FFF;
uint8_t have = dec.private_data.f_history[index];
uint8_t want = (0 <= j && j < fragment_length) ? fragment[j] : 0;
@@ -633,7 +628,6 @@ test_wuffs_deflate_table_redirect() {
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
memset(&(dec.private_data.f_huffs), 0, sizeof(dec.private_data.f_huffs));
int i;
int n = 0;
dec.private_data.f_code_lengths[n++] = 1;
dec.private_data.f_code_lengths[n++] = 2;
@@ -644,7 +638,7 @@ test_wuffs_deflate_table_redirect() {
dec.private_data.f_code_lengths[n++] = 7;
dec.private_data.f_code_lengths[n++] = 9;
dec.private_data.f_code_lengths[n++] = 10;
for (i = 0; i < 19; i++) {
for (int i = 0; i < 19; i++) {
dec.private_data.f_code_lengths[n++] = 12;
}
dec.private_data.f_code_lengths[n++] = 13;
@@ -658,7 +652,7 @@ test_wuffs_deflate_table_redirect() {
// should be zero outside of those tables.
const int n_f_huffs = sizeof(dec.private_data.f_huffs[0]) /
sizeof(dec.private_data.f_huffs[0][0]);
for (i = 0; i < n_f_huffs; i++) {
for (int i = 0; i < n_f_huffs; i++) {
bool have = dec.private_data.f_huffs[0][i] == 0;
bool want = i >= (1 << 9) + (1 << 3) + (1 << 3) + (1 << 4);
if (have != want) {
@@ -696,7 +690,7 @@ test_wuffs_deflate_table_redirect() {
0x80000801, 0x80000903, 0x80000801, 0x80000B03,
0x80000801, 0x80000A03, 0x80000801, 0x80000C03,
};
for (i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
have = dec.private_data.f_huffs[0][0x0200 + i];
want = wants[i];
if (have != want) {
@@ -728,10 +722,10 @@ test_mimic_deflate_decode_deflate_backref_crosses_blocks() {
}
const char* //
test_mimic_deflate_decode_deflate_degenerate_huffman_unused() {
test_mimic_deflate_decode_deflate_degenerate_huffman() {
CHECK_FOCUS(__func__);
return do_test_io_buffers(mimic_deflate_decode,
&g_deflate_deflate_degenerate_huffman_unused_gt,
&g_deflate_deflate_degenerate_huffman_gt,
UINT64_MAX, UINT64_MAX);
}
@@ -896,7 +890,7 @@ proc g_tests[] = {
test_wuffs_deflate_decode_256_bytes,
test_wuffs_deflate_decode_deflate_backref_crosses_blocks,
test_wuffs_deflate_decode_deflate_degenerate_huffman_unused,
test_wuffs_deflate_decode_deflate_degenerate_huffman,
test_wuffs_deflate_decode_deflate_distance_32768,
test_wuffs_deflate_decode_deflate_distance_code_31,
test_wuffs_deflate_decode_deflate_huffman_primlen_9,
@@ -917,7 +911,7 @@ proc g_tests[] = {
test_mimic_deflate_decode_256_bytes,
test_mimic_deflate_decode_deflate_backref_crosses_blocks,
test_mimic_deflate_decode_deflate_degenerate_huffman_unused,
test_mimic_deflate_decode_deflate_degenerate_huffman,
test_mimic_deflate_decode_deflate_distance_32768,
test_mimic_deflate_decode_deflate_distance_code_31,
test_mimic_deflate_decode_deflate_huffman_primlen_9,
+100 -93
View File
@@ -252,11 +252,6 @@ do_test_wuffs_gif_decode(const char* filename,
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
&pb, &ic.pixcfg, g_pixel_slice_u8));
uint32_t have = wuffs_gif__decoder__num_animation_loops(&dec);
if (have != 1) {
RETURN_FAIL("num_animation_loops: have %" PRIu32 ", want 1", have);
}
}
int num_iters = 0;
@@ -355,8 +350,7 @@ do_test_wuffs_gif_decode(const char* filename,
}
if (dst_pixfmt.repr == WUFFS_BASE__PIXEL_FORMAT__BGR) {
size_t i;
for (i = 0; i < ind_want.meta.wi; i++) {
for (size_t i = 0; i < ind_want.meta.wi; i++) {
uint8_t index = ind_want.data.ptr[i];
expanded_want.data.ptr[3 * i + 0] = pal_want_array[4 * index + 0];
expanded_want.data.ptr[3 * i + 1] = pal_want_array[4 * index + 1];
@@ -364,8 +358,7 @@ do_test_wuffs_gif_decode(const char* filename,
}
expanded_want.meta.wi = 3 * ind_want.meta.wi;
} else if (dst_pixfmt.repr == WUFFS_BASE__PIXEL_FORMAT__BGR_565) {
size_t i;
for (i = 0; i < ind_want.meta.wi; i++) {
for (size_t i = 0; i < ind_want.meta.wi; i++) {
uint8_t index = ind_want.data.ptr[i];
uint32_t b5 = pal_want_array[4 * index + 0] >> 3;
uint32_t g6 = pal_want_array[4 * index + 1] >> 2;
@@ -376,8 +369,7 @@ do_test_wuffs_gif_decode(const char* filename,
}
expanded_want.meta.wi = 2 * ind_want.meta.wi;
} else if (dst_pixfmt.repr == WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL) {
size_t i;
for (i = 0; i < ind_want.meta.wi; i++) {
for (size_t i = 0; i < ind_want.meta.wi; i++) {
uint8_t index = ind_want.data.ptr[i];
expanded_want.data.ptr[4 * i + 0] = pal_want_array[4 * index + 0];
expanded_want.data.ptr[4 * i + 1] = pal_want_array[4 * index + 1];
@@ -386,8 +378,7 @@ do_test_wuffs_gif_decode(const char* filename,
}
expanded_want.meta.wi = 4 * ind_want.meta.wi;
} else if (dst_pixfmt.repr == WUFFS_BASE__PIXEL_FORMAT__RGB) {
size_t i;
for (i = 0; i < ind_want.meta.wi; i++) {
for (size_t i = 0; i < ind_want.meta.wi; i++) {
uint8_t index = ind_want.data.ptr[i];
expanded_want.data.ptr[3 * i + 0] = pal_want_array[4 * index + 2];
expanded_want.data.ptr[3 * i + 1] = pal_want_array[4 * index + 1];
@@ -395,8 +386,7 @@ do_test_wuffs_gif_decode(const char* filename,
}
expanded_want.meta.wi = 3 * ind_want.meta.wi;
} else if (dst_pixfmt.repr == WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL) {
size_t i;
for (i = 0; i < ind_want.meta.wi; i++) {
for (size_t i = 0; i < ind_want.meta.wi; i++) {
uint8_t index = ind_want.data.ptr[i];
expanded_want.data.ptr[4 * i + 0] = pal_want_array[4 * index + 2];
expanded_want.data.ptr[4 * i + 1] = pal_want_array[4 * index + 1];
@@ -427,6 +417,16 @@ do_test_wuffs_gif_decode(const char* filename,
}
}
{
uint32_t have = wuffs_gif__decoder__num_animation_loops(&dec);
uint32_t want =
(wuffs_gif__decoder__num_decoded_frame_configs(&dec) > 1) ? 1 : 0;
if (have != want) {
RETURN_FAIL("num_animation_loops: have %" PRIu32 ", want %" PRIu32, have,
want);
}
}
return NULL;
}
@@ -580,8 +580,7 @@ do_test_wuffs_gif_decode_animated(
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
&pb, &ic.pixcfg, g_pixel_slice_u8));
uint32_t i;
for (i = 0; i < want_num_frames; i++) {
for (uint32_t i = 0; i < want_num_frames; i++) {
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__status status =
wuffs_gif__decoder__decode_frame_config(&dec, &fc, &src);
@@ -618,7 +617,7 @@ do_test_wuffs_gif_decode_animated(
// There should be no more frames, no matter how many times we call
// decode_frame.
for (i = 0; i < 3; i++) {
for (uint32_t i = 0; i < 3; i++) {
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__note__end_of_data) {
@@ -685,8 +684,7 @@ test_wuffs_gif_decode_delay_num_frames_decoded() {
}
src.meta.wi--;
int q;
for (q = 0; q < 2; q++) {
for (int q = 0; q < 2; q++) {
src.meta.ri = 0;
wuffs_gif__decoder dec;
@@ -721,9 +719,8 @@ test_wuffs_gif_decode_empty_palette() {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/artificial/gif-empty-palette.gif"));
int q;
for (q = 0; q < 2; q++) {
CHECK_STRING(read_file(&src, "test/data/artificial-gif/empty-palette.gif"));
for (int q = 0; q < 2; q++) {
src.meta.ri = 0;
wuffs_gif__decoder dec;
@@ -748,8 +745,7 @@ test_wuffs_gif_decode_empty_palette() {
RETURN_FAIL("q=%d: set_from_slice: \"%s\"", q, status.repr);
}
int i;
for (i = 0; i < 2; i++) {
for (int i = 0; i < 2; i++) {
status = wuffs_gif__decoder__decode_frame(
&dec, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, g_work_slice_u8, NULL);
if ((q == 1) && (i == 1)) {
@@ -789,9 +785,8 @@ test_wuffs_gif_decode_background_color() {
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-background-color.gif"));
int q;
for (q = 0; q < 2; q++) {
read_file(&src, "test/data/artificial-gif/background-color.gif"));
for (int q = 0; q < 2; q++) {
src.meta.ri = 0;
wuffs_gif__decoder dec;
@@ -828,9 +823,8 @@ test_wuffs_gif_decode_first_frame_is_opaque() {
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-frame-out-of-bounds.gif"));
int q;
for (q = 0; q < 2; q++) {
read_file(&src, "test/data/artificial-gif/frame-out-of-bounds.gif"));
for (int q = 0; q < 2; q++) {
src.meta.ri = 0;
wuffs_gif__decoder dec;
@@ -866,9 +860,8 @@ test_wuffs_gif_decode_frame_out_of_bounds() {
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-frame-out-of-bounds.gif"));
int q;
for (q = 0; q < 2; q++) {
read_file(&src, "test/data/artificial-gif/frame-out-of-bounds.gif"));
for (int q = 0; q < 2; q++) {
src.meta.ri = 0;
wuffs_gif__decoder dec;
@@ -888,7 +881,7 @@ test_wuffs_gif_decode_frame_out_of_bounds() {
// The nominal width and height for the overall image is 2×2, but its first
// frame extends those bounds to 4×2. See
// test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt for
// test/data/artificial-gif/frame-out-of-bounds.gif.make-artificial.txt for
// more discussion.
const uint32_t width = q ? 2 : 4;
@@ -914,7 +907,7 @@ test_wuffs_gif_decode_frame_out_of_bounds() {
RETURN_FAIL("q=%d: set_from_slice: \"%s\"", q, status.repr);
}
// See test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt
// See test/data/artificial-gif/frame-out-of-bounds.gif.make-artificial.txt
// for the want_frame_config_bounds and want_pixel_indexes source.
wuffs_base__rect_ie_u32 want_frame_config_bounds[4] = {
@@ -931,8 +924,7 @@ test_wuffs_gif_decode_frame_out_of_bounds() {
q ? "...." : "..45..89",
};
uint32_t i;
for (i = 0; true; i++) {
for (uint32_t i = 0; true; i++) {
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
{
status = wuffs_gif__decoder__decode_frame_config(&dec, &fc, &src);
@@ -964,14 +956,13 @@ test_wuffs_gif_decode_frame_out_of_bounds() {
{
wuffs_base__table_u8 p = wuffs_base__pixel_buffer__plane(&pb, 0);
uint32_t y, x;
for (y = 0; y < 5; y++) {
for (x = 0; x < 5; x++) {
for (uint32_t y = 0; y < 5; y++) {
for (uint32_t x = 0; x < 5; x++) {
p.ptr[(y * p.stride) + x] = 0xEE;
}
}
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) {
p.ptr[(y * p.stride) + x] = 0;
}
}
@@ -984,8 +975,8 @@ test_wuffs_gif_decode_frame_out_of_bounds() {
status.repr);
}
for (y = 0; y < 5; y++) {
for (x = 0; x < 5; x++) {
for (uint32_t y = 0; y < 5; y++) {
for (uint32_t x = 0; x < 5; x++) {
if ((x < width) && (y < height)) {
continue;
}
@@ -1009,8 +1000,8 @@ test_wuffs_gif_decode_frame_out_of_bounds() {
}
char have[(width * height) + 1];
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) {
uint8_t index = 0x0F & p.ptr[(y * p.stride) + x];
have[(y * width) + x] = index ? ('0' + index) : '.';
}
@@ -1036,9 +1027,8 @@ test_wuffs_gif_decode_zero_width_frame() {
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-zero-width-frame.gif"));
int q;
for (q = 0; q < 3; q++) {
read_file(&src, "test/data/artificial-gif/zero-width-frame.gif"));
for (int q = 0; q < 3; q++) {
src.meta.ri = 0;
wuffs_gif__decoder dec;
@@ -1274,8 +1264,8 @@ do_test_wuffs_gif_decode_metadata(bool full) {
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, full ? "test/data/artificial/gif-metadata-full.gif"
: "test/data/artificial/gif-metadata-empty.gif"));
read_file(&src, full ? "test/data/artificial-gif/metadata-full.gif"
: "test/data/artificial-gif/metadata-empty.gif"));
int iccp;
for (iccp = 0; iccp < 2; iccp++) {
@@ -1327,12 +1317,14 @@ do_test_wuffs_gif_decode_metadata(bool full) {
if (wuffs_base__status__is_error(&status)) {
RETURN_FAIL("tell_me_more (iccp=%d, xmp=%d): \"%s\"", iccp, xmp,
status.repr);
} else if (minfo.flavor !=
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA) {
RETURN_FAIL("tell_me_more (iccp=%d, xmp=%d): flavor: have %" PRIu32
", want %" PRIu32,
iccp, xmp, minfo.flavor,
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA);
} else if (
minfo.flavor !=
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH) {
RETURN_FAIL(
"tell_me_more (iccp=%d, xmp=%d): flavor: have %" PRIu32
", want %" PRIu32,
iccp, xmp, minfo.flavor,
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH);
}
have_fourcc = wuffs_base__more_information__metadata__fourcc(&minfo);
@@ -1480,7 +1472,7 @@ test_wuffs_gif_decode_multiple_graphic_controls() {
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(
&src, "test/data/artificial/gif-multiple-graphic-controls.gif"));
&src, "test/data/artificial-gif/multiple-graphic-controls.gif"));
wuffs_gif__decoder dec;
CHECK_STATUS("initialize",
@@ -1507,7 +1499,7 @@ test_wuffs_gif_decode_multiple_loop_counts() {
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-multiple-loop-counts.gif"));
read_file(&src, "test/data/artificial-gif/multiple-loop-counts.gif"));
wuffs_gif__decoder dec;
CHECK_STATUS("initialize",
@@ -1518,29 +1510,27 @@ test_wuffs_gif_decode_multiple_loop_counts() {
CHECK_STATUS("decode_image_config",
wuffs_gif__decoder__decode_image_config(&dec, &ic, &src));
// See test/data/artificial/gif-multiple-loop-counts.gif.make-artificial.txt
// See test/data/artificial-gif/multiple-loop-counts.gif.make-artificial.txt
// for the want_num_animation_loops source. Note that the GIF wire format's
// loop counts are the number of animation loops *after* the first play
// through, and Wuffs' are the number *including* the first play through.
uint32_t want_num_animation_loops[4] = {1, 1, 51, 31};
uint32_t want_num_animation_loops[4] = {0, 1, 51, 31};
uint32_t i;
for (i = 0; true; i++) {
{
wuffs_base__status status =
wuffs_gif__decoder__decode_frame_config(&dec, NULL, &src);
if (i == WUFFS_TESTLIB_ARRAY_SIZE(want_num_animation_loops)) {
if (status.repr != wuffs_base__note__end_of_data) {
RETURN_FAIL("decode_frame_config #%" PRIu32
": have \"%s\", want \"%s\"",
i, status.repr, wuffs_base__note__end_of_data);
}
break;
}
if (!wuffs_base__status__is_ok(&status)) {
RETURN_FAIL("decode_frame_config #%" PRIu32 ": \"%s\"", i, status.repr);
uint32_t i = 0;
while (true) {
wuffs_base__status status =
wuffs_gif__decoder__decode_frame_config(&dec, NULL, &src);
if (i == WUFFS_TESTLIB_ARRAY_SIZE(want_num_animation_loops)) {
if (status.repr != wuffs_base__note__end_of_data) {
RETURN_FAIL("decode_frame_config #%" PRIu32
": have \"%s\", want \"%s\"",
i, status.repr, wuffs_base__note__end_of_data);
}
break;
}
if (!wuffs_base__status__is_ok(&status)) {
RETURN_FAIL("decode_frame_config #%" PRIu32 ": \"%s\"", i, status.repr);
}
uint32_t have = wuffs_gif__decoder__num_animation_loops(&dec);
@@ -1550,6 +1540,7 @@ test_wuffs_gif_decode_multiple_loop_counts() {
", want %" PRIu32,
i, have, want);
}
i++;
}
uint32_t have = wuffs_gif__decoder__num_animation_loops(&dec);
@@ -1587,7 +1578,7 @@ test_wuffs_gif_decode_pixel_data_none() {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/artificial/gif-pixel-data-none.gif"));
CHECK_STRING(read_file(&src, "test/data/artificial-gif/pixel-data-none.gif"));
return do_test_wuffs_gif_decode_expecting(
src, 0, wuffs_base__error__not_enough_data, true);
@@ -1600,7 +1591,7 @@ test_wuffs_gif_decode_pixel_data_not_enough() {
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-pixel-data-not-enough.gif"));
read_file(&src, "test/data/artificial-gif/pixel-data-not-enough.gif"));
return do_test_wuffs_gif_decode_expecting(
src, 0, wuffs_base__error__not_enough_data, false);
@@ -1612,11 +1603,20 @@ test_wuffs_gif_decode_pixel_data_too_much_sans_quirk() {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-pixel-data-too-much.gif"));
return do_test_wuffs_gif_decode_expecting(
src, 0, wuffs_base__error__too_much_data, false);
src.meta = wuffs_base__empty_io_buffer_meta();
CHECK_STRING(read_file(
&src, "test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif"));
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
src, 0, wuffs_lzw__error__bad_code, false));
src.meta = wuffs_base__empty_io_buffer_meta();
CHECK_STRING(read_file(
&src, "test/data/artificial-gif/pixel-data-too-much-good-lzw.gif"));
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
src, 0, wuffs_base__error__too_much_data, false));
return NULL;
}
const char* //
@@ -1625,11 +1625,20 @@ test_wuffs_gif_decode_pixel_data_too_much_with_quirk() {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-pixel-data-too-much.gif"));
return do_test_wuffs_gif_decode_expecting(
src, WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA, NULL, false);
src.meta = wuffs_base__empty_io_buffer_meta();
CHECK_STRING(read_file(
&src, "test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif"));
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
src, WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA, NULL, false));
src.meta = wuffs_base__empty_io_buffer_meta();
CHECK_STRING(read_file(
&src, "test/data/artificial-gif/pixel-data-too-much-good-lzw.gif"));
CHECK_STRING(do_test_wuffs_gif_decode_expecting(
src, WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA, NULL, false));
return NULL;
}
const char* //
@@ -1815,8 +1824,7 @@ do_test_wuffs_gif_io_position(bool chunked) {
wuffs_base__frame_config fcs[4];
uint32_t width_wants[4] = {64, 37, 49, 49};
uint64_t pos_wants[4] = {781, 2126, 2187, 2542};
int i;
for (i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++) {
fcs[i] = ((wuffs_base__frame_config){});
wuffs_base__status status =
wuffs_gif__decoder__decode_frame_config(&dec, &fcs[i], &src);
@@ -1878,7 +1886,7 @@ do_test_wuffs_gif_io_position(bool chunked) {
return NULL;
}
for (i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++) {
src.meta.ri = pos_wants[i];
status = wuffs_gif__decoder__restart_frame(
@@ -1887,8 +1895,7 @@ do_test_wuffs_gif_io_position(bool chunked) {
RETURN_FAIL("restart_frame #%d: \"%s\"", i, status.repr);
}
int j;
for (j = i; j < 4; j++) {
for (int j = i; j < 4; j++) {
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
status = wuffs_gif__decoder__decode_frame_config(&dec, &fc, &src);
if (!wuffs_base__status__is_ok(&status)) {
@@ -1939,7 +1946,7 @@ test_wuffs_gif_small_frame_interlaced() {
.data = g_src_slice_u8,
});
CHECK_STRING(
read_file(&src, "test/data/artificial/gif-small-frame-interlaced.gif"));
read_file(&src, "test/data/artificial-gif/small-frame-interlaced.gif"));
wuffs_gif__decoder dec;
CHECK_STATUS("initialize",
+1 -2
View File
@@ -160,8 +160,7 @@ do_test_wuffs_gzip_checksum(bool ignore_checksum, uint32_t bad_checksum) {
// Decode the src data in 1 or 2 chunks, depending on whether end_limit is
// or isn't zero.
int i;
for (i = 0; i < 2; i++) {
for (int i = 0; i < 2; i++) {
uint64_t rlimit = UINT64_MAX;
const char* want_z = NULL;
if (i == 0) {
+103 -153
View File
@@ -86,8 +86,7 @@ test_wuffs_core_count_leading_zeroes_u64() {
{.num = 0xFFFFFFFFFFFFFFFF, .want = 0},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
uint32_t have = wuffs_base__count_leading_zeroes_u64(test_cases[tc].num);
if (have != test_cases[tc].want) {
RETURN_FAIL("0x%" PRIX64 ": have %" PRIu32 ", want %" PRIu32,
@@ -122,8 +121,7 @@ test_wuffs_core_multiply_u64() {
.want_lo = 0x89B3DE09506618CF},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__multiply_u64__output have =
wuffs_base__multiply_u64(test_cases[tc].x, test_cases[tc].y);
if ((have.hi != test_cases[tc].want_hi) ||
@@ -343,8 +341,7 @@ test_wuffs_strconv_hpd_rounded_integer() {
{.want = UINT64_MAX, .str = "1234567890123456789"},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__private_implementation__high_prec_dec hpd;
CHECK_STATUS("hpd__parse",
wuffs_base__private_implementation__high_prec_dec__parse(
@@ -389,8 +386,7 @@ test_wuffs_strconv_hpd_shift() {
.want = "+314159000000000000000000000."},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__private_implementation__high_prec_dec hpd;
CHECK_STATUS("hpd__parse",
wuffs_base__private_implementation__high_prec_dec__parse(
@@ -499,8 +495,7 @@ test_wuffs_strconv_ieee_754_bit_representation_from_u16() {
},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
double have_f64 = wuffs_base__ieee_754_bit_representation__from_u16_to_f64(
test_cases[tc].u16_bits);
double want_f64 = test_cases[tc].want_f64;
@@ -508,7 +503,7 @@ test_wuffs_strconv_ieee_754_bit_representation_from_u16() {
bool equal = ((have_f64 == want_f64) ||
((have_f64 != have_f64) && (want_f64 != want_f64)));
if (!equal) {
RETURN_FAIL("tc=%d: to_f64: have %g, want %g", tc, have_f64, want_f64);
RETURN_FAIL("tc=%zu: to_f64: have %g, want %g", tc, have_f64, want_f64);
}
uint64_t have_u64 =
@@ -516,7 +511,7 @@ test_wuffs_strconv_ieee_754_bit_representation_from_u16() {
uint64_t want_u64 = test_cases[tc].want_u64;
// There's more than one representation of NaN.
if ((have_u64 != want_u64) && (want_u64 != nan_u64)) {
RETURN_FAIL("tc=%d: to_u64: have 0x%016" PRIX64 ", want 0x%016" PRIX64,
RETURN_FAIL("tc=%zu: to_u64: have 0x%016" PRIX64 ", want 0x%016" PRIX64,
tc, have_u64, want_u64);
}
@@ -530,13 +525,13 @@ test_wuffs_strconv_ieee_754_bit_representation_from_u16() {
wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
want_u64 ^ ((uint64_t)noise)));
if (lv.value != test_cases[tc].u16_bits) {
RETURN_FAIL("tc=%d: noise=%d: to_u16 value: have 0x%04" PRIX16
RETURN_FAIL("tc=%zu: noise=%d: to_u16 value: have 0x%04" PRIX16
", want 0x%04" PRIX16,
tc, noise, lv.value, test_cases[tc].u16_bits);
}
int want_lossy = (want_f64 == want_f64) ? noise : 0;
if (((int)lv.lossy) != want_lossy) {
RETURN_FAIL("tc=%d: noise=%d: to_u16 lossy: have %d, want %d", tc,
RETURN_FAIL("tc=%zu: noise=%d: to_u16 lossy: have %d, want %d", tc,
noise, ((int)(lv.lossy)), want_lossy);
}
}
@@ -621,8 +616,7 @@ test_wuffs_strconv_ieee_754_bit_representation_from_u32() {
},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
double have_f64 = wuffs_base__ieee_754_bit_representation__from_u32_to_f64(
test_cases[tc].u32_bits);
double want_f64 = test_cases[tc].want_f64;
@@ -630,7 +624,7 @@ test_wuffs_strconv_ieee_754_bit_representation_from_u32() {
bool equal = ((have_f64 == want_f64) ||
((have_f64 != have_f64) && (want_f64 != want_f64)));
if (!equal) {
RETURN_FAIL("tc=%d: to_f64: have %g, want %g", tc, have_f64, want_f64);
RETURN_FAIL("tc=%zu: to_f64: have %g, want %g", tc, have_f64, want_f64);
}
uint64_t have_u64 =
@@ -638,7 +632,7 @@ test_wuffs_strconv_ieee_754_bit_representation_from_u32() {
uint64_t want_u64 = test_cases[tc].want_u64;
// There's more than one representation of NaN.
if ((have_u64 != want_u64) && (want_u64 != nan_u64)) {
RETURN_FAIL("tc=%d: to_u64: have 0x%016" PRIX64 ", want 0x%016" PRIX64,
RETURN_FAIL("tc=%zu: to_u64: have 0x%016" PRIX64 ", want 0x%016" PRIX64,
tc, have_u64, want_u64);
}
@@ -652,13 +646,13 @@ test_wuffs_strconv_ieee_754_bit_representation_from_u32() {
wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
want_u64 ^ ((uint64_t)noise)));
if (lv.value != test_cases[tc].u32_bits) {
RETURN_FAIL("tc=%d: noise=%d: to_u32 value: have 0x%08" PRIX32
RETURN_FAIL("tc=%zu: noise=%d: to_u32 value: have 0x%08" PRIX32
", want 0x%08" PRIX32,
tc, noise, lv.value, test_cases[tc].u32_bits);
}
int want_lossy = (want_f64 == want_f64) ? noise : 0;
if (((int)lv.lossy) != want_lossy) {
RETURN_FAIL("tc=%d: noise=%d: to_u32 lossy: have %d, want %d", tc,
RETURN_FAIL("tc=%zu: noise=%d: to_u32 lossy: have %d, want %d", tc,
noise, ((int)(lv.lossy)), want_lossy);
}
}
@@ -749,8 +743,7 @@ test_wuffs_strconv_base_64() {
"Zm9vYmFy", //
};
size_t tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(wants); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(wants); tc++) {
const bool src_closed = true;
wuffs_base__transform__output e = wuffs_base__base_64__encode(
@@ -828,8 +821,7 @@ test_wuffs_strconv_parse_number_f64_options() {
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES.
{
int o;
for (o = 0; o < 2; o++) {
for (int o = 0; o < 2; o++) {
const char* str = "001.25";
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
@@ -859,8 +851,7 @@ test_wuffs_strconv_parse_number_f64_options() {
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES.
{
int o;
for (o = 0; o < 2; o++) {
for (int o = 0; o < 2; o++) {
const char* str = "_1.2__5";
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
@@ -889,8 +880,7 @@ test_wuffs_strconv_parse_number_f64_options() {
// Test WUFFS_BASE__PARSE_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA.
{
int o;
for (o = 0; o < 2; o++) {
for (int o = 0; o < 2; o++) {
const char* str = "1,75";
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
@@ -920,8 +910,7 @@ test_wuffs_strconv_parse_number_f64_options() {
// Test WUFFS_BASE__PARSE_NUMBER_FXX__REJECT_INF_AND_NAN.
{
int o;
for (o = 0; o < 4; o++) {
for (int o = 0; o < 4; o++) {
const char* str = (o & 2) ? "1e999" : "nan";
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
@@ -1085,8 +1074,7 @@ test_wuffs_strconv_parse_number_f64_regular() {
{.want = fail, .str = "nun"},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
strlen(test_cases[tc].str)),
@@ -1138,8 +1126,7 @@ test_wuffs_strconv_parse_number_i64() {
{.want = fail, .str = "9223372036854775808"}, // 1 << 63.
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__result_i64 r = wuffs_base__parse_number_i64(
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
strlen(test_cases[tc].str)),
@@ -1225,8 +1212,7 @@ test_wuffs_strconv_parse_number_u64() {
{.want = fail, .str = "x"},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
wuffs_base__make_slice_u8((void*)test_cases[tc].str,
strlen(test_cases[tc].str)),
@@ -1240,8 +1226,7 @@ test_wuffs_strconv_parse_number_u64() {
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES.
{
int o;
for (o = 0; o < 2; o++) {
for (int o = 0; o < 2; o++) {
const char* str = "007";
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
@@ -1269,8 +1254,7 @@ test_wuffs_strconv_parse_number_u64() {
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES.
{
int o;
for (o = 0; o < 2; o++) {
for (int o = 0; o < 2; o++) {
const char* str = "56_7__8";
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
wuffs_base__make_slice_u8((void*)str, strlen(str)),
@@ -2135,12 +2119,10 @@ test_wuffs_strconv_render_number_f64() {
},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
double f64 = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
test_cases[tc].x);
int o;
for (o = 0; o < 6; o++) {
for (int o = 0; o < 6; o++) {
uint32_t precision = 0;
uint32_t options = 0;
const char* want = NULL;
@@ -2189,8 +2171,7 @@ test_wuffs_strconv_render_number_f64() {
// Test WUFFS_BASE__RENDER_NUMBER_FXX__DECIMAL_SEPARATOR_IS_A_COMMA.
{
int o;
for (o = 0; o < 2; o++) {
for (int o = 0; o < 2; o++) {
uint8_t dst[8] = {0};
const double f64 = 1.75;
const uint32_t precision = 2;
@@ -2263,8 +2244,7 @@ test_wuffs_strconv_render_number_i64() {
return "g_have_slice_u8.len is too short";
}
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
size_t n = wuffs_base__render_number_i64(
g_have_slice_u8, test_cases[tc].x,
WUFFS_BASE__RENDER_NUMBER_XXX__DEFAULT_OPTIONS);
@@ -2318,8 +2298,7 @@ test_wuffs_strconv_render_number_u64() {
return "g_have_slice_u8.len is too short";
}
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
size_t n = wuffs_base__render_number_u64(
g_have_slice_u8, test_cases[tc].x,
WUFFS_BASE__RENDER_NUMBER_XXX__DEFAULT_OPTIONS);
@@ -2466,8 +2445,7 @@ test_wuffs_strconv_utf_8_next() {
{.want0 = 0x0100FFFD, .want1 = 0x0100FFFD, .str = "\xED\xBF\xBF"},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__slice_u8 s = wuffs_base__make_slice_u8(
(void*)test_cases[tc].str, strlen(test_cases[tc].str));
// Override "The <NUL> byte" with "\x00".
@@ -2590,8 +2568,7 @@ test_wuffs_json_decode_interface() {
wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
uint32_t i;
for (i = 0; quirks[i]; i++) {
for (size_t i = 0; quirks[i]; i++) {
wuffs_json__decoder__set_quirk_enabled(&dec, quirks[i], true);
}
CHECK_STRING(do_test__wuffs_base__token_decoder(
@@ -2638,8 +2615,7 @@ const char* //
test_wuffs_json_decode_end_of_data() {
CHECK_FOCUS(__func__);
int i;
for (i = 0; i < 2; i++) {
for (int i = 0; i < 2; i++) {
uint8_t* src_ptr = (uint8_t*)("123null89");
size_t src_len = i ? 3 : 9;
@@ -2731,11 +2707,10 @@ test_wuffs_json_decode_long_numbers() {
wuffs_json__decoder dec;
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
size_t suffix_length = strlen(test_cases[tc].suffix);
if ((suffix_length + 1) > (119 - 102)) { // +1 for the terminal NUL.
RETURN_FAIL("tc=%d: src_array is too short", tc);
RETURN_FAIL("tc=%zu: src_array is too short", tc);
}
bool ends_with_space = (suffix_length > 0) &&
(test_cases[tc].suffix[suffix_length - 1] == ' ');
@@ -2776,7 +2751,7 @@ test_wuffs_json_decode_long_numbers() {
}
if (total_length != src.meta.ri) {
RETURN_FAIL(
"tc=%d, nines_length=%zu, closed=%d: total_length: have %zu, "
"tc=%zu, nines_length=%zu, closed=%d: total_length: have %zu, "
"want %zu",
tc, nines_length, closed, total_length, src.meta.ri);
}
@@ -2792,7 +2767,7 @@ test_wuffs_json_decode_long_numbers() {
if (have != want) {
RETURN_FAIL(
"tc=%d, nines_length=%zu, closed=%d: have \"%s\", want \"%s\"",
"tc=%zu, nines_length=%zu, closed=%d: have \"%s\", want \"%s\"",
tc, nines_length, closed, have, want);
}
}
@@ -2861,8 +2836,7 @@ test_wuffs_json_decode_prior_valid_utf_8() {
wuffs_json__decoder dec;
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
size_t n = strlen(test_cases[tc]);
size_t num_preceding = 0;
while (num_preceding < n) {
@@ -2874,7 +2848,7 @@ test_wuffs_json_decode_prior_valid_utf_8() {
}
num_preceding += x.byte_length;
if (num_preceding > n) {
RETURN_FAIL("tc=%d: utf_8__next overflow", tc);
RETURN_FAIL("tc=%zu: utf_8__next overflow", tc);
}
}
@@ -2922,7 +2896,7 @@ test_wuffs_json_decode_prior_valid_utf_8() {
have += wuffs_base__token__length(t);
} else {
RETURN_FAIL(
"tc=%d, prefix=%zu, suffix=%zu, closed=%d: unexpected token",
"tc=%zu, prefix=%zu, suffix=%zu, closed=%d: unexpected token",
tc, prefix, suffix, closed);
}
}
@@ -2932,7 +2906,7 @@ test_wuffs_json_decode_prior_valid_utf_8() {
}
if (have != want) {
RETURN_FAIL(
"tc=%d, prefix=%zu, suffix=%zu, closed=%d: have %zu, want %zu",
"tc=%zu, prefix=%zu, suffix=%zu, closed=%d: have %zu, want %zu",
tc, prefix, suffix, closed, have, want);
}
}
@@ -2999,10 +2973,8 @@ test_wuffs_json_decode_quirk_allow_backslash_etc() {
},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
int q;
for (q = 0; q < 2; q++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (int q = 0; q < 2; q++) {
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3025,7 +2997,7 @@ test_wuffs_json_decode_quirk_allow_backslash_etc() {
want_status_repr = wuffs_json__error__bad_c0_control_code;
}
if (have_status_repr != want_status_repr) {
RETURN_FAIL("tc=%d, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
RETURN_FAIL("tc=%zu, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
q, have_status_repr, want_status_repr);
}
if (want_status_repr != NULL) {
@@ -3043,7 +3015,7 @@ test_wuffs_json_decode_quirk_allow_backslash_etc() {
}
}
if (have != test_cases[tc].want) {
RETURN_FAIL("tc=%d, q=%d: Unicode code point: have U+%04" PRIX32
RETURN_FAIL("tc=%zu, q=%d: Unicode code point: have U+%04" PRIX32
", want U+%04" PRIX32,
tc, q, have, test_cases[tc].want);
}
@@ -3084,8 +3056,7 @@ test_wuffs_json_decode_quirk_allow_backslash_x() {
.str = "\"a\\x\""},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3102,7 +3073,7 @@ test_wuffs_json_decode_quirk_allow_backslash_x() {
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
.repr;
if (have_status_repr != test_cases[tc].want_status_repr) {
RETURN_FAIL("tc=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
RETURN_FAIL("tc=%zu: decode_tokens: have \"%s\", want \"%s\"", tc,
have_status_repr, test_cases[tc].want_status_repr);
}
@@ -3130,7 +3101,7 @@ test_wuffs_json_decode_quirk_allow_backslash_x() {
}
uint64_t want = test_cases[tc].want_code_points;
if (have != want) {
RETURN_FAIL("tc=%d: have U+%08" PRIX64 ", want U+%08" PRIX64, tc, have,
RETURN_FAIL("tc=%zu: have U+%08" PRIX64 ", want U+%08" PRIX64, tc, have,
want);
}
}
@@ -3156,10 +3127,8 @@ test_wuffs_json_decode_quirk_allow_extra_comma() {
{.want = "--", .str = "{,}"},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
int q;
for (q = 0; q < 2; q++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (int q = 0; q < 2; q++) {
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3177,7 +3146,7 @@ test_wuffs_json_decode_quirk_allow_extra_comma() {
const char* want =
(test_cases[tc].want[q] != '-') ? NULL : wuffs_json__error__bad_input;
if (have != want) {
RETURN_FAIL("tc=%d, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
RETURN_FAIL("tc=%zu, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
q, have, want);
}
@@ -3186,17 +3155,17 @@ test_wuffs_json_decode_quirk_allow_extra_comma() {
total_length += wuffs_base__token__length(&tok.data.ptr[tok.meta.ri++]);
}
if (total_length != src.meta.ri) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.meta.ri);
}
if (test_cases[tc].want[q] == 'X') {
if (total_length != src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.data.len);
}
} else if (test_cases[tc].want[q] == '+') {
if (total_length >= src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want < %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want < %zu", tc, q,
total_length, src.data.len);
}
}
@@ -3231,10 +3200,8 @@ test_wuffs_json_decode_quirk_allow_inf_nan_numbers() {
{.want = "--", .str = "∞"},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
int q;
for (q = 0; q < 2; q++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (int q = 0; q < 2; q++) {
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3252,7 +3219,7 @@ test_wuffs_json_decode_quirk_allow_inf_nan_numbers() {
const char* want =
(test_cases[tc].want[q] != '-') ? NULL : wuffs_json__error__bad_input;
if (have != want) {
RETURN_FAIL("tc=%d, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
RETURN_FAIL("tc=%zu, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
q, have, want);
}
@@ -3261,17 +3228,17 @@ test_wuffs_json_decode_quirk_allow_inf_nan_numbers() {
total_length += wuffs_base__token__length(&tok.data.ptr[tok.meta.ri++]);
}
if (total_length != src.meta.ri) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.meta.ri);
}
if (test_cases[tc].want[q] == 'X') {
if (total_length != src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.data.len);
}
} else if (test_cases[tc].want[q] == '+') {
if (total_length >= src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want < %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want < %zu", tc, q,
total_length, src.data.len);
}
}
@@ -3300,10 +3267,8 @@ test_wuffs_json_decode_quirk_allow_comment_etc() {
{.want = "----", .str = "[4/5]"}, // Lone slash.
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
int q;
for (q = 0; q < 4; q++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (int q = 0; q < 4; q++) {
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3323,7 +3288,7 @@ test_wuffs_json_decode_quirk_allow_comment_etc() {
const char* want =
(test_cases[tc].want[q] != '-') ? NULL : wuffs_json__error__bad_input;
if (have != want) {
RETURN_FAIL("tc=%d, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
RETURN_FAIL("tc=%zu, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
q, have, want);
}
@@ -3332,17 +3297,17 @@ test_wuffs_json_decode_quirk_allow_comment_etc() {
total_length += wuffs_base__token__length(&tok.data.ptr[tok.meta.ri++]);
}
if (total_length != src.meta.ri) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.meta.ri);
}
if (test_cases[tc].want[q] == 'X') {
if (total_length != src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.data.len);
}
} else if (test_cases[tc].want[q] == '+') {
if (total_length >= src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want < %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want < %zu", tc, q,
total_length, src.data.len);
}
}
@@ -3377,10 +3342,8 @@ test_wuffs_json_decode_quirk_allow_leading_etc() {
{.want = "----", .str = "\xEFtrue"},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
int q;
for (q = 0; q < 4; q++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (int q = 0; q < 4; q++) {
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3400,7 +3363,7 @@ test_wuffs_json_decode_quirk_allow_leading_etc() {
const char* want =
(test_cases[tc].want[q] != '-') ? NULL : wuffs_json__error__bad_input;
if (have != want) {
RETURN_FAIL("tc=%d, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
RETURN_FAIL("tc=%zu, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
q, have, want);
}
@@ -3409,17 +3372,17 @@ test_wuffs_json_decode_quirk_allow_leading_etc() {
total_length += wuffs_base__token__length(&tok.data.ptr[tok.meta.ri++]);
}
if (total_length != src.meta.ri) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.meta.ri);
}
if (test_cases[tc].want[q] == 'X') {
if (total_length != src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.data.len);
}
} else if (test_cases[tc].want[q] == '+') {
if (total_length >= src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want < %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want < %zu", tc, q,
total_length, src.data.len);
}
}
@@ -3472,10 +3435,8 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
"515 9", //
};
int tc;
// Test ALLOW_ETC.
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
void* tc_ptr = (void*)(test_cases[tc]);
size_t tc_len = strlen(test_cases[tc]);
char code = test_cases[tc][0];
@@ -3499,8 +3460,8 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8)
.repr;
if (have_repr != NULL) {
RETURN_FAIL("tc=%d, ALLOW_ETC: decode_tokens: have \"%s\", want NULL", tc,
have_repr);
RETURN_FAIL("tc=%zu, ALLOW_ETC: decode_tokens: have \"%s\", want NULL",
tc, have_repr);
}
size_t have_total_length = 0;
@@ -3510,16 +3471,16 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
}
size_t want_total_length = tc_len - ((code >= '4') ? 1 : 0);
if (have_total_length != src.meta.ri) {
RETURN_FAIL("tc=%d, ALLOW_ETC: total_length: have %zu, want %zu", tc,
RETURN_FAIL("tc=%zu, ALLOW_ETC: total_length: have %zu, want %zu", tc,
have_total_length, src.meta.ri);
} else if (have_total_length != want_total_length) {
RETURN_FAIL("tc=%d, ALLOW_ETC: total_length: have %zu, want %zu", tc,
RETURN_FAIL("tc=%zu, ALLOW_ETC: total_length: have %zu, want %zu", tc,
have_total_length, want_total_length);
}
}
// Test EXPECT_ETC.
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
void* tc_ptr = (void*)(test_cases[tc]);
size_t tc_len = strlen(test_cases[tc]);
char code = test_cases[tc][0];
@@ -3541,7 +3502,7 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
const char* want_repr =
((code == '3') || (code == '5')) ? wuffs_json__error__bad_input : NULL;
if (have_repr != want_repr) {
RETURN_FAIL("tc=%d, EXPECT_ETC: decode_tokens: have \"%s\", want \"%s\"",
RETURN_FAIL("tc=%zu, EXPECT_ETC: decode_tokens: have \"%s\", want \"%s\"",
tc, have_repr, want_repr);
} else if (have_repr != NULL) {
continue;
@@ -3554,10 +3515,10 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
}
size_t want_total_length = tc_len - ((code == '1') ? 0 : 1);
if (have_total_length != src.meta.ri) {
RETURN_FAIL("tc=%d, EXPECT_ETC: total_length: have %zu, want %zu", tc,
RETURN_FAIL("tc=%zu, EXPECT_ETC: total_length: have %zu, want %zu", tc,
have_total_length, src.meta.ri);
} else if (have_total_length != want_total_length) {
RETURN_FAIL("tc=%d, EXPECT_ETC: total_length: have %zu, want %zu", tc,
RETURN_FAIL("tc=%zu, EXPECT_ETC: total_length: have %zu, want %zu", tc,
have_total_length, want_total_length);
}
}
@@ -3594,10 +3555,8 @@ test_wuffs_json_decode_quirk_allow_trailing_filler() {
{.want = "XXX", .str = "0"}, //
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
int q;
for (q = 0; q < 3; q++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (int q = 0; q < 3; q++) {
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3617,7 +3576,7 @@ test_wuffs_json_decode_quirk_allow_trailing_filler() {
const char* want =
(test_cases[tc].want[q] != '-') ? NULL : wuffs_json__error__bad_input;
if (have != want) {
RETURN_FAIL("tc=%d, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
RETURN_FAIL("tc=%zu, q=%d: decode_tokens: have \"%s\", want \"%s\"", tc,
q, have, want);
}
@@ -3626,17 +3585,17 @@ test_wuffs_json_decode_quirk_allow_trailing_filler() {
total_length += wuffs_base__token__length(&tok.data.ptr[tok.meta.ri++]);
}
if (total_length != src.meta.ri) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.meta.ri);
}
if (test_cases[tc].want[q] == 'X') {
if (total_length != src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want %zu", tc, q,
total_length, src.data.len);
}
} else if (test_cases[tc].want[q] == '+') {
if (total_length >= src.data.len) {
RETURN_FAIL("tc=%d, q=%d: total_length: have %zu, want < %zu", tc, q,
RETURN_FAIL("tc=%zu, q=%d: total_length: have %zu, want < %zu", tc, q,
total_length, src.data.len);
}
}
@@ -3694,8 +3653,7 @@ test_wuffs_json_decode_quirk_replace_invalid_unicode() {
{.want = "a\xF0\x90\x80\x80?z", .str = "\"a\\uD800\\uDC00\\uDFFFz\""},
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_json__decoder dec;
CHECK_STATUS("initialize", wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3729,7 +3687,7 @@ test_wuffs_json_decode_quirk_replace_invalid_unicode() {
n = 1;
}
if ((have.data.len - have.meta.wi) < n) {
RETURN_FAIL("tc=%d: token too long", tc);
RETURN_FAIL("tc=%zu: token too long", tc);
}
memcpy(&have.data.ptr[have.meta.wi], &u[0], n);
have.meta.wi += n;
@@ -3740,35 +3698,35 @@ test_wuffs_json_decode_quirk_replace_invalid_unicode() {
} else if (vbd &
WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY) {
if ((have.data.len - have.meta.wi) < token_length) {
RETURN_FAIL("tc=%d: token too long", tc);
RETURN_FAIL("tc=%zu: token too long", tc);
}
memcpy(&have.data.ptr[have.meta.wi], &test_cases[tc].str[src_index],
token_length);
have.meta.wi += token_length;
} else {
RETURN_FAIL("tc=%d: unexpected string-token conversion", tc);
RETURN_FAIL("tc=%zu: unexpected string-token conversion", tc);
}
} else {
RETURN_FAIL("tc=%d: unexpected token", tc);
RETURN_FAIL("tc=%zu: unexpected token", tc);
}
src_index += token_length;
}
if (src_index != src.meta.ri) {
RETURN_FAIL("tc=%d: src_index: have %" PRIu64 ", want %zu", tc, src_index,
src.meta.ri);
RETURN_FAIL("tc=%zu: src_index: have %" PRIu64 ", want %zu", tc,
src_index, src.meta.ri);
}
if (have.meta.wi >= have.data.len) {
RETURN_FAIL("tc=%d: too many have bytes", tc);
RETURN_FAIL("tc=%zu: too many have bytes", tc);
}
have.data.ptr[have.meta.wi] = '\x00';
size_t len = strlen(test_cases[tc].want);
if ((len != have.meta.wi) ||
(memcmp(have.data.ptr, test_cases[tc].want, len) != 0)) {
RETURN_FAIL("tc=%d: have \"%s\", want \"%s\"", tc, have.data.ptr,
RETURN_FAIL("tc=%zu: have \"%s\", want \"%s\"", tc, have.data.ptr,
test_cases[tc].want);
}
}
@@ -3829,8 +3787,7 @@ test_wuffs_json_decode_unicode4_escapes() {
};
wuffs_json__decoder dec;
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
CHECK_STATUS("initialize",
wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -3844,8 +3801,7 @@ test_wuffs_json_decode_unicode4_escapes() {
uint32_t have = fail;
uint64_t total_length = 0;
size_t i;
for (i = tok.meta.ri; i < tok.meta.wi; i++) {
for (size_t i = tok.meta.ri; i < tok.meta.wi; i++) {
wuffs_base__token* t = &tok.data.ptr[i];
total_length =
wuffs_base__u64__sat_add(total_length, wuffs_base__token__length(t));
@@ -3907,8 +3863,7 @@ test_wuffs_json_decode_src_io_buffer_length() {
wuffs_json__decoder dec;
int i;
for (i = WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL - 2;
for (int i = WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL - 2;
i <= WUFFS_JSON__DECODER_NUMBER_LENGTH_MAX_INCL + 2; i++) {
if (i < 0) {
RETURN_FAIL("invalid test case: i=%d", i);
@@ -4019,8 +3974,7 @@ test_wuffs_json_decode_string() {
};
wuffs_json__decoder dec;
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
CHECK_STATUS("initialize",
wuffs_json__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
@@ -4034,8 +3988,7 @@ test_wuffs_json_decode_string() {
wuffs_json__decoder__decode_tokens(&dec, &tok, &src, g_work_slice_u8);
uint64_t total_length = 0;
size_t i;
for (i = tok.meta.ri; i < tok.meta.wi; i++) {
for (size_t i = tok.meta.ri; i < tok.meta.wi; i++) {
wuffs_base__token* t = &tok.data.ptr[i];
total_length =
wuffs_base__u64__sat_add(total_length, wuffs_base__token__length(t));
@@ -4071,9 +4024,8 @@ do_bench_wuffs_strconv_parse_number_f64(const char* str,
wuffs_base__slice_u8 s = wuffs_base__make_slice_u8((void*)str, strlen(str));
bench_start();
uint64_t i;
uint64_t iters = iters_unscaled * g_flags.iterscale;
for (i = 0; i < iters; i++) {
for (uint64_t i = 0; i < iters; i++) {
CHECK_STATUS("", wuffs_base__parse_number_f64(
s, WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS)
.status);
@@ -4114,11 +4066,9 @@ const char* //
do_bench_wuffs_strconv_render_number_f64(wuffs_base__slice_u64 test_cases,
uint64_t iters_unscaled) {
bench_start();
uint64_t i;
uint64_t iters = iters_unscaled * g_flags.iterscale;
for (i = 0; i < iters; i++) {
size_t tc;
for (tc = 0; tc < test_cases.len; tc++) {
for (uint64_t i = 0; i < iters; i++) {
for (size_t tc = 0; tc < test_cases.len; tc++) {
size_t n = wuffs_base__render_number_f64(
g_have_slice_u8,
wuffs_base__ieee_754_bit_representation__from_u64_to_f64(
+3 -6
View File
@@ -225,8 +225,7 @@ test_wuffs_lzw_decode_output_bad() {
// (0x41, 0x42, 0x43) then a bad 8-bit code 0xFF. Decoding should produce 3
// bytes and consume 4 bytes.
src.meta.wi = 20;
int i;
for (i = 0; i < src.meta.wi; i++) {
for (int i = 0; i < src.meta.wi; i++) {
src.data.ptr[i] = 0;
}
src.data.ptr[0] = 0x41;
@@ -271,8 +270,7 @@ test_wuffs_lzw_decode_output_empty() {
// Set up src to be 20 bytes long, starting with the 9-bit end code 0x101.
// Decoding should produce 0 bytes and consume 2 bytes.
src.meta.wi = 20;
int i;
for (i = 0; i < src.meta.wi; i++) {
for (int i = 0; i < src.meta.wi; i++) {
src.data.ptr[i] = 0;
}
src.data.ptr[0] = 0x01;
@@ -405,9 +403,8 @@ do_bench_wuffs_lzw_decode(const char* filename, uint64_t iters_unscaled) {
bench_start();
uint64_t n_bytes = 0;
uint64_t i;
uint64_t iters = iters_unscaled * g_flags.iterscale;
for (i = 0; i < iters; i++) {
for (uint64_t i = 0; i < iters; i++) {
have.meta.wi = 0;
src.meta.ri = 1; // Skip the literal width.
wuffs_lzw__decoder dec;
+491 -24
View File
@@ -118,8 +118,7 @@ do_test_xxxxx_png_decode_bad_crc32_checksum_critical(
#endif
};
int tc;
for (tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
@@ -132,7 +131,7 @@ do_test_xxxxx_png_decode_bad_crc32_checksum_critical(
wuffs_base__make_pixel_format(
WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, &src)) {
RETURN_FAIL("tc=%d (filename=\"%s\"): bad checksum not rejected", tc,
RETURN_FAIL("tc=%zu (filename=\"%s\"): bad checksum not rejected", tc,
test_cases[tc]);
}
}
@@ -149,6 +148,10 @@ do_wuffs_png_swizzle(uint32_t width,
CHECK_STATUS("initialize", wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
dec.private_impl.f_frame_rect_x0 = 0;
dec.private_impl.f_frame_rect_y0 = 0;
dec.private_impl.f_frame_rect_x1 = width;
dec.private_impl.f_frame_rect_y1 = height;
dec.private_impl.f_width = width;
dec.private_impl.f_height = height;
dec.private_impl.f_pass_bytes_per_row = width;
@@ -315,16 +318,14 @@ apply_png_encode_filters(wuffs_base__slice_u8 dst_rows,
(((width + 1) * height) != src_rows.len)) {
return "apply_png_encode_filters: unexpected rows.len";
}
size_t y;
uint8_t* src_prev = NULL;
for (y = 0; y < height; y++) {
for (size_t y = 0; y < height; y++) {
uint8_t filter = src_rows.ptr[(width + 1) * y];
dst_rows.ptr[(width + 1) * y] = filter;
uint8_t* dst_curr = &dst_rows.ptr[((width + 1) * y) + 1];
uint8_t* src_curr = &src_rows.ptr[((width + 1) * y) + 1];
size_t x;
for (x = 0; x < width; x++) {
for (size_t x = 0; x < width; x++) {
int32_t fa = 0;
int32_t fb = 0;
int32_t fc = 0;
@@ -449,26 +450,485 @@ test_wuffs_png_decode_filters_round_trip() {
const char* //
test_wuffs_png_decode_frame_config() {
CHECK_FOCUS(__func__);
static const uint64_t hibiscus_regular_want_areas[] = {
312 * 442,
};
static const uint64_t hibiscus_regular_want_io_ps[] = {
0x0021,
};
static const uint64_t animated_red_blue_want_areas[] = {
64 * 48,
37 * 9,
49 * 40,
37 * 9,
};
static const uint64_t animated_red_blue_want_io_ps[] = {
0x006D,
0x044A,
0x04D1,
0x0720,
};
struct {
const char* filename;
uint64_t want_count;
const uint64_t* want_areas;
const uint64_t* want_io_ps;
} test_cases[] = {
{
.filename = "test/data/hibiscus.regular.png",
.want_count = WUFFS_TESTLIB_ARRAY_SIZE(hibiscus_regular_want_areas),
.want_areas = hibiscus_regular_want_areas,
.want_io_ps = hibiscus_regular_want_io_ps,
},
{
.filename = "test/data/animated-red-blue.apng",
.want_count = WUFFS_TESTLIB_ARRAY_SIZE(animated_red_blue_want_areas),
.want_areas = animated_red_blue_want_areas,
.want_io_ps = animated_red_blue_want_io_ps,
},
};
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
wuffs_png__decoder dec;
CHECK_STATUS("initialize",
wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, test_cases[tc].filename));
uint64_t have_count = 0;
while (true) {
wuffs_base__status status =
wuffs_png__decoder__decode_frame_config(&dec, &fc, &src);
if (status.repr == wuffs_base__note__end_of_data) {
break;
} else if (!wuffs_base__status__is_ok(&status)) {
RETURN_FAIL("decode_frame_config tc=%zu #%" PRIu64 ": %s", tc,
have_count, status.repr);
}
if (have_count < test_cases[tc].want_count) {
uint64_t have_area = ((uint64_t)wuffs_base__frame_config__width(&fc)) *
((uint64_t)wuffs_base__frame_config__height(&fc));
if (have_area != test_cases[tc].want_areas[have_count]) {
RETURN_FAIL(
"area tc=%zu #%" PRIu64 ": have %" PRIu64 ", want %" PRIu64, tc,
have_count, have_area, test_cases[tc].want_areas[have_count]);
}
uint64_t have_io_p = wuffs_base__frame_config__io_position(&fc);
if (have_io_p != test_cases[tc].want_io_ps[have_count]) {
RETURN_FAIL("io_position tc=%zu #%" PRIu64 ": have %" PRIu64
", want %" PRIu64,
tc, have_count, have_io_p,
test_cases[tc].want_io_ps[have_count]);
}
}
have_count++;
}
if (have_count != test_cases[tc].want_count) {
RETURN_FAIL("count tc=%zu: have %" PRIu64 ", want %" PRIu64, tc,
have_count, test_cases[tc].want_count);
}
}
return NULL;
}
const char* //
test_wuffs_png_decode_metadata_chrm_gama_srgb() {
CHECK_FOCUS(__func__);
wuffs_png__decoder dec;
for (int q = 0; q < 4; q++) {
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/bricks-dither.png"));
wuffs_base__image_config ic = ((wuffs_base__image_config){});
CHECK_STATUS("initialize",
wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
uint32_t want_fourcc = 0;
uint32_t want[8] = {0};
uint32_t have[8] = {0};
if (q == 1) {
want_fourcc = WUFFS_BASE__FOURCC__CHRM;
want[0] = 31270;
want[1] = 32900;
want[2] = 64000;
want[3] = 33000;
want[4] = 30000;
want[5] = 60000;
want[6] = 15000;
want[7] = 6000;
} else if (q == 2) {
want_fourcc = WUFFS_BASE__FOURCC__GAMA;
want[0] = 45455;
} else if (q == 3) {
want_fourcc = WUFFS_BASE__FOURCC__SRGB;
want[0] = WUFFS_BASE__SRGB_RENDERING_INTENT__PERCEPTUAL;
have[0] = 123;
}
wuffs_png__decoder__set_report_metadata(&dec, want_fourcc, true);
while (true) {
wuffs_base__status status =
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
if (wuffs_base__status__is_ok(&status)) {
break;
} else if (status.repr != wuffs_base__note__metadata_reported) {
RETURN_FAIL("decode_image_config (q=%d): have \"%s\", want \"%s\"", q,
status.repr, wuffs_base__note__metadata_reported);
}
wuffs_base__io_buffer empty = wuffs_base__empty_io_buffer();
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
status = wuffs_png__decoder__tell_me_more(&dec, &empty, &minfo, &src);
if (wuffs_base__status__is_error(&status)) {
RETURN_FAIL("tell_me_more (q=%d): \"%s\"", q, status.repr);
} else if (minfo.flavor !=
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED) {
RETURN_FAIL("tell_me_more (q=%d): flavor: have %" PRIu32
", want %" PRIu32,
q, minfo.flavor,
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED);
}
uint32_t have_fourcc =
wuffs_base__more_information__metadata__fourcc(&minfo);
if (have_fourcc != want_fourcc) {
RETURN_FAIL("tell_me_more (q=%d): fourcc: have 0x%08" PRIX32
", want 0x%08" PRIX32,
q, have_fourcc, want_fourcc);
} else if (have_fourcc == WUFFS_BASE__FOURCC__CHRM) {
for (int i = 0; i < 8; i++) {
have[i] = ((uint32_t)(
wuffs_base__more_information__metadata_parsed__chrm(&minfo, i)));
}
} else if (have_fourcc == WUFFS_BASE__FOURCC__GAMA) {
have[0] = wuffs_base__more_information__metadata_parsed__gama(&minfo);
} else if (have_fourcc == WUFFS_BASE__FOURCC__SRGB) {
have[0] = wuffs_base__more_information__metadata_parsed__srgb(&minfo);
}
}
for (int i = 0; i < 8; i++) {
if (have[i] != want[i]) {
RETURN_FAIL("(q=%d, i=%d): have %" PRIu32 ", want %" PRIu32, q, i,
have[i], want[i]);
}
}
}
return NULL;
}
const char* //
test_wuffs_png_decode_metadata_exif() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/artificial-png/exif.png"));
wuffs_png__decoder dec;
CHECK_STATUS("initialize",
wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_png__decoder__set_report_metadata(&dec, WUFFS_BASE__FOURCC__EXIF, true);
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__io_buffer empty = wuffs_base__empty_io_buffer();
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
wuffs_base__status status =
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
if (status.repr != wuffs_base__note__metadata_reported) {
RETURN_FAIL("decode_image_config #0: have \"%s\", want \"%s\"", status.repr,
wuffs_base__note__metadata_reported);
}
status = wuffs_png__decoder__tell_me_more(&dec, &empty, &minfo, &src);
if (status.repr != wuffs_base__suspension__even_more_information) {
RETURN_FAIL("tell_me_more #0: have \"%s\", want \"%s\"", status.repr,
wuffs_base__suspension__even_more_information);
}
// "hd test/data/artificial-png/exif.png" says 0x29..0x33 holds "LoremIpsum".
wuffs_base__range_ie_u64 have =
wuffs_base__more_information__metadata_raw_passthrough__range(&minfo);
wuffs_base__range_ie_u64 want = wuffs_base__make_range_ie_u64(0x29, 0x33);
if (!wuffs_base__range_ie_u64__equals(&have, want)) {
RETURN_FAIL("range #0: have 0x%" PRIx64 "..0x%" PRIX64 ", want 0x%" PRIx64
"..0x%" PRIX64,
have.min_incl, have.max_excl, want.min_incl, want.max_excl);
} else if ((src.meta.ri == 0x29) && (src.meta.wi >= 0x33)) {
src.meta.ri = 0x33;
}
status = wuffs_png__decoder__tell_me_more(&dec, &empty, &minfo, &src);
if (status.repr != NULL) {
RETURN_FAIL("tell_me_more #1: have \"%s\", want \"(null)\"", status.repr);
}
have = wuffs_base__more_information__metadata_raw_passthrough__range(&minfo);
if (!wuffs_base__range_ie_u64__is_empty(&have)) {
RETURN_FAIL("tell_me_more #1: non-empty range");
}
status = wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
if (status.repr != NULL) {
RETURN_FAIL("decode_image_config #1: have \"%s\", want \"(null)\"",
status.repr);
} else if (wuffs_base__pixel_config__width(&ic.pixcfg) != 1) {
RETURN_FAIL("decode_image_config #1: have %" PRIu32 ", want 1",
wuffs_base__pixel_config__width(&ic.pixcfg));
}
return NULL;
}
const char* //
test_wuffs_png_decode_metadata_iccp() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
.data = g_have_slice_u8,
});
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
.data = g_want_slice_u8,
});
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&want, "test/data/DCI-P3-D65.icc"));
CHECK_STRING(read_file(
&src, "test/data/red-blue-gradient.dcip3d65-no-chrm-no-gama.png"));
bool seen_iccp = false;
wuffs_png__decoder dec;
CHECK_STATUS("initialize",
wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_png__decoder__set_report_metadata(&dec, WUFFS_BASE__FOURCC__ICCP, true);
wuffs_base__image_config ic = ((wuffs_base__image_config){});
while (true) {
wuffs_base__status status =
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
if (wuffs_base__status__is_ok(&status)) {
break;
} else if (status.repr != wuffs_base__note__metadata_reported) {
RETURN_FAIL("decode_image_config: have \"%s\", want \"%s\"", status.repr,
wuffs_base__note__metadata_reported);
}
{
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
wuffs_base__status status =
wuffs_png__decoder__tell_me_more(&dec, &have, &minfo, &src);
if (!wuffs_base__status__is_ok(&status)) {
RETURN_FAIL("tell_me_more: \"%s\"", status.repr);
} else if (minfo.flavor !=
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM) {
RETURN_FAIL(
"tell_me_more: flavor: have %" PRIu32 ", want %" PRIu32,
minfo.flavor,
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM);
} else if (wuffs_base__more_information__metadata__fourcc(&minfo) !=
WUFFS_BASE__FOURCC__ICCP) {
RETURN_FAIL("tell_me_more: fourcc: have %" PRIX32 ", want %" PRIX32,
wuffs_base__more_information__metadata__fourcc(&minfo),
WUFFS_BASE__FOURCC__ICCP);
}
CHECK_STRING(check_io_buffers_equal("", &have, &want));
seen_iccp = true;
}
}
if (!seen_iccp) {
RETURN_FAIL("seen_iccp: have %d, want %d", seen_iccp, true);
}
{
// 423 = 0x1A7 is just before the "????IDAT" bytes.
uint64_t have = wuffs_base__image_config__first_frame_io_position(&ic);
uint64_t want = 423;
if (have != want) {
RETURN_FAIL("first_frame_io_position: have %" PRIu64 ", want %" PRIu64,
have, want);
}
}
{
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__status status =
wuffs_png__decoder__decode_frame_config(&dec, &fc, &src);
if (!wuffs_base__status__is_ok(&status)) {
RETURN_FAIL("decode_frame_config: %s", status.repr);
}
uint32_t have = wuffs_base__frame_config__width(&fc);
uint32_t want = 256;
if (have != want) {
RETURN_FAIL("decode_frame_config: width: have %" PRIu32 ", want %" PRIu32,
have, want);
}
}
return NULL;
}
const char* //
test_wuffs_png_decode_metadata_kvp() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/artificial-png/key-value-pairs.png"));
const char* wants[] = {
"Key", //
"English", //
"Clé", //
"Français", //
"zlïbK", //
"zlïbV", //
"U-Key", //
"U-значение", //
"Z-Këy", //
"Z-значение", //
};
wuffs_png__decoder dec;
CHECK_STATUS("initialize",
wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_png__decoder__set_report_metadata(&dec, WUFFS_BASE__FOURCC__KVP, true);
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
size_t i = 0;
for (;; i++) {
wuffs_base__status status =
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
if (wuffs_base__status__is_ok(&status)) {
break;
} else if (status.repr != wuffs_base__note__metadata_reported) {
RETURN_FAIL("decode_image_config i=%zu: %s", i, status.repr);
}
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
.data = g_have_slice_u8,
});
status = wuffs_png__decoder__tell_me_more(&dec, &have, &minfo, &src);
if (!wuffs_base__status__is_ok(&status)) {
RETURN_FAIL("tell_me_more i=%zu: \"%s\"", i, status.repr);
} else if (minfo.flavor !=
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM) {
RETURN_FAIL("tell_me_more i=%zu: flavor: have %" PRIu32 ", want %" PRIu32,
i, minfo.flavor,
WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_TRANSFORM);
}
uint32_t have_fourcc =
wuffs_base__more_information__metadata__fourcc(&minfo);
uint32_t want_fourcc =
(i & 1) ? WUFFS_BASE__FOURCC__KVPV : WUFFS_BASE__FOURCC__KVPK;
if (have_fourcc != want_fourcc) {
RETURN_FAIL("tell_me_more i=%zu: fourcc: have %" PRIX32 ", want %" PRIX32,
i, have_fourcc, want_fourcc);
}
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
.data = g_want_slice_u8,
});
if (i < WUFFS_TESTLIB_ARRAY_SIZE(wants)) {
size_t n = strlen(wants[i]);
if (n <= want.data.len) {
memcpy(want.data.ptr, wants[i], n);
want.meta.wi = n;
}
}
CHECK_STRING(check_io_buffers_equal("", &have, &want));
}
if (i != WUFFS_TESTLIB_ARRAY_SIZE(wants)) {
RETURN_FAIL("i: have %zu, want %zu", i, WUFFS_TESTLIB_ARRAY_SIZE(wants));
}
return NULL;
}
const char* //
test_wuffs_png_decode_restart_frame() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/pjw-thumbnail.png"));
wuffs_png__decoder dec;
CHECK_STATUS("initialize",
wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/hibiscus.regular.png"));
CHECK_STATUS("decode_frame_config #0",
wuffs_png__decoder__decode_frame_config(&dec, &fc, &src));
wuffs_base__status status =
wuffs_png__decoder__decode_frame_config(&dec, &fc, &src);
if (status.repr != wuffs_base__note__end_of_data) {
RETURN_FAIL("decode_frame_config #1: have \"%s\", want \"%s\"", status.repr,
wuffs_base__note__end_of_data);
wuffs_base__image_config ic = ((wuffs_base__image_config){});
CHECK_STATUS("decode_image_config",
wuffs_png__decoder__decode_image_config(&dec, &ic, &src));
// 51 = 0x33 is just before the "????IDAT" bytes.
uint64_t ffio = wuffs_base__image_config__first_frame_io_position(&ic);
if (ffio != 51) {
RETURN_FAIL("first_frame_io_position: have %" PRIu64 ", want 51", ffio);
}
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
&pb, &ic.pixcfg, g_pixel_slice_u8));
for (int i = 0; i < 2; i++) {
if (i > 0) {
CHECK_STATUS("restart_frame",
wuffs_png__decoder__restart_frame(&dec, 0, 51));
if (51 <= src.meta.wi) {
src.meta.ri = 51;
}
}
uint64_t rpos = wuffs_base__io_buffer__reader_position(&src);
if (rpos != 51) {
RETURN_FAIL("reader_position (before) #%d: have %" PRIu64 ", want 51", i,
rpos);
}
wuffs_base__status status = wuffs_png__decoder__decode_frame(
&dec, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, g_work_slice_u8, NULL);
if (!wuffs_base__status__is_ok(&status)) {
RETURN_FAIL("decode_frame #%d: %s", i, status.repr);
}
// 196 = 0xC4 is just before the "????IEND" bytes.
rpos = wuffs_base__io_buffer__reader_position(&src);
if (rpos != 196) {
RETURN_FAIL("reader_position (after) #%d: have %" PRIu64 ", want 196", i,
rpos);
}
}
return NULL;
}
@@ -631,8 +1091,7 @@ do_bench_wuffs_png_decode_filter(uint8_t filter,
return "source data is too short";
}
uint32_t y;
for (y = 0; y < height; y++) {
for (uint32_t y = 0; y < height; y++) {
workbuf.data.ptr[(1 + bytes_per_row) * y] = filter;
}
@@ -647,6 +1106,10 @@ do_bench_wuffs_png_decode_filter(uint8_t filter,
CHECK_STATUS("initialize", wuffs_png__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
dec.private_impl.f_frame_rect_x0 = 0;
dec.private_impl.f_frame_rect_y0 = 0;
dec.private_impl.f_frame_rect_x1 = width;
dec.private_impl.f_frame_rect_y1 = height;
dec.private_impl.f_width = width;
dec.private_impl.f_height = height;
dec.private_impl.f_pass_bytes_per_row = bytes_per_row;
@@ -672,9 +1135,8 @@ do_bench_wuffs_png_decode_filter(uint8_t filter,
bench_start();
uint64_t n_bytes = 0;
uint64_t i;
uint64_t iters = iters_unscaled * g_flags.iterscale;
for (i = 0; i < iters; i++) {
for (uint64_t i = 0; i < iters; i++) {
CHECK_STATUS(
"filter_and_swizzle",
wuffs_png__decoder__filter_and_swizzle(
@@ -803,6 +1265,11 @@ proc g_tests[] = {
test_wuffs_png_decode_filters_round_trip,
test_wuffs_png_decode_frame_config,
test_wuffs_png_decode_interface,
test_wuffs_png_decode_metadata_chrm_gama_srgb,
test_wuffs_png_decode_metadata_exif,
test_wuffs_png_decode_metadata_iccp,
test_wuffs_png_decode_metadata_kvp,
test_wuffs_png_decode_restart_frame,
#ifdef WUFFS_MIMIC
+17 -28
View File
@@ -75,8 +75,7 @@ fill_palette_with_grays(wuffs_base__pixel_buffer* pb) {
if (palette.len != 1024) {
return;
}
int i;
for (i = 0; i < 256; i++) {
for (int i = 0; i < 256; i++) {
palette.ptr[(4 * i) + 0] = i;
palette.ptr[(4 * i) + 1] = i;
palette.ptr[(4 * i) + 2] = i;
@@ -90,8 +89,7 @@ fill_palette_with_nrgba_transparent_yellows(wuffs_base__pixel_buffer* pb) {
if (palette.len != 1024) {
return;
}
int i;
for (i = 0; i < 256; i++) {
for (int i = 0; i < 256; i++) {
palette.ptr[(4 * i) + 0] = 0x00;
palette.ptr[(4 * i) + 1] = 0x99;
palette.ptr[(4 * i) + 2] = 0xCC;
@@ -161,8 +159,7 @@ test_wuffs_pixel_buffer_fill_rect() {
},
};
int d;
for (d = 0; d < WUFFS_TESTLIB_ARRAY_SIZE(dsts); d++) {
for (size_t d = 0; d < WUFFS_TESTLIB_ARRAY_SIZE(dsts); d++) {
// Allocate the dst_pixbuf.
wuffs_base__pixel_config dst_pixcfg = ((wuffs_base__pixel_config){});
wuffs_base__pixel_config__set(&dst_pixcfg, dsts[d].pixfmt_repr,
@@ -173,13 +170,10 @@ test_wuffs_pixel_buffer_fill_rect() {
wuffs_base__pixel_buffer__set_from_slice(
&dst_pixbuf, &dst_pixcfg, g_have_slice_u8));
int orientation;
for (orientation = 0; orientation < 2; orientation++) {
for (int orientation = 0; orientation < 2; orientation++) {
// Reset to transparent black (or its closest approximation).
uint32_t y;
for (y = 0; y < height; y++) {
uint32_t x;
for (x = 0; x < width; x++) {
for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) {
CHECK_STATUS(
"set_color_u32_at",
wuffs_base__pixel_buffer__set_color_u32_at(&dst_pixbuf, x, y, 0));
@@ -204,7 +198,7 @@ test_wuffs_pixel_buffer_fill_rect() {
wuffs_base__pixel_buffer__color_u32_at(&dst_pixbuf, width / 2,
height / 2);
if (colors_differ(have_dst_pixel, want_dst_pixel, 0)) {
RETURN_FAIL("d=%d, orientation=%d: dst_pixel: have 0x%08" PRIX32
RETURN_FAIL("d=%zu, orientation=%d: dst_pixel: have 0x%08" PRIX32
", want 0x%08" PRIX32,
d, orientation, have_dst_pixel, want_dst_pixel);
}
@@ -324,8 +318,7 @@ test_wuffs_pixel_swizzler_swizzle() {
WUFFS_BASE__PIXEL_BLEND__SRC_OVER,
};
int s;
for (s = 0; s < WUFFS_TESTLIB_ARRAY_SIZE(srcs); s++) {
for (size_t s = 0; s < WUFFS_TESTLIB_ARRAY_SIZE(srcs); s++) {
// Allocate the src_pixbuf.
wuffs_base__pixel_config src_pixcfg = ((wuffs_base__pixel_config){});
wuffs_base__pixel_config__set(&src_pixcfg, srcs[s].pixfmt_repr,
@@ -350,12 +343,11 @@ test_wuffs_pixel_swizzler_swizzle() {
wuffs_base__pixel_buffer__color_u32_at(&src_pixbuf, width / 2,
height / 2);
if (have_src_pixel != srcs[s].color) {
RETURN_FAIL("s=%d: src_pixel: have 0x%08" PRIX32 ", want 0x%08" PRIX32, s,
have_src_pixel, srcs[s].color);
RETURN_FAIL("s=%zu: src_pixel: have 0x%08" PRIX32 ", want 0x%08" PRIX32,
s, have_src_pixel, srcs[s].color);
}
int d;
for (d = 0; d < WUFFS_TESTLIB_ARRAY_SIZE(dsts); d++) {
for (size_t d = 0; d < WUFFS_TESTLIB_ARRAY_SIZE(dsts); d++) {
// Allocate the dst_pixbuf.
wuffs_base__pixel_config dst_pixcfg = ((wuffs_base__pixel_config){});
wuffs_base__pixel_config__set(&dst_pixcfg, dsts[d].pixfmt_repr,
@@ -378,8 +370,7 @@ test_wuffs_pixel_swizzler_swizzle() {
WUFFS_TESTLIB_ARRAY_SIZE(fallback_palette_array));
}
int b;
for (b = 0; b < WUFFS_TESTLIB_ARRAY_SIZE(blends); b++) {
for (size_t b = 0; b < WUFFS_TESTLIB_ARRAY_SIZE(blends); b++) {
// Set the middle dst pixel.
CHECK_STATUS("set_color_u32_at",
wuffs_base__pixel_buffer__set_color_u32_at(
@@ -394,10 +385,10 @@ test_wuffs_pixel_swizzler_swizzle() {
wuffs_base__pixel_buffer__palette(&src_pixbuf), blends[b]));
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(
&swizzler,
wuffs_base__table_u8__row(
wuffs_base__table_u8__row_u32(
wuffs_base__pixel_buffer__plane(&dst_pixbuf, 0), height / 2),
dst_palette,
wuffs_base__table_u8__row(
wuffs_base__table_u8__row_u32(
wuffs_base__pixel_buffer__plane(&src_pixbuf, 0), height / 2));
// Check the middle dst pixel.
@@ -420,7 +411,7 @@ test_wuffs_pixel_swizzler_swizzle() {
wuffs_base__pixel_buffer__color_u32_at(&dst_pixbuf, width / 2,
height / 2);
if (colors_differ(have_dst_pixel, want_dst_pixel, tolerance)) {
RETURN_FAIL("s=%d, d=%d, b=%d: dst_pixel: have 0x%08" PRIX32
RETURN_FAIL("s=%zu, d=%zu, b=%zu: dst_pixel: have 0x%08" PRIX32
", want 0x%08" PRIX32 ", per-channel tolerance=%" PRId32,
s, d, b, have_dst_pixel, want_dst_pixel, tolerance);
}
@@ -559,11 +550,9 @@ do_bench_wuffs_pixel_swizzler(uint32_t dst_pixfmt_repr,
bench_start();
uint64_t n_bytes = 0;
uint64_t i;
uint64_t iters = iters_unscaled * g_flags.iterscale;
for (i = 0; i < iters; i++) {
uint32_t y;
for (y = 0; y < height; y++) {
for (uint64_t i = 0; i < iters; i++) {
for (uint32_t y = 0; y < height; y++) {
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(
&swizzler,
wuffs_base__make_slice_u8(
+51 -4
View File
@@ -71,6 +71,11 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// ---------------- Golden Tests
golden_test g_deflate_romeo_gt = {
.want_filename = "test/data/romeo.txt",
.src_filename = "test/data/romeo.txt.deflate",
};
golden_test g_zlib_midsummer_gt = {
.want_filename = "test/data/midsummer.txt",
.src_filename = "test/data/midsummer.txt.zlib",
@@ -107,6 +112,42 @@ test_wuffs_zlib_decode_interface() {
"test/data/romeo.txt.zlib", 0, SIZE_MAX, 942, 0x0A);
}
const char* //
wuffs_raw_deflate_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
wuffs_zlib__decoder dec;
CHECK_STATUS("initialize",
wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
wuffs_initialize_flags));
// This wuffs_zlib__decoder__set_quirk_enabled call is the only difference
// between wuffs_raw_deflate_decode and wuffs_zlib_decode immediately below.
wuffs_zlib__decoder__set_quirk_enabled(
&dec, WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE, true);
while (true) {
wuffs_base__io_buffer limited_dst = make_limited_writer(*dst, wlimit);
wuffs_base__io_buffer limited_src = make_limited_reader(*src, rlimit);
wuffs_base__status status = wuffs_zlib__decoder__transform_io(
&dec, &limited_dst, &limited_src, g_work_slice_u8);
dst->meta.wi += limited_dst.meta.wi;
src->meta.ri += limited_src.meta.ri;
if (((wlimit < UINT64_MAX) &&
(status.repr == wuffs_base__suspension__short_write)) ||
((rlimit < UINT64_MAX) &&
(status.repr == wuffs_base__suspension__short_read))) {
continue;
}
return status.repr;
}
}
const char* //
wuffs_zlib_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
@@ -170,8 +211,7 @@ do_test_wuffs_zlib_checksum(bool ignore_checksum, uint32_t bad_checksum) {
// Decode the src data in 1 or 2 chunks, depending on whether end_limit is
// or isn't zero.
int i;
for (i = 0; i < 2; i++) {
for (int i = 0; i < 2; i++) {
uint64_t rlimit = UINT64_MAX;
const char* want_z = NULL;
if (i == 0) {
@@ -241,6 +281,13 @@ test_wuffs_zlib_decode_pi() {
UINT64_MAX);
}
const char* //
test_wuffs_zlib_decode_raw_deflate_romeo() {
CHECK_FOCUS(__func__);
return do_test_io_buffers(wuffs_raw_deflate_decode, &g_deflate_romeo_gt,
UINT64_MAX, UINT64_MAX);
}
const char* //
test_wuffs_zlib_decode_sheep() {
CHECK_FOCUS(__func__);
@@ -255,8 +302,7 @@ test_wuffs_zlib_decode_sheep() {
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
int i;
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
wuffs_base__status status =
wuffs_zlib__decoder__transform_io(&dec, &have, &src, g_work_slice_u8);
@@ -378,6 +424,7 @@ proc g_tests[] = {
test_wuffs_zlib_decode_interface,
test_wuffs_zlib_decode_midsummer,
test_wuffs_zlib_decode_pi,
test_wuffs_zlib_decode_raw_deflate_romeo,
test_wuffs_zlib_decode_sheep,
#ifdef WUFFS_MIMIC
+17 -30
View File
@@ -369,8 +369,7 @@ chdir_to_the_wuffs_root_directory() {
// Chdir to the Wuffs root directory, assuming that we're starting from
// somewhere in the Wuffs repository, so we can find the root directory by
// running chdir("..") a number of times.
int n;
for (n = 0; n < 64; n++) {
for (int n = 0; n < 64; n++) {
if (access("wuffs-root-directory.txt", F_OK) == 0) {
return NULL;
}
@@ -423,14 +422,12 @@ test_main(int argc, char** argv, proc* tests, proc* benches) {
"compatible with the\n"
"# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install "
"it, first\n"
"# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
"# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
}
int i;
for (i = 0; i < reps; i++) {
for (int i = 0; i < reps; i++) {
g_bench_warm_up = i == 0;
proc* p;
for (p = procs; *p; p++) {
for (proc* p = procs; *p; p++) {
g_proc_func_name = "unknown_func_name";
g_fail_msg[0] = 0;
g_in_focus = false;
@@ -562,12 +559,10 @@ copy_to_io_buffer_from_pixel_buffer(wuffs_base__io_buffer* dst,
}
size_t bytes_per_pixel = bits_per_pixel / 8;
uint32_t p;
for (p = 0; p < 1; p++) {
for (uint32_t p = 0; p < 1; p++) {
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(src, p);
uint32_t y;
for (y = r.min_incl_y; y < r.max_excl_y; y++) {
wuffs_base__slice_u8 row = wuffs_base__table_u8__row(tab, y);
for (uint32_t y = r.min_incl_y; y < r.max_excl_y; y++) {
wuffs_base__slice_u8 row = wuffs_base__table_u8__row_u32(tab, y);
if ((r.min_incl_x >= r.max_excl_x) ||
(r.max_excl_x > (row.len / bytes_per_pixel))) {
break;
@@ -748,8 +743,7 @@ hex_dump(char* msg, wuffs_base__io_buffer* buf, size_t i) {
return msg;
}
size_t base = i - (i & 15);
int j;
for (j = -3 * 16; j <= +3 * 16; j += 16) {
for (int j = -3 * 16; j <= +3 * 16; j += 16) {
if ((j < 0) && (base < (size_t)(-j))) {
continue;
}
@@ -759,8 +753,7 @@ hex_dump(char* msg, wuffs_base__io_buffer* buf, size_t i) {
}
size_t n = buf->meta.wi - b;
INCR_FAIL(msg, " %06zx:", b);
size_t k;
for (k = 0; k < 16; k++) {
for (size_t k = 0; k < 16; k++) {
if (k % 2 == 0) {
INCR_FAIL(msg, " ");
}
@@ -771,7 +764,7 @@ hex_dump(char* msg, wuffs_base__io_buffer* buf, size_t i) {
}
}
INCR_FAIL(msg, " ");
for (k = 0; k < 16; k++) {
for (size_t k = 0; k < 16; k++) {
char c = ' ';
if (k < n) {
c = buf->data.ptr[b + k];
@@ -797,12 +790,10 @@ check_io_buffers_equal(const char* prefix,
RETURN_FAIL("%sio_buffers_equal: NULL argument", prefix);
}
char* msg = g_fail_msg;
size_t i;
size_t i = 0;
size_t n = have->meta.wi < want->meta.wi ? have->meta.wi : want->meta.wi;
for (i = 0; i < n; i++) {
if (have->data.ptr[i] != want->data.ptr[i]) {
break;
}
while ((i < n) && (have->data.ptr[i] == want->data.ptr[i])) {
i++;
}
if (have->meta.wi != want->meta.wi) {
INCR_FAIL(msg, "%sio_buffers_equal: wi: have %zu, want %zu.\n", prefix,
@@ -893,8 +884,7 @@ proc_io_buffers(const char* (*codec_func)(wuffs_base__io_buffer*,
bench_start();
}
uint64_t n_bytes = 0;
uint64_t i;
for (i = 0; i < iters; i++) {
for (uint64_t i = 0; i < iters; i++) {
have.meta.wi = 0;
src.meta.ri = gt->src_offset0;
const char* status =
@@ -979,8 +969,7 @@ proc_token_decoder(const char* (*codec_func)(wuffs_base__token_buffer*,
bench_start();
}
uint64_t n_bytes = 0;
uint64_t i;
for (i = 0; i < iters; i++) {
for (uint64_t i = 0; i < iters; i++) {
have.meta.wi = 0;
src.meta.ri = gt->src_offset0;
const char* status =
@@ -1067,8 +1056,7 @@ do_run__wuffs_base__image_decoder(wuffs_base__image_decoder* b,
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
size_t i;
for (i = 0; i < quirks_len; i++) {
for (size_t i = 0; i < quirks_len; i++) {
wuffs_base__image_decoder__set_quirk_enabled(b, quirks_ptr[i], true);
}
@@ -1145,9 +1133,8 @@ do_bench_image_decode(
bench_start();
uint64_t n_bytes = 0;
uint64_t i;
uint64_t iters = iters_unscaled * g_flags.iterscale;
for (i = 0; i < iters; i++) {
for (uint64_t i = 0; i < iters; i++) {
src.meta.ri = src_ri;
CHECK_STRING((*decode_func)(&n_bytes, NULL, wuffs_initialize_flags, pixfmt,
quirks_ptr, quirks_len, &src));
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
+22 -5
View File
@@ -6,22 +6,28 @@ files were generated by `script/extract-palette-indexes.go`. The `*.tokens`
files were generated by `script/print-json-token-debug-format.c`.
The `*.jpeg` files are usually the canonical versions of the test/data images,
and other versions (`*.bmp`, `*.gif`, `*.png`, `*.tiff`) were generated by
and other versions (`*.bmp`, `*.gif`, `*.png` etc) were usually generated by
ImageMagick's `convert` command line tool. The `*.wbmp` versions were generated
by the `script/convert-png-to-wbmp.go` command line tool. The `*.webp` versions
were generated by the cwebp command line tool. The `*.no-ancillary.png` files
were generated by the `script/strip-png-ancillary-chunks.go` command line tool.
The `*.qoi` files were generated by the qoiconv command line tool.
The `*.apng` files were generated by `gif2apng`. Those with finite animation
loop counts were manually patched to correct for a `gif2apng` bug.
https://bugs.chromium.org/p/chromium/issues/detail?id=592735 argues that GIF
and APNG/WEBP have different semantics but `gif2apng` does not cater for that.
---
The artificial directory holds artificially generated test data, often to
The `artificial-*` directories hold artificially generated test data, often to
explicitly test corner cases of various file formats. The files there usually
come in families whose names have a common prefix, such as three files
`foo.bar`, `foo.bar.qux`, `foo.bar.commentary.txt` all prefixed by `foo.bar`.
The file whose name is that prefix is usually the canonical (typically
hand-crafted) file, and the other files are then derived from that. Outside of
the artificial directory, the other files in this directory are typically real
world examples of various file formats, or deriviations of them.
the `artificial-*` directories, the other files in this directory are typically
real world examples of various file formats, or deriviations of them.
---
@@ -29,10 +35,17 @@ The non-ascii directory holds trivial UTF-8 (but not ASCII) text files.
---
`DCI-P3-D65.icc` comes from
[color.org](https://www.color.org/chardata/rgb/DCIP3.xalter).
`DCI-P3-D65.icc.zlib` is a zlib-compresion of that, created by Go's standard
library.
`archive.*` archives a subset of other files in this directory.
`animated-red-blue.gif` is an original animation by Nigel Tao
<nigeltao@golang.org>.
<nigeltao@golang.org>. `animated-red-blue.nia` and `animated-red-blue.*.nie`
were then generated by `example/convert-to-nia` and
`script/extract-nia-frames.go`.
`australian-abc-local-stations.json` was crawled from
[data.gov.au](http://data.gov.au/geoserver/abc-local-stations/wfs?request=GetFeature&typeName=ckan_d534c0e9_a9bf_487b_ac8f_b7877a09d162&outputFormat=json).
@@ -44,6 +57,8 @@ The non-ascii directory holds trivial UTF-8 (but not ASCII) text files.
`cbor-rfc-7049-examples.*.json` files were then generated by
`example/cbor-to-json`.
`checkerboard.*.png` was generated by `script/make-red-blue-gradient.go`.
`crude-flag.*` is an original animation by Nigel Tao
<nigeltao@golang.org>. See the `lib/nie` documentation.
@@ -110,6 +125,8 @@ which is in the public domain.
`pjw-thumbnail.*` are various encodings of an image derived from an iconic,
original photo of Peter J. Weinberger by Rob Pike <r@golang.org>.
`red-blue-gradient.*.png` was generated by `script/make-red-blue-gradient.go`.
`rfc-6901-json-pointer.json` is the example JSON document given in the [RFC
6901 "JavaScript Object Notation (JSON)
Pointer"](https://tools.ietf.org/rfc/rfc6901.txt) specification.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

@@ -1,5 +1,5 @@
Running deflate-backref-crosses-blocks.deflate through script/print-bits.go and
adding commentary:
Running backref-crosses-blocks.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0x00 0b_...._.000 Uncompressed block, non-final
@@ -1,9 +1,9 @@
Running deflate-degenerate-huffman-unused.deflate through script/print-bits.go
and adding commentary:
Running degenerate-huffman.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0x05 0b_...._.101 Dynamic Huffman block, final
000000 0x0000 . 0x05 0b_0000_0... NumLCodes: 257
000000 0x0000 . 0x04 0b_...._.100 Dynamic Huffman block, non-final
000000 0x0000 . 0x04 0b_0000_0... NumLCodes: 257
000001 0x0001 . 0xC0 0b_...0_0000 NumDCodes: 1
000001 0x0001 . 0xC0 0b_110._.... NumCLCodeLengths: 18
000002 0x0002 ! 0x21 0b_...._...1
@@ -63,4 +63,7 @@ Apply H-L and H-D.
000013 0x000D . 0x89 0b_..0._.... lcode: 111 literal 'o'
000013 0x000D . 0x89 0b_.0.._.... lcode: 111 literal 'o'
000013 0x000D . 0x89 0b_1..._.... lcode: 256 end of block
000014 0x000E . 0x01 0b_...._...1
000014 0x000E . 0x1B 0b_...._...1
The second Dynamic Huffman block (the final one) continues after that, but this
commentary stops here.
@@ -0,0 +1 @@
fooABCDABC
@@ -0,0 +1,64 @@
# Feed this file to script/make-artificial.go
make deflate
blockDynamicHuffman (nonFinal) {
huffman CodeLength {
1 00
2 01
17 10
18 11
}
huffman Literal/Length {
# 102='f', 111='o', 256=EOB
111 0
102 10
256 11
}
huffman Distance {
# Incomplete. There is no key/value pair whose value starts with "1".
#
# The sole key/value pair is also unused. (The one below is used.)
0 0
}
literal "foo"
endOfBlock
}
blockDynamicHuffman (final) {
huffman CodeLength {
0 00
1 01
2 100
3 101
17 110
18 111
}
huffman Literal/Length {
# 65='A', 66='B', 67='C', 68='D', 256=EOB, 257=Length3
65 100
66 101
67 110
68 111
256 00
257 01
}
huffman Distance {
# Incomplete. There is no key/value pair whose value starts with "1".
#
# The sole key/value pair is also used. (The one above is unused.)
#
# Per the second table in RFC 1951 section 3.2.5. "Compressed blocks
# (length and distance codes)", code 3 means a distance of 4.
3 0
}
literal "ABCD"
len 3 dist 4
endOfBlock
}
@@ -1,4 +1,4 @@
Running deflate-distance-32768.deflate through script/print-bits.go and adding
Running distance-32768.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
@@ -1,5 +1,5 @@
Running deflate-distance-code-31.deflate through script/print-bits.go and
adding commentary:
Running distance-code-31.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0x03 0b_...._.011 Fixed Huffman block, final
@@ -1,5 +1,5 @@
Running deflate-huffman-primlen-9.deflate through script/print-bits.go and
adding commentary:
Running huffman-primlen-9.deflate through script/print-bits.go and adding
commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0xED 0b_...._.101 Dynamic Huffman block, final
File renamed without changes.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 90 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 54 B

After

Width:  |  Height:  |  Size: 54 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 132 B

After

Width:  |  Height:  |  Size: 132 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 90 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 110 B

After

Width:  |  Height:  |  Size: 110 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 56 B

After

Width:  |  Height:  |  Size: 56 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 139 B

After

Width:  |  Height:  |  Size: 139 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 26 B

After

Width:  |  Height:  |  Size: 26 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 40 B

After

Width:  |  Height:  |  Size: 40 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 40 B

After

Width:  |  Height:  |  Size: 40 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 B

@@ -0,0 +1,37 @@
# Feed this file to script/make-artificial.go
make gif
header
image {
imageWidthHeight 2 2
palette {
0x00 0x00 0xFF
0x11 0x00 0xFF
0x22 0x00 0xFF
0x33 0x00 0xFF
}
}
frame {
frameLeftTopWidthHeight 0 0 2 2
}
# The frame area is 4 pixels and we supply 4 but then an invalid LZW code.
# Compare with pixel-data-too-much-good-lzw.gif.make-artificial.txt
#
# The disassembly (see also std/lzw/README.md) is:
#
# 0x02 LZW literal width.
# 0x02 GIF block length.
# 0x84 0xF1 = 0b1111_0001_1000_0100 (little endian).
# 0b...._...._...._.100 3-bit Clear code.
# 0b...._...._..00_0... 3-bit Literal 0x00.
# 0b...._...1_10.._.... 3-bit Copy code (2 bytes).
# 0b...._000._...._.... 3-bit Literal 0x00.
# 0b1111_...._...._.... 4-bit Invalid code.
# 0x00 GIF block terminator.
bytes 0x02 0x02 0x84 0xF1 0x00
trailer
Binary file not shown.

After

Width:  |  Height:  |  Size: 41 B

@@ -0,0 +1,37 @@
# Feed this file to script/make-artificial.go
make gif
header
image {
imageWidthHeight 2 2
palette {
0x00 0x00 0xFF
0x11 0x00 0xFF
0x22 0x00 0xFF
0x33 0x00 0xFF
}
}
frame {
frameLeftTopWidthHeight 0 0 2 2
}
# The frame area is 4 pixels but we supply 5 (that's still valid LZW data).
# Compare with pixel-data-too-much-bad-lzw.gif.make-artificial.txt
#
# The equivalent bytes' disassembly (see also std/lzw/README.md) is:
#
# 0x02 LZW literal width.
# 0x02 GIF block length.
# 0x84 0x5D = 0b0101_1101_1000_0100 (little endian).
# 0b...._...._...._.100 3-bit Clear code.
# 0b...._...._..00_0... 3-bit Literal 0x00.
# 0b...._...1_10.._.... 3-bit Copy code (2 bytes).
# 0b...._110._...._.... 3-bit Copy code (2 bytes).
# 0b0101_...._...._.... 4-bit End code.
# 0x00 GIF block terminator.
lzw 2 0x00 0x00 0x00 0x00 0x00
trailer
File renamed without changes.

Before

Width:  |  Height:  |  Size: 40 B

After

Width:  |  Height:  |  Size: 40 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 165 B

After

Width:  |  Height:  |  Size: 165 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 40 B

After

Width:  |  Height:  |  Size: 40 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

@@ -0,0 +1,87 @@
# Feed this file to script/make-artificial.go
# This APNG image has its first fcTL chunk after the IDAT chunks, so that the
# IDAT data (the "default image") is not displayed. See
# https://wiki.mozilla.org/APNG_Specification
make png
magic
IHDR {
raw {
# Width, height.
0x00 0x00 0x00 0x03
0x00 0x00 0x00 0x02
# Depth, color, compression, filter, interlace.
0x08 0x02 0x00 0x00 0x00
}
}
acTL {
raw {
# Frame count.
0x00 0x00 0x00 0x02
# Loop count.
0x00 0x00 0x00 0x00
}
}
IDAT {
zlib {
# 3x2 RGB pixels (with filter bytes), shades of red.
0x00 0x20 0x00 0x00 0x50 0x00 0x00 0x80 0x00 0x00
0x00 0x40 0x00 0x00 0xA0 0x00 0x00 0xFF 0x00 0x00
}
}
fcTL {
animSeqNum++
raw {
# Width, height, left, top.
0x00 0x00 0x00 0x03
0x00 0x00 0x00 0x02
0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00
# Duration (1/1 second).
0x00 0x01 0x00 0x01
# Disposal, blend.
0x00 0x00
}
}
fdAT {
animSeqNum++
zlib {
# 3x2 RGB pixels (with filter bytes), shades of cyan.
0x00 0x00 0x20 0x20 0x00 0x50 0x50 0x00 0x80 0x80
0x00 0x00 0x40 0x40 0x00 0xA0 0xA0 0x00 0xFF 0xFF
}
}
fcTL {
animSeqNum++
raw {
# Width, height, left, top.
0x00 0x00 0x00 0x01
0x00 0x00 0x00 0x02
0x00 0x00 0x00 0x02
0x00 0x00 0x00 0x00
# Duration (1/1 second).
0x00 0x01 0x00 0x01
# Disposal, blend.
0x00 0x00
}
}
fdAT {
animSeqNum++
zlib {
# 1x2 RGB pixels (with filter bytes), shades of gray.
0x00 0x80 0x80 0x80
0x00 0xFF 0xFF 0xFF
}
}
IEND {
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

@@ -0,0 +1,32 @@
# Feed this file to script/make-artificial.go
make png
magic
IHDR {
raw {
# Width, height.
0x00 0x00 0x00 0x01
0x00 0x00 0x00 0x01
# Depth, color, compression, filter, interlace.
0x08 0x00 0x00 0x00 0x00
}
}
eXIf {
raw {
# "LoremIpsum" isn't valid EXIF data. It's just a placeholder.
0x4C 0x6F 0x72 0x65 0x6D 0x49 0x70 0x73 0x75 0x6D
}
}
IDAT {
zlib {
# 1x1 gray pixels (with filter bytes).
0x00 0x80
}
}
IEND {
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

@@ -0,0 +1,99 @@
# Feed this file to script/make-artificial.go
make png
magic
IHDR {
raw {
# Width, height.
0x00 0x00 0x00 0x01
0x00 0x00 0x00 0x01
# Depth, color, compression, filter, interlace.
0x08 0x00 0x00 0x00 0x00
}
}
# Basic key-value pair.
tEXt {
raw {
# "Key\x00".
0x4B 0x65 0x79 0x00
# "English".
0x45 0x6E 0x67 0x6C 0x69 0x73 0x68
}
}
# Latin-1 (not UTF-8) uncompressed key-value pair.
tEXt {
raw {
# asLatin1("Clé\x00").
0x43 0x6C 0xE9 0x00
# asLatin1("Français").
0x46 0x72 0x61 0x6E 0xE7 0x61 0x69 0x73
}
}
# Latin-1 (not UTF-8) zlib-compressed key-value pair.
zTXt {
raw {
# asLatin1("zlïbK\x00").
0x7A 0x6C 0xEF 0x62 0x4B 0x00
# Compression method.
0x00
}
zlib {
# asLatin1("zlïbV").
0x7A 0x6C 0xEF 0x62 0x56
}
}
# UTF-8 uncompressed key-value pair.
iTXt {
raw {
# "U-Key\x00".
0x55 0x2D 0x4B 0x65 0x79 0x00
# Compression flag, compression method.
0x00 0x00
# Language tag: "ru\x00".
0x72 0x75 0x00
# Translated key: "U-ключ\x00".
0x55 0x2D 0xD0 0xBA 0xD0 0xBB 0xD1 0x8E
0xD1 0x87 0x00
# "U-значение".
0x55 0x2D 0xD0 0xB7 0xD0 0xBD 0xD0 0xB0
0xD1 0x87 0xD0 0xB5 0xD0 0xBD 0xD0 0xB8
0xD0 0xB5
}
}
# Latin-1 / UTF-8 zlib-compressed key-value pair.
iTXt {
raw {
# asLatin1("Z-Këy\x00").
0x5A 0x2D 0x4B 0xEB 0x79 0x00
# Compression flag, compression method.
0x01 0x00
# Language tag: "ru\x00".
0x72 0x75 0x00
# Translated key: "Z-ключ\x00".
0x5A 0x2D 0xD0 0xBA 0xD0 0xBB 0xD1 0x8E
0xD1 0x87 0x00
}
zlib {
# "Z-значение".
0x5A 0x2D 0xD0 0xB7 0xD0 0xBD 0xD0 0xB0
0xD1 0x87 0xD0 0xB5 0xD0 0xBD 0xD0 0xB8
0xD0 0xB5
}
}
IDAT {
zlib {
# 1x1 gray pixels (with filter bytes).
0x00 0x80
}
}
IEND {
}
@@ -1,27 +0,0 @@
# Feed this file to script/make-artificial.go
make deflate
blockDynamicHuffman (final) {
huffman CodeLength {
1 00
2 01
17 10
18 11
}
huffman Literal/Length {
# 102='f', 111='o', 256=EOB
111 0
102 10
256 11
}
huffman Distance {
# Incomplete. There is no key/value pair whose value starts with "1".
0 0
}
literal "foo"
endOfBlock
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 B

@@ -1,23 +0,0 @@
# Feed this file to script/make-artificial.go
make gif
header
image {
imageWidthHeight 2 2
palette {
0x00 0x00 0xFF
0x11 0x00 0xFF
0x22 0x00 0xFF
0x33 0x00 0xFF
}
}
frame {
frameLeftTopWidthHeight 0 0 2 2
}
# The frame is 4 pixels, but we supply 5.
lzw 2 0x00 0x00 0x00 0x00 0x00
trailer
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 B

+47 -31
View File
@@ -1,62 +1,78 @@
# Generated by script/print-nia-checksums.sh
d3bb0beb test/data/DCI-P3-D65.icc
646e081a test/data/animated-red-blue.000000.nie
181c6916 test/data/animated-red-blue.000001.nie
e651a889 test/data/animated-red-blue.000002.nie
14a5b4b0 test/data/animated-red-blue.000003.nie
76e40058 test/data/animated-red-blue.apng
76e40058 test/data/animated-red-blue.gif
912861f4 test/data/archive.iso
f9a10dac test/data/artificial/gif-background-color.gif
36e7d9c7 test/data/artificial/gif-empty-palette.gif
db4c30eb test/data/artificial/gif-frame-out-of-bounds.gif
fdcc644f test/data/artificial/gif-metadata-empty.gif
fdcc644f test/data/artificial/gif-metadata-full.gif
6d03b5f3 test/data/artificial/gif-multiple-graphic-controls.gif
47c877fd test/data/artificial/gif-multiple-loop-counts.gif
76c44866 test/data/artificial/gif-no-frames.gif
6ec818c3 test/data/artificial/gif-pixel-data-none.gif
5e57adb2 test/data/artificial/gif-pixel-data-not-enough.gif
3e29f88a test/data/artificial/gif-pixel-data-too-much.gif
f50d1d50 test/data/artificial/gif-small-frame-interlaced.gif
beaec397 test/data/artificial/gif-transparent-index.gif
6ec818c3 test/data/artificial/gif-zero-width-frame.gif
912861f4 test/data/australian-abc-local-stations.tokens
f9a10dac test/data/artificial-gif/background-color.gif
36e7d9c7 test/data/artificial-gif/empty-palette.gif
db4c30eb test/data/artificial-gif/frame-out-of-bounds.gif
f2dc2c43 test/data/artificial-gif/metadata-empty.gif
f2dc2c43 test/data/artificial-gif/metadata-full.gif
a1a9b56d test/data/artificial-gif/multiple-graphic-controls.gif
046a2d07 test/data/artificial-gif/multiple-loop-counts.gif
ba6e48f8 test/data/artificial-gif/no-frames.gif
f33b9bc1 test/data/artificial-gif/pixel-data-none.gif
ac9d76d8 test/data/artificial-gif/pixel-data-not-enough.gif
2342e3fc test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif
2342e3fc test/data/artificial-gif/pixel-data-too-much-good-lzw.gif
39a71dce test/data/artificial-gif/small-frame-interlaced.gif
beaec397 test/data/artificial-gif/transparent-index.gif
f33b9bc1 test/data/artificial-gif/zero-width-frame.gif
0564b364 test/data/artificial-png/apng-skip-idat.png
e08a7cc8 test/data/artificial-png/exif.png
e08a7cc8 test/data/artificial-png/key-value-pairs.png
076cb375 test/data/bricks-color.bmp
076cb375 test/data/bricks-color.png
f36c2e80 test/data/bricks-dither.bmp
3fc62e1e test/data/bricks-dither.gif
f36c2e80 test/data/bricks-dither.gif
f36c2e80 test/data/bricks-dither.no-ancillary.png
f36c2e80 test/data/bricks-dither.png
c2bce675 test/data/bricks-gray.bmp
0e16e6eb test/data/bricks-gray.gif
c2bce675 test/data/bricks-gray.gif
c2bce675 test/data/bricks-gray.no-ancillary.png
c2bce675 test/data/bricks-gray.png
7aebfe6c test/data/bricks-nodither.bmp
b641fef2 test/data/bricks-nodither.gif
7aebfe6c test/data/bricks-nodither.gif
7aebfe6c test/data/bricks-nodither.png
ae2e547d test/data/bricks-nodither.wbmp
912861f4 test/data/cbor-rfc-7049-examples.tokens
b47730a2 test/data/checkerboard.gamma1dot0.png
b47730a2 test/data/checkerboard.gamma2dot2.png
aa3e6c7c test/data/crude-flag.nie
3014b4c0 test/data/gifplayer-muybridge.gif
030f5a48 test/data/harvesters.bmp
0d213dc4 test/data/harvesters.gif
c18b3d5a test/data/harvesters.gif
030f5a48 test/data/harvesters.png
e776c90f test/data/hat.bmp
a161a63a test/data/hat.gif
6dcba6a4 test/data/hat.gif
e776c90f test/data/hat.png
d30bfe5d test/data/hat.wbmp
33a44f22 test/data/hibiscus.primitive.bmp
e948122d test/data/hibiscus.primitive.gif
25e212b3 test/data/hibiscus.primitive.gif
33a44f22 test/data/hibiscus.primitive.png
60040742 test/data/hibiscus.regular.bmp
7b8dda15 test/data/hibiscus.regular.gif
b727da8b test/data/hibiscus.regular.gif
60040742 test/data/hibiscus.regular.png
dcbb225a test/data/hippopotamus.bmp
21e17862 test/data/hippopotamus.interlaced.gif
ed4b78fc test/data/hippopotamus.interlaced.gif
dcbb225a test/data/hippopotamus.interlaced.png
a80781a1 test/data/hippopotamus.interlaced.truncated.gif
1f11edb9 test/data/hippopotamus.masked-with-muybridge.gif
c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
21e17862 test/data/hippopotamus.regular.gif
dcbb225a test/data/hippopotamus.nie
ed4b78fc test/data/hippopotamus.regular.gif
dcbb225a test/data/hippopotamus.regular.png
aa7e021c test/data/json-quirks.tokens
912861f4 test/data/json-things.unformatted.tokens
2dccfe56 test/data/muybridge-frame-000.wbmp
db2733f5 test/data/muybridge.apng
db2733f5 test/data/muybridge.gif
bf7e8c96 test/data/pjw-thumbnail.bmp
73d48c08 test/data/pjw-thumbnail.gif
bf7e8c96 test/data/pjw-thumbnail.gif
bf7e8c96 test/data/pjw-thumbnail.png
38cb4cbf test/data/red-blue-gradient.dcip3d65-no-chrm-no-gama.png
38cb4cbf test/data/red-blue-gradient.gamma1dot0.png
38cb4cbf test/data/red-blue-gradient.gamma1dot8.png
38cb4cbf test/data/red-blue-gradient.gamma2dot2.png
38cb4cbf test/data/red-blue-gradient.vanilla.png
75060601 test/data/rgb24png.bmp