Compare commits

...
Author SHA1 Message Date
Nigel Tao 3387e19512 release: wuffs gen -version=0.4.0-alpha.9 2024-09-14 14:28:26 +10:00
Nigel Tao a14745aa45 base38: tweak note re 4/2 and 4/4/2 notation 2024-09-14 13:14:21 +10:00
Nigel Tao aeb35f0449 example/std-imagedumper: print width x height 2024-09-12 09:06:46 +10:00
Nigel Tao 48d2ffcf14 example/std-imagedumper: add -resize=N flag 2024-09-11 23:15:54 +10:00
Nigel Tao c304bd4c08 example/std-imagedumper: use Unicode half-blocks 2024-09-11 22:24:53 +10:00
Nigel Tao 97cd8d8e8a example/jsonfindptrs: avoid g++ uninitialized warn 2024-09-11 21:49:28 +10:00
Nigel Tao 05f4c37964 example/std-imagedumper: add dark/light mode 2024-09-10 22:02:27 +10:00
Nigel Tao b9e3c26dcc example/std-imagedumper: add file size and timer 2024-09-10 21:41:02 +10:00
Nigel Tao 8aa51dfa49 example/std-imagedumper: add -braille-art flag 2024-09-10 07:46:07 +10:00
Nigel Tao 9e76d545b6 test/3pdata: add call-out to corrupted byte 2024-09-08 23:24:25 +10:00
Nigel Tao 36991e1909 std/qoi: fix restart io_position 2024-09-08 23:19:05 +10:00
Nigel Tao ef6814e6c6 example/stb-imagedumper: use ETC__ENABLE_ALLOWLIST
Binary size, before:
539144 gen/bin/example-stb-imagedumper

After:
534880 gen/bin/example-stb-imagedumper
2024-09-08 22:58:54 +10:00
Nigel Tao 42ba720d4e pixconv: allow swizzling to Y (gray) more often
Binary size, before:
124816 gen/lib/c/clang-dynamic/wuffs-base-pixconv.lo
124816 gen/lib/c/clang-static/wuffs-base-pixconv.o
196736 gen/lib/c/gcc-dynamic/wuffs-base-pixconv.lo
196672 gen/lib/c/gcc-static/wuffs-base-pixconv.o

After:
142032 gen/lib/c/clang-dynamic/wuffs-base-pixconv.lo
142032 gen/lib/c/clang-static/wuffs-base-pixconv.o
242712 gen/lib/c/gcc-dynamic/wuffs-base-pixconv.lo
242584 gen/lib/c/gcc-static/wuffs-base-pixconv.o
2024-09-08 22:54:35 +10:00
Nigel Tao 43d412a15f example/stb-imagedumper: add USE_ONLY_JPEG 2024-09-08 11:29:18 +10:00
Nigel Tao 53b3b0a9d0 std/jpeg: fix default-quality workbuf length check 2024-09-08 11:29:01 +10:00
Nigel Tao affff51fbf base: add pixel_format.coloration 2024-09-08 10:37:43 +10:00
Nigel Tao 85af5a4bed std/tga: rename to std/targa 2024-09-08 09:00:10 +10:00
Nigel Tao 8924b5f003 cgen: add ETC__ENABLE_DROP_IN_REPLACEMENT__STB
Fixes #153
2024-09-07 22:21:00 +10:00
Nigel Tao bb2600e423 test/data: add mona-lisa.*
wget -q -O mona-lisa.322x480.jpeg 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/322px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg'
convert mona-lisa.322x480.jpeg -resize 32x32 mona-lisa.21x32.png
pngcrush -ow -brute -rem alla mona-lisa.21x32.png
convert mona-lisa.21x32.png mona-lisa.21x32.ppm
cjpeg -quality 50 mona-lisa.21x32.ppm > mona-lisa.21x32.q50.jpeg
cjpeg -quality 90 mona-lisa.21x32.ppm > mona-lisa.21x32.q90.jpeg
etcpack mona-lisa.21x32.ppm mona-lisa.21x32.etc2.pkm
rm mona-lisa.21x32.ppm mona-lisa.322x480.jpeg

The *.th file was manually encoded by uploading mona-lisa.21x32.png to
https://evanw.github.io/thumbhash/ and prepending the magic identifier.
2024-09-06 14:26:38 +10:00
Nigel Tao 43b6fef8b1 std/thumbhash: add QUIRK_JUST_RAW_THUMBHASH 2024-09-06 13:23:38 +10:00
Nigel Tao 78f4e4ccc4 test/data: add official thumbhash PNG renderings 2024-09-06 12:56:00 +10:00
Nigel Tao 8c854ae702 std/thumbhash: implement do_decode_frame 2024-09-06 12:35:53 +10:00
Nigel Tao b8740d8881 std/thumbhash: add new package 2024-09-03 20:07:37 +10:00
Nigel Tao aa28bb076c test/data: add thumbhash (*.th) files 2024-09-03 10:02:30 +10:00
Nigel Tao 1723532443 base: add ABXR, ABXS magic numbers 2024-08-31 14:37:32 +10:00
Nigel Tao 86d16d90df base38: add enumerated-media-types.txt 2024-08-31 13:13:20 +10:00
Nigel Tao bd42fa7af2 base38: reassign alphabet and numbers
It changes from " 0-9?a-z" to ".0-9a-z~". The default or placeholder
changes from " " to "." so it's now always visible. The wildcard changes
from "?" to "~" so it's now sorted last.
2024-08-26 12:30:20 +10:00
Nigel Tao e12f10eef0 std/jpeg: tweak ignore too-short marker code
name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang14               317MB/s ± 0%  325MB/s ± 0%  +2.60%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang14  322MB/s ± 0%  325MB/s ± 0%  +0.94%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang14   864MB/s ± 0%  880MB/s ± 0%  +1.84%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang14              720MB/s ± 0%  730MB/s ± 0%  +1.39%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_420/clang14         783MB/s ± 0%  794MB/s ± 0%  +1.44%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang14         884MB/s ± 0%  914MB/s ± 0%  +3.39%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang14            781MB/s ± 0%  796MB/s ± 0%  +1.90%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc12                 359MB/s ± 0%  360MB/s ± 0%  +0.12%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc12    311MB/s ± 0%  310MB/s ± 0%  -0.30%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc12     909MB/s ± 0%  915MB/s ± 0%  +0.66%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc12                747MB/s ± 0%  750MB/s ± 0%  +0.34%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc12           817MB/s ± 0%  819MB/s ± 0%  +0.30%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc12           971MB/s ± 0%  972MB/s ± 0%  +0.11%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc12              819MB/s ± 0%  821MB/s ± 0%  +0.21%  (p=0.008 n=5+5)
2024-08-25 23:03:06 +10:00
Nigel Tao 6693250aa9 lang: add io_reader.peek_u8_at 2024-08-25 15:07:29 +10:00
Nigel Tao d4bab677b0 std/jpeg: skip 0xFF filler before restart search 2024-08-25 14:48:17 +10:00
Nigel Tao 6a9347843b std/jpeg: ignore too-short COM or APPn markers 2024-08-25 13:46:16 +10:00
Nigel Tao 408ab25f04 script: have confirm-matches-djpeg say "too large"
+Differ (large)
2024-08-25 13:05:59 +10:00
Nigel Tao 819742cfac std/jpeg: add "#short SOS bitstream" 2024-08-24 17:01:28 +10:00
Nigel Tao a824c55c3d std/jpeg: allow DHT markers before SOF 2024-08-24 16:13:31 +10:00
Nigel Tao 60e3b8cb1c test/data: add bricks-color.etc1s.pkm 2024-08-23 22:14:33 +10:00
Nigel Tao 96eda2ec0d std/etc2: support transparency 2024-08-18 15:09:51 +10:00
Nigel Tao 2d80615a08 std/etc2: refactor decoder.from_src_to_buffer 2024-08-18 10:07:58 +10:00
Nigel Tao 7637982814 std/etc2: support ETC2PACKAGE_RGB_NO_MIPMAPS 2024-08-18 09:42:22 +10:00
Nigel Tao 43df015669 std/etc2: add new package 2024-08-17 15:31:29 +10:00
Nigel Tao 5a8f636a66 base: add magic number for ETC2 2024-08-16 10:17:44 +10:00
Nigel Tao 4423a0cbbe test/data: add bricks-color.etc?.pkm 2024-08-16 09:21:12 +10:00
Nigel Tao beaf456500 release: wuffs gen -version=0.4.0-alpha.8 2024-08-13 10:46:04 +10:00
Nigel Tao 5d69840f8e cgen: swap calloc args
For calloc(nmemb, size), multiplication is commutative, but this still
fixes a -Werror=calloc-transposed-args failure with coreboot's compiler.
2024-08-12 22:33:33 +10:00
Nigel Tao 721e574398 base: avoid "#if SIZE_MAX < UINT64_MAX"
This fixes a -Werror=undef failure with coreboot's compiler.
2024-08-12 22:29:40 +10:00
Nigel Tao c89b3bc6d8 release: wuffs gen -version=0.4.0-alpha.7 2024-08-11 11:08:25 +10:00
Nigel Tao a07eb7704b std/jpeg: add QUIRK_REJECT_PROGRESSIVE_JPEGS 2024-08-11 10:15:13 +10:00
Nigel Tao bd27cc0d9b std/qoi: use PIXEL_FORMAT__BGRX 2024-08-09 13:48:34 +10:00
Nigel Tao d06700f00b std/qoi: add new package
Fixes #63
2024-08-08 23:49:17 +10:00
100 changed files with 22786 additions and 951 deletions

No files matched your search

+11
View File
@@ -78,6 +78,13 @@ func doGenrelease(args []string) error {
}
relFilename := filename[len(baseDirSlash):]
// std/tga was renamed to std/targa in September 2024 (Wuffs v0.4
// alpha). Ignore the generated file from older versions.
if relFilename == "wuffs-std-tga.c" {
println(filename + " is obsolete, please delete it.")
continue
}
s, err := os.ReadFile(filename)
if err != nil {
return err
@@ -110,6 +117,8 @@ func doGenrelease(args []string) error {
out.WriteString("\n")
}
out.WriteString("#endif // defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR)\n")
out.WriteString("\n")
out.WriteString(cgen.EmbeddedString_DropInSTBH.Trim())
out.Write(grImplStartsHere)
out.WriteString("\n")
@@ -129,6 +138,8 @@ func doGenrelease(args []string) error {
out.WriteString("\n")
}
out.WriteString("#endif // defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR)\n\n")
out.WriteString("\n")
out.WriteString(cgen.EmbeddedString_DropInSTBC.Trim())
out.Write(grImplEndsHere)
out.WriteString(grPragmaPop)
+6
View File
@@ -16,11 +16,14 @@ The LICENSE has changed from a single license (Apache 2) to a dual license
- Added `example/mzcat`.
- Added `get_quirk(key: u32) u64`.
- Added `std/crc64`.
- Added `std/etc2`.
- Added `std/jpeg`.
- Added `std/lzip`.
- Added `std/lzma`.
- Added `std/netpbm`.
- Added `std/qoi`.
- Added `std/sha256`.
- Added `std/thumbhash`.
- Added `std/vp8`.
- Added `std/webp`.
- Added `std/xxhash32`.
@@ -29,6 +32,7 @@ The LICENSE has changed from a single license (Apache 2) to a dual license
- Added `WUFFS_BASE__QUIRK_QUALITY`.
- Added `WUFFS_CONFIG__DISABLE_MSVC_CPU_ARCH__X86_64_FAMILY`.
- Added `WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST`.
- Added `WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB`.
- Added `WUFFS_CONFIG__ENABLE_MSVC_CPU_ARCH__X86_64_V2`.
- Added `WUFFS_CONFIG__ENABLE_MSVC_CPU_ARCH__X86_64_V3`.
- Added `wuffs_base__status__is_truncated_input_error`.
@@ -41,9 +45,11 @@ The LICENSE has changed from a single license (Apache 2) to a dual license
- Halved the sizeof `wuffs_foo__bar::unique_ptr`.
- Let `std/png` decode PNG color type 4 to `PIXEL_FORMAT__YA_NONPREMUL` (two
channels) instead of `PIXEL_FORMAT__BGRA_NONPREMUL` (four channels).
- Reassigned `lib/base38` alphabet and numbers.
- Removed the `std/gif -> std/lzw` dependency.
- Removed `endwhile` keyword.
- Removed `example/bzcat`.
- Renamed `std/tga` to `std/targa`.
- Set image decoder pixel width and height inclusive maximum to `0xFF_FFFF`,
down from `0x7FFF_FFFF`.
+122 -14
View File
@@ -31,26 +31,134 @@ Wuffs uses the big-endian interpretation, as it maintains ordering.
Base38 is a tighter encoding than FourCC, fitting four characters into 21 bits
instead of 32 bits. This is achieved by using a smaller alphabet of 38 possible
values (space, 0-9, ? or a-z), so that it cannot distinguish between e.g. an
upper case 'X' and a lower case 'x'. There's also the happy coincidence that
`38 ** 4 = 0x1FD110 = 2085136` is slightly smaller than `2 ** 21 = 0x200000 =
2097152`.
values ('.', 0-9, a-z or '~'), so that it cannot distinguish between e.g. an
upper case 'X' and a lower case 'x'. There are then two happy coincidences:
The base38 encoding of `"JPEG"` is `0x122FF6`, which is `1191926`, which is
`((21 * (38 ** 3)) + (27 * (38 ** 2)) + (16 * (38 ** 1)) + (18 * (38 ** 0)))`.
- `38 ** 4 = 0x1FD110 = 2085136` is slightly smaller than `2 ** 21 = 0x200000 =
2097152`.
- 21 bits is just large enough to hold every valid Unicode code point, so that
systems and data formats that can hold "one UCP" can be repurposed to
alternatively hold "one base38-encoded four-character string".
The base38 encoding of `"jpeg"` is `0x1153D3`, which is `1135571`, which is
`((20 * (38 ** 3)) + (26 * (38 ** 2)) + (15 * (38 ** 1)) + (17 * (38 ** 0)))`.
The base38 encoding of `"ping"` is `0x1633BD`, which is `1455037`, which is
`((26 * (38 ** 3)) + (19 * (38 ** 2)) + (24 * (38 ** 1)) + (17 * (38 ** 0)))`.
The minimum base38 value, 0x000000, corresponds to `"...."`. Depending on
context, this can be used as a default, built-in or placeholder value.
The maximum base38 value, 0x1FD10F = 2085135, corresponds to `"~~~~"`.
Depending on context, this can be used as a "matches everything" wildcard.
The maximum 21-bit value, 0x1FFFFF = 2097151, is not a valid base38 value but
can still be used in some contexts as a sentinel or option-not-set value.
### Base38 Namespaces
Using only 21 bits means that we can use base38 values to partition the set of
possible `uint32_t` values into file-format specific enumerations. Each package
(i.e. Wuffs implementation of a specific file format) can define up to 1024
different values in their own namespace, without conflicting with other
packages (assuming that there aren't e.g. two `"JPEG"` Wuffs packages in the
same library). The conventional `uint32_t` packing is:
local values in their own four-character namespace, without conflicting with
other packages (assuming that there aren't e.g. two `"jpeg"` Wuffs packages in
the same library). The conventional `uint32_t` packing is:
- Bit `31` (1 bit) is reserved (zero).
- Bits `10 ..= 30` (21 bits) are the base38 value, shifted by 10.
- Bits `0 ..= 9` (10 bits) are the enumeration value.
- Bits `10 ..= 30` (21 bits) are the base38-encoded namespace, shifted by 10.
- Bits `0 ..= 9` (10 bits) are the local enumeration value.
For example:
- [Quirk values](/doc/note/quirks.md) use this `((base38 << 10) | enumeration)`
scheme.
- [Tokens](/doc/note/tokens.md) assign 21 out of 64 bits for a Base38 value.
- [Quirk keys](/doc/note/quirks.md), as a `uint32_t`, use this
`((namespace << 10) | local)` scheme.
- [Tokens](/doc/note/tokens.md) assign 21 out of 64 bits for a base38 value.
### Base38 4/4/4 and 4/4/2
3×21 bits fits snugly into a `int64_t` or `uint64_t` (the sign or high bit is
unused). 63 bits can therefore hold a 12-character or three 4-character strings
(taken from base38's limited alphabet).
For example, in a custom RPC protocol, the namespace/class/method name could be
base38-encoded as a 4/4/4 string like `"net./conn/ping"`. As a number, the
4/4/4 format (instead of a monolithic 12) means that each 4-character fragment
is base-38 encoded independently and the three 21-bit numbers are then combined
(with bitshifting). `"net./conn/ping"` would be `((0x147150 << 42) | (0x0B7324
<< 21) | 0x1633BD)` which is `0x51C5416E_649633BD`. At the wire format level,
this would occupy a fixed-length (8 bytes) and that 64th bit could, for
example, indicate request or response.
A 2-character string can fit in 11 bits, as `38 ** 2 = 0x5A4 = 1444` is smaller
than `2 ** 11 = 0x800 = 2048`. Therefore:
- 32 bits (21 + 11) can hold a 6-character (as 4/2) alpha-numeric-ish string.
32 bits obviously fits snugly in a `uint32_t`.
- 53 bits (21 + 21 + 11) can hold a 10-character (as 4/4/2) alpha-numeric-ish
string. 53 bits fits snugly under JavaScript's `Number.MAX_SAFE_INTEGER` so
these integers can be losslessly stored in a `double` or a JSON value.
[Enumerated Media Types](./enumerated-media-types.txt) uses this base38 4/4/2
encoding, mapping `"image/jpeg"` to the base38 `"imag/jpeg/.."` which is
`((0x106BF7 << 32) | (0x1153D3 << 11) | 0x000)` which is `0x106BF7_8A9E9800`.
Some more examples:
- `0x09CC62_A9E37800 = "appl/octe/.." = "application/octet-stream"`
- `0x09CC62_B0B24000 = "appl/pdf./.." = "application/pdf"`
- `0x09CC62_DACDFC4E = "appl/voao/s." = "application/vnd.oasis.opendocument.spreadsheet"`
- `0x09CC62_DACDFC6C = "appl/voao/st" = "application/vnd.oasis.opendocument.spreadsheet-template"`
- `0x09CC62_DACDFC74 = "appl/voao/t." = "application/vnd.oasis.opendocument.text"`
- `0x09CC62_DADFCC6B = "appl/vopo/ss" = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"`
- `0x106BF7_8A9E9800 = "imag/jpeg/.." = "image/jpeg"`
- `0x106BF7_B276B000 = "imag/png./.." = "image/png"`
- `0x106BF7_FE887DA3 = "imag/~~~~/~~" = "image/*"`
- `0x197816_7DF74000 = "text/html/.." = "text/html"`
- `0x197816_B215E800 = "text/plai/.." = "text/plain"`
### Base38 Alphabet
Case-insensitive alpha-numeric, roughly speaking.
```
'.' = 0
'0' = 1
'1' = 2
'2' = 3
'3' = 4
'4' = 5
'5' = 6
'6' = 7
'7' = 8
'8' = 9
'9' = 10
'a' = 11
'b' = 12
'c' = 13
'd' = 14
'e' = 15
'f' = 16
'g' = 17
'h' = 18
'i' = 19
'j' = 20
'k' = 21
'l' = 22
'm' = 23
'n' = 24
'o' = 25
'p' = 26
'q' = 27
'r' = 28
's' = 29
't' = 30
'u' = 31
'v' = 32
'w' = 33
'x' = 34
'y' = 35
'z' = 36
'~' = 37
```
+233
View File
@@ -0,0 +1,233 @@
# Enumerated Media Types
# ----------------------
#
# This is a curated list of about 200 common Media Types (also known as MIME
# Types). The official name, with variable length, is in the fourth column. A
# fixed length contraction, presented in 4/4/2 format, is in the third column.
# The base38 numeric encoding of that 4/4/2 string is in the first (hex) and
# second (decimal) columns. These positive numbers are all less than or equal
# to ((1<<53)-1), also known as Number.MAX_SAFE_INTEGER in JavaScript, and so
# generally safe to pass around as a JSON value, float64, int64 or uint64.
#
# As an int64 or uint64, the high 32 bits (of which only 21 are used) hold the
# top-level type: 0x09CC62 means "application", 0x106BF7 means "image", etc.
#
# Using fixed-size numbers instead of variable-length strings can be useful in
# file formats, wire protocols, database tables or other contexts where dynamic
# memory allocation is unavailable or fallible or where variable-length data
# complicates matters. At the micro-optimization level, comparing or hashing
# uint64 numbers is also faster than for arbitrary strings.
#
# Using a sparse enumeration (instead of the dense 1 = "application/epub+zip",
# 2 = "application/java-archive", etc) means that, when debugging or logging,
# the numerical value can be converted to a somewhat-human-readable form (the
# "appl/java/ar" 4/4/2 string) purely algorithmically, without a lookup table.
# Inserting new entries can also preserve the sortedness of the 4/4/2 form
# without requiring renumbering.
#
# When debugging, if the numerical value is all that you know, grepping a large
# codebase for 0x09CC62_880DB9BE or 2757998351858110 will also produce far
# fewer false positives than grepping for 2.
#
# The pua.example subtypes (e.g. for private use within a system that deals
# with "foobar.example" files) are an unofficial suggestion for entries not in
# the official IANA registry, similar to Unicode's Private Use Area. For a PUA
# entry's 4/4/2 string, the middle-4 starts with a "~" (and cannot be "~~~~")
# but the rest of the middle-4-right-2 is freeform.
#
# The official IANA Media Types registry:
# https://www.iana.org/assignments/media-types/media-types.xhtml
#
# A popular subset of that registry, with about 800 entries, as well as a
# mapping between Media Types (like "application/java-archive") and filename
# extensions (like ".jar"):
# https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
#
# This file (enumerated-media-types.txt) is canonically hosted in the doc/note
# directory of the github.com/google/wuffs repository. That same directory also
# holds a base38-and-fourcc.md file that elaborates on base38 encoding.
0x09CC62_6933B000 2757997834252288 appl/epub/.. application/epub+zip
0x09CC62_880DB9BE 2757998351858110 appl/java/ar application/java-archive
0x09CC62_880DBC67 2757998351858791 appl/java/so application/java-serialized-object
0x09CC62_880DBCD7 2757998351858903 appl/java/vm application/java-vm
0x09CC62_8B321000 2757998404571136 appl/json/.. application/json
0x09CC62_9C23B800 2757998688843776 appl/mate/.. application/mathematica
0x09CC62_9C23F800 2757998688860160 appl/matm/.. application/mathml+xml
0x09CC62_9F53D800 2757998742329344 appl/mswo/.. application/msword
0x09CC62_A9E37800 2757998919514112 appl/octe/.. application/octet-stream
0x09CC62_B0B24000 2757999033729024 appl/pdf./.. application/pdf
0x09CC62_B2B30000 2757999067332608 appl/post/.. application/postscript
0x09CC62_C0E9C000 2757999305801728 appl/rtf./.. application/rtf
0x09CC62_C664E000 2757999397756928 appl/smil/.. application/smil+xml
0x09CC62_CE584000 2757999531147264 appl/ttml/.. application/ttml+xml
0x09CC62_D86553E7 2757999699776487 appl/vand/pa application/vnd.android.package-archive
0x09CC62_D8681384 2757999699956612 appl/vapp/mp application/vnd.apple.mpegurl
0x09CC62_D9754B34 2757999717600052 appl/vgoe/kl application/vnd.google-earth.kml+xml
0x09CC62_D9754B42 2757999717600066 appl/vgoe/kz application/vnd.google-earth.kmz
0x09CC62_D9C13800 2757999722575872 appl/vicc/.. application/vnd.iccprofile
0x09CC62_DA1CBB29 2757999728573225 appl/vkde/ka application/vnd.kde.karbon
0x09CC62_DA1CBB2B 2757999728573227 appl/vkde/kc application/vnd.kde.kchart
0x09CC62_DA1CBB2E 2757999728573230 appl/vkde/kf application/vnd.kde.kformula
0x09CC62_DA1CBB31 2757999728573233 appl/vkde/ki application/vnd.kde.kivio
0x09CC62_DA1CBB37 2757999728573239 appl/vkde/ko application/vnd.kde.kontour
0x09CC62_DA1CBB38 2757999728573240 appl/vkde/kp application/vnd.kde.kpresenter
0x09CC62_DA1CBB3B 2757999728573243 appl/vkde/ks application/vnd.kde.kspread
0x09CC62_DA1CBB3F 2757999728573247 appl/vkde/kw application/vnd.kde.kword
0x09CC62_DA8851F9 2757999735624185 appl/vms./ca application/vnd.ms-cab-compressed
0x09CC62_DA88525C 2757999735624284 appl/vms./ex application/vnd.ms-excel
0x09CC62_DA8852CA 2757999735624394 appl/vms./ht application/vnd.ms-htmlhelp
0x09CC62_DA8853F5 2757999735624693 appl/vms./po application/vnd.ms-powerpoint
0x09CC62_DACDF9EE 2757999740189166 appl/voao/c. application/vnd.oasis.opendocument.chart
0x09CC62_DACDFA0C 2757999740189196 appl/voao/ct application/vnd.oasis.opendocument.chart-template
0x09CC62_DACDFA14 2757999740189204 appl/voao/d. application/vnd.oasis.opendocument.database
0x09CC62_DACDFA60 2757999740189280 appl/voao/f. application/vnd.oasis.opendocument.formula
0x09CC62_DACDFA7E 2757999740189310 appl/voao/ft application/vnd.oasis.opendocument.formula-template
0x09CC62_DACDFA86 2757999740189318 appl/voao/g. application/vnd.oasis.opendocument.graphics
0x09CC62_DACDFAA4 2757999740189348 appl/voao/gt application/vnd.oasis.opendocument.graphics-template
0x09CC62_DACDFAD2 2757999740189394 appl/voao/i. application/vnd.oasis.opendocument.image
0x09CC62_DACDFAF0 2757999740189424 appl/voao/it application/vnd.oasis.opendocument.image-template
0x09CC62_DACDFBDC 2757999740189660 appl/voao/p. application/vnd.oasis.opendocument.presentation
0x09CC62_DACDFBFA 2757999740189690 appl/voao/pt application/vnd.oasis.opendocument.presentation-template
0x09CC62_DACDFC4E 2757999740189774 appl/voao/s. application/vnd.oasis.opendocument.spreadsheet
0x09CC62_DACDFC6C 2757999740189804 appl/voao/st application/vnd.oasis.opendocument.spreadsheet-template
0x09CC62_DACDFC74 2757999740189812 appl/voao/t. application/vnd.oasis.opendocument.text
0x09CC62_DACDFC8B 2757999740189835 appl/voao/tm application/vnd.oasis.opendocument.text-master
0x09CC62_DACDFC92 2757999740189842 appl/voao/tt application/vnd.oasis.opendocument.text-template
0x09CC62_DACDFC95 2757999740189845 appl/voao/tw application/vnd.oasis.opendocument.text-web
0x09CC62_DADFCBF6 2757999741357046 appl/vopo/pp application/vnd.openxmlformats-officedocument.presentationml.presentation
0x09CC62_DADFCBF8 2757999741357048 appl/vopo/pr application/vnd.openxmlformats-officedocument.presentationml.slide
0x09CC62_DADFCBF9 2757999741357049 appl/vopo/ps application/vnd.openxmlformats-officedocument.presentationml.slideshow
0x09CC62_DADFCBFA 2757999741357050 appl/vopo/pt application/vnd.openxmlformats-officedocument.presentationml.template
0x09CC62_DADFCC6B 2757999741357163 appl/vopo/ss application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
0x09CC62_DADFCC6C 2757999741357164 appl/vopo/st application/vnd.openxmlformats-officedocument.spreadsheetml.template
0x09CC62_DADFCCF4 2757999741357300 appl/vopo/wd application/vnd.openxmlformats-officedocument.wordprocessingml.document
0x09CC62_DADFCD04 2757999741357316 appl/vopo/wt application/vnd.openxmlformats-officedocument.wordprocessingml.template
0x09CC62_DF1E4800 2757999812560896 appl/wasm/.. application/wasm
0x09CC62_E5514000 2757999916564480 appl/x7z./.. application/x-7z-compressed
0x09CC62_E5BCB800 2757999923607552 appl/xabi/.. application/x-abiword
0x09CC62_E5CD9227 2757999924711975 appl/xapp/di application/x-apple-diskimage
0x09CC62_E5F28000 2757999927132160 appl/xbit/.. application/x-bittorrent
0x09CC62_E605D800 2757999928399872 appl/xbz2/.. application/x-bzip2
0x09CC62_E61DF800 2757999929980928 appl/xche/.. application/x-chess-pgn
0x09CC62_E6477000 2757999932698624 appl/xdeb/.. application/x-debian-package
0x09CC62_E653B800 2757999933503488 appl/xdoo/.. application/x-doom
0x09CC62_E65BD800 2757999934035968 appl/xdvi/.. application/x-dvi
0x09CC62_E6DA1800 2757999942309888 appl/xgnu/.. application/x-gnumeric
0x09CC62_E70E1800 2757999945717760 appl/xhtm/.. application/xhtml+xml
0x09CC62_E73A1800 2757999948601344 appl/xiso/.. application/x-iso9660-image
0x09CC62_E7AC4000 2757999956082688 appl/xlat/.. application/x-latex
0x09CC62_E7E58000 2757999959834624 appl/xml./.. application/xml
0x09CC62_E7E5F000 2757999959863296 appl/xmld/.. application/xml-dtd
0x09CC62_E7EDD1BC 2757999960379836 appl/xms./ap application/x-ms-application
0x09CC62_E7EDD460 2757999960380512 appl/xms./sh application/x-ms-shortcut
0x09CC62_E7EE4000 2757999960408064 appl/xmsd/.. application/x-msdownload
0x09CC62_E8BAF000 2757999973822464 appl/xrar/.. application/x-rar-compressed
0x09CC62_E8EF8000 2757999977267200 appl/xsh./.. application/x-sh
0x09CC62_E8F04800 2757999977318400 appl/xsho/.. application/x-shockwave-flash
0x09CC62_E8FAE000 2757999978012672 appl/xsql/.. application/x-sql
0x09CC62_E9153000 2757999979737088 appl/xtar/.. application/x-tar
0x09CC62_E91A2000 2757999980060672 appl/xtex/.. application/x-tex
0x09CC62_E91A2277 2757999980061303 appl/xtex/fm application/x-tex-tfm
0x09CC62_E91A22EA 2757999980061418 appl/xtex/in application/x-texinfo
0x09CC62_E9E68000 2757999993454592 appl/xxz./.. application/x-xz
0x09CC62_F49B4000 2758000173072384 appl/zip./.. application/zip
0x09CC62_FAA35800 2758000274266112 appl/~exa/.. application/pua.example
0x09CC62_FE887DA3 2758000339615139 appl/~~~~/~~ application/*
0x09E6CB_1DE9D000 2787034845007872 audi/3gpp/.. audio/3gpp
0x09E6CB_4C087000 2787035618766848 audi/acc3... audio/ac3
0x09E6CB_4DDD6000 2787035649499136 audi/amr./.. audio/amr
0x09E6CB_4DDE6800 2787035649566720 audi/amrw/.. audio/amr-wb
0x09E6CB_52746800 2787035726505984 audi/basi/.. audio/basic
0x09E6CB_9D79D800 2787036985153536 audi/midi/.. audio/midi
0x09E6CB_9E86B000 2787037002772480 audi/mobx/.. audio/mobile-xmf
0x09E6CB_9EAA7000 2787037005115392 audi/mp4./.. audio/mp4
0x09E6CB_9EB6D800 2787037005928448 audi/mpeg/.. audio/mpeg
0x09E6CB_AA881000 2787037204189184 audi/ogg./.. audio/ogg
0x09E6CB_E5BB5800 2787038197405696 audi/xaac/.. audio/x-aac
0x09E6CB_E5C4F000 2787038198034432 audi/xaif/.. audio/x-aiff
0x09E6CB_E6A9F800 2787038213044224 audi/xfla/.. audio/x-flac
0x09E6CB_E7D96000 2787038232928256 audi/xmat/.. audio/x-matroska
0x09E6CB_E7EB3800 2787038234097664 audi/xmpu/.. audio/x-mpegurl
0x09E6CB_E7EDD4F1 2787038234268913 audi/xms./wa audio/x-ms-wax
0x09E6CB_E7EDD4FD 2787038234268925 audi/xms./wm audio/x-ms-wma
0x09E6CB_E8702000 2787038242807808 audi/xpnr/.. audio/x-pn-realaudio
0x09E6CB_E99CB000 2787038262505472 audi/xwav/.. audio/x-wav
0x09E6CB_FE887DA3 2787038613503395 audi/~~~~/~~ audio/*
0x0DF632_5B96B000 3929870842638336 font/coll/.. font/collection
0x0DF632_ACD18000 3929872205447168 font/otf./.. font/otf
0x0DF632_CE4F4000 3929872767336448 font/ttf./.. font/ttf
0x0DF632_E1866000 3929873089716224 font/woff/.. font/woff
0x0DF632_E1866072 3929873089716338 font/woff/2. font/woff2
0x0DF632_FE887DA3 3929873576394147 font/~~~~/~~ font/*
0x106BF7_4F695000 4622309560766464 imag/avif/.. image/avif
0x106BF7_548DC000 4622309647040512 imag/bmp./.. image/bmp
0x106BF7_754B2000 4622310196322304 imag/gif./.. image/gif
0x106BF7_8A8FD000 4622310553145344 imag/jp2./.. image/jp2
0x106BF7_8A9E9800 4622310554114048 imag/jpeg/.. image/jpeg
0x106BF7_8AB4A000 4622310555557888 imag/jpx./.. image/jpx
0x106BF7_8C0F6000 4622310578282496 imag/jxl./.. image/jxl
0x106BF7_921BE000 4622310679764992 imag/ktx./.. image/ktx
0x106BF7_B276B000 4622311222587392 imag/png./.. image/png
0x106BF7_C7F90000 4622311583449088 imag/svgx/.. image/svg+xml
0x106BF7_CC5F6000 4622311657267200 imag/tiff/.. image/tiff
0x106BF7_D859CBF9 4622311858228217 imag/vado/ps image/vnd.adobe.photoshop
0x106BF7_D8E88000 4622311867580416 imag/vdjv/.. image/vnd.djvu
0x106BF7_DC3704F2 4622311923057906 imag/vwap/wb image/vnd.wap.wbmp
0x106BF7_DFBEB000 4622311982280704 imag/webp/.. image/webp
0x106BF7_E7271800 4622312106563584 imag/xico/.. image/x-icon
0x106BF7_E87151B9 4622312128205241 imag/xpor/am image/x-portable-anymap
0x106BF7_E87151DF 4622312128205279 imag/xpor/bm image/x-portable-bitmap
0x106BF7_E871529D 4622312128205469 imag/xpor/gm image/x-portable-graymap
0x106BF7_E87153F3 4622312128205811 imag/xpor/pm image/x-portable-pixmap
0x106BF7_E91BC800 4622312139376640 imag/xtga/.. image/x-tga
0x106BF7_FAA35800 4622312433473536 imag/~exa/.. image/pua.example
0x106BF7_FE887DA3 4622312498822563 imag/~~~~/~~ image/*
0x13F426_4DB31800 5616469907019776 mult/alte/.. multipart/alternative
0x13F426_56B07800 5616470057842688 mult/byte/.. multipart/byteranges
0x13F426_6FB61800 5616470477641728 mult/form/.. multipart/form-data
0x13F426_9D917800 5616471246993408 mult/mixe/.. multipart/mixed
0x13F426_E7E30000 5616472493850624 mult/xmix/.. multipart/x-mixed-replace
0x13F426_FE887DA3 5616472873794979 mult/~~~~/~~ multipart/*
0x197816_59144800 7168911796881408 text/cacm/.. text/cache-manifest
0x197816_591EB800 7168911797565440 text/cale/.. text/calendar
0x197816_5C52D000 7168911851311104 text/css./.. text/css
0x197816_5C566000 7168911851544576 text/csv./.. text/csv
0x197816_7DF74000 7168912415735808 text/html/.. text/html
0x197816_880E4800 7168912585017344 text/javs/.. text/javascript
0x197816_9C218800 7168912921823232 text/mark/.. text/markdown
0x197816_B215E800 7168913290160128 text/plai/.. text/plain
0x197816_C0E9C000 7168913538924544 text/rtf./.. text/rtf
0x197816_CAF20800 7168913707239424 text/tabs/.. text/tab-separated-values
0x197816_CE8B9000 7168913767632896 text/turt/.. text/turtle
0x197816_D4AC0000 7168913870422016 text/uril/.. text/uri-list
0x197816_E6082000 7168914161672192 text/xc../.. text/x-c
0x197816_E7521000 7168914183294976 text/xjav/.. text/x-java-source
0x197816_E7E58000 7168914192957440 text/xml./.. text/xml
0x197816_E971A000 7168914218917888 text/xvcl/.. text/x-vcalendar
0x197816_E971D000 7168914218930176 text/xvcr/.. text/x-vcard
0x197816_FE887DA3 7168914572737955 text/~~~~/~~ text/*
0x1B384F_1DE9D000 7661736826621952 vide/3gpp/.. video/3gpp
0x1B384F_1DE9D072 7661736826622066 vide/3gpp/2. video/3gpp2
0x1B384F_9EAA7000 7661738986729472 vide/mp4./.. video/mp4
0x1B384F_9EB6D800 7661738987542528 vide/mpeg/.. video/mpeg
0x1B384F_AA881000 7661739185803264 vide/ogg./.. video/ogg
0x1B384F_BA681800 7661739452143616 vide/quic/.. video/quicktime
0x1B384F_DA85B800 7661739990956032 vide/vmpu/.. video/vnd.mpegurl
0x1B384F_DFBE9800 7661740078569472 vide/webm/.. video/webm
0x1B384F_E6AAA000 7661740194701312 vide/xflv/.. video/x-flv
0x1B384F_E7D96000 7661740214542336 vide/xmat/.. video/x-matroska
0x1B384F_E7E86800 7661740215527424 vide/xmng/.. video/x-mng
0x1B384F_E7EDD1BF 7661740215882175 vide/xms./as video/x-ms-asf
0x1B384F_E7EDD4FD 7661740215883005 vide/xms./wm video/x-ms-wm
0x1B384F_E7EDD506 7661740215883014 vide/xms./wv video/x-ms-wmv
0x1B384F_E7EDD508 7661740215883016 vide/xms./wx video/x-ms-wmx
0x1B384F_E7EDD52E 7661740215883054 vide/xms./xx video/x-ms-wvx
0x1B384F_E7EED000 7661740215947264 vide/xmsv/.. video/x-msvideo
0x1B384F_FE887DA3 7661740595117475 vide/~~~~/~~ video/*
+2 -1
View File
@@ -26,7 +26,8 @@ no alpha) and floating point samples should mean a bit depth of 16, 32 or 64.
Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA (2
channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4
channels: cyan, magenta, yellow, black).
channels: cyan, magenta, yellow, black). BGRX holds 4 channels even though the
X-padding channel's values are ignored.
For direct formats with N > 1 channels, those channels can be laid out in
either 1 (interleaved) or N (planar) planes. For example, RGBA data is usually
+8 -5
View File
@@ -30,15 +30,16 @@ even for malformed input.
## Wuffs API
Each quirk is assigned a `uint32_t` number, packed using the [base38 namespace
Each quirk is assigned a 31-bit `uint32_t` number (the highest bit is unused),
whose high 21 bits use the [base38 namespace
convention](/doc/note/base38-and-fourcc.md). Decoders and encoders can have a
`set_quirk!(key: base.u32, value: base.u64) base.status` method whose key
argument is this `uint32_t` number.
For example, the base38 encoding of `"gif "` and `"json"` is `0x0F8586` and
`0x124265` respectively, so that the GIF-specific quirks have a `uint32_t` key
of `((0x0F8586 << 10) | g)` and the JSON-specific quirks have a `uint32_t` key
of `((0x124265 << 10) | j)`, for some small integers `g` and `j`. The high bits
For example, the base38 encoding of `"gif."` and `"json"` is `0x0EA964` and
`0x116642` respectively, so that the GIF-specific quirks have a `uint32_t` key
of `((0x0EA964 << 10) | g)` and the JSON-specific quirks have a `uint32_t` key
of `((0x116642 << 10) | j)`, for some small integers `g` and `j`. The high bits
are a namespace. The overall quirk keys are different even if `g` and `j`
re-use the same 10-bit integer.
@@ -76,8 +77,10 @@ Common quirks:
Package-specific quirks:
- [GIF image decoder quirks](/std/gif/decode_quirks.wuffs)
- [JPEG decoder quirks](/std/jpeg/decode_quirks.wuffs)
- [JSON decoder quirks](/std/json/decode_quirks.wuffs)
- [LZMA decoder quirks](/std/lzma/decode_quirks.wuffs)
- [LZW decoder quirks](/std/lzw/decode_quirks.wuffs)
- [TH decoder quirks](/std/thumbhash/decode_quirks.wuffs)
- [XZ decoder quirks](/std/xz/decode_quirks.wuffs)
- [ZLIB decoder quirks](/std/zlib/decode_quirks.wuffs)
+3 -3
View File
@@ -72,10 +72,10 @@ a simple token that provides the semantics for each `value_extension`.
- Bits `42 ..= 62` (21 bits) are the `value_major`.
- Bits `17 ..= 41` (25 bits) are the `value_minor`.
The `value_major` is a 21-bit [Base38](/doc/note/base38-and-fourcc.md) number.
The `value_major` is a 21-bit [base38](/doc/note/base38-and-fourcc.md) number.
For example, an HTML tokenizer might produce a combination of "base" tokens
(see below) and tokens whose `value_major` is `0x109B0B`, the Base38 encoding
of `html`. The `value_major` forms a namespace that distinguishes e.g.
(see below) and tokens whose `value_major` is `0x0FBEE8`, the base38 encoding
of `"html"`. The `value_major` forms a namespace that distinguishes e.g.
HTML-specific tokens from JSON-specific tokens.
If `value_major` is non-zero then `value_minor` has whatever meaning the
+3
View File
@@ -52,6 +52,7 @@ to enable.
- `CRC32: BASE`
- `CRC64: BASE`
- `DEFLATE: BASE`
- `ETC2: BASE`
- `GIF: BASE`
- `GZIP: BASE, CRC32, DEFLATE`
- `JPEG: BASE`
@@ -62,8 +63,10 @@ to enable.
- `NETPBM: BASE`
- `NIE: BASE`
- `PNG: BASE, ADLER32, CRC32, DEFLATE, ZLIB`
- `QOI: BASE`
- `SHA256: BASE`
- `TGA: BASE`
- `THUMBHASH: BASE`
- `VP8: BASE`
- `WBMP: BASE`
- `WEBP: BASE, VP8`
+5
View File
@@ -124,12 +124,15 @@ In Wuffs syntax, the `base.image_decoder` methods are:
## Implementations
- [std/bmp](/std/bmp)
- [std/etc2](/std/etc2)
- [std/gif](/std/gif)
- [std/jpeg](/std/jpeg)
- [std/netpbm](/std/netpbm)
- [std/nie](/std/nie)
- [std/png](/std/png)
- [std/qoi](/std/qoi)
- [std/tga](/std/tga)
- [std/thumbhash](/std/thumbhash)
- [std/wbmp](/std/wbmp)
- [std/webp](/std/webp)
@@ -155,6 +158,8 @@ Examples in other repositories:
## [Quirks](/doc/note/quirks.md)
- [GIF decoder quirks](/std/gif/decode_quirks.wuffs)
- [JPEG decoder quirks](/std/jpeg/decode_quirks.wuffs)
- [TH decoder quirks](/std/thumbhash/decode_quirks.wuffs)
## Related Documentation
+44 -7
View File
@@ -61,12 +61,15 @@ https://skia-review.googlesource.com/c/skia/+/290618
#define WUFFS_CONFIG__MODULE__BMP
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__ETC2
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TARGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
@@ -159,12 +162,15 @@ uint64_t g_num_printed_frames = 0;
wuffs_base__image_decoder* g_image_decoder = NULL;
union {
wuffs_bmp__decoder bmp;
wuffs_etc2__decoder etc2;
wuffs_gif__decoder gif;
wuffs_jpeg__decoder jpeg;
wuffs_netpbm__decoder netpbm;
wuffs_nie__decoder nie;
wuffs_png__decoder png;
wuffs_tga__decoder tga;
wuffs_qoi__decoder qoi;
wuffs_targa__decoder targa;
wuffs_thumbhash__decoder thumbhash;
wuffs_wbmp__decoder wbmp;
wuffs_webp__decoder webp;
} g_potential_decoders;
@@ -347,6 +353,16 @@ initialize_image_decoder() {
&g_potential_decoders.bmp);
return NULL;
case WUFFS_BASE__FOURCC__ETC2:
status = wuffs_etc2__decoder__initialize(
&g_potential_decoders.etc2, sizeof g_potential_decoders.etc2,
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
TRY(wuffs_base__status__message(&status));
g_image_decoder =
wuffs_etc2__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.etc2);
return NULL;
case WUFFS_BASE__FOURCC__GIF:
status = wuffs_gif__decoder__initialize(
&g_potential_decoders.gif, sizeof g_potential_decoders.gif,
@@ -397,14 +413,35 @@ initialize_image_decoder() {
&g_potential_decoders.png);
return NULL;
case WUFFS_BASE__FOURCC__TGA:
status = wuffs_tga__decoder__initialize(
&g_potential_decoders.tga, sizeof g_potential_decoders.tga,
case WUFFS_BASE__FOURCC__QOI:
status = wuffs_qoi__decoder__initialize(
&g_potential_decoders.qoi, sizeof g_potential_decoders.qoi,
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
TRY(wuffs_base__status__message(&status));
g_image_decoder =
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.tga);
wuffs_qoi__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.qoi);
return NULL;
case WUFFS_BASE__FOURCC__TGA:
status = wuffs_targa__decoder__initialize(
&g_potential_decoders.targa, sizeof g_potential_decoders.targa,
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
TRY(wuffs_base__status__message(&status));
g_image_decoder =
wuffs_targa__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.targa);
return NULL;
case WUFFS_BASE__FOURCC__TH:
status = wuffs_thumbhash__decoder__initialize(
&g_potential_decoders.thumbhash,
sizeof g_potential_decoders.thumbhash, WUFFS_VERSION,
WUFFS_INITIALIZE__DEFAULT_OPTIONS);
TRY(wuffs_base__status__message(&status));
g_image_decoder =
wuffs_thumbhash__decoder__upcast_as__wuffs_base__image_decoder(
&g_potential_decoders.thumbhash);
return NULL;
case WUFFS_BASE__FOURCC__WBMP:
+4 -1
View File
@@ -74,12 +74,15 @@ The Escape key quits.
#define WUFFS_CONFIG__MODULE__BMP
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__ETC2
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TARGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
+9
View File
@@ -508,7 +508,16 @@ class Callbacks : public wuffs_aux::DecodeJsonCallbacks {
m_stack.push_back(JsonValue(static_cast<JsonVector*>(nullptr)));
return "";
} else if (flags & WUFFS_BASE__TOKEN__VBD__STRUCTURE__TO_DICT) {
// Avoid a g++ -O3 -Wall -Werror "maybe uninitialized" false positive:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109448#c6
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
m_stack.push_back(JsonValue(static_cast<JsonMap*>(nullptr)));
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
return "";
}
return "main: internal error: bad push";
+4 -1
View File
@@ -72,12 +72,15 @@ isn't otherwise doing anything.
#define WUFFS_CONFIG__MODULE__BMP
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__ETC2
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TARGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
+1020
View File
@@ -0,0 +1,1020 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// ----------------
/*
stb-imagedumper decodes images, printing them (as ANSI color codes) to stdout.
It demonstrates using the STB Image API (e.g. stbi_load and stbi_image_free)
with either the actual STB Image implementation or Wuffs' reimplementation. By
default, it uses Wuffs' reimplementation. Define the USE_THE_REAL_STBI macro to
use the actual STB Image implementation instead: the stb_image.h file from
https://github.com/nothings/stb
The STB Image API is simple, covering the basic "decode this image data (as a
file, as bytes, etc) as RGB pixels" need. Wuffs also has its own API. Two, in
fact: a higher-level C++ one and a lower-level C one.
Wuffs' C++ API is also a one-shot "decode an image, synchronously" API but also
gives the caller access to metadata (e.g. EXIF orientation, color profiles),
more control over destination pixel formats (e.g. RGB versus BGR byte order,
premultiplied versus non-premultiplied alpha) and over memory allocators.
Wuffs' C API provides all of that (since the C++ API is implemented using the C
API) but also supports multi-shot streaming (asynchronous) I/O and animated
(not just still, single-frame) images.
See example/convert-to-nia and example/imageviewer in the Wuffs repository for
examples of using its C and C++ APIs.
Coming back to this program, if -demo is passed, it decodes four versions of
the same image of the Mona Lisa, in Thumbhash, PKM/ETC2, JPEG and PNG formats.
Only the last one is lossless.
As of September 2024, the actual STB Image implementation only decodes two out
of four: JPEG and PNG. Wuffs' reimplementation decodes all four demo images.
Define the USE_ONLY_JPEG macro to limit the variety of image file formats that
Wuffs decodes to just JPEG, for smaller binaries and faster compiles.
Pass the -a or -ascii-art flag to print ASCII art instead of ANSI color codes.
Pass the -b or -braille-art-light-mode (for black text on a white background)
or -B or -braille-art-dark-mode (for white text on a black background) flag to
print Unicode Braille Pattern characters instead of ANSI color codes. For
example:
----
$ stb-imagedumper -braille-art-light-mode test/data/pjw-thumbnail.png
test/data/pjw-thumbnail.png (208 bytes, 164 microseconds)
⠀⠀⠀⠀⢀⢴⣶⣶⣶⣦⣄⡀⠀⠀⠀⠀
⠀⠀⠀⢀⠈⠀⠀⠀⠹⣯⣿⣿⣷⣆⠀⠀
⠀⠀⣼⡇⢀⡀⠀⠀⠀⣙⣿⣿⣿⣿⡃⠀
⠀⢾⣿⢿⠔⠾⢞⠺⡿⣿⣿⣿⣿⣿⠂⠀
⠀⠈⢛⠅⠠⠔⣂⣀⣳⡮⣮⣿⣿⠉⠀⠀
⠀⠀⠸⡄⠠⠤⠤⠽⣿⡾⡾⣿⣿⠀⠀⠀
⠀⠀⠀⠀⠐⡂⠉⠛⣹⣷⣟⡓⠂⠀⠀⠀
⠀⠀⠀⠀⠈⢖⢽⣿⣿⣿⣿⠁⠀⠀⠀⠀
----
To run:
$CC stb-imagedumper.c && ./a.out *.{jpeg,png}; rm -f a.out
for a C compiler $CC, such as clang or gcc.
*/
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#if defined(USE_THE_REAL_STBI)
#define STBI_NO_HDR
#define STBI_NO_LINEAR
#define STB_IMAGE_IMPLEMENTATION
#include "/path/to/your/copy/of/github.com/nothings/stb/stb_image.h"
#else // defined(USE_THE_REAL_STBI)
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
// functions have static storage.
//
// This can help the compiler ignore or discard unused code, which can produce
// faster compiles and smaller binaries. Other motivations are discussed in the
// "ALLOW STATIC IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#define WUFFS_CONFIG__STATIC_FUNCTIONS
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__JPEG
#if !defined(USE_ONLY_JPEG)
#define WUFFS_CONFIG__MODULE__ADLER32
#define WUFFS_CONFIG__MODULE__BMP
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__ETC2
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TARGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
#define WUFFS_CONFIG__MODULE__ZLIB
#endif
// Defining the WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST (and the
// associated ETC__ALLOW_FOO) macros are optional, but can lead to smaller
// programs (in terms of binary size). By default (without these macros),
// Wuffs' standard library can decode images to a variety of pixel formats,
// such as BGR_565, BGRA_PREMUL or RGBA_NONPREMUL. The destination pixel format
// is selectable at runtime. Using these macros essentially makes the selection
// at compile time, by narrowing the list of supported destination pixel
// formats. The FOO in ETC__ALLOW_FOO should match the pixel format passed (as
// part of the wuffs_base__image_config argument) to the decode_frame method.
//
// If using the wuffs_aux C++ API, without overriding the SelectPixfmt method,
// the implicit destination pixel format is BGRA_PREMUL.
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGB
#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_NONPREMUL
// Defining this enables Wuffs' reimplementation of the STB library's API.
#define WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../release/c/wuffs-unsupported-snapshot.c"
#endif // defined(USE_THE_REAL_STBI)
// ----------------
#if defined(__unix__) || defined(__MACH__)
#include <sys/stat.h>
#include <time.h>
#define WUFFS_EXAMPLE_USE_TIMERS
uint64_t //
get_filesize(const char* filename) {
struct stat z;
if (stat(filename, &z) == 0) {
return z.st_size;
}
return 0;
}
bool g_started = false;
struct timespec g_start_time = {0};
int64_t //
micros_since_start(struct timespec* now) {
if (!g_started) {
return 0;
}
int64_t nanos = (int64_t)(now->tv_sec - g_start_time.tv_sec) * 1000000000 +
(int64_t)(now->tv_nsec - g_start_time.tv_nsec);
if (nanos < 0) {
return 0;
}
return nanos / 1000;
}
#else // defined(__unix__) || defined(__MACH__)
#warning "TODO: stat and timers on non-POSIX systems"
uint64_t //
get_filesize(const char* filename) {
return 0;
}
#endif // defined(__unix__) || defined(__MACH__)
// ----------------
const uint8_t g_src_ptr__mona_lisa_21_32_th[] = {
0xc3, 0xbe, 0xfe, 0xd1, 0x18, 0x0a, 0x1d, 0x02, 0x78, 0x95, 0x7f, 0x88,
0x87, 0x88, 0x87, 0x88, 0x77, 0x87, 0x47, 0x49, 0x7f, 0xa6, 0x02, 0x17,
};
const size_t g_src_len__mona_lisa_21_32_th = 24;
const uint8_t g_src_ptr__mona_lisa_21_32_etc2_pkm[] = {
0x50, 0x4b, 0x4d, 0x20, 0x32, 0x30, 0x00, 0x01, 0x00, 0x18, 0x00, 0x20,
0x00, 0x15, 0x00, 0x20, 0xb2, 0x74, 0x15, 0x32, 0x74, 0x8c, 0xb3, 0x18,
0xae, 0x70, 0x14, 0xaf, 0x70, 0x84, 0xf3, 0x58, 0xbb, 0xf2, 0x29, 0x92,
0x88, 0x80, 0x99, 0x1b, 0x63, 0x72, 0x42, 0x0b, 0x51, 0x19, 0x33, 0x2a,
0xac, 0x70, 0x15, 0x2f, 0x78, 0x9c, 0xf3, 0x18, 0xae, 0x72, 0x15, 0xaf,
0x72, 0x9c, 0xf3, 0xd9, 0x97, 0x97, 0x65, 0x09, 0x99, 0x9f, 0xe6, 0x09,
0x96, 0x94, 0x65, 0x4e, 0xe8, 0x08, 0xc3, 0x48, 0xb8, 0x96, 0x43, 0x70,
0x71, 0x99, 0x12, 0x23, 0x37, 0x27, 0x25, 0x6c, 0x8c, 0xe7, 0x2d, 0x11,
0x8a, 0x91, 0x60, 0x66, 0xf1, 0x0c, 0x0c, 0x08, 0x96, 0x9e, 0x60, 0x07,
0x99, 0x99, 0x22, 0x22, 0x42, 0x42, 0x31, 0x22, 0xcc, 0x8e, 0xd9, 0x19,
0x57, 0x54, 0x3e, 0x2a, 0xe2, 0x67, 0xd8, 0x80, 0xb7, 0x85, 0x42, 0x71,
0xfa, 0xa8, 0xa1, 0x69, 0x24, 0x14, 0x23, 0x08, 0x0f, 0xf0, 0x1e, 0x0b,
0x44, 0x06, 0xa2, 0xa2, 0xee, 0xef, 0x18, 0x96, 0x66, 0x6d, 0x56, 0x27,
0x22, 0x22, 0x33, 0x33, 0x53, 0x48, 0x3e, 0x27, 0x00, 0xdf, 0xd6, 0x01,
0x0c, 0x22, 0x76, 0x4b, 0x41, 0x5f, 0xc1, 0x46, 0x8d, 0x6b, 0x35, 0x85,
0x11, 0x17, 0x2a, 0xe9, 0x99, 0x05, 0x42, 0x93, 0x88, 0x8f, 0xa7, 0x91,
0x6f, 0x66, 0x46, 0x2f, 0x30, 0x9f, 0xc6, 0xdb, 0x63, 0x5a, 0x48, 0x07,
0x66, 0x66, 0xcc, 0xcc, 0x42, 0x15, 0xa9, 0x9a, 0xc0, 0x4f, 0x35, 0x36,
0xf3, 0x84, 0x42, 0x27, 0xcd, 0xfe, 0x22, 0x11, 0xb4, 0x93, 0x52, 0x85,
0xe2, 0x2a, 0xe1, 0x56, 0x15, 0x63, 0x32, 0x27, 0x32, 0xee, 0xdd, 0x1c,
0x25, 0x13, 0x23, 0x24, 0x0f, 0x0b, 0x3c, 0x04, 0x14, 0x64, 0x64, 0x43,
0xee, 0xee, 0x44, 0x44, 0x48, 0x3f, 0x30, 0x27, 0x7e, 0xe8, 0xb6, 0xd0,
0x33, 0x22, 0x28, 0x2f, 0x77, 0x44, 0x4c, 0x03, 0x36, 0x27, 0x28, 0x22,
0xfc, 0xcc, 0x89, 0x90, 0x05, 0x12, 0x21, 0x23, 0xf0, 0x20, 0x11, 0x10,
0x21, 0x19, 0x29, 0x02, 0x8c, 0xef, 0x38, 0xcb, 0x07, 0x34, 0x54, 0x43,
0x77, 0x77, 0x77, 0x77, 0x36, 0x27, 0x30, 0x43, 0xee, 0xf8, 0xd4, 0xcc,
0x5a, 0x37, 0x23, 0x6c, 0xc6, 0x2f, 0x93, 0x94, 0x96, 0x63, 0x32, 0x50,
0xb1, 0x98, 0x13, 0xbb, 0xa9, 0x15, 0x10, 0x92, 0xb9, 0x99, 0x57, 0x33,
0x27, 0x1f, 0x36, 0x03, 0x08, 0xdf, 0xd0, 0xab, 0x32, 0x28, 0x3f, 0x03,
0xee, 0xee, 0x00, 0x00, 0x8e, 0x90, 0x0d, 0x0f, 0x0e, 0x40, 0x81, 0x09,
0xb1, 0x15, 0x10, 0x92, 0xee, 0xef, 0xdc, 0xce, 0x34, 0x1e, 0x27, 0x23,
0xfe, 0x20, 0x62, 0x1c, 0x8a, 0x88, 0x07, 0x87, 0x06, 0x30, 0x40, 0x86,
0x0a, 0x01, 0x18, 0x02, 0xcc, 0xc4, 0x33, 0x10, 0x98, 0x9a, 0x0d, 0x9a,
0x1a, 0x58, 0x60, 0x47,
};
const size_t g_src_len__mona_lisa_21_32_etc2_pkm = 400;
const uint8_t g_src_ptr__mona_lisa_21_32_q50_jpeg[] = {
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43,
0x00, 0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e, 0x0d, 0x0e, 0x12,
0x11, 0x10, 0x13, 0x18, 0x28, 0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23,
0x25, 0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33, 0x38, 0x37, 0x40,
0x48, 0x5c, 0x4e, 0x40, 0x44, 0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51,
0x57, 0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71, 0x79, 0x70, 0x64,
0x78, 0x5c, 0x65, 0x67, 0x63, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x11, 0x12,
0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a, 0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42,
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
0x63, 0x63, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x00, 0x20, 0x00, 0x15, 0x03,
0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00,
0x1f, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0xff, 0xc4, 0x00, 0xb5, 0x10, 0x00,
0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00,
0x00, 0x01, 0x7d, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21,
0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81,
0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24,
0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25,
0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a,
0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a,
0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86,
0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3,
0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6,
0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1,
0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xc4, 0x00,
0x1f, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0xff, 0xc4, 0x00, 0xb5, 0x11, 0x00,
0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00,
0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31,
0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08,
0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15,
0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18,
0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39,
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55,
0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84,
0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa,
0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4,
0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xda, 0x00,
0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0x42,
0x96, 0xfe, 0x53, 0x49, 0xbd, 0x48, 0x51, 0xb8, 0x80, 0x6a, 0xac, 0xee,
0x2d, 0xaf, 0xe3, 0x82, 0x6f, 0x29, 0xa3, 0x90, 0x7c, 0xae, 0x99, 0xe0,
0xfa, 0x1a, 0xce, 0x90, 0x30, 0x80, 0x03, 0xb9, 0x9d, 0xbe, 0x55, 0xdb,
0xfd, 0xee, 0xd5, 0x6f, 0x5a, 0xb4, 0xbe, 0x4f, 0xb2, 0xdc, 0x5d, 0x10,
0x58, 0x7f, 0x02, 0x64, 0xe3, 0xb9, 0xae, 0x5b, 0x25, 0x24, 0xae, 0x68,
0xa1, 0xa3, 0xd0, 0xd3, 0xfb, 0x3c, 0x41, 0x41, 0xca, 0xe0, 0x8c, 0x83,
0xeb, 0x45, 0x66, 0x47, 0xe6, 0xbc, 0x6a, 0xc8, 0xec, 0xea, 0x47, 0x1b,
0x4e, 0x71, 0x45, 0x55, 0xbc, 0xc8, 0xb3, 0xec, 0x67, 0x4d, 0x33, 0x9f,
0x2d, 0xa2, 0x0e, 0x7c, 0xbe, 0x84, 0x73, 0xcf, 0xaf, 0x15, 0x1d, 0xe6,
0xa7, 0x3d, 0xd3, 0x22, 0xcf, 0x2b, 0xca, 0x8a, 0x30, 0x14, 0xb7, 0x15,
0x1d, 0x85, 0xf1, 0xb5, 0x9c, 0xca, 0x4b, 0x9e, 0x0e, 0x00, 0x38, 0xe6,
0x9b, 0x7b, 0x7e, 0x97, 0x12, 0x99, 0x3c, 0x84, 0xdc, 0x47, 0x27, 0x15,
0xb7, 0x2d, 0xa5, 0x6b, 0x1a, 0x37, 0x75, 0x7b, 0x96, 0x2c, 0x66, 0xdb,
0x11, 0x01, 0x88, 0xe7, 0xb1, 0xc5, 0x15, 0x46, 0x19, 0x80, 0x5e, 0x68,
0xab, 0x71, 0x42, 0x4d, 0x9f, 0xff, 0xd9,
};
const size_t g_src_len__mona_lisa_21_32_q50_jpeg = 799;
const uint8_t g_src_ptr__mona_lisa_21_32_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x20,
0x08, 0x02, 0x00, 0x00, 0x00, 0x72, 0xc2, 0xa4, 0xdf, 0x00, 0x00, 0x06,
0x07, 0x49, 0x44, 0x41, 0x54, 0x38, 0x11, 0x05, 0xc1, 0x49, 0x6f, 0x1c,
0xc7, 0x15, 0x00, 0xe0, 0xf7, 0x5e, 0x55, 0x75, 0x4f, 0xcf, 0xc6, 0x19,
0x92, 0xe2, 0x2a, 0x79, 0xd3, 0x62, 0x51, 0x4b, 0x64, 0x05, 0x50, 0x60,
0x04, 0xc9, 0xd5, 0xc8, 0x21, 0x08, 0x92, 0x8b, 0x91, 0x6b, 0x72, 0x09,
0xf2, 0x07, 0xfc, 0x7b, 0x72, 0xcf, 0x3d, 0x97, 0x9c, 0x02, 0x23, 0x80,
0x01, 0x5b, 0xb6, 0xe1, 0x48, 0x72, 0x44, 0x59, 0x1c, 0x6e, 0xe2, 0x32,
0xe4, 0xec, 0x3d, 0xdd, 0x5d, 0x5d, 0xf5, 0xde, 0xf3, 0xf7, 0xe1, 0x5f,
0xbf, 0xf8, 0xa3, 0xb0, 0x17, 0x40, 0x00, 0x46, 0xa2, 0x10, 0x02, 0x21,
0x00, 0x9a, 0x06, 0x29, 0xa3, 0x51, 0xb4, 0x51, 0x18, 0xd5, 0x8b, 0x88,
0x04, 0x8e, 0x40, 0x8a, 0x46, 0xc9, 0x91, 0x31, 0x84, 0xce, 0x88, 0xd8,
0x1b, 0x2d, 0x65, 0x21, 0x16, 0x01, 0xb4, 0x28, 0x50, 0x13, 0x01, 0xaa,
0xb5, 0x64, 0x38, 0xa8, 0x73, 0xe8, 0x5c, 0xac, 0x09, 0x94, 0xc8, 0x19,
0x08, 0x8c, 0x28, 0xa0, 0xa0, 0x36, 0x33, 0x04, 0xc6, 0xa0, 0xd4, 0x62,
0x93, 0x24, 0x51, 0xb0, 0x48, 0xa0, 0xe0, 0x48, 0x23, 0xb0, 0x63, 0x15,
0x4b, 0x60, 0x4c, 0xc6, 0x62, 0x35, 0x30, 0x35, 0x9c, 0xb8, 0x86, 0xa2,
0xd5, 0xba, 0x04, 0x11, 0x40, 0x8b, 0x2e, 0x23, 0x14, 0x82, 0xa0, 0x36,
0xb5, 0x69, 0x23, 0x23, 0x10, 0x03, 0x41, 0x15, 0x10, 0x53, 0x6b, 0x33,
0xe1, 0xd2, 0xd8, 0x74, 0xbc, 0x7f, 0x74, 0xf5, 0x6a, 0x70, 0x32, 0x44,
0xaf, 0x74, 0xeb, 0xc1, 0xd6, 0x83, 0xdf, 0xdc, 0xab, 0x84, 0x54, 0x8c,
0x49, 0xb3, 0x94, 0x82, 0x35, 0xc4, 0x62, 0x04, 0x9d, 0xf9, 0xec, 0xb3,
0x5f, 0x34, 0x5b, 0x59, 0x9a, 0x38, 0x4b, 0xd4, 0x6c, 0x24, 0x96, 0xb0,
0xd9, 0x6e, 0xe7, 0x97, 0xcb, 0x7e, 0x7e, 0xfe, 0xeb, 0x5f, 0x6d, 0x43,
0xf4, 0x2f, 0x5e, 0x2f, 0xbf, 0xfd, 0xfa, 0xaa, 0xd7, 0x6f, 0xdc, 0x7e,
0xfc, 0x3e, 0x28, 0x35, 0xb3, 0xb4, 0xd9, 0x30, 0xa8, 0x6a, 0x8c, 0x71,
0xd6, 0xda, 0x76, 0x27, 0x71, 0xce, 0x24, 0x49, 0x33, 0xb1, 0xa0, 0xa1,
0x0e, 0xac, 0xac, 0x6e, 0xf6, 0xe6, 0xf0, 0xf3, 0xcf, 0x1f, 0xf6, 0xd7,
0x3b, 0x6b, 0x6b, 0x66, 0x34, 0xf6, 0xd7, 0x73, 0xfc, 0xcf, 0xbf, 0x0f,
0xee, 0x3e, 0x7d, 0xaf, 0xdb, 0x6d, 0x38, 0x47, 0x8e, 0xb2, 0xd4, 0xa5,
0x12, 0x4a, 0x4a, 0x32, 0xb3, 0xf7, 0xe8, 0xfd, 0x32, 0x2f, 0x8c, 0x32,
0x87, 0x4a, 0xa0, 0xb1, 0xb1, 0xb9, 0x76, 0x35, 0x38, 0x3d, 0xfb, 0xe1,
0xf8, 0xc1, 0xc7, 0xbd, 0xf1, 0x28, 0x3f, 0x3f, 0x2f, 0x98, 0x75, 0xff,
0xa8, 0x1e, 0xcd, 0x95, 0xd2, 0x1a, 0x33, 0xeb, 0x05, 0x6e, 0xb4, 0xa9,
0x9d, 0x61, 0xe9, 0xe3, 0x68, 0x01, 0xf6, 0xf5, 0xcb, 0xd1, 0xce, 0x07,
0x2b, 0xf3, 0x69, 0xbe, 0x58, 0x94, 0x9d, 0x5e, 0x9b, 0xe8, 0xa3, 0xa3,
0xc1, 0x3c, 0x7a, 0x3a, 0x1e, 0x8c, 0x22, 0x87, 0xe9, 0x2c, 0xa4, 0xce,
0xb6, 0x1a, 0xce, 0x80, 0x0e, 0x87, 0x01, 0xdf, 0x95, 0xe6, 0xdc, 0xef,
0x76, 0x37, 0x7b, 0xad, 0xd4, 0xfb, 0x98, 0x97, 0xce, 0x66, 0x16, 0xc7,
0x93, 0x3a, 0x31, 0x75, 0xa8, 0x65, 0x34, 0x99, 0x5c, 0x9e, 0x7c, 0x33,
0x3d, 0x5c, 0x3c, 0x5e, 0xd3, 0xc7, 0x9f, 0xec, 0x1e, 0x1c, 0x4c, 0x9e,
0x3e, 0x69, 0xff, 0xf7, 0xab, 0xa3, 0x7c, 0x19, 0x8c, 0x33, 0x12, 0x38,
0x51, 0xf1, 0x62, 0x06, 0x43, 0x5f, 0x2c, 0xc3, 0x2c, 0xaf, 0x2b, 0x0f,
0x76, 0x3c, 0x2a, 0x9d, 0x8f, 0xad, 0x26, 0x20, 0x11, 0x2a, 0x2d, 0x72,
0x3f, 0x9b, 0x87, 0xb7, 0x8b, 0x78, 0x3a, 0xb8, 0x7a, 0xfd, 0xe3, 0xa4,
0xf6, 0xfe, 0xc7, 0x37, 0x0b, 0x56, 0x21, 0xe3, 0x16, 0x53, 0x7f, 0x79,
0xb6, 0xa0, 0x24, 0x7d, 0x51, 0xd6, 0x6f, 0x9b, 0xce, 0xcf, 0x7d, 0x62,
0x52, 0xaa, 0x4b, 0x6f, 0x85, 0x31, 0x88, 0x9f, 0x95, 0x75, 0x15, 0x6d,
0x6a, 0xd7, 0xd7, 0xd3, 0xb3, 0xcb, 0xfa, 0xdb, 0xff, 0x4d, 0xef, 0xdf,
0xeb, 0x1e, 0x1d, 0xcf, 0xce, 0x2e, 0xbc, 0x2a, 0xa2, 0x48, 0x42, 0xd8,
0x69, 0x52, 0x6a, 0xd5, 0xd7, 0x5a, 0x2e, 0x82, 0x32, 0x29, 0x83, 0xd9,
0xd9, 0xd8, 0x08, 0xec, 0xad, 0x4d, 0xc5, 0x38, 0x9b, 0xa5, 0xab, 0x9b,
0x7d, 0x27, 0x32, 0x39, 0x9e, 0xbc, 0x38, 0xac, 0x22, 0xcb, 0x0f, 0xaf,
0x66, 0xc3, 0x19, 0xb3, 0x4a, 0x5e, 0x2b, 0x26, 0xa6, 0xb7, 0xd3, 0xb1,
0x96, 0xb8, 0x8c, 0xbe, 0x8a, 0x49, 0x33, 0xb3, 0x48, 0xd6, 0x64, 0x4d,
0xdb, 0x36, 0x49, 0x3b, 0xcb, 0x1a, 0x40, 0xb6, 0x91, 0x3a, 0x57, 0x1a,
0xb4, 0x8d, 0xe4, 0x7a, 0x59, 0xcf, 0x4a, 0x79, 0xfa, 0x49, 0x3f, 0x04,
0x7f, 0x72, 0x9c, 0x7f, 0xf9, 0x7d, 0xcd, 0x55, 0x58, 0x8c, 0xe6, 0x2b,
0xab, 0xcd, 0x76, 0xcb, 0xde, 0xec, 0x42, 0x5e, 0x56, 0x00, 0xa9, 0xdd,
0xed, 0x58, 0xbf, 0xd2, 0x5d, 0xb5, 0x53, 0x3b, 0x1b, 0x5d, 0x4c, 0xe9,
0x5d, 0x21, 0xbe, 0x92, 0xb2, 0xd6, 0xdf, 0xfd, 0xb6, 0xf7, 0xa7, 0x3f,
0x7c, 0x98, 0xa5, 0x48, 0x0e, 0x9f, 0x7f, 0x35, 0xb8, 0xbe, 0x1c, 0x9f,
0xe4, 0x30, 0xda, 0x9f, 0xdd, 0x78, 0x86, 0x1f, 0xdf, 0xec, 0x64, 0xc8,
0xbe, 0x32, 0xbe, 0x62, 0x7b, 0x43, 0xf2, 0xea, 0x7a, 0xbc, 0xb1, 0x6d,
0x4c, 0xdf, 0xce, 0xe7, 0x15, 0x93, 0x5e, 0x8f, 0xe1, 0xe1, 0x8e, 0xfc,
0xfd, 0x2f, 0x7b, 0xab, 0x1b, 0xeb, 0x65, 0x51, 0x20, 0x41, 0x2b, 0x01,
0x90, 0x68, 0x10, 0xb7, 0x9b, 0x36, 0x8e, 0xca, 0xb5, 0x87, 0x5d, 0x01,
0x77, 0xcb, 0x25, 0x17, 0x17, 0x62, 0x9e, 0xdd, 0xd9, 0x46, 0x60, 0x61,
0xd3, 0xef, 0x63, 0x3b, 0x89, 0xfb, 0x87, 0x04, 0x91, 0xbf, 0xf8, 0xdb,
0xad, 0xbb, 0x8f, 0xde, 0x63, 0x4e, 0x4c, 0xd2, 0x50, 0x88, 0x83, 0xd7,
0xa7, 0xf3, 0xa5, 0x3c, 0x79, 0xd4, 0xce, 0x1a, 0xe6, 0xbb, 0x97, 0xe1,
0xf2, 0xb4, 0x6c, 0x52, 0xd2, 0xea, 0xb5, 0xb6, 0x37, 0xad, 0xd5, 0xda,
0x6c, 0xad, 0x10, 0x23, 0x69, 0xc9, 0xe7, 0x57, 0xe9, 0xe9, 0x28, 0x3e,
0xd8, 0xa5, 0x68, 0xd2, 0xe1, 0x75, 0xbe, 0xbe, 0xd1, 0x6a, 0x76, 0x56,
0xae, 0xcf, 0x97, 0xe3, 0x12, 0xa7, 0x9c, 0xbe, 0xfa, 0x2e, 0x1c, 0x0c,
0x63, 0x19, 0x5d, 0x71, 0x69, 0x5b, 0x21, 0xaf, 0x47, 0xb2, 0x71, 0x7b,
0xd5, 0x9e, 0x8d, 0xe1, 0xc3, 0x16, 0x74, 0xfb, 0x7c, 0x51, 0xe2, 0xd7,
0x6f, 0x92, 0x5e, 0x8f, 0xb2, 0x2e, 0xfd, 0xe3, 0x9f, 0x27, 0xb7, 0xdf,
0x1b, 0xed, 0x6e, 0x1f, 0x65, 0xad, 0xf4, 0xe0, 0xdd, 0xf4, 0x5f, 0x5f,
0x2e, 0x67, 0x85, 0x5d, 0xeb, 0x1b, 0xe7, 0x34, 0x88, 0xaa, 0xa1, 0x05,
0xa5, 0xb6, 0xe4, 0xb3, 0xd7, 0xde, 0x5e, 0x7a, 0x7b, 0x3c, 0x32, 0x1f,
0x28, 0x8f, 0xe6, 0xca, 0x64, 0x1d, 0xe2, 0xd5, 0x54, 0x00, 0x8d, 0x19,
0xeb, 0xc1, 0xd9, 0xb8, 0x60, 0x7d, 0x7b, 0x1e, 0x47, 0x73, 0xda, 0x58,
0xd1, 0x76, 0x2a, 0x77, 0xee, 0xd0, 0xe1, 0xb9, 0xbc, 0x5b, 0xf0, 0xa4,
0xe2, 0x1c, 0xdc, 0x52, 0x8c, 0xbd, 0xb3, 0x6b, 0x6e, 0xde, 0xee, 0xae,
0x74, 0xe0, 0xea, 0x9b, 0x52, 0x44, 0x03, 0x53, 0x5e, 0x19, 0x83, 0x72,
0x74, 0x16, 0x3a, 0x4d, 0xaa, 0x18, 0xf2, 0x82, 0x53, 0x87, 0x85, 0xd7,
0xb6, 0xd5, 0xd1, 0x54, 0x06, 0x57, 0xe8, 0x32, 0x43, 0xce, 0xe6, 0xe4,
0x3a, 0x4d, 0xb6, 0x11, 0xec, 0xfe, 0x69, 0x55, 0x56, 0xfc, 0xd3, 0x85,
0x6c, 0xf7, 0x60, 0x5e, 0x40, 0xe1, 0xd1, 0x10, 0x2a, 0x60, 0xea, 0x74,
0x96, 0xab, 0x08, 0x96, 0x51, 0xd6, 0xba, 0x34, 0xb8, 0x94, 0xeb, 0x89,
0x18, 0x24, 0x05, 0xac, 0x58, 0x4e, 0x66, 0xb2, 0x03, 0xc1, 0x86, 0x10,
0x4f, 0xa6, 0x3c, 0xc9, 0x35, 0x35, 0xe0, 0x90, 0x1b, 0xe8, 0xf3, 0xa0,
0x8c, 0x94, 0xa5, 0xea, 0x6b, 0x98, 0x2e, 0x04, 0x11, 0x91, 0x70, 0x5e,
0x70, 0x59, 0xe8, 0x9a, 0xc3, 0x5a, 0x58, 0x39, 0xb2, 0xb8, 0x2a, 0x00,
0x0b, 0xd9, 0x58, 0x87, 0xe9, 0x42, 0x33, 0x88, 0x1d, 0xa8, 0xeb, 0x4a,
0xa6, 0x0b, 0x98, 0xcc, 0x85, 0x8c, 0x36, 0x52, 0xf2, 0x15, 0x0a, 0x43,
0x50, 0x55, 0xc5, 0xdc, 0x63, 0x8a, 0x6a, 0x55, 0x94, 0xa0, 0x08, 0x5c,
0x87, 0x98, 0x18, 0x63, 0x0d, 0xda, 0x45, 0x45, 0x8b, 0x4a, 0xb7, 0xfb,
0x72, 0x6f, 0x1b, 0x4a, 0x8f, 0x5b, 0xeb, 0x76, 0xeb, 0x56, 0x77, 0x38,
0x2c, 0x9e, 0xff, 0xdf, 0x0f, 0xa7, 0x62, 0x13, 0x52, 0x23, 0x75, 0x10,
0x44, 0x32, 0x84, 0x8c, 0x5a, 0x47, 0x09, 0x06, 0x92, 0x08, 0x45, 0x25,
0x27, 0x73, 0x35, 0x3b, 0x6b, 0xb7, 0x96, 0x5e, 0x9d, 0x91, 0xcc, 0xc0,
0x64, 0xae, 0x9f, 0xfe, 0xb2, 0xfb, 0xe7, 0xdf, 0x6f, 0x3c, 0xb9, 0x9b,
0x3d, 0xbb, 0xdf, 0x68, 0x3b, 0x38, 0xbe, 0xe6, 0xeb, 0x05, 0x14, 0x35,
0x20, 0x62, 0x60, 0x70, 0x68, 0x04, 0x89, 0x92, 0x46, 0xea, 0xac, 0x25,
0x72, 0xce, 0x9a, 0xdd, 0xde, 0xd6, 0x24, 0xf7, 0xe3, 0x5c, 0xe6, 0x39,
0x2f, 0x02, 0x0e, 0x47, 0x61, 0x7e, 0x5d, 0x34, 0x13, 0x59, 0x69, 0xd3,
0xfd, 0x9b, 0xb4, 0xb7, 0x85, 0x75, 0x55, 0xde, 0x5e, 0x0f, 0xf7, 0x56,
0xfc, 0xde, 0x5a, 0xf4, 0xb5, 0x8c, 0x2b, 0x5a, 0xed, 0xb7, 0x99, 0x95,
0x01, 0x53, 0x14, 0xd3, 0x6b, 0x6d, 0xe6, 0x55, 0x14, 0xd0, 0x85, 0x97,
0xa2, 0x96, 0x4f, 0xf7, 0xd2, 0xbd, 0xbb, 0xd9, 0xf0, 0xac, 0x88, 0x3e,
0x8e, 0xe7, 0x7c, 0x79, 0x5e, 0x6e, 0x18, 0xee, 0x18, 0xdf, 0xa6, 0xa8,
0x41, 0xad, 0xe8, 0x55, 0x09, 0x93, 0xa2, 0x06, 0x44, 0x50, 0x5d, 0x4f,
0xc5, 0x8e, 0x8b, 0x88, 0xc0, 0x99, 0x51, 0x2f, 0x7a, 0xa3, 0x09, 0x1f,
0xf5, 0x65, 0x25, 0xd3, 0xa3, 0x49, 0xdc, 0x1f, 0x94, 0x9b, 0xab, 0x26,
0x9f, 0xc7, 0xa3, 0xf3, 0x38, 0x18, 0x01, 0x1a, 0x1b, 0x19, 0x0a, 0x0f,
0x55, 0x88, 0x35, 0xa8, 0x33, 0x98, 0x99, 0x34, 0x25, 0xb0, 0xc8, 0x8c,
0xa0, 0x55, 0x10, 0x54, 0x2d, 0x6a, 0x7a, 0x79, 0x50, 0x5f, 0x4d, 0xea,
0xe7, 0x6f, 0x42, 0x14, 0xfd, 0xe9, 0x2c, 0x2e, 0x4b, 0x5e, 0x78, 0xbd,
0xcc, 0xb1, 0x12, 0x04, 0x04, 0x15, 0xf1, 0x2c, 0x89, 0xa1, 0x44, 0x99,
0x62, 0x18, 0x2f, 0xd1, 0x12, 0x6a, 0x64, 0x11, 0x95, 0xc4, 0xc0, 0xa2,
0x8a, 0xdf, 0x0f, 0x20, 0x39, 0x94, 0xa9, 0xd7, 0x66, 0xd3, 0x84, 0x52,
0xa7, 0xb9, 0x44, 0x01, 0x2f, 0xe0, 0x59, 0x22, 0x00, 0x01, 0x08, 0xa8,
0x57, 0xed, 0x82, 0x54, 0x21, 0x90, 0x31, 0x36, 0x44, 0xae, 0x63, 0x34,
0x04, 0x15, 0x6b, 0x93, 0x74, 0x54, 0x40, 0x1d, 0xc5, 0x22, 0x94, 0x75,
0x5c, 0x44, 0x28, 0x45, 0x83, 0xaa, 0x45, 0x15, 0x55, 0x51, 0x00, 0x50,
0x05, 0x60, 0x0e, 0x55, 0xcd, 0x0a, 0x84, 0x8a, 0x96, 0x05, 0x51, 0x91,
0x05, 0x53, 0x03, 0x68, 0xa0, 0x0c, 0x2a, 0x0a, 0x0d, 0x02, 0x05, 0x42,
0x54, 0x4b, 0x8a, 0xa0, 0x09, 0x68, 0x00, 0xf5, 0x0c, 0x04, 0x02, 0x00,
0x51, 0xa1, 0x62, 0x35, 0x08, 0x15, 0xc3, 0xcf, 0x54, 0x8f, 0x0d, 0x07,
0x3c, 0xd1, 0x0f, 0x66, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,
0xae, 0x42, 0x60, 0x82,
};
const size_t g_src_len__mona_lisa_21_32_png = 1600;
// ----------------
// g_braille holds the Unicode Code Point bit masks for the 8 dots in a Unicode
// Braille Pattern character (a character in U+2800 ..= U+28FF).
const uint8_t g_braille[4][2] = {
{0x01, 0x08},
{0x02, 0x10},
{0x04, 0x20},
{0x40, 0x80},
};
// g_noise is a 32×32 blue noise texture, based on "LDR_LLL1_42.png" (but
// tweaked so that the values range in 0x00 ..= 0xfe) from the zip file linked
// to from http://momentsingraphics.de/BlueNoise.html (the files within are
// mirrored at https://github.com/Calinou/free-blue-noise-textures) and whose
// LICENSE.txt says "To the extent possible under law, Christoph Peters has
// waived all copyright and related or neighboring rights".
const uint8_t g_noise[32][32] = {
{0x3c, 0xd4, 0xb6, 0x77, 0x64, 0xab, 0xef, 0x03, 0x7d, 0x2f, 0xc0,
0x24, 0x79, 0x3e, 0x87, 0x9a, 0x36, 0x7f, 0xbc, 0xf0, 0x42, 0xaf,
0x2d, 0x63, 0x22, 0xc3, 0x4e, 0x33, 0xe9, 0x67, 0x9c, 0x01},
{0xa9, 0x23, 0x50, 0xdd, 0x36, 0x26, 0x4b, 0x94, 0xdc, 0x14, 0xfb,
0x47, 0x5f, 0xf2, 0x13, 0x53, 0xe7, 0xd7, 0x28, 0x8a, 0x07, 0xc6,
0x54, 0xe5, 0xb5, 0x0e, 0x78, 0xae, 0x14, 0x84, 0xc0, 0x20},
{0x7d, 0x95, 0xea, 0x06, 0x8a, 0xfa, 0xc3, 0x70, 0x5c, 0xa6, 0x88,
0xcc, 0x09, 0xba, 0xa6, 0x68, 0x1e, 0xb3, 0x5a, 0xa5, 0x68, 0xfd,
0x18, 0x90, 0x70, 0x3a, 0xf0, 0x5f, 0xca, 0x44, 0x2b, 0x58},
{0x12, 0xbd, 0x43, 0x61, 0xb0, 0x9d, 0x0e, 0x3f, 0xec, 0xb6, 0x36,
0x6e, 0x94, 0xde, 0x2f, 0xce, 0x77, 0x92, 0x11, 0xe2, 0x37, 0x81,
0xa0, 0x46, 0xcd, 0xdf, 0xa3, 0x05, 0x97, 0xdc, 0x73, 0xe4},
{0x35, 0x6d, 0xf2, 0xc7, 0x1d, 0x56, 0x7b, 0xce, 0x2a, 0x17, 0x54,
0xe9, 0x21, 0x7e, 0x4e, 0xeb, 0x3b, 0xf9, 0x47, 0xca, 0x75, 0xb9,
0xd9, 0x0b, 0x5a, 0x27, 0x8a, 0x4d, 0xf5, 0x1f, 0xb7, 0x8e},
{0xd0, 0xa4, 0x28, 0x81, 0xd9, 0x32, 0xe4, 0xa3, 0x8f, 0x65, 0xd8,
0x9b, 0x42, 0xb2, 0x04, 0x8b, 0x19, 0xbe, 0x9b, 0x00, 0x51, 0x22,
0x31, 0xf6, 0x7c, 0xbf, 0x1a, 0x6c, 0xb0, 0x3c, 0x63, 0x0a},
{0xf9, 0x53, 0x15, 0x93, 0x67, 0xb8, 0x4b, 0x01, 0xf4, 0x82, 0xbe,
0x11, 0xfd, 0x61, 0xc4, 0xa4, 0x57, 0x6d, 0x2c, 0xdd, 0xed, 0xb1,
0x92, 0x63, 0xa8, 0xe2, 0x35, 0xc8, 0x7f, 0xd5, 0x9d, 0x49},
{0x85, 0xae, 0xe2, 0x41, 0x0c, 0xfe, 0x76, 0xc5, 0x20, 0x45, 0xac,
0x30, 0xcb, 0x73, 0x24, 0xef, 0xda, 0x80, 0xab, 0x5e, 0x89, 0x6e,
0xd2, 0x16, 0x40, 0x98, 0x52, 0xfb, 0x10, 0x2c, 0xe8, 0xc3},
{0x04, 0x60, 0x73, 0xca, 0x9a, 0xa8, 0x59, 0x38, 0xdd, 0x5e, 0x70,
0x0a, 0x51, 0x84, 0x98, 0x34, 0x44, 0x0f, 0xf6, 0x1b, 0x38, 0x49,
0x08, 0xbb, 0xea, 0x72, 0x03, 0xaa, 0x8d, 0x59, 0x77, 0x20},
{0x39, 0xd8, 0x2f, 0xee, 0x1c, 0x2b, 0x87, 0xb3, 0x95, 0xed, 0xd1,
0xa2, 0xf6, 0xe1, 0x16, 0xd2, 0x69, 0xb7, 0xcd, 0x94, 0xc5, 0xa3,
0xfd, 0x58, 0x86, 0x25, 0xda, 0x65, 0xee, 0x42, 0xba, 0x97},
{0xf4, 0xb4, 0x8c, 0x48, 0xbf, 0x6d, 0xe7, 0x08, 0x19, 0x7c, 0x29,
0x8e, 0x3b, 0xb9, 0x4a, 0xa7, 0x8b, 0x07, 0x55, 0x74, 0x25, 0xe0,
0x7c, 0x30, 0xcd, 0xb5, 0x3a, 0xc4, 0xa2, 0x18, 0xce, 0x69},
{0x11, 0xa1, 0x5a, 0x06, 0x7e, 0xda, 0x4f, 0xc9, 0x42, 0xbb, 0x56,
0x1d, 0x6a, 0x02, 0x7a, 0x59, 0xfc, 0x2d, 0xe6, 0x3f, 0xb0, 0x13,
0x9a, 0x6a, 0x1b, 0x90, 0x4c, 0x0b, 0x81, 0x29, 0xe0, 0x4e},
{0x79, 0x23, 0xd4, 0xf8, 0xac, 0x36, 0x9b, 0xfb, 0x67, 0xa7, 0xf0,
0xdb, 0xad, 0xc6, 0xea, 0x21, 0xc0, 0x9e, 0x83, 0xd5, 0x62, 0x50,
0xec, 0x43, 0xaa, 0xf7, 0xe3, 0x73, 0x57, 0x5f, 0xad, 0x89},
{0xe9, 0xbc, 0x3e, 0x6a, 0x15, 0x60, 0x23, 0x8d, 0x13, 0x33, 0x85,
0x48, 0x99, 0x30, 0x62, 0xd9, 0x3b, 0x6d, 0x18, 0xf3, 0x8f, 0x01,
0xbe, 0xda, 0x0d, 0x5f, 0x9f, 0x31, 0xc6, 0x93, 0x02, 0x34},
{0xc9, 0x52, 0x98, 0x85, 0xcf, 0xec, 0xb5, 0x76, 0xd3, 0xc2, 0x09,
0x71, 0xf8, 0x14, 0x82, 0x92, 0x0c, 0xaa, 0x4a, 0xb8, 0x32, 0xca,
0x71, 0x88, 0x2b, 0x7d, 0xd2, 0x1f, 0xb0, 0x63, 0x44, 0x6f},
{0x19, 0xdf, 0x09, 0x2d, 0xa5, 0x45, 0x00, 0xe1, 0x4d, 0x5d, 0xe5,
0x24, 0xcc, 0x41, 0xb6, 0x4f, 0xf5, 0xd1, 0x5d, 0x7b, 0x22, 0xa1,
0x3d, 0xf1, 0x54, 0xbc, 0x46, 0xf4, 0x12, 0xd6, 0xee, 0x9e},
{0x5d, 0xb2, 0x76, 0xf4, 0xbf, 0x58, 0x95, 0x2a, 0x81, 0xa0, 0xb2,
0x8f, 0x57, 0xa5, 0xde, 0x75, 0x2a, 0xc2, 0x06, 0xe0, 0xfe, 0x67,
0x15, 0xb1, 0x96, 0x06, 0x6c, 0x8a, 0x3a, 0x78, 0xb9, 0x27},
{0xfa, 0x47, 0x91, 0x1c, 0x37, 0x6f, 0xc8, 0xf1, 0x3d, 0x1a, 0x9f,
0x38, 0x6b, 0x03, 0xee, 0x1c, 0x9c, 0x89, 0x39, 0xa8, 0x93, 0x46,
0xd5, 0xe3, 0x25, 0xc8, 0xa7, 0xe8, 0x99, 0x55, 0x08, 0x88},
{0x33, 0xd1, 0x64, 0xe7, 0x83, 0xd7, 0x0e, 0xac, 0x69, 0xbd, 0x0c,
0xd7, 0x7f, 0x2e, 0xbd, 0x5e, 0x45, 0x6e, 0xe8, 0x54, 0x0f, 0x83,
0x5a, 0x75, 0x34, 0xf8, 0x5c, 0x1a, 0x2c, 0xcc, 0xe3, 0xa9},
{0x0d, 0xc4, 0xa0, 0x12, 0xb7, 0x4c, 0x23, 0x8c, 0xde, 0x78, 0x48,
0x97, 0xeb, 0xaf, 0x8b, 0xcd, 0xfb, 0x17, 0xc7, 0x2e, 0xd0, 0xad,
0xc0, 0x09, 0x8e, 0x4d, 0x80, 0xdd, 0xbe, 0x66, 0x40, 0x7d},
{0x52, 0x71, 0x26, 0x3f, 0xfc, 0xa7, 0x62, 0xf5, 0x55, 0x2c, 0xd1,
0x61, 0x20, 0x4f, 0x3d, 0x0d, 0xa2, 0x7a, 0xb3, 0x64, 0xef, 0x20,
0x3f, 0xea, 0x9c, 0xb7, 0x3d, 0x04, 0x74, 0xa3, 0x1f, 0xf1},
{0xb1, 0x89, 0xdc, 0x5b, 0x95, 0x7a, 0x31, 0x03, 0x9e, 0xb4, 0x10,
0xc1, 0xa4, 0x74, 0xe4, 0xd9, 0x27, 0x4d, 0x8f, 0x02, 0x99, 0x7e,
0x6b, 0xd7, 0x14, 0x65, 0xcf, 0xac, 0xfe, 0x4b, 0x94, 0xd6},
{0x01, 0x30, 0xeb, 0xbb, 0x0c, 0xd3, 0xc1, 0xe5, 0x43, 0x84, 0xed,
0x37, 0xf9, 0x05, 0x85, 0x68, 0xb8, 0xf3, 0x3e, 0xde, 0x34, 0xfa,
0x4f, 0xa5, 0x2e, 0xf1, 0x22, 0x8b, 0x32, 0x13, 0xc1, 0x61},
{0xf7, 0x9d, 0x49, 0x6c, 0x1d, 0x3c, 0x90, 0x70, 0xcb, 0x17, 0x68,
0x91, 0x56, 0xc7, 0x2f, 0x9b, 0x5b, 0x10, 0xc2, 0x72, 0x5d, 0xbc,
0x0b, 0x87, 0xc5, 0x78, 0x51, 0xe0, 0x5c, 0xe9, 0x83, 0x3b},
{0x77, 0x17, 0xc8, 0xad, 0x86, 0xf2, 0x58, 0x26, 0xa6, 0x4c, 0x7c,
0xdf, 0x1b, 0xb2, 0x46, 0xd4, 0x1e, 0x80, 0xcf, 0x9f, 0x1a, 0xab,
0x26, 0xe7, 0x43, 0x97, 0x0f, 0xbb, 0x6f, 0xa0, 0x24, 0xcf},
{0x66, 0x91, 0xe3, 0x29, 0x50, 0xdb, 0xb6, 0x12, 0xfe, 0xd5, 0xb8,
0x29, 0xa1, 0x72, 0xe6, 0x8c, 0xfc, 0xae, 0x2d, 0x47, 0xe2, 0x8d,
0xd3, 0x6e, 0x5f, 0xf7, 0xa9, 0x3e, 0xcc, 0x0b, 0xae, 0x55},
{0xba, 0x08, 0x38, 0x7e, 0xa1, 0x05, 0x66, 0x9a, 0x35, 0x60, 0x00,
0x41, 0xf3, 0x62, 0x0a, 0x39, 0x53, 0x6c, 0x04, 0xef, 0x79, 0x39,
0x4e, 0xb3, 0x00, 0x1f, 0xd6, 0x7f, 0x2a, 0x4b, 0xfc, 0xd8},
{0x44, 0xed, 0x60, 0xd0, 0xf9, 0x45, 0xc6, 0x79, 0x88, 0xe8, 0xc2,
0x96, 0x82, 0xcb, 0x15, 0xa4, 0xbf, 0xd8, 0x96, 0x59, 0xc7, 0x11,
0xfd, 0x99, 0xc4, 0x37, 0x8e, 0x65, 0xf0, 0x96, 0x87, 0x1d},
{0xa8, 0x98, 0x21, 0xaf, 0x72, 0x16, 0xdf, 0x28, 0x4c, 0xa9, 0x1e,
0x56, 0x32, 0xb4, 0xec, 0x7b, 0x25, 0x41, 0x86, 0xb5, 0x21, 0x69,
0x84, 0x28, 0xeb, 0x76, 0xe1, 0x53, 0x05, 0xc5, 0x35, 0x71},
{0xdc, 0x80, 0xc1, 0x57, 0x31, 0x90, 0xb9, 0xf5, 0x0e, 0xce, 0x75,
0xf8, 0xdb, 0x49, 0x91, 0x5b, 0xe1, 0x10, 0xf6, 0x33, 0xe6, 0xa6,
0xbd, 0x5c, 0x48, 0xaa, 0x16, 0xba, 0xa2, 0xe4, 0x5e, 0x0f},
{0x2e, 0x4a, 0xf7, 0x0a, 0xe6, 0x40, 0x5b, 0x9c, 0x6a, 0x3a, 0x8d,
0x07, 0x66, 0x19, 0x2b, 0x6f, 0xab, 0xc9, 0x9d, 0x74, 0x50, 0x0d,
0xdb, 0x3c, 0x07, 0xd0, 0x6b, 0x27, 0x40, 0x7a, 0xb1, 0xf2},
{0x8c, 0x6b, 0x18, 0x9f, 0xcb, 0x82, 0x1e, 0xd3, 0xb4, 0x52, 0xe5,
0x9f, 0xaf, 0xd4, 0xc3, 0xde, 0x02, 0x4a, 0x64, 0x1b, 0xd2, 0x93,
0x7b, 0xf3, 0x9e, 0x86, 0xfa, 0x92, 0xd6, 0x1c, 0x51, 0xc9},
};
// ----------------
struct {
int remaining_argc;
char** remaining_argv;
bool ascii_art;
bool braille_art_dark_mode;
bool braille_art_light_mode;
bool demo;
int resize;
} g_flags = {0};
static const char* g_usage =
"Usage: stb-imagedumper *.{jpeg,png}\n"
"\n"
"Flags:\n"
" -a or -ascii-art (use ASCII art instead of ANSI color codes)\n"
" -B or -braille-art-dark-mode (use white-on-black Braille art)\n"
" -b or -braille-art-light-mode (use black-on-white Braille art)\n"
" -demo (dump the built-in demonstration images)\n"
" -r or -resize=N (resize to fit in N×N, N≤1024; -r means N=64)\n";
const char* //
parse_flags(int argc, char** argv) {
int c = (argc > 0) ? 1 : 0; // Skip argv[0], the program name.
for (; c < argc; c++) {
char* arg = argv[c];
if (*arg++ != '-') {
break;
}
// A double-dash "--foo" is equivalent to a single-dash "-foo". As special
// cases, a bare "-" is not a flag (some programs may interpret it as
// stdin) and a bare "--" means to stop parsing flags.
if (*arg == '\x00') {
break;
} else if (*arg == '-') {
arg++;
if (*arg == '\x00') {
c++;
break;
}
}
if (!strcmp(arg, "a") || !strcmp(arg, "ascii-art")) {
g_flags.ascii_art = true;
continue;
}
if (!strcmp(arg, "B") || !strcmp(arg, "braille-art-dark-mode")) {
g_flags.braille_art_dark_mode = true;
continue;
}
if (!strcmp(arg, "b") || !strcmp(arg, "braille-art-light-mode")) {
g_flags.braille_art_light_mode = true;
continue;
}
if (!strcmp(arg, "demo")) {
g_flags.demo = true;
continue;
}
if (!strcmp(arg, "r")) {
g_flags.resize = 64;
continue;
}
if (!strncmp(arg, "resize=", 7)) {
while (*arg++ != '=') {
}
g_flags.resize = atoi(arg);
if ((g_flags.resize <= 0) || (1024 < g_flags.resize)) {
return g_usage;
}
continue;
}
return g_usage;
}
g_flags.remaining_argc = argc - c;
g_flags.remaining_argv = argv + c;
return NULL;
}
// ----------------
static int //
intmax(int a, int b) {
return (a < b) ? b : a;
}
static uint64_t //
u64min(uint64_t a, uint64_t b) {
return (a < b) ? a : b;
}
static bool //
resize_wh(int* inout_w, int* inout_h, int dst_wh) {
// Check arguments.
if (!inout_w || !inout_h || (dst_wh <= 0) || (0x4000 < dst_wh) || //
(*inout_w <= 0) || (0xffffff < *inout_w) || //
(*inout_h <= 0) || (0xffffff < *inout_h)) {
printf("main: resize failed: invalid argument\n");
return false;
}
// Compute dst width × height from src width × height.
uint64_t dw = 0;
uint64_t dh = 0;
uint64_t sw = (uint64_t)(*inout_w);
uint64_t sh = (uint64_t)(*inout_h);
if (sw < sh) {
dw = intmax(1, (int)(((sw * dst_wh * 2) + sh) / (2 * sh)));
dh = dst_wh;
} else {
dw = dst_wh;
dh = intmax(1, (int)(((sh * dst_wh * 2) + sw) / (2 * sw)));
}
// Return width and height.
*inout_w = (int)dw;
*inout_h = (int)dh;
return true;
}
static unsigned char* //
resize(int* inout_w,
int* inout_h,
unsigned char* src_pixels,
int dst_wh,
int bytes_per_pixel) {
// Check arguments.
if (!inout_w || !inout_h || (dst_wh <= 0) || (0x4000 < dst_wh) || //
(*inout_w <= 0) || (0xffffff < *inout_w) || //
(*inout_h <= 0) || (0xffffff < *inout_h) || //
((bytes_per_pixel != 1) && (bytes_per_pixel != 3))) {
printf("main: resize failed: invalid argument\n");
return NULL;
}
// Compute dst width × height from src width × height.
uint64_t dw = 0;
uint64_t dh = 0;
uint64_t sw = (uint64_t)(*inout_w);
uint64_t sh = (uint64_t)(*inout_h);
if (sw < sh) {
dw = intmax(1, (int)(((sw * dst_wh * 2) + sh) / (2 * sh)));
dh = dst_wh;
} else {
dw = dst_wh;
dh = intmax(1, (int)(((sh * dst_wh * 2) + sw) / (2 * sw)));
}
// Allocate the dst pixel buffer.
unsigned char* dst_pixels =
malloc((size_t)dw * (size_t)dh * (size_t)bytes_per_pixel);
if (!dst_pixels) {
printf("main: resize failed: out of memory\n");
return NULL;
}
// For every dst pixel, accumulate the weighted sum of the corresponding
// source pixels. It's a basic box filter (scaling (sw×sh) explicit src
// pixels up to ((sw*dw)×(sh*dh)) implicit tmp pixels down to (dw×dh)
// explicit dst pixels) and the implementation is very slow (no SIMD and lots
// of branches and uint64_t divisions) but also very simple (for an image
// resizing algorithm).
unsigned char* dst = dst_pixels;
for (uint64_t dy = 0; dy < dh; dy++) {
for (uint64_t dx = 0; dx < dw; dx++) {
uint64_t tot0 = 0;
uint64_t tot1 = 0;
uint64_t tot2 = 0;
uint64_t totw = 0;
uint64_t ty = dy * sh;
int sy = (int)(ty / dh);
for (uint64_t ty_end = (dy + 1) * sh; ty < ty_end; sy++) {
uint64_t weighty = u64min(ty_end - ty, dh - (ty % dh));
ty += weighty;
uint64_t tx = dx * sw;
int sx = (int)(tx / dw);
for (uint64_t tx_end = (dx + 1) * sw; tx < tx_end; sx++) {
uint64_t weightx = u64min(tx_end - tx, dw - (tx % dw));
tx += weightx;
uint64_t weight = weightx * weighty;
totw += weight;
if (bytes_per_pixel == 1) {
size_t i = (((size_t)sy * (size_t)sw) + (size_t)sx) * 1;
tot0 += weight * src_pixels[i + 0];
} else {
size_t i = (((size_t)sy * (size_t)sw) + (size_t)sx) * 3;
tot0 += weight * src_pixels[i + 0];
tot1 += weight * src_pixels[i + 1];
tot2 += weight * src_pixels[i + 2];
}
}
}
if (bytes_per_pixel == 1) {
*dst++ = (unsigned char)(((tot0 * 2) + totw) / (totw * 2));
} else {
*dst++ = (unsigned char)(((tot0 * 2) + totw) / (totw * 2));
*dst++ = (unsigned char)(((tot1 * 2) + totw) / (totw * 2));
*dst++ = (unsigned char)(((tot2 * 2) + totw) / (totw * 2));
}
}
}
// Return width, height and pixel buffer.
*inout_w = (int)dw;
*inout_h = (int)dh;
return dst_pixels;
}
// ----------------
#define MAX_INCL_DIMENSION 10000
// BYTES_PER_COLOR_OUTPUT_CHARACTER is long enough to contain
// "\x1B[38;2;255;255;255m\x1B[48;2;255;255;255mABC" plus a trailing NUL byte.
// It starts with a true color terminal escape code. ABC is three bytes for the
// UTF-8 representation "\xE2\x96\x80" of "▀", U+2580 UPPER HALF BLOCK.
#define BYTES_PER_COLOR_OUTPUT_CHARACTER 42
static void //
handle(const char* filename,
uint64_t filesize,
const uint8_t* src_ptr,
const size_t src_len) {
int src_w = 0;
int src_h = 0;
int channels_in_file = 0;
int bytes_per_pixel = (g_flags.ascii_art || g_flags.braille_art_dark_mode ||
g_flags.braille_art_light_mode)
? STBI_grey // 1.
: STBI_rgb; // 3.
unsigned char* src_pixels = NULL;
#if defined(WUFFS_EXAMPLE_USE_TIMERS)
g_started = true;
clock_gettime(CLOCK_MONOTONIC, &g_start_time);
#endif
if (src_len > 0) {
src_pixels = stbi_load_from_memory(src_ptr, src_len, //
&src_w, &src_h, &channels_in_file,
bytes_per_pixel);
} else {
src_pixels = stbi_load(filename, //
&src_w, &src_h, &channels_in_file, bytes_per_pixel);
}
int64_t elapsed_micros = 0;
#if defined(WUFFS_EXAMPLE_USE_TIMERS)
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
elapsed_micros = micros_since_start(&now);
#endif
char resize_info_string[64];
resize_info_string[0] = 0;
if (g_flags.resize > 0) {
int resize_w = src_w;
int resize_h = src_h;
if (!resize_wh(&resize_w, &resize_h, g_flags.resize)) {
stbi_image_free(src_pixels);
return;
}
snprintf(resize_info_string, sizeof(resize_info_string), " → %d×%d",
resize_w, resize_h);
}
printf("\n%s (%" PRIu64 " bytes, %d×%d%s pixels, %" PRIi64 " microseconds)\n",
filename, filesize, src_w, src_h, resize_info_string, elapsed_micros);
if (!src_pixels) {
printf("%s\n", stbi_failure_reason());
return;
} else if ((src_w < 0) || (MAX_INCL_DIMENSION < src_w) || //
(src_h < 0) || (MAX_INCL_DIMENSION < src_h)) {
printf("main: image is too large\n");
stbi_image_free(src_pixels);
return;
} else if ((src_w == 0) || (src_h == 0)) {
stbi_image_free(src_pixels);
return;
}
uint8_t* dst_pixels = NULL;
uint8_t* pixels = src_pixels;
int w = src_w;
int h = src_h;
if (g_flags.resize > 0) {
dst_pixels = resize(&w, &h, src_pixels, g_flags.resize, bytes_per_pixel);
if (!dst_pixels) {
stbi_image_free(src_pixels);
return;
}
pixels = dst_pixels;
}
// The +16 is some slack for a new-line and ANSI reset code.
static char
buffer[(MAX_INCL_DIMENSION * BYTES_PER_COLOR_OUTPUT_CHARACTER) + 16];
if (g_flags.ascii_art) {
unsigned char* src = pixels;
for (int y = 0; y < h; y++) {
char* dst = buffer;
for (int x = 0; x < w; x++) {
*dst++ = "-:=+IOX@"[(src[0] & 0xff) >> 5];
src++;
}
*dst++ = '\n';
fwrite(buffer, sizeof(char), dst - buffer, stdout);
}
} else if (g_flags.braille_art_dark_mode || g_flags.braille_art_light_mode) {
uint8_t xor = g_flags.braille_art_dark_mode ? 0x00 : 0xff;
// Each 2×4 pixel block becomes one Unicode Braille Pattern character. We
// also apply blue noise dithering, similar to what's described at
// https://surma.dev/things/ditherpunk/
for (int y = 0; y < h; y += 4) {
char* dst = buffer;
for (int x = 0; x < w; x += 2) {
dst[0] = 0xE2; // The 3-byte UTF-8 encoding of U+2800
dst[1] = 0xA0; // BRAILLE PATTERN BLANK. We'll then set
dst[2] = 0x80; // dst[1] and dst[2]'s low 2 and 6 bits.
for (int dy = 0; (dy < 4) && ((y + dy) < h); dy++) {
size_t ty = y + dy;
for (int dx = 0; (dx < 2) && ((x + dx) < w); dx++) {
size_t tx = x + dx;
uint8_t pixel = pixels[(ty * (size_t)w) + tx];
uint8_t threshold = g_noise[ty & 31][tx & 31];
if ((xor^pixel) > (xor^threshold)) {
uint8_t b = g_braille[dy][dx];
dst[1] |= b >> 6;
dst[2] |= b & 0x3f;
}
}
}
dst += 3;
}
*dst++ = '\n';
fwrite(buffer, sizeof(char), dst - buffer, stdout);
}
} else {
unsigned char* src = pixels;
for (int y = 0; y < h; y += 2) {
char* dst = buffer;
for (int x = 0; x < w; x++) {
// "\xE2\x96\x80" is U+2588 UPPER HALF BLOCK. Before that is a true
// color terminal escape code for foreground and background color, to
// dump two pixels per output character.
uint8_t upper0 = (uint8_t)src[0];
uint8_t upper1 = (uint8_t)src[1];
uint8_t upper2 = (uint8_t)src[2];
if ((y + 1) >= h) {
dst += sprintf(dst, "\x1B[38;2;%d;%d;%dm\xE2\x96\x80", //
upper0, upper1, upper2);
} else {
uint8_t lower0 = (uint8_t)src[(w * 3) + 0];
uint8_t lower1 = (uint8_t)src[(w * 3) + 1];
uint8_t lower2 = (uint8_t)src[(w * 3) + 2];
dst +=
sprintf(dst,
"\x1B[38;2;%d;%d;%dm\x1B[48;2;%d;%d;%dm\xE2\x96\x80", //
upper0, upper1, upper2, lower0, lower1, lower2);
}
src += 3;
}
memcpy(dst, "\x1B[0m\n", 5);
dst += 5;
fwrite(buffer, sizeof(char), dst - buffer, stdout);
if ((y + 1) < h) {
src += w * 3;
}
}
}
fflush(stdout);
free(dst_pixels);
stbi_image_free(src_pixels);
printf("\n");
}
int //
main(int argc, char** argv) {
const char* usage = parse_flags(argc, argv);
if (usage) {
fputs(usage, stderr);
return 1;
}
struct {
const char* filename;
const uint8_t* src_ptr;
const size_t src_len;
} demos[] = {
{
"«demo»/mona-lisa.21x32.th",
g_src_ptr__mona_lisa_21_32_th,
g_src_len__mona_lisa_21_32_th,
},
{
"«demo»/mona-lisa.21x32.etc2.pkm",
g_src_ptr__mona_lisa_21_32_etc2_pkm,
g_src_len__mona_lisa_21_32_etc2_pkm,
},
{
"«demo»/mona-lisa.21x32.q50.jpeg",
g_src_ptr__mona_lisa_21_32_q50_jpeg,
g_src_len__mona_lisa_21_32_q50_jpeg,
},
{
"«demo»/mona-lisa.21x32.png",
g_src_ptr__mona_lisa_21_32_png,
g_src_len__mona_lisa_21_32_png,
},
{
NULL,
NULL,
0,
},
};
if (g_flags.demo) {
for (size_t c = 0; demos[c].filename != NULL; c++) {
handle(demos[c].filename, demos[c].src_len, demos[c].src_ptr,
demos[c].src_len);
}
}
for (int c = 0; c < g_flags.remaining_argc; c++) {
const char* filename = g_flags.remaining_argv[c];
handle(filename, get_filesize(filename), NULL, 0);
}
return 0;
}
+1 -1
View File
@@ -22,7 +22,7 @@ gzip: test/data/*.gz
jpeg: test/data/*.jpeg ../libjpeg_turbo_corpus/*.jpg
json: test/data/*.json ../rapidjson_corpus/* ../simdjson_corpus/* ../JSONTestSuite/test_*/*.json
png: test/data/*.png test/data/artificial-png/*.png ../pngsuite_corpus/*.png
tga: test/data/*.tga
targa: test/data/*.tga
wbmp: test/data/*.wbmp
xz: test/data/*.xz ../xz_corpus/*.xz
zlib: test/data/*.zlib
@@ -21,7 +21,7 @@ such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput.
When working on the fuzz implementation, or as a coherence check, defining
WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files:
gcc -DWUFFS_CONFIG__FUZZLIB_MAIN tga_fuzzer.c
gcc -DWUFFS_CONFIG__FUZZLIB_MAIN targa_fuzzer.c
./a.out ../../../test/data/*.tga
rm -f ./a.out
@@ -59,7 +59,7 @@ It should print "PASS", amongst other information, and exit(0).
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__TARGA
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
@@ -70,8 +70,8 @@ It should print "PASS", amongst other information, and exit(0).
const char* //
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
wuffs_tga__decoder dec;
wuffs_base__status status = wuffs_tga__decoder__initialize(
wuffs_targa__decoder dec;
wuffs_base__status status = wuffs_targa__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
hash = wuffs_base__u64__rotate_right(hash, 1);
@@ -80,5 +80,5 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
}
return fuzz_image_decoder(
src, hash,
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec));
wuffs_targa__decoder__upcast_as__wuffs_base__image_decoder(&dec));
}
+20 -4
View File
@@ -62,6 +62,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
case WUFFS_BASE__FOURCC__ETC2:
return wuffs_etc2__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
case WUFFS_BASE__FOURCC__GIF:
return wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
@@ -91,9 +96,19 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
}
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
case WUFFS_BASE__FOURCC__QOI:
return wuffs_qoi__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
case WUFFS_BASE__FOURCC__TGA:
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
return wuffs_targa__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
case WUFFS_BASE__FOURCC__TH:
return wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
@@ -135,7 +150,7 @@ DecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config,
return AllocPixbufResult(DecodeImage_UnsupportedPixelConfiguration);
}
void* ptr =
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
if (!ptr) {
return AllocPixbufResult(DecodeImage_OutOfMemory);
}
@@ -160,7 +175,7 @@ DecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range,
return AllocWorkbufResult(DecodeImage_OutOfMemory);
}
void* ptr =
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
if (!ptr) {
return AllocWorkbufResult(DecodeImage_OutOfMemory);
}
@@ -460,6 +475,7 @@ redirect:
wuffs_base__pixel_format pixel_format = callbacks.SelectPixfmt(image_config);
if (pixel_format.repr != image_config.pixcfg.pixel_format().repr) {
switch (pixel_format.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
case WUFFS_BASE__PIXEL_FORMAT__BGR:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
+15 -6
View File
@@ -80,18 +80,26 @@ class DecodeImageCallbacks {
//
// The default SelectDecoder accepts the FOURCC codes listed below. For
// modular builds (i.e. when #define'ing WUFFS_CONFIG__MODULES), acceptance
// of the ETC file format is optional (for each value of ETC) and depends on
// of the FOO file format is optional (for each value of FOO) and depends on
// the corresponding module to be enabled at compile time (i.e. #define'ing
// WUFFS_CONFIG__MODULE__ETC).
// WUFFS_CONFIG__MODULE__FOO).
//
// - WUFFS_BASE__FOURCC__BMP
// - WUFFS_BASE__FOURCC__ETC2
// - WUFFS_BASE__FOURCC__GIF
// - WUFFS_BASE__FOURCC__JPEG
// - WUFFS_BASE__FOURCC__NIE
// - WUFFS_BASE__FOURCC__NPBM
// - WUFFS_BASE__FOURCC__PNG
// - WUFFS_BASE__FOURCC__TGA
// - WUFFS_BASE__FOURCC__QOI
// - WUFFS_BASE__FOURCC__TARGA
// - WUFFS_BASE__FOURCC__TH
// - WUFFS_BASE__FOURCC__WBMP
// - WUFFS_BASE__FOURCC__WEBP
//
// The FOOBAR in WUFFS_BASE__FOURCC__FOBA is limited to four characters, but
// the FOOBAR in the corresponding WUFFS_CONFIG__MODULE__FOOBAR macro might
// be fuller and longer. For example, NPBM / NETPBM or TH / THUMBHASH.
virtual wuffs_base__image_decoder::unique_ptr //
SelectDecoder(uint32_t fourcc,
wuffs_base__slice_u8 prefix_data,
@@ -100,8 +108,8 @@ class DecodeImageCallbacks {
// 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.
// If it is METADATA_RAW_PASSTHROUGH 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 |
@@ -115,6 +123,7 @@ class DecodeImageCallbacks {
// 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__Y
// - WUFFS_BASE__PIXEL_FORMAT__BGR_565
// - WUFFS_BASE__PIXEL_FORMAT__BGR
// - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL
@@ -217,7 +226,7 @@ struct DecodeImageArgFlags {
// DefaultValue returns 0.
static DecodeImageArgFlags DefaultValue();
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
// TODO: support all of the REPORT_METADATA_FOO flags, not just CHRM, EXIF,
// GAMA, ICCP, KVP, SRGB and XMP.
// Background Color.
+12
View File
@@ -173,12 +173,24 @@ wuffs_private_impl__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {
// ---------------- Numeric Types (Utility)
#define wuffs_base__utility__i64_divide(a, b) \
((uint64_t)(((int64_t)(a)) / ((int64_t)(b))))
#define wuffs_base__utility__sign_extend_convert_u8_u32(a) \
((uint32_t)(int32_t)(int8_t)(a))
#define wuffs_base__utility__sign_extend_convert_u8_u64(a) \
((uint64_t)(int64_t)(int8_t)(a))
#define wuffs_base__utility__sign_extend_convert_u16_u32(a) \
((uint32_t)(int32_t)(int16_t)(a))
#define wuffs_base__utility__sign_extend_convert_u16_u64(a) \
((uint64_t)(int64_t)(int16_t)(a))
#define wuffs_base__utility__sign_extend_convert_u32_u64(a) \
((uint64_t)(int64_t)(int32_t)(a))
#define wuffs_base__utility__sign_extend_rshift_u32(a, n) \
((uint32_t)(((int32_t)(a)) >> (n)))
+14
View File
@@ -62,6 +62,20 @@
#endif
// ---------------- Obsolete Macros Check
// std/tga was renamed to std/targa in September 2024 (Wuffs v0.4 alpha).
#if defined(WUFFS_CONFIG__MODULE__TGA)
#if defined(__GNUC__) || defined(__clang__)
#warning "WUFFS_CONFIG__MODULE__TGA was renamed to WUFFS_CONFIG__MODULE__TARGA"
#elif defined(_MSC_VER)
#pragma message( \
"WUFFS_CONFIG__MODULE__TGA was renamed to WUFFS_CONFIG__MODULE__TARGA")
#endif
#endif
// ---------------- Configuration
// Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU
+67 -1
View File
@@ -199,6 +199,46 @@ wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul(
return (a16 << 48) | (r16 << 32) | (g16 << 16) | (b16 << 0);
}
static inline uint8_t //
wuffs_base__color_u64_argb_premul__as__color_u8_gray(uint64_t argb_premul) {
uint32_t r16 = ((uint32_t)(0xFFFF & (argb_premul >> 32)));
uint32_t g16 = ((uint32_t)(0xFFFF & (argb_premul >> 16)));
uint32_t b16 = ((uint32_t)(0xFFFF & (argb_premul >> 0)));
// These coefficients (the fractions 0.299, 0.587 and 0.114) are the same
// as those given by the JFIF specification.
//
// Note that 19595 + 38470 + 7471 equals 65536, also known as (1 << 16). We
// shift by 24, not just by 16, because the return value is 8-bit color, not
// 16-bit color.
uint32_t weighted_average =
(19595 * r16) + (38470 * g16) + (7471 * b16) + 32768;
return (uint8_t)(weighted_average >> 24);
}
static inline uint8_t //
wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray(
uint64_t argb_nonpremul) {
uint32_t a16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 48)));
uint32_t r16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 32)));
r16 = (r16 * a16) / 0xFFFF;
uint32_t g16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 16)));
g16 = (g16 * a16) / 0xFFFF;
uint32_t b16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 0)));
b16 = (b16 * a16) / 0xFFFF;
// These coefficients (the fractions 0.299, 0.587 and 0.114) are the same
// as those given by the JFIF specification.
//
// Note that 19595 + 38470 + 7471 equals 65536, also known as (1 << 16). We
// shift by 24, not just by 16, because the return value is 8-bit color, not
// 16-bit color.
uint32_t weighted_average =
(19595 * r16) + (38470 * g16) + (7471 * b16) + 32768;
return (uint8_t)(weighted_average >> 24);
}
static inline uint64_t //
wuffs_base__color_u32__as__color_u64(uint32_t c) {
uint64_t a16 = 0x101 * (0xFF & (c >> 24));
@@ -321,6 +361,20 @@ typedef uint32_t wuffs_base__pixel_alpha_transparency;
// --------
// wuffs_base__pixel_coloration is whether a pixel format's color model has no
// color (alpha only), gray color or rich (non-gray) color. Rich color includes
// RGB, BGR, YCC, YCCK, CMY and CMYK.
//
// Coloration does not capture the alpha aspect of the color model. It does not
// distinguish RGB from RGBA.
typedef uint32_t wuffs_base__pixel_coloration;
#define WUFFS_BASE__PIXEL_COLORATION__NONE 0
#define WUFFS_BASE__PIXEL_COLORATION__GRAY 1
#define WUFFS_BASE__PIXEL_COLORATION__RICH 3
// --------
// Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL.
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4
@@ -349,6 +403,7 @@ typedef struct wuffs_base__pixel_format__struct {
inline bool is_indexed() const;
inline bool is_interleaved() const;
inline bool is_planar() const;
inline uint32_t coloration() const;
inline uint32_t num_planes() const;
inline wuffs_base__pixel_alpha_transparency transparency() const;
#endif // __cplusplus
@@ -455,6 +510,12 @@ wuffs_base__pixel_format__is_planar(const wuffs_base__pixel_format* f) {
return ((f->repr >> 16) & 0x03) != 0;
}
static inline uint32_t //
wuffs_base__pixel_format__coloration(const wuffs_base__pixel_format* f) {
uint32_t n = (f->repr) >> 29;
return (n <= 1) ? n : 3;
}
static inline uint32_t //
wuffs_base__pixel_format__num_planes(const wuffs_base__pixel_format* f) {
return ((f->repr >> 16) & 0x03) + 1;
@@ -497,6 +558,11 @@ wuffs_base__pixel_format::is_planar() const {
return wuffs_base__pixel_format__is_planar(this);
}
inline uint32_t //
wuffs_base__pixel_format::coloration() const {
return wuffs_base__pixel_format__coloration(this);
}
inline uint32_t //
wuffs_base__pixel_format::num_planes() const {
return wuffs_base__pixel_format__num_planes(this);
@@ -651,7 +717,7 @@ wuffs_base__pixel_config__set(wuffs_base__pixel_config* c,
}
if (pixfmt_repr) {
do {
#if SIZE_MAX < UINT64_MAX
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
uint64_t wh = ((uint64_t)width) * ((uint64_t)height);
// TODO: handle things other than 1 byte per pixel.
if (wh > ((uint64_t)SIZE_MAX)) {
+25 -20
View File
@@ -145,26 +145,31 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
int32_t fourcc;
const char* magic;
} table[] = {
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm)
{+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA
{+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x41425852, "\x03\x03\x00\x08\x00"}, // ABXR
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
{+0x584D4C20, "\x05\x3C\x3F\x78\x6D\x6C\x20"}, // XML
{+0x41425853, "\x03\x41\x42\x58\x00"}, // ABXS
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{+0x45544332, "\x03\x50\x4B\x4D\x20"}, // ETC2 (*.pkm)
{+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm)
{+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA
{+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x54482020, "\x02\xC3\xBE\xFE"}, // TH
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
};
static const size_t table_len = sizeof(table) / sizeof(table[0]);
+749 -3
View File
@@ -142,9 +142,8 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
wuffs_base__peek_u32le__no_bounds_check(row + (4 * ((size_t)x)));
case WUFFS_BASE__PIXEL_FORMAT__RGB:
return wuffs_private_impl__swap_u32_argb_abgr(
0xFF000000 |
wuffs_base__peek_u24le__no_bounds_check(row + (3 * ((size_t)x))));
return 0xFF000000 |
wuffs_base__peek_u24be__no_bounds_check(row + (3 * ((size_t)x)));
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
return wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
@@ -250,6 +249,10 @@ wuffs_base__pixel_buffer__set_color_u32_at(
wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul(
color));
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
wuffs_base__poke_u32le__no_bounds_check(
row + (4 * ((size_t)x)), (color >> 31) ? (color | 0xFF000000) : 0);
break;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
wuffs_base__poke_u24le__no_bounds_check(
@@ -855,6 +858,34 @@ wuffs_private_impl__swizzle_squash_align4_bgr_565_8888(uint8_t* dst_ptr,
// --------
static uint64_t //
wuffs_private_impl__swizzle_squash_align4_y_8888(uint8_t* dst_ptr,
size_t dst_len,
const uint8_t* src_ptr,
size_t src_len,
bool nonpremul) {
size_t len = (dst_len < src_len ? dst_len : src_len) / 4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
while (n--) {
uint32_t argb = wuffs_base__peek_u32le__no_bounds_check(s);
if (nonpremul) {
argb =
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(argb);
}
uint32_t s0 = wuffs_base__color_u32_argb_premul__as__color_u8_gray(argb);
wuffs_base__poke_u32le__no_bounds_check(
d, (argb & 0xFF000000) | (s0 * 0x010101));
s += 4;
d += 4;
}
return len;
}
// --------
static uint64_t //
wuffs_private_impl__swizzle_swap_rgb_bgr(uint8_t* dst_ptr,
size_t dst_len,
@@ -4680,6 +4711,62 @@ wuffs_private_impl__swizzle_xxxxxxxx__y_16be(uint8_t* dst_ptr,
// --------
static uint64_t //
wuffs_private_impl__swizzle_y__bgr(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len3 = src_len / 3;
size_t len = (dst_len < src_len3) ? dst_len : src_len3;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u24le__no_bounds_check(s + (0 * 3));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 3;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgr_565(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(
wuffs_base__peek_u16le__no_bounds_check(s + (0 * 2)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
@@ -4693,6 +4780,8 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
@@ -4721,6 +4810,8 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over(
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
@@ -4735,6 +4826,154 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over(
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len8 = src_len / 8;
size_t len = (dst_len < src_len8) ? dst_len : src_len8;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray(
wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8)));
s += 1 * 8;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len8 = src_len / 8;
size_t len = (dst_len < src_len8) ? dst_len : src_len8;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[0]);
uint32_t dg = 0x101 * ((uint32_t)d[0]);
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));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
// Composite src (nonpremul) over dst (premul).
dr = ((sr * sa) + (dr * ia)) / 0xFFFF;
dg = ((sg * sa) + (dg * ia)) / 0xFFFF;
db = ((sb * sa) + (db * ia)) / 0xFFFF;
// Convert to 16-bit color to 8-bit gray.
uint32_t weighted_average =
(19595 * dr) + (38470 * dg) + (7471 * db) + 32768;
d[0] = (uint8_t)(weighted_average >> 24);
s += 1 * 8;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_premul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_premul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[0]);
uint32_t dg = 0x101 * ((uint32_t)d[0]);
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]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
// Composite src (premul) over dst (premul).
dr = sr + ((dr * ia) / 0xFFFF);
dg = sg + ((dg * ia) / 0xFFFF);
db = sb + ((db * ia) / 0xFFFF);
// Convert to 16-bit color to 8-bit gray.
uint32_t weighted_average =
(19595 * dr) + (38470 * dg) + (7471 * db) + 32768;
d[0] = (uint8_t)(weighted_average >> 24);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
size_t dst_len,
@@ -4748,6 +4987,8 @@ wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
@@ -4761,6 +5002,152 @@ wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgb(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len3 = src_len / 3;
size_t len = (dst_len < src_len3) ? dst_len : src_len3;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u24be__no_bounds_check(s + (0 * 3));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 3;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_nonpremul__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_premul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_premul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_premul_u32_axxx(d0, s0));
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
size_t dst_len,
@@ -4774,6 +5161,8 @@ wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = s[0];
@@ -4785,6 +5174,162 @@ wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__ya_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
d[0] = (uint8_t)
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__ya_nonpremul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | ((uint32_t)(d[0]) * 0x010101);
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
d[0] = (uint8_t)wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0,
s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = dst_palette_ptr[(size_t)s[0] * 4];
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index_bgra_nonpremul__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr +
((size_t)s[0] * 4));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index_binary_alpha__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr +
((size_t)s[0] * 4));
if (s0) {
d[0] = (uint8_t)s0;
}
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
// --------
static uint64_t //
wuffs_private_impl__swizzle_y_16le__y_16be(uint8_t* dst_ptr,
size_t dst_len,
@@ -4973,6 +5518,15 @@ wuffs_private_impl__pixel_swizzler__prepare__ya_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__ya_nonpremul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__ya_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -5042,6 +5596,26 @@ wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
if (wuffs_private_impl__swizzle_squash_align4_y_8888(
dst_palette.ptr, dst_palette.len, src_palette.ptr,
src_palette.len, true) !=
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
return NULL;
}
return wuffs_private_impl__swizzle_y__index__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
src_palette) !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return NULL;
}
return wuffs_private_impl__swizzle_y__index_bgra_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
src_palette) !=
@@ -5214,6 +5788,21 @@ wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_binary(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
if (wuffs_private_impl__swizzle_squash_align4_y_8888(
dst_palette.ptr, dst_palette.len, src_palette.ptr,
src_palette.len, false) !=
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
return NULL;
}
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__index__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__index_binary_alpha__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
@@ -5331,6 +5920,9 @@ wuffs_private_impl__pixel_swizzler__prepare__bgr_565(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__bgr_565;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_copy_2_2;
@@ -5367,6 +5959,9 @@ wuffs_private_impl__pixel_swizzler__prepare__bgr(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__bgr;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_bgr_565__bgr;
@@ -5520,6 +6115,15 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -5613,6 +6217,15 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_premul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -5693,6 +6306,109 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_premul(
return NULL;
}
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
wuffs_private_impl__pixel_swizzler__prepare__bgra_binary(
wuffs_base__pixel_swizzler* p,
wuffs_base__pixel_format dst_pixfmt,
wuffs_base__slice_u8 dst_palette,
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_copy_4_4;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_copy_4_4;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_premul__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr__rgba_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_premul__rgba_premul__src_over;
}
return NULL;
}
return NULL;
}
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
wuffs_private_impl__pixel_swizzler__prepare__bgrx(
wuffs_base__pixel_swizzler* p,
@@ -5741,6 +6457,9 @@ wuffs_private_impl__pixel_swizzler__prepare__rgb(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__rgb;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_bgr_565__rgb;
@@ -5786,6 +6505,15 @@ wuffs_private_impl__pixel_swizzler__prepare__rgba_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__rgba_nonpremul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__rgba_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -5884,6 +6612,15 @@ wuffs_private_impl__pixel_swizzler__prepare__rgba_premul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__rgba_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -5985,6 +6722,10 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
switch (dst_pixfmt.repr) {
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y)
case WUFFS_BASE__PIXEL_FORMAT__Y:
break;
#endif
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565)
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
break;
@@ -6111,6 +6852,11 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
p, dst_pixfmt, dst_palette, src_palette, blend);
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
func = wuffs_private_impl__pixel_swizzler__prepare__bgra_binary(
p, dst_pixfmt, dst_palette, src_palette, blend);
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
func = wuffs_private_impl__pixel_swizzler__prepare__bgrx(
p, dst_pixfmt, dst_palette, src_palette, blend);
@@ -1364,6 +1364,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
switch (dst->pixcfg.private_impl.pixfmt.repr) {
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y)
case WUFFS_BASE__PIXEL_FORMAT__Y:
break;
#endif
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565)
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
break;
+8
View File
@@ -253,6 +253,14 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
b.writeb(')')
return nil
case t.IDPeekU8At:
b.printf("%s%s[", iopPrefix, recvName)
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
return err
}
b.writeb(']')
return nil
case t.IDPeekU64LEAt:
b.printf("wuffs_base__peek_u64le__no_bounds_check(%s%s + ", iopPrefix, recvName)
if err := g.writeExpr(b, args[0].AsArg().Value(), false, depth); err != nil {
+1 -1
View File
@@ -1535,7 +1535,7 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
return err
}
b.writes(" {\n")
b.printf("%s%s* x =\n(%s%s*)(calloc(sizeof(%s%s), 1));\n",
b.printf("%s%s* x =\n(%s%s*)(calloc(1, sizeof(%s%s)));\n",
g.pkgPrefix, structName, g.pkgPrefix, structName, g.pkgPrefix, structName)
b.writes("if (!x) {\nreturn NULL;\n}\n")
b.printf("if (%s%s__initialize(\nx, sizeof(%s%s), "+
+540
View File
@@ -0,0 +1,540 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// ---------------- Wuffs' reimplementation of the STB API.
//
// This is a drop-in replacement of that third-party library.
//
// Disabled by default, unless you #define the
// WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB macro beforehand.
//
// For API docs, see https://github.com/nothings/stb
#if defined(WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
#include <limits.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
// --------
#if defined(__GNUC__)
__thread const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#elif defined(_MSC_VER)
__declspec(thread) const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#else
const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#endif
// --------
static void //
wuffs_drop_in__stb__read( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user) {
uint8_t* ptr = wuffs_base__io_buffer__writer_pointer(srcbuf);
size_t len = wuffs_base__io_buffer__writer_length(srcbuf);
if (len > INT_MAX) {
len = INT_MAX;
}
int n = clbk->read(user, (char*)ptr, (int)len);
if (n > 0) {
srcbuf->meta.wi += (size_t)n;
} else {
srcbuf->meta.closed = clbk->eof(user);
}
}
static wuffs_base__image_decoder* //
wuffs_drop_in__stb__make_decoder( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user) {
while (1) {
int32_t fourcc = wuffs_base__magic_number_guess_fourcc(
wuffs_base__io_buffer__reader_slice(srcbuf), srcbuf->meta.closed);
if (fourcc < 0) {
if (srcbuf->meta.closed || !clbk) {
break;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
continue;
}
switch (fourcc) {
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
case WUFFS_BASE__FOURCC__BMP:
return wuffs_bmp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
case WUFFS_BASE__FOURCC__ETC2:
return wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
case WUFFS_BASE__FOURCC__GIF:
return wuffs_gif__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG)
case WUFFS_BASE__FOURCC__JPEG:
return wuffs_jpeg__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE)
case WUFFS_BASE__FOURCC__NIE:
return wuffs_nie__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NETPBM)
case WUFFS_BASE__FOURCC__NPBM:
return wuffs_netpbm__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
case WUFFS_BASE__FOURCC__PNG:
return wuffs_png__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
case WUFFS_BASE__FOURCC__QOI:
return wuffs_qoi__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
case WUFFS_BASE__FOURCC__TGA:
return wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
case WUFFS_BASE__FOURCC__TH:
return wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
case WUFFS_BASE__FOURCC__WBMP:
return wuffs_wbmp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WEBP)
case WUFFS_BASE__FOURCC__WEBP:
return wuffs_webp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
}
wuffs_drop_in__stb__g_failure_reason = "unknown image type";
break;
}
return NULL;
}
// --------
static void* //
wuffs_drop_in__stb__load1( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user, //
wuffs_base__image_decoder* dec, //
wuffs_base__image_config* ic, //
uint32_t dst_pixfmt, //
int desired_channels, //
int info_only) {
// Favor faster decodes over rejecting invalid checksums.
wuffs_base__image_decoder__set_quirk(dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
1);
while (1) {
wuffs_base__status status =
wuffs_base__image_decoder__decode_image_config(dec, ic, srcbuf);
if (status.repr == NULL) {
break;
} else if ((status.repr != wuffs_base__suspension__short_read) || !clbk) {
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
size_t wl = wuffs_base__io_buffer__writer_length(srcbuf);
wuffs_base__io_buffer__compact(srcbuf);
if (wl >= wuffs_base__io_buffer__writer_length(srcbuf)) {
wuffs_drop_in__stb__g_failure_reason = "I/O buffer is too small";
return NULL;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
}
uint32_t w = wuffs_base__pixel_config__width(&ic->pixcfg);
uint32_t h = wuffs_base__pixel_config__height(&ic->pixcfg);
if ((w > 0xFFFFFF) || (h > 0xFFFFFF)) {
wuffs_drop_in__stb__g_failure_reason = "image is too large";
return NULL;
} else if (info_only) {
return NULL;
}
uint64_t pixbuf_len = (uint64_t)w * (uint64_t)h * (uint64_t)desired_channels;
uint64_t workbuf_len = wuffs_base__image_decoder__workbuf_len(dec).max_incl;
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
if ((pixbuf_len > ((uint64_t)SIZE_MAX)) ||
(workbuf_len > ((uint64_t)SIZE_MAX))) {
wuffs_drop_in__stb__g_failure_reason = "image is too large";
return NULL;
}
#endif
void* pixbuf_ptr = malloc((size_t)pixbuf_len);
if (!pixbuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
void* workbuf_ptr = malloc((size_t)workbuf_len);
if (!workbuf_ptr) {
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__slice_u8 workbuf =
wuffs_base__make_slice_u8(workbuf_ptr, (size_t)workbuf_len);
wuffs_base__pixel_config pc = ((wuffs_base__pixel_config){});
wuffs_base__pixel_config__set(&pc, dst_pixfmt,
WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, w, h);
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
{
wuffs_base__status status = wuffs_base__pixel_buffer__set_from_slice(
&pb, &pc, wuffs_base__make_slice_u8(pixbuf_ptr, (size_t)pixbuf_len));
if (status.repr) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
}
while (1) {
wuffs_base__status status = wuffs_base__image_decoder__decode_frame(
dec, &pb, srcbuf, WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL);
if (status.repr == NULL) {
break;
} else if ((status.repr != wuffs_base__suspension__short_read) || !clbk) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
size_t wl = wuffs_base__io_buffer__writer_length(srcbuf);
wuffs_base__io_buffer__compact(srcbuf);
if (wl >= wuffs_base__io_buffer__writer_length(srcbuf)) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = "I/O buffer is too small";
return NULL;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
}
free(workbuf_ptr);
return pixbuf_ptr;
}
static void* //
wuffs_drop_in__stb__load0( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels, //
int info_only) {
uint32_t dst_pixfmt = 0;
switch (desired_channels) {
case 1:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__Y;
break;
case 3:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGB;
break;
case 4:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL;
break;
default:
wuffs_drop_in__stb__g_failure_reason = "unsupported format conversion";
return NULL;
}
wuffs_base__image_decoder* dec =
wuffs_drop_in__stb__make_decoder(srcbuf, clbk, user);
if (!dec) {
if (wuffs_drop_in__stb__g_failure_reason == NULL) {
wuffs_drop_in__stb__g_failure_reason = "couldn't allocate image decoder";
}
return NULL;
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
stbi_uc* ret = wuffs_drop_in__stb__load1(
srcbuf, clbk, user, dec, &ic, dst_pixfmt, desired_channels, info_only);
free(dec);
if (!info_only && !ret) {
return NULL;
}
if (x) {
*x = (int)wuffs_base__pixel_config__width(&ic.pixcfg);
}
if (y) {
*y = (int)wuffs_base__pixel_config__height(&ic.pixcfg);
}
if (channels_in_file) {
wuffs_base__pixel_format src_pixfmt =
wuffs_base__pixel_config__pixel_format(&ic.pixcfg);
uint32_t n_color = wuffs_base__pixel_format__coloration(&src_pixfmt);
uint32_t n_alpha = wuffs_base__pixel_format__transparency(&src_pixfmt) !=
WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE;
*channels_in_file = (int)(n_color + n_alpha);
}
return ret;
}
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
if (len < 0) {
wuffs_drop_in__stb__g_failure_reason = "negative buffer length";
return 0;
} else if (len == 0) {
wuffs_drop_in__stb__g_failure_reason = "empty buffer";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__reader((uint8_t*)(stbi_uc*)buffer, (size_t)len, true);
wuffs_drop_in__stb__load0(&srcbuf, NULL, NULL, x, y, comp, 1, 1);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
if (len < 0) {
wuffs_drop_in__stb__g_failure_reason = "negative buffer length";
return NULL;
} else if (len == 0) {
wuffs_drop_in__stb__g_failure_reason = "empty buffer";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__reader((uint8_t*)(stbi_uc*)buffer, (size_t)len, true);
return wuffs_drop_in__stb__load0(&srcbuf, NULL, NULL, x, y, channels_in_file,
desired_channels, 0);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
wuffs_drop_in__stb__load0(&srcbuf, clbk, user, x, y, comp, 1, 1);
free(iobuf_ptr);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_uc* ret = wuffs_drop_in__stb__load0(
&srcbuf, clbk, user, x, y, channels_in_file, desired_channels, 0);
free(iobuf_ptr);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC void //
stbi_image_free( //
void* retval_from_stbi_load) {
wuffs_drop_in__stb__g_failure_reason = NULL;
free(retval_from_stbi_load);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC const char* //
stbi_failure_reason(void) {
return wuffs_drop_in__stb__g_failure_reason
? wuffs_drop_in__stb__g_failure_reason
: "ok";
}
// --------
#if !defined(STBI_NO_STDIO)
#include <stdio.h>
// TODO: retry after EINTR?
static int //
wuffs_drop_in__stb__file_callbacks__read( //
void* user, //
char* data, //
int size) {
return (int)fread(data, 1u, (size_t)size, (FILE*)user);
}
static void //
wuffs_drop_in__stb__file_callbacks__skip( //
void* user, //
int n) {
fseek((FILE*)user, (long)n, SEEK_CUR);
}
static int //
wuffs_drop_in__stb__file_callbacks__eof( //
void* user) {
return feof((FILE*)user);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info( //
char const* filename, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
FILE* f = fopen(filename, "rb");
if (!f) {
wuffs_drop_in__stb__g_failure_reason = "could not open file";
return 0;
}
int ret = stbi_info_from_file(f, x, y, comp);
fclose(f);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load( //
char const* filename, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
FILE* f = fopen(filename, "rb");
if (!f) {
wuffs_drop_in__stb__g_failure_reason = "could not open file";
return NULL;
}
stbi_uc* ret =
stbi_load_from_file(f, x, y, channels_in_file, desired_channels);
fclose(f);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_file( //
FILE* f, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_io_callbacks clbk;
clbk.read = &wuffs_drop_in__stb__file_callbacks__read;
clbk.skip = &wuffs_drop_in__stb__file_callbacks__skip;
clbk.eof = &wuffs_drop_in__stb__file_callbacks__eof;
wuffs_drop_in__stb__load0(&srcbuf, &clbk, f, x, y, comp, 1, 1);
free(iobuf_ptr);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_file( //
FILE* f, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_io_callbacks clbk;
clbk.read = &wuffs_drop_in__stb__file_callbacks__read;
clbk.skip = &wuffs_drop_in__stb__file_callbacks__skip;
clbk.eof = &wuffs_drop_in__stb__file_callbacks__eof;
stbi_uc* ret = wuffs_drop_in__stb__load0(
&srcbuf, &clbk, f, x, y, channels_in_file, desired_channels, 0);
free(iobuf_ptr);
return ret;
}
#endif // !defined(STBI_NO_STDIO)
// --------
#ifdef __cplusplus
} // extern "C"
#endif
#endif // defined (WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
+134
View File
@@ -0,0 +1,134 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// ---------------- Wuffs' reimplementation of the STB API.
//
// This is a drop-in replacement of that third-party library.
//
// Disabled by default, unless you #define the
// WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB macro beforehand.
//
// For API docs, see https://github.com/nothings/stb
#if defined(WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
#ifdef __cplusplus
extern "C" {
#endif
#if defined(WUFFS_CONFIG__STATIC_FUNCTIONS) || defined(STB_IMAGE_STATIC)
#define WUFFS_DROP_IN__STB__MAYBE_STATIC static
#else
#define WUFFS_DROP_IN__STB__MAYBE_STATIC
#endif
enum {
STBI_default = 0,
STBI_grey = 1,
STBI_grey_alpha = 2,
STBI_rgb = 3,
STBI_rgb_alpha = 4
};
typedef unsigned char stbi_uc;
typedef unsigned short stbi_us;
typedef struct {
int (*read)(void* user, char* data, int size);
void (*skip)(void* user, int n);
int (*eof)(void* user);
} stbi_io_callbacks;
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
// --------
#if !defined(STBI_NO_STDIO)
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info( //
char const* filename, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load( //
char const* filename, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_file( //
FILE* f, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_file( //
FILE* f, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
#endif // !defined(STBI_NO_STDIO)
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC void //
stbi_image_free( //
void* retval_from_stbi_load);
WUFFS_DROP_IN__STB__MAYBE_STATIC const char* //
stbi_failure_reason(void);
#ifdef __cplusplus
}
#endif
#endif // defined (WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
+8
View File
@@ -142,3 +142,11 @@ var EmbeddedStrings_AuxNonBaseHhFiles = []EmbeddedString{
embedAuxImageHh,
embedAuxJsonHh,
}
// ----
//go:embed drop-in/stb.c
var EmbeddedString_DropInSTBC EmbeddedString
//go:embed drop-in/stb.h
var EmbeddedString_DropInSTBH EmbeddedString
+10 -1
View File
@@ -24,6 +24,8 @@ import (
)
var FourCCs = [...][2]string{
{"ABXR", "Android Binary XML (for resources; see AndroidBinXmlParser.java)"},
{"ABXS", "Android Binary XML (for system_server; see BinaryXmlSerializer.java)"},
{"BGCL", "Background Color"},
{"BMP ", "Bitmap"},
{"BRTL", "Brotli"},
@@ -32,6 +34,7 @@ var FourCCs = [...][2]string{
{"CHRM", "Primary Chromaticities and White Point"},
{"CSS ", "Cascading Style Sheets"},
{"EPS ", "Encapsulated PostScript"},
{"ETC2", "Ericsson Texture Compression 2 (iPACKMAN)"},
{"EXIF", "Exchangeable Image File Format"},
{"FLAC", "Free Lossless Audio Codec"},
{"GAMA", "Gamma Correction"},
@@ -75,6 +78,7 @@ var FourCCs = [...][2]string{
{"TAR ", "Tape Archive"},
{"TEXT", "Text"},
{"TGA ", "Truevision Advanced Raster Graphics Adapter"},
{"TH ", "Thumbhash"},
{"TIFF", "Tagged Image File Format"},
{"TOML", "Tom's Obvious Minimal Language"},
{"WAVE", "Waveform"},
@@ -385,6 +389,7 @@ var funcsOther = [...]string{
"utility.empty_rect_ii_u32() rect_ii_u32",
"utility.empty_rect_ie_u32() rect_ie_u32",
"utility.empty_slice_u8() slice u8",
"utility.i64_divide(a: u64, b: u64[1 ..=]) u64",
"utility.make_bitvec256(e00: u64, e01: u64, e02: u64, e03: u64) bitvec256",
"utility.make_optional_u63(has_value: bool, value: u64[..= 0x7FFF_FFFF_FFFF_FFFF]) optional_u63",
"utility.make_pixel_format(repr: u32) pixel_format",
@@ -397,7 +402,10 @@ var funcsOther = [...]string{
"utility.make_rect_ie_u32(" +
"min_incl_x: u32, min_incl_y: u32, max_excl_x: u32, max_excl_y: u32) rect_ie_u32",
"utility.sign_extend_convert_u8_u32(a: u8) u32",
"utility.sign_extend_convert_u8_u64(a: u8) u64",
"utility.sign_extend_convert_u16_u32(a: u16) u32",
"utility.sign_extend_convert_u16_u64(a: u16) u64",
"utility.sign_extend_convert_u32_u64(a: u32) u64",
"utility.sign_extend_rshift_u32(a: u32, n: u32[..= 31]) u32",
"utility.sign_extend_rshift_u64(a: u64, n: u32[..= 63]) u64",
@@ -509,8 +517,9 @@ var funcsOther = [...]string{
"io_reader.peek_u64le() u64",
// As an implementation restriction, we require that offset has a constant
// value. The (0x1_0000 - sizeof(u64)) limit is arbitrary, but high enough
// value. The (0x1_0000 - sizeof(uxx)) limit is arbitrary, but high enough
// in practice.
"io_reader.peek_u8_at(offset: u32[..= 0xFFFF]) u8",
"io_reader.peek_u64le_at(offset: u32[..= 0xFFF8]) u64",
"io_reader.count_since(mark: u64) u64",
+8 -4
View File
@@ -1259,16 +1259,20 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
advanceExpr, update = actual, true
}
} else if method == t.IDPeekU64LEAt {
} else if (method == t.IDPeekU8At) || (method == t.IDPeekU64LEAt) {
args := n.Args()
if len(args) != 1 {
return bounds{}, fmt.Errorf("check: internal error: bad peek_u64le_at arguments")
return bounds{}, fmt.Errorf("check: internal error: bad peek_uxx_at arguments")
}
offset := args[0].AsArg().Value()
if offset.ConstValue() == nil {
return bounds{}, fmt.Errorf("check: peek_u64le_at offset is not a constant value")
return bounds{}, fmt.Errorf("check: peek_uxx_at offset is not a constant value")
}
advance, update = big.NewInt(8), false
adv := int64(1)
if method == t.IDPeekU64LEAt {
adv = 8
}
advance, update = big.NewInt(adv), false
advance.Add(advance, offset.ConstValue())
} else if method >= t.IDPeekU8 {
+2
View File
@@ -570,6 +570,7 @@ const (
IDPeekUndoByte = ID(0x1A0)
IDPeekU8 = ID(0x1A1)
IDPeekU8At = ID(0x1A2)
IDPeekU8AsU16 = ID(0x1A5)
IDPeekU16BE = ID(0x1A6)
@@ -1020,6 +1021,7 @@ var builtInsByID = [nBuiltInIDs]string{
IDPeekUndoByte: "peek_undo_byte",
IDPeekU8: "peek_u8",
IDPeekU8At: "peek_u8_at",
IDPeekU8AsU16: "peek_u8_as_u16",
IDPeekU16BE: "peek_u16be",
+35 -32
View File
@@ -10,7 +10,7 @@
// ----------------
// Package base38 converts a 4-byte string, each byte in [ 0-9?a-z], to a base
// Package base38 converts a 4-byte string, each byte in [.0-9a-z~], to a base
// 38 number.
package base38
@@ -25,10 +25,13 @@ const (
// Encode encodes a 4-byte string as a uint32 in the range [0, Max].
//
// Each byte must be ' ', be in the range '0'-'9', be '?' or be in the range
// 'a'-'z'.
// Each byte must be one of:
// - '.'
// - in the range ['0', '9']
// - in the range ['a', 'z']
// - '~'
//
// The string " " is mapped to zero.
// The string "...." is mapped to zero.
func Encode(s string) (u uint32, ok bool) {
if len(s) == 4 {
for i := 0; i < 4; i++ {
@@ -47,7 +50,7 @@ func Encode(s string) (u uint32, ok bool) {
}
var table = [256]uint8{
' ': 1,
'.': 1,
'0': 2,
'1': 3,
'2': 4,
@@ -58,31 +61,31 @@ var table = [256]uint8{
'7': 9,
'8': 10,
'9': 11,
'?': 12,
'a': 13,
'b': 14,
'c': 15,
'd': 16,
'e': 17,
'f': 18,
'g': 19,
'h': 20,
'i': 21,
'j': 22,
'k': 23,
'l': 24,
'm': 25,
'n': 26,
'o': 27,
'p': 28,
'q': 29,
'r': 30,
's': 31,
't': 32,
'u': 33,
'v': 34,
'w': 35,
'x': 36,
'y': 37,
'z': 38,
'a': 12,
'b': 13,
'c': 14,
'd': 15,
'e': 16,
'f': 17,
'g': 18,
'h': 19,
'i': 20,
'j': 21,
'k': 22,
'l': 23,
'm': 24,
'n': 25,
'o': 26,
'p': 27,
'q': 28,
'r': 29,
's': 30,
't': 31,
'u': 32,
'v': 33,
'w': 34,
'x': 35,
'y': 36,
'z': 37,
'~': 38,
}
+24 -22
View File
@@ -37,23 +37,25 @@ func TestValid(tt *testing.T) {
s string
want uint32
}{
{" ", mk(0, 0, 0, 0)},
{"0 ", mk(1, 0, 0, 0)},
{" 0 ", mk(0, 1, 0, 0)},
{" 0 ", mk(0, 0, 1, 0)},
{" 0", mk(0, 0, 0, 1)},
{"??12", mk(11, 11, 2, 3)},
{"....", mk(0, 0, 0, 0)},
{"0...", mk(1, 0, 0, 0)},
{".0..", mk(0, 1, 0, 0)},
{"..0.", mk(0, 0, 1, 0)},
{"...0", mk(0, 0, 0, 1)},
{"aa12", mk(11, 11, 2, 3)},
{"6543", mk(7, 6, 5, 4)},
{"789a", mk(8, 9, 10, 12)},
{"bcde", mk(13, 14, 15, 16)},
{"fghi", mk(17, 18, 19, 20)},
{"jklm", mk(21, 22, 23, 24)},
{" m0m", mk(0, 24, 1, 24)},
{"nopq", mk(25, 26, 27, 28)},
{"rstu", mk(29, 30, 31, 32)},
{"vwxy", mk(33, 34, 35, 36)},
{"z?z9", mk(37, 11, 37, 10)},
{"zzzz", mk(37, 37, 37, 37)},
{"789a", mk(8, 9, 10, 11)},
{"bcde", mk(12, 13, 14, 15)},
{"fghi", mk(16, 17, 18, 19)},
{"jklm", mk(20, 21, 22, 23)},
{".m0m", mk(0, 23, 1, 23)},
{"nopq", mk(24, 25, 26, 27)},
{"rstu", mk(28, 29, 30, 31)},
{"vwxy", mk(32, 33, 34, 35)},
{"zzzz", mk(36, 36, 36, 36)},
{"z~z9", mk(36, 37, 36, 10)},
{"~z~9", mk(37, 36, 37, 10)},
{"~~~~", mk(37, 37, 37, 37)},
}
maxSeen := false
@@ -81,12 +83,12 @@ func TestValid(tt *testing.T) {
func TestInvalid(tt *testing.T) {
testCases := []string{
"",
" ",
" ",
" ",
"....",
" ",
" ",
".",
"..",
"...",
" ",
".....",
"......",
"Abcd",
"a\x00cd",
"ab+d",
+7893 -315
View File
@@ -118,6 +118,20 @@ extern "C" {
#endif
// ---------------- Obsolete Macros Check
// std/tga was renamed to std/targa in September 2024 (Wuffs v0.4 alpha).
#if defined(WUFFS_CONFIG__MODULE__TGA)
#if defined(__GNUC__) || defined(__clang__)
#warning "WUFFS_CONFIG__MODULE__TGA was renamed to WUFFS_CONFIG__MODULE__TARGA"
#elif defined(_MSC_VER)
#pragma message( \
"WUFFS_CONFIG__MODULE__TGA was renamed to WUFFS_CONFIG__MODULE__TARGA")
#endif
#endif
// ---------------- Configuration
// Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU
@@ -754,6 +768,12 @@ typedef struct wuffs_base__transform__output__struct {
// Wuffs' u32 values are big-endian ("JPEG" is 0x4A504547 not 0x4745504A) to
// preserve ordering: "JPEG" < "MP3 " and 0x4A504547 < 0x4D503320.
// Android Binary XML (for resources; see AndroidBinXmlParser.java).
#define WUFFS_BASE__FOURCC__ABXR 0x41425852
// Android Binary XML (for system_server; see BinaryXmlSerializer.java).
#define WUFFS_BASE__FOURCC__ABXS 0x41425853
// Background Color.
#define WUFFS_BASE__FOURCC__BGCL 0x4247434C
@@ -778,6 +798,9 @@ typedef struct wuffs_base__transform__output__struct {
// Encapsulated PostScript.
#define WUFFS_BASE__FOURCC__EPS 0x45505320
// Ericsson Texture Compression 2 (iPACKMAN).
#define WUFFS_BASE__FOURCC__ETC2 0x45544332
// Exchangeable Image File Format.
#define WUFFS_BASE__FOURCC__EXIF 0x45584946
@@ -907,6 +930,9 @@ typedef struct wuffs_base__transform__output__struct {
// Truevision Advanced Raster Graphics Adapter.
#define WUFFS_BASE__FOURCC__TGA 0x54474120
// Thumbhash.
#define WUFFS_BASE__FOURCC__TH 0x54482020
// Tagged Image File Format.
#define WUFFS_BASE__FOURCC__TIFF 0x54494646
@@ -4212,6 +4238,46 @@ wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul(
return (a16 << 48) | (r16 << 32) | (g16 << 16) | (b16 << 0);
}
static inline uint8_t //
wuffs_base__color_u64_argb_premul__as__color_u8_gray(uint64_t argb_premul) {
uint32_t r16 = ((uint32_t)(0xFFFF & (argb_premul >> 32)));
uint32_t g16 = ((uint32_t)(0xFFFF & (argb_premul >> 16)));
uint32_t b16 = ((uint32_t)(0xFFFF & (argb_premul >> 0)));
// These coefficients (the fractions 0.299, 0.587 and 0.114) are the same
// as those given by the JFIF specification.
//
// Note that 19595 + 38470 + 7471 equals 65536, also known as (1 << 16). We
// shift by 24, not just by 16, because the return value is 8-bit color, not
// 16-bit color.
uint32_t weighted_average =
(19595 * r16) + (38470 * g16) + (7471 * b16) + 32768;
return (uint8_t)(weighted_average >> 24);
}
static inline uint8_t //
wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray(
uint64_t argb_nonpremul) {
uint32_t a16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 48)));
uint32_t r16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 32)));
r16 = (r16 * a16) / 0xFFFF;
uint32_t g16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 16)));
g16 = (g16 * a16) / 0xFFFF;
uint32_t b16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 0)));
b16 = (b16 * a16) / 0xFFFF;
// These coefficients (the fractions 0.299, 0.587 and 0.114) are the same
// as those given by the JFIF specification.
//
// Note that 19595 + 38470 + 7471 equals 65536, also known as (1 << 16). We
// shift by 24, not just by 16, because the return value is 8-bit color, not
// 16-bit color.
uint32_t weighted_average =
(19595 * r16) + (38470 * g16) + (7471 * b16) + 32768;
return (uint8_t)(weighted_average >> 24);
}
static inline uint64_t //
wuffs_base__color_u32__as__color_u64(uint32_t c) {
uint64_t a16 = 0x101 * (0xFF & (c >> 24));
@@ -4334,6 +4400,20 @@ typedef uint32_t wuffs_base__pixel_alpha_transparency;
// --------
// wuffs_base__pixel_coloration is whether a pixel format's color model has no
// color (alpha only), gray color or rich (non-gray) color. Rich color includes
// RGB, BGR, YCC, YCCK, CMY and CMYK.
//
// Coloration does not capture the alpha aspect of the color model. It does not
// distinguish RGB from RGBA.
typedef uint32_t wuffs_base__pixel_coloration;
#define WUFFS_BASE__PIXEL_COLORATION__NONE 0
#define WUFFS_BASE__PIXEL_COLORATION__GRAY 1
#define WUFFS_BASE__PIXEL_COLORATION__RICH 3
// --------
// Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL.
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4
@@ -4362,6 +4442,7 @@ typedef struct wuffs_base__pixel_format__struct {
inline bool is_indexed() const;
inline bool is_interleaved() const;
inline bool is_planar() const;
inline uint32_t coloration() const;
inline uint32_t num_planes() const;
inline wuffs_base__pixel_alpha_transparency transparency() const;
#endif // __cplusplus
@@ -4468,6 +4549,12 @@ wuffs_base__pixel_format__is_planar(const wuffs_base__pixel_format* f) {
return ((f->repr >> 16) & 0x03) != 0;
}
static inline uint32_t //
wuffs_base__pixel_format__coloration(const wuffs_base__pixel_format* f) {
uint32_t n = (f->repr) >> 29;
return (n <= 1) ? n : 3;
}
static inline uint32_t //
wuffs_base__pixel_format__num_planes(const wuffs_base__pixel_format* f) {
return ((f->repr >> 16) & 0x03) + 1;
@@ -4510,6 +4597,11 @@ wuffs_base__pixel_format::is_planar() const {
return wuffs_base__pixel_format__is_planar(this);
}
inline uint32_t //
wuffs_base__pixel_format::coloration() const {
return wuffs_base__pixel_format__coloration(this);
}
inline uint32_t //
wuffs_base__pixel_format::num_planes() const {
return wuffs_base__pixel_format__num_planes(this);
@@ -4664,7 +4756,7 @@ wuffs_base__pixel_config__set(wuffs_base__pixel_config* c,
}
if (pixfmt_repr) {
do {
#if SIZE_MAX < UINT64_MAX
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
uint64_t wh = ((uint64_t)width) * ((uint64_t)height);
// TODO: handle things other than 1 byte per pixel.
if (wh > ((uint64_t)SIZE_MAX)) {
@@ -7962,7 +8054,7 @@ extern const char wuffs_cbor__error__unsupported_recursion_depth[];
#define WUFFS_CBOR__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 9u
#define WUFFS_CBOR__TOKEN_VALUE_MAJOR 787997u
#define WUFFS_CBOR__TOKEN_VALUE_MAJOR 731642u
#define WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK 262143u
@@ -8935,6 +9027,372 @@ struct wuffs_deflate__decoder__struct {
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_etc2__error__bad_header[];
extern const char wuffs_etc2__error__truncated_input[];
extern const char wuffs_etc2__error__unsupported_etc2_file[];
// ---------------- Public Consts
#define WUFFS_ETC2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_etc2__decoder__struct wuffs_etc2__decoder;
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_etc2__decoder__initialize(
wuffs_etc2__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_etc2__decoder(void);
// ---------------- Allocs
// These functions allocate and initialize Wuffs structs. They return NULL if
// memory allocation fails. If they return non-NULL, there is no need to call
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_etc2__decoder*
wuffs_etc2__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_etc2__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_etc2__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_etc2__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
// ---------------- Public Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__get_quirk(
const wuffs_etc2__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__set_quirk(
wuffs_etc2__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_image_config(
wuffs_etc2__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_frame_config(
wuffs_etc2__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_frame(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_etc2__decoder__frame_dirty_rect(
const wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_etc2__decoder__num_animation_loops(
const wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__num_decoded_frame_configs(
const wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__num_decoded_frames(
const wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__restart_frame(
wuffs_etc2__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_etc2__decoder__set_report_metadata(
wuffs_etc2__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__tell_me_more(
wuffs_etc2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_etc2__decoder__workbuf_len(
const wuffs_etc2__decoder* self);
#ifdef __cplusplus
} // extern "C"
#endif
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
// details that aren't guaranteed to be stable across Wuffs versions.
//
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_etc2__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
//
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
struct {
uint32_t magic;
uint32_t active_coroutine;
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
wuffs_base__vtable null_vtable;
uint32_t f_pixfmt;
uint32_t f_width;
uint32_t f_height;
uint8_t f_call_sequence;
bool f_srgb;
uint32_t f_num_buffered_blocks;
uint32_t f_dst_x;
uint32_t f_dst_y;
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config;
uint32_t p_do_decode_image_config;
uint32_t p_decode_frame_config;
uint32_t p_do_decode_frame_config;
uint32_t p_decode_frame;
uint32_t p_do_decode_frame;
uint32_t p_from_src_to_colors;
} private_impl;
struct {
uint64_t f_alphas[64];
uint64_t f_colors[64];
uint8_t f_buffer[4096];
struct {
uint16_t v_rounded_up_width;
uint16_t v_rounded_up_height;
uint64_t scratch;
} s_do_decode_image_config;
struct {
uint32_t v_remaining;
} s_do_decode_frame;
struct {
uint32_t v_bi;
uint64_t scratch;
} s_from_src_to_colors;
} private_data;
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_etc2__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_etc2__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
// Disallow constructing or copying an object via standard C++ mechanisms,
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
// size and field layout is not part of the public, stable, memory-safe API.
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
// their first argument) rather than tweaking bar.private_impl.qux fields.
//
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_etc2__decoder__struct() = delete;
wuffs_etc2__decoder__struct(const wuffs_etc2__decoder__struct&) = delete;
wuffs_etc2__decoder__struct& operator=(
const wuffs_etc2__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
// As above, the size of the struct is not part of the public API, and unless
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
// allocated, not stack allocated. Its size is not intended to be known at
// compile time, but it is unfortunately divulged as a side effect of
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
// instead of "sizeof T", invoking the operator. To make the two values
// different, so that passing the latter will be rejected by the initialize
// function, we add an arbitrary amount of dead weight.
uint8_t dead_weight[123000000]; // 123 MB.
#endif // !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
initialize(
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_etc2__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
inline wuffs_base__image_decoder*
upcast_as__wuffs_base__image_decoder() {
return (wuffs_base__image_decoder*)this;
}
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_etc2__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_etc2__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_etc2__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_etc2__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_etc2__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_etc2__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_etc2__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_etc2__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_etc2__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_etc2__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_etc2__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
tell_me_more(
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_etc2__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_etc2__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_etc2__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
@@ -8952,19 +9410,19 @@ extern const char wuffs_gif__error__truncated_input[];
#define WUFFS_GIF__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
#define WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES 1041635328u
#define WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES 983928832u
#define WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND 1041635329u
#define WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND 983928833u
#define WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR 1041635330u
#define WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR 983928834u
#define WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA 1041635331u
#define WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA 983928835u
#define WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT 1041635332u
#define WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT 983928836u
#define WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME 1041635333u
#define WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME 983928837u
#define WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE 1041635334u
#define WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE 983928838u
// ---------------- Struct Declarations
@@ -9664,6 +10122,8 @@ extern const char wuffs_jpeg__error__bad_marker[];
extern const char wuffs_jpeg__error__bad_scan_count[];
extern const char wuffs_jpeg__error__missing_huffman_table[];
extern const char wuffs_jpeg__error__missing_quantization_table[];
extern const char wuffs_jpeg__error__rejected_progressive_jpeg[];
extern const char wuffs_jpeg__error__short_sos_bitstream[];
extern const char wuffs_jpeg__error__truncated_input[];
extern const char wuffs_jpeg__error__unsupported_arithmetic_coding[];
extern const char wuffs_jpeg__error__unsupported_color_model[];
@@ -9681,6 +10141,8 @@ extern const char wuffs_jpeg__error__unsupported_scan_count[];
#define WUFFS_JPEG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 51552191232u
#define WUFFS_JPEG__QUIRK_REJECT_PROGRESSIVE_JPEGS 1162824704u
// ---------------- Struct Declarations
typedef struct wuffs_jpeg__decoder__struct wuffs_jpeg__decoder;
@@ -9908,6 +10370,7 @@ struct wuffs_jpeg__decoder__struct {
bool f_bitstream_is_closed;
bool f_expect_multiple_scans;
bool f_use_lower_quality;
bool f_reject_progressive_jpegs;
bool f_swizzle_immediately;
wuffs_base__status f_swizzle_immediately_status;
uint32_t f_swizzle_immediately_b_offsets[10];
@@ -10176,45 +10639,45 @@ extern const char wuffs_json__error__unsupported_recursion_depth[];
#define WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 100u
#define WUFFS_JSON__QUIRK_ALLOW_ASCII_CONTROL_CODES 1225364480u
#define WUFFS_JSON__QUIRK_ALLOW_ASCII_CONTROL_CODES 1167656960u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A 1225364481u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A 1167656961u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U 1225364482u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U 1167656962u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_E 1225364483u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_E 1167656963u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_NEW_LINE 1225364484u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_NEW_LINE 1167656964u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_QUESTION_MARK 1225364485u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_QUESTION_MARK 1167656965u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE 1225364486u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE 1167656966u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_V 1225364487u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_V 1167656967u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS 1225364489u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS 1167656969u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_ZERO 1225364490u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_ZERO 1167656970u
#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK 1225364491u
#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK 1167656971u
#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE 1225364492u
#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE 1167656972u
#define WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA 1225364493u
#define WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA 1167656973u
#define WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS 1225364494u
#define WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS 1167656974u
#define WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR 1225364495u
#define WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR 1167656975u
#define WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK 1225364496u
#define WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK 1167656976u
#define WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER 1225364497u
#define WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER 1167656977u
#define WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF 1225364498u
#define WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF 1167656978u
#define WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T 1225364499u
#define WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T 1167656979u
#define WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE 1225364500u
#define WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE 1167656980u
// ---------------- Struct Declarations
@@ -10460,9 +10923,9 @@ extern const char wuffs_lzma__error__unsupported_properties[];
#define WUFFS_LZMA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 4294967568u
#define WUFFS_LZMA__QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE 1348001792u
#define WUFFS_LZMA__QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE 1290294272u
#define WUFFS_LZMA__QUIRK_FORMAT_EXTENSION 1348001793u
#define WUFFS_LZMA__QUIRK_FORMAT_EXTENSION 1290294273u
// ---------------- Struct Declarations
@@ -11021,7 +11484,7 @@ extern const char wuffs_lzw__error__truncated_input[];
#define WUFFS_LZW__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
#define WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE 1348378624u
#define WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE 1290672128u
// ---------------- Struct Declarations
@@ -11977,7 +12440,7 @@ extern const char wuffs_zlib__error__truncated_input[];
// ---------------- Public Consts
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976u
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2056083456u
#define WUFFS_ZLIB__DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE 0u
@@ -12742,6 +13205,371 @@ struct wuffs_png__decoder__struct {
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_qoi__error__bad_footer[];
extern const char wuffs_qoi__error__bad_header[];
extern const char wuffs_qoi__error__truncated_input[];
// ---------------- Public Consts
#define WUFFS_QOI__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_qoi__decoder__struct wuffs_qoi__decoder;
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_qoi__decoder__initialize(
wuffs_qoi__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_qoi__decoder(void);
// ---------------- Allocs
// These functions allocate and initialize Wuffs structs. They return NULL if
// memory allocation fails. If they return non-NULL, there is no need to call
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_qoi__decoder*
wuffs_qoi__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_qoi__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_qoi__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_qoi__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_qoi__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
// ---------------- Public Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__get_quirk(
const wuffs_qoi__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__set_quirk(
wuffs_qoi__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_image_config(
wuffs_qoi__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_frame_config(
wuffs_qoi__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_frame(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_qoi__decoder__frame_dirty_rect(
const wuffs_qoi__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_qoi__decoder__num_animation_loops(
const wuffs_qoi__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__num_decoded_frame_configs(
const wuffs_qoi__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__num_decoded_frames(
const wuffs_qoi__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__restart_frame(
wuffs_qoi__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_qoi__decoder__set_report_metadata(
wuffs_qoi__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__tell_me_more(
wuffs_qoi__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_qoi__decoder__workbuf_len(
const wuffs_qoi__decoder* self);
#ifdef __cplusplus
} // extern "C"
#endif
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
// details that aren't guaranteed to be stable across Wuffs versions.
//
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_qoi__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
//
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
struct {
uint32_t magic;
uint32_t active_coroutine;
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
wuffs_base__vtable null_vtable;
uint32_t f_pixfmt;
uint32_t f_width;
uint32_t f_height;
uint64_t f_remaining_pixels_times_4;
uint8_t f_call_sequence;
uint32_t f_buffer_index;
uint32_t f_dst_x;
uint32_t f_dst_y;
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config;
uint32_t p_do_decode_image_config;
uint32_t p_decode_frame_config;
uint32_t p_do_decode_frame_config;
uint32_t p_decode_frame;
uint32_t p_do_decode_frame;
uint32_t p_from_src_to_buffer;
} private_impl;
struct {
uint8_t f_pixel[4];
uint8_t f_cache[256];
uint8_t f_buffer[8196];
struct {
uint64_t scratch;
} s_do_decode_image_config;
struct {
uint64_t scratch;
} s_do_decode_frame;
struct {
uint8_t v_dg;
uint32_t v_bi;
uint32_t v_bk;
} s_from_src_to_buffer;
} private_data;
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_qoi__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_qoi__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_qoi__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
// Disallow constructing or copying an object via standard C++ mechanisms,
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
// size and field layout is not part of the public, stable, memory-safe API.
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
// their first argument) rather than tweaking bar.private_impl.qux fields.
//
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_qoi__decoder__struct() = delete;
wuffs_qoi__decoder__struct(const wuffs_qoi__decoder__struct&) = delete;
wuffs_qoi__decoder__struct& operator=(
const wuffs_qoi__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
// As above, the size of the struct is not part of the public API, and unless
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
// allocated, not stack allocated. Its size is not intended to be known at
// compile time, but it is unfortunately divulged as a side effect of
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
// instead of "sizeof T", invoking the operator. To make the two values
// different, so that passing the latter will be rejected by the initialize
// function, we add an arbitrary amount of dead weight.
uint8_t dead_weight[123000000]; // 123 MB.
#endif // !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
initialize(
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_qoi__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
inline wuffs_base__image_decoder*
upcast_as__wuffs_base__image_decoder() {
return (wuffs_base__image_decoder*)this;
}
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_qoi__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_qoi__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_qoi__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_qoi__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_qoi__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_qoi__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_qoi__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_qoi__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_qoi__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_qoi__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_qoi__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
tell_me_more(
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_qoi__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_qoi__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_qoi__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
@@ -12973,22 +13801,22 @@ struct wuffs_sha256__hasher__struct {
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_tga__error__bad_header[];
extern const char wuffs_tga__error__bad_run_length_encoding[];
extern const char wuffs_tga__error__truncated_input[];
extern const char wuffs_tga__error__unsupported_tga_file[];
extern const char wuffs_targa__error__bad_header[];
extern const char wuffs_targa__error__bad_run_length_encoding[];
extern const char wuffs_targa__error__truncated_input[];
extern const char wuffs_targa__error__unsupported_targa_file[];
// ---------------- Public Consts
#define WUFFS_TGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
#define WUFFS_TARGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_tga__decoder__struct wuffs_tga__decoder;
typedef struct wuffs_targa__decoder__struct wuffs_targa__decoder;
#ifdef __cplusplus
extern "C" {
@@ -13003,14 +13831,14 @@ extern "C" {
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_tga__decoder__initialize(
wuffs_tga__decoder* self,
wuffs_targa__decoder__initialize(
wuffs_targa__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_tga__decoder(void);
sizeof__wuffs_targa__decoder(void);
// ---------------- Allocs
@@ -13020,19 +13848,19 @@ sizeof__wuffs_tga__decoder(void);
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_tga__decoder*
wuffs_tga__decoder__alloc(void);
wuffs_targa__decoder*
wuffs_targa__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_tga__decoder__alloc());
wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_targa__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_tga__decoder* p) {
wuffs_targa__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_targa__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
@@ -13040,35 +13868,35 @@ wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__get_quirk(
const wuffs_tga__decoder* self,
wuffs_targa__decoder__get_quirk(
const wuffs_targa__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__set_quirk(
wuffs_tga__decoder* self,
wuffs_targa__decoder__set_quirk(
wuffs_targa__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_image_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_image_config(
wuffs_targa__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_frame_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_frame_config(
wuffs_targa__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_frame(
wuffs_targa__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
@@ -13077,50 +13905,50 @@ wuffs_tga__decoder__decode_frame(
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_tga__decoder__frame_dirty_rect(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__frame_dirty_rect(
const wuffs_targa__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_tga__decoder__num_animation_loops(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__num_animation_loops(
const wuffs_targa__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__num_decoded_frame_configs(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__num_decoded_frame_configs(
const wuffs_targa__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__num_decoded_frames(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__num_decoded_frames(
const wuffs_targa__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__restart_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__restart_frame(
wuffs_targa__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_tga__decoder__set_report_metadata(
wuffs_tga__decoder* self,
wuffs_targa__decoder__set_report_metadata(
wuffs_targa__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__tell_me_more(
wuffs_tga__decoder* self,
wuffs_targa__decoder__tell_me_more(
wuffs_targa__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_tga__decoder__workbuf_len(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__workbuf_len(
const wuffs_targa__decoder* self);
#ifdef __cplusplus
} // extern "C"
@@ -13135,7 +13963,7 @@ wuffs_tga__decoder__workbuf_len(
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_tga__decoder__struct {
struct wuffs_targa__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
@@ -13199,19 +14027,19 @@ struct wuffs_tga__decoder__struct {
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_tga__decoder, wuffs_unique_ptr_deleter>;
using unique_ptr = std::unique_ptr<wuffs_targa__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_tga__decoder__alloc());
return unique_ptr(wuffs_targa__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder());
wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
@@ -13227,10 +14055,10 @@ struct wuffs_tga__decoder__struct {
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_tga__decoder__struct() = delete;
wuffs_tga__decoder__struct(const wuffs_tga__decoder__struct&) = delete;
wuffs_tga__decoder__struct& operator=(
const wuffs_tga__decoder__struct&) = delete;
wuffs_targa__decoder__struct() = delete;
wuffs_targa__decoder__struct(const wuffs_targa__decoder__struct&) = delete;
wuffs_targa__decoder__struct& operator=(
const wuffs_targa__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
@@ -13250,7 +14078,7 @@ struct wuffs_tga__decoder__struct {
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_tga__decoder__initialize(
return wuffs_targa__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
@@ -13262,28 +14090,28 @@ struct wuffs_tga__decoder__struct {
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_tga__decoder__get_quirk(this, a_key);
return wuffs_targa__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_tga__decoder__set_quirk(this, a_key, a_value);
return wuffs_targa__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_tga__decoder__decode_image_config(this, a_dst, a_src);
return wuffs_targa__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_tga__decoder__decode_frame_config(this, a_dst, a_src);
return wuffs_targa__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
@@ -13293,41 +14121,41 @@ struct wuffs_tga__decoder__struct {
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_tga__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
return wuffs_targa__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_tga__decoder__frame_dirty_rect(this);
return wuffs_targa__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_tga__decoder__num_animation_loops(this);
return wuffs_targa__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_tga__decoder__num_decoded_frame_configs(this);
return wuffs_targa__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_tga__decoder__num_decoded_frames(this);
return wuffs_targa__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_tga__decoder__restart_frame(this, a_index, a_io_position);
return wuffs_targa__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_tga__decoder__set_report_metadata(this, a_fourcc, a_report);
return wuffs_targa__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
@@ -13335,20 +14163,397 @@ struct wuffs_tga__decoder__struct {
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_tga__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
return wuffs_targa__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_tga__decoder__workbuf_len(this);
return wuffs_targa__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_tga__decoder__struct
}; // struct wuffs_targa__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_thumbhash__error__bad_header[];
extern const char wuffs_thumbhash__error__truncated_input[];
// ---------------- Public Consts
#define WUFFS_THUMBHASH__QUIRK_JUST_RAW_THUMBHASH 1712283648u
#define WUFFS_THUMBHASH__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_thumbhash__decoder__struct wuffs_thumbhash__decoder;
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_thumbhash__decoder__initialize(
wuffs_thumbhash__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_thumbhash__decoder(void);
// ---------------- Allocs
// These functions allocate and initialize Wuffs structs. They return NULL if
// memory allocation fails. If they return non-NULL, there is no need to call
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_thumbhash__decoder*
wuffs_thumbhash__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_thumbhash__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_thumbhash__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_thumbhash__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
// ---------------- Public Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__get_quirk(
const wuffs_thumbhash__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__set_quirk(
wuffs_thumbhash__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_thumbhash__decoder__frame_dirty_rect(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_thumbhash__decoder__num_animation_loops(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frame_configs(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frames(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__restart_frame(
wuffs_thumbhash__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_thumbhash__decoder__set_report_metadata(
wuffs_thumbhash__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__tell_me_more(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_thumbhash__decoder__workbuf_len(
const wuffs_thumbhash__decoder* self);
#ifdef __cplusplus
} // extern "C"
#endif
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
// details that aren't guaranteed to be stable across Wuffs versions.
//
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_thumbhash__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
//
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
struct {
uint32_t magic;
uint32_t active_coroutine;
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
wuffs_base__vtable null_vtable;
uint32_t f_pixfmt;
uint8_t f_w_dimension_code;
uint8_t f_h_dimension_code;
uint8_t f_call_sequence;
uint8_t f_frame_config_io_position;
uint64_t f_l_dc;
uint64_t f_p_dc;
uint64_t f_q_dc;
uint64_t f_a_dc;
bool f_quirk_just_raw_thumbhash;
uint8_t f_l_scale;
uint8_t f_p_scale;
uint8_t f_q_scale;
uint8_t f_a_scale;
uint8_t f_has_alpha;
uint8_t f_l_count;
uint8_t f_is_landscape;
uint32_t f_lx;
uint32_t f_ly;
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config;
uint32_t p_do_decode_image_config;
uint32_t p_decode_frame_config;
uint32_t p_do_decode_frame_config;
uint32_t p_decode_frame;
uint32_t p_do_decode_frame;
uint32_t p_from_src_to_coeffs;
} private_impl;
struct {
uint32_t f_lac[32];
uint32_t f_pac[8];
uint32_t f_qac[8];
uint32_t f_aac[16];
uint8_t f_pixels[32][128];
struct {
uint64_t scratch;
} s_do_decode_image_config;
struct {
uint32_t v_cy;
uint32_t v_cx;
uint32_t v_i;
bool v_has_bits;
} s_from_src_to_coeffs;
} private_data;
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_thumbhash__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_thumbhash__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
// Disallow constructing or copying an object via standard C++ mechanisms,
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
// size and field layout is not part of the public, stable, memory-safe API.
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
// their first argument) rather than tweaking bar.private_impl.qux fields.
//
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_thumbhash__decoder__struct() = delete;
wuffs_thumbhash__decoder__struct(const wuffs_thumbhash__decoder__struct&) = delete;
wuffs_thumbhash__decoder__struct& operator=(
const wuffs_thumbhash__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
// As above, the size of the struct is not part of the public API, and unless
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
// allocated, not stack allocated. Its size is not intended to be known at
// compile time, but it is unfortunately divulged as a side effect of
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
// instead of "sizeof T", invoking the operator. To make the two values
// different, so that passing the latter will be rejected by the initialize
// function, we add an arbitrary amount of dead weight.
uint8_t dead_weight[123000000]; // 123 MB.
#endif // !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
initialize(
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_thumbhash__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
inline wuffs_base__image_decoder*
upcast_as__wuffs_base__image_decoder() {
return (wuffs_base__image_decoder*)this;
}
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_thumbhash__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_thumbhash__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_thumbhash__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_thumbhash__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_thumbhash__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_thumbhash__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_thumbhash__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_thumbhash__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_thumbhash__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
tell_me_more(
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_thumbhash__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_thumbhash__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__VP8) || defined(WUFFS_NONMONOLITHIC)
@@ -14764,7 +15969,7 @@ extern const char wuffs_xz__error__unsupported_filter_combination[];
// ---------------- Public Consts
#define WUFFS_XZ__QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS 2021322752u
#define WUFFS_XZ__QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS 1963655168u
#define WUFFS_XZ__DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE 0u
@@ -15353,18 +16558,26 @@ class DecodeImageCallbacks {
//
// The default SelectDecoder accepts the FOURCC codes listed below. For
// modular builds (i.e. when #define'ing WUFFS_CONFIG__MODULES), acceptance
// of the ETC file format is optional (for each value of ETC) and depends on
// of the FOO file format is optional (for each value of FOO) and depends on
// the corresponding module to be enabled at compile time (i.e. #define'ing
// WUFFS_CONFIG__MODULE__ETC).
// WUFFS_CONFIG__MODULE__FOO).
//
// - WUFFS_BASE__FOURCC__BMP
// - WUFFS_BASE__FOURCC__ETC2
// - WUFFS_BASE__FOURCC__GIF
// - WUFFS_BASE__FOURCC__JPEG
// - WUFFS_BASE__FOURCC__NIE
// - WUFFS_BASE__FOURCC__NPBM
// - WUFFS_BASE__FOURCC__PNG
// - WUFFS_BASE__FOURCC__TGA
// - WUFFS_BASE__FOURCC__QOI
// - WUFFS_BASE__FOURCC__TARGA
// - WUFFS_BASE__FOURCC__TH
// - WUFFS_BASE__FOURCC__WBMP
// - WUFFS_BASE__FOURCC__WEBP
//
// The FOOBAR in WUFFS_BASE__FOURCC__FOBA is limited to four characters, but
// the FOOBAR in the corresponding WUFFS_CONFIG__MODULE__FOOBAR macro might
// be fuller and longer. For example, NPBM / NETPBM or TH / THUMBHASH.
virtual wuffs_base__image_decoder::unique_ptr //
SelectDecoder(uint32_t fourcc,
wuffs_base__slice_u8 prefix_data,
@@ -15373,8 +16586,8 @@ class DecodeImageCallbacks {
// 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.
// If it is METADATA_RAW_PASSTHROUGH 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 |
@@ -15388,6 +16601,7 @@ class DecodeImageCallbacks {
// 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__Y
// - WUFFS_BASE__PIXEL_FORMAT__BGR_565
// - WUFFS_BASE__PIXEL_FORMAT__BGR
// - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL
@@ -15490,7 +16704,7 @@ struct DecodeImageArgFlags {
// DefaultValue returns 0.
static DecodeImageArgFlags DefaultValue();
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
// TODO: support all of the REPORT_METADATA_FOO flags, not just CHRM, EXIF,
// GAMA, ICCP, KVP, SRGB and XMP.
// Background Color.
@@ -15737,6 +16951,131 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
#endif // defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
// ---------------- Wuffs' reimplementation of the STB API.
//
// This is a drop-in replacement of that third-party library.
//
// Disabled by default, unless you #define the
// WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB macro beforehand.
//
// For API docs, see https://github.com/nothings/stb
#if defined(WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
#ifdef __cplusplus
extern "C" {
#endif
#if defined(WUFFS_CONFIG__STATIC_FUNCTIONS) || defined(STB_IMAGE_STATIC)
#define WUFFS_DROP_IN__STB__MAYBE_STATIC static
#else
#define WUFFS_DROP_IN__STB__MAYBE_STATIC
#endif
enum {
STBI_default = 0,
STBI_grey = 1,
STBI_grey_alpha = 2,
STBI_rgb = 3,
STBI_rgb_alpha = 4
};
typedef unsigned char stbi_uc;
typedef unsigned short stbi_us;
typedef struct {
int (*read)(void* user, char* data, int size);
void (*skip)(void* user, int n);
int (*eof)(void* user);
} stbi_io_callbacks;
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
// --------
#if !defined(STBI_NO_STDIO)
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info( //
char const* filename, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load( //
char const* filename, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_file( //
FILE* f, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_file( //
FILE* f, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
#endif // !defined(STBI_NO_STDIO)
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC void //
stbi_image_free( //
void* retval_from_stbi_load);
WUFFS_DROP_IN__STB__MAYBE_STATIC const char* //
stbi_failure_reason(void);
#ifdef __cplusplus
}
#endif
#endif // defined (WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
// ‼ WUFFS C HEADER ENDS HERE.
#ifdef WUFFS_IMPLEMENTATION
@@ -15909,12 +17248,24 @@ wuffs_private_impl__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {
// ---------------- Numeric Types (Utility)
#define wuffs_base__utility__i64_divide(a, b) \
((uint64_t)(((int64_t)(a)) / ((int64_t)(b))))
#define wuffs_base__utility__sign_extend_convert_u8_u32(a) \
((uint32_t)(int32_t)(int8_t)(a))
#define wuffs_base__utility__sign_extend_convert_u8_u64(a) \
((uint64_t)(int64_t)(int8_t)(a))
#define wuffs_base__utility__sign_extend_convert_u16_u32(a) \
((uint32_t)(int32_t)(int16_t)(a))
#define wuffs_base__utility__sign_extend_convert_u16_u64(a) \
((uint64_t)(int64_t)(int16_t)(a))
#define wuffs_base__utility__sign_extend_convert_u32_u64(a) \
((uint64_t)(int64_t)(int32_t)(a))
#define wuffs_base__utility__sign_extend_rshift_u32(a, n) \
((uint32_t)(((int32_t)(a)) >> (n)))
@@ -21622,26 +22973,31 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
int32_t fourcc;
const char* magic;
} table[] = {
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm)
{+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA
{+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x41425852, "\x03\x03\x00\x08\x00"}, // ABXR
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
{+0x584D4C20, "\x05\x3C\x3F\x78\x6D\x6C\x20"}, // XML
{+0x41425853, "\x03\x41\x42\x58\x00"}, // ABXS
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{+0x45544332, "\x03\x50\x4B\x4D\x20"}, // ETC2 (*.pkm)
{+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm)
{+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA
{+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x54482020, "\x02\xC3\xBE\xFE"}, // TH
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
};
static const size_t table_len = sizeof(table) / sizeof(table[0]);
@@ -21875,9 +23231,8 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
wuffs_base__peek_u32le__no_bounds_check(row + (4 * ((size_t)x)));
case WUFFS_BASE__PIXEL_FORMAT__RGB:
return wuffs_private_impl__swap_u32_argb_abgr(
0xFF000000 |
wuffs_base__peek_u24le__no_bounds_check(row + (3 * ((size_t)x))));
return 0xFF000000 |
wuffs_base__peek_u24be__no_bounds_check(row + (3 * ((size_t)x)));
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
return wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
@@ -21983,6 +23338,10 @@ wuffs_base__pixel_buffer__set_color_u32_at(
wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul(
color));
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
wuffs_base__poke_u32le__no_bounds_check(
row + (4 * ((size_t)x)), (color >> 31) ? (color | 0xFF000000) : 0);
break;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
wuffs_base__poke_u24le__no_bounds_check(
@@ -22588,6 +23947,34 @@ wuffs_private_impl__swizzle_squash_align4_bgr_565_8888(uint8_t* dst_ptr,
// --------
static uint64_t //
wuffs_private_impl__swizzle_squash_align4_y_8888(uint8_t* dst_ptr,
size_t dst_len,
const uint8_t* src_ptr,
size_t src_len,
bool nonpremul) {
size_t len = (dst_len < src_len ? dst_len : src_len) / 4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
while (n--) {
uint32_t argb = wuffs_base__peek_u32le__no_bounds_check(s);
if (nonpremul) {
argb =
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(argb);
}
uint32_t s0 = wuffs_base__color_u32_argb_premul__as__color_u8_gray(argb);
wuffs_base__poke_u32le__no_bounds_check(
d, (argb & 0xFF000000) | (s0 * 0x010101));
s += 4;
d += 4;
}
return len;
}
// --------
static uint64_t //
wuffs_private_impl__swizzle_swap_rgb_bgr(uint8_t* dst_ptr,
size_t dst_len,
@@ -26413,6 +27800,62 @@ wuffs_private_impl__swizzle_xxxxxxxx__y_16be(uint8_t* dst_ptr,
// --------
static uint64_t //
wuffs_private_impl__swizzle_y__bgr(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len3 = src_len / 3;
size_t len = (dst_len < src_len3) ? dst_len : src_len3;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u24le__no_bounds_check(s + (0 * 3));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 3;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgr_565(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(
wuffs_base__peek_u16le__no_bounds_check(s + (0 * 2)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
@@ -26426,6 +27869,8 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
@@ -26454,6 +27899,8 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over(
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
@@ -26468,6 +27915,154 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over(
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len8 = src_len / 8;
size_t len = (dst_len < src_len8) ? dst_len : src_len8;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray(
wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8)));
s += 1 * 8;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len8 = src_len / 8;
size_t len = (dst_len < src_len8) ? dst_len : src_len8;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[0]);
uint32_t dg = 0x101 * ((uint32_t)d[0]);
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));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
// Composite src (nonpremul) over dst (premul).
dr = ((sr * sa) + (dr * ia)) / 0xFFFF;
dg = ((sg * sa) + (dg * ia)) / 0xFFFF;
db = ((sb * sa) + (db * ia)) / 0xFFFF;
// Convert to 16-bit color to 8-bit gray.
uint32_t weighted_average =
(19595 * dr) + (38470 * dg) + (7471 * db) + 32768;
d[0] = (uint8_t)(weighted_average >> 24);
s += 1 * 8;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_premul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_premul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[0]);
uint32_t dg = 0x101 * ((uint32_t)d[0]);
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]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
// Composite src (premul) over dst (premul).
dr = sr + ((dr * ia) / 0xFFFF);
dg = sg + ((dg * ia) / 0xFFFF);
db = sb + ((db * ia) / 0xFFFF);
// Convert to 16-bit color to 8-bit gray.
uint32_t weighted_average =
(19595 * dr) + (38470 * dg) + (7471 * db) + 32768;
d[0] = (uint8_t)(weighted_average >> 24);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
size_t dst_len,
@@ -26481,6 +28076,8 @@ wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
@@ -26494,6 +28091,152 @@ wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgb(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len3 = src_len / 3;
size_t len = (dst_len < src_len3) ? dst_len : src_len3;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u24be__no_bounds_check(s + (0 * 3));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 3;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_nonpremul__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_premul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_premul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_premul_u32_axxx(d0, s0));
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
size_t dst_len,
@@ -26507,6 +28250,8 @@ wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = s[0];
@@ -26518,6 +28263,162 @@ wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__ya_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
d[0] = (uint8_t)
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__ya_nonpremul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | ((uint32_t)(d[0]) * 0x010101);
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
d[0] = (uint8_t)wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0,
s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = dst_palette_ptr[(size_t)s[0] * 4];
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index_bgra_nonpremul__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr +
((size_t)s[0] * 4));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index_binary_alpha__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr +
((size_t)s[0] * 4));
if (s0) {
d[0] = (uint8_t)s0;
}
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
// --------
static uint64_t //
wuffs_private_impl__swizzle_y_16le__y_16be(uint8_t* dst_ptr,
size_t dst_len,
@@ -26706,6 +28607,15 @@ wuffs_private_impl__pixel_swizzler__prepare__ya_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__ya_nonpremul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__ya_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -26775,6 +28685,26 @@ wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
if (wuffs_private_impl__swizzle_squash_align4_y_8888(
dst_palette.ptr, dst_palette.len, src_palette.ptr,
src_palette.len, true) !=
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
return NULL;
}
return wuffs_private_impl__swizzle_y__index__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
src_palette) !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return NULL;
}
return wuffs_private_impl__swizzle_y__index_bgra_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
src_palette) !=
@@ -26947,6 +28877,21 @@ wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_binary(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
if (wuffs_private_impl__swizzle_squash_align4_y_8888(
dst_palette.ptr, dst_palette.len, src_palette.ptr,
src_palette.len, false) !=
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
return NULL;
}
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__index__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__index_binary_alpha__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
@@ -27064,6 +29009,9 @@ wuffs_private_impl__pixel_swizzler__prepare__bgr_565(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__bgr_565;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_copy_2_2;
@@ -27100,6 +29048,9 @@ wuffs_private_impl__pixel_swizzler__prepare__bgr(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__bgr;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_bgr_565__bgr;
@@ -27253,6 +29204,15 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -27346,6 +29306,15 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_premul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -27426,6 +29395,109 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_premul(
return NULL;
}
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
wuffs_private_impl__pixel_swizzler__prepare__bgra_binary(
wuffs_base__pixel_swizzler* p,
wuffs_base__pixel_format dst_pixfmt,
wuffs_base__slice_u8 dst_palette,
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_copy_4_4;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_copy_4_4;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_premul__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr__rgba_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_premul__rgba_premul__src_over;
}
return NULL;
}
return NULL;
}
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
wuffs_private_impl__pixel_swizzler__prepare__bgrx(
wuffs_base__pixel_swizzler* p,
@@ -27474,6 +29546,9 @@ wuffs_private_impl__pixel_swizzler__prepare__rgb(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__rgb;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_bgr_565__rgb;
@@ -27519,6 +29594,15 @@ wuffs_private_impl__pixel_swizzler__prepare__rgba_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__rgba_nonpremul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__rgba_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -27617,6 +29701,15 @@ wuffs_private_impl__pixel_swizzler__prepare__rgba_premul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__rgba_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -27718,6 +29811,10 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
switch (dst_pixfmt.repr) {
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y)
case WUFFS_BASE__PIXEL_FORMAT__Y:
break;
#endif
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565)
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
break;
@@ -27844,6 +29941,11 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
p, dst_pixfmt, dst_palette, src_palette, blend);
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
func = wuffs_private_impl__pixel_swizzler__prepare__bgra_binary(
p, dst_pixfmt, dst_palette, src_palette, blend);
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
func = wuffs_private_impl__pixel_swizzler__prepare__bgrx(
p, dst_pixfmt, dst_palette, src_palette, blend);
@@ -29298,6 +31400,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
switch (dst->pixcfg.private_impl.pixfmt.repr) {
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y)
case WUFFS_BASE__PIXEL_FORMAT__Y:
break;
#endif
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565)
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
break;
@@ -30483,7 +32589,7 @@ wuffs_adler32__hasher__initialize(
wuffs_adler32__hasher*
wuffs_adler32__hasher__alloc(void) {
wuffs_adler32__hasher* x =
(wuffs_adler32__hasher*)(calloc(sizeof(wuffs_adler32__hasher), 1));
(wuffs_adler32__hasher*)(calloc(1, sizeof(wuffs_adler32__hasher)));
if (!x) {
return NULL;
}
@@ -31089,7 +33195,7 @@ wuffs_bmp__decoder__initialize(
wuffs_bmp__decoder*
wuffs_bmp__decoder__alloc(void) {
wuffs_bmp__decoder* x =
(wuffs_bmp__decoder*)(calloc(sizeof(wuffs_bmp__decoder), 1));
(wuffs_bmp__decoder*)(calloc(1, sizeof(wuffs_bmp__decoder)));
if (!x) {
return NULL;
}
@@ -33855,7 +35961,7 @@ wuffs_bzip2__decoder__initialize(
wuffs_bzip2__decoder*
wuffs_bzip2__decoder__alloc(void) {
wuffs_bzip2__decoder* x =
(wuffs_bzip2__decoder*)(calloc(sizeof(wuffs_bzip2__decoder), 1));
(wuffs_bzip2__decoder*)(calloc(1, sizeof(wuffs_bzip2__decoder)));
if (!x) {
return NULL;
}
@@ -35413,7 +37519,7 @@ wuffs_cbor__decoder__initialize(
wuffs_cbor__decoder*
wuffs_cbor__decoder__alloc(void) {
wuffs_cbor__decoder* x =
(wuffs_cbor__decoder*)(calloc(sizeof(wuffs_cbor__decoder), 1));
(wuffs_cbor__decoder*)(calloc(1, sizeof(wuffs_cbor__decoder)));
if (!x) {
return NULL;
}
@@ -35689,7 +37795,7 @@ wuffs_cbor__decoder__decode_tokens(
(((uint64_t)(((uint32_t)(WUFFS_CBOR__TOKEN_LENGTHS[v_c_minor])))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
} else {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(16777216u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(9u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
}
@@ -35913,12 +38019,12 @@ wuffs_cbor__decoder__decode_tokens(
}
if (v_string_length < 262144u) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)((4194304u | ((uint32_t)(v_string_length))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(((uint32_t)(WUFFS_CBOR__TOKEN_LENGTHS[v_c_minor])))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
} else {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)((4194304u | ((uint32_t)((v_string_length >> 46u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
(((uint64_t)(0u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
@@ -35931,7 +38037,7 @@ wuffs_cbor__decoder__decode_tokens(
} else if (v_c_major == 7u) {
if (v_c_minor < 20u) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)((8388608u | ((uint32_t)((v_string_length & 255u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(1u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
goto label__goto_parsed_a_leaf_value__break;
@@ -35950,7 +38056,7 @@ wuffs_cbor__decoder__decode_tokens(
break;
}
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)((8388608u | ((uint32_t)((v_string_length & 255u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(2u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
goto label__goto_parsed_a_leaf_value__break;
@@ -36725,7 +38831,7 @@ wuffs_crc32__ieee_hasher__initialize(
wuffs_crc32__ieee_hasher*
wuffs_crc32__ieee_hasher__alloc(void) {
wuffs_crc32__ieee_hasher* x =
(wuffs_crc32__ieee_hasher*)(calloc(sizeof(wuffs_crc32__ieee_hasher), 1));
(wuffs_crc32__ieee_hasher*)(calloc(1, sizeof(wuffs_crc32__ieee_hasher)));
if (!x) {
return NULL;
}
@@ -37560,7 +39666,7 @@ wuffs_crc64__ecma_hasher__initialize(
wuffs_crc64__ecma_hasher*
wuffs_crc64__ecma_hasher__alloc(void) {
wuffs_crc64__ecma_hasher* x =
(wuffs_crc64__ecma_hasher*)(calloc(sizeof(wuffs_crc64__ecma_hasher), 1));
(wuffs_crc64__ecma_hasher*)(calloc(1, sizeof(wuffs_crc64__ecma_hasher)));
if (!x) {
return NULL;
}
@@ -38111,7 +40217,7 @@ wuffs_deflate__decoder__initialize(
wuffs_deflate__decoder*
wuffs_deflate__decoder__alloc(void) {
wuffs_deflate__decoder* x =
(wuffs_deflate__decoder*)(calloc(sizeof(wuffs_deflate__decoder), 1));
(wuffs_deflate__decoder*)(calloc(1, sizeof(wuffs_deflate__decoder)));
if (!x) {
return NULL;
}
@@ -40248,6 +42354,1908 @@ wuffs_deflate__decoder__decode_huffman_slow(
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
// ---------------- Status Codes Implementations
const char wuffs_etc2__error__bad_header[] = "#etc2: bad header";
const char wuffs_etc2__error__truncated_input[] = "#etc2: truncated input";
const char wuffs_etc2__error__unsupported_etc2_file[] = "#etc2: unsupported ETC2 file";
// ---------------- Private Consts
static const uint32_t
WUFFS_ETC2__DIFFS[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 1u, 2u, 3u, 4294967292u, 4294967293u, 4294967294u, 4294967295u,
};
static const uint32_t
WUFFS_ETC2__MODIFIERS[16][4] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
2u, 8u, 4294967294u, 4294967288u,
}, {
5u, 17u, 4294967291u, 4294967279u,
}, {
9u, 29u, 4294967287u, 4294967267u,
}, {
13u, 42u, 4294967283u, 4294967254u,
}, {
18u, 60u, 4294967278u, 4294967236u,
}, {
24u, 80u, 4294967272u, 4294967216u,
}, {
33u, 106u, 4294967263u, 4294967190u,
}, {
47u, 183u, 4294967249u, 4294967113u,
},
{
0u, 8u, 0u, 4294967288u,
}, {
0u, 17u, 0u, 4294967279u,
}, {
0u, 29u, 0u, 4294967267u,
}, {
0u, 42u, 0u, 4294967254u,
}, {
0u, 60u, 0u, 4294967236u,
}, {
0u, 80u, 0u, 4294967216u,
}, {
0u, 106u, 0u, 4294967190u,
}, {
0u, 183u, 0u, 4294967113u,
},
};
static const uint8_t
WUFFS_ETC2__T_H_MODIFIERS[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
3u, 6u, 11u, 16u, 23u, 32u, 41u, 64u,
};
static const uint32_t
WUFFS_ETC2__ALPHA_MODIFIERS[16][8] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
4294967293u, 4294967290u, 4294967287u, 4294967281u, 2u, 5u, 8u, 14u,
}, {
4294967293u, 4294967289u, 4294967286u, 4294967283u, 2u, 6u, 9u, 12u,
}, {
4294967294u, 4294967291u, 4294967288u, 4294967283u, 1u, 4u, 7u, 12u,
}, {
4294967294u, 4294967292u, 4294967290u, 4294967283u, 1u, 3u, 5u, 12u,
}, {
4294967293u, 4294967290u, 4294967288u, 4294967284u, 2u, 5u, 7u, 11u,
}, {
4294967293u, 4294967289u, 4294967287u, 4294967285u, 2u, 6u, 8u, 10u,
}, {
4294967292u, 4294967289u, 4294967288u, 4294967285u, 3u, 6u, 7u, 10u,
}, {
4294967293u, 4294967291u, 4294967288u, 4294967285u, 2u, 4u, 7u, 10u,
},
{
4294967294u, 4294967290u, 4294967288u, 4294967286u, 1u, 5u, 7u, 9u,
}, {
4294967294u, 4294967291u, 4294967288u, 4294967286u, 1u, 4u, 7u, 9u,
}, {
4294967294u, 4294967292u, 4294967288u, 4294967286u, 1u, 3u, 7u, 9u,
}, {
4294967294u, 4294967291u, 4294967289u, 4294967286u, 1u, 4u, 6u, 9u,
}, {
4294967293u, 4294967292u, 4294967289u, 4294967286u, 2u, 3u, 6u, 9u,
}, {
4294967295u, 4294967294u, 4294967293u, 4294967286u, 0u, 1u, 2u, 9u,
}, {
4294967292u, 4294967290u, 4294967288u, 4294967287u, 3u, 5u, 7u, 8u,
}, {
4294967293u, 4294967291u, 4294967289u, 4294967287u, 2u, 4u, 6u, 8u,
},
};
static const uint8_t
WUFFS_ETC2__CLAMP[1024] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u,
8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u,
16u, 17u, 18u, 19u, 20u, 21u, 22u, 23u,
24u, 25u, 26u, 27u, 28u, 29u, 30u, 31u,
32u, 33u, 34u, 35u, 36u, 37u, 38u, 39u,
40u, 41u, 42u, 43u, 44u, 45u, 46u, 47u,
48u, 49u, 50u, 51u, 52u, 53u, 54u, 55u,
56u, 57u, 58u, 59u, 60u, 61u, 62u, 63u,
64u, 65u, 66u, 67u, 68u, 69u, 70u, 71u,
72u, 73u, 74u, 75u, 76u, 77u, 78u, 79u,
80u, 81u, 82u, 83u, 84u, 85u, 86u, 87u,
88u, 89u, 90u, 91u, 92u, 93u, 94u, 95u,
96u, 97u, 98u, 99u, 100u, 101u, 102u, 103u,
104u, 105u, 106u, 107u, 108u, 109u, 110u, 111u,
112u, 113u, 114u, 115u, 116u, 117u, 118u, 119u,
120u, 121u, 122u, 123u, 124u, 125u, 126u, 127u,
128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u,
136u, 137u, 138u, 139u, 140u, 141u, 142u, 143u,
144u, 145u, 146u, 147u, 148u, 149u, 150u, 151u,
152u, 153u, 154u, 155u, 156u, 157u, 158u, 159u,
160u, 161u, 162u, 163u, 164u, 165u, 166u, 167u,
168u, 169u, 170u, 171u, 172u, 173u, 174u, 175u,
176u, 177u, 178u, 179u, 180u, 181u, 182u, 183u,
184u, 185u, 186u, 187u, 188u, 189u, 190u, 191u,
192u, 193u, 194u, 195u, 196u, 197u, 198u, 199u,
200u, 201u, 202u, 203u, 204u, 205u, 206u, 207u,
208u, 209u, 210u, 211u, 212u, 213u, 214u, 215u,
216u, 217u, 218u, 219u, 220u, 221u, 222u, 223u,
224u, 225u, 226u, 227u, 228u, 229u, 230u, 231u,
232u, 233u, 234u, 235u, 236u, 237u, 238u, 239u,
240u, 241u, 242u, 243u, 244u, 245u, 246u, 247u,
248u, 249u, 250u, 251u, 252u, 253u, 254u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
};
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_image_config(
wuffs_etc2__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_frame_config(
wuffs_etc2__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_frame(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__from_src_to_colors(
wuffs_etc2__decoder* self,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__from_colors_to_buffer(
wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_t_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset,
bool a_transparent);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_h_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset,
bool a_transparent);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_planar_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_half_block(
wuffs_etc2__decoder* self,
uint32_t a_bits,
uint32_t a_offset,
uint32_t a_which,
uint32_t a_r,
uint32_t a_g,
uint32_t a_b,
bool a_flip,
bool a_transparent,
bool a_second);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__from_alphas_to_buffer(
wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__from_buffer_to_dst(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_etc2__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_etc2__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_etc2__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_etc2__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_etc2__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_etc2__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_etc2__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_etc2__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_etc2__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_etc2__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_etc2__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_etc2__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_etc2__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_etc2__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_etc2__decoder__initialize(
wuffs_etc2__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (sizeof(*self) != sizeof_star_self) {
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
}
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
}
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
// The whole point of this if-check is to detect an uninitialized *self.
// We disable the warning on GCC. Clang-5.0 does not have this warning.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (self->private_impl.magic != 0) {
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
}
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_etc2__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_etc2__decoder*
wuffs_etc2__decoder__alloc(void) {
wuffs_etc2__decoder* x =
(wuffs_etc2__decoder*)(calloc(1, sizeof(wuffs_etc2__decoder)));
if (!x) {
return NULL;
}
if (wuffs_etc2__decoder__initialize(
x, sizeof(wuffs_etc2__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
return x;
}
size_t
sizeof__wuffs_etc2__decoder(void) {
return sizeof(wuffs_etc2__decoder);
}
// ---------------- Function Implementations
// -------- func etc2.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__get_quirk(
const wuffs_etc2__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func etc2.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__set_quirk(
wuffs_etc2__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func etc2.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_image_config(
wuffs_etc2__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_etc2__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_etc2__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func etc2.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_image_config(
wuffs_etc2__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_c32 = 0;
uint16_t v_rounded_up_width = 0;
uint16_t v_rounded_up_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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config;
if (coro_susp_point) {
v_rounded_up_width = self->private_data.s_do_decode_image_config.v_rounded_up_width;
v_rounded_up_height = self->private_data.s_do_decode_image_config.v_rounded_up_height;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0u) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
{
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_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 == 24) {
t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_c32 = t_0;
}
if (v_c32 != 541936464u) {
status = wuffs_base__make_status(wuffs_etc2__error__bad_header);
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_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 += 8u;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
v_c32 = t_1;
}
if ((v_c32 == 12337u) || (v_c32 == 16789554u) || (v_c32 == 151007282u)) {
self->private_impl.f_pixfmt = 2415954056u;
} else if ((v_c32 == 50343986u) || (v_c32 == 167784498u)) {
self->private_impl.f_pixfmt = 2164295816u;
} else if ((v_c32 == 67121202u) || (v_c32 == 184561714u)) {
self->private_impl.f_pixfmt = 2197850248u;
} else if ((v_c32 & 65535u) == 12338u) {
status = wuffs_base__make_status(wuffs_etc2__error__unsupported_etc2_file);
goto exit;
} else {
status = wuffs_base__make_status(wuffs_etc2__error__bad_header);
goto exit;
}
self->private_impl.f_srgb = ((v_c32 >> 24u) >= 9u);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint16_t t_2;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_2 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2);
if (num_bits_2 == 8) {
t_2 = ((uint16_t)(*scratch >> 48));
break;
}
num_bits_2 += 8u;
*scratch |= ((uint64_t)(num_bits_2));
}
}
v_rounded_up_width = t_2;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
uint16_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_3 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 8) {
t_3 = ((uint16_t)(*scratch >> 48));
break;
}
num_bits_3 += 8u;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_rounded_up_height = t_3;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
uint32_t t_4;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_4 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4);
if (num_bits_4 == 8) {
t_4 = ((uint32_t)(*scratch >> 48));
break;
}
num_bits_4 += 8u;
*scratch |= ((uint64_t)(num_bits_4));
}
}
v_c32 = t_4;
}
if (((v_c32 + 3u) & 4294967292u) != ((uint32_t)(v_rounded_up_width))) {
status = wuffs_base__make_status(wuffs_etc2__error__bad_header);
goto exit;
}
self->private_impl.f_width = v_c32;
{
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_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFFu));
*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 += 8u;
*scratch |= ((uint64_t)(num_bits_5));
}
}
v_c32 = t_5;
}
if (((v_c32 + 3u) & 4294967292u) != ((uint32_t)(v_rounded_up_height))) {
status = wuffs_base__make_status(wuffs_etc2__error__bad_header);
goto exit;
}
self->private_impl.f_height = v_c32;
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
self->private_impl.f_pixfmt,
0u,
self->private_impl.f_width,
self->private_impl.f_height,
16u,
(self->private_impl.f_pixfmt == 2415954056u));
}
self->private_impl.f_call_sequence = 32u;
goto ok;
ok:
self->private_impl.p_do_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_image_config.v_rounded_up_width = v_rounded_up_width;
self->private_data.s_do_decode_image_config.v_rounded_up_height = v_rounded_up_height;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func etc2.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_frame_config(
wuffs_etc2__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 2)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_etc2__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_etc2__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func etc2.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_frame_config(
wuffs_etc2__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 32u) {
} else if (self->private_impl.f_call_sequence < 32u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_etc2__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 40u) {
if (16u != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
goto exit;
}
} else if (self->private_impl.f_call_sequence == 64u) {
self->private_impl.f_call_sequence = 96u;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height),
((wuffs_base__flicks)(0u)),
0u,
16u,
0u,
(self->private_impl.f_pixfmt == 2415954056u),
false,
4278190080u);
}
self->private_impl.f_call_sequence = 64u;
ok:
self->private_impl.p_do_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func etc2.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_frame(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 3)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_etc2__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_etc2__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func etc2.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_frame(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_remaining = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame;
if (coro_susp_point) {
v_remaining = self->private_data.s_do_decode_frame.v_remaining;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64u) {
} else if (self->private_impl.f_call_sequence < 64u) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_etc2__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
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(a_dst),
wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
wuffs_base__utility__empty_slice_u8(),
a_blend);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
self->private_impl.f_dst_x = 0u;
self->private_impl.f_dst_y = 0u;
v_remaining = (((self->private_impl.f_width + 3u) / 4u) * ((self->private_impl.f_height + 3u) / 4u));
while (v_remaining > 0u) {
self->private_impl.f_num_buffered_blocks = wuffs_base__u32__min(v_remaining, 64u);
if (v_remaining < self->private_impl.f_num_buffered_blocks) {
status = wuffs_base__make_status(wuffs_base__error__too_much_data);
goto exit;
}
v_remaining -= self->private_impl.f_num_buffered_blocks;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_etc2__decoder__from_src_to_colors(self, a_src);
if (status.repr) {
goto suspend;
}
wuffs_etc2__decoder__from_colors_to_buffer(self);
if (self->private_impl.f_pixfmt == 2164295816u) {
wuffs_etc2__decoder__from_alphas_to_buffer(self);
}
v_status = wuffs_etc2__decoder__from_buffer_to_dst(self, a_dst);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
}
self->private_impl.f_call_sequence = 96u;
ok:
self->private_impl.p_do_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_frame.v_remaining = v_remaining;
goto exit;
exit:
return status;
}
// -------- func etc2.decoder.from_src_to_colors
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__from_src_to_colors(
wuffs_etc2__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_bi = 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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_from_src_to_colors;
if (coro_susp_point) {
v_bi = self->private_data.s_from_src_to_colors.v_bi;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (v_bi < self->private_impl.f_num_buffered_blocks) {
if (self->private_impl.f_pixfmt == 2164295816u) {
{
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_u64be__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_from_src_to_colors.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_from_src_to_colors.scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 56) {
t_0 = ((uint64_t)(*scratch >> 0));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_data.f_alphas[v_bi] = t_0;
}
}
{
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_u64be__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_from_src_to_colors.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_from_src_to_colors.scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 56) {
t_1 = ((uint64_t)(*scratch >> 0));
break;
}
num_bits_1 += 8u;
*scratch |= ((uint64_t)(num_bits_1));
}
}
self->private_data.f_colors[v_bi] = t_1;
}
v_bi += 1u;
}
goto ok;
ok:
self->private_impl.p_from_src_to_colors = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_from_src_to_colors = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_from_src_to_colors.v_bi = v_bi;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func etc2.decoder.from_colors_to_buffer
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__from_colors_to_buffer(
wuffs_etc2__decoder* self) {
uint32_t v_bi = 0;
uint64_t v_color = 0;
uint32_t v_r0 = 0;
uint32_t v_r1 = 0;
uint32_t v_g0 = 0;
uint32_t v_g1 = 0;
uint32_t v_b0 = 0;
uint32_t v_b1 = 0;
bool v_diff = false;
bool v_tran = false;
bool v_flip = false;
while (v_bi < self->private_impl.f_num_buffered_blocks) {
v_color = self->private_data.f_colors[v_bi];
v_diff = ((v_color & 8589934592u) != 0u);
v_tran = ( ! v_diff && (self->private_impl.f_pixfmt == 2197850248u));
if ( ! v_diff && (self->private_impl.f_pixfmt != 2197850248u)) {
v_r0 = ((uint32_t)((15u & (v_color >> 60u))));
v_r0 = ((v_r0 << 4u) | v_r0);
v_r1 = ((uint32_t)((15u & (v_color >> 56u))));
v_r1 = ((v_r1 << 4u) | v_r1);
v_g0 = ((uint32_t)((15u & (v_color >> 52u))));
v_g0 = ((v_g0 << 4u) | v_g0);
v_g1 = ((uint32_t)((15u & (v_color >> 48u))));
v_g1 = ((v_g1 << 4u) | v_g1);
v_b0 = ((uint32_t)((15u & (v_color >> 44u))));
v_b0 = ((v_b0 << 4u) | v_b0);
v_b1 = ((uint32_t)((15u & (v_color >> 40u))));
v_b1 = ((v_b1 << 4u) | v_b1);
} else {
v_r0 = ((uint32_t)((31u & (v_color >> 59u))));
v_r1 = ((uint32_t)(v_r0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 56u))]));
if ((v_r1 >> 5u) != 0u) {
wuffs_etc2__decoder__decode_t_mode(self, v_color, (16u * v_bi), v_tran);
v_bi += 1u;
continue;
}
v_r0 = (((uint32_t)(v_r0 << 3u)) | (v_r0 >> 2u));
v_r1 = (((uint32_t)(v_r1 << 3u)) | (v_r1 >> 2u));
v_g0 = ((uint32_t)((31u & (v_color >> 51u))));
v_g1 = ((uint32_t)(v_g0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 48u))]));
if ((v_g1 >> 5u) != 0u) {
wuffs_etc2__decoder__decode_h_mode(self, v_color, (16u * v_bi), v_tran);
v_bi += 1u;
continue;
}
v_g0 = (((uint32_t)(v_g0 << 3u)) | (v_g0 >> 2u));
v_g1 = (((uint32_t)(v_g1 << 3u)) | (v_g1 >> 2u));
v_b0 = ((uint32_t)((31u & (v_color >> 43u))));
v_b1 = ((uint32_t)(v_b0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 40u))]));
if ((v_b1 >> 5u) != 0u) {
wuffs_etc2__decoder__decode_planar_mode(self, v_color, (16u * v_bi));
v_bi += 1u;
continue;
}
v_b0 = (((uint32_t)(v_b0 << 3u)) | (v_b0 >> 2u));
v_b1 = (((uint32_t)(v_b1 << 3u)) | (v_b1 >> 2u));
}
v_flip = ((v_color & 4294967296u) != 0u);
wuffs_etc2__decoder__decode_half_block(self,
((uint32_t)(v_color)),
(16u * v_bi),
((uint32_t)(((v_color >> 37u) & 7u))),
v_r0,
v_g0,
v_b0,
v_flip,
v_tran,
false);
wuffs_etc2__decoder__decode_half_block(self,
((uint32_t)(v_color)),
(16u * v_bi),
((uint32_t)(((v_color >> 34u) & 7u))),
v_r1,
v_g1,
v_b1,
v_flip,
v_tran,
true);
v_bi += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.decode_t_mode
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_t_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset,
bool a_transparent) {
uint8_t v_r[4] = {0};
uint8_t v_g[4] = {0};
uint8_t v_b[4] = {0};
uint8_t v_a[4] = {0};
uint32_t v_which = 0;
uint32_t v_delta = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_x4y = 0;
uint32_t v_index = 0;
uint32_t v_o = 0;
v_r[0u] = ((uint8_t)(((uint8_t)((12u & (a_bits >> 57u)))) | ((uint8_t)((3u & (a_bits >> 56u))))));
v_r[0u] = ((uint8_t)(((uint8_t)(v_r[0u] << 4u)) | v_r[0u]));
v_g[0u] = ((uint8_t)((15u & (a_bits >> 52u))));
v_g[0u] = ((uint8_t)(((uint8_t)(v_g[0u] << 4u)) | v_g[0u]));
v_b[0u] = ((uint8_t)((15u & (a_bits >> 48u))));
v_b[0u] = ((uint8_t)(((uint8_t)(v_b[0u] << 4u)) | v_b[0u]));
v_a[0u] = 255u;
v_r[2u] = ((uint8_t)((15u & (a_bits >> 44u))));
v_r[2u] = ((uint8_t)(((uint8_t)(v_r[2u] << 4u)) | v_r[2u]));
v_g[2u] = ((uint8_t)((15u & (a_bits >> 40u))));
v_g[2u] = ((uint8_t)(((uint8_t)(v_g[2u] << 4u)) | v_g[2u]));
v_b[2u] = ((uint8_t)((15u & (a_bits >> 36u))));
v_b[2u] = ((uint8_t)(((uint8_t)(v_b[2u] << 4u)) | v_b[2u]));
v_a[2u] = 255u;
v_which = (((uint32_t)((6u & (a_bits >> 33u)))) | ((uint32_t)((1u & (a_bits >> 32u)))));
v_delta = ((uint32_t)(WUFFS_ETC2__T_H_MODIFIERS[v_which]));
v_r[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) + v_delta)) & 1023u)];
v_g[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) + v_delta)) & 1023u)];
v_b[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) + v_delta)) & 1023u)];
v_a[1u] = 255u;
v_r[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) - v_delta)) & 1023u)];
v_g[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) - v_delta)) & 1023u)];
v_b[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) - v_delta)) & 1023u)];
v_a[3u] = 255u;
if (a_transparent) {
v_r[2u] = 0u;
v_g[2u] = 0u;
v_b[2u] = 0u;
v_a[2u] = 0u;
}
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_x4y = ((v_x * 4u) | v_y);
v_index = (((uint32_t)(((a_bits >> v_x4y) & 1u))) | ((uint32_t)(((a_bits >> (v_x4y + 15u)) & 2u))));
v_o = (a_offset + (v_x * 4u) + (v_y * 1024u));
self->private_data.f_buffer[(v_o + 0u)] = v_b[v_index];
self->private_data.f_buffer[(v_o + 1u)] = v_g[v_index];
self->private_data.f_buffer[(v_o + 2u)] = v_r[v_index];
self->private_data.f_buffer[(v_o + 3u)] = v_a[v_index];
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.decode_h_mode
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_h_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset,
bool a_transparent) {
uint8_t v_r[4] = {0};
uint8_t v_g[4] = {0};
uint8_t v_b[4] = {0};
uint8_t v_a[4] = {0};
uint32_t v_rgb0 = 0;
uint32_t v_rgb2 = 0;
uint32_t v_which = 0;
uint32_t v_delta = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_x4y = 0;
uint32_t v_index = 0;
uint32_t v_o = 0;
v_r[0u] = ((uint8_t)((15u & (a_bits >> 59u))));
v_r[0u] = ((uint8_t)(((uint8_t)(v_r[0u] << 4u)) | v_r[0u]));
v_g[0u] = ((uint8_t)(((uint8_t)((14u & (a_bits >> 55u)))) | ((uint8_t)((1u & (a_bits >> 52u))))));
v_g[0u] = ((uint8_t)(((uint8_t)(v_g[0u] << 4u)) | v_g[0u]));
v_b[0u] = ((uint8_t)(((uint8_t)((8u & (a_bits >> 48u)))) | ((uint8_t)((7u & (a_bits >> 47u))))));
v_b[0u] = ((uint8_t)(((uint8_t)(v_b[0u] << 4u)) | v_b[0u]));
v_r[2u] = ((uint8_t)((15u & (a_bits >> 43u))));
v_r[2u] = ((uint8_t)(((uint8_t)(v_r[2u] << 4u)) | v_r[2u]));
v_g[2u] = ((uint8_t)((15u & (a_bits >> 39u))));
v_g[2u] = ((uint8_t)(((uint8_t)(v_g[2u] << 4u)) | v_g[2u]));
v_b[2u] = ((uint8_t)((15u & (a_bits >> 35u))));
v_b[2u] = ((uint8_t)(((uint8_t)(v_b[2u] << 4u)) | v_b[2u]));
v_rgb0 = ((((uint32_t)(v_r[0u])) << 16u) | (((uint32_t)(v_g[0u])) << 8u) | (((uint32_t)(v_b[0u])) << 0u));
v_rgb2 = ((((uint32_t)(v_r[2u])) << 16u) | (((uint32_t)(v_g[2u])) << 8u) | (((uint32_t)(v_b[2u])) << 0u));
v_which = (((uint32_t)((4u & (a_bits >> 32u)))) | ((uint32_t)((2u & (a_bits >> 31u)))));
if (v_rgb0 >= v_rgb2) {
v_which |= 1u;
}
v_delta = ((uint32_t)(WUFFS_ETC2__T_H_MODIFIERS[v_which]));
v_r[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[0u])) - v_delta)) & 1023u)];
v_g[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[0u])) - v_delta)) & 1023u)];
v_b[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[0u])) - v_delta)) & 1023u)];
v_a[1u] = 255u;
v_r[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[0u])) + v_delta)) & 1023u)];
v_g[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[0u])) + v_delta)) & 1023u)];
v_b[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[0u])) + v_delta)) & 1023u)];
v_a[0u] = 255u;
v_r[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) - v_delta)) & 1023u)];
v_g[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) - v_delta)) & 1023u)];
v_b[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) - v_delta)) & 1023u)];
v_a[3u] = 255u;
v_r[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) + v_delta)) & 1023u)];
v_g[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) + v_delta)) & 1023u)];
v_b[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) + v_delta)) & 1023u)];
v_a[2u] = 255u;
if (a_transparent) {
v_r[2u] = 0u;
v_g[2u] = 0u;
v_b[2u] = 0u;
v_a[2u] = 0u;
}
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_x4y = ((v_x * 4u) | v_y);
v_index = (((uint32_t)(((a_bits >> v_x4y) & 1u))) | ((uint32_t)(((a_bits >> (v_x4y + 15u)) & 2u))));
v_o = (a_offset + (v_x * 4u) + (v_y * 1024u));
self->private_data.f_buffer[(v_o + 0u)] = v_b[v_index];
self->private_data.f_buffer[(v_o + 1u)] = v_g[v_index];
self->private_data.f_buffer[(v_o + 2u)] = v_r[v_index];
self->private_data.f_buffer[(v_o + 3u)] = v_a[v_index];
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.decode_planar_mode
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_planar_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset) {
uint32_t v_ro = 0;
uint32_t v_go = 0;
uint32_t v_bo = 0;
uint32_t v_rh = 0;
uint32_t v_gh = 0;
uint32_t v_bh = 0;
uint32_t v_rv = 0;
uint32_t v_gv = 0;
uint32_t v_bv = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_o = 0;
uint32_t v_rp = 0;
uint32_t v_gp = 0;
uint32_t v_bp = 0;
v_ro = ((uint32_t)((63u & (a_bits >> 57u))));
v_ro = (((uint32_t)(v_ro << 2u)) | (v_ro >> 4u));
v_go = (((uint32_t)((64u & (a_bits >> 50u)))) | ((uint32_t)((63u & (a_bits >> 49u)))));
v_go = (((uint32_t)(v_go << 1u)) | (v_go >> 6u));
v_bo = (((uint32_t)((32u & (a_bits >> 43u)))) | ((uint32_t)((24u & (a_bits >> 40u)))) | ((uint32_t)((7u & (a_bits >> 39u)))));
v_bo = (((uint32_t)(v_bo << 2u)) | (v_bo >> 4u));
v_rh = (((uint32_t)((62u & (a_bits >> 33u)))) | ((uint32_t)((1u & (a_bits >> 32u)))));
v_rh = (((uint32_t)(v_rh << 2u)) | (v_rh >> 4u));
v_gh = ((uint32_t)((127u & (a_bits >> 25u))));
v_gh = (((uint32_t)(v_gh << 1u)) | (v_gh >> 6u));
v_bh = ((uint32_t)((63u & (a_bits >> 19u))));
v_bh = (((uint32_t)(v_bh << 2u)) | (v_bh >> 4u));
v_rv = ((uint32_t)((63u & (a_bits >> 13u))));
v_rv = (((uint32_t)(v_rv << 2u)) | (v_rv >> 4u));
v_gv = ((uint32_t)((127u & (a_bits >> 6u))));
v_gv = (((uint32_t)(v_gv << 1u)) | (v_gv >> 6u));
v_bv = ((uint32_t)((63u & (a_bits >> 0u))));
v_bv = (((uint32_t)(v_bv << 2u)) | (v_bv >> 4u));
v_rh -= v_ro;
v_gh -= v_go;
v_bh -= v_bo;
v_rv -= v_ro;
v_gv -= v_go;
v_bv -= v_bo;
v_ro *= 4u;
v_go *= 4u;
v_bo *= 4u;
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_o = (a_offset + (v_x * 4u) + (v_y * 1024u));
v_bp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_bh)) + ((uint32_t)(v_y * v_bv)))) + v_bo));
self->private_data.f_buffer[(v_o + 0u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_bp + 2u)) / 4u) & 1023u)];
v_gp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_gh)) + ((uint32_t)(v_y * v_gv)))) + v_go));
self->private_data.f_buffer[(v_o + 1u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_gp + 2u)) / 4u) & 1023u)];
v_rp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_rh)) + ((uint32_t)(v_y * v_rv)))) + v_ro));
self->private_data.f_buffer[(v_o + 2u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_rp + 2u)) / 4u) & 1023u)];
v_x += 1u;
self->private_data.f_buffer[(v_o + 3u)] = 255u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.decode_half_block
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_half_block(
wuffs_etc2__decoder* self,
uint32_t a_bits,
uint32_t a_offset,
uint32_t a_which,
uint32_t a_r,
uint32_t a_g,
uint32_t a_b,
bool a_flip,
bool a_transparent,
bool a_second) {
uint32_t v_which = 0;
uint32_t v_x0 = 0;
uint32_t v_y0 = 0;
uint32_t v_x = 0;
uint32_t v_y = 0;
uint32_t v_i = 0;
uint32_t v_x4y = 0;
uint32_t v_index = 0;
uint32_t v_modif = 0;
uint32_t v_o = 0;
v_which = a_which;
if (a_transparent) {
v_which |= 8u;
}
if ( ! a_second) {
} else if (a_flip) {
v_y0 = 2u;
} else {
v_x0 = 2u;
}
while (v_i < 8u) {
if (a_flip) {
v_x = ((v_x0 + (v_i / 2u)) & 3u);
v_y = (v_y0 + (v_i & 1u));
} else {
v_x = (v_x0 + (v_i / 4u));
v_y = ((v_y0 + v_i) & 3u);
}
v_x4y = ((v_x * 4u) | v_y);
v_index = (((a_bits >> v_x4y) & 1u) | ((a_bits >> (v_x4y + 15u)) & 2u));
v_modif = WUFFS_ETC2__MODIFIERS[v_which][v_index];
v_o = (a_offset + (v_x * 4u) + (v_y * 1024u));
if (a_transparent && (v_index == 2u)) {
self->private_data.f_buffer[(v_o + 0u)] = 0u;
self->private_data.f_buffer[(v_o + 1u)] = 0u;
self->private_data.f_buffer[(v_o + 2u)] = 0u;
self->private_data.f_buffer[(v_o + 3u)] = 0u;
} else {
self->private_data.f_buffer[(v_o + 0u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_b + v_modif)) & 1023u)];
self->private_data.f_buffer[(v_o + 1u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_g + v_modif)) & 1023u)];
self->private_data.f_buffer[(v_o + 2u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_r + v_modif)) & 1023u)];
self->private_data.f_buffer[(v_o + 3u)] = 255u;
}
v_i += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.from_alphas_to_buffer
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__from_alphas_to_buffer(
wuffs_etc2__decoder* self) {
uint32_t v_bi = 0;
uint64_t v_alpha = 0;
uint32_t v_a0 = 0;
uint32_t v_multiplier = 0;
uint32_t v_which = 0;
uint32_t v_offset = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_shift = 0;
uint32_t v_delta = 0;
uint32_t v_o = 0;
while (v_bi < self->private_impl.f_num_buffered_blocks) {
v_alpha = self->private_data.f_alphas[v_bi];
v_a0 = ((uint32_t)((v_alpha >> 56u)));
v_multiplier = ((uint32_t)(((v_alpha >> 52u) & 15u)));
v_which = ((uint32_t)(((v_alpha >> 48u) & 15u)));
v_offset = (16u * v_bi);
v_y = 0u;
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_shift = ((((v_x ^ 3u) * 4u) | (v_y ^ 3u)) * 3u);
v_delta = ((uint32_t)(v_multiplier * WUFFS_ETC2__ALPHA_MODIFIERS[v_which][(7u & (v_alpha >> v_shift))]));
v_o = (v_offset + (v_x * 4u) + (v_y * 1024u));
self->private_data.f_buffer[(v_o + 3u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(v_a0 + v_delta)) & 1023u)];
v_x += 1u;
}
v_y += 1u;
}
v_bi += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.from_buffer_to_dst
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__from_buffer_to_dst(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst) {
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint32_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
wuffs_base__table_u8 v_tab = {0};
uint32_t v_bi = 0;
uint32_t v_rem_x = 0;
uint32_t v_dy = 0;
wuffs_base__slice_u8 v_dst = {0};
wuffs_base__slice_u8 v_src = {0};
uint32_t v_si = 0;
uint32_t v_sj = 0;
uint64_t v_i = 0;
uint32_t v_num_src_pixels = 0;
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
if ((v_dst_bits_per_pixel & 7u) != 0u) {
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8u);
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u);
while (v_bi < self->private_impl.f_num_buffered_blocks) {
if (self->private_impl.f_width <= self->private_impl.f_dst_x) {
self->private_impl.f_dst_x = 0u;
self->private_impl.f_dst_y += 4u;
if (self->private_impl.f_dst_y >= self->private_impl.f_height) {
break;
}
v_rem_x = self->private_impl.f_width;
} else {
v_rem_x = (self->private_impl.f_width - self->private_impl.f_dst_x);
}
v_dy = 0u;
while (v_dy < 4u) {
v_si = ((1024u * v_dy) + (16u * v_bi));
v_sj = ((1024u * v_dy) + 1024u);
if (v_si < v_sj) {
v_src = wuffs_base__make_slice_u8_ij(self->private_data.f_buffer, v_si, v_sj);
}
if (((uint64_t)((4u * v_rem_x))) < ((uint64_t)(v_src.len))) {
v_src = wuffs_base__slice_u8__subslice_j(v_src, ((uint64_t)((4u * v_rem_x))));
}
if (((uint32_t)(self->private_impl.f_dst_y + v_dy)) >= self->private_impl.f_height) {
break;
}
v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, ((uint32_t)(self->private_impl.f_dst_y + v_dy)));
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);
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
if (v_i < ((uint64_t)(v_dst.len))) {
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), wuffs_base__pixel_buffer__palette(a_dst), v_src);
}
v_dy += 1u;
}
v_num_src_pixels = (((uint32_t)(((uint64_t)(v_src.len)))) / 4u);
self->private_impl.f_dst_x += v_num_src_pixels;
v_bi += ((v_num_src_pixels + 3u) / 4u);
}
return wuffs_base__make_status(NULL);
}
// -------- func etc2.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_etc2__decoder__frame_dirty_rect(
const wuffs_etc2__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_rect_ie_u32();
}
return wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height);
}
// -------- func etc2.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_etc2__decoder__num_animation_loops(
const wuffs_etc2__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func etc2.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__num_decoded_frame_configs(
const wuffs_etc2__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 32u) {
return 1u;
}
return 0u;
}
// -------- func etc2.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__num_decoded_frames(
const wuffs_etc2__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 64u) {
return 1u;
}
return 0u;
}
// -------- func etc2.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__restart_frame(
wuffs_etc2__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (self->private_impl.f_call_sequence < 32u) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if ((a_index != 0u) || (a_io_position != 16u)) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 40u;
return wuffs_base__make_status(NULL);
}
// -------- func etc2.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_etc2__decoder__set_report_metadata(
wuffs_etc2__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__tell_me_more(
wuffs_etc2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 4)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
goto ok;
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func etc2.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_etc2__decoder__workbuf_len(
const wuffs_etc2__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_range_ii_u64();
}
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
// ---------------- Status Codes Implementations
@@ -40303,7 +44311,7 @@ WUFFS_GIF__XMPDATAXMP[11] WUFFS_BASE__POTENTIALLY_UNUSED = {
88u, 77u, 80u,
};
#define WUFFS_GIF__QUIRKS_BASE 1041635328u
#define WUFFS_GIF__QUIRKS_BASE 983928832u
#define WUFFS_GIF__QUIRKS_COUNT 7u
@@ -40526,7 +44534,7 @@ wuffs_gif__decoder__initialize(
wuffs_gif__decoder*
wuffs_gif__decoder__alloc(void) {
wuffs_gif__decoder* x =
(wuffs_gif__decoder*)(calloc(sizeof(wuffs_gif__decoder), 1));
(wuffs_gif__decoder*)(calloc(1, sizeof(wuffs_gif__decoder)));
if (!x) {
return NULL;
}
@@ -40562,8 +44570,8 @@ wuffs_gif__decoder__get_quirk(
uint32_t v_key = 0;
if (a_key >= 1041635328u) {
v_key = (a_key - 1041635328u);
if (a_key >= 983928832u) {
v_key = (a_key - 983928832u);
if (v_key < 7u) {
if (self->private_impl.f_quirks[v_key]) {
return 1u;
@@ -40591,8 +44599,8 @@ wuffs_gif__decoder__set_quirk(
: wuffs_base__error__initialize_not_called);
}
if ((self->private_impl.f_call_sequence == 0u) && (a_key >= 1041635328u)) {
a_key -= 1041635328u;
if ((self->private_impl.f_call_sequence == 0u) && (a_key >= 983928832u)) {
a_key -= 983928832u;
if (a_key < 7u) {
self->private_impl.f_quirks[a_key] = (a_value > 0u);
return wuffs_base__make_status(NULL);
@@ -43437,7 +47445,7 @@ wuffs_gzip__decoder__initialize(
wuffs_gzip__decoder*
wuffs_gzip__decoder__alloc(void) {
wuffs_gzip__decoder* x =
(wuffs_gzip__decoder*)(calloc(sizeof(wuffs_gzip__decoder), 1));
(wuffs_gzip__decoder*)(calloc(1, sizeof(wuffs_gzip__decoder)));
if (!x) {
return NULL;
}
@@ -43934,6 +47942,8 @@ const char wuffs_jpeg__error__bad_marker[] = "#jpeg: bad marker";
const char wuffs_jpeg__error__bad_scan_count[] = "#jpeg: bad scan count";
const char wuffs_jpeg__error__missing_huffman_table[] = "#jpeg: missing Huffman table";
const char wuffs_jpeg__error__missing_quantization_table[] = "#jpeg: missing Quantization table";
const char wuffs_jpeg__error__rejected_progressive_jpeg[] = "#jpeg: rejected progressive JPEG";
const char wuffs_jpeg__error__short_sos_bitstream[] = "#jpeg: short SOS bitstream";
const char wuffs_jpeg__error__truncated_input[] = "#jpeg: truncated input";
const char wuffs_jpeg__error__unsupported_arithmetic_coding[] = "#jpeg: unsupported arithmetic coding";
const char wuffs_jpeg__error__unsupported_color_model[] = "#jpeg: unsupported color model";
@@ -44172,6 +48182,8 @@ WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_CHROMA[179] WUFFS_BASE__POTENTIALLY_UNUSED = {
248u, 249u, 250u,
};
#define WUFFS_JPEG__QUIRKS_BASE 1162824704u
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
@@ -44540,7 +48552,7 @@ wuffs_jpeg__decoder__initialize(
wuffs_jpeg__decoder*
wuffs_jpeg__decoder__alloc(void) {
wuffs_jpeg__decoder* x =
(wuffs_jpeg__decoder*)(calloc(sizeof(wuffs_jpeg__decoder), 1));
(wuffs_jpeg__decoder*)(calloc(1, sizeof(wuffs_jpeg__decoder)));
if (!x) {
return NULL;
}
@@ -46089,6 +50101,10 @@ wuffs_jpeg__decoder__get_quirk(
if (self->private_impl.f_use_lower_quality) {
return 18446744073709551615u;
}
} else if (a_key == 1162824704u) {
if (self->private_impl.f_reject_progressive_jpegs) {
return 1u;
}
}
return 0u;
}
@@ -46114,6 +50130,9 @@ wuffs_jpeg__decoder__set_quirk(
if (a_key == 2u) {
self->private_impl.f_use_lower_quality = (a_value >= 9223372036854775808u);
return wuffs_base__make_status(NULL);
} else if (a_key == 1162824704u) {
self->private_impl.f_reject_progressive_jpegs = (a_value != 0u);
return wuffs_base__make_status(NULL);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
@@ -46313,6 +50332,9 @@ wuffs_jpeg__decoder__do_decode_image_config(
self->private_impl.f_payload_length = t_4;
}
if (self->private_impl.f_payload_length < 2u) {
if ((v_marker == 254u) || ((224u <= v_marker) && (v_marker < 240u))) {
continue;
}
status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker);
goto exit;
}
@@ -46323,9 +50345,20 @@ wuffs_jpeg__decoder__do_decode_image_config(
goto exit;
} else if (v_marker < 208u) {
if (v_marker <= 194u) {
if (self->private_impl.f_sof_marker != 0u) {
if ((v_marker == 194u) && self->private_impl.f_reject_progressive_jpegs) {
status = wuffs_base__make_status(wuffs_jpeg__error__rejected_progressive_jpeg);
goto exit;
} else if (self->private_impl.f_sof_marker != 0u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker);
goto exit;
} else if (v_marker == 192u) {
if (self->private_impl.f_seen_dht[2u] ||
self->private_impl.f_seen_dht[3u] ||
self->private_impl.f_seen_dht[6u] ||
self->private_impl.f_seen_dht[7u]) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker);
goto exit;
}
}
self->private_impl.f_sof_marker = v_marker;
if (a_src) {
@@ -46344,8 +50377,18 @@ wuffs_jpeg__decoder__do_decode_image_config(
status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_lossless_coding);
goto exit;
} else if (v_marker == 196u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker);
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_jpeg__decoder__decode_dht(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
continue;
} else if ((197u <= v_marker) && (v_marker <= 199u)) {
status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_hierarchical_coding);
goto exit;
@@ -46367,7 +50410,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_jpeg__decoder__decode_dqt(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
@@ -46380,7 +50423,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
status = wuffs_jpeg__decoder__decode_dri(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
@@ -46397,7 +50440,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
status = wuffs_jpeg__decoder__decode_appn(self, a_src, v_marker);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
@@ -46414,7 +50457,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
}
}
self->private_data.s_do_decode_image_config.scratch = self->private_impl.f_payload_length;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
if (self->private_data.s_do_decode_image_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
@@ -47528,11 +51571,11 @@ wuffs_jpeg__decoder__do_decode_frame(
}
self->private_impl.f_swizzle_immediately = false;
if (self->private_impl.f_components_workbuf_offsets[8u] > ((uint64_t)(a_workbuf.len))) {
if (self->private_impl.f_sof_marker >= 194u) {
if ((self->private_impl.f_sof_marker >= 194u) || ! self->private_impl.f_use_lower_quality) {
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
goto exit;
}
self->private_impl.f_swizzle_immediately = self->private_impl.f_use_lower_quality;
self->private_impl.f_swizzle_immediately = true;
self->private_impl.f_swizzle_immediately_status = wuffs_base__make_status(NULL);
} else if (self->private_impl.f_components_workbuf_offsets[4u] < self->private_impl.f_components_workbuf_offsets[8u]) {
wuffs_private_impl__bulk_memset(a_workbuf.ptr + self->private_impl.f_components_workbuf_offsets[4u], (self->private_impl.f_components_workbuf_offsets[8u] - self->private_impl.f_components_workbuf_offsets[4u]), 0u);
@@ -47762,10 +51805,6 @@ wuffs_jpeg__decoder__decode_dht(
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_sof_marker == 0u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker);
goto exit;
}
while (self->private_impl.f_payload_length > 0u) {
if (self->private_impl.f_payload_length < 17u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker);
@@ -48089,7 +52128,7 @@ wuffs_jpeg__decoder__decode_sos(
if (v_bitstream_length < ((uint32_t)(self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri))) {
break;
} else if (self->private_impl.f_bitstream_padding == 0u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker);
status = wuffs_base__make_status(wuffs_jpeg__error__short_sos_bitstream);
goto exit;
} else if ((a_src && a_src->meta.closed) && ! self->private_impl.f_bitstream_is_closed) {
if (self->private_impl.f_bitstream_wi < 1024u) {
@@ -48621,13 +52660,17 @@ wuffs_jpeg__decoder__fill_bitstream(
continue;
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 1u) {
break;
} else if (((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)) > 0u) {
break;
} else {
}
v_c8 = iop_a_src[1u];
if (v_c8 == 0u) {
self->private_data.f_bitstream_buffer[v_wi] = 255u;
v_wi += 1u;
iop_a_src += 2u;
continue;
} else if (v_c8 < 255u) {
break;
}
iop_a_src += 1u;
}
if (((uint64_t)(io2_a_src - iop_a_src)) > 1u) {
if ((wuffs_base__peek_u8be__no_bounds_check(iop_a_src) >= 255u) && (((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)) > 0u)) {
@@ -51105,7 +55148,7 @@ WUFFS_JSON__LUT_HEXADECIMAL_DIGITS[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
};
#define WUFFS_JSON__QUIRKS_BASE 1225364480u
#define WUFFS_JSON__QUIRKS_BASE 1167656960u
#define WUFFS_JSON__QUIRKS_COUNT 21u
@@ -51222,7 +55265,7 @@ wuffs_json__decoder__initialize(
wuffs_json__decoder*
wuffs_json__decoder__alloc(void) {
wuffs_json__decoder* x =
(wuffs_json__decoder*)(calloc(sizeof(wuffs_json__decoder), 1));
(wuffs_json__decoder*)(calloc(1, sizeof(wuffs_json__decoder)));
if (!x) {
return NULL;
}
@@ -51258,8 +55301,8 @@ wuffs_json__decoder__get_quirk(
uint32_t v_key = 0;
if (a_key >= 1225364480u) {
v_key = (a_key - 1225364480u);
if (a_key >= 1167656960u) {
v_key = (a_key - 1167656960u);
if (v_key < 21u) {
if (self->private_impl.f_quirks[v_key]) {
return 1u;
@@ -51287,8 +55330,8 @@ wuffs_json__decoder__set_quirk(
: wuffs_base__error__initialize_not_called);
}
if (a_key >= 1225364480u) {
a_key -= 1225364480u;
if (a_key >= 1167656960u) {
a_key -= 1167656960u;
if (a_key < 21u) {
self->private_impl.f_quirks[a_key] = (a_value > 0u);
return wuffs_base__make_status(NULL);
@@ -53142,7 +57185,7 @@ WUFFS_LZMA__CLAMP_NO_MORE_THAN_3[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 1u, 2u, 3u, 3u, 3u, 3u, 3u,
};
#define WUFFS_LZMA__QUIRKS_BASE 1348001792u
#define WUFFS_LZMA__QUIRKS_BASE 1290294272u
// ---------------- Private Initializer Prototypes
@@ -53280,7 +57323,7 @@ wuffs_lzma__decoder__initialize(
wuffs_lzma__decoder*
wuffs_lzma__decoder__alloc(void) {
wuffs_lzma__decoder* x =
(wuffs_lzma__decoder*)(calloc(sizeof(wuffs_lzma__decoder), 1));
(wuffs_lzma__decoder*)(calloc(1, sizeof(wuffs_lzma__decoder)));
if (!x) {
return NULL;
}
@@ -55309,11 +59352,11 @@ wuffs_lzma__decoder__get_quirk(
return 0;
}
if (a_key == 1348001792u) {
if (a_key == 1290294272u) {
if (self->private_impl.f_allow_non_zero_initial_byte) {
return 1u;
}
} else if (a_key == 1348001793u) {
} else if (a_key == 1290294273u) {
return ((uint64_t)(self->private_impl.f_format_extension));
}
return 0u;
@@ -55340,9 +59383,9 @@ wuffs_lzma__decoder__set_quirk(
uint32_t v_v = 0;
uint32_t v_n = 0;
if (a_key == 1348001792u) {
if (a_key == 1290294272u) {
self->private_impl.f_allow_non_zero_initial_byte = (a_value > 0u);
} else if (a_key == 1348001793u) {
} else if (a_key == 1290294273u) {
if (a_value == 0u) {
self->private_impl.f_format_extension = 0u;
return wuffs_base__make_status(NULL);
@@ -56471,7 +60514,7 @@ wuffs_lzip__decoder__initialize(
wuffs_lzip__decoder*
wuffs_lzip__decoder__alloc(void) {
wuffs_lzip__decoder* x =
(wuffs_lzip__decoder*)(calloc(sizeof(wuffs_lzip__decoder), 1));
(wuffs_lzip__decoder*)(calloc(1, sizeof(wuffs_lzip__decoder)));
if (!x) {
return NULL;
}
@@ -56729,7 +60772,7 @@ wuffs_lzip__decoder__do_transform_io(
uint8_t t_1 = *iop_a_src++;
v_c8 = t_1;
}
v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001793u, (1u | (((uint64_t)(v_c8)) << 8u)));
v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294273u, (1u | (((uint64_t)(v_c8)) << 8u)));
if ( ! wuffs_base__status__is_ok(&v_status)) {
if (v_status.repr == wuffs_base__error__bad_argument) {
status = wuffs_base__make_status(wuffs_lzip__error__bad_header);
@@ -56746,7 +60789,7 @@ wuffs_lzip__decoder__do_transform_io(
}
self->private_impl.f_ssize_have = 0u;
self->private_impl.f_dsize_have = 0u;
wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001792u, 1u);
wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294272u, 1u);
while (true) {
v_dmark = ((uint64_t)(iop_a_dst - io0_a_dst));
v_smark = ((uint64_t)(iop_a_src - io0_a_src));
@@ -56933,7 +60976,7 @@ const char wuffs_lzw__error__internal_error_inconsistent_i_o[] = "#lzw: internal
// ---------------- Private Consts
#define WUFFS_LZW__QUIRKS_BASE 1348378624u
#define WUFFS_LZW__QUIRKS_BASE 1290672128u
// ---------------- Private Initializer Prototypes
@@ -57020,7 +61063,7 @@ wuffs_lzw__decoder__initialize(
wuffs_lzw__decoder*
wuffs_lzw__decoder__alloc(void) {
wuffs_lzw__decoder* x =
(wuffs_lzw__decoder*)(calloc(sizeof(wuffs_lzw__decoder), 1));
(wuffs_lzw__decoder*)(calloc(1, sizeof(wuffs_lzw__decoder)));
if (!x) {
return NULL;
}
@@ -57054,7 +61097,7 @@ wuffs_lzw__decoder__get_quirk(
return 0;
}
if (a_key == 1348378624u) {
if (a_key == 1290672128u) {
return ((uint64_t)(self->private_impl.f_pending_literal_width_plus_one));
}
return 0u;
@@ -57078,7 +61121,7 @@ wuffs_lzw__decoder__set_quirk(
: wuffs_base__error__initialize_not_called);
}
if (a_key == 1348378624u) {
if (a_key == 1290672128u) {
if (a_value > 9u) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
@@ -57636,7 +61679,7 @@ wuffs_netpbm__decoder__initialize(
wuffs_netpbm__decoder*
wuffs_netpbm__decoder__alloc(void) {
wuffs_netpbm__decoder* x =
(wuffs_netpbm__decoder*)(calloc(sizeof(wuffs_netpbm__decoder), 1));
(wuffs_netpbm__decoder*)(calloc(1, sizeof(wuffs_netpbm__decoder)));
if (!x) {
return NULL;
}
@@ -58776,7 +62819,7 @@ wuffs_nie__decoder__initialize(
wuffs_nie__decoder*
wuffs_nie__decoder__alloc(void) {
wuffs_nie__decoder* x =
(wuffs_nie__decoder*)(calloc(sizeof(wuffs_nie__decoder), 1));
(wuffs_nie__decoder*)(calloc(1, sizeof(wuffs_nie__decoder)));
if (!x) {
return NULL;
}
@@ -59714,7 +63757,7 @@ const char wuffs_zlib__error__truncated_input[] = "#zlib: truncated input";
// ---------------- Private Consts
#define WUFFS_ZLIB__QUIRKS_BASE 2113790976u
#define WUFFS_ZLIB__QUIRKS_BASE 2056083456u
#define WUFFS_ZLIB__QUIRKS_COUNT 1u
@@ -59820,7 +63863,7 @@ wuffs_zlib__decoder__initialize(
wuffs_zlib__decoder*
wuffs_zlib__decoder__alloc(void) {
wuffs_zlib__decoder* x =
(wuffs_zlib__decoder*)(calloc(sizeof(wuffs_zlib__decoder), 1));
(wuffs_zlib__decoder*)(calloc(1, sizeof(wuffs_zlib__decoder)));
if (!x) {
return NULL;
}
@@ -59899,8 +63942,8 @@ wuffs_zlib__decoder__get_quirk(
if ((a_key == 1u) && self->private_impl.f_ignore_checksum) {
return 1u;
} else if (a_key >= 2113790976u) {
v_key = (a_key - 2113790976u);
} else if (a_key >= 2056083456u) {
v_key = (a_key - 2056083456u);
if (v_key < 1u) {
if (self->private_impl.f_quirks[v_key]) {
return 1u;
@@ -59934,8 +63977,8 @@ wuffs_zlib__decoder__set_quirk(
} else if (a_key == 1u) {
self->private_impl.f_ignore_checksum = (a_value > 0u);
return wuffs_base__make_status(NULL);
} else if (a_key >= 2113790976u) {
a_key -= 2113790976u;
} else if (a_key >= 2056083456u) {
a_key -= 2056083456u;
if (a_key < 1u) {
self->private_impl.f_quirks[a_key] = (a_value > 0u);
return wuffs_base__make_status(NULL);
@@ -60788,7 +64831,7 @@ wuffs_png__decoder__initialize(
wuffs_png__decoder*
wuffs_png__decoder__alloc(void) {
wuffs_png__decoder* x =
(wuffs_png__decoder*)(calloc(sizeof(wuffs_png__decoder), 1));
(wuffs_png__decoder*)(calloc(1, sizeof(wuffs_png__decoder)));
if (!x) {
return NULL;
}
@@ -66798,6 +70841,1282 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
// ---------------- Status Codes Implementations
const char wuffs_qoi__error__bad_footer[] = "#qoi: bad footer";
const char wuffs_qoi__error__bad_header[] = "#qoi: bad header";
const char wuffs_qoi__error__truncated_input[] = "#qoi: truncated input";
// ---------------- Private Consts
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_image_config(
wuffs_qoi__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_frame_config(
wuffs_qoi__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_frame(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__from_src_to_buffer(
wuffs_qoi__decoder* self,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__from_buffer_to_dst(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_qoi__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_qoi__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_qoi__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_qoi__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_qoi__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_qoi__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_qoi__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_qoi__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_qoi__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_qoi__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_qoi__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_qoi__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_qoi__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_qoi__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_qoi__decoder__initialize(
wuffs_qoi__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (sizeof(*self) != sizeof_star_self) {
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
}
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
}
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
// The whole point of this if-check is to detect an uninitialized *self.
// We disable the warning on GCC. Clang-5.0 does not have this warning.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (self->private_impl.magic != 0) {
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
}
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_qoi__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_qoi__decoder*
wuffs_qoi__decoder__alloc(void) {
wuffs_qoi__decoder* x =
(wuffs_qoi__decoder*)(calloc(1, sizeof(wuffs_qoi__decoder)));
if (!x) {
return NULL;
}
if (wuffs_qoi__decoder__initialize(
x, sizeof(wuffs_qoi__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
return x;
}
size_t
sizeof__wuffs_qoi__decoder(void) {
return sizeof(wuffs_qoi__decoder);
}
// ---------------- Function Implementations
// -------- func qoi.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__get_quirk(
const wuffs_qoi__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func qoi.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__set_quirk(
wuffs_qoi__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func qoi.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_image_config(
wuffs_qoi__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_qoi__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_qoi__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func qoi.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_image_config(
wuffs_qoi__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_a = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0u) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
{
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_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 == 24) {
t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_a = t_0;
}
if (v_a != 1718185841u) {
status = wuffs_base__make_status(wuffs_qoi__error__bad_header);
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_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu));
*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 += 8u;
*scratch |= ((uint64_t)(num_bits_1));
}
}
v_a = t_1;
}
if (v_a > 16777215u) {
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
goto exit;
}
self->private_impl.f_width = v_a;
{
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_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu));
*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 += 8u;
*scratch |= ((uint64_t)(num_bits_2));
}
}
v_a = t_2;
}
if (v_a > 16777215u) {
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
goto exit;
}
self->private_impl.f_height = v_a;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint32_t t_3 = *iop_a_src++;
v_a = t_3;
}
if (v_a == 3u) {
self->private_impl.f_pixfmt = 2415954056u;
} else if (v_a == 4u) {
self->private_impl.f_pixfmt = 2164295816u;
} else {
status = wuffs_base__make_status(wuffs_qoi__error__bad_header);
goto exit;
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src++;
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
self->private_impl.f_pixfmt,
0u,
self->private_impl.f_width,
self->private_impl.f_height,
14u,
(self->private_impl.f_pixfmt == 2415954056u));
}
self->private_impl.f_call_sequence = 32u;
goto ok;
ok:
self->private_impl.p_do_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func qoi.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_frame_config(
wuffs_qoi__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 2)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_qoi__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_qoi__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func qoi.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_frame_config(
wuffs_qoi__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 32u) {
} else if (self->private_impl.f_call_sequence < 32u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_qoi__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 40u) {
if (14u != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
goto exit;
}
} else if (self->private_impl.f_call_sequence == 64u) {
self->private_impl.f_call_sequence = 96u;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height),
((wuffs_base__flicks)(0u)),
0u,
14u,
0u,
(self->private_impl.f_pixfmt == 2415954056u),
false,
0u);
}
self->private_impl.f_call_sequence = 64u;
ok:
self->private_impl.p_do_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func qoi.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_frame(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 3)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_qoi__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_qoi__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func qoi.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_frame(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint64_t v_c64 = 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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64u) {
} else if (self->private_impl.f_call_sequence < 64u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_qoi__decoder__do_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 {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
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(a_dst),
wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
wuffs_base__utility__empty_slice_u8(),
a_blend);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
self->private_impl.f_dst_x = 0u;
self->private_impl.f_dst_y = 0u;
self->private_data.f_pixel[0u] = 0u;
self->private_data.f_pixel[1u] = 0u;
self->private_data.f_pixel[2u] = 0u;
self->private_data.f_pixel[3u] = 255u;
wuffs_private_impl__bulk_memset(&self->private_data.f_cache[0], 256u, 0u);
self->private_impl.f_remaining_pixels_times_4 = (((uint64_t)(self->private_impl.f_width)) * ((uint64_t)(self->private_impl.f_height)) * 4u);
while (self->private_impl.f_remaining_pixels_times_4 > 0u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_qoi__decoder__from_src_to_buffer(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_remaining_pixels_times_4 < ((uint64_t)(self->private_impl.f_buffer_index))) {
status = wuffs_base__make_status(wuffs_base__error__too_much_data);
goto exit;
}
self->private_impl.f_remaining_pixels_times_4 -= ((uint64_t)(self->private_impl.f_buffer_index));
v_status = wuffs_qoi__decoder__from_buffer_to_dst(self, a_dst);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
t_0 = wuffs_base__peek_u64be__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_do_decode_frame.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_do_decode_frame.scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 56) {
t_0 = ((uint64_t)(*scratch >> 0));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_c64 = t_0;
}
if (v_c64 != 1u) {
status = wuffs_base__make_status(wuffs_qoi__error__bad_footer);
goto exit;
}
self->private_impl.f_call_sequence = 96u;
ok:
self->private_impl.p_do_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func qoi.decoder.from_src_to_buffer
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__from_src_to_buffer(
wuffs_qoi__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c8 = 0;
uint8_t v_dg = 0;
uint32_t v_bi = 0;
uint32_t v_bj = 0;
uint32_t v_bk = 0;
uint32_t v_ci = 0;
uint32_t v_hash4 = 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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_from_src_to_buffer;
if (coro_susp_point) {
v_dg = self->private_data.s_from_src_to_buffer.v_dg;
v_bi = self->private_data.s_from_src_to_buffer.v_bi;
v_bk = self->private_data.s_from_src_to_buffer.v_bk;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
v_bk = 7936u;
if (self->private_impl.f_remaining_pixels_times_4 < 7936u) {
v_bk = ((uint32_t)(self->private_impl.f_remaining_pixels_times_4));
}
while (v_bi < v_bk) {
{
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_c8 = t_0;
}
if (v_c8 == 254u) {
{
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++;
self->private_data.f_pixel[2u] = t_1;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_2 = *iop_a_src++;
self->private_data.f_pixel[1u] = t_2;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_3 = *iop_a_src++;
self->private_data.f_pixel[0u] = t_3;
}
} else if (v_c8 == 255u) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_4 = *iop_a_src++;
self->private_data.f_pixel[2u] = t_4;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_5 = *iop_a_src++;
self->private_data.f_pixel[1u] = t_5;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_6 = *iop_a_src++;
self->private_data.f_pixel[0u] = t_6;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_7 = *iop_a_src++;
self->private_data.f_pixel[3u] = t_7;
}
} else if (((uint8_t)(v_c8 >> 6u)) == 0u) {
v_ci = (4u * ((uint32_t)(((uint8_t)(v_c8 & 63u)))));
self->private_data.f_pixel[0u] = self->private_data.f_cache[(v_ci + 0u)];
self->private_data.f_pixel[1u] = self->private_data.f_cache[(v_ci + 1u)];
self->private_data.f_pixel[2u] = self->private_data.f_cache[(v_ci + 2u)];
self->private_data.f_pixel[3u] = self->private_data.f_cache[(v_ci + 3u)];
self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u];
self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u];
self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u];
v_bi += 4u;
continue;
} else if (((uint8_t)(v_c8 >> 6u)) == 1u) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 4u)) & 3u)) + 254u));
self->private_data.f_pixel[1u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 2u)) & 3u)) + 254u));
self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 0u)) & 3u)) + 254u));
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else if (((uint8_t)(v_c8 >> 6u)) == 2u) {
v_dg = ((uint8_t)(((uint8_t)(v_c8 & 63u)) + 224u));
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_8 = *iop_a_src++;
v_c8 = t_8;
}
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 4u))))));
self->private_data.f_pixel[1u] += v_dg;
self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 0u))))));
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_bj = (v_bi + (4u * (63u & (1u + ((uint32_t)(v_c8))))));
while (v_bi < v_bj) {
self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u];
self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u];
self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u];
v_bi += 4u;
}
continue;
}
v_hash4 = (4u * (63u & ((((uint32_t)(self->private_data.f_pixel[2u])) * 3u) +
(((uint32_t)(self->private_data.f_pixel[1u])) * 5u) +
(((uint32_t)(self->private_data.f_pixel[0u])) * 7u) +
(((uint32_t)(self->private_data.f_pixel[3u])) * 11u))));
self->private_data.f_cache[(v_hash4 + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_cache[(v_hash4 + 1u)] = self->private_data.f_pixel[1u];
self->private_data.f_cache[(v_hash4 + 2u)] = self->private_data.f_pixel[2u];
self->private_data.f_cache[(v_hash4 + 3u)] = self->private_data.f_pixel[3u];
self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u];
self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u];
self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u];
v_bi += 4u;
}
self->private_impl.f_buffer_index = v_bi;
goto ok;
ok:
self->private_impl.p_from_src_to_buffer = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_from_src_to_buffer = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_from_src_to_buffer.v_dg = v_dg;
self->private_data.s_from_src_to_buffer.v_bi = v_bi;
self->private_data.s_from_src_to_buffer.v_bk = v_bk;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func qoi.decoder.from_buffer_to_dst
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__from_buffer_to_dst(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst) {
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint32_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
wuffs_base__table_u8 v_tab = {0};
uint32_t v_bi = 0;
uint32_t v_rem_x = 0;
wuffs_base__slice_u8 v_dst = {0};
wuffs_base__slice_u8 v_src = {0};
uint32_t v_src_length = 0;
uint64_t v_i = 0;
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
if ((v_dst_bits_per_pixel & 7u) != 0u) {
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8u);
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u);
while (v_bi < self->private_impl.f_buffer_index) {
if (self->private_impl.f_width <= self->private_impl.f_dst_x) {
self->private_impl.f_dst_x = 0u;
self->private_impl.f_dst_y += 1u;
if (self->private_impl.f_dst_y >= self->private_impl.f_height) {
break;
}
v_rem_x = self->private_impl.f_width;
} else {
v_rem_x = (self->private_impl.f_width - self->private_impl.f_dst_x);
}
v_src = wuffs_base__make_slice_u8_ij(self->private_data.f_buffer, v_bi, self->private_impl.f_buffer_index);
if (((uint64_t)((4u * v_rem_x))) < ((uint64_t)(v_src.len))) {
v_src = wuffs_base__slice_u8__subslice_j(v_src, ((uint64_t)((4u * v_rem_x))));
}
v_src_length = ((uint32_t)(((uint64_t)(v_src.len))));
v_bi += v_src_length;
v_dst = wuffs_private_impl__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);
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
self->private_impl.f_dst_x += (v_src_length / 4u);
if (v_i < ((uint64_t)(v_dst.len))) {
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), wuffs_base__pixel_buffer__palette(a_dst), v_src);
}
}
return wuffs_base__make_status(NULL);
}
// -------- func qoi.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_qoi__decoder__frame_dirty_rect(
const wuffs_qoi__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_rect_ie_u32();
}
return wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height);
}
// -------- func qoi.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_qoi__decoder__num_animation_loops(
const wuffs_qoi__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func qoi.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__num_decoded_frame_configs(
const wuffs_qoi__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 32u) {
return 1u;
}
return 0u;
}
// -------- func qoi.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__num_decoded_frames(
const wuffs_qoi__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 64u) {
return 1u;
}
return 0u;
}
// -------- func qoi.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__restart_frame(
wuffs_qoi__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (self->private_impl.f_call_sequence < 32u) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if ((a_index != 0u) || (a_io_position != 14u)) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 40u;
return wuffs_base__make_status(NULL);
}
// -------- func qoi.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_qoi__decoder__set_report_metadata(
wuffs_qoi__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func qoi.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__tell_me_more(
wuffs_qoi__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 4)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
goto ok;
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func qoi.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_qoi__decoder__workbuf_len(
const wuffs_qoi__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_range_ii_u64();
}
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256)
// ---------------- Status Codes Implementations
@@ -66899,7 +72218,7 @@ wuffs_sha256__hasher__initialize(
wuffs_sha256__hasher*
wuffs_sha256__hasher__alloc(void) {
wuffs_sha256__hasher* x =
(wuffs_sha256__hasher*)(calloc(sizeof(wuffs_sha256__hasher), 1));
(wuffs_sha256__hasher*)(calloc(1, sizeof(wuffs_sha256__hasher)));
if (!x) {
return NULL;
}
@@ -67403,14 +72722,14 @@ wuffs_sha256__hasher__checksum_bitvec256(
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
// ---------------- Status Codes Implementations
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding";
const char wuffs_tga__error__truncated_input[] = "#tga: truncated input";
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
const char wuffs_targa__error__bad_header[] = "#targa: bad header";
const char wuffs_targa__error__bad_run_length_encoding[] = "#targa: bad run length encoding";
const char wuffs_targa__error__truncated_input[] = "#targa: truncated input";
const char wuffs_targa__error__unsupported_targa_file[] = "#targa: unsupported TARGA file";
// ---------------- Private Consts
@@ -67420,22 +72739,22 @@ const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA fil
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_image_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_image_config(
wuffs_targa__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_frame_config(
wuffs_targa__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_frame(
wuffs_targa__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
@@ -67445,46 +72764,46 @@ wuffs_tga__decoder__do_decode_frame(
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder = {
wuffs_targa__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_tga__decoder__decode_frame),
wuffs_base__decode_frame_options*))(&wuffs_targa__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_frame_config),
wuffs_base__io_buffer*))(&wuffs_targa__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_tga__decoder__frame_dirty_rect),
wuffs_base__io_buffer*))(&wuffs_targa__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_targa__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_tga__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_tga__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frames),
uint32_t))(&wuffs_targa__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_targa__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_targa__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_targa__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_tga__decoder__restart_frame),
uint64_t))(&wuffs_targa__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_tga__decoder__set_quirk),
uint64_t))(&wuffs_targa__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_tga__decoder__set_report_metadata),
bool))(&wuffs_targa__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_tga__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_tga__decoder__workbuf_len),
wuffs_base__io_buffer*))(&wuffs_targa__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_targa__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_tga__decoder__initialize(
wuffs_tga__decoder* self,
wuffs_targa__decoder__initialize(
wuffs_targa__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
@@ -67525,19 +72844,19 @@ wuffs_tga__decoder__initialize(
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder);
(const void*)(&wuffs_targa__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_tga__decoder*
wuffs_tga__decoder__alloc(void) {
wuffs_tga__decoder* x =
(wuffs_tga__decoder*)(calloc(sizeof(wuffs_tga__decoder), 1));
wuffs_targa__decoder*
wuffs_targa__decoder__alloc(void) {
wuffs_targa__decoder* x =
(wuffs_targa__decoder*)(calloc(1, sizeof(wuffs_targa__decoder)));
if (!x) {
return NULL;
}
if (wuffs_tga__decoder__initialize(
x, sizeof(wuffs_tga__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
if (wuffs_targa__decoder__initialize(
x, sizeof(wuffs_targa__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
@@ -67545,18 +72864,18 @@ wuffs_tga__decoder__alloc(void) {
}
size_t
sizeof__wuffs_tga__decoder(void) {
return sizeof(wuffs_tga__decoder);
sizeof__wuffs_targa__decoder(void) {
return sizeof(wuffs_targa__decoder);
}
// ---------------- Function Implementations
// -------- func tga.decoder.get_quirk
// -------- func targa.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__get_quirk(
const wuffs_tga__decoder* self,
wuffs_targa__decoder__get_quirk(
const wuffs_targa__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
@@ -67569,12 +72888,12 @@ wuffs_tga__decoder__get_quirk(
return 0u;
}
// -------- func tga.decoder.set_quirk
// -------- func targa.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__set_quirk(
wuffs_tga__decoder* self,
wuffs_targa__decoder__set_quirk(
wuffs_targa__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
@@ -67590,12 +72909,12 @@ wuffs_tga__decoder__set_quirk(
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func tga.decoder.decode_image_config
// -------- func targa.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_image_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_image_config(
wuffs_targa__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
@@ -67627,11 +72946,11 @@ wuffs_tga__decoder__decode_image_config(
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_image_config(self, a_dst, a_src);
wuffs_base__status t_0 = wuffs_targa__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
status = wuffs_base__make_status(wuffs_targa__error__truncated_input);
goto exit;
}
status = v_status;
@@ -67656,12 +72975,12 @@ wuffs_tga__decoder__decode_image_config(
return status;
}
// -------- func tga.decoder.do_decode_image_config
// -------- func targa.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_image_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_image_config(
wuffs_targa__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
@@ -67711,7 +73030,7 @@ wuffs_tga__decoder__do_decode_image_config(
self->private_impl.f_header_color_map_type = t_1;
}
if (self->private_impl.f_header_color_map_type > 1u) {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
{
@@ -67730,7 +73049,7 @@ wuffs_tga__decoder__do_decode_image_config(
(self->private_impl.f_header_image_type == 10u) ||
(self->private_impl.f_header_image_type == 11u)) {
} else {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
{
@@ -67802,18 +73121,18 @@ wuffs_tga__decoder__do_decode_image_config(
}
if (self->private_impl.f_header_color_map_type != 0u) {
if ((self->private_impl.f_header_color_map_first_entry_index != 0u) || (self->private_impl.f_header_color_map_length > 256u)) {
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file);
goto exit;
} else if ((self->private_impl.f_header_color_map_entry_size != 15u) &&
(self->private_impl.f_header_color_map_entry_size != 16u) &&
(self->private_impl.f_header_color_map_entry_size != 24u) &&
(self->private_impl.f_header_color_map_entry_size != 32u)) {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
} else {
if ((self->private_impl.f_header_color_map_first_entry_index != 0u) || (self->private_impl.f_header_color_map_length != 0u) || (self->private_impl.f_header_color_map_entry_size != 0u)) {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
}
@@ -67899,7 +73218,7 @@ wuffs_tga__decoder__do_decode_image_config(
(self->private_impl.f_header_pixel_depth != 16u) &&
(self->private_impl.f_header_pixel_depth != 24u) &&
(self->private_impl.f_header_pixel_depth != 32u)) {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
if (((uint8_t)(self->private_impl.f_header_image_type | 8u)) == 9u) {
@@ -67922,7 +73241,7 @@ wuffs_tga__decoder__do_decode_image_config(
self->private_impl.f_src_bytes_per_pixel = 4u;
self->private_impl.f_src_pixfmt = 2164295816u;
} else {
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file);
goto exit;
}
} else {
@@ -67932,7 +73251,7 @@ wuffs_tga__decoder__do_decode_image_config(
self->private_impl.f_src_pixfmt = 536870920u;
self->private_impl.f_opaque = true;
} else {
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file);
goto exit;
}
}
@@ -67946,7 +73265,7 @@ wuffs_tga__decoder__do_decode_image_config(
self->private_impl.f_header_image_descriptor = t_9;
}
if (((uint8_t)(self->private_impl.f_header_image_descriptor & 16u)) != 0u) {
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file);
goto exit;
}
self->private_data.s_do_decode_image_config.scratch = ((uint32_t)(self->private_impl.f_header_id_length));
@@ -68109,12 +73428,12 @@ wuffs_tga__decoder__do_decode_image_config(
return status;
}
// -------- func tga.decoder.decode_frame_config
// -------- func targa.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_frame_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_frame_config(
wuffs_targa__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
@@ -68146,11 +73465,11 @@ wuffs_tga__decoder__decode_frame_config(
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame_config(self, a_dst, a_src);
wuffs_base__status t_0 = wuffs_targa__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
status = wuffs_base__make_status(wuffs_targa__error__truncated_input);
goto exit;
}
status = v_status;
@@ -68175,12 +73494,12 @@ wuffs_tga__decoder__decode_frame_config(
return status;
}
// -------- func tga.decoder.do_decode_frame_config
// -------- func targa.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_frame_config(
wuffs_targa__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
@@ -68206,7 +73525,7 @@ wuffs_tga__decoder__do_decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_tga__decoder__do_decode_image_config(self, NULL, a_src);
status = wuffs_targa__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -68262,12 +73581,12 @@ wuffs_tga__decoder__do_decode_frame_config(
return status;
}
// -------- func tga.decoder.decode_frame
// -------- func targa.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_frame(
wuffs_targa__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
@@ -68302,7 +73621,7 @@ wuffs_tga__decoder__decode_frame(
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame(self,
wuffs_base__status t_0 = wuffs_targa__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
@@ -68311,7 +73630,7 @@ wuffs_tga__decoder__decode_frame(
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
status = wuffs_base__make_status(wuffs_targa__error__truncated_input);
goto exit;
}
status = v_status;
@@ -68336,12 +73655,12 @@ wuffs_tga__decoder__decode_frame(
return status;
}
// -------- func tga.decoder.do_decode_frame
// -------- func targa.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_frame(
wuffs_targa__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
@@ -68401,7 +73720,7 @@ wuffs_tga__decoder__do_decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_tga__decoder__do_decode_frame_config(self, NULL, a_src);
status = wuffs_targa__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -68503,7 +73822,7 @@ wuffs_tga__decoder__do_decode_frame(
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1u);
iop_a_src += 1u;
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding);
goto exit;
}
} else {
@@ -68549,7 +73868,7 @@ wuffs_tga__decoder__do_decode_frame(
iop_a_src += 1u;
}
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding);
goto exit;
}
}
@@ -68593,7 +73912,7 @@ wuffs_tga__decoder__do_decode_frame(
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1u);
iop_a_src += 1u;
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding);
goto exit;
}
} else {
@@ -68614,7 +73933,7 @@ wuffs_tga__decoder__do_decode_frame(
self->private_data.f_scratch[2u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u))));
self->private_data.f_scratch[3u] = 255u;
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding);
goto exit;
}
}
@@ -68661,12 +73980,12 @@ wuffs_tga__decoder__do_decode_frame(
return status;
}
// -------- func tga.decoder.frame_dirty_rect
// -------- func targa.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_tga__decoder__frame_dirty_rect(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__frame_dirty_rect(
const wuffs_targa__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
@@ -68682,12 +74001,12 @@ wuffs_tga__decoder__frame_dirty_rect(
self->private_impl.f_height);
}
// -------- func tga.decoder.num_animation_loops
// -------- func targa.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_tga__decoder__num_animation_loops(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__num_animation_loops(
const wuffs_targa__decoder* self) {
if (!self) {
return 0;
}
@@ -68699,12 +74018,12 @@ wuffs_tga__decoder__num_animation_loops(
return 0u;
}
// -------- func tga.decoder.num_decoded_frame_configs
// -------- func targa.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__num_decoded_frame_configs(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__num_decoded_frame_configs(
const wuffs_targa__decoder* self) {
if (!self) {
return 0;
}
@@ -68719,12 +74038,12 @@ wuffs_tga__decoder__num_decoded_frame_configs(
return 0u;
}
// -------- func tga.decoder.num_decoded_frames
// -------- func targa.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__num_decoded_frames(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__num_decoded_frames(
const wuffs_targa__decoder* self) {
if (!self) {
return 0;
}
@@ -68739,12 +74058,12 @@ wuffs_tga__decoder__num_decoded_frames(
return 0u;
}
// -------- func tga.decoder.restart_frame
// -------- func targa.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__restart_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__restart_frame(
wuffs_targa__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
@@ -68768,23 +74087,23 @@ wuffs_tga__decoder__restart_frame(
return wuffs_base__make_status(NULL);
}
// -------- func tga.decoder.set_report_metadata
// -------- func targa.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_tga__decoder__set_report_metadata(
wuffs_tga__decoder* self,
wuffs_targa__decoder__set_report_metadata(
wuffs_targa__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func tga.decoder.tell_me_more
// -------- func targa.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__tell_me_more(
wuffs_tga__decoder* self,
wuffs_targa__decoder__tell_me_more(
wuffs_targa__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
@@ -68822,12 +74141,12 @@ wuffs_tga__decoder__tell_me_more(
return status;
}
// -------- func tga.decoder.workbuf_len
// -------- func targa.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_tga__decoder__workbuf_len(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__workbuf_len(
const wuffs_targa__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
@@ -68839,7 +74158,1719 @@ wuffs_tga__decoder__workbuf_len(
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
// ---------------- Status Codes Implementations
const char wuffs_thumbhash__error__bad_header[] = "#thumbhash: bad header";
const char wuffs_thumbhash__error__truncated_input[] = "#thumbhash: truncated input";
// ---------------- Private Consts
#define WUFFS_THUMBHASH__QUIRKS_BASE 1712283648u
static const uint8_t
WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 14u, 18u, 19u, 23u, 26u, 27u, 32u,
};
static const uint8_t
WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 0u, 14u, 32u, 51u, 74u, 100u, 127u,
};
static const uint8_t
WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[2][8] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
23u, 23u, 23u, 23u, 39u, 71u, 103u, 119u,
}, {
55u, 55u, 55u, 55u, 87u, 119u, 118u, 116u,
},
};
static const uint16_t
WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[16] WUFFS_BASE__POTENTIALLY_UNUSED = {
49152u, 51337u, 53521u, 55706u, 57890u, 60075u, 62259u, 64444u,
1092u, 3277u, 5461u, 7646u, 9830u, 12015u, 14199u, 16384u,
};
static const uint16_t
WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[16] WUFFS_BASE__POTENTIALLY_UNUSED = {
45056u, 47787u, 50517u, 53248u, 55979u, 58709u, 61440u, 64171u,
1365u, 4096u, 6827u, 9557u, 12288u, 15019u, 17749u, 20480u,
};
static const uint16_t
WUFFS_THUMBHASH__COSINES[159][6] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
16281u, 15973u, 15465u, 14761u, 13873u, 12810u,
}, {
15465u, 12810u, 8717u, 3646u, 63702u, 58427u,
}, {
13873u, 7109u, 63702u, 55321u, 50071u, 49563u,
}, {
11585u, 0u, 53951u, 49152u, 53951u, 0u,
}, {
8717u, 58427u, 49255u, 55321u, 5411u, 15973u,
}, {
5411u, 52726u, 51663u, 3646u, 16281u, 7109u,
}, {
1834u, 49563u, 60125u, 14761u, 8717u, 52726u,
}, {
63702u, 49563u, 5411u, 14761u, 56819u, 52726u,
},
{
60125u, 52726u, 13873u, 3646u, 49255u, 7109u,
}, {
56819u, 58427u, 16281u, 55321u, 60125u, 15973u,
}, {
53951u, 0u, 11585u, 49152u, 11585u, 0u,
}, {
51663u, 7109u, 1834u, 55321u, 15465u, 49563u,
}, {
50071u, 12810u, 56819u, 3646u, 1834u, 58427u,
}, {
49255u, 15973u, 50071u, 14761u, 51663u, 12810u,
}, {
16322u, 16135u, 15826u, 15396u, 14849u, 14189u,
}, {
15826u, 14189u, 11585u, 8192u, 4240u, 0u,
},
{
14849u, 10531u, 4240u, 62691u, 56139u, 51347u,
}, {
13421u, 5604u, 61296u, 52985u, 49214u, 51347u,
}, {
11585u, 0u, 53951u, 49152u, 53951u, 0u,
}, {
9397u, 59932u, 49710u, 52985u, 1428u, 14189u,
}, {
6924u, 55005u, 49710u, 62691u, 13421u, 14189u,
}, {
4240u, 51347u, 53951u, 8192u, 15826u, 0u,
}, {
1428u, 49401u, 61296u, 15396u, 6924u, 51347u,
}, {
64108u, 49401u, 4240u, 15396u, 58612u, 51347u,
},
{
61296u, 51347u, 11585u, 8192u, 49710u, 0u,
}, {
58612u, 55005u, 15826u, 62691u, 52115u, 14189u,
}, {
56139u, 59932u, 15826u, 52985u, 64108u, 14189u,
}, {
53951u, 0u, 11585u, 49152u, 11585u, 0u,
}, {
52115u, 5604u, 4240u, 52985u, 16322u, 51347u,
}, {
50687u, 10531u, 61296u, 62691u, 9397u, 51347u,
}, {
49710u, 14189u, 53951u, 8192u, 61296u, 0u,
}, {
49214u, 16135u, 49710u, 15396u, 50687u, 14189u,
},
{
16328u, 16161u, 15883u, 15496u, 15004u, 14409u,
}, {
15883u, 14409u, 12054u, 8961u, 5320u, 1353u,
}, {
15004u, 11097u, 5320u, 64183u, 57738u, 52607u,
}, {
13716u, 6581u, 62839u, 54439u, 49653u, 50040u,
}, {
12054u, 1353u, 55473u, 49375u, 51820u, 61514u,
}, {
10063u, 61514u, 50532u, 51127u, 62839u, 11097u,
}, {
7798u, 56575u, 49208u, 58955u, 10063u, 16161u,
}, {
5320u, 52607u, 51820u, 4022u, 16328u, 6581u,
},
{
2697u, 50040u, 57738u, 12929u, 12054u, 56575u,
}, {
0u, 49152u, 0u, 16384u, 0u, 49152u,
}, {
62839u, 50040u, 7798u, 12929u, 53482u, 56575u,
}, {
60216u, 52607u, 13716u, 4022u, 49208u, 6581u,
}, {
57738u, 56575u, 16328u, 58955u, 55473u, 16161u,
}, {
55473u, 61514u, 15004u, 51127u, 2697u, 11097u,
}, {
53482u, 1353u, 10063u, 49375u, 13716u, 61514u,
}, {
51820u, 6581u, 2697u, 54439u, 15883u, 50040u,
},
{
50532u, 11097u, 60216u, 64183u, 7798u, 52607u,
}, {
49653u, 14409u, 53482u, 8961u, 60216u, 1353u,
}, {
49208u, 16161u, 49653u, 15496u, 50532u, 14409u,
}, {
16346u, 16231u, 16041u, 15776u, 15438u, 15028u,
}, {
16041u, 15028u, 13385u, 11183u, 8513u, 5487u,
}, {
15438u, 12709u, 8513u, 3333u, 63305u, 57998u,
}, {
14547u, 9448u, 2231u, 60049u, 53562u, 49760u,
}, {
13385u, 5487u, 61116u, 52827u, 49190u, 51537u,
},
{
11974u, 1118u, 55196u, 49305u, 52151u, 62203u,
}, {
10340u, 62203u, 50989u, 50508u, 61116u, 9448u,
}, {
8513u, 57998u, 49190u, 56088u, 6527u, 16231u,
}, {
6527u, 54353u, 50098u, 64418u, 14547u, 12709u,
}, {
4420u, 51537u, 53562u, 7538u, 16041u, 1118u,
}, {
2231u, 49760u, 59009u, 13999u, 10340u, 54353u,
}, {
0u, 49152u, 0u, 16384u, 0u, 49152u,
}, {
63305u, 49760u, 6527u, 13999u, 55196u, 54353u,
},
{
61116u, 51537u, 11974u, 7538u, 49495u, 1118u,
}, {
59009u, 54353u, 15438u, 64418u, 50989u, 12709u,
}, {
57023u, 57998u, 16346u, 56088u, 59009u, 16231u,
}, {
55196u, 62203u, 14547u, 50508u, 4420u, 9448u,
}, {
53562u, 1118u, 10340u, 49305u, 13385u, 62203u,
}, {
52151u, 5487u, 4420u, 52827u, 16346u, 51537u,
}, {
50989u, 9448u, 63305u, 60049u, 11974u, 49760u,
}, {
50098u, 12709u, 57023u, 3333u, 2231u, 57998u,
},
{
49495u, 15028u, 52151u, 11183u, 57023u, 5487u,
}, {
49190u, 16231u, 49495u, 15776u, 50098u, 15028u,
}, {
16354u, 16265u, 16116u, 15908u, 15642u, 15319u,
}, {
16116u, 15319u, 14021u, 12264u, 10104u, 7614u,
}, {
15642u, 13484u, 10104u, 5810u, 989u, 61615u,
}, {
14941u, 10865u, 4874u, 63561u, 57060u, 52052u,
}, {
14021u, 7614u, 64547u, 56229u, 50595u, 49271u,
}, {
12897u, 3921u, 58812u, 51029u, 49420u, 54671u,
},
{
11585u, 0u, 53951u, 49152u, 53951u, 0u,
}, {
10104u, 61615u, 50595u, 51029u, 62583u, 10865u,
}, {
8476u, 57922u, 49182u, 56229u, 6724u, 16265u,
}, {
6724u, 54671u, 49894u, 63561u, 14021u, 13484u,
}, {
4874u, 52052u, 52639u, 5810u, 16354u, 3921u,
}, {
2953u, 50217u, 57060u, 12264u, 12897u, 57922u,
}, {
989u, 49271u, 62583u, 15908u, 4874u, 50217u,
}, {
64547u, 49271u, 2953u, 15908u, 60662u, 50217u,
},
{
62583u, 50217u, 8476u, 12264u, 52639u, 57922u,
}, {
60662u, 52052u, 12897u, 5810u, 49182u, 3921u,
}, {
58812u, 54671u, 15642u, 63561u, 51515u, 13484u,
}, {
57060u, 57922u, 16354u, 56229u, 58812u, 16265u,
}, {
55432u, 61615u, 14941u, 51029u, 2953u, 10865u,
}, {
53951u, 0u, 11585u, 49152u, 11585u, 0u,
}, {
52639u, 3921u, 6724u, 51029u, 16116u, 54671u,
}, {
51515u, 7614u, 989u, 56229u, 14941u, 49271u,
},
{
50595u, 10865u, 60662u, 63561u, 8476u, 52052u,
}, {
49894u, 13484u, 55432u, 5810u, 64547u, 61615u,
}, {
49420u, 15319u, 51515u, 12264u, 55432u, 7614u,
}, {
49182u, 16265u, 49420u, 15908u, 49894u, 15319u,
}, {
16356u, 16273u, 16135u, 15942u, 15696u, 15396u,
}, {
16135u, 15396u, 14189u, 12551u, 10531u, 8192u,
}, {
15696u, 13689u, 10531u, 6489u, 1902u, 62691u,
}, {
15044u, 11243u, 5604u, 64583u, 58183u, 52985u,
},
{
14189u, 8192u, 0u, 57344u, 51347u, 49152u,
}, {
13142u, 4699u, 59932u, 51847u, 49180u, 52985u,
}, {
11917u, 953u, 55005u, 49263u, 52394u, 62691u,
}, {
10531u, 62691u, 51347u, 50140u, 59932u, 8192u,
}, {
9003u, 59047u, 49401u, 54293u, 3778u, 15396u,
}, {
7353u, 55752u, 49401u, 60837u, 11917u, 15396u,
}, {
5604u, 52985u, 51347u, 2845u, 16135u, 8192u,
}, {
3778u, 50895u, 55005u, 9784u, 15044u, 62691u,
},
{
1902u, 49594u, 59932u, 14641u, 9003u, 52985u,
}, {
0u, 49152u, 0u, 16384u, 0u, 49152u,
}, {
63634u, 49594u, 5604u, 14641u, 56533u, 52985u,
}, {
61758u, 50895u, 10531u, 9784u, 50492u, 62691u,
}, {
59932u, 52985u, 14189u, 2845u, 49401u, 8192u,
}, {
58183u, 55752u, 16135u, 60837u, 53619u, 15396u,
}, {
56533u, 59047u, 16135u, 54293u, 61758u, 15396u,
}, {
55005u, 62691u, 14189u, 50140u, 5604u, 8192u,
},
{
53619u, 953u, 10531u, 49263u, 13142u, 62691u,
}, {
52394u, 4699u, 5604u, 51847u, 16356u, 52985u,
}, {
51347u, 8192u, 0u, 57344u, 14189u, 49152u,
}, {
50492u, 11243u, 59932u, 64583u, 7353u, 52985u,
}, {
49840u, 13689u, 55005u, 6489u, 63634u, 62691u,
}, {
49401u, 15396u, 51347u, 12551u, 55005u, 8192u,
}, {
49180u, 16273u, 49401u, 15942u, 49840u, 15396u,
}, {
16364u, 16305u, 16207u, 16069u, 15893u, 15679u,
},
{
16207u, 15679u, 14811u, 13623u, 12140u, 10394u,
}, {
15893u, 14449u, 12140u, 9102u, 5520u, 1606u,
}, {
15426u, 12665u, 8423u, 3196u, 63132u, 57813u,
}, {
14811u, 10394u, 3981u, 62340u, 55776u, 51087u,
}, {
14053u, 7723u, 64732u, 56434u, 50725u, 49231u,
}, {
13160u, 4756u, 60016u, 51913u, 49172u, 52871u,
}, {
12140u, 1606u, 55776u, 49467u, 51483u, 60780u,
}, {
11003u, 63930u, 52376u, 49467u, 57113u, 4756u,
},
{
9760u, 60780u, 50110u, 51913u, 64732u, 12665u,
}, {
8423u, 57813u, 49172u, 56434u, 7005u, 16305u,
}, {
7005u, 55142u, 49643u, 62340u, 13160u, 14449u,
}, {
5520u, 52871u, 51483u, 3196u, 16207u, 7723u,
}, {
3981u, 51087u, 54533u, 9102u, 15426u, 63930u,
}, {
2404u, 49857u, 58531u, 13623u, 11003u, 55142u,
}, {
804u, 49231u, 63132u, 16069u, 3981u, 49857u,
}, {
64732u, 49231u, 2404u, 16069u, 61555u, 49857u,
},
{
63132u, 49857u, 7005u, 13623u, 54533u, 55142u,
}, {
61555u, 51087u, 11003u, 9102u, 50110u, 63930u,
}, {
60016u, 52871u, 14053u, 3196u, 49329u, 7723u,
}, {
58531u, 55142u, 15893u, 62340u, 52376u, 14449u,
}, {
57113u, 57813u, 16364u, 56434u, 58531u, 16305u,
}, {
55776u, 60780u, 15426u, 51913u, 804u, 12665u,
}, {
54533u, 63930u, 13160u, 49467u, 8423u, 4756u,
}, {
53396u, 1606u, 9760u, 49467u, 14053u, 60780u,
},
{
52376u, 4756u, 5520u, 51913u, 16364u, 52871u,
}, {
51483u, 7723u, 804u, 56434u, 14811u, 49231u,
}, {
50725u, 10394u, 61555u, 62340u, 9760u, 51087u,
}, {
50110u, 12665u, 57113u, 3196u, 2404u, 57813u,
}, {
49643u, 14449u, 53396u, 9102u, 60016u, 1606u,
}, {
49329u, 15679u, 50725u, 13623u, 53396u, 10394u,
}, {
49172u, 16305u, 49329u, 16069u, 49643u, 15679u,
},
};
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_src_to_coeffs(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_thumbhash__decoder__from_coeffs_to_pixels(
wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_pixels_to_dst(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_thumbhash__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_thumbhash__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_thumbhash__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_thumbhash__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_thumbhash__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_thumbhash__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_thumbhash__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_thumbhash__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_thumbhash__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_thumbhash__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_thumbhash__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_thumbhash__decoder__initialize(
wuffs_thumbhash__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (sizeof(*self) != sizeof_star_self) {
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
}
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
}
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
// The whole point of this if-check is to detect an uninitialized *self.
// We disable the warning on GCC. Clang-5.0 does not have this warning.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (self->private_impl.magic != 0) {
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
}
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_thumbhash__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_thumbhash__decoder*
wuffs_thumbhash__decoder__alloc(void) {
wuffs_thumbhash__decoder* x =
(wuffs_thumbhash__decoder*)(calloc(1, sizeof(wuffs_thumbhash__decoder)));
if (!x) {
return NULL;
}
if (wuffs_thumbhash__decoder__initialize(
x, sizeof(wuffs_thumbhash__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
return x;
}
size_t
sizeof__wuffs_thumbhash__decoder(void) {
return sizeof(wuffs_thumbhash__decoder);
}
// ---------------- Function Implementations
// -------- func thumbhash.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__get_quirk(
const wuffs_thumbhash__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if ((a_key == 1712283648u) && self->private_impl.f_quirk_just_raw_thumbhash) {
return 1u;
}
return 0u;
}
// -------- func thumbhash.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__set_quirk(
wuffs_thumbhash__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (a_key == 1712283648u) {
self->private_impl.f_quirk_just_raw_thumbhash = (a_value > 0u);
return wuffs_base__make_status(NULL);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func thumbhash.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_c32 = 0;
uint8_t v_swap = 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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0u) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
if ( ! self->private_impl.f_quirk_just_raw_thumbhash) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
t_0 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
iop_a_src += 3;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 == 16) {
t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_c32 = t_0;
}
if (v_c32 != 16694979u) {
status = wuffs_base__make_status(wuffs_thumbhash__error__bad_header);
goto exit;
}
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
t_1 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
iop_a_src += 3;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 == 16) {
t_1 = ((uint32_t)(*scratch));
break;
}
num_bits_1 += 8u;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
v_c32 = t_1;
}
self->private_impl.f_l_dc = (((uint64_t)(((v_c32 >> 0u) & 63u))) * 136339441844224u);
self->private_impl.f_p_dc = ((uint64_t)((((uint64_t)(((v_c32 >> 6u) & 63u))) * 272678883688448u) - 8589384836186112u));
self->private_impl.f_q_dc = ((uint64_t)((((uint64_t)(((v_c32 >> 12u) & 63u))) * 272678883688448u) - 8589384836186112u));
self->private_impl.f_l_scale = ((uint8_t)(((v_c32 >> 18u) & 31u)));
self->private_impl.f_has_alpha = ((uint8_t)(((v_c32 >> 23u) & 1u)));
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint32_t t_2;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_2 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
if (num_bits_2 == 8) {
t_2 = ((uint32_t)(*scratch));
break;
}
num_bits_2 += 8u;
*scratch |= ((uint64_t)(num_bits_2)) << 56;
}
}
v_c32 = t_2;
}
self->private_impl.f_l_count = ((uint8_t)(((v_c32 >> 0u) & 7u)));
self->private_impl.f_p_scale = ((uint8_t)(((v_c32 >> 3u) & 63u)));
self->private_impl.f_q_scale = ((uint8_t)(((v_c32 >> 9u) & 63u)));
self->private_impl.f_is_landscape = ((uint8_t)(((v_c32 >> 15u) & 1u)));
self->private_impl.f_w_dimension_code = ((uint8_t)(((uint8_t)(WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[self->private_impl.f_has_alpha][self->private_impl.f_l_count] >> 4u)) & 7u));
self->private_impl.f_h_dimension_code = ((uint8_t)(((uint8_t)(WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[self->private_impl.f_has_alpha][self->private_impl.f_l_count] >> 0u)) & 7u));
if (self->private_impl.f_is_landscape != 0u) {
v_swap = self->private_impl.f_w_dimension_code;
self->private_impl.f_w_dimension_code = self->private_impl.f_h_dimension_code;
self->private_impl.f_h_dimension_code = v_swap;
}
if (self->private_impl.f_is_landscape != 0u) {
self->private_impl.f_lx = ((uint32_t)(((uint8_t)(7u - ((uint8_t)(2u * self->private_impl.f_has_alpha))))));
self->private_impl.f_ly = ((uint32_t)(wuffs_base__u8__max(self->private_impl.f_l_count, 3u)));
} else {
self->private_impl.f_lx = ((uint32_t)(wuffs_base__u8__max(self->private_impl.f_l_count, 3u)));
self->private_impl.f_ly = ((uint32_t)(((uint8_t)(7u - ((uint8_t)(2u * self->private_impl.f_has_alpha))))));
}
self->private_impl.f_frame_config_io_position = 8u;
if (self->private_impl.f_has_alpha != 0u) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint32_t t_3 = *iop_a_src++;
v_c32 = t_3;
}
self->private_impl.f_a_dc = (((uint64_t)(((v_c32 >> 0u) & 15u))) << 42u);
self->private_impl.f_a_scale = ((uint8_t)(((v_c32 >> 4u) & 15u)));
self->private_impl.f_frame_config_io_position = 9u;
}
if (self->private_impl.f_quirk_just_raw_thumbhash) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
self->private_impl.f_frame_config_io_position -= 3u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
}
self->private_impl.f_pixfmt = 2415954056u;
if (self->private_impl.f_has_alpha != 0u) {
self->private_impl.f_pixfmt = 2164295816u;
}
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
self->private_impl.f_pixfmt,
0u,
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])),
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code])),
((uint64_t)(self->private_impl.f_frame_config_io_position)),
(self->private_impl.f_has_alpha == 0u));
}
self->private_impl.f_call_sequence = 32u;
goto ok;
ok:
self->private_impl.p_do_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func thumbhash.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 2)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 32u) {
} else if (self->private_impl.f_call_sequence < 32u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_thumbhash__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 40u) {
if (((uint64_t)(self->private_impl.f_frame_config_io_position)) != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
goto exit;
}
} else if (self->private_impl.f_call_sequence == 64u) {
self->private_impl.f_call_sequence = 96u;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])),
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code]))),
((wuffs_base__flicks)(0u)),
0u,
((uint64_t)(self->private_impl.f_frame_config_io_position)),
0u,
(self->private_impl.f_has_alpha == 0u),
false,
0u);
}
self->private_impl.f_call_sequence = 64u;
ok:
self->private_impl.p_do_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func thumbhash.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 3)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64u) {
} else if (self->private_impl.f_call_sequence < 64u) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_thumbhash__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
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(a_dst),
wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
wuffs_base__utility__empty_slice_u8(),
a_blend);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_thumbhash__decoder__from_src_to_coeffs(self, a_src);
if (status.repr) {
goto suspend;
}
wuffs_thumbhash__decoder__from_coeffs_to_pixels(self);
v_status = wuffs_thumbhash__decoder__from_pixels_to_dst(self, a_dst);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
self->private_impl.f_call_sequence = 96u;
ok:
self->private_impl.p_do_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
return status;
}
// -------- func thumbhash.decoder.from_src_to_coeffs
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_src_to_coeffs(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c8 = 0;
uint32_t v_cy = 0;
uint32_t v_cx = 0;
uint32_t v_i = 0;
bool v_has_bits = false;
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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_from_src_to_coeffs;
if (coro_susp_point) {
v_cy = self->private_data.s_from_src_to_coeffs.v_cy;
v_cx = self->private_data.s_from_src_to_coeffs.v_cx;
v_i = self->private_data.s_from_src_to_coeffs.v_i;
v_has_bits = self->private_data.s_from_src_to_coeffs.v_has_bits;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
v_i = 0u;
v_cy = 0u;
while (v_cy < self->private_impl.f_ly) {
v_cx = 0u;
if (v_cy == 0u) {
v_cx = 1u;
}
while (((uint32_t)(v_cx * self->private_impl.f_ly)) < ((uint32_t)(self->private_impl.f_lx * ((uint32_t)(self->private_impl.f_ly - v_cy))))) {
if (v_has_bits) {
v_has_bits = false;
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
v_c8 >>= 4u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_has_bits = true;
{
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_c8 = t_0;
}
}
self->private_data.f_lac[(v_i & 31u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_l_scale)) * 126u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[((uint8_t)(v_c8 & 15u))])));
v_i += 1u;
v_cx += 1u;
}
v_cy += 1u;
}
v_i = 0u;
v_cx = 0u;
while (v_cx < 5u) {
if (v_has_bits) {
v_has_bits = false;
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
v_c8 >>= 4u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_has_bits = true;
{
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_c8 = t_1;
}
}
self->private_data.f_pac[(v_i & 7u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_p_scale)) * 62u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[((uint8_t)(v_c8 & 15u))])));
v_i += 1u;
v_cx += 1u;
}
v_i = 0u;
v_cx = 0u;
while (v_cx < 5u) {
if (v_has_bits) {
v_has_bits = false;
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
v_c8 >>= 4u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_has_bits = true;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_2 = *iop_a_src++;
v_c8 = t_2;
}
}
self->private_data.f_qac[(v_i & 7u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_q_scale)) * 62u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[((uint8_t)(v_c8 & 15u))])));
v_i += 1u;
v_cx += 1u;
}
if (self->private_impl.f_has_alpha == 0u) {
status = wuffs_base__make_status(NULL);
goto ok;
}
v_i = 0u;
v_cx = 0u;
while (v_cx < 14u) {
if (v_has_bits) {
v_has_bits = false;
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
v_c8 >>= 4u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_has_bits = true;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_3 = *iop_a_src++;
v_c8 = t_3;
}
}
self->private_data.f_aac[(v_i & 15u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_a_scale)) * 2u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[((uint8_t)(v_c8 & 15u))])));
v_i += 1u;
v_cx += 1u;
}
ok:
self->private_impl.p_from_src_to_coeffs = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_from_src_to_coeffs = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_from_src_to_coeffs.v_cy = v_cy;
self->private_data.s_from_src_to_coeffs.v_cx = v_cx;
self->private_data.s_from_src_to_coeffs.v_i = v_i;
self->private_data.s_from_src_to_coeffs.v_has_bits = v_has_bits;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func thumbhash.decoder.from_coeffs_to_pixels
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_thumbhash__decoder__from_coeffs_to_pixels(
wuffs_thumbhash__decoder* self) {
uint32_t v_h = 0;
uint32_t v_w = 0;
uint32_t v_fy[8] = {0};
uint32_t v_fx[8] = {0};
uint32_t v_cosines_base_y = 0;
uint32_t v_cosines_base_x = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_f = 0;
uint64_t v_l = 0;
uint64_t v_p = 0;
uint64_t v_q = 0;
uint64_t v_b = 0;
uint64_t v_g = 0;
uint64_t v_r = 0;
uint64_t v_a = 0;
uint32_t v_i = 0;
uint32_t v_cy = 0;
uint32_t v_cx = 0;
v_h = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code]));
v_w = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code]));
v_fy[0u] = 16384u;
v_fx[0u] = 16384u;
v_a = 255u;
v_y = 0u;
while (v_y < v_h) {
v_cosines_base_y = ((uint32_t)(WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[self->private_impl.f_h_dimension_code]));
v_fy[1u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][0u]);
v_fy[2u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][1u]);
v_fy[3u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][2u]);
v_fy[4u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][3u]);
v_fy[5u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][4u]);
v_fy[6u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][5u]);
v_x = 0u;
while (v_x < v_w) {
v_cosines_base_x = ((uint32_t)(WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[self->private_impl.f_w_dimension_code]));
v_fx[1u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][0u]);
v_fx[2u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][1u]);
v_fx[3u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][2u]);
v_fx[4u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][3u]);
v_fx[5u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][4u]);
v_fx[6u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][5u]);
v_l = self->private_impl.f_l_dc;
v_i = 0u;
v_cy = 0u;
while (v_cy < self->private_impl.f_ly) {
v_cx = 0u;
if (v_cy == 0u) {
v_cx = 1u;
}
while (((uint32_t)(v_cx * self->private_impl.f_ly)) < ((uint32_t)(self->private_impl.f_lx * ((uint32_t)(self->private_impl.f_ly - v_cy))))) {
v_f = ((uint32_t)(v_fx[(v_cx & 7u)] * v_fy[(v_cy & 7u)]));
v_l += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_lac[(v_i & 31u)])));
v_i += 1u;
v_cx += 1u;
}
v_cy += 1u;
}
v_p = self->private_impl.f_p_dc;
v_q = self->private_impl.f_q_dc;
v_i = 0u;
v_cy = 0u;
while (v_cy < 3u) {
v_cx = 0u;
if (v_cy == 0u) {
v_cx = 1u;
}
while (v_cx < (3u - v_cy)) {
v_f = ((uint32_t)(v_fx[v_cx] * v_fy[v_cy]));
v_p += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_pac[(v_i & 7u)])));
v_q += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_qac[(v_i & 7u)])));
v_i += 1u;
v_cx += 1u;
}
v_cy += 1u;
}
v_b = ((uint64_t)(v_l - wuffs_base__utility__i64_divide(((uint64_t)(2u * v_p)), 3u)));
v_r = wuffs_base__utility__sign_extend_rshift_u64(((uint64_t)(((uint64_t)(((uint64_t)(3u * v_l)) + v_q)) - v_b)), 1u);
v_g = ((uint64_t)(v_r - v_q));
if ((v_b >> 63u) != 0u) {
v_b = 0u;
} else if (v_b >= 8589384836185950u) {
v_b = 255u;
} else {
v_b /= 33683862102690u;
}
if ((v_g >> 63u) != 0u) {
v_g = 0u;
} else if (v_g >= 8589384836185950u) {
v_g = 255u;
} else {
v_g /= 33683862102690u;
}
if ((v_r >> 63u) != 0u) {
v_r = 0u;
} else if (v_r >= 8589384836185950u) {
v_r = 255u;
} else {
v_r /= 33683862102690u;
}
if (self->private_impl.f_has_alpha != 0u) {
v_a = self->private_impl.f_a_dc;
v_i = 0u;
v_cy = 0u;
while (v_cy < 5u) {
v_cx = 0u;
if (v_cy == 0u) {
v_cx = 1u;
}
while (v_cx < (5u - v_cy)) {
v_f = ((uint32_t)(v_fx[v_cx] * v_fy[v_cy]));
v_a += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_aac[(v_i & 15u)])));
v_i += 1u;
v_cx += 1u;
}
v_cy += 1u;
}
if ((v_a >> 63u) != 0u) {
v_a = 0u;
} else if (v_a >= 65970697666500u) {
v_a = 255u;
} else {
v_a /= 258708618300u;
}
}
self->private_data.f_pixels[v_y][((4u * v_x) + 0u)] = ((uint8_t)(v_b));
self->private_data.f_pixels[v_y][((4u * v_x) + 1u)] = ((uint8_t)(v_g));
self->private_data.f_pixels[v_y][((4u * v_x) + 2u)] = ((uint8_t)(v_r));
self->private_data.f_pixels[v_y][((4u * v_x) + 3u)] = ((uint8_t)(v_a));
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func thumbhash.decoder.from_pixels_to_dst
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_pixels_to_dst(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst) {
uint32_t v_h = 0;
uint32_t v_w = 0;
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint32_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
wuffs_base__table_u8 v_tab = {0};
uint32_t v_y = 0;
wuffs_base__slice_u8 v_dst = {0};
wuffs_base__slice_u8 v_src = {0};
v_h = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code]));
v_w = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code]));
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
if ((v_dst_bits_per_pixel & 7u) != 0u) {
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8u);
v_dst_bytes_per_row = ((uint64_t)((v_w * v_dst_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u);
while (v_y < v_h) {
v_src = wuffs_base__make_slice_u8(self->private_data.f_pixels[v_y], (v_w * 4u));
v_dst = wuffs_private_impl__table_u8__row_u32(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);
}
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__pixel_buffer__palette(a_dst), v_src);
v_y += 1u;
}
return wuffs_base__make_status(NULL);
}
// -------- func thumbhash.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_thumbhash__decoder__frame_dirty_rect(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_rect_ie_u32();
}
return wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])),
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code])));
}
// -------- func thumbhash.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_thumbhash__decoder__num_animation_loops(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func thumbhash.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frame_configs(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 32u) {
return 1u;
}
return 0u;
}
// -------- func thumbhash.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frames(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 64u) {
return 1u;
}
return 0u;
}
// -------- func thumbhash.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__restart_frame(
wuffs_thumbhash__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (self->private_impl.f_call_sequence < 32u) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if ((a_index != 0u) || (a_io_position != ((uint64_t)(self->private_impl.f_frame_config_io_position)))) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 40u;
return wuffs_base__make_status(NULL);
}
// -------- func thumbhash.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_thumbhash__decoder__set_report_metadata(
wuffs_thumbhash__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func thumbhash.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__tell_me_more(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 4)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
goto ok;
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_thumbhash__decoder__workbuf_len(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_range_ii_u64();
}
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__VP8)
@@ -68901,7 +75932,7 @@ wuffs_vp8__placeholder__initialize(
wuffs_vp8__placeholder*
wuffs_vp8__placeholder__alloc(void) {
wuffs_vp8__placeholder* x =
(wuffs_vp8__placeholder*)(calloc(sizeof(wuffs_vp8__placeholder), 1));
(wuffs_vp8__placeholder*)(calloc(1, sizeof(wuffs_vp8__placeholder)));
if (!x) {
return NULL;
}
@@ -69049,7 +76080,7 @@ wuffs_wbmp__decoder__initialize(
wuffs_wbmp__decoder*
wuffs_wbmp__decoder__alloc(void) {
wuffs_wbmp__decoder* x =
(wuffs_wbmp__decoder*)(calloc(sizeof(wuffs_wbmp__decoder), 1));
(wuffs_wbmp__decoder*)(calloc(1, sizeof(wuffs_wbmp__decoder)));
if (!x) {
return NULL;
}
@@ -70184,7 +77215,7 @@ wuffs_webp__decoder__initialize(
wuffs_webp__decoder*
wuffs_webp__decoder__alloc(void) {
wuffs_webp__decoder* x =
(wuffs_webp__decoder*)(calloc(sizeof(wuffs_webp__decoder), 1));
(wuffs_webp__decoder*)(calloc(1, sizeof(wuffs_webp__decoder)));
if (!x) {
return NULL;
}
@@ -73919,7 +80950,7 @@ wuffs_xxhash32__hasher__initialize(
wuffs_xxhash32__hasher*
wuffs_xxhash32__hasher__alloc(void) {
wuffs_xxhash32__hasher* x =
(wuffs_xxhash32__hasher*)(calloc(sizeof(wuffs_xxhash32__hasher), 1));
(wuffs_xxhash32__hasher*)(calloc(1, sizeof(wuffs_xxhash32__hasher)));
if (!x) {
return NULL;
}
@@ -74332,7 +81363,7 @@ wuffs_xxhash64__hasher__initialize(
wuffs_xxhash64__hasher*
wuffs_xxhash64__hasher__alloc(void) {
wuffs_xxhash64__hasher* x =
(wuffs_xxhash64__hasher*)(calloc(sizeof(wuffs_xxhash64__hasher), 1));
(wuffs_xxhash64__hasher*)(calloc(1, sizeof(wuffs_xxhash64__hasher)));
if (!x) {
return NULL;
}
@@ -74760,7 +81791,7 @@ WUFFS_XZ__FILTER_06_IA64_BRANCH_TABLE[32] WUFFS_BASE__POTENTIALLY_UNUSED = {
4u, 4u, 0u, 0u, 4u, 4u, 0u, 0u,
};
#define WUFFS_XZ__QUIRKS_BASE 2021322752u
#define WUFFS_XZ__QUIRKS_BASE 1963655168u
static const uint8_t
WUFFS_XZ__CHECKSUM_LENGTH[4] WUFFS_BASE__POTENTIALLY_UNUSED = {
@@ -74973,7 +82004,7 @@ wuffs_xz__decoder__initialize(
wuffs_xz__decoder*
wuffs_xz__decoder__alloc(void) {
wuffs_xz__decoder* x =
(wuffs_xz__decoder*)(calloc(sizeof(wuffs_xz__decoder), 1));
(wuffs_xz__decoder*)(calloc(1, sizeof(wuffs_xz__decoder)));
if (!x) {
return NULL;
}
@@ -75504,7 +82535,7 @@ wuffs_xz__decoder__get_quirk(
if (self->private_impl.f_ignore_checksum) {
return 1u;
}
} else if (a_key == 2021322752u) {
} else if (a_key == 1963655168u) {
if (self->private_impl.f_standalone_format) {
return 1u;
}
@@ -75533,7 +82564,7 @@ wuffs_xz__decoder__set_quirk(
if (a_key == 1u) {
self->private_impl.f_ignore_checksum = (a_value > 0u);
return wuffs_base__make_status(NULL);
} else if (a_key == 2021322752u) {
} else if (a_key == 1963655168u) {
self->private_impl.f_standalone_format = (a_value > 0u);
return wuffs_base__make_status(NULL);
}
@@ -76857,7 +83888,7 @@ wuffs_xz__decoder__decode_block_header_sans_padding(
uint8_t t_10 = *iop_a_src++;
v_c8 = t_10;
}
v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001793u, (2u | (((uint64_t)(v_c8)) << 8u)));
v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294273u, (2u | (((uint64_t)(v_c8)) << 8u)));
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = wuffs_base__make_status(wuffs_xz__error__bad_filter);
goto exit;
@@ -77922,6 +84953,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
case WUFFS_BASE__FOURCC__ETC2:
return wuffs_etc2__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
case WUFFS_BASE__FOURCC__GIF:
return wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
@@ -77951,9 +84987,19 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
}
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
case WUFFS_BASE__FOURCC__QOI:
return wuffs_qoi__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
case WUFFS_BASE__FOURCC__TGA:
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
return wuffs_targa__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
case WUFFS_BASE__FOURCC__TH:
return wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
@@ -77995,7 +85041,7 @@ DecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config,
return AllocPixbufResult(DecodeImage_UnsupportedPixelConfiguration);
}
void* ptr =
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
if (!ptr) {
return AllocPixbufResult(DecodeImage_OutOfMemory);
}
@@ -78020,7 +85066,7 @@ DecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range,
return AllocWorkbufResult(DecodeImage_OutOfMemory);
}
void* ptr =
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
if (!ptr) {
return AllocWorkbufResult(DecodeImage_OutOfMemory);
}
@@ -78320,6 +85366,7 @@ redirect:
wuffs_base__pixel_format pixel_format = callbacks.SelectPixfmt(image_config);
if (pixel_format.repr != image_config.pixcfg.pixel_format().repr) {
switch (pixel_format.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
case WUFFS_BASE__PIXEL_FORMAT__BGR:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
@@ -79073,6 +86120,537 @@ done:
#endif // defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
// ---------------- Wuffs' reimplementation of the STB API.
//
// This is a drop-in replacement of that third-party library.
//
// Disabled by default, unless you #define the
// WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB macro beforehand.
//
// For API docs, see https://github.com/nothings/stb
#if defined(WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
#include <limits.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
// --------
#if defined(__GNUC__)
__thread const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#elif defined(_MSC_VER)
__declspec(thread) const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#else
const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#endif
// --------
static void //
wuffs_drop_in__stb__read( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user) {
uint8_t* ptr = wuffs_base__io_buffer__writer_pointer(srcbuf);
size_t len = wuffs_base__io_buffer__writer_length(srcbuf);
if (len > INT_MAX) {
len = INT_MAX;
}
int n = clbk->read(user, (char*)ptr, (int)len);
if (n > 0) {
srcbuf->meta.wi += (size_t)n;
} else {
srcbuf->meta.closed = clbk->eof(user);
}
}
static wuffs_base__image_decoder* //
wuffs_drop_in__stb__make_decoder( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user) {
while (1) {
int32_t fourcc = wuffs_base__magic_number_guess_fourcc(
wuffs_base__io_buffer__reader_slice(srcbuf), srcbuf->meta.closed);
if (fourcc < 0) {
if (srcbuf->meta.closed || !clbk) {
break;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
continue;
}
switch (fourcc) {
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
case WUFFS_BASE__FOURCC__BMP:
return wuffs_bmp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
case WUFFS_BASE__FOURCC__ETC2:
return wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
case WUFFS_BASE__FOURCC__GIF:
return wuffs_gif__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG)
case WUFFS_BASE__FOURCC__JPEG:
return wuffs_jpeg__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE)
case WUFFS_BASE__FOURCC__NIE:
return wuffs_nie__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NETPBM)
case WUFFS_BASE__FOURCC__NPBM:
return wuffs_netpbm__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
case WUFFS_BASE__FOURCC__PNG:
return wuffs_png__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
case WUFFS_BASE__FOURCC__QOI:
return wuffs_qoi__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
case WUFFS_BASE__FOURCC__TGA:
return wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
case WUFFS_BASE__FOURCC__TH:
return wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
case WUFFS_BASE__FOURCC__WBMP:
return wuffs_wbmp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WEBP)
case WUFFS_BASE__FOURCC__WEBP:
return wuffs_webp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
}
wuffs_drop_in__stb__g_failure_reason = "unknown image type";
break;
}
return NULL;
}
// --------
static void* //
wuffs_drop_in__stb__load1( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user, //
wuffs_base__image_decoder* dec, //
wuffs_base__image_config* ic, //
uint32_t dst_pixfmt, //
int desired_channels, //
int info_only) {
// Favor faster decodes over rejecting invalid checksums.
wuffs_base__image_decoder__set_quirk(dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
1);
while (1) {
wuffs_base__status status =
wuffs_base__image_decoder__decode_image_config(dec, ic, srcbuf);
if (status.repr == NULL) {
break;
} else if ((status.repr != wuffs_base__suspension__short_read) || !clbk) {
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
size_t wl = wuffs_base__io_buffer__writer_length(srcbuf);
wuffs_base__io_buffer__compact(srcbuf);
if (wl >= wuffs_base__io_buffer__writer_length(srcbuf)) {
wuffs_drop_in__stb__g_failure_reason = "I/O buffer is too small";
return NULL;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
}
uint32_t w = wuffs_base__pixel_config__width(&ic->pixcfg);
uint32_t h = wuffs_base__pixel_config__height(&ic->pixcfg);
if ((w > 0xFFFFFF) || (h > 0xFFFFFF)) {
wuffs_drop_in__stb__g_failure_reason = "image is too large";
return NULL;
} else if (info_only) {
return NULL;
}
uint64_t pixbuf_len = (uint64_t)w * (uint64_t)h * (uint64_t)desired_channels;
uint64_t workbuf_len = wuffs_base__image_decoder__workbuf_len(dec).max_incl;
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
if ((pixbuf_len > ((uint64_t)SIZE_MAX)) ||
(workbuf_len > ((uint64_t)SIZE_MAX))) {
wuffs_drop_in__stb__g_failure_reason = "image is too large";
return NULL;
}
#endif
void* pixbuf_ptr = malloc((size_t)pixbuf_len);
if (!pixbuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
void* workbuf_ptr = malloc((size_t)workbuf_len);
if (!workbuf_ptr) {
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__slice_u8 workbuf =
wuffs_base__make_slice_u8(workbuf_ptr, (size_t)workbuf_len);
wuffs_base__pixel_config pc = ((wuffs_base__pixel_config){});
wuffs_base__pixel_config__set(&pc, dst_pixfmt,
WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, w, h);
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
{
wuffs_base__status status = wuffs_base__pixel_buffer__set_from_slice(
&pb, &pc, wuffs_base__make_slice_u8(pixbuf_ptr, (size_t)pixbuf_len));
if (status.repr) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
}
while (1) {
wuffs_base__status status = wuffs_base__image_decoder__decode_frame(
dec, &pb, srcbuf, WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL);
if (status.repr == NULL) {
break;
} else if ((status.repr != wuffs_base__suspension__short_read) || !clbk) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
size_t wl = wuffs_base__io_buffer__writer_length(srcbuf);
wuffs_base__io_buffer__compact(srcbuf);
if (wl >= wuffs_base__io_buffer__writer_length(srcbuf)) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = "I/O buffer is too small";
return NULL;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
}
free(workbuf_ptr);
return pixbuf_ptr;
}
static void* //
wuffs_drop_in__stb__load0( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels, //
int info_only) {
uint32_t dst_pixfmt = 0;
switch (desired_channels) {
case 1:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__Y;
break;
case 3:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGB;
break;
case 4:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL;
break;
default:
wuffs_drop_in__stb__g_failure_reason = "unsupported format conversion";
return NULL;
}
wuffs_base__image_decoder* dec =
wuffs_drop_in__stb__make_decoder(srcbuf, clbk, user);
if (!dec) {
if (wuffs_drop_in__stb__g_failure_reason == NULL) {
wuffs_drop_in__stb__g_failure_reason = "couldn't allocate image decoder";
}
return NULL;
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
stbi_uc* ret = wuffs_drop_in__stb__load1(
srcbuf, clbk, user, dec, &ic, dst_pixfmt, desired_channels, info_only);
free(dec);
if (!info_only && !ret) {
return NULL;
}
if (x) {
*x = (int)wuffs_base__pixel_config__width(&ic.pixcfg);
}
if (y) {
*y = (int)wuffs_base__pixel_config__height(&ic.pixcfg);
}
if (channels_in_file) {
wuffs_base__pixel_format src_pixfmt =
wuffs_base__pixel_config__pixel_format(&ic.pixcfg);
uint32_t n_color = wuffs_base__pixel_format__coloration(&src_pixfmt);
uint32_t n_alpha = wuffs_base__pixel_format__transparency(&src_pixfmt) !=
WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE;
*channels_in_file = (int)(n_color + n_alpha);
}
return ret;
}
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
if (len < 0) {
wuffs_drop_in__stb__g_failure_reason = "negative buffer length";
return 0;
} else if (len == 0) {
wuffs_drop_in__stb__g_failure_reason = "empty buffer";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__reader((uint8_t*)(stbi_uc*)buffer, (size_t)len, true);
wuffs_drop_in__stb__load0(&srcbuf, NULL, NULL, x, y, comp, 1, 1);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
if (len < 0) {
wuffs_drop_in__stb__g_failure_reason = "negative buffer length";
return NULL;
} else if (len == 0) {
wuffs_drop_in__stb__g_failure_reason = "empty buffer";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__reader((uint8_t*)(stbi_uc*)buffer, (size_t)len, true);
return wuffs_drop_in__stb__load0(&srcbuf, NULL, NULL, x, y, channels_in_file,
desired_channels, 0);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
wuffs_drop_in__stb__load0(&srcbuf, clbk, user, x, y, comp, 1, 1);
free(iobuf_ptr);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_uc* ret = wuffs_drop_in__stb__load0(
&srcbuf, clbk, user, x, y, channels_in_file, desired_channels, 0);
free(iobuf_ptr);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC void //
stbi_image_free( //
void* retval_from_stbi_load) {
wuffs_drop_in__stb__g_failure_reason = NULL;
free(retval_from_stbi_load);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC const char* //
stbi_failure_reason(void) {
return wuffs_drop_in__stb__g_failure_reason
? wuffs_drop_in__stb__g_failure_reason
: "ok";
}
// --------
#if !defined(STBI_NO_STDIO)
#include <stdio.h>
// TODO: retry after EINTR?
static int //
wuffs_drop_in__stb__file_callbacks__read( //
void* user, //
char* data, //
int size) {
return (int)fread(data, 1u, (size_t)size, (FILE*)user);
}
static void //
wuffs_drop_in__stb__file_callbacks__skip( //
void* user, //
int n) {
fseek((FILE*)user, (long)n, SEEK_CUR);
}
static int //
wuffs_drop_in__stb__file_callbacks__eof( //
void* user) {
return feof((FILE*)user);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info( //
char const* filename, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
FILE* f = fopen(filename, "rb");
if (!f) {
wuffs_drop_in__stb__g_failure_reason = "could not open file";
return 0;
}
int ret = stbi_info_from_file(f, x, y, comp);
fclose(f);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load( //
char const* filename, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
FILE* f = fopen(filename, "rb");
if (!f) {
wuffs_drop_in__stb__g_failure_reason = "could not open file";
return NULL;
}
stbi_uc* ret =
stbi_load_from_file(f, x, y, channels_in_file, desired_channels);
fclose(f);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_file( //
FILE* f, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_io_callbacks clbk;
clbk.read = &wuffs_drop_in__stb__file_callbacks__read;
clbk.skip = &wuffs_drop_in__stb__file_callbacks__skip;
clbk.eof = &wuffs_drop_in__stb__file_callbacks__eof;
wuffs_drop_in__stb__load0(&srcbuf, &clbk, f, x, y, comp, 1, 1);
free(iobuf_ptr);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_file( //
FILE* f, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_io_callbacks clbk;
clbk.read = &wuffs_drop_in__stb__file_callbacks__read;
clbk.skip = &wuffs_drop_in__stb__file_callbacks__skip;
clbk.eof = &wuffs_drop_in__stb__file_callbacks__eof;
stbi_uc* ret = wuffs_drop_in__stb__load0(
&srcbuf, &clbk, f, x, y, channels_in_file, desired_channels, 0);
free(iobuf_ptr);
return ret;
}
#endif // !defined(STBI_NO_STDIO)
// --------
#ifdef __cplusplus
} // extern "C"
#endif
#endif // defined (WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
#endif // WUFFS_IMPLEMENTATION
#if defined(__GNUC__)
+7898 -320
View File
@@ -81,15 +81,15 @@ extern "C" {
// each major.minor branch, the commit count should increase monotonically.
//
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
// ffb64df0a0b127e20d5eb0e1aab40c29409c0c3e committed on 2024-08-04.
// a14745aa458fd2b2785034efa04eab3c7b5b91e0 committed on 2024-09-14.
#define WUFFS_VERSION 0x000040000
#define WUFFS_VERSION_MAJOR 0
#define WUFFS_VERSION_MINOR 4
#define WUFFS_VERSION_PATCH 0
#define WUFFS_VERSION_PRE_RELEASE_LABEL "alpha.6"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3789
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20240804
#define WUFFS_VERSION_STRING "0.4.0-alpha.6+3789.20240804"
#define WUFFS_VERSION_PRE_RELEASE_LABEL "alpha.9"
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3837
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20240914
#define WUFFS_VERSION_STRING "0.4.0-alpha.9+3837.20240914"
// ---------------- Private Implementation Macros Re-definition Check
@@ -119,6 +119,20 @@ extern "C" {
#endif
// ---------------- Obsolete Macros Check
// std/tga was renamed to std/targa in September 2024 (Wuffs v0.4 alpha).
#if defined(WUFFS_CONFIG__MODULE__TGA)
#if defined(__GNUC__) || defined(__clang__)
#warning "WUFFS_CONFIG__MODULE__TGA was renamed to WUFFS_CONFIG__MODULE__TARGA"
#elif defined(_MSC_VER)
#pragma message( \
"WUFFS_CONFIG__MODULE__TGA was renamed to WUFFS_CONFIG__MODULE__TARGA")
#endif
#endif
// ---------------- Configuration
// Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU
@@ -755,6 +769,12 @@ typedef struct wuffs_base__transform__output__struct {
// Wuffs' u32 values are big-endian ("JPEG" is 0x4A504547 not 0x4745504A) to
// preserve ordering: "JPEG" < "MP3 " and 0x4A504547 < 0x4D503320.
// Android Binary XML (for resources; see AndroidBinXmlParser.java).
#define WUFFS_BASE__FOURCC__ABXR 0x41425852
// Android Binary XML (for system_server; see BinaryXmlSerializer.java).
#define WUFFS_BASE__FOURCC__ABXS 0x41425853
// Background Color.
#define WUFFS_BASE__FOURCC__BGCL 0x4247434C
@@ -779,6 +799,9 @@ typedef struct wuffs_base__transform__output__struct {
// Encapsulated PostScript.
#define WUFFS_BASE__FOURCC__EPS 0x45505320
// Ericsson Texture Compression 2 (iPACKMAN).
#define WUFFS_BASE__FOURCC__ETC2 0x45544332
// Exchangeable Image File Format.
#define WUFFS_BASE__FOURCC__EXIF 0x45584946
@@ -908,6 +931,9 @@ typedef struct wuffs_base__transform__output__struct {
// Truevision Advanced Raster Graphics Adapter.
#define WUFFS_BASE__FOURCC__TGA 0x54474120
// Thumbhash.
#define WUFFS_BASE__FOURCC__TH 0x54482020
// Tagged Image File Format.
#define WUFFS_BASE__FOURCC__TIFF 0x54494646
@@ -4213,6 +4239,46 @@ wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul(
return (a16 << 48) | (r16 << 32) | (g16 << 16) | (b16 << 0);
}
static inline uint8_t //
wuffs_base__color_u64_argb_premul__as__color_u8_gray(uint64_t argb_premul) {
uint32_t r16 = ((uint32_t)(0xFFFF & (argb_premul >> 32)));
uint32_t g16 = ((uint32_t)(0xFFFF & (argb_premul >> 16)));
uint32_t b16 = ((uint32_t)(0xFFFF & (argb_premul >> 0)));
// These coefficients (the fractions 0.299, 0.587 and 0.114) are the same
// as those given by the JFIF specification.
//
// Note that 19595 + 38470 + 7471 equals 65536, also known as (1 << 16). We
// shift by 24, not just by 16, because the return value is 8-bit color, not
// 16-bit color.
uint32_t weighted_average =
(19595 * r16) + (38470 * g16) + (7471 * b16) + 32768;
return (uint8_t)(weighted_average >> 24);
}
static inline uint8_t //
wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray(
uint64_t argb_nonpremul) {
uint32_t a16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 48)));
uint32_t r16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 32)));
r16 = (r16 * a16) / 0xFFFF;
uint32_t g16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 16)));
g16 = (g16 * a16) / 0xFFFF;
uint32_t b16 = ((uint32_t)(0xFFFF & (argb_nonpremul >> 0)));
b16 = (b16 * a16) / 0xFFFF;
// These coefficients (the fractions 0.299, 0.587 and 0.114) are the same
// as those given by the JFIF specification.
//
// Note that 19595 + 38470 + 7471 equals 65536, also known as (1 << 16). We
// shift by 24, not just by 16, because the return value is 8-bit color, not
// 16-bit color.
uint32_t weighted_average =
(19595 * r16) + (38470 * g16) + (7471 * b16) + 32768;
return (uint8_t)(weighted_average >> 24);
}
static inline uint64_t //
wuffs_base__color_u32__as__color_u64(uint32_t c) {
uint64_t a16 = 0x101 * (0xFF & (c >> 24));
@@ -4335,6 +4401,20 @@ typedef uint32_t wuffs_base__pixel_alpha_transparency;
// --------
// wuffs_base__pixel_coloration is whether a pixel format's color model has no
// color (alpha only), gray color or rich (non-gray) color. Rich color includes
// RGB, BGR, YCC, YCCK, CMY and CMYK.
//
// Coloration does not capture the alpha aspect of the color model. It does not
// distinguish RGB from RGBA.
typedef uint32_t wuffs_base__pixel_coloration;
#define WUFFS_BASE__PIXEL_COLORATION__NONE 0
#define WUFFS_BASE__PIXEL_COLORATION__GRAY 1
#define WUFFS_BASE__PIXEL_COLORATION__RICH 3
// --------
// Deprecated: use WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX_INCL.
#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4
@@ -4363,6 +4443,7 @@ typedef struct wuffs_base__pixel_format__struct {
inline bool is_indexed() const;
inline bool is_interleaved() const;
inline bool is_planar() const;
inline uint32_t coloration() const;
inline uint32_t num_planes() const;
inline wuffs_base__pixel_alpha_transparency transparency() const;
#endif // __cplusplus
@@ -4469,6 +4550,12 @@ wuffs_base__pixel_format__is_planar(const wuffs_base__pixel_format* f) {
return ((f->repr >> 16) & 0x03) != 0;
}
static inline uint32_t //
wuffs_base__pixel_format__coloration(const wuffs_base__pixel_format* f) {
uint32_t n = (f->repr) >> 29;
return (n <= 1) ? n : 3;
}
static inline uint32_t //
wuffs_base__pixel_format__num_planes(const wuffs_base__pixel_format* f) {
return ((f->repr >> 16) & 0x03) + 1;
@@ -4511,6 +4598,11 @@ wuffs_base__pixel_format::is_planar() const {
return wuffs_base__pixel_format__is_planar(this);
}
inline uint32_t //
wuffs_base__pixel_format::coloration() const {
return wuffs_base__pixel_format__coloration(this);
}
inline uint32_t //
wuffs_base__pixel_format::num_planes() const {
return wuffs_base__pixel_format__num_planes(this);
@@ -4665,7 +4757,7 @@ wuffs_base__pixel_config__set(wuffs_base__pixel_config* c,
}
if (pixfmt_repr) {
do {
#if SIZE_MAX < UINT64_MAX
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
uint64_t wh = ((uint64_t)width) * ((uint64_t)height);
// TODO: handle things other than 1 byte per pixel.
if (wh > ((uint64_t)SIZE_MAX)) {
@@ -7963,7 +8055,7 @@ extern const char wuffs_cbor__error__unsupported_recursion_depth[];
#define WUFFS_CBOR__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 9u
#define WUFFS_CBOR__TOKEN_VALUE_MAJOR 787997u
#define WUFFS_CBOR__TOKEN_VALUE_MAJOR 731642u
#define WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK 262143u
@@ -8936,6 +9028,372 @@ struct wuffs_deflate__decoder__struct {
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_etc2__error__bad_header[];
extern const char wuffs_etc2__error__truncated_input[];
extern const char wuffs_etc2__error__unsupported_etc2_file[];
// ---------------- Public Consts
#define WUFFS_ETC2__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_etc2__decoder__struct wuffs_etc2__decoder;
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_etc2__decoder__initialize(
wuffs_etc2__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_etc2__decoder(void);
// ---------------- Allocs
// These functions allocate and initialize Wuffs structs. They return NULL if
// memory allocation fails. If they return non-NULL, there is no need to call
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_etc2__decoder*
wuffs_etc2__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_etc2__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_etc2__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_etc2__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
// ---------------- Public Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__get_quirk(
const wuffs_etc2__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__set_quirk(
wuffs_etc2__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_image_config(
wuffs_etc2__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_frame_config(
wuffs_etc2__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_frame(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_etc2__decoder__frame_dirty_rect(
const wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_etc2__decoder__num_animation_loops(
const wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__num_decoded_frame_configs(
const wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__num_decoded_frames(
const wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__restart_frame(
wuffs_etc2__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_etc2__decoder__set_report_metadata(
wuffs_etc2__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__tell_me_more(
wuffs_etc2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_etc2__decoder__workbuf_len(
const wuffs_etc2__decoder* self);
#ifdef __cplusplus
} // extern "C"
#endif
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
// details that aren't guaranteed to be stable across Wuffs versions.
//
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_etc2__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
//
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
struct {
uint32_t magic;
uint32_t active_coroutine;
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
wuffs_base__vtable null_vtable;
uint32_t f_pixfmt;
uint32_t f_width;
uint32_t f_height;
uint8_t f_call_sequence;
bool f_srgb;
uint32_t f_num_buffered_blocks;
uint32_t f_dst_x;
uint32_t f_dst_y;
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config;
uint32_t p_do_decode_image_config;
uint32_t p_decode_frame_config;
uint32_t p_do_decode_frame_config;
uint32_t p_decode_frame;
uint32_t p_do_decode_frame;
uint32_t p_from_src_to_colors;
} private_impl;
struct {
uint64_t f_alphas[64];
uint64_t f_colors[64];
uint8_t f_buffer[4096];
struct {
uint16_t v_rounded_up_width;
uint16_t v_rounded_up_height;
uint64_t scratch;
} s_do_decode_image_config;
struct {
uint32_t v_remaining;
} s_do_decode_frame;
struct {
uint32_t v_bi;
uint64_t scratch;
} s_from_src_to_colors;
} private_data;
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_etc2__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_etc2__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
// Disallow constructing or copying an object via standard C++ mechanisms,
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
// size and field layout is not part of the public, stable, memory-safe API.
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
// their first argument) rather than tweaking bar.private_impl.qux fields.
//
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_etc2__decoder__struct() = delete;
wuffs_etc2__decoder__struct(const wuffs_etc2__decoder__struct&) = delete;
wuffs_etc2__decoder__struct& operator=(
const wuffs_etc2__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
// As above, the size of the struct is not part of the public API, and unless
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
// allocated, not stack allocated. Its size is not intended to be known at
// compile time, but it is unfortunately divulged as a side effect of
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
// instead of "sizeof T", invoking the operator. To make the two values
// different, so that passing the latter will be rejected by the initialize
// function, we add an arbitrary amount of dead weight.
uint8_t dead_weight[123000000]; // 123 MB.
#endif // !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
initialize(
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_etc2__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
inline wuffs_base__image_decoder*
upcast_as__wuffs_base__image_decoder() {
return (wuffs_base__image_decoder*)this;
}
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_etc2__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_etc2__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_etc2__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_etc2__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_etc2__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_etc2__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_etc2__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_etc2__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_etc2__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_etc2__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_etc2__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
tell_me_more(
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_etc2__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_etc2__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_etc2__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
@@ -8953,19 +9411,19 @@ extern const char wuffs_gif__error__truncated_input[];
#define WUFFS_GIF__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
#define WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES 1041635328u
#define WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES 983928832u
#define WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND 1041635329u
#define WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND 983928833u
#define WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR 1041635330u
#define WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR 983928834u
#define WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA 1041635331u
#define WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA 983928835u
#define WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT 1041635332u
#define WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT 983928836u
#define WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME 1041635333u
#define WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME 983928837u
#define WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE 1041635334u
#define WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE 983928838u
// ---------------- Struct Declarations
@@ -9665,6 +10123,8 @@ extern const char wuffs_jpeg__error__bad_marker[];
extern const char wuffs_jpeg__error__bad_scan_count[];
extern const char wuffs_jpeg__error__missing_huffman_table[];
extern const char wuffs_jpeg__error__missing_quantization_table[];
extern const char wuffs_jpeg__error__rejected_progressive_jpeg[];
extern const char wuffs_jpeg__error__short_sos_bitstream[];
extern const char wuffs_jpeg__error__truncated_input[];
extern const char wuffs_jpeg__error__unsupported_arithmetic_coding[];
extern const char wuffs_jpeg__error__unsupported_color_model[];
@@ -9682,6 +10142,8 @@ extern const char wuffs_jpeg__error__unsupported_scan_count[];
#define WUFFS_JPEG__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 51552191232u
#define WUFFS_JPEG__QUIRK_REJECT_PROGRESSIVE_JPEGS 1162824704u
// ---------------- Struct Declarations
typedef struct wuffs_jpeg__decoder__struct wuffs_jpeg__decoder;
@@ -9909,6 +10371,7 @@ struct wuffs_jpeg__decoder__struct {
bool f_bitstream_is_closed;
bool f_expect_multiple_scans;
bool f_use_lower_quality;
bool f_reject_progressive_jpegs;
bool f_swizzle_immediately;
wuffs_base__status f_swizzle_immediately_status;
uint32_t f_swizzle_immediately_b_offsets[10];
@@ -10177,45 +10640,45 @@ extern const char wuffs_json__error__unsupported_recursion_depth[];
#define WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL 100u
#define WUFFS_JSON__QUIRK_ALLOW_ASCII_CONTROL_CODES 1225364480u
#define WUFFS_JSON__QUIRK_ALLOW_ASCII_CONTROL_CODES 1167656960u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A 1225364481u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A 1167656961u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U 1225364482u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U 1167656962u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_E 1225364483u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_E 1167656963u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_NEW_LINE 1225364484u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_NEW_LINE 1167656964u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_QUESTION_MARK 1225364485u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_QUESTION_MARK 1167656965u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE 1225364486u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE 1167656966u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_V 1225364487u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_V 1167656967u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS 1225364489u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS 1167656969u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_ZERO 1225364490u
#define WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_ZERO 1167656970u
#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK 1225364491u
#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK 1167656971u
#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE 1225364492u
#define WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE 1167656972u
#define WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA 1225364493u
#define WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA 1167656973u
#define WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS 1225364494u
#define WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS 1167656974u
#define WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR 1225364495u
#define WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR 1167656975u
#define WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK 1225364496u
#define WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK 1167656976u
#define WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER 1225364497u
#define WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER 1167656977u
#define WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF 1225364498u
#define WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF 1167656978u
#define WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T 1225364499u
#define WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T 1167656979u
#define WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE 1225364500u
#define WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE 1167656980u
// ---------------- Struct Declarations
@@ -10461,9 +10924,9 @@ extern const char wuffs_lzma__error__unsupported_properties[];
#define WUFFS_LZMA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 4294967568u
#define WUFFS_LZMA__QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE 1348001792u
#define WUFFS_LZMA__QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE 1290294272u
#define WUFFS_LZMA__QUIRK_FORMAT_EXTENSION 1348001793u
#define WUFFS_LZMA__QUIRK_FORMAT_EXTENSION 1290294273u
// ---------------- Struct Declarations
@@ -11022,7 +11485,7 @@ extern const char wuffs_lzw__error__truncated_input[];
#define WUFFS_LZW__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
#define WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE 1348378624u
#define WUFFS_LZW__QUIRK_LITERAL_WIDTH_PLUS_ONE 1290672128u
// ---------------- Struct Declarations
@@ -11978,7 +12441,7 @@ extern const char wuffs_zlib__error__truncated_input[];
// ---------------- Public Consts
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976u
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2056083456u
#define WUFFS_ZLIB__DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE 0u
@@ -12743,6 +13206,371 @@ struct wuffs_png__decoder__struct {
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_qoi__error__bad_footer[];
extern const char wuffs_qoi__error__bad_header[];
extern const char wuffs_qoi__error__truncated_input[];
// ---------------- Public Consts
#define WUFFS_QOI__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_qoi__decoder__struct wuffs_qoi__decoder;
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_qoi__decoder__initialize(
wuffs_qoi__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_qoi__decoder(void);
// ---------------- Allocs
// These functions allocate and initialize Wuffs structs. They return NULL if
// memory allocation fails. If they return non-NULL, there is no need to call
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_qoi__decoder*
wuffs_qoi__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_qoi__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_qoi__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_qoi__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_qoi__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
// ---------------- Public Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__get_quirk(
const wuffs_qoi__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__set_quirk(
wuffs_qoi__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_image_config(
wuffs_qoi__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_frame_config(
wuffs_qoi__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_frame(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_qoi__decoder__frame_dirty_rect(
const wuffs_qoi__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_qoi__decoder__num_animation_loops(
const wuffs_qoi__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__num_decoded_frame_configs(
const wuffs_qoi__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__num_decoded_frames(
const wuffs_qoi__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__restart_frame(
wuffs_qoi__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_qoi__decoder__set_report_metadata(
wuffs_qoi__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__tell_me_more(
wuffs_qoi__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_qoi__decoder__workbuf_len(
const wuffs_qoi__decoder* self);
#ifdef __cplusplus
} // extern "C"
#endif
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
// details that aren't guaranteed to be stable across Wuffs versions.
//
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_qoi__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
//
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
struct {
uint32_t magic;
uint32_t active_coroutine;
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
wuffs_base__vtable null_vtable;
uint32_t f_pixfmt;
uint32_t f_width;
uint32_t f_height;
uint64_t f_remaining_pixels_times_4;
uint8_t f_call_sequence;
uint32_t f_buffer_index;
uint32_t f_dst_x;
uint32_t f_dst_y;
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config;
uint32_t p_do_decode_image_config;
uint32_t p_decode_frame_config;
uint32_t p_do_decode_frame_config;
uint32_t p_decode_frame;
uint32_t p_do_decode_frame;
uint32_t p_from_src_to_buffer;
} private_impl;
struct {
uint8_t f_pixel[4];
uint8_t f_cache[256];
uint8_t f_buffer[8196];
struct {
uint64_t scratch;
} s_do_decode_image_config;
struct {
uint64_t scratch;
} s_do_decode_frame;
struct {
uint8_t v_dg;
uint32_t v_bi;
uint32_t v_bk;
} s_from_src_to_buffer;
} private_data;
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_qoi__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_qoi__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_qoi__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
// Disallow constructing or copying an object via standard C++ mechanisms,
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
// size and field layout is not part of the public, stable, memory-safe API.
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
// their first argument) rather than tweaking bar.private_impl.qux fields.
//
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_qoi__decoder__struct() = delete;
wuffs_qoi__decoder__struct(const wuffs_qoi__decoder__struct&) = delete;
wuffs_qoi__decoder__struct& operator=(
const wuffs_qoi__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
// As above, the size of the struct is not part of the public API, and unless
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
// allocated, not stack allocated. Its size is not intended to be known at
// compile time, but it is unfortunately divulged as a side effect of
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
// instead of "sizeof T", invoking the operator. To make the two values
// different, so that passing the latter will be rejected by the initialize
// function, we add an arbitrary amount of dead weight.
uint8_t dead_weight[123000000]; // 123 MB.
#endif // !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
initialize(
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_qoi__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
inline wuffs_base__image_decoder*
upcast_as__wuffs_base__image_decoder() {
return (wuffs_base__image_decoder*)this;
}
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_qoi__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_qoi__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_qoi__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_qoi__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_qoi__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_qoi__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_qoi__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_qoi__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_qoi__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_qoi__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_qoi__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
tell_me_more(
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_qoi__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_qoi__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_qoi__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
@@ -12974,22 +13802,22 @@ struct wuffs_sha256__hasher__struct {
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_tga__error__bad_header[];
extern const char wuffs_tga__error__bad_run_length_encoding[];
extern const char wuffs_tga__error__truncated_input[];
extern const char wuffs_tga__error__unsupported_tga_file[];
extern const char wuffs_targa__error__bad_header[];
extern const char wuffs_targa__error__bad_run_length_encoding[];
extern const char wuffs_targa__error__truncated_input[];
extern const char wuffs_targa__error__unsupported_targa_file[];
// ---------------- Public Consts
#define WUFFS_TGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
#define WUFFS_TARGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_tga__decoder__struct wuffs_tga__decoder;
typedef struct wuffs_targa__decoder__struct wuffs_targa__decoder;
#ifdef __cplusplus
extern "C" {
@@ -13004,14 +13832,14 @@ extern "C" {
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_tga__decoder__initialize(
wuffs_tga__decoder* self,
wuffs_targa__decoder__initialize(
wuffs_targa__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_tga__decoder(void);
sizeof__wuffs_targa__decoder(void);
// ---------------- Allocs
@@ -13021,19 +13849,19 @@ sizeof__wuffs_tga__decoder(void);
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_tga__decoder*
wuffs_tga__decoder__alloc(void);
wuffs_targa__decoder*
wuffs_targa__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_tga__decoder__alloc());
wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_targa__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_tga__decoder* p) {
wuffs_targa__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_targa__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
@@ -13041,35 +13869,35 @@ wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__get_quirk(
const wuffs_tga__decoder* self,
wuffs_targa__decoder__get_quirk(
const wuffs_targa__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__set_quirk(
wuffs_tga__decoder* self,
wuffs_targa__decoder__set_quirk(
wuffs_targa__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_image_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_image_config(
wuffs_targa__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_frame_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_frame_config(
wuffs_targa__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_frame(
wuffs_targa__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
@@ -13078,50 +13906,50 @@ wuffs_tga__decoder__decode_frame(
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_tga__decoder__frame_dirty_rect(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__frame_dirty_rect(
const wuffs_targa__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_tga__decoder__num_animation_loops(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__num_animation_loops(
const wuffs_targa__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__num_decoded_frame_configs(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__num_decoded_frame_configs(
const wuffs_targa__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__num_decoded_frames(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__num_decoded_frames(
const wuffs_targa__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__restart_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__restart_frame(
wuffs_targa__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_tga__decoder__set_report_metadata(
wuffs_tga__decoder* self,
wuffs_targa__decoder__set_report_metadata(
wuffs_targa__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__tell_me_more(
wuffs_tga__decoder* self,
wuffs_targa__decoder__tell_me_more(
wuffs_targa__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_tga__decoder__workbuf_len(
const wuffs_tga__decoder* self);
wuffs_targa__decoder__workbuf_len(
const wuffs_targa__decoder* self);
#ifdef __cplusplus
} // extern "C"
@@ -13136,7 +13964,7 @@ wuffs_tga__decoder__workbuf_len(
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_tga__decoder__struct {
struct wuffs_targa__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
@@ -13200,19 +14028,19 @@ struct wuffs_tga__decoder__struct {
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_tga__decoder, wuffs_unique_ptr_deleter>;
using unique_ptr = std::unique_ptr<wuffs_targa__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_tga__decoder__alloc());
return unique_ptr(wuffs_targa__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder());
wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
@@ -13228,10 +14056,10 @@ struct wuffs_tga__decoder__struct {
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_tga__decoder__struct() = delete;
wuffs_tga__decoder__struct(const wuffs_tga__decoder__struct&) = delete;
wuffs_tga__decoder__struct& operator=(
const wuffs_tga__decoder__struct&) = delete;
wuffs_targa__decoder__struct() = delete;
wuffs_targa__decoder__struct(const wuffs_targa__decoder__struct&) = delete;
wuffs_targa__decoder__struct& operator=(
const wuffs_targa__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
@@ -13251,7 +14079,7 @@ struct wuffs_tga__decoder__struct {
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_tga__decoder__initialize(
return wuffs_targa__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
@@ -13263,28 +14091,28 @@ struct wuffs_tga__decoder__struct {
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_tga__decoder__get_quirk(this, a_key);
return wuffs_targa__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_tga__decoder__set_quirk(this, a_key, a_value);
return wuffs_targa__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_tga__decoder__decode_image_config(this, a_dst, a_src);
return wuffs_targa__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_tga__decoder__decode_frame_config(this, a_dst, a_src);
return wuffs_targa__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
@@ -13294,41 +14122,41 @@ struct wuffs_tga__decoder__struct {
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_tga__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
return wuffs_targa__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_tga__decoder__frame_dirty_rect(this);
return wuffs_targa__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_tga__decoder__num_animation_loops(this);
return wuffs_targa__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_tga__decoder__num_decoded_frame_configs(this);
return wuffs_targa__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_tga__decoder__num_decoded_frames(this);
return wuffs_targa__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_tga__decoder__restart_frame(this, a_index, a_io_position);
return wuffs_targa__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_tga__decoder__set_report_metadata(this, a_fourcc, a_report);
return wuffs_targa__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
@@ -13336,20 +14164,397 @@ struct wuffs_tga__decoder__struct {
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_tga__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
return wuffs_targa__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_tga__decoder__workbuf_len(this);
return wuffs_targa__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_tga__decoder__struct
}; // struct wuffs_targa__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA) || defined(WUFFS_NONMONOLITHIC)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH) || defined(WUFFS_NONMONOLITHIC)
// ---------------- Status Codes
extern const char wuffs_thumbhash__error__bad_header[];
extern const char wuffs_thumbhash__error__truncated_input[];
// ---------------- Public Consts
#define WUFFS_THUMBHASH__QUIRK_JUST_RAW_THUMBHASH 1712283648u
#define WUFFS_THUMBHASH__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0u
// ---------------- Struct Declarations
typedef struct wuffs_thumbhash__decoder__struct wuffs_thumbhash__decoder;
#ifdef __cplusplus
extern "C" {
#endif
// ---------------- Public Initializer Prototypes
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_thumbhash__decoder__initialize(
wuffs_thumbhash__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options);
size_t
sizeof__wuffs_thumbhash__decoder(void);
// ---------------- Allocs
// These functions allocate and initialize Wuffs structs. They return NULL if
// memory allocation fails. If they return non-NULL, there is no need to call
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
// calling free on the returned pointer. That pointer is effectively a C++
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
wuffs_thumbhash__decoder*
wuffs_thumbhash__decoder__alloc(void);
static inline wuffs_base__image_decoder*
wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder(void) {
return (wuffs_base__image_decoder*)(wuffs_thumbhash__decoder__alloc());
}
// ---------------- Upcasts
static inline wuffs_base__image_decoder*
wuffs_thumbhash__decoder__upcast_as__wuffs_base__image_decoder(
wuffs_thumbhash__decoder* p) {
return (wuffs_base__image_decoder*)p;
}
// ---------------- Public Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__get_quirk(
const wuffs_thumbhash__decoder* self,
uint32_t a_key);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__set_quirk(
wuffs_thumbhash__decoder* self,
uint32_t a_key,
uint64_t a_value);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_thumbhash__decoder__frame_dirty_rect(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_thumbhash__decoder__num_animation_loops(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frame_configs(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frames(
const wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__restart_frame(
wuffs_thumbhash__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_thumbhash__decoder__set_report_metadata(
wuffs_thumbhash__decoder* self,
uint32_t a_fourcc,
bool a_report);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__tell_me_more(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_thumbhash__decoder__workbuf_len(
const wuffs_thumbhash__decoder* self);
#ifdef __cplusplus
} // extern "C"
#endif
// ---------------- Struct Definitions
// These structs' fields, and the sizeof them, are private implementation
// details that aren't guaranteed to be stable across Wuffs versions.
//
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
struct wuffs_thumbhash__decoder__struct {
// Do not access the private_impl's or private_data's fields directly. There
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
// the wuffs_foo__bar__baz functions.
//
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
struct {
uint32_t magic;
uint32_t active_coroutine;
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
wuffs_base__vtable null_vtable;
uint32_t f_pixfmt;
uint8_t f_w_dimension_code;
uint8_t f_h_dimension_code;
uint8_t f_call_sequence;
uint8_t f_frame_config_io_position;
uint64_t f_l_dc;
uint64_t f_p_dc;
uint64_t f_q_dc;
uint64_t f_a_dc;
bool f_quirk_just_raw_thumbhash;
uint8_t f_l_scale;
uint8_t f_p_scale;
uint8_t f_q_scale;
uint8_t f_a_scale;
uint8_t f_has_alpha;
uint8_t f_l_count;
uint8_t f_is_landscape;
uint32_t f_lx;
uint32_t f_ly;
wuffs_base__pixel_swizzler f_swizzler;
uint32_t p_decode_image_config;
uint32_t p_do_decode_image_config;
uint32_t p_decode_frame_config;
uint32_t p_do_decode_frame_config;
uint32_t p_decode_frame;
uint32_t p_do_decode_frame;
uint32_t p_from_src_to_coeffs;
} private_impl;
struct {
uint32_t f_lac[32];
uint32_t f_pac[8];
uint32_t f_qac[8];
uint32_t f_aac[16];
uint8_t f_pixels[32][128];
struct {
uint64_t scratch;
} s_do_decode_image_config;
struct {
uint32_t v_cy;
uint32_t v_cx;
uint32_t v_i;
bool v_has_bits;
} s_from_src_to_coeffs;
} private_data;
#ifdef __cplusplus
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
using unique_ptr = std::unique_ptr<wuffs_thumbhash__decoder, wuffs_unique_ptr_deleter>;
// On failure, the alloc_etc functions return nullptr. They don't throw.
static inline unique_ptr
alloc() {
return unique_ptr(wuffs_thumbhash__decoder__alloc());
}
static inline wuffs_base__image_decoder::unique_ptr
alloc_as__wuffs_base__image_decoder() {
return wuffs_base__image_decoder::unique_ptr(
wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder());
}
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
// Disallow constructing or copying an object via standard C++ mechanisms,
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
// size and field layout is not part of the public, stable, memory-safe API.
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
// their first argument) rather than tweaking bar.private_impl.qux fields.
//
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
// order to provide convenience methods. These forward on "this", so that you
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
wuffs_thumbhash__decoder__struct() = delete;
wuffs_thumbhash__decoder__struct(const wuffs_thumbhash__decoder__struct&) = delete;
wuffs_thumbhash__decoder__struct& operator=(
const wuffs_thumbhash__decoder__struct&) = delete;
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
#if !defined(WUFFS_IMPLEMENTATION)
// As above, the size of the struct is not part of the public API, and unless
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
// allocated, not stack allocated. Its size is not intended to be known at
// compile time, but it is unfortunately divulged as a side effect of
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
// instead of "sizeof T", invoking the operator. To make the two values
// different, so that passing the latter will be rejected by the initialize
// function, we add an arbitrary amount of dead weight.
uint8_t dead_weight[123000000]; // 123 MB.
#endif // !defined(WUFFS_IMPLEMENTATION)
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
initialize(
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options) {
return wuffs_thumbhash__decoder__initialize(
this, sizeof_star_self, wuffs_version, options);
}
inline wuffs_base__image_decoder*
upcast_as__wuffs_base__image_decoder() {
return (wuffs_base__image_decoder*)this;
}
inline uint64_t
get_quirk(
uint32_t a_key) const {
return wuffs_thumbhash__decoder__get_quirk(this, a_key);
}
inline wuffs_base__status
set_quirk(
uint32_t a_key,
uint64_t a_value) {
return wuffs_thumbhash__decoder__set_quirk(this, a_key, a_value);
}
inline wuffs_base__status
decode_image_config(
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__decode_image_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame_config(
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__decode_frame_config(this, a_dst, a_src);
}
inline wuffs_base__status
decode_frame(
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
return wuffs_thumbhash__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
}
inline wuffs_base__rect_ie_u32
frame_dirty_rect() const {
return wuffs_thumbhash__decoder__frame_dirty_rect(this);
}
inline uint32_t
num_animation_loops() const {
return wuffs_thumbhash__decoder__num_animation_loops(this);
}
inline uint64_t
num_decoded_frame_configs() const {
return wuffs_thumbhash__decoder__num_decoded_frame_configs(this);
}
inline uint64_t
num_decoded_frames() const {
return wuffs_thumbhash__decoder__num_decoded_frames(this);
}
inline wuffs_base__status
restart_frame(
uint64_t a_index,
uint64_t a_io_position) {
return wuffs_thumbhash__decoder__restart_frame(this, a_index, a_io_position);
}
inline wuffs_base__empty_struct
set_report_metadata(
uint32_t a_fourcc,
bool a_report) {
return wuffs_thumbhash__decoder__set_report_metadata(this, a_fourcc, a_report);
}
inline wuffs_base__status
tell_me_more(
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
return wuffs_thumbhash__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
}
inline wuffs_base__range_ii_u64
workbuf_len() const {
return wuffs_thumbhash__decoder__workbuf_len(this);
}
#endif // __cplusplus
}; // struct wuffs_thumbhash__decoder__struct
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH) || defined(WUFFS_NONMONOLITHIC)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__VP8) || defined(WUFFS_NONMONOLITHIC)
@@ -14765,7 +15970,7 @@ extern const char wuffs_xz__error__unsupported_filter_combination[];
// ---------------- Public Consts
#define WUFFS_XZ__QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS 2021322752u
#define WUFFS_XZ__QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS 1963655168u
#define WUFFS_XZ__DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE 0u
@@ -15354,18 +16559,26 @@ class DecodeImageCallbacks {
//
// The default SelectDecoder accepts the FOURCC codes listed below. For
// modular builds (i.e. when #define'ing WUFFS_CONFIG__MODULES), acceptance
// of the ETC file format is optional (for each value of ETC) and depends on
// of the FOO file format is optional (for each value of FOO) and depends on
// the corresponding module to be enabled at compile time (i.e. #define'ing
// WUFFS_CONFIG__MODULE__ETC).
// WUFFS_CONFIG__MODULE__FOO).
//
// - WUFFS_BASE__FOURCC__BMP
// - WUFFS_BASE__FOURCC__ETC2
// - WUFFS_BASE__FOURCC__GIF
// - WUFFS_BASE__FOURCC__JPEG
// - WUFFS_BASE__FOURCC__NIE
// - WUFFS_BASE__FOURCC__NPBM
// - WUFFS_BASE__FOURCC__PNG
// - WUFFS_BASE__FOURCC__TGA
// - WUFFS_BASE__FOURCC__QOI
// - WUFFS_BASE__FOURCC__TARGA
// - WUFFS_BASE__FOURCC__TH
// - WUFFS_BASE__FOURCC__WBMP
// - WUFFS_BASE__FOURCC__WEBP
//
// The FOOBAR in WUFFS_BASE__FOURCC__FOBA is limited to four characters, but
// the FOOBAR in the corresponding WUFFS_CONFIG__MODULE__FOOBAR macro might
// be fuller and longer. For example, NPBM / NETPBM or TH / THUMBHASH.
virtual wuffs_base__image_decoder::unique_ptr //
SelectDecoder(uint32_t fourcc,
wuffs_base__slice_u8 prefix_data,
@@ -15374,8 +16587,8 @@ class DecodeImageCallbacks {
// 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.
// If it is METADATA_RAW_PASSTHROUGH 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 |
@@ -15389,6 +16602,7 @@ class DecodeImageCallbacks {
// 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__Y
// - WUFFS_BASE__PIXEL_FORMAT__BGR_565
// - WUFFS_BASE__PIXEL_FORMAT__BGR
// - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL
@@ -15491,7 +16705,7 @@ struct DecodeImageArgFlags {
// DefaultValue returns 0.
static DecodeImageArgFlags DefaultValue();
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
// TODO: support all of the REPORT_METADATA_FOO flags, not just CHRM, EXIF,
// GAMA, ICCP, KVP, SRGB and XMP.
// Background Color.
@@ -15738,6 +16952,131 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
#endif // defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
// ---------------- Wuffs' reimplementation of the STB API.
//
// This is a drop-in replacement of that third-party library.
//
// Disabled by default, unless you #define the
// WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB macro beforehand.
//
// For API docs, see https://github.com/nothings/stb
#if defined(WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
#ifdef __cplusplus
extern "C" {
#endif
#if defined(WUFFS_CONFIG__STATIC_FUNCTIONS) || defined(STB_IMAGE_STATIC)
#define WUFFS_DROP_IN__STB__MAYBE_STATIC static
#else
#define WUFFS_DROP_IN__STB__MAYBE_STATIC
#endif
enum {
STBI_default = 0,
STBI_grey = 1,
STBI_grey_alpha = 2,
STBI_rgb = 3,
STBI_rgb_alpha = 4
};
typedef unsigned char stbi_uc;
typedef unsigned short stbi_us;
typedef struct {
int (*read)(void* user, char* data, int size);
void (*skip)(void* user, int n);
int (*eof)(void* user);
} stbi_io_callbacks;
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
// --------
#if !defined(STBI_NO_STDIO)
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info( //
char const* filename, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load( //
char const* filename, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_file( //
FILE* f, //
int* x, //
int* y, //
int* comp);
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_file( //
FILE* f, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels);
#endif // !defined(STBI_NO_STDIO)
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC void //
stbi_image_free( //
void* retval_from_stbi_load);
WUFFS_DROP_IN__STB__MAYBE_STATIC const char* //
stbi_failure_reason(void);
#ifdef __cplusplus
}
#endif
#endif // defined (WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
// ‼ WUFFS C HEADER ENDS HERE.
#ifdef WUFFS_IMPLEMENTATION
@@ -15910,12 +17249,24 @@ wuffs_private_impl__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {
// ---------------- Numeric Types (Utility)
#define wuffs_base__utility__i64_divide(a, b) \
((uint64_t)(((int64_t)(a)) / ((int64_t)(b))))
#define wuffs_base__utility__sign_extend_convert_u8_u32(a) \
((uint32_t)(int32_t)(int8_t)(a))
#define wuffs_base__utility__sign_extend_convert_u8_u64(a) \
((uint64_t)(int64_t)(int8_t)(a))
#define wuffs_base__utility__sign_extend_convert_u16_u32(a) \
((uint32_t)(int32_t)(int16_t)(a))
#define wuffs_base__utility__sign_extend_convert_u16_u64(a) \
((uint64_t)(int64_t)(int16_t)(a))
#define wuffs_base__utility__sign_extend_convert_u32_u64(a) \
((uint64_t)(int64_t)(int32_t)(a))
#define wuffs_base__utility__sign_extend_rshift_u32(a, n) \
((uint32_t)(((int32_t)(a)) >> (n)))
@@ -21623,26 +22974,31 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
int32_t fourcc;
const char* magic;
} table[] = {
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm)
{+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA
{+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
{-0x30302020, "\x01\x00\x00"}, // '00 'be
{+0x41425852, "\x03\x03\x00\x08\x00"}, // ABXR
{+0x475A2020, "\x02\x1F\x8B\x08"}, // GZ
{+0x5A535444, "\x03\x28\xB5\x2F\xFD"}, // ZSTD
{+0x584D4C20, "\x05\x3C\x3F\x78\x6D\x6C\x20"}, // XML
{+0x41425853, "\x03\x41\x42\x58\x00"}, // ABXS
{+0x425A3220, "\x02\x42\x5A\x68"}, // BZ2
{+0x424D5020, "\x01\x42\x4D"}, // BMP
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
{+0x4C5A4950, "\x04\x4C\x5A\x49\x50\x01"}, // LZIP
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
{+0x45544332, "\x03\x50\x4B\x4D\x20"}, // ETC2 (*.pkm)
{+0x4E50424D, "\x02\x50\x35\x0A"}, // NPBM (P5; *.pgm)
{+0x4E50424D, "\x02\x50\x36\x0A"}, // NPBM (P6; *.ppm)
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
{+0x4C5A4D41, "\x04\x5D\x00\x10\x00\x00"}, // LZMA
{+0x4C5A4D41, "\x02\x5D\x00\x00"}, // LZMA
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
{+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
{+0x54482020, "\x02\xC3\xBE\xFE"}, // TH
{+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
};
static const size_t table_len = sizeof(table) / sizeof(table[0]);
@@ -21876,9 +23232,8 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
wuffs_base__peek_u32le__no_bounds_check(row + (4 * ((size_t)x)));
case WUFFS_BASE__PIXEL_FORMAT__RGB:
return wuffs_private_impl__swap_u32_argb_abgr(
0xFF000000 |
wuffs_base__peek_u24le__no_bounds_check(row + (3 * ((size_t)x))));
return 0xFF000000 |
wuffs_base__peek_u24be__no_bounds_check(row + (3 * ((size_t)x)));
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
return wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
@@ -21984,6 +23339,10 @@ wuffs_base__pixel_buffer__set_color_u32_at(
wuffs_base__color_u32_argb_premul__as__color_u64_argb_nonpremul(
color));
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
wuffs_base__poke_u32le__no_bounds_check(
row + (4 * ((size_t)x)), (color >> 31) ? (color | 0xFF000000) : 0);
break;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
wuffs_base__poke_u24le__no_bounds_check(
@@ -22589,6 +23948,34 @@ wuffs_private_impl__swizzle_squash_align4_bgr_565_8888(uint8_t* dst_ptr,
// --------
static uint64_t //
wuffs_private_impl__swizzle_squash_align4_y_8888(uint8_t* dst_ptr,
size_t dst_len,
const uint8_t* src_ptr,
size_t src_len,
bool nonpremul) {
size_t len = (dst_len < src_len ? dst_len : src_len) / 4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
while (n--) {
uint32_t argb = wuffs_base__peek_u32le__no_bounds_check(s);
if (nonpremul) {
argb =
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(argb);
}
uint32_t s0 = wuffs_base__color_u32_argb_premul__as__color_u8_gray(argb);
wuffs_base__poke_u32le__no_bounds_check(
d, (argb & 0xFF000000) | (s0 * 0x010101));
s += 4;
d += 4;
}
return len;
}
// --------
static uint64_t //
wuffs_private_impl__swizzle_swap_rgb_bgr(uint8_t* dst_ptr,
size_t dst_len,
@@ -26414,6 +27801,62 @@ wuffs_private_impl__swizzle_xxxxxxxx__y_16be(uint8_t* dst_ptr,
// --------
static uint64_t //
wuffs_private_impl__swizzle_y__bgr(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len3 = src_len / 3;
size_t len = (dst_len < src_len3) ? dst_len : src_len3;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u24le__no_bounds_check(s + (0 * 3));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 3;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgr_565(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(
wuffs_base__peek_u16le__no_bounds_check(s + (0 * 2)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
@@ -26427,6 +27870,8 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
@@ -26455,6 +27900,8 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over(
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
@@ -26469,6 +27916,154 @@ wuffs_private_impl__swizzle_y__bgra_nonpremul__src_over(
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len8 = src_len / 8;
size_t len = (dst_len < src_len8) ? dst_len : src_len8;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray(
wuffs_base__peek_u64le__no_bounds_check(s + (0 * 8)));
s += 1 * 8;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len8 = src_len / 8;
size_t len = (dst_len < src_len8) ? dst_len : src_len8;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[0]);
uint32_t dg = 0x101 * ((uint32_t)d[0]);
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));
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
// Composite src (nonpremul) over dst (premul).
dr = ((sr * sa) + (dr * ia)) / 0xFFFF;
dg = ((sg * sa) + (dg * ia)) / 0xFFFF;
db = ((sb * sa) + (db * ia)) / 0xFFFF;
// Convert to 16-bit color to 8-bit gray.
uint32_t weighted_average =
(19595 * dr) + (38470 * dg) + (7471 * db) + 32768;
d[0] = (uint8_t)(weighted_average >> 24);
s += 1 * 8;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_premul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgra_premul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
// Extract 16-bit color components.
uint32_t dr = 0x101 * ((uint32_t)d[0]);
uint32_t dg = 0x101 * ((uint32_t)d[0]);
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]);
// Calculate the inverse of the src-alpha: how much of the dst to keep.
uint32_t ia = 0xFFFF - sa;
// Composite src (premul) over dst (premul).
dr = sr + ((dr * ia) / 0xFFFF);
dg = sg + ((dg * ia) / 0xFFFF);
db = sb + ((db * ia) / 0xFFFF);
// Convert to 16-bit color to 8-bit gray.
uint32_t weighted_average =
(19595 * dr) + (38470 * dg) + (7471 * db) + 32768;
d[0] = (uint8_t)(weighted_average >> 24);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
size_t dst_len,
@@ -26482,6 +28077,8 @@ wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4));
@@ -26495,6 +28092,152 @@ wuffs_private_impl__swizzle_y__bgrx(uint8_t* dst_ptr,
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgb(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len3 = src_len / 3;
size_t len = (dst_len < src_len3) ? dst_len : src_len3;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 =
0xFF000000 | wuffs_base__peek_u24be__no_bounds_check(s + (0 * 3));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 3;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4))));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_nonpremul__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_premul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(s0);
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__rgba_premul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len4 = src_len / 4;
size_t len = (dst_len < src_len4) ? dst_len : src_len4;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_private_impl__swap_u32_argb_abgr(
wuffs_base__peek_u32le__no_bounds_check(s + (0 * 4)));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_premul_u32_axxx(d0, s0));
s += 1 * 4;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
size_t dst_len,
@@ -26508,6 +28251,8 @@ wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = s[0];
@@ -26519,6 +28264,162 @@ wuffs_private_impl__swizzle_y__y_16be(uint8_t* dst_ptr,
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__ya_nonpremul__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
d[0] = (uint8_t)
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__ya_nonpremul__src_over(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t src_len2 = src_len / 2;
size_t len = (dst_len < src_len2) ? dst_len : src_len2;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | ((uint32_t)(d[0]) * 0x010101);
uint32_t s0 = ((uint32_t)(s[1]) << 24) | ((uint32_t)(s[0]) * 0x010101);
d[0] = (uint8_t)wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0,
s0);
s += 1 * 2;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index__src(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
d[0] = dst_palette_ptr[(size_t)s[0] * 4];
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index_bgra_nonpremul__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t d0 = 0xFF000000 | (0x00010101 * ((uint32_t)(d[0])));
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr +
((size_t)s[0] * 4));
d[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(d0, s0));
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
static uint64_t //
wuffs_private_impl__swizzle_y__index_binary_alpha__src_over(
uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
if (dst_palette_len !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return 0;
}
size_t len = (dst_len < src_len) ? dst_len : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
uint32_t s0 = wuffs_base__peek_u32le__no_bounds_check(dst_palette_ptr +
((size_t)s[0] * 4));
if (s0) {
d[0] = (uint8_t)s0;
}
s += 1 * 1;
d += 1 * 1;
n -= 1;
}
return len;
}
// --------
static uint64_t //
wuffs_private_impl__swizzle_y_16le__y_16be(uint8_t* dst_ptr,
size_t dst_len,
@@ -26707,6 +28608,15 @@ wuffs_private_impl__pixel_swizzler__prepare__ya_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__ya_nonpremul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__ya_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -26776,6 +28686,26 @@ wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
if (wuffs_private_impl__swizzle_squash_align4_y_8888(
dst_palette.ptr, dst_palette.len, src_palette.ptr,
src_palette.len, true) !=
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
return NULL;
}
return wuffs_private_impl__swizzle_y__index__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
src_palette) !=
WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {
return NULL;
}
return wuffs_private_impl__swizzle_y__index_bgra_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
if (wuffs_private_impl__slice_u8__copy_from_slice(dst_palette,
src_palette) !=
@@ -26948,6 +28878,21 @@ wuffs_private_impl__pixel_swizzler__prepare__indexed__bgra_binary(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
if (wuffs_private_impl__swizzle_squash_align4_y_8888(
dst_palette.ptr, dst_palette.len, src_palette.ptr,
src_palette.len, false) !=
(WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {
return NULL;
}
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__index__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__index_binary_alpha__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
@@ -27065,6 +29010,9 @@ wuffs_private_impl__pixel_swizzler__prepare__bgr_565(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__bgr_565;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_copy_2_2;
@@ -27101,6 +29049,9 @@ wuffs_private_impl__pixel_swizzler__prepare__bgr(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__bgr;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_bgr_565__bgr;
@@ -27254,6 +29205,15 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_nonpremul_4x16le(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_nonpremul_4x16le__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -27347,6 +29307,15 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_premul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -27427,6 +29396,109 @@ wuffs_private_impl__pixel_swizzler__prepare__bgra_premul(
return NULL;
}
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
wuffs_private_impl__pixel_swizzler__prepare__bgra_binary(
wuffs_base__pixel_swizzler* p,
wuffs_base__pixel_format dst_pixfmt,
wuffs_base__slice_u8 dst_palette,
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr_565__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_copy_4_4;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul_4x16le__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_copy_4_4;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_premul__bgra_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGB:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_bgr__rgba_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgr__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_nonpremul__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
#if defined(WUFFS_PRIVATE_IMPL__CPU_ARCH__X86_64_V2)
if (wuffs_base__cpu_arch__have_x86_sse42()) {
return wuffs_private_impl__swizzle_swap_rgbx_bgrx__x86_sse42;
}
#endif
return wuffs_private_impl__swizzle_swap_rgbx_bgrx;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_bgra_premul__rgba_premul__src_over;
}
return NULL;
}
return NULL;
}
static inline WUFFS_BASE__FORCE_INLINE wuffs_base__pixel_swizzler__func //
wuffs_private_impl__pixel_swizzler__prepare__bgrx(
wuffs_base__pixel_swizzler* p,
@@ -27475,6 +29547,9 @@ wuffs_private_impl__pixel_swizzler__prepare__rgb(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
return wuffs_private_impl__swizzle_y__rgb;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
return wuffs_private_impl__swizzle_bgr_565__rgb;
@@ -27520,6 +29595,15 @@ wuffs_private_impl__pixel_swizzler__prepare__rgba_nonpremul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__rgba_nonpremul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__rgba_nonpremul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -27618,6 +29702,15 @@ wuffs_private_impl__pixel_swizzler__prepare__rgba_premul(
wuffs_base__slice_u8 src_palette,
wuffs_base__pixel_blend blend) {
switch (dst_pixfmt.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
return wuffs_private_impl__swizzle_y__rgba_premul__src;
case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:
return wuffs_private_impl__swizzle_y__rgba_premul__src_over;
}
return NULL;
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
switch (blend) {
case WUFFS_BASE__PIXEL_BLEND__SRC:
@@ -27719,6 +29812,10 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
switch (dst_pixfmt.repr) {
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y)
case WUFFS_BASE__PIXEL_FORMAT__Y:
break;
#endif
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565)
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
break;
@@ -27845,6 +29942,11 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
p, dst_pixfmt, dst_palette, src_palette, blend);
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
func = wuffs_private_impl__pixel_swizzler__prepare__bgra_binary(
p, dst_pixfmt, dst_palette, src_palette, blend);
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
func = wuffs_private_impl__pixel_swizzler__prepare__bgrx(
p, dst_pixfmt, dst_palette, src_palette, blend);
@@ -29299,6 +31401,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST)
switch (dst->pixcfg.private_impl.pixfmt.repr) {
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y)
case WUFFS_BASE__PIXEL_FORMAT__Y:
break;
#endif
#if defined(WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_BGR_565)
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
break;
@@ -30484,7 +32590,7 @@ wuffs_adler32__hasher__initialize(
wuffs_adler32__hasher*
wuffs_adler32__hasher__alloc(void) {
wuffs_adler32__hasher* x =
(wuffs_adler32__hasher*)(calloc(sizeof(wuffs_adler32__hasher), 1));
(wuffs_adler32__hasher*)(calloc(1, sizeof(wuffs_adler32__hasher)));
if (!x) {
return NULL;
}
@@ -31090,7 +33196,7 @@ wuffs_bmp__decoder__initialize(
wuffs_bmp__decoder*
wuffs_bmp__decoder__alloc(void) {
wuffs_bmp__decoder* x =
(wuffs_bmp__decoder*)(calloc(sizeof(wuffs_bmp__decoder), 1));
(wuffs_bmp__decoder*)(calloc(1, sizeof(wuffs_bmp__decoder)));
if (!x) {
return NULL;
}
@@ -33856,7 +35962,7 @@ wuffs_bzip2__decoder__initialize(
wuffs_bzip2__decoder*
wuffs_bzip2__decoder__alloc(void) {
wuffs_bzip2__decoder* x =
(wuffs_bzip2__decoder*)(calloc(sizeof(wuffs_bzip2__decoder), 1));
(wuffs_bzip2__decoder*)(calloc(1, sizeof(wuffs_bzip2__decoder)));
if (!x) {
return NULL;
}
@@ -35414,7 +37520,7 @@ wuffs_cbor__decoder__initialize(
wuffs_cbor__decoder*
wuffs_cbor__decoder__alloc(void) {
wuffs_cbor__decoder* x =
(wuffs_cbor__decoder*)(calloc(sizeof(wuffs_cbor__decoder), 1));
(wuffs_cbor__decoder*)(calloc(1, sizeof(wuffs_cbor__decoder)));
if (!x) {
return NULL;
}
@@ -35690,7 +37796,7 @@ wuffs_cbor__decoder__decode_tokens(
(((uint64_t)(((uint32_t)(WUFFS_CBOR__TOKEN_LENGTHS[v_c_minor])))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
} else {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(16777216u)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(9u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
}
@@ -35914,12 +38020,12 @@ wuffs_cbor__decoder__decode_tokens(
}
if (v_string_length < 262144u) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)((4194304u | ((uint32_t)(v_string_length))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(((uint32_t)(WUFFS_CBOR__TOKEN_LENGTHS[v_c_minor])))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
} else {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)((4194304u | ((uint32_t)((v_string_length >> 46u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(1u)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
(((uint64_t)(0u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
@@ -35932,7 +38038,7 @@ wuffs_cbor__decoder__decode_tokens(
} else if (v_c_major == 7u) {
if (v_c_minor < 20u) {
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)((8388608u | ((uint32_t)((v_string_length & 255u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(1u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
goto label__goto_parsed_a_leaf_value__break;
@@ -35951,7 +38057,7 @@ wuffs_cbor__decoder__decode_tokens(
break;
}
*iop_a_dst++ = wuffs_base__make_token(
(((uint64_t)(787997u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)(731642u)) << WUFFS_BASE__TOKEN__VALUE_MAJOR__SHIFT) |
(((uint64_t)((8388608u | ((uint32_t)((v_string_length & 255u)))))) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
(((uint64_t)(2u)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
goto label__goto_parsed_a_leaf_value__break;
@@ -36726,7 +38832,7 @@ wuffs_crc32__ieee_hasher__initialize(
wuffs_crc32__ieee_hasher*
wuffs_crc32__ieee_hasher__alloc(void) {
wuffs_crc32__ieee_hasher* x =
(wuffs_crc32__ieee_hasher*)(calloc(sizeof(wuffs_crc32__ieee_hasher), 1));
(wuffs_crc32__ieee_hasher*)(calloc(1, sizeof(wuffs_crc32__ieee_hasher)));
if (!x) {
return NULL;
}
@@ -37561,7 +39667,7 @@ wuffs_crc64__ecma_hasher__initialize(
wuffs_crc64__ecma_hasher*
wuffs_crc64__ecma_hasher__alloc(void) {
wuffs_crc64__ecma_hasher* x =
(wuffs_crc64__ecma_hasher*)(calloc(sizeof(wuffs_crc64__ecma_hasher), 1));
(wuffs_crc64__ecma_hasher*)(calloc(1, sizeof(wuffs_crc64__ecma_hasher)));
if (!x) {
return NULL;
}
@@ -38112,7 +40218,7 @@ wuffs_deflate__decoder__initialize(
wuffs_deflate__decoder*
wuffs_deflate__decoder__alloc(void) {
wuffs_deflate__decoder* x =
(wuffs_deflate__decoder*)(calloc(sizeof(wuffs_deflate__decoder), 1));
(wuffs_deflate__decoder*)(calloc(1, sizeof(wuffs_deflate__decoder)));
if (!x) {
return NULL;
}
@@ -40249,6 +42355,1908 @@ wuffs_deflate__decoder__decode_huffman_slow(
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
// ---------------- Status Codes Implementations
const char wuffs_etc2__error__bad_header[] = "#etc2: bad header";
const char wuffs_etc2__error__truncated_input[] = "#etc2: truncated input";
const char wuffs_etc2__error__unsupported_etc2_file[] = "#etc2: unsupported ETC2 file";
// ---------------- Private Consts
static const uint32_t
WUFFS_ETC2__DIFFS[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 1u, 2u, 3u, 4294967292u, 4294967293u, 4294967294u, 4294967295u,
};
static const uint32_t
WUFFS_ETC2__MODIFIERS[16][4] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
2u, 8u, 4294967294u, 4294967288u,
}, {
5u, 17u, 4294967291u, 4294967279u,
}, {
9u, 29u, 4294967287u, 4294967267u,
}, {
13u, 42u, 4294967283u, 4294967254u,
}, {
18u, 60u, 4294967278u, 4294967236u,
}, {
24u, 80u, 4294967272u, 4294967216u,
}, {
33u, 106u, 4294967263u, 4294967190u,
}, {
47u, 183u, 4294967249u, 4294967113u,
},
{
0u, 8u, 0u, 4294967288u,
}, {
0u, 17u, 0u, 4294967279u,
}, {
0u, 29u, 0u, 4294967267u,
}, {
0u, 42u, 0u, 4294967254u,
}, {
0u, 60u, 0u, 4294967236u,
}, {
0u, 80u, 0u, 4294967216u,
}, {
0u, 106u, 0u, 4294967190u,
}, {
0u, 183u, 0u, 4294967113u,
},
};
static const uint8_t
WUFFS_ETC2__T_H_MODIFIERS[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
3u, 6u, 11u, 16u, 23u, 32u, 41u, 64u,
};
static const uint32_t
WUFFS_ETC2__ALPHA_MODIFIERS[16][8] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
4294967293u, 4294967290u, 4294967287u, 4294967281u, 2u, 5u, 8u, 14u,
}, {
4294967293u, 4294967289u, 4294967286u, 4294967283u, 2u, 6u, 9u, 12u,
}, {
4294967294u, 4294967291u, 4294967288u, 4294967283u, 1u, 4u, 7u, 12u,
}, {
4294967294u, 4294967292u, 4294967290u, 4294967283u, 1u, 3u, 5u, 12u,
}, {
4294967293u, 4294967290u, 4294967288u, 4294967284u, 2u, 5u, 7u, 11u,
}, {
4294967293u, 4294967289u, 4294967287u, 4294967285u, 2u, 6u, 8u, 10u,
}, {
4294967292u, 4294967289u, 4294967288u, 4294967285u, 3u, 6u, 7u, 10u,
}, {
4294967293u, 4294967291u, 4294967288u, 4294967285u, 2u, 4u, 7u, 10u,
},
{
4294967294u, 4294967290u, 4294967288u, 4294967286u, 1u, 5u, 7u, 9u,
}, {
4294967294u, 4294967291u, 4294967288u, 4294967286u, 1u, 4u, 7u, 9u,
}, {
4294967294u, 4294967292u, 4294967288u, 4294967286u, 1u, 3u, 7u, 9u,
}, {
4294967294u, 4294967291u, 4294967289u, 4294967286u, 1u, 4u, 6u, 9u,
}, {
4294967293u, 4294967292u, 4294967289u, 4294967286u, 2u, 3u, 6u, 9u,
}, {
4294967295u, 4294967294u, 4294967293u, 4294967286u, 0u, 1u, 2u, 9u,
}, {
4294967292u, 4294967290u, 4294967288u, 4294967287u, 3u, 5u, 7u, 8u,
}, {
4294967293u, 4294967291u, 4294967289u, 4294967287u, 2u, 4u, 6u, 8u,
},
};
static const uint8_t
WUFFS_ETC2__CLAMP[1024] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u,
8u, 9u, 10u, 11u, 12u, 13u, 14u, 15u,
16u, 17u, 18u, 19u, 20u, 21u, 22u, 23u,
24u, 25u, 26u, 27u, 28u, 29u, 30u, 31u,
32u, 33u, 34u, 35u, 36u, 37u, 38u, 39u,
40u, 41u, 42u, 43u, 44u, 45u, 46u, 47u,
48u, 49u, 50u, 51u, 52u, 53u, 54u, 55u,
56u, 57u, 58u, 59u, 60u, 61u, 62u, 63u,
64u, 65u, 66u, 67u, 68u, 69u, 70u, 71u,
72u, 73u, 74u, 75u, 76u, 77u, 78u, 79u,
80u, 81u, 82u, 83u, 84u, 85u, 86u, 87u,
88u, 89u, 90u, 91u, 92u, 93u, 94u, 95u,
96u, 97u, 98u, 99u, 100u, 101u, 102u, 103u,
104u, 105u, 106u, 107u, 108u, 109u, 110u, 111u,
112u, 113u, 114u, 115u, 116u, 117u, 118u, 119u,
120u, 121u, 122u, 123u, 124u, 125u, 126u, 127u,
128u, 129u, 130u, 131u, 132u, 133u, 134u, 135u,
136u, 137u, 138u, 139u, 140u, 141u, 142u, 143u,
144u, 145u, 146u, 147u, 148u, 149u, 150u, 151u,
152u, 153u, 154u, 155u, 156u, 157u, 158u, 159u,
160u, 161u, 162u, 163u, 164u, 165u, 166u, 167u,
168u, 169u, 170u, 171u, 172u, 173u, 174u, 175u,
176u, 177u, 178u, 179u, 180u, 181u, 182u, 183u,
184u, 185u, 186u, 187u, 188u, 189u, 190u, 191u,
192u, 193u, 194u, 195u, 196u, 197u, 198u, 199u,
200u, 201u, 202u, 203u, 204u, 205u, 206u, 207u,
208u, 209u, 210u, 211u, 212u, 213u, 214u, 215u,
216u, 217u, 218u, 219u, 220u, 221u, 222u, 223u,
224u, 225u, 226u, 227u, 228u, 229u, 230u, 231u,
232u, 233u, 234u, 235u, 236u, 237u, 238u, 239u,
240u, 241u, 242u, 243u, 244u, 245u, 246u, 247u,
248u, 249u, 250u, 251u, 252u, 253u, 254u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
};
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_image_config(
wuffs_etc2__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_frame_config(
wuffs_etc2__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_frame(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__from_src_to_colors(
wuffs_etc2__decoder* self,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__from_colors_to_buffer(
wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_t_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset,
bool a_transparent);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_h_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset,
bool a_transparent);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_planar_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_half_block(
wuffs_etc2__decoder* self,
uint32_t a_bits,
uint32_t a_offset,
uint32_t a_which,
uint32_t a_r,
uint32_t a_g,
uint32_t a_b,
bool a_flip,
bool a_transparent,
bool a_second);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__from_alphas_to_buffer(
wuffs_etc2__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__from_buffer_to_dst(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_etc2__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_etc2__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_etc2__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_etc2__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_etc2__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_etc2__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_etc2__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_etc2__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_etc2__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_etc2__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_etc2__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_etc2__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_etc2__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_etc2__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_etc2__decoder__initialize(
wuffs_etc2__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (sizeof(*self) != sizeof_star_self) {
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
}
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
}
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
// The whole point of this if-check is to detect an uninitialized *self.
// We disable the warning on GCC. Clang-5.0 does not have this warning.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (self->private_impl.magic != 0) {
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
}
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_etc2__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_etc2__decoder*
wuffs_etc2__decoder__alloc(void) {
wuffs_etc2__decoder* x =
(wuffs_etc2__decoder*)(calloc(1, sizeof(wuffs_etc2__decoder)));
if (!x) {
return NULL;
}
if (wuffs_etc2__decoder__initialize(
x, sizeof(wuffs_etc2__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
return x;
}
size_t
sizeof__wuffs_etc2__decoder(void) {
return sizeof(wuffs_etc2__decoder);
}
// ---------------- Function Implementations
// -------- func etc2.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__get_quirk(
const wuffs_etc2__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func etc2.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__set_quirk(
wuffs_etc2__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func etc2.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_image_config(
wuffs_etc2__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_etc2__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_etc2__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func etc2.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_image_config(
wuffs_etc2__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_c32 = 0;
uint16_t v_rounded_up_width = 0;
uint16_t v_rounded_up_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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config;
if (coro_susp_point) {
v_rounded_up_width = self->private_data.s_do_decode_image_config.v_rounded_up_width;
v_rounded_up_height = self->private_data.s_do_decode_image_config.v_rounded_up_height;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0u) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
{
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_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 == 24) {
t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_c32 = t_0;
}
if (v_c32 != 541936464u) {
status = wuffs_base__make_status(wuffs_etc2__error__bad_header);
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_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 += 8u;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
v_c32 = t_1;
}
if ((v_c32 == 12337u) || (v_c32 == 16789554u) || (v_c32 == 151007282u)) {
self->private_impl.f_pixfmt = 2415954056u;
} else if ((v_c32 == 50343986u) || (v_c32 == 167784498u)) {
self->private_impl.f_pixfmt = 2164295816u;
} else if ((v_c32 == 67121202u) || (v_c32 == 184561714u)) {
self->private_impl.f_pixfmt = 2197850248u;
} else if ((v_c32 & 65535u) == 12338u) {
status = wuffs_base__make_status(wuffs_etc2__error__unsupported_etc2_file);
goto exit;
} else {
status = wuffs_base__make_status(wuffs_etc2__error__bad_header);
goto exit;
}
self->private_impl.f_srgb = ((v_c32 >> 24u) >= 9u);
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint16_t t_2;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_2 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2);
if (num_bits_2 == 8) {
t_2 = ((uint16_t)(*scratch >> 48));
break;
}
num_bits_2 += 8u;
*scratch |= ((uint64_t)(num_bits_2));
}
}
v_rounded_up_width = t_2;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
uint16_t t_3;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_3 = wuffs_base__peek_u16be__no_bounds_check(iop_a_src);
iop_a_src += 2;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
if (num_bits_3 == 8) {
t_3 = ((uint16_t)(*scratch >> 48));
break;
}
num_bits_3 += 8u;
*scratch |= ((uint64_t)(num_bits_3));
}
}
v_rounded_up_height = t_3;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
uint32_t t_4;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_4 = ((uint32_t)(wuffs_base__peek_u16be__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_4 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_4);
if (num_bits_4 == 8) {
t_4 = ((uint32_t)(*scratch >> 48));
break;
}
num_bits_4 += 8u;
*scratch |= ((uint64_t)(num_bits_4));
}
}
v_c32 = t_4;
}
if (((v_c32 + 3u) & 4294967292u) != ((uint32_t)(v_rounded_up_width))) {
status = wuffs_base__make_status(wuffs_etc2__error__bad_header);
goto exit;
}
self->private_impl.f_width = v_c32;
{
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_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_5 = ((uint32_t)(*scratch & 0xFFu));
*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 += 8u;
*scratch |= ((uint64_t)(num_bits_5));
}
}
v_c32 = t_5;
}
if (((v_c32 + 3u) & 4294967292u) != ((uint32_t)(v_rounded_up_height))) {
status = wuffs_base__make_status(wuffs_etc2__error__bad_header);
goto exit;
}
self->private_impl.f_height = v_c32;
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
self->private_impl.f_pixfmt,
0u,
self->private_impl.f_width,
self->private_impl.f_height,
16u,
(self->private_impl.f_pixfmt == 2415954056u));
}
self->private_impl.f_call_sequence = 32u;
goto ok;
ok:
self->private_impl.p_do_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_image_config.v_rounded_up_width = v_rounded_up_width;
self->private_data.s_do_decode_image_config.v_rounded_up_height = v_rounded_up_height;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func etc2.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_frame_config(
wuffs_etc2__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 2)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_etc2__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_etc2__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func etc2.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_frame_config(
wuffs_etc2__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 32u) {
} else if (self->private_impl.f_call_sequence < 32u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_etc2__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 40u) {
if (16u != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
goto exit;
}
} else if (self->private_impl.f_call_sequence == 64u) {
self->private_impl.f_call_sequence = 96u;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height),
((wuffs_base__flicks)(0u)),
0u,
16u,
0u,
(self->private_impl.f_pixfmt == 2415954056u),
false,
4278190080u);
}
self->private_impl.f_call_sequence = 64u;
ok:
self->private_impl.p_do_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func etc2.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__decode_frame(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 3)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_etc2__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_etc2__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func etc2.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__do_decode_frame(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_remaining = 0;
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame;
if (coro_susp_point) {
v_remaining = self->private_data.s_do_decode_frame.v_remaining;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64u) {
} else if (self->private_impl.f_call_sequence < 64u) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_etc2__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
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(a_dst),
wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
wuffs_base__utility__empty_slice_u8(),
a_blend);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
self->private_impl.f_dst_x = 0u;
self->private_impl.f_dst_y = 0u;
v_remaining = (((self->private_impl.f_width + 3u) / 4u) * ((self->private_impl.f_height + 3u) / 4u));
while (v_remaining > 0u) {
self->private_impl.f_num_buffered_blocks = wuffs_base__u32__min(v_remaining, 64u);
if (v_remaining < self->private_impl.f_num_buffered_blocks) {
status = wuffs_base__make_status(wuffs_base__error__too_much_data);
goto exit;
}
v_remaining -= self->private_impl.f_num_buffered_blocks;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_etc2__decoder__from_src_to_colors(self, a_src);
if (status.repr) {
goto suspend;
}
wuffs_etc2__decoder__from_colors_to_buffer(self);
if (self->private_impl.f_pixfmt == 2164295816u) {
wuffs_etc2__decoder__from_alphas_to_buffer(self);
}
v_status = wuffs_etc2__decoder__from_buffer_to_dst(self, a_dst);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
}
self->private_impl.f_call_sequence = 96u;
ok:
self->private_impl.p_do_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_do_decode_frame.v_remaining = v_remaining;
goto exit;
exit:
return status;
}
// -------- func etc2.decoder.from_src_to_colors
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__from_src_to_colors(
wuffs_etc2__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_bi = 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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_from_src_to_colors;
if (coro_susp_point) {
v_bi = self->private_data.s_from_src_to_colors.v_bi;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (v_bi < self->private_impl.f_num_buffered_blocks) {
if (self->private_impl.f_pixfmt == 2164295816u) {
{
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_u64be__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_from_src_to_colors.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_from_src_to_colors.scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 56) {
t_0 = ((uint64_t)(*scratch >> 0));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_data.f_alphas[v_bi] = t_0;
}
}
{
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_u64be__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_from_src_to_colors.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_from_src_to_colors.scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
if (num_bits_1 == 56) {
t_1 = ((uint64_t)(*scratch >> 0));
break;
}
num_bits_1 += 8u;
*scratch |= ((uint64_t)(num_bits_1));
}
}
self->private_data.f_colors[v_bi] = t_1;
}
v_bi += 1u;
}
goto ok;
ok:
self->private_impl.p_from_src_to_colors = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_from_src_to_colors = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_from_src_to_colors.v_bi = v_bi;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func etc2.decoder.from_colors_to_buffer
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__from_colors_to_buffer(
wuffs_etc2__decoder* self) {
uint32_t v_bi = 0;
uint64_t v_color = 0;
uint32_t v_r0 = 0;
uint32_t v_r1 = 0;
uint32_t v_g0 = 0;
uint32_t v_g1 = 0;
uint32_t v_b0 = 0;
uint32_t v_b1 = 0;
bool v_diff = false;
bool v_tran = false;
bool v_flip = false;
while (v_bi < self->private_impl.f_num_buffered_blocks) {
v_color = self->private_data.f_colors[v_bi];
v_diff = ((v_color & 8589934592u) != 0u);
v_tran = ( ! v_diff && (self->private_impl.f_pixfmt == 2197850248u));
if ( ! v_diff && (self->private_impl.f_pixfmt != 2197850248u)) {
v_r0 = ((uint32_t)((15u & (v_color >> 60u))));
v_r0 = ((v_r0 << 4u) | v_r0);
v_r1 = ((uint32_t)((15u & (v_color >> 56u))));
v_r1 = ((v_r1 << 4u) | v_r1);
v_g0 = ((uint32_t)((15u & (v_color >> 52u))));
v_g0 = ((v_g0 << 4u) | v_g0);
v_g1 = ((uint32_t)((15u & (v_color >> 48u))));
v_g1 = ((v_g1 << 4u) | v_g1);
v_b0 = ((uint32_t)((15u & (v_color >> 44u))));
v_b0 = ((v_b0 << 4u) | v_b0);
v_b1 = ((uint32_t)((15u & (v_color >> 40u))));
v_b1 = ((v_b1 << 4u) | v_b1);
} else {
v_r0 = ((uint32_t)((31u & (v_color >> 59u))));
v_r1 = ((uint32_t)(v_r0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 56u))]));
if ((v_r1 >> 5u) != 0u) {
wuffs_etc2__decoder__decode_t_mode(self, v_color, (16u * v_bi), v_tran);
v_bi += 1u;
continue;
}
v_r0 = (((uint32_t)(v_r0 << 3u)) | (v_r0 >> 2u));
v_r1 = (((uint32_t)(v_r1 << 3u)) | (v_r1 >> 2u));
v_g0 = ((uint32_t)((31u & (v_color >> 51u))));
v_g1 = ((uint32_t)(v_g0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 48u))]));
if ((v_g1 >> 5u) != 0u) {
wuffs_etc2__decoder__decode_h_mode(self, v_color, (16u * v_bi), v_tran);
v_bi += 1u;
continue;
}
v_g0 = (((uint32_t)(v_g0 << 3u)) | (v_g0 >> 2u));
v_g1 = (((uint32_t)(v_g1 << 3u)) | (v_g1 >> 2u));
v_b0 = ((uint32_t)((31u & (v_color >> 43u))));
v_b1 = ((uint32_t)(v_b0 + WUFFS_ETC2__DIFFS[(7u & (v_color >> 40u))]));
if ((v_b1 >> 5u) != 0u) {
wuffs_etc2__decoder__decode_planar_mode(self, v_color, (16u * v_bi));
v_bi += 1u;
continue;
}
v_b0 = (((uint32_t)(v_b0 << 3u)) | (v_b0 >> 2u));
v_b1 = (((uint32_t)(v_b1 << 3u)) | (v_b1 >> 2u));
}
v_flip = ((v_color & 4294967296u) != 0u);
wuffs_etc2__decoder__decode_half_block(self,
((uint32_t)(v_color)),
(16u * v_bi),
((uint32_t)(((v_color >> 37u) & 7u))),
v_r0,
v_g0,
v_b0,
v_flip,
v_tran,
false);
wuffs_etc2__decoder__decode_half_block(self,
((uint32_t)(v_color)),
(16u * v_bi),
((uint32_t)(((v_color >> 34u) & 7u))),
v_r1,
v_g1,
v_b1,
v_flip,
v_tran,
true);
v_bi += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.decode_t_mode
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_t_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset,
bool a_transparent) {
uint8_t v_r[4] = {0};
uint8_t v_g[4] = {0};
uint8_t v_b[4] = {0};
uint8_t v_a[4] = {0};
uint32_t v_which = 0;
uint32_t v_delta = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_x4y = 0;
uint32_t v_index = 0;
uint32_t v_o = 0;
v_r[0u] = ((uint8_t)(((uint8_t)((12u & (a_bits >> 57u)))) | ((uint8_t)((3u & (a_bits >> 56u))))));
v_r[0u] = ((uint8_t)(((uint8_t)(v_r[0u] << 4u)) | v_r[0u]));
v_g[0u] = ((uint8_t)((15u & (a_bits >> 52u))));
v_g[0u] = ((uint8_t)(((uint8_t)(v_g[0u] << 4u)) | v_g[0u]));
v_b[0u] = ((uint8_t)((15u & (a_bits >> 48u))));
v_b[0u] = ((uint8_t)(((uint8_t)(v_b[0u] << 4u)) | v_b[0u]));
v_a[0u] = 255u;
v_r[2u] = ((uint8_t)((15u & (a_bits >> 44u))));
v_r[2u] = ((uint8_t)(((uint8_t)(v_r[2u] << 4u)) | v_r[2u]));
v_g[2u] = ((uint8_t)((15u & (a_bits >> 40u))));
v_g[2u] = ((uint8_t)(((uint8_t)(v_g[2u] << 4u)) | v_g[2u]));
v_b[2u] = ((uint8_t)((15u & (a_bits >> 36u))));
v_b[2u] = ((uint8_t)(((uint8_t)(v_b[2u] << 4u)) | v_b[2u]));
v_a[2u] = 255u;
v_which = (((uint32_t)((6u & (a_bits >> 33u)))) | ((uint32_t)((1u & (a_bits >> 32u)))));
v_delta = ((uint32_t)(WUFFS_ETC2__T_H_MODIFIERS[v_which]));
v_r[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) + v_delta)) & 1023u)];
v_g[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) + v_delta)) & 1023u)];
v_b[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) + v_delta)) & 1023u)];
v_a[1u] = 255u;
v_r[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) - v_delta)) & 1023u)];
v_g[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) - v_delta)) & 1023u)];
v_b[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) - v_delta)) & 1023u)];
v_a[3u] = 255u;
if (a_transparent) {
v_r[2u] = 0u;
v_g[2u] = 0u;
v_b[2u] = 0u;
v_a[2u] = 0u;
}
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_x4y = ((v_x * 4u) | v_y);
v_index = (((uint32_t)(((a_bits >> v_x4y) & 1u))) | ((uint32_t)(((a_bits >> (v_x4y + 15u)) & 2u))));
v_o = (a_offset + (v_x * 4u) + (v_y * 1024u));
self->private_data.f_buffer[(v_o + 0u)] = v_b[v_index];
self->private_data.f_buffer[(v_o + 1u)] = v_g[v_index];
self->private_data.f_buffer[(v_o + 2u)] = v_r[v_index];
self->private_data.f_buffer[(v_o + 3u)] = v_a[v_index];
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.decode_h_mode
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_h_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset,
bool a_transparent) {
uint8_t v_r[4] = {0};
uint8_t v_g[4] = {0};
uint8_t v_b[4] = {0};
uint8_t v_a[4] = {0};
uint32_t v_rgb0 = 0;
uint32_t v_rgb2 = 0;
uint32_t v_which = 0;
uint32_t v_delta = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_x4y = 0;
uint32_t v_index = 0;
uint32_t v_o = 0;
v_r[0u] = ((uint8_t)((15u & (a_bits >> 59u))));
v_r[0u] = ((uint8_t)(((uint8_t)(v_r[0u] << 4u)) | v_r[0u]));
v_g[0u] = ((uint8_t)(((uint8_t)((14u & (a_bits >> 55u)))) | ((uint8_t)((1u & (a_bits >> 52u))))));
v_g[0u] = ((uint8_t)(((uint8_t)(v_g[0u] << 4u)) | v_g[0u]));
v_b[0u] = ((uint8_t)(((uint8_t)((8u & (a_bits >> 48u)))) | ((uint8_t)((7u & (a_bits >> 47u))))));
v_b[0u] = ((uint8_t)(((uint8_t)(v_b[0u] << 4u)) | v_b[0u]));
v_r[2u] = ((uint8_t)((15u & (a_bits >> 43u))));
v_r[2u] = ((uint8_t)(((uint8_t)(v_r[2u] << 4u)) | v_r[2u]));
v_g[2u] = ((uint8_t)((15u & (a_bits >> 39u))));
v_g[2u] = ((uint8_t)(((uint8_t)(v_g[2u] << 4u)) | v_g[2u]));
v_b[2u] = ((uint8_t)((15u & (a_bits >> 35u))));
v_b[2u] = ((uint8_t)(((uint8_t)(v_b[2u] << 4u)) | v_b[2u]));
v_rgb0 = ((((uint32_t)(v_r[0u])) << 16u) | (((uint32_t)(v_g[0u])) << 8u) | (((uint32_t)(v_b[0u])) << 0u));
v_rgb2 = ((((uint32_t)(v_r[2u])) << 16u) | (((uint32_t)(v_g[2u])) << 8u) | (((uint32_t)(v_b[2u])) << 0u));
v_which = (((uint32_t)((4u & (a_bits >> 32u)))) | ((uint32_t)((2u & (a_bits >> 31u)))));
if (v_rgb0 >= v_rgb2) {
v_which |= 1u;
}
v_delta = ((uint32_t)(WUFFS_ETC2__T_H_MODIFIERS[v_which]));
v_r[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[0u])) - v_delta)) & 1023u)];
v_g[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[0u])) - v_delta)) & 1023u)];
v_b[1u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[0u])) - v_delta)) & 1023u)];
v_a[1u] = 255u;
v_r[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[0u])) + v_delta)) & 1023u)];
v_g[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[0u])) + v_delta)) & 1023u)];
v_b[0u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[0u])) + v_delta)) & 1023u)];
v_a[0u] = 255u;
v_r[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) - v_delta)) & 1023u)];
v_g[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) - v_delta)) & 1023u)];
v_b[3u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) - v_delta)) & 1023u)];
v_a[3u] = 255u;
v_r[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_r[2u])) + v_delta)) & 1023u)];
v_g[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_g[2u])) + v_delta)) & 1023u)];
v_b[2u] = WUFFS_ETC2__CLAMP[(((uint32_t)(((uint32_t)(v_b[2u])) + v_delta)) & 1023u)];
v_a[2u] = 255u;
if (a_transparent) {
v_r[2u] = 0u;
v_g[2u] = 0u;
v_b[2u] = 0u;
v_a[2u] = 0u;
}
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_x4y = ((v_x * 4u) | v_y);
v_index = (((uint32_t)(((a_bits >> v_x4y) & 1u))) | ((uint32_t)(((a_bits >> (v_x4y + 15u)) & 2u))));
v_o = (a_offset + (v_x * 4u) + (v_y * 1024u));
self->private_data.f_buffer[(v_o + 0u)] = v_b[v_index];
self->private_data.f_buffer[(v_o + 1u)] = v_g[v_index];
self->private_data.f_buffer[(v_o + 2u)] = v_r[v_index];
self->private_data.f_buffer[(v_o + 3u)] = v_a[v_index];
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.decode_planar_mode
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_planar_mode(
wuffs_etc2__decoder* self,
uint64_t a_bits,
uint32_t a_offset) {
uint32_t v_ro = 0;
uint32_t v_go = 0;
uint32_t v_bo = 0;
uint32_t v_rh = 0;
uint32_t v_gh = 0;
uint32_t v_bh = 0;
uint32_t v_rv = 0;
uint32_t v_gv = 0;
uint32_t v_bv = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_o = 0;
uint32_t v_rp = 0;
uint32_t v_gp = 0;
uint32_t v_bp = 0;
v_ro = ((uint32_t)((63u & (a_bits >> 57u))));
v_ro = (((uint32_t)(v_ro << 2u)) | (v_ro >> 4u));
v_go = (((uint32_t)((64u & (a_bits >> 50u)))) | ((uint32_t)((63u & (a_bits >> 49u)))));
v_go = (((uint32_t)(v_go << 1u)) | (v_go >> 6u));
v_bo = (((uint32_t)((32u & (a_bits >> 43u)))) | ((uint32_t)((24u & (a_bits >> 40u)))) | ((uint32_t)((7u & (a_bits >> 39u)))));
v_bo = (((uint32_t)(v_bo << 2u)) | (v_bo >> 4u));
v_rh = (((uint32_t)((62u & (a_bits >> 33u)))) | ((uint32_t)((1u & (a_bits >> 32u)))));
v_rh = (((uint32_t)(v_rh << 2u)) | (v_rh >> 4u));
v_gh = ((uint32_t)((127u & (a_bits >> 25u))));
v_gh = (((uint32_t)(v_gh << 1u)) | (v_gh >> 6u));
v_bh = ((uint32_t)((63u & (a_bits >> 19u))));
v_bh = (((uint32_t)(v_bh << 2u)) | (v_bh >> 4u));
v_rv = ((uint32_t)((63u & (a_bits >> 13u))));
v_rv = (((uint32_t)(v_rv << 2u)) | (v_rv >> 4u));
v_gv = ((uint32_t)((127u & (a_bits >> 6u))));
v_gv = (((uint32_t)(v_gv << 1u)) | (v_gv >> 6u));
v_bv = ((uint32_t)((63u & (a_bits >> 0u))));
v_bv = (((uint32_t)(v_bv << 2u)) | (v_bv >> 4u));
v_rh -= v_ro;
v_gh -= v_go;
v_bh -= v_bo;
v_rv -= v_ro;
v_gv -= v_go;
v_bv -= v_bo;
v_ro *= 4u;
v_go *= 4u;
v_bo *= 4u;
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_o = (a_offset + (v_x * 4u) + (v_y * 1024u));
v_bp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_bh)) + ((uint32_t)(v_y * v_bv)))) + v_bo));
self->private_data.f_buffer[(v_o + 0u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_bp + 2u)) / 4u) & 1023u)];
v_gp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_gh)) + ((uint32_t)(v_y * v_gv)))) + v_go));
self->private_data.f_buffer[(v_o + 1u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_gp + 2u)) / 4u) & 1023u)];
v_rp = ((uint32_t)(((uint32_t)(((uint32_t)(v_x * v_rh)) + ((uint32_t)(v_y * v_rv)))) + v_ro));
self->private_data.f_buffer[(v_o + 2u)] = WUFFS_ETC2__CLAMP[((((uint32_t)(v_rp + 2u)) / 4u) & 1023u)];
v_x += 1u;
self->private_data.f_buffer[(v_o + 3u)] = 255u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.decode_half_block
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__decode_half_block(
wuffs_etc2__decoder* self,
uint32_t a_bits,
uint32_t a_offset,
uint32_t a_which,
uint32_t a_r,
uint32_t a_g,
uint32_t a_b,
bool a_flip,
bool a_transparent,
bool a_second) {
uint32_t v_which = 0;
uint32_t v_x0 = 0;
uint32_t v_y0 = 0;
uint32_t v_x = 0;
uint32_t v_y = 0;
uint32_t v_i = 0;
uint32_t v_x4y = 0;
uint32_t v_index = 0;
uint32_t v_modif = 0;
uint32_t v_o = 0;
v_which = a_which;
if (a_transparent) {
v_which |= 8u;
}
if ( ! a_second) {
} else if (a_flip) {
v_y0 = 2u;
} else {
v_x0 = 2u;
}
while (v_i < 8u) {
if (a_flip) {
v_x = ((v_x0 + (v_i / 2u)) & 3u);
v_y = (v_y0 + (v_i & 1u));
} else {
v_x = (v_x0 + (v_i / 4u));
v_y = ((v_y0 + v_i) & 3u);
}
v_x4y = ((v_x * 4u) | v_y);
v_index = (((a_bits >> v_x4y) & 1u) | ((a_bits >> (v_x4y + 15u)) & 2u));
v_modif = WUFFS_ETC2__MODIFIERS[v_which][v_index];
v_o = (a_offset + (v_x * 4u) + (v_y * 1024u));
if (a_transparent && (v_index == 2u)) {
self->private_data.f_buffer[(v_o + 0u)] = 0u;
self->private_data.f_buffer[(v_o + 1u)] = 0u;
self->private_data.f_buffer[(v_o + 2u)] = 0u;
self->private_data.f_buffer[(v_o + 3u)] = 0u;
} else {
self->private_data.f_buffer[(v_o + 0u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_b + v_modif)) & 1023u)];
self->private_data.f_buffer[(v_o + 1u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_g + v_modif)) & 1023u)];
self->private_data.f_buffer[(v_o + 2u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(a_r + v_modif)) & 1023u)];
self->private_data.f_buffer[(v_o + 3u)] = 255u;
}
v_i += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.from_alphas_to_buffer
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_etc2__decoder__from_alphas_to_buffer(
wuffs_etc2__decoder* self) {
uint32_t v_bi = 0;
uint64_t v_alpha = 0;
uint32_t v_a0 = 0;
uint32_t v_multiplier = 0;
uint32_t v_which = 0;
uint32_t v_offset = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_shift = 0;
uint32_t v_delta = 0;
uint32_t v_o = 0;
while (v_bi < self->private_impl.f_num_buffered_blocks) {
v_alpha = self->private_data.f_alphas[v_bi];
v_a0 = ((uint32_t)((v_alpha >> 56u)));
v_multiplier = ((uint32_t)(((v_alpha >> 52u) & 15u)));
v_which = ((uint32_t)(((v_alpha >> 48u) & 15u)));
v_offset = (16u * v_bi);
v_y = 0u;
while (v_y < 4u) {
v_x = 0u;
while (v_x < 4u) {
v_shift = ((((v_x ^ 3u) * 4u) | (v_y ^ 3u)) * 3u);
v_delta = ((uint32_t)(v_multiplier * WUFFS_ETC2__ALPHA_MODIFIERS[v_which][(7u & (v_alpha >> v_shift))]));
v_o = (v_offset + (v_x * 4u) + (v_y * 1024u));
self->private_data.f_buffer[(v_o + 3u)] = WUFFS_ETC2__CLAMP[(((uint32_t)(v_a0 + v_delta)) & 1023u)];
v_x += 1u;
}
v_y += 1u;
}
v_bi += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.from_buffer_to_dst
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_etc2__decoder__from_buffer_to_dst(
wuffs_etc2__decoder* self,
wuffs_base__pixel_buffer* a_dst) {
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint32_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
wuffs_base__table_u8 v_tab = {0};
uint32_t v_bi = 0;
uint32_t v_rem_x = 0;
uint32_t v_dy = 0;
wuffs_base__slice_u8 v_dst = {0};
wuffs_base__slice_u8 v_src = {0};
uint32_t v_si = 0;
uint32_t v_sj = 0;
uint64_t v_i = 0;
uint32_t v_num_src_pixels = 0;
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
if ((v_dst_bits_per_pixel & 7u) != 0u) {
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8u);
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u);
while (v_bi < self->private_impl.f_num_buffered_blocks) {
if (self->private_impl.f_width <= self->private_impl.f_dst_x) {
self->private_impl.f_dst_x = 0u;
self->private_impl.f_dst_y += 4u;
if (self->private_impl.f_dst_y >= self->private_impl.f_height) {
break;
}
v_rem_x = self->private_impl.f_width;
} else {
v_rem_x = (self->private_impl.f_width - self->private_impl.f_dst_x);
}
v_dy = 0u;
while (v_dy < 4u) {
v_si = ((1024u * v_dy) + (16u * v_bi));
v_sj = ((1024u * v_dy) + 1024u);
if (v_si < v_sj) {
v_src = wuffs_base__make_slice_u8_ij(self->private_data.f_buffer, v_si, v_sj);
}
if (((uint64_t)((4u * v_rem_x))) < ((uint64_t)(v_src.len))) {
v_src = wuffs_base__slice_u8__subslice_j(v_src, ((uint64_t)((4u * v_rem_x))));
}
if (((uint32_t)(self->private_impl.f_dst_y + v_dy)) >= self->private_impl.f_height) {
break;
}
v_dst = wuffs_private_impl__table_u8__row_u32(v_tab, ((uint32_t)(self->private_impl.f_dst_y + v_dy)));
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);
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
if (v_i < ((uint64_t)(v_dst.len))) {
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), wuffs_base__pixel_buffer__palette(a_dst), v_src);
}
v_dy += 1u;
}
v_num_src_pixels = (((uint32_t)(((uint64_t)(v_src.len)))) / 4u);
self->private_impl.f_dst_x += v_num_src_pixels;
v_bi += ((v_num_src_pixels + 3u) / 4u);
}
return wuffs_base__make_status(NULL);
}
// -------- func etc2.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_etc2__decoder__frame_dirty_rect(
const wuffs_etc2__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_rect_ie_u32();
}
return wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height);
}
// -------- func etc2.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_etc2__decoder__num_animation_loops(
const wuffs_etc2__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func etc2.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__num_decoded_frame_configs(
const wuffs_etc2__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 32u) {
return 1u;
}
return 0u;
}
// -------- func etc2.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_etc2__decoder__num_decoded_frames(
const wuffs_etc2__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 64u) {
return 1u;
}
return 0u;
}
// -------- func etc2.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__restart_frame(
wuffs_etc2__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (self->private_impl.f_call_sequence < 32u) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if ((a_index != 0u) || (a_io_position != 16u)) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 40u;
return wuffs_base__make_status(NULL);
}
// -------- func etc2.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_etc2__decoder__set_report_metadata(
wuffs_etc2__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func etc2.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_etc2__decoder__tell_me_more(
wuffs_etc2__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 4)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
goto ok;
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func etc2.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_etc2__decoder__workbuf_len(
const wuffs_etc2__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_range_ii_u64();
}
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
// ---------------- Status Codes Implementations
@@ -40304,7 +44312,7 @@ WUFFS_GIF__XMPDATAXMP[11] WUFFS_BASE__POTENTIALLY_UNUSED = {
88u, 77u, 80u,
};
#define WUFFS_GIF__QUIRKS_BASE 1041635328u
#define WUFFS_GIF__QUIRKS_BASE 983928832u
#define WUFFS_GIF__QUIRKS_COUNT 7u
@@ -40527,7 +44535,7 @@ wuffs_gif__decoder__initialize(
wuffs_gif__decoder*
wuffs_gif__decoder__alloc(void) {
wuffs_gif__decoder* x =
(wuffs_gif__decoder*)(calloc(sizeof(wuffs_gif__decoder), 1));
(wuffs_gif__decoder*)(calloc(1, sizeof(wuffs_gif__decoder)));
if (!x) {
return NULL;
}
@@ -40563,8 +44571,8 @@ wuffs_gif__decoder__get_quirk(
uint32_t v_key = 0;
if (a_key >= 1041635328u) {
v_key = (a_key - 1041635328u);
if (a_key >= 983928832u) {
v_key = (a_key - 983928832u);
if (v_key < 7u) {
if (self->private_impl.f_quirks[v_key]) {
return 1u;
@@ -40592,8 +44600,8 @@ wuffs_gif__decoder__set_quirk(
: wuffs_base__error__initialize_not_called);
}
if ((self->private_impl.f_call_sequence == 0u) && (a_key >= 1041635328u)) {
a_key -= 1041635328u;
if ((self->private_impl.f_call_sequence == 0u) && (a_key >= 983928832u)) {
a_key -= 983928832u;
if (a_key < 7u) {
self->private_impl.f_quirks[a_key] = (a_value > 0u);
return wuffs_base__make_status(NULL);
@@ -43438,7 +47446,7 @@ wuffs_gzip__decoder__initialize(
wuffs_gzip__decoder*
wuffs_gzip__decoder__alloc(void) {
wuffs_gzip__decoder* x =
(wuffs_gzip__decoder*)(calloc(sizeof(wuffs_gzip__decoder), 1));
(wuffs_gzip__decoder*)(calloc(1, sizeof(wuffs_gzip__decoder)));
if (!x) {
return NULL;
}
@@ -43935,6 +47943,8 @@ const char wuffs_jpeg__error__bad_marker[] = "#jpeg: bad marker";
const char wuffs_jpeg__error__bad_scan_count[] = "#jpeg: bad scan count";
const char wuffs_jpeg__error__missing_huffman_table[] = "#jpeg: missing Huffman table";
const char wuffs_jpeg__error__missing_quantization_table[] = "#jpeg: missing Quantization table";
const char wuffs_jpeg__error__rejected_progressive_jpeg[] = "#jpeg: rejected progressive JPEG";
const char wuffs_jpeg__error__short_sos_bitstream[] = "#jpeg: short SOS bitstream";
const char wuffs_jpeg__error__truncated_input[] = "#jpeg: truncated input";
const char wuffs_jpeg__error__unsupported_arithmetic_coding[] = "#jpeg: unsupported arithmetic coding";
const char wuffs_jpeg__error__unsupported_color_model[] = "#jpeg: unsupported color model";
@@ -44173,6 +48183,8 @@ WUFFS_JPEG__DEFAULT_HUFF_TABLE_AC_CHROMA[179] WUFFS_BASE__POTENTIALLY_UNUSED = {
248u, 249u, 250u,
};
#define WUFFS_JPEG__QUIRKS_BASE 1162824704u
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
@@ -44541,7 +48553,7 @@ wuffs_jpeg__decoder__initialize(
wuffs_jpeg__decoder*
wuffs_jpeg__decoder__alloc(void) {
wuffs_jpeg__decoder* x =
(wuffs_jpeg__decoder*)(calloc(sizeof(wuffs_jpeg__decoder), 1));
(wuffs_jpeg__decoder*)(calloc(1, sizeof(wuffs_jpeg__decoder)));
if (!x) {
return NULL;
}
@@ -46090,6 +50102,10 @@ wuffs_jpeg__decoder__get_quirk(
if (self->private_impl.f_use_lower_quality) {
return 18446744073709551615u;
}
} else if (a_key == 1162824704u) {
if (self->private_impl.f_reject_progressive_jpegs) {
return 1u;
}
}
return 0u;
}
@@ -46115,6 +50131,9 @@ wuffs_jpeg__decoder__set_quirk(
if (a_key == 2u) {
self->private_impl.f_use_lower_quality = (a_value >= 9223372036854775808u);
return wuffs_base__make_status(NULL);
} else if (a_key == 1162824704u) {
self->private_impl.f_reject_progressive_jpegs = (a_value != 0u);
return wuffs_base__make_status(NULL);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
@@ -46314,6 +50333,9 @@ wuffs_jpeg__decoder__do_decode_image_config(
self->private_impl.f_payload_length = t_4;
}
if (self->private_impl.f_payload_length < 2u) {
if ((v_marker == 254u) || ((224u <= v_marker) && (v_marker < 240u))) {
continue;
}
status = wuffs_base__make_status(wuffs_jpeg__error__bad_marker);
goto exit;
}
@@ -46324,9 +50346,20 @@ wuffs_jpeg__decoder__do_decode_image_config(
goto exit;
} else if (v_marker < 208u) {
if (v_marker <= 194u) {
if (self->private_impl.f_sof_marker != 0u) {
if ((v_marker == 194u) && self->private_impl.f_reject_progressive_jpegs) {
status = wuffs_base__make_status(wuffs_jpeg__error__rejected_progressive_jpeg);
goto exit;
} else if (self->private_impl.f_sof_marker != 0u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker);
goto exit;
} else if (v_marker == 192u) {
if (self->private_impl.f_seen_dht[2u] ||
self->private_impl.f_seen_dht[3u] ||
self->private_impl.f_seen_dht[6u] ||
self->private_impl.f_seen_dht[7u]) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sof_marker);
goto exit;
}
}
self->private_impl.f_sof_marker = v_marker;
if (a_src) {
@@ -46345,8 +50378,18 @@ wuffs_jpeg__decoder__do_decode_image_config(
status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_lossless_coding);
goto exit;
} else if (v_marker == 196u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker);
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_jpeg__decoder__decode_dht(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
continue;
} else if ((197u <= v_marker) && (v_marker <= 199u)) {
status = wuffs_base__make_status(wuffs_jpeg__error__unsupported_hierarchical_coding);
goto exit;
@@ -46368,7 +50411,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
status = wuffs_jpeg__decoder__decode_dqt(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
@@ -46381,7 +50424,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
status = wuffs_jpeg__decoder__decode_dri(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
@@ -46398,7 +50441,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
status = wuffs_jpeg__decoder__decode_appn(self, a_src, v_marker);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
@@ -46415,7 +50458,7 @@ wuffs_jpeg__decoder__do_decode_image_config(
}
}
self->private_data.s_do_decode_image_config.scratch = self->private_impl.f_payload_length;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
if (self->private_data.s_do_decode_image_config.scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
self->private_data.s_do_decode_image_config.scratch -= ((uint64_t)(io2_a_src - iop_a_src));
iop_a_src = io2_a_src;
@@ -47529,11 +51572,11 @@ wuffs_jpeg__decoder__do_decode_frame(
}
self->private_impl.f_swizzle_immediately = false;
if (self->private_impl.f_components_workbuf_offsets[8u] > ((uint64_t)(a_workbuf.len))) {
if (self->private_impl.f_sof_marker >= 194u) {
if ((self->private_impl.f_sof_marker >= 194u) || ! self->private_impl.f_use_lower_quality) {
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
goto exit;
}
self->private_impl.f_swizzle_immediately = self->private_impl.f_use_lower_quality;
self->private_impl.f_swizzle_immediately = true;
self->private_impl.f_swizzle_immediately_status = wuffs_base__make_status(NULL);
} else if (self->private_impl.f_components_workbuf_offsets[4u] < self->private_impl.f_components_workbuf_offsets[8u]) {
wuffs_private_impl__bulk_memset(a_workbuf.ptr + self->private_impl.f_components_workbuf_offsets[4u], (self->private_impl.f_components_workbuf_offsets[8u] - self->private_impl.f_components_workbuf_offsets[4u]), 0u);
@@ -47763,10 +51806,6 @@ wuffs_jpeg__decoder__decode_dht(
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_sof_marker == 0u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker);
goto exit;
}
while (self->private_impl.f_payload_length > 0u) {
if (self->private_impl.f_payload_length < 17u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_dht_marker);
@@ -48090,7 +52129,7 @@ wuffs_jpeg__decoder__decode_sos(
if (v_bitstream_length < ((uint32_t)(self->private_impl.f_bitstream_wi - self->private_impl.f_bitstream_ri))) {
break;
} else if (self->private_impl.f_bitstream_padding == 0u) {
status = wuffs_base__make_status(wuffs_jpeg__error__bad_sos_marker);
status = wuffs_base__make_status(wuffs_jpeg__error__short_sos_bitstream);
goto exit;
} else if ((a_src && a_src->meta.closed) && ! self->private_impl.f_bitstream_is_closed) {
if (self->private_impl.f_bitstream_wi < 1024u) {
@@ -48622,13 +52661,17 @@ wuffs_jpeg__decoder__fill_bitstream(
continue;
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 1u) {
break;
} else if (((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)) > 0u) {
break;
} else {
}
v_c8 = iop_a_src[1u];
if (v_c8 == 0u) {
self->private_data.f_bitstream_buffer[v_wi] = 255u;
v_wi += 1u;
iop_a_src += 2u;
continue;
} else if (v_c8 < 255u) {
break;
}
iop_a_src += 1u;
}
if (((uint64_t)(io2_a_src - iop_a_src)) > 1u) {
if ((wuffs_base__peek_u8be__no_bounds_check(iop_a_src) >= 255u) && (((uint16_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u)) > 0u)) {
@@ -51106,7 +55149,7 @@ WUFFS_JSON__LUT_HEXADECIMAL_DIGITS[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
};
#define WUFFS_JSON__QUIRKS_BASE 1225364480u
#define WUFFS_JSON__QUIRKS_BASE 1167656960u
#define WUFFS_JSON__QUIRKS_COUNT 21u
@@ -51223,7 +55266,7 @@ wuffs_json__decoder__initialize(
wuffs_json__decoder*
wuffs_json__decoder__alloc(void) {
wuffs_json__decoder* x =
(wuffs_json__decoder*)(calloc(sizeof(wuffs_json__decoder), 1));
(wuffs_json__decoder*)(calloc(1, sizeof(wuffs_json__decoder)));
if (!x) {
return NULL;
}
@@ -51259,8 +55302,8 @@ wuffs_json__decoder__get_quirk(
uint32_t v_key = 0;
if (a_key >= 1225364480u) {
v_key = (a_key - 1225364480u);
if (a_key >= 1167656960u) {
v_key = (a_key - 1167656960u);
if (v_key < 21u) {
if (self->private_impl.f_quirks[v_key]) {
return 1u;
@@ -51288,8 +55331,8 @@ wuffs_json__decoder__set_quirk(
: wuffs_base__error__initialize_not_called);
}
if (a_key >= 1225364480u) {
a_key -= 1225364480u;
if (a_key >= 1167656960u) {
a_key -= 1167656960u;
if (a_key < 21u) {
self->private_impl.f_quirks[a_key] = (a_value > 0u);
return wuffs_base__make_status(NULL);
@@ -53143,7 +57186,7 @@ WUFFS_LZMA__CLAMP_NO_MORE_THAN_3[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 1u, 2u, 3u, 3u, 3u, 3u, 3u,
};
#define WUFFS_LZMA__QUIRKS_BASE 1348001792u
#define WUFFS_LZMA__QUIRKS_BASE 1290294272u
// ---------------- Private Initializer Prototypes
@@ -53281,7 +57324,7 @@ wuffs_lzma__decoder__initialize(
wuffs_lzma__decoder*
wuffs_lzma__decoder__alloc(void) {
wuffs_lzma__decoder* x =
(wuffs_lzma__decoder*)(calloc(sizeof(wuffs_lzma__decoder), 1));
(wuffs_lzma__decoder*)(calloc(1, sizeof(wuffs_lzma__decoder)));
if (!x) {
return NULL;
}
@@ -55310,11 +59353,11 @@ wuffs_lzma__decoder__get_quirk(
return 0;
}
if (a_key == 1348001792u) {
if (a_key == 1290294272u) {
if (self->private_impl.f_allow_non_zero_initial_byte) {
return 1u;
}
} else if (a_key == 1348001793u) {
} else if (a_key == 1290294273u) {
return ((uint64_t)(self->private_impl.f_format_extension));
}
return 0u;
@@ -55341,9 +59384,9 @@ wuffs_lzma__decoder__set_quirk(
uint32_t v_v = 0;
uint32_t v_n = 0;
if (a_key == 1348001792u) {
if (a_key == 1290294272u) {
self->private_impl.f_allow_non_zero_initial_byte = (a_value > 0u);
} else if (a_key == 1348001793u) {
} else if (a_key == 1290294273u) {
if (a_value == 0u) {
self->private_impl.f_format_extension = 0u;
return wuffs_base__make_status(NULL);
@@ -56472,7 +60515,7 @@ wuffs_lzip__decoder__initialize(
wuffs_lzip__decoder*
wuffs_lzip__decoder__alloc(void) {
wuffs_lzip__decoder* x =
(wuffs_lzip__decoder*)(calloc(sizeof(wuffs_lzip__decoder), 1));
(wuffs_lzip__decoder*)(calloc(1, sizeof(wuffs_lzip__decoder)));
if (!x) {
return NULL;
}
@@ -56730,7 +60773,7 @@ wuffs_lzip__decoder__do_transform_io(
uint8_t t_1 = *iop_a_src++;
v_c8 = t_1;
}
v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001793u, (1u | (((uint64_t)(v_c8)) << 8u)));
v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294273u, (1u | (((uint64_t)(v_c8)) << 8u)));
if ( ! wuffs_base__status__is_ok(&v_status)) {
if (v_status.repr == wuffs_base__error__bad_argument) {
status = wuffs_base__make_status(wuffs_lzip__error__bad_header);
@@ -56747,7 +60790,7 @@ wuffs_lzip__decoder__do_transform_io(
}
self->private_impl.f_ssize_have = 0u;
self->private_impl.f_dsize_have = 0u;
wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001792u, 1u);
wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294272u, 1u);
while (true) {
v_dmark = ((uint64_t)(iop_a_dst - io0_a_dst));
v_smark = ((uint64_t)(iop_a_src - io0_a_src));
@@ -56934,7 +60977,7 @@ const char wuffs_lzw__error__internal_error_inconsistent_i_o[] = "#lzw: internal
// ---------------- Private Consts
#define WUFFS_LZW__QUIRKS_BASE 1348378624u
#define WUFFS_LZW__QUIRKS_BASE 1290672128u
// ---------------- Private Initializer Prototypes
@@ -57021,7 +61064,7 @@ wuffs_lzw__decoder__initialize(
wuffs_lzw__decoder*
wuffs_lzw__decoder__alloc(void) {
wuffs_lzw__decoder* x =
(wuffs_lzw__decoder*)(calloc(sizeof(wuffs_lzw__decoder), 1));
(wuffs_lzw__decoder*)(calloc(1, sizeof(wuffs_lzw__decoder)));
if (!x) {
return NULL;
}
@@ -57055,7 +61098,7 @@ wuffs_lzw__decoder__get_quirk(
return 0;
}
if (a_key == 1348378624u) {
if (a_key == 1290672128u) {
return ((uint64_t)(self->private_impl.f_pending_literal_width_plus_one));
}
return 0u;
@@ -57079,7 +61122,7 @@ wuffs_lzw__decoder__set_quirk(
: wuffs_base__error__initialize_not_called);
}
if (a_key == 1348378624u) {
if (a_key == 1290672128u) {
if (a_value > 9u) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
@@ -57637,7 +61680,7 @@ wuffs_netpbm__decoder__initialize(
wuffs_netpbm__decoder*
wuffs_netpbm__decoder__alloc(void) {
wuffs_netpbm__decoder* x =
(wuffs_netpbm__decoder*)(calloc(sizeof(wuffs_netpbm__decoder), 1));
(wuffs_netpbm__decoder*)(calloc(1, sizeof(wuffs_netpbm__decoder)));
if (!x) {
return NULL;
}
@@ -58777,7 +62820,7 @@ wuffs_nie__decoder__initialize(
wuffs_nie__decoder*
wuffs_nie__decoder__alloc(void) {
wuffs_nie__decoder* x =
(wuffs_nie__decoder*)(calloc(sizeof(wuffs_nie__decoder), 1));
(wuffs_nie__decoder*)(calloc(1, sizeof(wuffs_nie__decoder)));
if (!x) {
return NULL;
}
@@ -59715,7 +63758,7 @@ const char wuffs_zlib__error__truncated_input[] = "#zlib: truncated input";
// ---------------- Private Consts
#define WUFFS_ZLIB__QUIRKS_BASE 2113790976u
#define WUFFS_ZLIB__QUIRKS_BASE 2056083456u
#define WUFFS_ZLIB__QUIRKS_COUNT 1u
@@ -59821,7 +63864,7 @@ wuffs_zlib__decoder__initialize(
wuffs_zlib__decoder*
wuffs_zlib__decoder__alloc(void) {
wuffs_zlib__decoder* x =
(wuffs_zlib__decoder*)(calloc(sizeof(wuffs_zlib__decoder), 1));
(wuffs_zlib__decoder*)(calloc(1, sizeof(wuffs_zlib__decoder)));
if (!x) {
return NULL;
}
@@ -59900,8 +63943,8 @@ wuffs_zlib__decoder__get_quirk(
if ((a_key == 1u) && self->private_impl.f_ignore_checksum) {
return 1u;
} else if (a_key >= 2113790976u) {
v_key = (a_key - 2113790976u);
} else if (a_key >= 2056083456u) {
v_key = (a_key - 2056083456u);
if (v_key < 1u) {
if (self->private_impl.f_quirks[v_key]) {
return 1u;
@@ -59935,8 +63978,8 @@ wuffs_zlib__decoder__set_quirk(
} else if (a_key == 1u) {
self->private_impl.f_ignore_checksum = (a_value > 0u);
return wuffs_base__make_status(NULL);
} else if (a_key >= 2113790976u) {
a_key -= 2113790976u;
} else if (a_key >= 2056083456u) {
a_key -= 2056083456u;
if (a_key < 1u) {
self->private_impl.f_quirks[a_key] = (a_value > 0u);
return wuffs_base__make_status(NULL);
@@ -60789,7 +64832,7 @@ wuffs_png__decoder__initialize(
wuffs_png__decoder*
wuffs_png__decoder__alloc(void) {
wuffs_png__decoder* x =
(wuffs_png__decoder*)(calloc(sizeof(wuffs_png__decoder), 1));
(wuffs_png__decoder*)(calloc(1, sizeof(wuffs_png__decoder)));
if (!x) {
return NULL;
}
@@ -66799,6 +70842,1282 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
// ---------------- Status Codes Implementations
const char wuffs_qoi__error__bad_footer[] = "#qoi: bad footer";
const char wuffs_qoi__error__bad_header[] = "#qoi: bad header";
const char wuffs_qoi__error__truncated_input[] = "#qoi: truncated input";
// ---------------- Private Consts
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_image_config(
wuffs_qoi__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_frame_config(
wuffs_qoi__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_frame(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__from_src_to_buffer(
wuffs_qoi__decoder* self,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__from_buffer_to_dst(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_qoi__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_qoi__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_qoi__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_qoi__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_qoi__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_qoi__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_qoi__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_qoi__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_qoi__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_qoi__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_qoi__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_qoi__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_qoi__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_qoi__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_qoi__decoder__initialize(
wuffs_qoi__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (sizeof(*self) != sizeof_star_self) {
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
}
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
}
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
// The whole point of this if-check is to detect an uninitialized *self.
// We disable the warning on GCC. Clang-5.0 does not have this warning.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (self->private_impl.magic != 0) {
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
}
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_qoi__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_qoi__decoder*
wuffs_qoi__decoder__alloc(void) {
wuffs_qoi__decoder* x =
(wuffs_qoi__decoder*)(calloc(1, sizeof(wuffs_qoi__decoder)));
if (!x) {
return NULL;
}
if (wuffs_qoi__decoder__initialize(
x, sizeof(wuffs_qoi__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
return x;
}
size_t
sizeof__wuffs_qoi__decoder(void) {
return sizeof(wuffs_qoi__decoder);
}
// ---------------- Function Implementations
// -------- func qoi.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__get_quirk(
const wuffs_qoi__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func qoi.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__set_quirk(
wuffs_qoi__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func qoi.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_image_config(
wuffs_qoi__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_qoi__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_qoi__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func qoi.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_image_config(
wuffs_qoi__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_a = 0;
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0u) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
{
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_u32le__no_bounds_check(iop_a_src);
iop_a_src += 4;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 == 24) {
t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_a = t_0;
}
if (v_a != 1718185841u) {
status = wuffs_base__make_status(wuffs_qoi__error__bad_header);
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_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFFu));
*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 += 8u;
*scratch |= ((uint64_t)(num_bits_1));
}
}
v_a = t_1;
}
if (v_a > 16777215u) {
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
goto exit;
}
self->private_impl.f_width = v_a;
{
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_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFFu));
*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 += 8u;
*scratch |= ((uint64_t)(num_bits_2));
}
}
v_a = t_2;
}
if (v_a > 16777215u) {
status = wuffs_base__make_status(wuffs_base__error__unsupported_image_dimension);
goto exit;
}
self->private_impl.f_height = v_a;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint32_t t_3 = *iop_a_src++;
v_a = t_3;
}
if (v_a == 3u) {
self->private_impl.f_pixfmt = 2415954056u;
} else if (v_a == 4u) {
self->private_impl.f_pixfmt = 2164295816u;
} else {
status = wuffs_base__make_status(wuffs_qoi__error__bad_header);
goto exit;
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
iop_a_src++;
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
self->private_impl.f_pixfmt,
0u,
self->private_impl.f_width,
self->private_impl.f_height,
14u,
(self->private_impl.f_pixfmt == 2415954056u));
}
self->private_impl.f_call_sequence = 32u;
goto ok;
ok:
self->private_impl.p_do_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func qoi.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_frame_config(
wuffs_qoi__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 2)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_qoi__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_qoi__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func qoi.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_frame_config(
wuffs_qoi__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 32u) {
} else if (self->private_impl.f_call_sequence < 32u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_qoi__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 40u) {
if (14u != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
goto exit;
}
} else if (self->private_impl.f_call_sequence == 64u) {
self->private_impl.f_call_sequence = 96u;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height),
((wuffs_base__flicks)(0u)),
0u,
14u,
0u,
(self->private_impl.f_pixfmt == 2415954056u),
false,
0u);
}
self->private_impl.f_call_sequence = 64u;
ok:
self->private_impl.p_do_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func qoi.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__decode_frame(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 3)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_qoi__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_qoi__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func qoi.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__do_decode_frame(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint64_t v_c64 = 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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64u) {
} else if (self->private_impl.f_call_sequence < 64u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_qoi__decoder__do_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 {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
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(a_dst),
wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
wuffs_base__utility__empty_slice_u8(),
a_blend);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
self->private_impl.f_dst_x = 0u;
self->private_impl.f_dst_y = 0u;
self->private_data.f_pixel[0u] = 0u;
self->private_data.f_pixel[1u] = 0u;
self->private_data.f_pixel[2u] = 0u;
self->private_data.f_pixel[3u] = 255u;
wuffs_private_impl__bulk_memset(&self->private_data.f_cache[0], 256u, 0u);
self->private_impl.f_remaining_pixels_times_4 = (((uint64_t)(self->private_impl.f_width)) * ((uint64_t)(self->private_impl.f_height)) * 4u);
while (self->private_impl.f_remaining_pixels_times_4 > 0u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_qoi__decoder__from_src_to_buffer(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_remaining_pixels_times_4 < ((uint64_t)(self->private_impl.f_buffer_index))) {
status = wuffs_base__make_status(wuffs_base__error__too_much_data);
goto exit;
}
self->private_impl.f_remaining_pixels_times_4 -= ((uint64_t)(self->private_impl.f_buffer_index));
v_status = wuffs_qoi__decoder__from_buffer_to_dst(self, a_dst);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint64_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 8)) {
t_0 = wuffs_base__peek_u64be__no_bounds_check(iop_a_src);
iop_a_src += 8;
} else {
self->private_data.s_do_decode_frame.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_do_decode_frame.scratch;
uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFFu));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 56) {
t_0 = ((uint64_t)(*scratch >> 0));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0));
}
}
v_c64 = t_0;
}
if (v_c64 != 1u) {
status = wuffs_base__make_status(wuffs_qoi__error__bad_footer);
goto exit;
}
self->private_impl.f_call_sequence = 96u;
ok:
self->private_impl.p_do_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func qoi.decoder.from_src_to_buffer
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__from_src_to_buffer(
wuffs_qoi__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c8 = 0;
uint8_t v_dg = 0;
uint32_t v_bi = 0;
uint32_t v_bj = 0;
uint32_t v_bk = 0;
uint32_t v_ci = 0;
uint32_t v_hash4 = 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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_from_src_to_buffer;
if (coro_susp_point) {
v_dg = self->private_data.s_from_src_to_buffer.v_dg;
v_bi = self->private_data.s_from_src_to_buffer.v_bi;
v_bk = self->private_data.s_from_src_to_buffer.v_bk;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
v_bk = 7936u;
if (self->private_impl.f_remaining_pixels_times_4 < 7936u) {
v_bk = ((uint32_t)(self->private_impl.f_remaining_pixels_times_4));
}
while (v_bi < v_bk) {
{
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_c8 = t_0;
}
if (v_c8 == 254u) {
{
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++;
self->private_data.f_pixel[2u] = t_1;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_2 = *iop_a_src++;
self->private_data.f_pixel[1u] = t_2;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_3 = *iop_a_src++;
self->private_data.f_pixel[0u] = t_3;
}
} else if (v_c8 == 255u) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_4 = *iop_a_src++;
self->private_data.f_pixel[2u] = t_4;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_5 = *iop_a_src++;
self->private_data.f_pixel[1u] = t_5;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_6 = *iop_a_src++;
self->private_data.f_pixel[0u] = t_6;
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_7 = *iop_a_src++;
self->private_data.f_pixel[3u] = t_7;
}
} else if (((uint8_t)(v_c8 >> 6u)) == 0u) {
v_ci = (4u * ((uint32_t)(((uint8_t)(v_c8 & 63u)))));
self->private_data.f_pixel[0u] = self->private_data.f_cache[(v_ci + 0u)];
self->private_data.f_pixel[1u] = self->private_data.f_cache[(v_ci + 1u)];
self->private_data.f_pixel[2u] = self->private_data.f_cache[(v_ci + 2u)];
self->private_data.f_pixel[3u] = self->private_data.f_cache[(v_ci + 3u)];
self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u];
self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u];
self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u];
v_bi += 4u;
continue;
} else if (((uint8_t)(v_c8 >> 6u)) == 1u) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 4u)) & 3u)) + 254u));
self->private_data.f_pixel[1u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 2u)) & 3u)) + 254u));
self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(((uint8_t)(v_c8 >> 0u)) & 3u)) + 254u));
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else if (((uint8_t)(v_c8 >> 6u)) == 2u) {
v_dg = ((uint8_t)(((uint8_t)(v_c8 & 63u)) + 224u));
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_8 = *iop_a_src++;
v_c8 = t_8;
}
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
self->private_data.f_pixel[2u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 4u))))));
self->private_data.f_pixel[1u] += v_dg;
self->private_data.f_pixel[0u] += ((uint8_t)(((uint8_t)(v_dg + 248u)) + ((uint8_t)(15u & ((uint8_t)(v_c8 >> 0u))))));
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_bj = (v_bi + (4u * (63u & (1u + ((uint32_t)(v_c8))))));
while (v_bi < v_bj) {
self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u];
self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u];
self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u];
v_bi += 4u;
}
continue;
}
v_hash4 = (4u * (63u & ((((uint32_t)(self->private_data.f_pixel[2u])) * 3u) +
(((uint32_t)(self->private_data.f_pixel[1u])) * 5u) +
(((uint32_t)(self->private_data.f_pixel[0u])) * 7u) +
(((uint32_t)(self->private_data.f_pixel[3u])) * 11u))));
self->private_data.f_cache[(v_hash4 + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_cache[(v_hash4 + 1u)] = self->private_data.f_pixel[1u];
self->private_data.f_cache[(v_hash4 + 2u)] = self->private_data.f_pixel[2u];
self->private_data.f_cache[(v_hash4 + 3u)] = self->private_data.f_pixel[3u];
self->private_data.f_buffer[(v_bi + 0u)] = self->private_data.f_pixel[0u];
self->private_data.f_buffer[(v_bi + 1u)] = self->private_data.f_pixel[1u];
self->private_data.f_buffer[(v_bi + 2u)] = self->private_data.f_pixel[2u];
self->private_data.f_buffer[(v_bi + 3u)] = self->private_data.f_pixel[3u];
v_bi += 4u;
}
self->private_impl.f_buffer_index = v_bi;
goto ok;
ok:
self->private_impl.p_from_src_to_buffer = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_from_src_to_buffer = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_from_src_to_buffer.v_dg = v_dg;
self->private_data.s_from_src_to_buffer.v_bi = v_bi;
self->private_data.s_from_src_to_buffer.v_bk = v_bk;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func qoi.decoder.from_buffer_to_dst
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_qoi__decoder__from_buffer_to_dst(
wuffs_qoi__decoder* self,
wuffs_base__pixel_buffer* a_dst) {
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint32_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
wuffs_base__table_u8 v_tab = {0};
uint32_t v_bi = 0;
uint32_t v_rem_x = 0;
wuffs_base__slice_u8 v_dst = {0};
wuffs_base__slice_u8 v_src = {0};
uint32_t v_src_length = 0;
uint64_t v_i = 0;
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
if ((v_dst_bits_per_pixel & 7u) != 0u) {
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8u);
v_dst_bytes_per_row = ((uint64_t)((self->private_impl.f_width * v_dst_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u);
while (v_bi < self->private_impl.f_buffer_index) {
if (self->private_impl.f_width <= self->private_impl.f_dst_x) {
self->private_impl.f_dst_x = 0u;
self->private_impl.f_dst_y += 1u;
if (self->private_impl.f_dst_y >= self->private_impl.f_height) {
break;
}
v_rem_x = self->private_impl.f_width;
} else {
v_rem_x = (self->private_impl.f_width - self->private_impl.f_dst_x);
}
v_src = wuffs_base__make_slice_u8_ij(self->private_data.f_buffer, v_bi, self->private_impl.f_buffer_index);
if (((uint64_t)((4u * v_rem_x))) < ((uint64_t)(v_src.len))) {
v_src = wuffs_base__slice_u8__subslice_j(v_src, ((uint64_t)((4u * v_rem_x))));
}
v_src_length = ((uint32_t)(((uint64_t)(v_src.len))));
v_bi += v_src_length;
v_dst = wuffs_private_impl__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);
}
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
self->private_impl.f_dst_x += (v_src_length / 4u);
if (v_i < ((uint64_t)(v_dst.len))) {
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), wuffs_base__pixel_buffer__palette(a_dst), v_src);
}
}
return wuffs_base__make_status(NULL);
}
// -------- func qoi.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_qoi__decoder__frame_dirty_rect(
const wuffs_qoi__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_rect_ie_u32();
}
return wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
self->private_impl.f_width,
self->private_impl.f_height);
}
// -------- func qoi.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_qoi__decoder__num_animation_loops(
const wuffs_qoi__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func qoi.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__num_decoded_frame_configs(
const wuffs_qoi__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 32u) {
return 1u;
}
return 0u;
}
// -------- func qoi.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_qoi__decoder__num_decoded_frames(
const wuffs_qoi__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 64u) {
return 1u;
}
return 0u;
}
// -------- func qoi.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__restart_frame(
wuffs_qoi__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (self->private_impl.f_call_sequence < 32u) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if ((a_index != 0u) || (a_io_position != 14u)) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 40u;
return wuffs_base__make_status(NULL);
}
// -------- func qoi.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_qoi__decoder__set_report_metadata(
wuffs_qoi__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func qoi.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_qoi__decoder__tell_me_more(
wuffs_qoi__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 4)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
goto ok;
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func qoi.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_qoi__decoder__workbuf_len(
const wuffs_qoi__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_range_ii_u64();
}
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256)
// ---------------- Status Codes Implementations
@@ -66900,7 +72219,7 @@ wuffs_sha256__hasher__initialize(
wuffs_sha256__hasher*
wuffs_sha256__hasher__alloc(void) {
wuffs_sha256__hasher* x =
(wuffs_sha256__hasher*)(calloc(sizeof(wuffs_sha256__hasher), 1));
(wuffs_sha256__hasher*)(calloc(1, sizeof(wuffs_sha256__hasher)));
if (!x) {
return NULL;
}
@@ -67404,14 +72723,14 @@ wuffs_sha256__hasher__checksum_bitvec256(
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__SHA256)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
// ---------------- Status Codes Implementations
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding";
const char wuffs_tga__error__truncated_input[] = "#tga: truncated input";
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
const char wuffs_targa__error__bad_header[] = "#targa: bad header";
const char wuffs_targa__error__bad_run_length_encoding[] = "#targa: bad run length encoding";
const char wuffs_targa__error__truncated_input[] = "#targa: truncated input";
const char wuffs_targa__error__unsupported_targa_file[] = "#targa: unsupported TARGA file";
// ---------------- Private Consts
@@ -67421,22 +72740,22 @@ const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA fil
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_image_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_image_config(
wuffs_targa__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_frame_config(
wuffs_targa__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_frame(
wuffs_targa__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
@@ -67446,46 +72765,46 @@ wuffs_tga__decoder__do_decode_frame(
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder = {
wuffs_targa__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_tga__decoder__decode_frame),
wuffs_base__decode_frame_options*))(&wuffs_targa__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_frame_config),
wuffs_base__io_buffer*))(&wuffs_targa__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_tga__decoder__frame_dirty_rect),
wuffs_base__io_buffer*))(&wuffs_targa__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_targa__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_tga__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_tga__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frames),
uint32_t))(&wuffs_targa__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_targa__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_targa__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_targa__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_tga__decoder__restart_frame),
uint64_t))(&wuffs_targa__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_tga__decoder__set_quirk),
uint64_t))(&wuffs_targa__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_tga__decoder__set_report_metadata),
bool))(&wuffs_targa__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_tga__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_tga__decoder__workbuf_len),
wuffs_base__io_buffer*))(&wuffs_targa__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_targa__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_tga__decoder__initialize(
wuffs_tga__decoder* self,
wuffs_targa__decoder__initialize(
wuffs_targa__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
@@ -67526,19 +72845,19 @@ wuffs_tga__decoder__initialize(
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder);
(const void*)(&wuffs_targa__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_tga__decoder*
wuffs_tga__decoder__alloc(void) {
wuffs_tga__decoder* x =
(wuffs_tga__decoder*)(calloc(sizeof(wuffs_tga__decoder), 1));
wuffs_targa__decoder*
wuffs_targa__decoder__alloc(void) {
wuffs_targa__decoder* x =
(wuffs_targa__decoder*)(calloc(1, sizeof(wuffs_targa__decoder)));
if (!x) {
return NULL;
}
if (wuffs_tga__decoder__initialize(
x, sizeof(wuffs_tga__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
if (wuffs_targa__decoder__initialize(
x, sizeof(wuffs_targa__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
@@ -67546,18 +72865,18 @@ wuffs_tga__decoder__alloc(void) {
}
size_t
sizeof__wuffs_tga__decoder(void) {
return sizeof(wuffs_tga__decoder);
sizeof__wuffs_targa__decoder(void) {
return sizeof(wuffs_targa__decoder);
}
// ---------------- Function Implementations
// -------- func tga.decoder.get_quirk
// -------- func targa.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__get_quirk(
const wuffs_tga__decoder* self,
wuffs_targa__decoder__get_quirk(
const wuffs_targa__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
@@ -67570,12 +72889,12 @@ wuffs_tga__decoder__get_quirk(
return 0u;
}
// -------- func tga.decoder.set_quirk
// -------- func targa.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__set_quirk(
wuffs_tga__decoder* self,
wuffs_targa__decoder__set_quirk(
wuffs_targa__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
@@ -67591,12 +72910,12 @@ wuffs_tga__decoder__set_quirk(
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func tga.decoder.decode_image_config
// -------- func targa.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_image_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_image_config(
wuffs_targa__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
@@ -67628,11 +72947,11 @@ wuffs_tga__decoder__decode_image_config(
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_image_config(self, a_dst, a_src);
wuffs_base__status t_0 = wuffs_targa__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
status = wuffs_base__make_status(wuffs_targa__error__truncated_input);
goto exit;
}
status = v_status;
@@ -67657,12 +72976,12 @@ wuffs_tga__decoder__decode_image_config(
return status;
}
// -------- func tga.decoder.do_decode_image_config
// -------- func targa.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_image_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_image_config(
wuffs_targa__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
@@ -67712,7 +73031,7 @@ wuffs_tga__decoder__do_decode_image_config(
self->private_impl.f_header_color_map_type = t_1;
}
if (self->private_impl.f_header_color_map_type > 1u) {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
{
@@ -67731,7 +73050,7 @@ wuffs_tga__decoder__do_decode_image_config(
(self->private_impl.f_header_image_type == 10u) ||
(self->private_impl.f_header_image_type == 11u)) {
} else {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
{
@@ -67803,18 +73122,18 @@ wuffs_tga__decoder__do_decode_image_config(
}
if (self->private_impl.f_header_color_map_type != 0u) {
if ((self->private_impl.f_header_color_map_first_entry_index != 0u) || (self->private_impl.f_header_color_map_length > 256u)) {
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file);
goto exit;
} else if ((self->private_impl.f_header_color_map_entry_size != 15u) &&
(self->private_impl.f_header_color_map_entry_size != 16u) &&
(self->private_impl.f_header_color_map_entry_size != 24u) &&
(self->private_impl.f_header_color_map_entry_size != 32u)) {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
} else {
if ((self->private_impl.f_header_color_map_first_entry_index != 0u) || (self->private_impl.f_header_color_map_length != 0u) || (self->private_impl.f_header_color_map_entry_size != 0u)) {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
}
@@ -67900,7 +73219,7 @@ wuffs_tga__decoder__do_decode_image_config(
(self->private_impl.f_header_pixel_depth != 16u) &&
(self->private_impl.f_header_pixel_depth != 24u) &&
(self->private_impl.f_header_pixel_depth != 32u)) {
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
status = wuffs_base__make_status(wuffs_targa__error__bad_header);
goto exit;
}
if (((uint8_t)(self->private_impl.f_header_image_type | 8u)) == 9u) {
@@ -67923,7 +73242,7 @@ wuffs_tga__decoder__do_decode_image_config(
self->private_impl.f_src_bytes_per_pixel = 4u;
self->private_impl.f_src_pixfmt = 2164295816u;
} else {
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file);
goto exit;
}
} else {
@@ -67933,7 +73252,7 @@ wuffs_tga__decoder__do_decode_image_config(
self->private_impl.f_src_pixfmt = 536870920u;
self->private_impl.f_opaque = true;
} else {
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file);
goto exit;
}
}
@@ -67947,7 +73266,7 @@ wuffs_tga__decoder__do_decode_image_config(
self->private_impl.f_header_image_descriptor = t_9;
}
if (((uint8_t)(self->private_impl.f_header_image_descriptor & 16u)) != 0u) {
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
status = wuffs_base__make_status(wuffs_targa__error__unsupported_targa_file);
goto exit;
}
self->private_data.s_do_decode_image_config.scratch = ((uint32_t)(self->private_impl.f_header_id_length));
@@ -68110,12 +73429,12 @@ wuffs_tga__decoder__do_decode_image_config(
return status;
}
// -------- func tga.decoder.decode_frame_config
// -------- func targa.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_frame_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_frame_config(
wuffs_targa__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
@@ -68147,11 +73466,11 @@ wuffs_tga__decoder__decode_frame_config(
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame_config(self, a_dst, a_src);
wuffs_base__status t_0 = wuffs_targa__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
status = wuffs_base__make_status(wuffs_targa__error__truncated_input);
goto exit;
}
status = v_status;
@@ -68176,12 +73495,12 @@ wuffs_tga__decoder__decode_frame_config(
return status;
}
// -------- func tga.decoder.do_decode_frame_config
// -------- func targa.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame_config(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_frame_config(
wuffs_targa__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
@@ -68207,7 +73526,7 @@ wuffs_tga__decoder__do_decode_frame_config(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_tga__decoder__do_decode_image_config(self, NULL, a_src);
status = wuffs_targa__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -68263,12 +73582,12 @@ wuffs_tga__decoder__do_decode_frame_config(
return status;
}
// -------- func tga.decoder.decode_frame
// -------- func targa.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__decode_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__decode_frame(
wuffs_targa__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
@@ -68303,7 +73622,7 @@ wuffs_tga__decoder__decode_frame(
while (true) {
{
wuffs_base__status t_0 = wuffs_tga__decoder__do_decode_frame(self,
wuffs_base__status t_0 = wuffs_targa__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
@@ -68312,7 +73631,7 @@ wuffs_tga__decoder__decode_frame(
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_tga__error__truncated_input);
status = wuffs_base__make_status(wuffs_targa__error__truncated_input);
goto exit;
}
status = v_status;
@@ -68337,12 +73656,12 @@ wuffs_tga__decoder__decode_frame(
return status;
}
// -------- func tga.decoder.do_decode_frame
// -------- func targa.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_tga__decoder__do_decode_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__do_decode_frame(
wuffs_targa__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
@@ -68402,7 +73721,7 @@ wuffs_tga__decoder__do_decode_frame(
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_tga__decoder__do_decode_frame_config(self, NULL, a_src);
status = wuffs_targa__decoder__do_decode_frame_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -68504,7 +73823,7 @@ wuffs_tga__decoder__do_decode_frame(
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1u);
iop_a_src += 1u;
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding);
goto exit;
}
} else {
@@ -68550,7 +73869,7 @@ wuffs_tga__decoder__do_decode_frame(
iop_a_src += 1u;
}
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding);
goto exit;
}
}
@@ -68594,7 +73913,7 @@ wuffs_tga__decoder__do_decode_frame(
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1u);
iop_a_src += 1u;
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding);
goto exit;
}
} else {
@@ -68615,7 +73934,7 @@ wuffs_tga__decoder__do_decode_frame(
self->private_data.f_scratch[2u] = ((uint8_t)(((v_c5 << 3u) | (v_c5 >> 2u))));
self->private_data.f_scratch[3u] = 255u;
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
status = wuffs_base__make_status(wuffs_targa__error__bad_run_length_encoding);
goto exit;
}
}
@@ -68662,12 +73981,12 @@ wuffs_tga__decoder__do_decode_frame(
return status;
}
// -------- func tga.decoder.frame_dirty_rect
// -------- func targa.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_tga__decoder__frame_dirty_rect(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__frame_dirty_rect(
const wuffs_targa__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
@@ -68683,12 +74002,12 @@ wuffs_tga__decoder__frame_dirty_rect(
self->private_impl.f_height);
}
// -------- func tga.decoder.num_animation_loops
// -------- func targa.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_tga__decoder__num_animation_loops(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__num_animation_loops(
const wuffs_targa__decoder* self) {
if (!self) {
return 0;
}
@@ -68700,12 +74019,12 @@ wuffs_tga__decoder__num_animation_loops(
return 0u;
}
// -------- func tga.decoder.num_decoded_frame_configs
// -------- func targa.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__num_decoded_frame_configs(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__num_decoded_frame_configs(
const wuffs_targa__decoder* self) {
if (!self) {
return 0;
}
@@ -68720,12 +74039,12 @@ wuffs_tga__decoder__num_decoded_frame_configs(
return 0u;
}
// -------- func tga.decoder.num_decoded_frames
// -------- func targa.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_tga__decoder__num_decoded_frames(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__num_decoded_frames(
const wuffs_targa__decoder* self) {
if (!self) {
return 0;
}
@@ -68740,12 +74059,12 @@ wuffs_tga__decoder__num_decoded_frames(
return 0u;
}
// -------- func tga.decoder.restart_frame
// -------- func targa.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__restart_frame(
wuffs_tga__decoder* self,
wuffs_targa__decoder__restart_frame(
wuffs_targa__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
@@ -68769,23 +74088,23 @@ wuffs_tga__decoder__restart_frame(
return wuffs_base__make_status(NULL);
}
// -------- func tga.decoder.set_report_metadata
// -------- func targa.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_tga__decoder__set_report_metadata(
wuffs_tga__decoder* self,
wuffs_targa__decoder__set_report_metadata(
wuffs_targa__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func tga.decoder.tell_me_more
// -------- func targa.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_tga__decoder__tell_me_more(
wuffs_tga__decoder* self,
wuffs_targa__decoder__tell_me_more(
wuffs_targa__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
@@ -68823,12 +74142,12 @@ wuffs_tga__decoder__tell_me_more(
return status;
}
// -------- func tga.decoder.workbuf_len
// -------- func targa.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_tga__decoder__workbuf_len(
const wuffs_tga__decoder* self) {
wuffs_targa__decoder__workbuf_len(
const wuffs_targa__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
@@ -68840,7 +74159,1719 @@ wuffs_tga__decoder__workbuf_len(
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
// ---------------- Status Codes Implementations
const char wuffs_thumbhash__error__bad_header[] = "#thumbhash: bad header";
const char wuffs_thumbhash__error__truncated_input[] = "#thumbhash: truncated input";
// ---------------- Private Consts
#define WUFFS_THUMBHASH__QUIRKS_BASE 1712283648u
static const uint8_t
WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 14u, 18u, 19u, 23u, 26u, 27u, 32u,
};
static const uint8_t
WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[8] WUFFS_BASE__POTENTIALLY_UNUSED = {
0u, 0u, 14u, 32u, 51u, 74u, 100u, 127u,
};
static const uint8_t
WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[2][8] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
23u, 23u, 23u, 23u, 39u, 71u, 103u, 119u,
}, {
55u, 55u, 55u, 55u, 87u, 119u, 118u, 116u,
},
};
static const uint16_t
WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[16] WUFFS_BASE__POTENTIALLY_UNUSED = {
49152u, 51337u, 53521u, 55706u, 57890u, 60075u, 62259u, 64444u,
1092u, 3277u, 5461u, 7646u, 9830u, 12015u, 14199u, 16384u,
};
static const uint16_t
WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[16] WUFFS_BASE__POTENTIALLY_UNUSED = {
45056u, 47787u, 50517u, 53248u, 55979u, 58709u, 61440u, 64171u,
1365u, 4096u, 6827u, 9557u, 12288u, 15019u, 17749u, 20480u,
};
static const uint16_t
WUFFS_THUMBHASH__COSINES[159][6] WUFFS_BASE__POTENTIALLY_UNUSED = {
{
16281u, 15973u, 15465u, 14761u, 13873u, 12810u,
}, {
15465u, 12810u, 8717u, 3646u, 63702u, 58427u,
}, {
13873u, 7109u, 63702u, 55321u, 50071u, 49563u,
}, {
11585u, 0u, 53951u, 49152u, 53951u, 0u,
}, {
8717u, 58427u, 49255u, 55321u, 5411u, 15973u,
}, {
5411u, 52726u, 51663u, 3646u, 16281u, 7109u,
}, {
1834u, 49563u, 60125u, 14761u, 8717u, 52726u,
}, {
63702u, 49563u, 5411u, 14761u, 56819u, 52726u,
},
{
60125u, 52726u, 13873u, 3646u, 49255u, 7109u,
}, {
56819u, 58427u, 16281u, 55321u, 60125u, 15973u,
}, {
53951u, 0u, 11585u, 49152u, 11585u, 0u,
}, {
51663u, 7109u, 1834u, 55321u, 15465u, 49563u,
}, {
50071u, 12810u, 56819u, 3646u, 1834u, 58427u,
}, {
49255u, 15973u, 50071u, 14761u, 51663u, 12810u,
}, {
16322u, 16135u, 15826u, 15396u, 14849u, 14189u,
}, {
15826u, 14189u, 11585u, 8192u, 4240u, 0u,
},
{
14849u, 10531u, 4240u, 62691u, 56139u, 51347u,
}, {
13421u, 5604u, 61296u, 52985u, 49214u, 51347u,
}, {
11585u, 0u, 53951u, 49152u, 53951u, 0u,
}, {
9397u, 59932u, 49710u, 52985u, 1428u, 14189u,
}, {
6924u, 55005u, 49710u, 62691u, 13421u, 14189u,
}, {
4240u, 51347u, 53951u, 8192u, 15826u, 0u,
}, {
1428u, 49401u, 61296u, 15396u, 6924u, 51347u,
}, {
64108u, 49401u, 4240u, 15396u, 58612u, 51347u,
},
{
61296u, 51347u, 11585u, 8192u, 49710u, 0u,
}, {
58612u, 55005u, 15826u, 62691u, 52115u, 14189u,
}, {
56139u, 59932u, 15826u, 52985u, 64108u, 14189u,
}, {
53951u, 0u, 11585u, 49152u, 11585u, 0u,
}, {
52115u, 5604u, 4240u, 52985u, 16322u, 51347u,
}, {
50687u, 10531u, 61296u, 62691u, 9397u, 51347u,
}, {
49710u, 14189u, 53951u, 8192u, 61296u, 0u,
}, {
49214u, 16135u, 49710u, 15396u, 50687u, 14189u,
},
{
16328u, 16161u, 15883u, 15496u, 15004u, 14409u,
}, {
15883u, 14409u, 12054u, 8961u, 5320u, 1353u,
}, {
15004u, 11097u, 5320u, 64183u, 57738u, 52607u,
}, {
13716u, 6581u, 62839u, 54439u, 49653u, 50040u,
}, {
12054u, 1353u, 55473u, 49375u, 51820u, 61514u,
}, {
10063u, 61514u, 50532u, 51127u, 62839u, 11097u,
}, {
7798u, 56575u, 49208u, 58955u, 10063u, 16161u,
}, {
5320u, 52607u, 51820u, 4022u, 16328u, 6581u,
},
{
2697u, 50040u, 57738u, 12929u, 12054u, 56575u,
}, {
0u, 49152u, 0u, 16384u, 0u, 49152u,
}, {
62839u, 50040u, 7798u, 12929u, 53482u, 56575u,
}, {
60216u, 52607u, 13716u, 4022u, 49208u, 6581u,
}, {
57738u, 56575u, 16328u, 58955u, 55473u, 16161u,
}, {
55473u, 61514u, 15004u, 51127u, 2697u, 11097u,
}, {
53482u, 1353u, 10063u, 49375u, 13716u, 61514u,
}, {
51820u, 6581u, 2697u, 54439u, 15883u, 50040u,
},
{
50532u, 11097u, 60216u, 64183u, 7798u, 52607u,
}, {
49653u, 14409u, 53482u, 8961u, 60216u, 1353u,
}, {
49208u, 16161u, 49653u, 15496u, 50532u, 14409u,
}, {
16346u, 16231u, 16041u, 15776u, 15438u, 15028u,
}, {
16041u, 15028u, 13385u, 11183u, 8513u, 5487u,
}, {
15438u, 12709u, 8513u, 3333u, 63305u, 57998u,
}, {
14547u, 9448u, 2231u, 60049u, 53562u, 49760u,
}, {
13385u, 5487u, 61116u, 52827u, 49190u, 51537u,
},
{
11974u, 1118u, 55196u, 49305u, 52151u, 62203u,
}, {
10340u, 62203u, 50989u, 50508u, 61116u, 9448u,
}, {
8513u, 57998u, 49190u, 56088u, 6527u, 16231u,
}, {
6527u, 54353u, 50098u, 64418u, 14547u, 12709u,
}, {
4420u, 51537u, 53562u, 7538u, 16041u, 1118u,
}, {
2231u, 49760u, 59009u, 13999u, 10340u, 54353u,
}, {
0u, 49152u, 0u, 16384u, 0u, 49152u,
}, {
63305u, 49760u, 6527u, 13999u, 55196u, 54353u,
},
{
61116u, 51537u, 11974u, 7538u, 49495u, 1118u,
}, {
59009u, 54353u, 15438u, 64418u, 50989u, 12709u,
}, {
57023u, 57998u, 16346u, 56088u, 59009u, 16231u,
}, {
55196u, 62203u, 14547u, 50508u, 4420u, 9448u,
}, {
53562u, 1118u, 10340u, 49305u, 13385u, 62203u,
}, {
52151u, 5487u, 4420u, 52827u, 16346u, 51537u,
}, {
50989u, 9448u, 63305u, 60049u, 11974u, 49760u,
}, {
50098u, 12709u, 57023u, 3333u, 2231u, 57998u,
},
{
49495u, 15028u, 52151u, 11183u, 57023u, 5487u,
}, {
49190u, 16231u, 49495u, 15776u, 50098u, 15028u,
}, {
16354u, 16265u, 16116u, 15908u, 15642u, 15319u,
}, {
16116u, 15319u, 14021u, 12264u, 10104u, 7614u,
}, {
15642u, 13484u, 10104u, 5810u, 989u, 61615u,
}, {
14941u, 10865u, 4874u, 63561u, 57060u, 52052u,
}, {
14021u, 7614u, 64547u, 56229u, 50595u, 49271u,
}, {
12897u, 3921u, 58812u, 51029u, 49420u, 54671u,
},
{
11585u, 0u, 53951u, 49152u, 53951u, 0u,
}, {
10104u, 61615u, 50595u, 51029u, 62583u, 10865u,
}, {
8476u, 57922u, 49182u, 56229u, 6724u, 16265u,
}, {
6724u, 54671u, 49894u, 63561u, 14021u, 13484u,
}, {
4874u, 52052u, 52639u, 5810u, 16354u, 3921u,
}, {
2953u, 50217u, 57060u, 12264u, 12897u, 57922u,
}, {
989u, 49271u, 62583u, 15908u, 4874u, 50217u,
}, {
64547u, 49271u, 2953u, 15908u, 60662u, 50217u,
},
{
62583u, 50217u, 8476u, 12264u, 52639u, 57922u,
}, {
60662u, 52052u, 12897u, 5810u, 49182u, 3921u,
}, {
58812u, 54671u, 15642u, 63561u, 51515u, 13484u,
}, {
57060u, 57922u, 16354u, 56229u, 58812u, 16265u,
}, {
55432u, 61615u, 14941u, 51029u, 2953u, 10865u,
}, {
53951u, 0u, 11585u, 49152u, 11585u, 0u,
}, {
52639u, 3921u, 6724u, 51029u, 16116u, 54671u,
}, {
51515u, 7614u, 989u, 56229u, 14941u, 49271u,
},
{
50595u, 10865u, 60662u, 63561u, 8476u, 52052u,
}, {
49894u, 13484u, 55432u, 5810u, 64547u, 61615u,
}, {
49420u, 15319u, 51515u, 12264u, 55432u, 7614u,
}, {
49182u, 16265u, 49420u, 15908u, 49894u, 15319u,
}, {
16356u, 16273u, 16135u, 15942u, 15696u, 15396u,
}, {
16135u, 15396u, 14189u, 12551u, 10531u, 8192u,
}, {
15696u, 13689u, 10531u, 6489u, 1902u, 62691u,
}, {
15044u, 11243u, 5604u, 64583u, 58183u, 52985u,
},
{
14189u, 8192u, 0u, 57344u, 51347u, 49152u,
}, {
13142u, 4699u, 59932u, 51847u, 49180u, 52985u,
}, {
11917u, 953u, 55005u, 49263u, 52394u, 62691u,
}, {
10531u, 62691u, 51347u, 50140u, 59932u, 8192u,
}, {
9003u, 59047u, 49401u, 54293u, 3778u, 15396u,
}, {
7353u, 55752u, 49401u, 60837u, 11917u, 15396u,
}, {
5604u, 52985u, 51347u, 2845u, 16135u, 8192u,
}, {
3778u, 50895u, 55005u, 9784u, 15044u, 62691u,
},
{
1902u, 49594u, 59932u, 14641u, 9003u, 52985u,
}, {
0u, 49152u, 0u, 16384u, 0u, 49152u,
}, {
63634u, 49594u, 5604u, 14641u, 56533u, 52985u,
}, {
61758u, 50895u, 10531u, 9784u, 50492u, 62691u,
}, {
59932u, 52985u, 14189u, 2845u, 49401u, 8192u,
}, {
58183u, 55752u, 16135u, 60837u, 53619u, 15396u,
}, {
56533u, 59047u, 16135u, 54293u, 61758u, 15396u,
}, {
55005u, 62691u, 14189u, 50140u, 5604u, 8192u,
},
{
53619u, 953u, 10531u, 49263u, 13142u, 62691u,
}, {
52394u, 4699u, 5604u, 51847u, 16356u, 52985u,
}, {
51347u, 8192u, 0u, 57344u, 14189u, 49152u,
}, {
50492u, 11243u, 59932u, 64583u, 7353u, 52985u,
}, {
49840u, 13689u, 55005u, 6489u, 63634u, 62691u,
}, {
49401u, 15396u, 51347u, 12551u, 55005u, 8192u,
}, {
49180u, 16273u, 49401u, 15942u, 49840u, 15396u,
}, {
16364u, 16305u, 16207u, 16069u, 15893u, 15679u,
},
{
16207u, 15679u, 14811u, 13623u, 12140u, 10394u,
}, {
15893u, 14449u, 12140u, 9102u, 5520u, 1606u,
}, {
15426u, 12665u, 8423u, 3196u, 63132u, 57813u,
}, {
14811u, 10394u, 3981u, 62340u, 55776u, 51087u,
}, {
14053u, 7723u, 64732u, 56434u, 50725u, 49231u,
}, {
13160u, 4756u, 60016u, 51913u, 49172u, 52871u,
}, {
12140u, 1606u, 55776u, 49467u, 51483u, 60780u,
}, {
11003u, 63930u, 52376u, 49467u, 57113u, 4756u,
},
{
9760u, 60780u, 50110u, 51913u, 64732u, 12665u,
}, {
8423u, 57813u, 49172u, 56434u, 7005u, 16305u,
}, {
7005u, 55142u, 49643u, 62340u, 13160u, 14449u,
}, {
5520u, 52871u, 51483u, 3196u, 16207u, 7723u,
}, {
3981u, 51087u, 54533u, 9102u, 15426u, 63930u,
}, {
2404u, 49857u, 58531u, 13623u, 11003u, 55142u,
}, {
804u, 49231u, 63132u, 16069u, 3981u, 49857u,
}, {
64732u, 49231u, 2404u, 16069u, 61555u, 49857u,
},
{
63132u, 49857u, 7005u, 13623u, 54533u, 55142u,
}, {
61555u, 51087u, 11003u, 9102u, 50110u, 63930u,
}, {
60016u, 52871u, 14053u, 3196u, 49329u, 7723u,
}, {
58531u, 55142u, 15893u, 62340u, 52376u, 14449u,
}, {
57113u, 57813u, 16364u, 56434u, 58531u, 16305u,
}, {
55776u, 60780u, 15426u, 51913u, 804u, 12665u,
}, {
54533u, 63930u, 13160u, 49467u, 8423u, 4756u,
}, {
53396u, 1606u, 9760u, 49467u, 14053u, 60780u,
},
{
52376u, 4756u, 5520u, 51913u, 16364u, 52871u,
}, {
51483u, 7723u, 804u, 56434u, 14811u, 49231u,
}, {
50725u, 10394u, 61555u, 62340u, 9760u, 51087u,
}, {
50110u, 12665u, 57113u, 3196u, 2404u, 57813u,
}, {
49643u, 14449u, 53396u, 9102u, 60016u, 1606u,
}, {
49329u, 15679u, 50725u, 13623u, 53396u, 10394u,
}, {
49172u, 16305u, 49329u, 16069u, 49643u, 15679u,
},
};
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_src_to_coeffs(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_src);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_thumbhash__decoder__from_coeffs_to_pixels(
wuffs_thumbhash__decoder* self);
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_pixels_to_dst(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst);
// ---------------- VTables
const wuffs_base__image_decoder__func_ptrs
wuffs_thumbhash__decoder__func_ptrs_for__wuffs_base__image_decoder = {
(wuffs_base__status(*)(void*,
wuffs_base__pixel_buffer*,
wuffs_base__io_buffer*,
wuffs_base__pixel_blend,
wuffs_base__slice_u8,
wuffs_base__decode_frame_options*))(&wuffs_thumbhash__decoder__decode_frame),
(wuffs_base__status(*)(void*,
wuffs_base__frame_config*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__decode_frame_config),
(wuffs_base__status(*)(void*,
wuffs_base__image_config*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__decode_image_config),
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_thumbhash__decoder__frame_dirty_rect),
(uint64_t(*)(const void*,
uint32_t))(&wuffs_thumbhash__decoder__get_quirk),
(uint32_t(*)(const void*))(&wuffs_thumbhash__decoder__num_animation_loops),
(uint64_t(*)(const void*))(&wuffs_thumbhash__decoder__num_decoded_frame_configs),
(uint64_t(*)(const void*))(&wuffs_thumbhash__decoder__num_decoded_frames),
(wuffs_base__status(*)(void*,
uint64_t,
uint64_t))(&wuffs_thumbhash__decoder__restart_frame),
(wuffs_base__status(*)(void*,
uint32_t,
uint64_t))(&wuffs_thumbhash__decoder__set_quirk),
(wuffs_base__empty_struct(*)(void*,
uint32_t,
bool))(&wuffs_thumbhash__decoder__set_report_metadata),
(wuffs_base__status(*)(void*,
wuffs_base__io_buffer*,
wuffs_base__more_information*,
wuffs_base__io_buffer*))(&wuffs_thumbhash__decoder__tell_me_more),
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_thumbhash__decoder__workbuf_len),
};
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
wuffs_thumbhash__decoder__initialize(
wuffs_thumbhash__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version,
uint32_t options){
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (sizeof(*self) != sizeof_star_self) {
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
}
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
}
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
// The whole point of this if-check is to detect an uninitialized *self.
// We disable the warning on GCC. Clang-5.0 does not have this warning.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
if (self->private_impl.magic != 0) {
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
}
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
memset(self, 0, sizeof(*self));
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
} else {
memset(&(self->private_impl), 0, sizeof(self->private_impl));
}
}
self->private_impl.magic = WUFFS_BASE__MAGIC;
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
wuffs_base__image_decoder__vtable_name;
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
(const void*)(&wuffs_thumbhash__decoder__func_ptrs_for__wuffs_base__image_decoder);
return wuffs_base__make_status(NULL);
}
wuffs_thumbhash__decoder*
wuffs_thumbhash__decoder__alloc(void) {
wuffs_thumbhash__decoder* x =
(wuffs_thumbhash__decoder*)(calloc(1, sizeof(wuffs_thumbhash__decoder)));
if (!x) {
return NULL;
}
if (wuffs_thumbhash__decoder__initialize(
x, sizeof(wuffs_thumbhash__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
free(x);
return NULL;
}
return x;
}
size_t
sizeof__wuffs_thumbhash__decoder(void) {
return sizeof(wuffs_thumbhash__decoder);
}
// ---------------- Function Implementations
// -------- func thumbhash.decoder.get_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__get_quirk(
const wuffs_thumbhash__decoder* self,
uint32_t a_key) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if ((a_key == 1712283648u) && self->private_impl.f_quirk_just_raw_thumbhash) {
return 1u;
}
return 0u;
}
// -------- func thumbhash.decoder.set_quirk
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__set_quirk(
wuffs_thumbhash__decoder* self,
uint32_t a_key,
uint64_t a_value) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (a_key == 1712283648u) {
self->private_impl.f_quirk_just_raw_thumbhash = (a_value > 0u);
return wuffs_base__make_status(NULL);
}
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
// -------- func thumbhash.decoder.decode_image_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_image_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_image_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_image_config(
wuffs_thumbhash__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint32_t v_c32 = 0;
uint8_t v_swap = 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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_image_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence != 0u) {
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
goto exit;
}
if ( ! self->private_impl.f_quirk_just_raw_thumbhash) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
uint32_t t_0;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
t_0 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
iop_a_src += 3;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 == 16) {
t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8u;
*scratch |= ((uint64_t)(num_bits_0)) << 56;
}
}
v_c32 = t_0;
}
if (v_c32 != 16694979u) {
status = wuffs_base__make_status(wuffs_thumbhash__error__bad_header);
goto exit;
}
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
uint32_t t_1;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
t_1 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
iop_a_src += 3;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.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 == 16) {
t_1 = ((uint32_t)(*scratch));
break;
}
num_bits_1 += 8u;
*scratch |= ((uint64_t)(num_bits_1)) << 56;
}
}
v_c32 = t_1;
}
self->private_impl.f_l_dc = (((uint64_t)(((v_c32 >> 0u) & 63u))) * 136339441844224u);
self->private_impl.f_p_dc = ((uint64_t)((((uint64_t)(((v_c32 >> 6u) & 63u))) * 272678883688448u) - 8589384836186112u));
self->private_impl.f_q_dc = ((uint64_t)((((uint64_t)(((v_c32 >> 12u) & 63u))) * 272678883688448u) - 8589384836186112u));
self->private_impl.f_l_scale = ((uint8_t)(((v_c32 >> 18u) & 31u)));
self->private_impl.f_has_alpha = ((uint8_t)(((v_c32 >> 23u) & 1u)));
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
uint32_t t_2;
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
t_2 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
iop_a_src += 2;
} else {
self->private_data.s_do_decode_image_config.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_do_decode_image_config.scratch;
uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
if (num_bits_2 == 8) {
t_2 = ((uint32_t)(*scratch));
break;
}
num_bits_2 += 8u;
*scratch |= ((uint64_t)(num_bits_2)) << 56;
}
}
v_c32 = t_2;
}
self->private_impl.f_l_count = ((uint8_t)(((v_c32 >> 0u) & 7u)));
self->private_impl.f_p_scale = ((uint8_t)(((v_c32 >> 3u) & 63u)));
self->private_impl.f_q_scale = ((uint8_t)(((v_c32 >> 9u) & 63u)));
self->private_impl.f_is_landscape = ((uint8_t)(((v_c32 >> 15u) & 1u)));
self->private_impl.f_w_dimension_code = ((uint8_t)(((uint8_t)(WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[self->private_impl.f_has_alpha][self->private_impl.f_l_count] >> 4u)) & 7u));
self->private_impl.f_h_dimension_code = ((uint8_t)(((uint8_t)(WUFFS_THUMBHASH__DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[self->private_impl.f_has_alpha][self->private_impl.f_l_count] >> 0u)) & 7u));
if (self->private_impl.f_is_landscape != 0u) {
v_swap = self->private_impl.f_w_dimension_code;
self->private_impl.f_w_dimension_code = self->private_impl.f_h_dimension_code;
self->private_impl.f_h_dimension_code = v_swap;
}
if (self->private_impl.f_is_landscape != 0u) {
self->private_impl.f_lx = ((uint32_t)(((uint8_t)(7u - ((uint8_t)(2u * self->private_impl.f_has_alpha))))));
self->private_impl.f_ly = ((uint32_t)(wuffs_base__u8__max(self->private_impl.f_l_count, 3u)));
} else {
self->private_impl.f_lx = ((uint32_t)(wuffs_base__u8__max(self->private_impl.f_l_count, 3u)));
self->private_impl.f_ly = ((uint32_t)(((uint8_t)(7u - ((uint8_t)(2u * self->private_impl.f_has_alpha))))));
}
self->private_impl.f_frame_config_io_position = 8u;
if (self->private_impl.f_has_alpha != 0u) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint32_t t_3 = *iop_a_src++;
v_c32 = t_3;
}
self->private_impl.f_a_dc = (((uint64_t)(((v_c32 >> 0u) & 15u))) << 42u);
self->private_impl.f_a_scale = ((uint8_t)(((v_c32 >> 4u) & 15u)));
self->private_impl.f_frame_config_io_position = 9u;
}
if (self->private_impl.f_quirk_just_raw_thumbhash) {
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
self->private_impl.f_frame_config_io_position -= 3u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
}
self->private_impl.f_pixfmt = 2415954056u;
if (self->private_impl.f_has_alpha != 0u) {
self->private_impl.f_pixfmt = 2164295816u;
}
if (a_dst != NULL) {
wuffs_base__image_config__set(
a_dst,
self->private_impl.f_pixfmt,
0u,
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])),
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code])),
((uint64_t)(self->private_impl.f_frame_config_io_position)),
(self->private_impl.f_has_alpha == 0u));
}
self->private_impl.f_call_sequence = 32u;
goto ok;
ok:
self->private_impl.p_do_decode_image_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_image_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func thumbhash.decoder.decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 2)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_frame_config(self, a_dst, a_src);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_frame_config
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame_config(
wuffs_thumbhash__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
const uint8_t* iop_a_src = NULL;
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_config;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 32u) {
} else if (self->private_impl.f_call_sequence < 32u) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_thumbhash__decoder__do_decode_image_config(self, NULL, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
} else if (self->private_impl.f_call_sequence == 40u) {
if (((uint64_t)(self->private_impl.f_frame_config_io_position)) != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
goto exit;
}
} else if (self->private_impl.f_call_sequence == 64u) {
self->private_impl.f_call_sequence = 96u;
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
if (a_dst != NULL) {
wuffs_base__frame_config__set(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])),
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code]))),
((wuffs_base__flicks)(0u)),
0u,
((uint64_t)(self->private_impl.f_frame_config_io_position)),
0u,
(self->private_impl.f_has_alpha == 0u),
false,
0u);
}
self->private_impl.f_call_sequence = 64u;
ok:
self->private_impl.p_do_decode_frame_config = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame_config = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func thumbhash.decoder.decode_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 3)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while (true) {
{
wuffs_base__status t_0 = wuffs_thumbhash__decoder__do_decode_frame(self,
a_dst,
a_src,
a_blend,
a_workbuf,
a_opts);
v_status = t_0;
}
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
status = wuffs_base__make_status(wuffs_thumbhash__error__truncated_input);
goto exit;
}
status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
}
ok:
self->private_impl.p_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.do_decode_frame
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__do_decode_frame(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_buffer* a_src,
wuffs_base__pixel_blend a_blend,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts) {
wuffs_base__status status = wuffs_base__make_status(NULL);
wuffs_base__status v_status = wuffs_base__make_status(NULL);
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame;
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
if (self->private_impl.f_call_sequence == 64u) {
} else if (self->private_impl.f_call_sequence < 64u) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_thumbhash__decoder__do_decode_frame_config(self, NULL, a_src);
if (status.repr) {
goto suspend;
}
} else {
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
goto ok;
}
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(a_dst),
wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
wuffs_base__utility__empty_slice_u8(),
a_blend);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_thumbhash__decoder__from_src_to_coeffs(self, a_src);
if (status.repr) {
goto suspend;
}
wuffs_thumbhash__decoder__from_coeffs_to_pixels(self);
v_status = wuffs_thumbhash__decoder__from_pixels_to_dst(self, a_dst);
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = v_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;
}
self->private_impl.f_call_sequence = 96u;
ok:
self->private_impl.p_do_decode_frame = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_do_decode_frame = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
goto exit;
exit:
return status;
}
// -------- func thumbhash.decoder.from_src_to_coeffs
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_src_to_coeffs(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
uint8_t v_c8 = 0;
uint32_t v_cy = 0;
uint32_t v_cx = 0;
uint32_t v_i = 0;
bool v_has_bits = false;
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 && a_src->data.ptr) {
io0_a_src = a_src->data.ptr;
io1_a_src = io0_a_src + a_src->meta.ri;
iop_a_src = io1_a_src;
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_from_src_to_coeffs;
if (coro_susp_point) {
v_cy = self->private_data.s_from_src_to_coeffs.v_cy;
v_cx = self->private_data.s_from_src_to_coeffs.v_cx;
v_i = self->private_data.s_from_src_to_coeffs.v_i;
v_has_bits = self->private_data.s_from_src_to_coeffs.v_has_bits;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
v_i = 0u;
v_cy = 0u;
while (v_cy < self->private_impl.f_ly) {
v_cx = 0u;
if (v_cy == 0u) {
v_cx = 1u;
}
while (((uint32_t)(v_cx * self->private_impl.f_ly)) < ((uint32_t)(self->private_impl.f_lx * ((uint32_t)(self->private_impl.f_ly - v_cy))))) {
if (v_has_bits) {
v_has_bits = false;
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
v_c8 >>= 4u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_has_bits = true;
{
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_c8 = t_0;
}
}
self->private_data.f_lac[(v_i & 31u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_l_scale)) * 126u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[((uint8_t)(v_c8 & 15u))])));
v_i += 1u;
v_cx += 1u;
}
v_cy += 1u;
}
v_i = 0u;
v_cx = 0u;
while (v_cx < 5u) {
if (v_has_bits) {
v_has_bits = false;
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
v_c8 >>= 4u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_has_bits = true;
{
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_c8 = t_1;
}
}
self->private_data.f_pac[(v_i & 7u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_p_scale)) * 62u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[((uint8_t)(v_c8 & 15u))])));
v_i += 1u;
v_cx += 1u;
}
v_i = 0u;
v_cx = 0u;
while (v_cx < 5u) {
if (v_has_bits) {
v_has_bits = false;
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
v_c8 >>= 4u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_has_bits = true;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_2 = *iop_a_src++;
v_c8 = t_2;
}
}
self->private_data.f_qac[(v_i & 7u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_q_scale)) * 62u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_25[((uint8_t)(v_c8 & 15u))])));
v_i += 1u;
v_cx += 1u;
}
if (self->private_impl.f_has_alpha == 0u) {
status = wuffs_base__make_status(NULL);
goto ok;
}
v_i = 0u;
v_cx = 0u;
while (v_cx < 14u) {
if (v_has_bits) {
v_has_bits = false;
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
v_c8 >>= 4u;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else {
v_has_bits = true;
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
goto suspend;
}
uint8_t t_3 = *iop_a_src++;
v_c8 = t_3;
}
}
self->private_data.f_aac[(v_i & 15u)] = ((uint32_t)(((uint32_t)(((uint32_t)(self->private_impl.f_a_scale)) * 2u)) * wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__FROM_4_BITS_TO_PLUS_MINUS_1_00[((uint8_t)(v_c8 & 15u))])));
v_i += 1u;
v_cx += 1u;
}
ok:
self->private_impl.p_from_src_to_coeffs = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_from_src_to_coeffs = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_from_src_to_coeffs.v_cy = v_cy;
self->private_data.s_from_src_to_coeffs.v_cx = v_cx;
self->private_data.s_from_src_to_coeffs.v_i = v_i;
self->private_data.s_from_src_to_coeffs.v_has_bits = v_has_bits;
goto exit;
exit:
if (a_src && a_src->data.ptr) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
return status;
}
// -------- func thumbhash.decoder.from_coeffs_to_pixels
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__empty_struct
wuffs_thumbhash__decoder__from_coeffs_to_pixels(
wuffs_thumbhash__decoder* self) {
uint32_t v_h = 0;
uint32_t v_w = 0;
uint32_t v_fy[8] = {0};
uint32_t v_fx[8] = {0};
uint32_t v_cosines_base_y = 0;
uint32_t v_cosines_base_x = 0;
uint32_t v_y = 0;
uint32_t v_x = 0;
uint32_t v_f = 0;
uint64_t v_l = 0;
uint64_t v_p = 0;
uint64_t v_q = 0;
uint64_t v_b = 0;
uint64_t v_g = 0;
uint64_t v_r = 0;
uint64_t v_a = 0;
uint32_t v_i = 0;
uint32_t v_cy = 0;
uint32_t v_cx = 0;
v_h = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code]));
v_w = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code]));
v_fy[0u] = 16384u;
v_fx[0u] = 16384u;
v_a = 255u;
v_y = 0u;
while (v_y < v_h) {
v_cosines_base_y = ((uint32_t)(WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[self->private_impl.f_h_dimension_code]));
v_fy[1u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][0u]);
v_fy[2u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][1u]);
v_fy[3u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][2u]);
v_fy[4u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][3u]);
v_fy[5u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][4u]);
v_fy[6u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_y + v_y)][5u]);
v_x = 0u;
while (v_x < v_w) {
v_cosines_base_x = ((uint32_t)(WUFFS_THUMBHASH__CUMULATIVE_DIMENSIONS[self->private_impl.f_w_dimension_code]));
v_fx[1u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][0u]);
v_fx[2u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][1u]);
v_fx[3u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][2u]);
v_fx[4u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][3u]);
v_fx[5u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][4u]);
v_fx[6u] = wuffs_base__utility__sign_extend_convert_u16_u32(WUFFS_THUMBHASH__COSINES[(v_cosines_base_x + v_x)][5u]);
v_l = self->private_impl.f_l_dc;
v_i = 0u;
v_cy = 0u;
while (v_cy < self->private_impl.f_ly) {
v_cx = 0u;
if (v_cy == 0u) {
v_cx = 1u;
}
while (((uint32_t)(v_cx * self->private_impl.f_ly)) < ((uint32_t)(self->private_impl.f_lx * ((uint32_t)(self->private_impl.f_ly - v_cy))))) {
v_f = ((uint32_t)(v_fx[(v_cx & 7u)] * v_fy[(v_cy & 7u)]));
v_l += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_lac[(v_i & 31u)])));
v_i += 1u;
v_cx += 1u;
}
v_cy += 1u;
}
v_p = self->private_impl.f_p_dc;
v_q = self->private_impl.f_q_dc;
v_i = 0u;
v_cy = 0u;
while (v_cy < 3u) {
v_cx = 0u;
if (v_cy == 0u) {
v_cx = 1u;
}
while (v_cx < (3u - v_cy)) {
v_f = ((uint32_t)(v_fx[v_cx] * v_fy[v_cy]));
v_p += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_pac[(v_i & 7u)])));
v_q += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_qac[(v_i & 7u)])));
v_i += 1u;
v_cx += 1u;
}
v_cy += 1u;
}
v_b = ((uint64_t)(v_l - wuffs_base__utility__i64_divide(((uint64_t)(2u * v_p)), 3u)));
v_r = wuffs_base__utility__sign_extend_rshift_u64(((uint64_t)(((uint64_t)(((uint64_t)(3u * v_l)) + v_q)) - v_b)), 1u);
v_g = ((uint64_t)(v_r - v_q));
if ((v_b >> 63u) != 0u) {
v_b = 0u;
} else if (v_b >= 8589384836185950u) {
v_b = 255u;
} else {
v_b /= 33683862102690u;
}
if ((v_g >> 63u) != 0u) {
v_g = 0u;
} else if (v_g >= 8589384836185950u) {
v_g = 255u;
} else {
v_g /= 33683862102690u;
}
if ((v_r >> 63u) != 0u) {
v_r = 0u;
} else if (v_r >= 8589384836185950u) {
v_r = 255u;
} else {
v_r /= 33683862102690u;
}
if (self->private_impl.f_has_alpha != 0u) {
v_a = self->private_impl.f_a_dc;
v_i = 0u;
v_cy = 0u;
while (v_cy < 5u) {
v_cx = 0u;
if (v_cy == 0u) {
v_cx = 1u;
}
while (v_cx < (5u - v_cy)) {
v_f = ((uint32_t)(v_fx[v_cx] * v_fy[v_cy]));
v_a += ((uint64_t)(wuffs_base__utility__sign_extend_convert_u32_u64(v_f) * wuffs_base__utility__sign_extend_convert_u32_u64(self->private_data.f_aac[(v_i & 15u)])));
v_i += 1u;
v_cx += 1u;
}
v_cy += 1u;
}
if ((v_a >> 63u) != 0u) {
v_a = 0u;
} else if (v_a >= 65970697666500u) {
v_a = 255u;
} else {
v_a /= 258708618300u;
}
}
self->private_data.f_pixels[v_y][((4u * v_x) + 0u)] = ((uint8_t)(v_b));
self->private_data.f_pixels[v_y][((4u * v_x) + 1u)] = ((uint8_t)(v_g));
self->private_data.f_pixels[v_y][((4u * v_x) + 2u)] = ((uint8_t)(v_r));
self->private_data.f_pixels[v_y][((4u * v_x) + 3u)] = ((uint8_t)(v_a));
v_x += 1u;
}
v_y += 1u;
}
return wuffs_base__make_empty_struct();
}
// -------- func thumbhash.decoder.from_pixels_to_dst
WUFFS_BASE__GENERATED_C_CODE
static wuffs_base__status
wuffs_thumbhash__decoder__from_pixels_to_dst(
wuffs_thumbhash__decoder* self,
wuffs_base__pixel_buffer* a_dst) {
uint32_t v_h = 0;
uint32_t v_w = 0;
wuffs_base__pixel_format v_dst_pixfmt = {0};
uint32_t v_dst_bits_per_pixel = 0;
uint32_t v_dst_bytes_per_pixel = 0;
uint64_t v_dst_bytes_per_row = 0;
wuffs_base__table_u8 v_tab = {0};
uint32_t v_y = 0;
wuffs_base__slice_u8 v_dst = {0};
wuffs_base__slice_u8 v_src = {0};
v_h = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code]));
v_w = ((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code]));
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
if ((v_dst_bits_per_pixel & 7u) != 0u) {
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_dst_bytes_per_pixel = (v_dst_bits_per_pixel / 8u);
v_dst_bytes_per_row = ((uint64_t)((v_w * v_dst_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0u);
while (v_y < v_h) {
v_src = wuffs_base__make_slice_u8(self->private_data.f_pixels[v_y], (v_w * 4u));
v_dst = wuffs_private_impl__table_u8__row_u32(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);
}
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, wuffs_base__pixel_buffer__palette(a_dst), v_src);
v_y += 1u;
}
return wuffs_base__make_status(NULL);
}
// -------- func thumbhash.decoder.frame_dirty_rect
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
wuffs_thumbhash__decoder__frame_dirty_rect(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_rect_ie_u32();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_rect_ie_u32();
}
return wuffs_base__utility__make_rect_ie_u32(
0u,
0u,
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_w_dimension_code])),
((uint32_t)(WUFFS_THUMBHASH__DIMENSIONS_FROM_DIMENSION_CODES[self->private_impl.f_h_dimension_code])));
}
// -------- func thumbhash.decoder.num_animation_loops
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint32_t
wuffs_thumbhash__decoder__num_animation_loops(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
return 0u;
}
// -------- func thumbhash.decoder.num_decoded_frame_configs
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frame_configs(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 32u) {
return 1u;
}
return 0u;
}
// -------- func thumbhash.decoder.num_decoded_frames
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC uint64_t
wuffs_thumbhash__decoder__num_decoded_frames(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return 0;
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
if (self->private_impl.f_call_sequence > 64u) {
return 1u;
}
return 0u;
}
// -------- func thumbhash.decoder.restart_frame
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__restart_frame(
wuffs_thumbhash__decoder* self,
uint64_t a_index,
uint64_t a_io_position) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (self->private_impl.f_call_sequence < 32u) {
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
}
if ((a_index != 0u) || (a_io_position != ((uint64_t)(self->private_impl.f_frame_config_io_position)))) {
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
self->private_impl.f_call_sequence = 40u;
return wuffs_base__make_status(NULL);
}
// -------- func thumbhash.decoder.set_report_metadata
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
wuffs_thumbhash__decoder__set_report_metadata(
wuffs_thumbhash__decoder* self,
uint32_t a_fourcc,
bool a_report) {
return wuffs_base__make_empty_struct();
}
// -------- func thumbhash.decoder.tell_me_more
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
wuffs_thumbhash__decoder__tell_me_more(
wuffs_thumbhash__decoder* self,
wuffs_base__io_buffer* a_dst,
wuffs_base__more_information* a_minfo,
wuffs_base__io_buffer* a_src) {
if (!self) {
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return wuffs_base__make_status(
(self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
: wuffs_base__error__initialize_not_called);
}
if (!a_dst || !a_src) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__bad_argument);
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 4)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
}
self->private_impl.active_coroutine = 0;
wuffs_base__status status = wuffs_base__make_status(NULL);
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
goto exit;
goto ok;
ok:
goto exit;
exit:
if (wuffs_base__status__is_error(&status)) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
}
return status;
}
// -------- func thumbhash.decoder.workbuf_len
WUFFS_BASE__GENERATED_C_CODE
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
wuffs_thumbhash__decoder__workbuf_len(
const wuffs_thumbhash__decoder* self) {
if (!self) {
return wuffs_base__utility__empty_range_ii_u64();
}
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return wuffs_base__utility__empty_range_ii_u64();
}
return wuffs_base__utility__make_range_ii_u64(0u, 0u);
}
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__VP8)
@@ -68902,7 +75933,7 @@ wuffs_vp8__placeholder__initialize(
wuffs_vp8__placeholder*
wuffs_vp8__placeholder__alloc(void) {
wuffs_vp8__placeholder* x =
(wuffs_vp8__placeholder*)(calloc(sizeof(wuffs_vp8__placeholder), 1));
(wuffs_vp8__placeholder*)(calloc(1, sizeof(wuffs_vp8__placeholder)));
if (!x) {
return NULL;
}
@@ -69050,7 +76081,7 @@ wuffs_wbmp__decoder__initialize(
wuffs_wbmp__decoder*
wuffs_wbmp__decoder__alloc(void) {
wuffs_wbmp__decoder* x =
(wuffs_wbmp__decoder*)(calloc(sizeof(wuffs_wbmp__decoder), 1));
(wuffs_wbmp__decoder*)(calloc(1, sizeof(wuffs_wbmp__decoder)));
if (!x) {
return NULL;
}
@@ -70185,7 +77216,7 @@ wuffs_webp__decoder__initialize(
wuffs_webp__decoder*
wuffs_webp__decoder__alloc(void) {
wuffs_webp__decoder* x =
(wuffs_webp__decoder*)(calloc(sizeof(wuffs_webp__decoder), 1));
(wuffs_webp__decoder*)(calloc(1, sizeof(wuffs_webp__decoder)));
if (!x) {
return NULL;
}
@@ -73920,7 +80951,7 @@ wuffs_xxhash32__hasher__initialize(
wuffs_xxhash32__hasher*
wuffs_xxhash32__hasher__alloc(void) {
wuffs_xxhash32__hasher* x =
(wuffs_xxhash32__hasher*)(calloc(sizeof(wuffs_xxhash32__hasher), 1));
(wuffs_xxhash32__hasher*)(calloc(1, sizeof(wuffs_xxhash32__hasher)));
if (!x) {
return NULL;
}
@@ -74333,7 +81364,7 @@ wuffs_xxhash64__hasher__initialize(
wuffs_xxhash64__hasher*
wuffs_xxhash64__hasher__alloc(void) {
wuffs_xxhash64__hasher* x =
(wuffs_xxhash64__hasher*)(calloc(sizeof(wuffs_xxhash64__hasher), 1));
(wuffs_xxhash64__hasher*)(calloc(1, sizeof(wuffs_xxhash64__hasher)));
if (!x) {
return NULL;
}
@@ -74761,7 +81792,7 @@ WUFFS_XZ__FILTER_06_IA64_BRANCH_TABLE[32] WUFFS_BASE__POTENTIALLY_UNUSED = {
4u, 4u, 0u, 0u, 4u, 4u, 0u, 0u,
};
#define WUFFS_XZ__QUIRKS_BASE 2021322752u
#define WUFFS_XZ__QUIRKS_BASE 1963655168u
static const uint8_t
WUFFS_XZ__CHECKSUM_LENGTH[4] WUFFS_BASE__POTENTIALLY_UNUSED = {
@@ -74974,7 +82005,7 @@ wuffs_xz__decoder__initialize(
wuffs_xz__decoder*
wuffs_xz__decoder__alloc(void) {
wuffs_xz__decoder* x =
(wuffs_xz__decoder*)(calloc(sizeof(wuffs_xz__decoder), 1));
(wuffs_xz__decoder*)(calloc(1, sizeof(wuffs_xz__decoder)));
if (!x) {
return NULL;
}
@@ -75505,7 +82536,7 @@ wuffs_xz__decoder__get_quirk(
if (self->private_impl.f_ignore_checksum) {
return 1u;
}
} else if (a_key == 2021322752u) {
} else if (a_key == 1963655168u) {
if (self->private_impl.f_standalone_format) {
return 1u;
}
@@ -75534,7 +82565,7 @@ wuffs_xz__decoder__set_quirk(
if (a_key == 1u) {
self->private_impl.f_ignore_checksum = (a_value > 0u);
return wuffs_base__make_status(NULL);
} else if (a_key == 2021322752u) {
} else if (a_key == 1963655168u) {
self->private_impl.f_standalone_format = (a_value > 0u);
return wuffs_base__make_status(NULL);
}
@@ -76858,7 +83889,7 @@ wuffs_xz__decoder__decode_block_header_sans_padding(
uint8_t t_10 = *iop_a_src++;
v_c8 = t_10;
}
v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1348001793u, (2u | (((uint64_t)(v_c8)) << 8u)));
v_status = wuffs_lzma__decoder__set_quirk(&self->private_data.f_lzma, 1290294273u, (2u | (((uint64_t)(v_c8)) << 8u)));
if ( ! wuffs_base__status__is_ok(&v_status)) {
status = wuffs_base__make_status(wuffs_xz__error__bad_filter);
goto exit;
@@ -77923,6 +84954,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
return wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
case WUFFS_BASE__FOURCC__ETC2:
return wuffs_etc2__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
case WUFFS_BASE__FOURCC__GIF:
return wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
@@ -77952,9 +84988,19 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
}
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
case WUFFS_BASE__FOURCC__QOI:
return wuffs_qoi__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
case WUFFS_BASE__FOURCC__TGA:
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
return wuffs_targa__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
case WUFFS_BASE__FOURCC__TH:
return wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
@@ -77996,7 +85042,7 @@ DecodeImageCallbacks::AllocPixbuf(const wuffs_base__image_config& image_config,
return AllocPixbufResult(DecodeImage_UnsupportedPixelConfiguration);
}
void* ptr =
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
if (!ptr) {
return AllocPixbufResult(DecodeImage_OutOfMemory);
}
@@ -78021,7 +85067,7 @@ DecodeImageCallbacks::AllocWorkbuf(wuffs_base__range_ii_u64 len_range,
return AllocWorkbufResult(DecodeImage_OutOfMemory);
}
void* ptr =
allow_uninitialized_memory ? malloc((size_t)len) : calloc((size_t)len, 1);
allow_uninitialized_memory ? malloc((size_t)len) : calloc(1, (size_t)len);
if (!ptr) {
return AllocWorkbufResult(DecodeImage_OutOfMemory);
}
@@ -78321,6 +85367,7 @@ redirect:
wuffs_base__pixel_format pixel_format = callbacks.SelectPixfmt(image_config);
if (pixel_format.repr != image_config.pixcfg.pixel_format().repr) {
switch (pixel_format.repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
case WUFFS_BASE__PIXEL_FORMAT__BGR:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
@@ -79074,6 +86121,537 @@ done:
#endif // defined(__cplusplus) && defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
// ---------------- Wuffs' reimplementation of the STB API.
//
// This is a drop-in replacement of that third-party library.
//
// Disabled by default, unless you #define the
// WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB macro beforehand.
//
// For API docs, see https://github.com/nothings/stb
#if defined(WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
#include <limits.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
// --------
#if defined(__GNUC__)
__thread const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#elif defined(_MSC_VER)
__declspec(thread) const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#else
const char* //
wuffs_drop_in__stb__g_failure_reason = NULL;
#endif
// --------
static void //
wuffs_drop_in__stb__read( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user) {
uint8_t* ptr = wuffs_base__io_buffer__writer_pointer(srcbuf);
size_t len = wuffs_base__io_buffer__writer_length(srcbuf);
if (len > INT_MAX) {
len = INT_MAX;
}
int n = clbk->read(user, (char*)ptr, (int)len);
if (n > 0) {
srcbuf->meta.wi += (size_t)n;
} else {
srcbuf->meta.closed = clbk->eof(user);
}
}
static wuffs_base__image_decoder* //
wuffs_drop_in__stb__make_decoder( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user) {
while (1) {
int32_t fourcc = wuffs_base__magic_number_guess_fourcc(
wuffs_base__io_buffer__reader_slice(srcbuf), srcbuf->meta.closed);
if (fourcc < 0) {
if (srcbuf->meta.closed || !clbk) {
break;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
continue;
}
switch (fourcc) {
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
case WUFFS_BASE__FOURCC__BMP:
return wuffs_bmp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ETC2)
case WUFFS_BASE__FOURCC__ETC2:
return wuffs_etc2__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
case WUFFS_BASE__FOURCC__GIF:
return wuffs_gif__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__JPEG)
case WUFFS_BASE__FOURCC__JPEG:
return wuffs_jpeg__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NIE)
case WUFFS_BASE__FOURCC__NIE:
return wuffs_nie__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__NETPBM)
case WUFFS_BASE__FOURCC__NPBM:
return wuffs_netpbm__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
case WUFFS_BASE__FOURCC__PNG:
return wuffs_png__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__QOI)
case WUFFS_BASE__FOURCC__QOI:
return wuffs_qoi__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TARGA)
case WUFFS_BASE__FOURCC__TGA:
return wuffs_targa__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__THUMBHASH)
case WUFFS_BASE__FOURCC__TH:
return wuffs_thumbhash__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
case WUFFS_BASE__FOURCC__WBMP:
return wuffs_wbmp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WEBP)
case WUFFS_BASE__FOURCC__WEBP:
return wuffs_webp__decoder__alloc_as__wuffs_base__image_decoder();
#endif
}
wuffs_drop_in__stb__g_failure_reason = "unknown image type";
break;
}
return NULL;
}
// --------
static void* //
wuffs_drop_in__stb__load1( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user, //
wuffs_base__image_decoder* dec, //
wuffs_base__image_config* ic, //
uint32_t dst_pixfmt, //
int desired_channels, //
int info_only) {
// Favor faster decodes over rejecting invalid checksums.
wuffs_base__image_decoder__set_quirk(dec, WUFFS_BASE__QUIRK_IGNORE_CHECKSUM,
1);
while (1) {
wuffs_base__status status =
wuffs_base__image_decoder__decode_image_config(dec, ic, srcbuf);
if (status.repr == NULL) {
break;
} else if ((status.repr != wuffs_base__suspension__short_read) || !clbk) {
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
size_t wl = wuffs_base__io_buffer__writer_length(srcbuf);
wuffs_base__io_buffer__compact(srcbuf);
if (wl >= wuffs_base__io_buffer__writer_length(srcbuf)) {
wuffs_drop_in__stb__g_failure_reason = "I/O buffer is too small";
return NULL;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
}
uint32_t w = wuffs_base__pixel_config__width(&ic->pixcfg);
uint32_t h = wuffs_base__pixel_config__height(&ic->pixcfg);
if ((w > 0xFFFFFF) || (h > 0xFFFFFF)) {
wuffs_drop_in__stb__g_failure_reason = "image is too large";
return NULL;
} else if (info_only) {
return NULL;
}
uint64_t pixbuf_len = (uint64_t)w * (uint64_t)h * (uint64_t)desired_channels;
uint64_t workbuf_len = wuffs_base__image_decoder__workbuf_len(dec).max_incl;
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
if ((pixbuf_len > ((uint64_t)SIZE_MAX)) ||
(workbuf_len > ((uint64_t)SIZE_MAX))) {
wuffs_drop_in__stb__g_failure_reason = "image is too large";
return NULL;
}
#endif
void* pixbuf_ptr = malloc((size_t)pixbuf_len);
if (!pixbuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
void* workbuf_ptr = malloc((size_t)workbuf_len);
if (!workbuf_ptr) {
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__slice_u8 workbuf =
wuffs_base__make_slice_u8(workbuf_ptr, (size_t)workbuf_len);
wuffs_base__pixel_config pc = ((wuffs_base__pixel_config){});
wuffs_base__pixel_config__set(&pc, dst_pixfmt,
WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, w, h);
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
{
wuffs_base__status status = wuffs_base__pixel_buffer__set_from_slice(
&pb, &pc, wuffs_base__make_slice_u8(pixbuf_ptr, (size_t)pixbuf_len));
if (status.repr) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
}
while (1) {
wuffs_base__status status = wuffs_base__image_decoder__decode_frame(
dec, &pb, srcbuf, WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL);
if (status.repr == NULL) {
break;
} else if ((status.repr != wuffs_base__suspension__short_read) || !clbk) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = status.repr;
return NULL;
}
size_t wl = wuffs_base__io_buffer__writer_length(srcbuf);
wuffs_base__io_buffer__compact(srcbuf);
if (wl >= wuffs_base__io_buffer__writer_length(srcbuf)) {
free(workbuf_ptr);
free(pixbuf_ptr);
wuffs_drop_in__stb__g_failure_reason = "I/O buffer is too small";
return NULL;
}
wuffs_drop_in__stb__read(srcbuf, clbk, user);
}
free(workbuf_ptr);
return pixbuf_ptr;
}
static void* //
wuffs_drop_in__stb__load0( //
wuffs_base__io_buffer* srcbuf, //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels, //
int info_only) {
uint32_t dst_pixfmt = 0;
switch (desired_channels) {
case 1:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__Y;
break;
case 3:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGB;
break;
case 4:
dst_pixfmt = WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL;
break;
default:
wuffs_drop_in__stb__g_failure_reason = "unsupported format conversion";
return NULL;
}
wuffs_base__image_decoder* dec =
wuffs_drop_in__stb__make_decoder(srcbuf, clbk, user);
if (!dec) {
if (wuffs_drop_in__stb__g_failure_reason == NULL) {
wuffs_drop_in__stb__g_failure_reason = "couldn't allocate image decoder";
}
return NULL;
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
stbi_uc* ret = wuffs_drop_in__stb__load1(
srcbuf, clbk, user, dec, &ic, dst_pixfmt, desired_channels, info_only);
free(dec);
if (!info_only && !ret) {
return NULL;
}
if (x) {
*x = (int)wuffs_base__pixel_config__width(&ic.pixcfg);
}
if (y) {
*y = (int)wuffs_base__pixel_config__height(&ic.pixcfg);
}
if (channels_in_file) {
wuffs_base__pixel_format src_pixfmt =
wuffs_base__pixel_config__pixel_format(&ic.pixcfg);
uint32_t n_color = wuffs_base__pixel_format__coloration(&src_pixfmt);
uint32_t n_alpha = wuffs_base__pixel_format__transparency(&src_pixfmt) !=
WUFFS_BASE__PIXEL_ALPHA_TRANSPARENCY__OPAQUE;
*channels_in_file = (int)(n_color + n_alpha);
}
return ret;
}
// --------
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
if (len < 0) {
wuffs_drop_in__stb__g_failure_reason = "negative buffer length";
return 0;
} else if (len == 0) {
wuffs_drop_in__stb__g_failure_reason = "empty buffer";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__reader((uint8_t*)(stbi_uc*)buffer, (size_t)len, true);
wuffs_drop_in__stb__load0(&srcbuf, NULL, NULL, x, y, comp, 1, 1);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_memory( //
stbi_uc const* buffer, //
int len, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
if (len < 0) {
wuffs_drop_in__stb__g_failure_reason = "negative buffer length";
return NULL;
} else if (len == 0) {
wuffs_drop_in__stb__g_failure_reason = "empty buffer";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__reader((uint8_t*)(stbi_uc*)buffer, (size_t)len, true);
return wuffs_drop_in__stb__load0(&srcbuf, NULL, NULL, x, y, channels_in_file,
desired_channels, 0);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
wuffs_drop_in__stb__load0(&srcbuf, clbk, user, x, y, comp, 1, 1);
free(iobuf_ptr);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_callbacks( //
stbi_io_callbacks const* clbk, //
void* user, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_uc* ret = wuffs_drop_in__stb__load0(
&srcbuf, clbk, user, x, y, channels_in_file, desired_channels, 0);
free(iobuf_ptr);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC void //
stbi_image_free( //
void* retval_from_stbi_load) {
wuffs_drop_in__stb__g_failure_reason = NULL;
free(retval_from_stbi_load);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC const char* //
stbi_failure_reason(void) {
return wuffs_drop_in__stb__g_failure_reason
? wuffs_drop_in__stb__g_failure_reason
: "ok";
}
// --------
#if !defined(STBI_NO_STDIO)
#include <stdio.h>
// TODO: retry after EINTR?
static int //
wuffs_drop_in__stb__file_callbacks__read( //
void* user, //
char* data, //
int size) {
return (int)fread(data, 1u, (size_t)size, (FILE*)user);
}
static void //
wuffs_drop_in__stb__file_callbacks__skip( //
void* user, //
int n) {
fseek((FILE*)user, (long)n, SEEK_CUR);
}
static int //
wuffs_drop_in__stb__file_callbacks__eof( //
void* user) {
return feof((FILE*)user);
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info( //
char const* filename, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
FILE* f = fopen(filename, "rb");
if (!f) {
wuffs_drop_in__stb__g_failure_reason = "could not open file";
return 0;
}
int ret = stbi_info_from_file(f, x, y, comp);
fclose(f);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load( //
char const* filename, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
FILE* f = fopen(filename, "rb");
if (!f) {
wuffs_drop_in__stb__g_failure_reason = "could not open file";
return NULL;
}
stbi_uc* ret =
stbi_load_from_file(f, x, y, channels_in_file, desired_channels);
fclose(f);
return ret;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC int //
stbi_info_from_file( //
FILE* f, //
int* x, //
int* y, //
int* comp) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return 0;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_io_callbacks clbk;
clbk.read = &wuffs_drop_in__stb__file_callbacks__read;
clbk.skip = &wuffs_drop_in__stb__file_callbacks__skip;
clbk.eof = &wuffs_drop_in__stb__file_callbacks__eof;
wuffs_drop_in__stb__load0(&srcbuf, &clbk, f, x, y, comp, 1, 1);
free(iobuf_ptr);
return wuffs_drop_in__stb__g_failure_reason == NULL;
}
WUFFS_DROP_IN__STB__MAYBE_STATIC stbi_uc* //
stbi_load_from_file( //
FILE* f, //
int* x, //
int* y, //
int* channels_in_file, //
int desired_channels) {
wuffs_drop_in__stb__g_failure_reason = NULL;
void* iobuf_ptr = malloc(65536u);
if (!iobuf_ptr) {
wuffs_drop_in__stb__g_failure_reason = "out of memory";
return NULL;
}
wuffs_base__io_buffer srcbuf =
wuffs_base__ptr_u8__writer((uint8_t*)iobuf_ptr, 65536u);
stbi_io_callbacks clbk;
clbk.read = &wuffs_drop_in__stb__file_callbacks__read;
clbk.skip = &wuffs_drop_in__stb__file_callbacks__skip;
clbk.eof = &wuffs_drop_in__stb__file_callbacks__eof;
stbi_uc* ret = wuffs_drop_in__stb__load0(
&srcbuf, &clbk, f, x, y, channels_in_file, desired_channels, 0);
free(iobuf_ptr);
return ret;
}
#endif // !defined(STBI_NO_STDIO)
// --------
#ifdef __cplusplus
} // extern "C"
#endif
#endif // defined (WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB)
#endif // WUFFS_IMPLEMENTATION
#if defined(__GNUC__)
+1 -1
View File
@@ -36,7 +36,7 @@ func main1() error {
args := os.Args
if len(args) > 1 {
for _, arg := range args[1:] {
arg := (strings.ToLower(arg) + " ")[:4]
arg := (strings.ToLower(arg) + "....")[:4]
if code, ok := base38.Encode(arg); ok {
code0 := fmt.Sprintf("0x%06X", code)
code1 := fmt.Sprintf("0x%08X", code<<10)
+23 -2
View File
@@ -72,10 +72,31 @@ handle() {
# Image file format specifications cover how to correctly decode complete
# input but usually do not mandate exactly how to decode truncated input.
# Print "trunc" vs "other" to distinguish these cases.
#
# A short SOS (Start Of Scan) bitstream is similar. Strictly speaking, such
# JPEG images are invalid. In practice, decoders have some discretion in how
# many implicit zero bits to produce before giving up. Giving up effectively
# truncates the input, even if we haven't reached the actual end of file.
#
# The ectn (example-convert-to-nia) program runs under a SECCOMP_MODE_STRICT
# sandbox, which prohibits dynamic memory allocation (calling malloc). Using
# only statically allocated memory, its maximum supported image size has to
# be configured at compile time, not probed at runtime. The ectn program can
# reject some perfectly valid (but large) JPEG images that the djpeg program
# is happy to process (if run on a system with plentiful RAM).
#
# These "image is too large" rejections are a property of the ectn program
# (and its sandbox), not of the Wuffs library. Wuffs' JPEG decoder can
# happily decode such images if the library caller gives it enough memory.
#
# Print "trunc" vs "sSOSb" vs "large" vs "other" to distinguish these cases.
local error=$(gen/bin/example-convert-to-nia -output-netpbm <$1 2>&1 >/dev/null)
if [[ $error =~ :\ truncated.input$ ]]; then
if [[ $error =~ ^jpeg:\ truncated\ input$ ]]; then
echo "Differ (trunc) $1"
elif [[ $error =~ ^jpeg:\ short\ SOS\ bitstream$ ]]; then
echo "Differ (sSOSb) $1"
elif [[ $error =~ ^main:\ image\ is\ too\ large ]]; then
echo "Differ (large) $1"
else
echo "Differ (other) $1"
result=1
+15 -3
View File
@@ -59,13 +59,16 @@
#define WUFFS_CONFIG__MODULE__BZIP2
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__ETC2
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__GZIP
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TARGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
@@ -110,6 +113,9 @@ handle_image_decoder(wuffs_base__io_buffer src,
case WUFFS_BASE__FOURCC__BMP:
dec = wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__ETC2:
dec = wuffs_etc2__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__GIF:
dec = wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
break;
@@ -125,8 +131,14 @@ handle_image_decoder(wuffs_base__io_buffer src,
case WUFFS_BASE__FOURCC__PNG:
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TGA:
dec = wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
case WUFFS_BASE__FOURCC__QOI:
dec = wuffs_qoi__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TARGA:
dec = wuffs_targa__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TH:
dec = wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__WBMP:
dec = wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
+4 -1
View File
@@ -52,12 +52,15 @@ to use the wuffs_aux C++ API to decode an image and iterate over its pixels.
#define WUFFS_CONFIG__MODULE__BMP
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__ETC2
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TARGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__ZLIB
+15 -3
View File
@@ -48,12 +48,15 @@ print-image-metadata prints images' metadata.
#define WUFFS_CONFIG__MODULE__BMP
#define WUFFS_CONFIG__MODULE__CRC32
#define WUFFS_CONFIG__MODULE__DEFLATE
#define WUFFS_CONFIG__MODULE__ETC2
#define WUFFS_CONFIG__MODULE__GIF
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__NETPBM
#define WUFFS_CONFIG__MODULE__NIE
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__QOI
#define WUFFS_CONFIG__MODULE__TARGA
#define WUFFS_CONFIG__MODULE__THUMBHASH
#define WUFFS_CONFIG__MODULE__VP8
#define WUFFS_CONFIG__MODULE__WBMP
#define WUFFS_CONFIG__MODULE__WEBP
@@ -372,6 +375,9 @@ redirect:
case WUFFS_BASE__FOURCC__BMP:
dec = wuffs_bmp__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__ETC2:
dec = wuffs_etc2__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__GIF:
dec = wuffs_gif__decoder::alloc_as__wuffs_base__image_decoder();
break;
@@ -387,8 +393,14 @@ redirect:
case WUFFS_BASE__FOURCC__PNG:
dec = wuffs_png__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TGA:
dec = wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
case WUFFS_BASE__FOURCC__QOI:
dec = wuffs_qoi__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TARGA:
dec = wuffs_targa__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__TH:
dec = wuffs_thumbhash__decoder::alloc_as__wuffs_base__image_decoder();
break;
case WUFFS_BASE__FOURCC__WBMP:
dec = wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
+9 -8
View File
@@ -40,11 +40,11 @@ func main1() error {
pos := 0
if len(src) < 2 {
return posError(pos)
return posError(pos, len(src))
}
for pos <= (len(src) - 2) {
if src[pos] != 0xFF {
return posError(pos)
return posError(pos, len(src))
}
marker := src[pos+1]
fmt.Printf("pos = 0x%08X = %10d marker = 0xFF 0x%02X %s\n", pos, pos, marker, names[marker])
@@ -59,12 +59,12 @@ func main1() error {
}
if pos >= (len(src) - 2) {
return posError(pos)
return posError(pos, len(src))
}
payloadLength := (int(src[pos]) << 8) | int(src[pos+1])
pos += payloadLength
if (payloadLength < 2) || (pos < 0) || (pos > len(src)) {
return posError(pos)
return posError(pos, len(src))
}
if marker != 0xDA { // SOS (Start Of Scan) marker.
@@ -74,7 +74,7 @@ func main1() error {
if src[pos] != 0xFF {
pos += 1
} else if pos >= (len(src) - 1) {
return posError(pos)
return posError(pos, len(src))
} else if m := src[pos+1]; (m != 0x00) && ((m < 0xD0) || (0xD7 < m)) {
break
} else {
@@ -82,11 +82,12 @@ func main1() error {
}
}
}
return posError(pos)
return posError(pos, len(src))
}
func posError(pos int) error {
return fmt.Errorf("invalid JPEG at pos = 0x%08X = %10d", pos, pos)
func posError(pos int, lenSrc int) error {
return fmt.Errorf("bad JPEG, pos = 0x%08X = %10d, len(src) = 0x%08X = %10d",
pos, pos, lenSrc, lenSrc)
}
var names = [256]string{
+8 -8
View File
@@ -255,9 +255,9 @@ const char* g_vbc_names[16] = {
};
const int g_base38_decode[38] = {
' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '?', //
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', //
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', //
'.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', //
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', //
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '~', //
};
const char* //
@@ -341,10 +341,10 @@ main1(int argc, char** argv) {
if (vmajor > 0) {
char vmajor_name[5];
vmajor_name[0] = '*';
vmajor_name[1] = '*';
vmajor_name[2] = '*';
vmajor_name[3] = '*';
vmajor_name[0] = '?';
vmajor_name[1] = '?';
vmajor_name[2] = '?';
vmajor_name[3] = '?';
vmajor_name[4] = '\x00';
uint32_t m = vmajor;
if (m < 38 * 38 * 38 * 38) {
@@ -364,7 +364,7 @@ main1(int argc, char** argv) {
vmajor_name[3] = g_base38_decode[m3];
}
printf("vmajor=0x%06" PRIX32 ":%s vminor=0x%07" PRIX32 "\n", vmajor,
printf("vmajor=0x%06" PRIX32 "=%s vminor=0x%07" PRIX32 "\n", vmajor,
vmajor_name, vminor);
} else if (vmajor == 0) {
printf("vbc=%s vbd=0x%06" PRIX32 "\n", g_vbc_names[vbc & 15], vbd);
+144
View File
@@ -0,0 +1,144 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//go:build ignore
// +build ignore
package main
// print-thumbhash-tables.go prints the std/thumbhash tables.
//
// Usage: go run print-thumbhash-tables.go
import (
"fmt"
"math"
"os"
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
printLxLy()
fmt.Println()
printFrom4Bits(1.00)
fmt.Println()
printFrom4Bits(1.25)
fmt.Println()
printCosines()
return nil
}
func printLxLy() {
for bits := 0; bits < 16; bits++ {
lCount := bits & 7
if lCount < 3 {
continue
} else if lCount == 3 {
fmt.Println()
}
hasAlpha := (bits >> 3) & 1
isLandscape := (bits >> 4) & 1
lx := lCount
ly := 7
if hasAlpha != 0 {
ly = 5
}
if isLandscape != 0 {
lx, ly = ly, lx
}
ratio := float64(lx) / float64(ly)
w, h := 32, 32
if ratio > 1 {
h = int(math.Round(32 / ratio))
} else {
w = int(math.Round(32 * ratio))
}
lenlac := 0
for cy := 0; cy < ly; cy++ {
for cx := ifElse(cy, 0, 1); (cx * ly) < (lx * (ly - cy)); cx++ {
lenlac++
}
}
lenpac := 0
for cy := 0; cy < 3; cy++ {
for cx := ifElse(cy, 0, 1); (cx * 3) < (3 * (3 - cy)); cx++ {
lenpac++
}
}
lenaac := 0
if hasAlpha != 0 {
for cy := 0; cy < 5; cy++ {
for cx := ifElse(cy, 0, 1); (cx * 5) < (5 * (5 - cy)); cx++ {
lenaac++
}
}
}
fileSize := 5 + hasAlpha + (lenlac+lenpac+lenpac+lenaac+1)/2
fmt.Printf("l_count: %d lx / ly = %d / %d w = %2d h = %2d #lac = %2d #pac = #qac = %d #aac = %2d file_size = 3 + %2d\n",
lCount, lx, ly, w, h, lenlac, lenpac, lenaac, fileSize)
}
}
func printFrom4Bits(scale float64) {
for i := 0; i < 16; i++ {
x := (float64(i)/7.5 - 1) * scale
y := (x * (1 << 14))
fmt.Printf("0x%04X, // %s%0.3f\n", 0xFFFF&int(math.Round(y)), plusSign(y), x)
}
}
func printCosines() {
widths := []int{
0, 14, 18, 19, 23, 26, 27, 32,
}
for _, w := range widths {
fmt.Printf("\n// w = %2d\n", w)
for x := 0; x < w; x++ {
fmt.Printf("[")
for cx := 1; cx < 7; cx++ {
u := math.Cos(math.Pi * float64(cx) * (float64(x) + 0.5) / float64(w))
v := u * (1 << 14)
fmt.Printf("0x%04X", 0xFFFF&int(math.Round(v)))
if cx < 6 {
fmt.Printf(",")
}
}
fmt.Printf("], // x = %2d\n", x)
}
}
}
func ifElse(c int, x int, y int) int {
if c != 0 {
return x
}
return y
}
func plusSign(x float64) string {
if x >= 0 {
return "+"
}
return ""
}
+2 -2
View File
@@ -37,8 +37,8 @@ pub const DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL : base.u64 = 9
// --------
// TOKEN_VALUE_MAJOR is the base-38 encoding of "cbor".
pub const TOKEN_VALUE_MAJOR : base.u32 = 0x0C_061D
// TOKEN_VALUE_MAJOR is the base38 encoding of "cbor".
pub const TOKEN_VALUE_MAJOR : base.u32 = 0x0B_29FA
// TOKEN_VALUE_MINOR__DETAIL_MASK is a mask for the low 18 bits of a token's
// value_minor. 18 is 64 - base.TOKEN__VALUE_EXTENSION__NUM_BITS.
+1035
View File
@@ -0,0 +1,1035 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// --------
// ETC1 / ETC2 is a lossy, fixed-rate texture compression format. ETC1 uses 8
// bytes per 4×4 pixel block, 0.5 bytes per pixel (after rounding image
// dimensions up to a multiple of 4). The ETC1 specification is at:
// http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
//
// That's the raw format for uploading to GPUs. The iPACKMAN file format (*.pkm
// files) prepends a 16-byte header, stating width, height and pixel format.
//
// Android v2.2 Froyo (2010) and its OpenGL ES shipped with ETC1 / PKM support.
// AOSP has a software implementation, used by its etc1tool program:
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/native/opengl/libs/ETC1/etc1.cpp;l=200;drc=efb735f4d5a2f04550e33e8aa9485f906018fe4e
//
// ETC2 (mandatory in OpenGL ES 3.0; see the 3.0 spec Appendix C.1 or the 3.2
// spec Appendix C.2 "ETC Compressed Texture Image Formats") extends ETC1 in a
// backwards-compatible way by re-purposing bit patterns that well-behaved
// encoders wouldn't emit. It also uses 8 bytes per 4×4 block (0.5 bytes per
// pixel), unless producing 8-bit alpha (instead of no alpha or 1-bit alpha),
// in which case it's doubled to 16 bytes per 4×4 block (1 byte per pixel).
//
// https://registry.khronos.org/OpenGL/specs/es/3.0/es_spec_3.0.pdf
// https://registry.khronos.org/OpenGL/specs/es/3.2/es_spec_3.2.pdf
// https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html#ETC1
// https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html#ETC1S
// https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html#ETC2
// https://www.khronos.org/assets/uploads/developers/library/2012-siggraph-opengl-es-bof/Ericsson-ETC2-SIGGRAPH_Aug12.pdf
// https://www.graphicshardware.org/previous/www_2007/presentations/strom-etc2-gh07.pdf
// https://github.com/Ericsson/ETCPACK
// https://en.wikipedia.org/wiki/Ericsson_Texture_Compression
pub status "#bad header"
pub status "#truncated input"
pub status "#unsupported ETC2 file"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.image_decoder(
pixfmt : base.u32,
width : base.u32[..= 0xFFFF],
height : base.u32[..= 0xFFFF],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
call_sequence : base.u8,
srgb : base.bool,
num_buffered_blocks : base.u32[..= 64],
dst_x : base.u32,
dst_y : base.u32,
swizzler : base.pixel_swizzler,
util : base.utility,
) + (
alphas : array[64] base.u64,
colors : array[64] base.u64,
// buffer holds 64 blocks. Each block is 4×4 pixels, 64 bytes.
buffer : array[4096] base.u8,
)
pub func decoder.get_quirk(key: base.u32) base.u64 {
return 0
}
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
return base."#unsupported option"
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_decode_image_config?(dst: args.dst, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var c32 : base.u32
var rounded_up_width : base.u16
var rounded_up_height : base.u16
if this.call_sequence <> 0x00 {
return base."#bad call sequence"
}
c32 = args.src.read_u32le?()
if c32 <> 'PKM 'le {
return "#bad header"
}
c32 = args.src.read_u32le?()
if (c32 == '10\x00\x00'le) or // ETC1.
(c32 == '20\x00\x01'le) or // ETC2 RGB.
(c32 == '20\x00\x09'le) { // ETC2 sRGB.
this.pixfmt = base.PIXEL_FORMAT__BGRX
} else if (c32 == '20\x00\x03'le) or // ETC2 RGBA8.
(c32 == '20\x00\x0A'le) { // ETC2 sRGBA8.
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
} else if (c32 == '20\x00\x04'le) or // ETC2 RGBA1.
(c32 == '20\x00\x0B'le) { // ETC2 sRGBA1.
this.pixfmt = base.PIXEL_FORMAT__BGRA_BINARY
} else if (c32 & 0xFFFF) == '20'le {
return "#unsupported ETC2 file"
} else {
return "#bad header"
}
this.srgb = (c32 >> 24) >= 0x09
rounded_up_width = args.src.read_u16be?()
rounded_up_height = args.src.read_u16be?()
c32 = args.src.read_u16be_as_u32?()
if ((c32 + 3) & 0xFFFF_FFFC) <> (rounded_up_width as base.u32) {
return "#bad header"
}
this.width = c32
c32 = args.src.read_u16be_as_u32?()
if ((c32 + 3) & 0xFFFF_FFFC) <> (rounded_up_height as base.u32) {
return "#bad header"
}
this.height = c32
if args.dst <> nullptr {
args.dst.set!(
pixfmt: this.pixfmt,
pixsub: 0,
width: this.width,
height: this.height,
first_frame_io_position: 16,
first_frame_is_opaque: this.pixfmt == base.PIXEL_FORMAT__BGRX)
}
this.call_sequence = 0x20
}
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_decode_frame_config?(dst: args.dst, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
this.do_decode_image_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 0x28 {
if 16 <> args.src.position() {
return base."#bad restart"
}
} else if this.call_sequence == 0x40 {
this.call_sequence = 0x60
return base."@end of data"
} else {
return base."@end of data"
}
if args.dst <> nullptr {
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: this.width,
max_excl_y: this.height),
duration: 0,
index: 0,
io_position: 16,
disposal: 0,
opaque_within_bounds: this.pixfmt == base.PIXEL_FORMAT__BGRX,
overwrite_instead_of_blend: false,
background_color: 0xFF00_0000)
}
this.call_sequence = 0x40
}
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var status : base.status
while true {
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var remaining : base.u32[..= 0x1000_0000]
var status : base.status
if this.call_sequence == 0x40 {
// No-op.
} else if this.call_sequence < 0x40 {
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
status = this.swizzler.prepare!(
dst_pixfmt: args.dst.pixel_format(),
dst_palette: args.dst.palette(),
src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
src_palette: this.util.empty_slice_u8(),
blend: args.blend)
if not status.is_ok() {
return status
}
this.dst_x = 0
this.dst_y = 0
remaining = ((this.width + 3) / 4) * ((this.height + 3) / 4)
while remaining > 0 {
this.num_buffered_blocks = remaining.min(no_more_than: 64)
if remaining < this.num_buffered_blocks {
return base."#too much data"
}
remaining -= this.num_buffered_blocks
this.from_src_to_colors?(src: args.src)
this.from_colors_to_buffer!()
if this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL {
this.from_alphas_to_buffer!()
}
status = this.from_buffer_to_dst!(dst: args.dst)
if not status.is_ok() {
return status
}
}
this.call_sequence = 0x60
}
pri func decoder.from_src_to_colors?(src: base.io_reader) {
var bi : base.u32[..= 64]
while bi < this.num_buffered_blocks {
assert bi < 64 via "a < b: a < c; c <= b"(c: this.num_buffered_blocks)
if this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL {
this.alphas[bi] = args.src.read_u64be?()
}
this.colors[bi] = args.src.read_u64be?()
bi += 1
}
}
pri func decoder.from_colors_to_buffer!() {
var bi : base.u32[..= 64]
var color : base.u64
var r0 : base.u32
var r1 : base.u32
var g0 : base.u32
var g1 : base.u32
var b0 : base.u32
var b1 : base.u32
var diff : base.bool
var tran : base.bool
var flip : base.bool
while bi < this.num_buffered_blocks {
assert bi < 64 via "a < b: a < c; c <= b"(c: this.num_buffered_blocks)
color = this.colors[bi]
diff = (color & 0x2_0000_0000) <> 0
tran = (not diff) and (this.pixfmt == base.PIXEL_FORMAT__BGRA_BINARY)
if (not diff) and (this.pixfmt <> base.PIXEL_FORMAT__BGRA_BINARY) {
// The high 32 bits of color:
//
// 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 dec
// 3F 3E 3D 3C 3B 3A 39 38 37 36 35 34 33 32 31 30 2F 2E 2D 2C 2B 2A 29 28 27 26 25 24 23 22 21 20 hex
// R0 r0 r0 r0 R1 r1 r1 r1 G0 g0 g0 g0 G1 g1 g1 g1 B0 b0 b0 b0 B1 b1 b1 b1 W0 w0 w0 W1 w1 w1 00 Fl
r0 = (0x0F & (color >> 0x3C)) as base.u32
r0 = (r0 << 4) | r0
r1 = (0x0F & (color >> 0x38)) as base.u32
r1 = (r1 << 4) | r1
g0 = (0x0F & (color >> 0x34)) as base.u32
g0 = (g0 << 4) | g0
g1 = (0x0F & (color >> 0x30)) as base.u32
g1 = (g1 << 4) | g1
b0 = (0x0F & (color >> 0x2C)) as base.u32
b0 = (b0 << 4) | b0
b1 = (0x0F & (color >> 0x28)) as base.u32
b1 = (b1 << 4) | b1
} else {
// The high 32 bits of color (unless ETC2's T / H / Planar modes):
//
// 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 dec
// 3F 3E 3D 3C 3B 3A 39 38 37 36 35 34 33 32 31 30 2F 2E 2D 2C 2B 2A 29 28 27 26 25 24 23 22 21 20 hex
// R0 r0 r0 r0 r0 R1 r1 r1 G0 g0 g0 g0 g0 G1 g1 g1 B0 b0 b0 b0 b0 B1 b1 b1 W0 w0 w0 W1 w1 w1 .. Fl
r0 = (0x1F & (color >> 0x3B)) as base.u32
r1 = r0 ~mod+ DIFFS[0x07 & (color >> 0x38)]
if (r1 >> 5) <> 0 {
this.decode_t_mode!(
bits: color,
offset: 16 * bi,
transparent: tran)
bi += 1
continue
}
r0 = (r0 ~mod<< 3) | (r0 >> 2)
r1 = (r1 ~mod<< 3) | (r1 >> 2)
g0 = (0x1F & (color >> 0x33)) as base.u32
g1 = g0 ~mod+ DIFFS[0x07 & (color >> 0x30)]
if (g1 >> 5) <> 0 {
this.decode_h_mode!(
bits: color,
offset: 16 * bi,
transparent: tran)
bi += 1
continue
}
g0 = (g0 ~mod<< 3) | (g0 >> 2)
g1 = (g1 ~mod<< 3) | (g1 >> 2)
b0 = (0x1F & (color >> 0x2B)) as base.u32
b1 = b0 ~mod+ DIFFS[0x07 & (color >> 0x28)]
if (b1 >> 5) <> 0 {
this.decode_planar_mode!(
bits: color,
offset: 16 * bi)
bi += 1
continue
}
b0 = (b0 ~mod<< 3) | (b0 >> 2)
b1 = (b1 ~mod<< 3) | (b1 >> 2)
}
flip = (color & 0x1_0000_0000) <> 0
this.decode_half_block!(
bits: (color & 0xFFFF_FFFF) as base.u32,
offset: 16 * bi,
which: ((color >> 0x25) & 7) as base.u32,
r: r0,
g: g0,
b: b0,
flip: flip,
transparent: tran,
second: false)
this.decode_half_block!(
bits: (color & 0xFFFF_FFFF) as base.u32,
offset: 16 * bi,
which: ((color >> 0x22) & 7) as base.u32,
r: r1,
g: g1,
b: b1,
flip: flip,
transparent: tran,
second: true)
bi += 1
}
}
pri func decoder.decode_t_mode!(
bits: base.u64,
offset: base.u32[..= 1008],
transparent: base.bool) {
var r : array[4] base.u8
var g : array[4] base.u8
var b : array[4] base.u8
var a : array[4] base.u8
var which : base.u32[..= 7]
var delta : base.u32
var y : base.u32
var x : base.u32
var x4y : base.u32[..= 15]
var index : base.u32[..= 3]
var o : base.u32[..= 4092]
// Unjumble T-mode's 59 bits and convert from RGB444 to RGB888.
//
// 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 dec
// 3F 3E 3D 3C 3B 3A 39 38 37 36 35 34 33 32 31 30 2F 2E 2D 2C 2B 2A 29 28 27 26 25 24 23 22 21 20 hex
// .. .. .. R0 r0 .. r0 r0 G0 g0 g0 g0 B0 b0 b0 b0 R2 r2 r2 r2 G2 g2 g2 g2 B2 b2 b2 b2 Wh wh .. wh
//
// The low 32 bits hold "2 bits per pixel" indexes into the r, g, b arrays.
r[0] = ((0x0C & (args.bits >> 0x39)) as base.u8) |
((0x03 & (args.bits >> 0x38)) as base.u8)
r[0] = (r[0] << 4) | r[0]
g[0] = (0x0F & (args.bits >> 0x34)) as base.u8
g[0] = (g[0] << 4) | g[0]
b[0] = (0x0F & (args.bits >> 0x30)) as base.u8
b[0] = (b[0] << 4) | b[0]
a[0] = 0xFF
r[2] = (0x0F & (args.bits >> 0x2C)) as base.u8
r[2] = (r[2] << 4) | r[2]
g[2] = (0x0F & (args.bits >> 0x28)) as base.u8
g[2] = (g[2] << 4) | g[2]
b[2] = (0x0F & (args.bits >> 0x24)) as base.u8
b[2] = (b[2] << 4) | b[2]
a[2] = 0xFF
// Modulate and apply transparency.
which = ((0x06 & (args.bits >> 0x21)) as base.u32) |
((0x01 & (args.bits >> 0x20)) as base.u32)
delta = T_H_MODIFIERS[which] as base.u32
r[1] = CLAMP[((r[2] as base.u32) ~mod+ delta) & 1023]
g[1] = CLAMP[((g[2] as base.u32) ~mod+ delta) & 1023]
b[1] = CLAMP[((b[2] as base.u32) ~mod+ delta) & 1023]
a[1] = 0xFF
r[3] = CLAMP[((r[2] as base.u32) ~mod- delta) & 1023]
g[3] = CLAMP[((g[2] as base.u32) ~mod- delta) & 1023]
b[3] = CLAMP[((b[2] as base.u32) ~mod- delta) & 1023]
a[3] = 0xFF
if args.transparent {
r[2] = 0
g[2] = 0
b[2] = 0
a[2] = 0
}
// Paint the 4×4 block.
while y < 4 {
x = 0
while x < 4,
inv y < 4,
{
x4y = (x * 4) | y
index = (((args.bits >> x4y) & 1) as base.u32) |
(((args.bits >> (x4y + 15)) & 2) as base.u32)
o = args.offset + (x * 4) + (y * 1024)
this.buffer[o + 0] = b[index]
this.buffer[o + 1] = g[index]
this.buffer[o + 2] = r[index]
this.buffer[o + 3] = a[index]
x += 1
}
y += 1
}
}
pri func decoder.decode_h_mode!(
bits: base.u64,
offset: base.u32[..= 1008],
transparent: base.bool) {
var r : array[4] base.u8
var g : array[4] base.u8
var b : array[4] base.u8
var a : array[4] base.u8
var rgb0 : base.u32
var rgb2 : base.u32
var which : base.u32[..= 7]
var delta : base.u32
var y : base.u32
var x : base.u32
var x4y : base.u32[..= 15]
var index : base.u32[..= 3]
var o : base.u32[..= 4092]
// Unjumble H-mode's 58 bits (one of the 'which' bits is implied by order)
// and convert from RGB444 to RGB888.
//
// 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 dec
// 3F 3E 3D 3C 3B 3A 39 38 37 36 35 34 33 32 31 30 2F 2E 2D 2C 2B 2A 29 28 27 26 25 24 23 22 21 20 hex
// .. R0 r0 r0 r0 G0 g0 g0 .. .. .. g0 B0 .. b0 b0 b0 R2 r2 r2 r2 G2 g2 g2 g2 B2 b2 b2 b2 Wh .. wh
//
// The low 32 bits hold "2 bits per pixel" indexes into the r, g, b arrays.
r[0] = (0x0F & (args.bits >> 0x3B)) as base.u8
r[0] = (r[0] << 4) | r[0]
g[0] = ((0x0E & (args.bits >> 0x37)) as base.u8) |
((0x01 & (args.bits >> 0x34)) as base.u8)
g[0] = (g[0] << 4) | g[0]
b[0] = ((0x08 & (args.bits >> 0x30)) as base.u8) |
((0x07 & (args.bits >> 0x2F)) as base.u8)
b[0] = (b[0] << 4) | b[0]
r[2] = (0x0F & (args.bits >> 0x2B)) as base.u8
r[2] = (r[2] << 4) | r[2]
g[2] = (0x0F & (args.bits >> 0x27)) as base.u8
g[2] = (g[2] << 4) | g[2]
b[2] = (0x0F & (args.bits >> 0x23)) as base.u8
b[2] = (b[2] << 4) | b[2]
// Modulate and apply transparency.
rgb0 = ((r[0] as base.u32) << 0x10) |
((g[0] as base.u32) << 0x08) |
((b[0] as base.u32) << 0x00)
rgb2 = ((r[2] as base.u32) << 0x10) |
((g[2] as base.u32) << 0x08) |
((b[2] as base.u32) << 0x00)
which = ((0x04 & (args.bits >> 0x20)) as base.u32) |
((0x02 & (args.bits >> 0x1F)) as base.u32)
if rgb0 >= rgb2 {
which |= 1
}
delta = T_H_MODIFIERS[which] as base.u32
r[1] = CLAMP[((r[0] as base.u32) ~mod- delta) & 1023]
g[1] = CLAMP[((g[0] as base.u32) ~mod- delta) & 1023]
b[1] = CLAMP[((b[0] as base.u32) ~mod- delta) & 1023]
a[1] = 0xFF
r[0] = CLAMP[((r[0] as base.u32) ~mod+ delta) & 1023]
g[0] = CLAMP[((g[0] as base.u32) ~mod+ delta) & 1023]
b[0] = CLAMP[((b[0] as base.u32) ~mod+ delta) & 1023]
a[0] = 0xFF
r[3] = CLAMP[((r[2] as base.u32) ~mod- delta) & 1023]
g[3] = CLAMP[((g[2] as base.u32) ~mod- delta) & 1023]
b[3] = CLAMP[((b[2] as base.u32) ~mod- delta) & 1023]
a[3] = 0xFF
r[2] = CLAMP[((r[2] as base.u32) ~mod+ delta) & 1023]
g[2] = CLAMP[((g[2] as base.u32) ~mod+ delta) & 1023]
b[2] = CLAMP[((b[2] as base.u32) ~mod+ delta) & 1023]
a[2] = 0xFF
if args.transparent {
r[2] = 0
g[2] = 0
b[2] = 0
a[2] = 0
}
// Paint the 4×4 block.
while y < 4 {
x = 0
while x < 4,
inv y < 4,
{
x4y = (x * 4) | y
index = (((args.bits >> x4y) & 1) as base.u32) |
(((args.bits >> (x4y + 15)) & 2) as base.u32)
o = args.offset + (x * 4) + (y * 1024)
this.buffer[o + 0] = b[index]
this.buffer[o + 1] = g[index]
this.buffer[o + 2] = r[index]
this.buffer[o + 3] = a[index]
x += 1
}
y += 1
}
}
pri func decoder.decode_planar_mode!(
bits: base.u64,
offset: base.u32[..= 1008]) {
var ro : base.u32
var go : base.u32
var bo : base.u32
var rh : base.u32
var gh : base.u32
var bh : base.u32
var rv : base.u32
var gv : base.u32
var bv : base.u32
var y : base.u32
var x : base.u32
var o : base.u32[..= 4092]
var rp : base.u32
var gp : base.u32
var bp : base.u32
// Unjumble Planar-mode's 57 bits and convert from RGB676 to RGB888.
//
// 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 dec
// 3F 3E 3D 3C 3B 3A 39 38 37 36 35 34 33 32 31 30 2F 2E 2D 2C 2B 2A 29 28 27 26 25 24 23 22 21 20 hex
// .. Ro ro ro ro ro ro Go .. go go go go go go Bo .. .. .. bo bo .. bo bo bo Rh rh rh rh rh .. rh
//
// 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 dec
// 1F 1E 1D 1C 1B 1A 19 18 17 16 15 14 13 12 11 10 0F 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01 00 hex
// Gh gh gh gh gh gh gh Bh bh bh bh bh bh Rv rv rv rv rv rv Gv gv gv gv gv gv gv Bv bv bv bv bv bv
ro = (0x3F & (args.bits >> 0x39)) as base.u32
ro = (ro ~mod<< 2) | (ro >> 4)
go = ((0x40 & (args.bits >> 0x32)) as base.u32) |
((0x3F & (args.bits >> 0x31)) as base.u32)
go = (go ~mod<< 1) | (go >> 6)
bo = ((0x20 & (args.bits >> 0x2B)) as base.u32) |
((0x18 & (args.bits >> 0x28)) as base.u32) |
((0x07 & (args.bits >> 0x27)) as base.u32)
bo = (bo ~mod<< 2) | (bo >> 4)
rh = ((0x3E & (args.bits >> 0x21)) as base.u32) |
((0x01 & (args.bits >> 0x20)) as base.u32)
rh = (rh ~mod<< 2) | (rh >> 4)
gh = (0x7F & (args.bits >> 0x19)) as base.u32
gh = (gh ~mod<< 1) | (gh >> 6)
bh = (0x3F & (args.bits >> 0x13)) as base.u32
bh = (bh ~mod<< 2) | (bh >> 4)
rv = (0x3F & (args.bits >> 0x0D)) as base.u32
rv = (rv ~mod<< 2) | (rv >> 4)
gv = (0x7F & (args.bits >> 0x06)) as base.u32
gv = (gv ~mod<< 1) | (gv >> 6)
bv = (0x3F & (args.bits >> 0x00)) as base.u32
bv = (bv ~mod<< 2) | (bv >> 4)
// Convert h and v colors from absolute to relative.
rh ~mod-= ro
gh ~mod-= go
bh ~mod-= bo
rv ~mod-= ro
gv ~mod-= go
bv ~mod-= bo
// Prepare to linearly interpolate (which involves dividing by 4).
ro ~mod*= 4
go ~mod*= 4
bo ~mod*= 4
// Paint the 4×4 block.
while y < 4 {
x = 0
while x < 4,
inv y < 4,
{
o = args.offset + (x * 4) + (y * 1024)
bp = ((x ~mod* bh) ~mod+ (y ~mod* bv)) ~mod+ bo
this.buffer[o + 0] = CLAMP[((bp ~mod+ 2) / 4) & 1023]
gp = ((x ~mod* gh) ~mod+ (y ~mod* gv)) ~mod+ go
this.buffer[o + 1] = CLAMP[((gp ~mod+ 2) / 4) & 1023]
rp = ((x ~mod* rh) ~mod+ (y ~mod* rv)) ~mod+ ro
this.buffer[o + 2] = CLAMP[((rp ~mod+ 2) / 4) & 1023]
x += 1
this.buffer[o + 3] = 0xFF
}
y += 1
}
}
pri func decoder.decode_half_block!(
bits: base.u32,
offset: base.u32[..= 1008],
which: base.u32[..= 7],
r: base.u32,
g: base.u32,
b: base.u32,
flip: base.bool,
transparent: base.bool,
second: base.bool) {
var which : base.u32[..= 15]
var x0 : base.u32[..= 2]
var y0 : base.u32[..= 2]
var x : base.u32[..= 3]
var y : base.u32[..= 3]
var i : base.u32
var x4y : base.u32[..= 15]
var index : base.u32[..= 3]
var modif : base.u32
var o : base.u32[..= 4092]
which = args.which
if args.transparent {
which |= 8
}
if not args.second {
// No-op.
} else if args.flip {
y0 = 2
} else {
x0 = 2
}
while i < 8 {
if args.flip {
x = (x0 + (i / 2)) & 3
y = (y0 + (i & 1))
} else {
x = (x0 + (i / 4))
y = (y0 + i) & 3
}
x4y = (x * 4) | y
index = ((args.bits >> x4y) & 1) |
((args.bits >> (x4y + 15)) & 2)
modif = MODIFIERS[which][index]
o = args.offset + (x * 4) + (y * 1024)
if args.transparent and (index == 2) {
this.buffer[o + 0] = 0
this.buffer[o + 1] = 0
this.buffer[o + 2] = 0
this.buffer[o + 3] = 0
} else {
this.buffer[o + 0] = CLAMP[(args.b ~mod+ modif) & 1023]
this.buffer[o + 1] = CLAMP[(args.g ~mod+ modif) & 1023]
this.buffer[o + 2] = CLAMP[(args.r ~mod+ modif) & 1023]
this.buffer[o + 3] = 0xFF
}
i += 1
}
}
pri func decoder.from_alphas_to_buffer!() {
var bi : base.u32[..= 64]
var alpha : base.u64
var a0 : base.u32
var multiplier : base.u32[..= 15]
var which : base.u32[..= 15]
var offset : base.u32[..= 1008]
var y : base.u32
var x : base.u32
var shift : base.u32[..= 45]
var delta : base.u32
var o : base.u32[..= 4092]
while bi < this.num_buffered_blocks {
assert bi < 64 via "a < b: a < c; c <= b"(c: this.num_buffered_blocks)
alpha = this.alphas[bi]
a0 = (alpha >> 56) as base.u32
multiplier = ((alpha >> 52) & 0x0F) as base.u32
which = ((alpha >> 48) & 0x0F) as base.u32
offset = 16 * bi
y = 0
while y < 4,
inv bi < 64,
{
x = 0
while x < 4,
inv bi < 64,
inv y < 4,
{
shift = (((x ^ 3) * 4) | (y ^ 3)) * 3
delta = multiplier ~mod* ALPHA_MODIFIERS[which][7 & (alpha >> shift)]
o = offset + (x * 4) + (y * 1024)
this.buffer[o + 3] = CLAMP[(a0 ~mod+ delta) & 1023]
x += 1
}
y += 1
}
bi += 1
}
}
pri func decoder.from_buffer_to_dst!(dst: ptr base.pixel_buffer) base.status {
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var tab : table base.u8
var bi : base.u32
var rem_x : base.u32[..= 0xFFFF]
var dy : base.u32[..= 4]
var dst : slice base.u8
var src : slice base.u8
var si : base.u32[..= 4080]
var sj : base.u32[..= 4096]
var i : base.u64
var num_src_pixels : base.u32
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
dst_pixfmt = args.dst.pixel_format()
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = dst_bits_per_pixel / 8
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
tab = args.dst.plane(p: 0)
while bi < this.num_buffered_blocks {
assert bi < 64 via "a < b: a < c; c <= b"(c: this.num_buffered_blocks)
if this.width <= this.dst_x {
this.dst_x = 0
this.dst_y ~mod+= 4
if this.dst_y >= this.height {
break
}
rem_x = this.width
} else {
rem_x = this.width - this.dst_x
}
dy = 0
while dy < 4,
inv bi < 64,
{
si = (1024 * dy) + (16 * bi)
sj = (1024 * dy) + (16 * 64)
if si < sj {
src = this.buffer[si .. sj]
}
if ((4 * rem_x) as base.u64) < src.length() {
src = src[.. (4 * rem_x) as base.u64]
}
if (this.dst_y ~mod+ dy) >= this.height {
break
}
dst = tab.row_u32(y: this.dst_y ~mod+ dy)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
if i < dst.length() {
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: args.dst.palette(),
src: src)
}
dy += 1
}
num_src_pixels = ((src.length() & 0xFFFF_FFFF) as base.u32) / 4
this.dst_x ~mod+= num_src_pixels
bi ~mod+= (num_src_pixels + 3) / 4
}
return ok
}
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
return this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: this.width,
max_excl_y: this.height)
}
pub func decoder.num_animation_loops() base.u32 {
return 0
}
pub func decoder.num_decoded_frame_configs() base.u64 {
if this.call_sequence > 0x20 {
return 1
}
return 0
}
pub func decoder.num_decoded_frames() base.u64 {
if this.call_sequence > 0x40 {
return 1
}
return 0
}
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
if this.call_sequence < 0x20 {
return base."#bad call sequence"
}
if (args.index <> 0) or (args.io_position <> 16) {
return base."#bad argument"
}
this.call_sequence = 0x28
return ok
}
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
// No-op. ETC2 doesn't support metadata.
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
return base."#no more information"
}
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
}
pri const DIFFS : roarray[8] base.u32 = [
0x0000_0000,
0x0000_0001,
0x0000_0002,
0x0000_0003,
0xFFFF_FFFC,
0xFFFF_FFFD,
0xFFFF_FFFE,
0xFFFF_FFFF,
]
pri const MODIFIERS : roarray[16] roarray[4] base.u32 = [
[0x0000_0002, 0x0000_0008, 0xFFFF_FFFE, 0xFFFF_FFF8], // [ -8, -2, +2, +8] re-ordered.
[0x0000_0005, 0x0000_0011, 0xFFFF_FFFB, 0xFFFF_FFEF], // [ -17, -5, +5, +17] re-ordered.
[0x0000_0009, 0x0000_001D, 0xFFFF_FFF7, 0xFFFF_FFE3], // [ -29, -9, +9, +29] re-ordered.
[0x0000_000D, 0x0000_002A, 0xFFFF_FFF3, 0xFFFF_FFD6], // [ -42, -13, +13, +42] re-ordered.
[0x0000_0012, 0x0000_003C, 0xFFFF_FFEE, 0xFFFF_FFC4], // [ -60, -18, +18, +60] re-ordered.
[0x0000_0018, 0x0000_0050, 0xFFFF_FFE8, 0xFFFF_FFB0], // [ -80, -24, +24, +80] re-ordered.
[0x0000_0021, 0x0000_006A, 0xFFFF_FFDF, 0xFFFF_FF96], // [-106, -33, +33, +106] re-ordered.
[0x0000_002F, 0x0000_00B7, 0xFFFF_FFD1, 0xFFFF_FF49], // [-183, -47, +47, +183] re-ordered.
[0x0000_0000, 0x0000_0008, 0x0000_0000, 0xFFFF_FFF8], // [ -8, 0, 0, +8] re-ordered.
[0x0000_0000, 0x0000_0011, 0x0000_0000, 0xFFFF_FFEF], // [ -17, 0, 0, +17] re-ordered.
[0x0000_0000, 0x0000_001D, 0x0000_0000, 0xFFFF_FFE3], // [ -29, 0, 0, +29] re-ordered.
[0x0000_0000, 0x0000_002A, 0x0000_0000, 0xFFFF_FFD6], // [ -42, 0, 0, +42] re-ordered.
[0x0000_0000, 0x0000_003C, 0x0000_0000, 0xFFFF_FFC4], // [ -60, 0, 0, +60] re-ordered.
[0x0000_0000, 0x0000_0050, 0x0000_0000, 0xFFFF_FFB0], // [ -80, 0, 0, +80] re-ordered.
[0x0000_0000, 0x0000_006A, 0x0000_0000, 0xFFFF_FF96], // [-106, 0, 0, +106] re-ordered.
[0x0000_0000, 0x0000_00B7, 0x0000_0000, 0xFFFF_FF49], // [-183, 0, 0, +183] re-ordered.
]
pri const T_H_MODIFIERS : roarray[8] base.u8 = [3, 6, 11, 16, 23, 32, 41, 64]
pri const ALPHA_MODIFIERS : roarray[16] roarray[8] base.u32 = [
[0xFFFF_FFFD, 0xFFFF_FFFA, 0xFFFF_FFF7, 0xFFFF_FFF1, 0x0000_0002, 0x0000_0005, 0x0000_0008, 0x0000_000E], // [-3, -6, -9, -15, +2, +5, +8, +14]
[0xFFFF_FFFD, 0xFFFF_FFF9, 0xFFFF_FFF6, 0xFFFF_FFF3, 0x0000_0002, 0x0000_0006, 0x0000_0009, 0x0000_000C], // [-3, -7, -10, -13, +2, +6, +9, +12]
[0xFFFF_FFFE, 0xFFFF_FFFB, 0xFFFF_FFF8, 0xFFFF_FFF3, 0x0000_0001, 0x0000_0004, 0x0000_0007, 0x0000_000C], // [-2, -5, -8, -13, +1, +4, +7, +12]
[0xFFFF_FFFE, 0xFFFF_FFFC, 0xFFFF_FFFA, 0xFFFF_FFF3, 0x0000_0001, 0x0000_0003, 0x0000_0005, 0x0000_000C], // [-2, -4, -6, -13, +1, +3, +5, +12]
[0xFFFF_FFFD, 0xFFFF_FFFA, 0xFFFF_FFF8, 0xFFFF_FFF4, 0x0000_0002, 0x0000_0005, 0x0000_0007, 0x0000_000B], // [-3, -6, -8, -12, +2, +5, +7, +11]
[0xFFFF_FFFD, 0xFFFF_FFF9, 0xFFFF_FFF7, 0xFFFF_FFF5, 0x0000_0002, 0x0000_0006, 0x0000_0008, 0x0000_000A], // [-3, -7, -9, -11, +2, +6, +8, +10]
[0xFFFF_FFFC, 0xFFFF_FFF9, 0xFFFF_FFF8, 0xFFFF_FFF5, 0x0000_0003, 0x0000_0006, 0x0000_0007, 0x0000_000A], // [-4, -7, -8, -11, +3, +6, +7, +10]
[0xFFFF_FFFD, 0xFFFF_FFFB, 0xFFFF_FFF8, 0xFFFF_FFF5, 0x0000_0002, 0x0000_0004, 0x0000_0007, 0x0000_000A], // [-3, -5, -8, -11, +2, +4, +7, +10]
[0xFFFF_FFFE, 0xFFFF_FFFA, 0xFFFF_FFF8, 0xFFFF_FFF6, 0x0000_0001, 0x0000_0005, 0x0000_0007, 0x0000_0009], // [-2, -6, -8, -10, +1, +5, +7, +9]
[0xFFFF_FFFE, 0xFFFF_FFFB, 0xFFFF_FFF8, 0xFFFF_FFF6, 0x0000_0001, 0x0000_0004, 0x0000_0007, 0x0000_0009], // [-2, -5, -8, -10, +1, +4, +7, +9]
[0xFFFF_FFFE, 0xFFFF_FFFC, 0xFFFF_FFF8, 0xFFFF_FFF6, 0x0000_0001, 0x0000_0003, 0x0000_0007, 0x0000_0009], // [-2, -4, -8, -10, +1, +3, +7, +9]
[0xFFFF_FFFE, 0xFFFF_FFFB, 0xFFFF_FFF9, 0xFFFF_FFF6, 0x0000_0001, 0x0000_0004, 0x0000_0006, 0x0000_0009], // [-2, -5, -7, -10, +1, +4, +6, +9]
[0xFFFF_FFFD, 0xFFFF_FFFC, 0xFFFF_FFF9, 0xFFFF_FFF6, 0x0000_0002, 0x0000_0003, 0x0000_0006, 0x0000_0009], // [-3, -4, -7, -10, +2, +3, +6, +9]
[0xFFFF_FFFF, 0xFFFF_FFFE, 0xFFFF_FFFD, 0xFFFF_FFF6, 0x0000_0000, 0x0000_0001, 0x0000_0002, 0x0000_0009], // [-1, -2, -3, -10, +0, +1, +2, +9]
[0xFFFF_FFFC, 0xFFFF_FFFA, 0xFFFF_FFF8, 0xFFFF_FFF7, 0x0000_0003, 0x0000_0005, 0x0000_0007, 0x0000_0008], // [-4, -6, -8, -9, +3, +5, +7, +8]
[0xFFFF_FFFD, 0xFFFF_FFFB, 0xFFFF_FFF9, 0xFFFF_FFF7, 0x0000_0002, 0x0000_0004, 0x0000_0006, 0x0000_0008], // [-3, -5, -7, -9, +2, +4, +6, +8]
]
pri const CLAMP : roarray[1024] base.u8 = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
+10 -10
View File
@@ -12,9 +12,9 @@
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "gif " is 0x0F_8586. Left shifting by 10 gives
// 0x3E16_1800.
pri const QUIRKS_BASE : base.u32 = 0x3E16_1800
// The base38 encoding of "gif." is 0x0E_A964. Left shifting by 10 gives
// 0x3AA5_9000.
pri const QUIRKS_BASE : base.u32 = 0x3AA5_9000
// --------
@@ -32,7 +32,7 @@ pri const QUIRKS_BASE : base.u32 = 0x3E16_1800
// see the N+1'th frame's header (or the end-of-animation terminator), so that
// e.g. the API for visiting the N'th frame can also return whether it's the
// final frame. Enabling this quirk allows for matching that behavior.
pub const QUIRK_DELAY_NUM_DECODED_FRAMES : base.u32 = 0x3E16_1800 | 0x00
pub const QUIRK_DELAY_NUM_DECODED_FRAMES : base.u32 = 0x3AA5_9000 | 0x00
// When this quirk is enabled, the background color of the first frame is set
// to black whenever that first frame has a local (frame-specific) palette.
@@ -44,7 +44,7 @@ pub const QUIRK_DELAY_NUM_DECODED_FRAMES : base.u32 = 0x3E16_1800 | 0x00
//
// There isn't really much of a rationale for this, other than it matches the
// behavior of another GIF implementation.
pub const QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND : base.u32 = 0x3E16_1800 | 0x01
pub const QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND : base.u32 = 0x3AA5_9000 | 0x01
// When this quirk is enabled, the background color is taken from the GIF
// instead of always being transparent black. If the background color index in
@@ -60,12 +60,12 @@ pub const QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND : base.u32 = 0x
// processing WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND. In both
// cases, the caller of Wuffs, not Wuffs itself, is responsible for filling the
// pixel buffer with that color.
pub const QUIRK_HONOR_BACKGROUND_COLOR : base.u32 = 0x3E16_1800 | 0x02
pub const QUIRK_HONOR_BACKGROUND_COLOR : base.u32 = 0x3AA5_9000 | 0x02
// When this quirk is enabled, silently ignore e.g. a frame that reports a
// width and height of 6 pixels each, followed by 50 pixel values. In that
// case, we process the first 36 pixel values and discard the excess 14.
pub const QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA : base.u32 = 0x3E16_1800 | 0x03
pub const QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA : base.u32 = 0x3AA5_9000 | 0x03
// When this quirk is enabled, if the initial frame bounds extends beyond the
// image bounds, then the image bounds stay unchanged. By default (with this
@@ -74,14 +74,14 @@ pub const QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA : base.u32 = 0x3E16_1800 | 0x03
//
// For more discussion, see
// https://github.com/google/wuffs/blob/main/test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt
pub const QUIRK_IMAGE_BOUNDS_ARE_STRICT : base.u32 = 0x3E16_1800 | 0x04
pub const QUIRK_IMAGE_BOUNDS_ARE_STRICT : base.u32 = 0x3AA5_9000 | 0x04
// When this quirk is enabled, a frame with zero width or height is rejected
// during decode_frame (but accepted during decode_frame_config).
pub const QUIRK_REJECT_EMPTY_FRAME : base.u32 = 0x3E16_1800 | 0x05
pub const QUIRK_REJECT_EMPTY_FRAME : base.u32 = 0x3AA5_9000 | 0x05
// When this quirk is enabled, a frame with no explicit palette is rejected,
// instead of implicitly having a palette with every entry being opaque black.
pub const QUIRK_REJECT_EMPTY_PALETTE : base.u32 = 0x3E16_1800 | 0x06
pub const QUIRK_REJECT_EMPTY_PALETTE : base.u32 = 0x3AA5_9000 | 0x06
pri const QUIRKS_COUNT : base.u32 = 0x07
+42 -41
View File
@@ -18,6 +18,8 @@ pub status "#bad marker"
pub status "#bad scan count"
pub status "#missing Huffman table"
pub status "#missing Quantization table"
pub status "#rejected progressive JPEG"
pub status "#short SOS bitstream"
pub status "#truncated input"
pub status "#unsupported arithmetic coding"
pub status "#unsupported color model"
@@ -281,7 +283,8 @@ pub struct decoder? implements base.image_decoder(
expect_multiple_scans : base.bool,
use_lower_quality : base.bool,
use_lower_quality : base.bool,
reject_progressive_jpegs : base.bool,
swizzle_immediately : base.bool,
swizzle_immediately_status : base.status,
@@ -342,40 +345,21 @@ pub func decoder.get_quirk(key: base.u32) base.u64 {
if this.use_lower_quality {
return 0xFFFF_FFFF_FFFF_FFFF
}
} else if args.key == QUIRK_REJECT_PROGRESSIVE_JPEGS {
if this.reject_progressive_jpegs {
return 1
}
}
return 0
}
// If key is base.QUIRK_QUALITY then, when re-interpreting the value as a
// signed i64 value, a negative quirk value opts the decoder in to a slightly
// worse quality but leaner (less memory required) chroma upsampling algorithm.
//
// Negative (in i64 space) means >= 0x8000_0000_0000_0000 (in u64 space).
//
// Specifically, a negative quirk value uses a box filter. A non-negative quirk
// value (including the default value, zero) uses the same triangle filter that
// libjpeg-turbo also uses by default, which requires chroma upsampling on the
// edges of a MCU (Minimum Coded Unit) to remember adjacent MCU's values.
//
// Leaner means that for common (sequential) JPEG images, the range returned by
// decoder.workbuf_len can have a minimum value of zero, meaning that no work
// buffer memory needs to be allocated. Decoding rarer (progressive) JPEGs will
// still require a positive amount of work buffer memory. The exact amount
// required depends on factors like the JPEG image's width, height, component
// count and subsampling ratios.
//
// Regardless of the quirk value, as always, the workbuf_len method returns a
// range, whose min and max can be different. The caller is able to choose
// between providing the minimal amount of work buffer memory (for slightly
// slower decoding) or the maximal amount (for slightly faster decoding).
//
// Callers that never wish to allocate work buffer memory can simply reject
// progressive JPEGs (where workbuf_len().min_incl > 0 despite setting the
// base.QUIRK_QUALITY key to a negative quirk value) as unsupported.
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
if args.key == base.QUIRK_QUALITY {
this.use_lower_quality = args.value >= 0x8000_0000_0000_0000
return ok
} else if args.key == QUIRK_REJECT_PROGRESSIVE_JPEGS {
this.reject_progressive_jpegs = args.value <> 0
return ok
}
return base."#unsupported option"
}
@@ -443,6 +427,14 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
this.payload_length = args.src.read_u16be_as_u32?()
// Payload length includes the 2 bytes for the u16be just read.
if this.payload_length < 2 {
if (marker == 0xFE) or // COM.
((0xE0 <= marker) and (marker < 0xF0)) { // APPn.
// Strictly speaking, this is invalid according to Section
// B.1.1.4 "Marker segments". However, libjpeg-turbo allows
// it (for COM and APPn markers; see its jdmarker.c file's
// skip_variable function) so we do too.
continue
}
return "#bad marker"
}
this.payload_length -= 2
@@ -454,8 +446,16 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
} else if marker < 0xD0 { // SOFn (Start of Frame) and friends.
if marker <= 0xC2 {
if this.sof_marker <> 0 {
if (marker == 0xC2) and this.reject_progressive_jpegs {
return "#rejected progressive JPEG"
} else if this.sof_marker <> 0 {
return "#bad SOF marker"
} else if (marker == 0xC0) {
// SOF0 (which is 0xC0) means a baseline JPEG. The baseline
// (th <= 1) restriction is specified in table B.5.
if this.seen_dht[2] or this.seen_dht[3] or this.seen_dht[6] or this.seen_dht[7] {
return "#bad SOF marker"
}
}
this.sof_marker = marker
this.decode_sof?(src: args.src)
@@ -465,8 +465,8 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
return "#unsupported lossless coding"
} else if marker == 0xC4 { // DHT (Define Huffman Table).
// We shouldn't see DHT before SOF.
return "#bad DHT marker"
this.decode_dht?(src: args.src)
continue
} else if (0xC5 <= marker) and (marker <= 0xC7) {
return "#unsupported hierarchical coding"
@@ -993,10 +993,10 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
// is long enough and setting this.swizzle_immediately.
this.swizzle_immediately = false
if this.components_workbuf_offsets[8] > args.workbuf.length() {
if this.sof_marker >= 0xC2 {
if (this.sof_marker >= 0xC2) or not this.use_lower_quality {
return base."#bad workbuf length"
}
this.swizzle_immediately = this.use_lower_quality
this.swizzle_immediately = true
this.swizzle_immediately_status = ok
} else if this.components_workbuf_offsets[4] < this.components_workbuf_offsets[8] {
args.workbuf[this.components_workbuf_offsets[4] .. this.components_workbuf_offsets[8]].bulk_memset!(byte_value: 0)
@@ -1119,9 +1119,6 @@ pri func decoder.decode_dht?(src: base.io_reader) {
var i : base.u32
var failed : base.bool
if this.sof_marker == 0 {
return "#bad DHT marker"
}
while this.payload_length > 0 {
if this.payload_length < 17 {
return "#bad DHT marker"
@@ -1382,7 +1379,7 @@ pri func decoder.decode_sos?(dst: ptr base.pixel_buffer, src: base.io_reader, wo
if bitstream_length < (this.bitstream_wi ~mod- this.bitstream_ri) {
break.fill_bitstream
} else if this.bitstream_padding == 0 {
return "#bad SOS marker"
return "#short SOS bitstream"
} else if args.src.is_closed() and (not this.bitstream_is_closed) {
if this.bitstream_wi < (0x800 / 2) {
assert this.bitstream_wi <= (this.bitstream_wi + 264) via "a <= (a + b): 0 <= b"()
@@ -1748,18 +1745,22 @@ pri func decoder.fill_bitstream!(src: base.io_reader) {
wi += 1
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
continue
} else if args.src.length() <= 1 {
break
}
} else if (args.src.peek_u16le() >> 8) > 0 {
break
} else {
c8 = args.src.peek_u8_at(offset: 1)
if c8 == 0x00 {
this.bitstream_buffer[wi] = 0xFF
wi += 1
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
continue
} else if c8 < 0xFF {
break
}
// Section B.1.1.2: "Any marker may optionally be preceded by any
// number of [0xFF] fill bytes".
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
}
// If we hit a "\xFF\x??" marker then pad the bitstream. In this method
+77
View File
@@ -0,0 +1,77 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// --------
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "jpeg" is 0x11_53D3. Left shifting by 10 gives
// 0x454F_4C00.
pri const QUIRKS_BASE : base.u32 = 0x454F_4C00
// --------
// When this quirk value is non-zero, the decoder will not support progressive
// JPEG images. When combined with setting base.QUIRK_QUALITY to "lower
// quality", this means that decoding will never require any temporary "work
// buffer" memory: decoder.workbuf_len will always return a range (a min and
// max pair) whose minimum value is zero.
//
// The maximum value can still be positive, as using more memory might lead to
// faster decoding, but a zero minimum means that it's valid for the caller to
// not allocate any memory for a work buffer.
//
// When opted into lower quality decoding, the workbuf_len minimum will be zero
// and positive for sequential and progressive JPEGs respectively, regardless
// of this QUIRK_REJECT_PROGRESSIVE_JPEGS key's value. But setting this quirk
// explicitly will produce a "#rejected progressive JPEG" error when
// encountering a progressive JPEG. This results in more readable calling code,
// instead of commenting about "positive work buffer minimum length implies a
// progressive JPEG".
pub const QUIRK_REJECT_PROGRESSIVE_JPEGS : base.u32 = 0x454F_4C00 | 0x00
// --------
// The base.QUIRK_QUALITY key is defined in the base package, not this package.
// Still, here's some documentation on how this package responds to that (key,
// value) quirk pair.
//
// If decoder.set_quirk is passed a base.QUIRK_QUALITY as the key argument
// then, when re-interpreting the u64 value argument as a signed i64 number, a
// negative number opts the decoder in to a slightly worse quality but leaner
// (less memory required) chroma upsampling algorithm.
//
// Negative (in i64 space) means >= 0x8000_0000_0000_0000 (in u64 space).
// base.QUIRK_QUALITY__VALUE__LOWER_QUALITY is one such value.
//
// Specifically, a negative quirk value uses a box filter. A non-negative quirk
// value (including the default value, zero) uses the same triangle filter that
// libjpeg-turbo also uses by default, which requires chroma upsampling on the
// edges of a MCU (Minimum Coded Unit) to remember adjacent MCU's values.
//
// Leaner means that for common (sequential) JPEG images, the range returned by
// decoder.workbuf_len will have a minimum value of zero, meaning that no work
// buffer memory needs to be allocated. Decoding rarer (progressive) JPEGs will
// still always require a positive amount of work buffer memory, for reasons
// unrelated to chroma upsampling. The exact amount required depends on factors
// like the JPEG image's width, height, component count and subsampling ratios.
//
// Regardless of the quirk value, as always, the workbuf_len method returns a
// range, whose min and max can be different. The caller is able to choose
// between providing the minimal amount of work buffer memory (for slightly
// slower decoding) or the maximal amount (for slightly faster decoding).
//
// Callers that never wish to allocate work buffer memory can simply reject
// progressive JPEGs (where "workbuf_len().min_incl > 0" despite setting the
// base.QUIRK_QUALITY key to a negative quirk value) as unsupported. See also
// QUIRK_REJECT_PROGRESSIVE_JPEGS.
//
// For some pictures comparing box and triangle filter decodings, see
// https://nigeltao.github.io/blog/2024/jpeg-chroma-upsampling.html
+24 -24
View File
@@ -12,9 +12,9 @@
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "json" is 0x12_4265. Left shifting by 10 gives
// 0x4909_9400.
pri const QUIRKS_BASE : base.u32 = 0x4909_9400
// The base38 encoding of "json" is 0x11_6642. Left shifting by 10 gives
// 0x4599_0800.
pri const QUIRKS_BASE : base.u32 = 0x4599_0800
// --------
@@ -30,22 +30,22 @@ pri const QUIRKS_BASE : base.u32 = 0x4909_9400
//
// Any indentation following a new line is not stripped, but remains part of
// the decoded string.
pub const QUIRK_ALLOW_ASCII_CONTROL_CODES : base.u32 = 0x4909_9400 | 0x00
pub const QUIRK_ALLOW_ASCII_CONTROL_CODES : base.u32 = 0x4599_0800 | 0x00
// When this quirk is enabled, e.g. "abc\az" is accepted as a JSON string,
// equivalent to "abc\u0007z", containing an ASCII Bell control character.
pub const QUIRK_ALLOW_BACKSLASH_A : base.u32 = 0x4909_9400 | 0x01
pub const QUIRK_ALLOW_BACKSLASH_A : base.u32 = 0x4599_0800 | 0x01
// When this quirk is enabled, e.g. "abc\U0001F4A9z" is accepted as a JSON
// string, equivalent to "abc\uD83D\uDCA9z", containing the U+0001F4A9 PILE OF
// POO Unicode code point. There are exactly 8 encoded bytes after each "\U".
//
// This quirk can combine with QUIRK_REPLACE_INVALID_UNICODE.
pub const QUIRK_ALLOW_BACKSLASH_CAPITAL_U : base.u32 = 0x4909_9400 | 0x02
pub const QUIRK_ALLOW_BACKSLASH_CAPITAL_U : base.u32 = 0x4599_0800 | 0x02
// When this quirk is enabled, e.g. "abc\ez" is accepted as a JSON string,
// equivalent to "abc\u001Bz", containing an ASCII Escape control character.
pub const QUIRK_ALLOW_BACKSLASH_E : base.u32 = 0x4909_9400 | 0x03
pub const QUIRK_ALLOW_BACKSLASH_E : base.u32 = 0x4599_0800 | 0x03
// When this quirk is enabled, e.g. ("abc\
// z") is accepted as a JSON string, equivalent to "abc\nz".
@@ -56,22 +56,22 @@ pub const QUIRK_ALLOW_BACKSLASH_E : base.u32 = 0x4909_9400 | 0x03
//
// Any indentation following a new line is not stripped, but remains part of
// the decoded string.
pub const QUIRK_ALLOW_BACKSLASH_NEW_LINE : base.u32 = 0x4909_9400 | 0x04
pub const QUIRK_ALLOW_BACKSLASH_NEW_LINE : base.u32 = 0x4599_0800 | 0x04
// When this quirk is enabled, e.g. "abc\?z" is accepted as a JSON string,
// equivalent to "abc?z".
pub const QUIRK_ALLOW_BACKSLASH_QUESTION_MARK : base.u32 = 0x4909_9400 | 0x05
pub const QUIRK_ALLOW_BACKSLASH_QUESTION_MARK : base.u32 = 0x4599_0800 | 0x05
// When this quirk is enabled, e.g. "abc\'z" is accepted as a JSON string,
// equivalent to "abc'z".
pub const QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE : base.u32 = 0x4909_9400 | 0x06
pub const QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE : base.u32 = 0x4599_0800 | 0x06
// When this quirk is enabled, e.g. "abc\vz" is accepted as a JSON string,
// equivalent to "abc\u000Bz", containing an ASCII Vertical Tab control
// character.
pub const QUIRK_ALLOW_BACKSLASH_V : base.u32 = 0x4909_9400 | 0x07
pub const QUIRK_ALLOW_BACKSLASH_V : base.u32 = 0x4599_0800 | 0x07
// (0x4909_9400 | 0x08) is reserved for QUIRK_ALLOW_BACKSLASH_X_AS_BYTES. This
// (0x4599_0800 | 0x08) is reserved for QUIRK_ALLOW_BACKSLASH_X_AS_BYTES. This
// quirk used to be implemented, but it was removed due to its complexity.
// Enabling it (as a run-time option) meant that decoded JSON strings are no
// longer guaranteed to be valid UTF-8. We could re-implement it (i.e. undo
@@ -86,11 +86,11 @@ pub const QUIRK_ALLOW_BACKSLASH_V : base.u32 = 0x4909_9400 | 0x07
//
// There are exactly 2 encoded bytes after each "\x". "\x", "\x9", "\x9$" and
// "\X99" are all still rejected.
pub const QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS : base.u32 = 0x4909_9400 | 0x09
pub const QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS : base.u32 = 0x4599_0800 | 0x09
// When this quirk is enabled, e.g. "abc\0z" is accepted as a JSON string,
// equivalent to "abc\u0000z", containing an ASCII NUL control character.
pub const QUIRK_ALLOW_BACKSLASH_ZERO : base.u32 = 0x4909_9400 | 0x0A
pub const QUIRK_ALLOW_BACKSLASH_ZERO : base.u32 = 0x4599_0800 | 0x0A
// When this quirk is enabled, "/* C/C++ style block comments */" are accepted
// anywhere whitespace would be. See also QUIRK_ALLOW_TRAILING_FILLER.
@@ -100,7 +100,7 @@ pub const QUIRK_ALLOW_BACKSLASH_ZERO : base.u32 = 0x4909_9400 | 0x0A
//
// To avoid ambiguity (as comments can contain new lines), this quirk cannot be
// combined with QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF.
pub const QUIRK_ALLOW_COMMENT_BLOCK : base.u32 = 0x4909_9400 | 0x0B
pub const QUIRK_ALLOW_COMMENT_BLOCK : base.u32 = 0x4599_0800 | 0x0B
// When this quirk is enabled, "// C/C++ style line comments\n" are accepted
// anywhere whitespace would be. See also QUIRK_ALLOW_TRAILING_FILLER.
@@ -119,7 +119,7 @@ pub const QUIRK_ALLOW_COMMENT_BLOCK : base.u32 = 0x4909_9400 | 0x0B
//
// To avoid ambiguity (as comments can contain new lines), this quirk cannot be
// combined with QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF.
pub const QUIRK_ALLOW_COMMENT_LINE : base.u32 = 0x4909_9400 | 0x0C
pub const QUIRK_ALLOW_COMMENT_LINE : base.u32 = 0x4599_0800 | 0x0C
// When this quirk is enabled, there may be a comma after the final array
// element or object key-value pair and before the closing "]" or "}". A comma
@@ -128,12 +128,12 @@ pub const QUIRK_ALLOW_COMMENT_LINE : base.u32 = 0x4909_9400 | 0x0C
//
// For example, `[1,]`, `[1,2,3,]` and `{"k":"v",}` all become acceptable, but
// `[,]`, `{,}` and `{"k",:"v"}` are still rejected.
pub const QUIRK_ALLOW_EXTRA_COMMA : base.u32 = 0x4909_9400 | 0x0D
pub const QUIRK_ALLOW_EXTRA_COMMA : base.u32 = 0x4599_0800 | 0x0D
// When this quirk is enabled, "inf", "Infinity", "NAN" and their
// case-insensitive variants, optionally preceded immediately by "-" or "+",
// are accepted anywhere a JSON number would be.
pub const QUIRK_ALLOW_INF_NAN_NUMBERS : base.u32 = 0x4909_9400 | 0x0E
pub const QUIRK_ALLOW_INF_NAN_NUMBERS : base.u32 = 0x4599_0800 | 0x0E
// When this quirk is enabled, the input byte stream may optionally start with
// "\x1E" (the ASCII Record Separator control character). That byte is skipped
@@ -145,7 +145,7 @@ pub const QUIRK_ALLOW_INF_NAN_NUMBERS : base.u32 = 0x4909_9400 | 0x0E
// When combined with QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF, this format is
// also known as RFC 7464, Json Text Sequences and MIME type
// "application/json-seq".
pub const QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR : base.u32 = 0x4909_9400 | 0x0F
pub const QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR : base.u32 = 0x4599_0800 | 0x0F
// When this quirk is enabled, the input byte stream may optionally start with
// "\xEF\xBB\xBF", the UTF-8 encoding of the Unicode BOM (Byte Order Mark).
@@ -153,7 +153,7 @@ pub const QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR : base.u32 = 0x4909_9400 |
//
// When combined with QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR, either mark
// may come first in the byte stream.
pub const QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK : base.u32 = 0x4909_9400 | 0x10
pub const QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK : base.u32 = 0x4599_0800 | 0x10
// When this quirk is enabled, following a successful decoding of a top-level
// JSON value, any trailing whitespace (ASCII characters 0x09, 0x0A, 0x0D or
@@ -166,7 +166,7 @@ pub const QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK : base.u32 = 0x4909_9400 |
// To avoid ambiguity, this quirk cannot be combined with
// QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF. Unlike that quirk, enabling this
// quirk will consume multiple trailing '\n' bytes.
pub const QUIRK_ALLOW_TRAILING_FILLER : base.u32 = 0x4909_9400 | 0x11
pub const QUIRK_ALLOW_TRAILING_FILLER : base.u32 = 0x4599_0800 | 0x11
// When this quirk is enabled, following a successful decoding of a top-level
// JSON value, any trailing whitespace (ASCII characters 0x09, 0x0A, 0x0D or
@@ -202,14 +202,14 @@ pub const QUIRK_ALLOW_TRAILING_FILLER : base.u32 = 0x4909_9400 | 0x11
// When combined with QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR, this format
// is also known as RFC 7464, Json Text Sequences and MIME type
// "application/json-seq".
pub const QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF : base.u32 = 0x4909_9400 | 0x12
pub const QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF : base.u32 = 0x4599_0800 | 0x12
// When this quirk is enabled, JSON Pointer strings containing "~n", "~r" or
// "~t", which would otherwise be invalid, are unescaped as "\n", "\r" or "\t".
//
// This quirk isn't used by Wuffs' std/json package per se, but it is used by
// the wuffs_aux::DecodeJson function.
pub const QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T : base.u32 = 0x4909_9400 | 0x13
pub const QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T : base.u32 = 0x4599_0800 | 0x13
// When this quirk is enabled, invalid UTF-8 inside a JSON string is accepted.
// Each byte of invalid UTF-8 is equivalent to "\uFFFD", the Unicode
@@ -225,6 +225,6 @@ pub const QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T : base.u32 = 0x4909_9
// When combined with QUIRK_ALLOW_BACKSLASH_CAPITAL_U, a "\U12345678" 10-byte
// unit that is an invalid Unicode code point (i.e. in the range U+D800 ..=
// U+DFFF or above U+10FFFF) is similarly replaced with U+FFFD.
pub const QUIRK_REPLACE_INVALID_UNICODE : base.u32 = 0x4909_9400 | 0x14
pub const QUIRK_REPLACE_INVALID_UNICODE : base.u32 = 0x4599_0800 | 0x14
pri const QUIRKS_COUNT : base.u32 = 0x15
+5 -5
View File
@@ -12,9 +12,9 @@
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "lzma" is 0x141638. Left shifting by 10 gives
// 0x5058_E000.
pri const QUIRKS_BASE : base.u32 = 0x5058_E000
// The base38 encoding of "lzma" is 0x13_3A15. Left shifting by 10 gives
// 0x4CE8_5400.
pri const QUIRKS_BASE : base.u32 = 0x4CE8_5400
// --------
@@ -22,7 +22,7 @@ pri const QUIRKS_BASE : base.u32 = 0x5058_E000
// initial byte [after properties or other headers] is not equal to ZERO, the
// LZMA Decoder must stop decoding and report error" from the spec
// https://raw.githubusercontent.com/jljusten/LZMA-SDK/781863cdf592da3e97420f50de5dac056ad352a5/DOC/lzma-specification.txt
pub const QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE : base.u32 = 0x5058_E000 | 0x00
pub const QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE : base.u32 = 0x4CE8_5400 | 0x00
// When this quirk is set, a positive value indicates an extension to the LZMA
// format. Zero means to use the default LZMA format.
@@ -39,4 +39,4 @@ pub const QUIRK_ALLOW_NON_ZERO_INITIAL_BYTE : base.u32 = 0x5058_E000 | 0x00
// For LZMA2, the high 7 bytes (shifted right by 8) must be less than or equal
// to 40 and indicates the dictionary size. See section "5.3.1. LZMA2" of
// https://tukaani.org/xz/xz-file-format.txt
pub const QUIRK_FORMAT_EXTENSION : base.u32 = 0x5058_E000 | 0x01
pub const QUIRK_FORMAT_EXTENSION : base.u32 = 0x4CE8_5400 | 0x01
+4 -4
View File
@@ -12,13 +12,13 @@
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "lzw " is 0x1417A8. Left shifting by 10 gives
// 0x505E_A000.
pri const QUIRKS_BASE : base.u32 = 0x505E_A000
// The base38 encoding of "lzw." is 0x13_3B86. Left shifting by 10 gives
// 0x4CEE_1800.
pri const QUIRKS_BASE : base.u32 = 0x4CEE_1800
// --------
// When this quirk is set (to a value in the range 0 ..= 9), a positive value
// is one more than the initial number of bits of a literal code. Zero means to
// use the default literal width, 8.
pub const QUIRK_LITERAL_WIDTH_PLUS_ONE : base.u32 = 0x505E_A000 | 0x00
pub const QUIRK_LITERAL_WIDTH_PLUS_ONE : base.u32 = 0x4CEE_1800 | 0x00
+414
View File
@@ -0,0 +1,414 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
pub status "#bad footer"
pub status "#bad header"
pub status "#truncated input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.image_decoder(
pixfmt : base.u32,
width : base.u32[..= 0xFF_FFFF],
height : base.u32[..= 0xFF_FFFF],
remaining_pixels_times_4 : base.u64,
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
call_sequence : base.u8,
buffer_index : base.u32[..= 8192],
dst_x : base.u32,
dst_y : base.u32,
swizzler : base.pixel_swizzler,
util : base.utility,
) + (
pixel : array[4] base.u8,
cache : array[256] base.u8,
buffer : array[8192 + 4] base.u8,
)
pub func decoder.get_quirk(key: base.u32) base.u64 {
return 0
}
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
return base."#unsupported option"
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_decode_image_config?(dst: args.dst, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var a : base.u32
if this.call_sequence <> 0x00 {
return base."#bad call sequence"
}
a = args.src.read_u32le?()
if a <> 'qoif'le {
return "#bad header"
}
a = args.src.read_u32be?()
if a > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.width = a
a = args.src.read_u32be?()
if a > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.height = a
a = args.src.read_u8_as_u32?()
if a == 3 {
this.pixfmt = base.PIXEL_FORMAT__BGRX
} else if a == 4 {
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
} else {
return "#bad header"
}
args.src.skip?(n: 1)
if args.dst <> nullptr {
args.dst.set!(
pixfmt: this.pixfmt,
pixsub: 0,
width: this.width,
height: this.height,
first_frame_io_position: 14,
first_frame_is_opaque: this.pixfmt == base.PIXEL_FORMAT__BGRX)
}
this.call_sequence = 0x20
}
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_decode_frame_config?(dst: args.dst, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
this.do_decode_image_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 0x28 {
if 14 <> args.src.position() {
return base."#bad restart"
}
} else if this.call_sequence == 0x40 {
this.call_sequence = 0x60
return base."@end of data"
} else {
return base."@end of data"
}
if args.dst <> nullptr {
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: this.width,
max_excl_y: this.height),
duration: 0,
index: 0,
io_position: 14,
disposal: 0,
opaque_within_bounds: this.pixfmt == base.PIXEL_FORMAT__BGRX,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
}
this.call_sequence = 0x40
}
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var status : base.status
while true {
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var status : base.status
var c64 : base.u64
if this.call_sequence == 0x40 {
// No-op.
} else if this.call_sequence < 0x40 {
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
status = this.swizzler.prepare!(
dst_pixfmt: args.dst.pixel_format(),
dst_palette: args.dst.palette(),
src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
src_palette: this.util.empty_slice_u8(),
blend: args.blend)
if not status.is_ok() {
return status
}
this.dst_x = 0
this.dst_y = 0
this.pixel[0] = 0x00
this.pixel[1] = 0x00
this.pixel[2] = 0x00
this.pixel[3] = 0xFF
this.cache[.. 256].bulk_memset!(byte_value: 0)
this.remaining_pixels_times_4 = (this.width as base.u64) * (this.height as base.u64) * 4
while this.remaining_pixels_times_4 > 0 {
this.from_src_to_buffer?(src: args.src)
if this.remaining_pixels_times_4 < (this.buffer_index as base.u64) {
return base."#too much data"
}
this.remaining_pixels_times_4 -= this.buffer_index as base.u64
status = this.from_buffer_to_dst!(dst: args.dst)
if not status.is_ok() {
return status
}
}
c64 = args.src.read_u64be?()
if c64 <> 1 {
return "#bad footer"
}
this.call_sequence = 0x60
}
pri func decoder.from_src_to_buffer?(src: base.io_reader) {
var c8 : base.u8
var dg : base.u8
var bi : base.u32[..= 8192]
var bj : base.u32[..= 8188]
var bk : base.u32[..= 7936]
var ci : base.u32[..= 252]
var hash4 : base.u32[..= 252]
bk = 7936 // 4 * (2048 - 64), so we always have room for a QOI_OP_RUN.
if this.remaining_pixels_times_4 < 7936 {
bk = this.remaining_pixels_times_4 as base.u32
}
while bi < bk {
assert bi < 7936 via "a < b: a < c; c <= b"(c: bk)
c8 = args.src.read_u8?()
if c8 == 0xFE { // QOI_OP_RGB.
this.pixel[2] = args.src.read_u8?()
this.pixel[1] = args.src.read_u8?()
this.pixel[0] = args.src.read_u8?()
} else if c8 == 0xFF { // QOI_OP_RGBA.
this.pixel[2] = args.src.read_u8?()
this.pixel[1] = args.src.read_u8?()
this.pixel[0] = args.src.read_u8?()
this.pixel[3] = args.src.read_u8?()
} else if (c8 >> 6) == 0 { // QOI_OP_INDEX.
ci = 4 * ((c8 & 0x3F) as base.u32)
this.pixel[0] = this.cache[ci + 0]
this.pixel[1] = this.cache[ci + 1]
this.pixel[2] = this.cache[ci + 2]
this.pixel[3] = this.cache[ci + 3]
this.buffer[bi + 0] = this.pixel[0]
this.buffer[bi + 1] = this.pixel[1]
this.buffer[bi + 2] = this.pixel[2]
this.buffer[bi + 3] = this.pixel[3]
bi += 4
continue
} else if (c8 >> 6) == 1 { // QOI_OP_DIFF.
this.pixel[2] ~mod+= ((c8 >> 4) & 0x03) ~mod+ 0xFE
this.pixel[1] ~mod+= ((c8 >> 2) & 0x03) ~mod+ 0xFE
this.pixel[0] ~mod+= ((c8 >> 0) & 0x03) ~mod+ 0xFE
} else if (c8 >> 6) == 2 { // QOI_OP_LUMA.
dg = (c8 & 0x3F) ~mod+ 0xE0
c8 = args.src.read_u8?()
this.pixel[2] ~mod+= (dg ~mod+ 0xF8) ~mod+ (0x0F & (c8 >> 4))
this.pixel[1] ~mod+= dg
this.pixel[0] ~mod+= (dg ~mod+ 0xF8) ~mod+ (0x0F & (c8 >> 0))
} else { // QOI_OP_RUN.
bj = bi + (4 * (0x3F & (1 + (c8 as base.u32))))
while bi < bj {
assert bi < 8188 via "a < b: a < c; c <= b"(c: bj)
this.buffer[bi + 0] = this.pixel[0]
this.buffer[bi + 1] = this.pixel[1]
this.buffer[bi + 2] = this.pixel[2]
this.buffer[bi + 3] = this.pixel[3]
bi += 4
}
continue
}
hash4 = 4 * (63 & (
((this.pixel[2] as base.u32) * 3) +
((this.pixel[1] as base.u32) * 5) +
((this.pixel[0] as base.u32) * 7) +
((this.pixel[3] as base.u32) * 11)))
this.cache[hash4 + 0] = this.pixel[0]
this.cache[hash4 + 1] = this.pixel[1]
this.cache[hash4 + 2] = this.pixel[2]
this.cache[hash4 + 3] = this.pixel[3]
this.buffer[bi + 0] = this.pixel[0]
this.buffer[bi + 1] = this.pixel[1]
this.buffer[bi + 2] = this.pixel[2]
this.buffer[bi + 3] = this.pixel[3]
bi += 4
}
this.buffer_index = bi
}
pri func decoder.from_buffer_to_dst!(dst: ptr base.pixel_buffer) base.status {
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var tab : table base.u8
var bi : base.u32
var rem_x : base.u32[..= 0xFF_FFFF]
var dst : slice base.u8
var src : slice base.u8
var src_length : base.u32
var i : base.u64
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
dst_pixfmt = args.dst.pixel_format()
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = dst_bits_per_pixel / 8
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
tab = args.dst.plane(p: 0)
while bi < this.buffer_index {
assert bi < 8192 via "a < b: a < c; c <= b"(c: this.buffer_index)
if this.width <= this.dst_x {
this.dst_x = 0
this.dst_y ~mod+= 1
if this.dst_y >= this.height {
break
}
rem_x = this.width
} else {
rem_x = this.width - this.dst_x
}
src = this.buffer[bi .. this.buffer_index]
if ((4 * rem_x) as base.u64) < src.length() {
src = src[.. (4 * rem_x) as base.u64]
}
src_length = (src.length() & 0xFFFF_FFFF) as base.u32
bi ~mod+= src_length
dst = tab.row_u32(y: this.dst_y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
i = (this.dst_x as base.u64) * (dst_bytes_per_pixel as base.u64)
this.dst_x ~mod+= src_length / 4
if i < dst.length() {
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst[i ..],
dst_palette: args.dst.palette(),
src: src)
}
}
return ok
}
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
return this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: this.width,
max_excl_y: this.height)
}
pub func decoder.num_animation_loops() base.u32 {
return 0
}
pub func decoder.num_decoded_frame_configs() base.u64 {
if this.call_sequence > 0x20 {
return 1
}
return 0
}
pub func decoder.num_decoded_frames() base.u64 {
if this.call_sequence > 0x40 {
return 1
}
return 0
}
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
if this.call_sequence < 0x20 {
return base."#bad call sequence"
}
if (args.index <> 0) or (args.io_position <> 14) {
return base."#bad argument"
}
this.call_sequence = 0x28
return ok
}
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
// No-op. QOI doesn't support metadata.
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
return base."#no more information"
}
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
}
@@ -11,7 +11,7 @@
pub status "#bad header"
pub status "#bad run length encoding"
pub status "#truncated input"
pub status "#unsupported TGA file"
pub status "#unsupported TARGA file"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
@@ -104,7 +104,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
// We have a color-mapped image (in Wuffs, an indexed pixel format).
if (this.header_color_map_first_entry_index <> 0) or
(this.header_color_map_length > 0x100) {
return "#unsupported TGA file"
return "#unsupported TARGA file"
} else if (this.header_color_map_entry_size <> 0x0F) and
(this.header_color_map_entry_size <> 0x10) and
(this.header_color_map_entry_size <> 0x18) and
@@ -162,7 +162,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
this.src_bytes_per_pixel = 4
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
} else {
return "#unsupported TGA file"
return "#unsupported TARGA file"
}
} else {
@@ -172,14 +172,14 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
this.src_pixfmt = base.PIXEL_FORMAT__Y
this.opaque = true
} else {
return "#unsupported TGA file"
return "#unsupported TARGA file"
}
}
this.header_image_descriptor = args.src.read_u8?()
if (this.header_image_descriptor & 0x10) <> 0 {
// We don't support right-to-left, only left-to-right pixel order.
return "#unsupported TGA file"
return "#unsupported TARGA file"
}
// Skip the Image ID.
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// --------
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "th.." is 0x19_83D8. Left shifting by 10 gives
// 0x660F_6000.
pri const QUIRKS_BASE : base.u32 = 0x660F_6000
// --------
// When this quirk is enabled, the decoder speaks just raw thumbhash, without
// the "\xC3\xBE\xFE" magic identifier to start the file.
//
// Enabling this quirk matches the behavior of the original JavaScript
// reference implementation at https://evanw.github.io/thumbhash/
pub const QUIRK_JUST_RAW_THUMBHASH : base.u32 = 0x660F_6000 | 0x00
+1023
View File
@@ -0,0 +1,1023 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// --------
// Thumbhash is a tiny image format (maximum image dimensions are 32×32 pixels;
// maximum image file size is 29 bytes or 32 bytes with a 3-byte header), based
// on the Discrete Cosine Transform.
//
// https://evanw.github.io/thumbhash/ has the original description and
// implementation. This implementation assumes a 3-byte magic identifier is
// prepended, unless QUIRK_JUST_RAW_THUMBHASH is enabled, so that /usr/bin/file
// or similar programs can identify the data as thumbhash-formatted data.
//
// That 3-byte magic string is "\xC3\xBE\xFE", which is arbitrary and not part
// of the original thumbhash description or implementation. But "\xC3\xBE" is
// the UTF-8 encoding of 'þ' (U+00FE LATIN SMALL LETTER THORN) and "\xFE" is
// invalid UTF-8 but is the ISO-8859-1 encoding of 'þ'. The Old English letter
// 'þ' is pronounced like the "th" that starts "thumbhash".
//
// This implementation also uses fixed point math instead of floating point.
pub status "#bad header"
pub status "#truncated input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.image_decoder(
pixfmt : base.u32,
w_dimension_code : base.u8[..= 7],
h_dimension_code : base.u8[..= 7],
// The call sequence state machine is discussed in
// (/doc/std/image-decoders-call-sequence.md).
call_sequence : base.u8,
frame_config_io_position : base.u8[..= 9],
// The L, P and Q DC values occupy 6 bits in the file format.
// Conceptually, they range from 0 to 1 (for L) or from -1 to +1 (for P
// and Q). That's what values are calculated in the original JavaScript
// reference implementation, which uses floating point.
//
// This implementation uses fixed point. The fx and fy cosine tables
// and the FROM_4_BITS_TO_PLUS_MINUS_ETC tables are all stored as 2.14
// signed fixed point (represented in this code as a base.u16, since
// Wuffs as of 2024 only speaks unsigned integers). Multiplying two of
// those uses 4.28 (as a base.u32). Multiplying three of those uses
// 22.42 (as a base.u64).
//
// We eventually combine L, P and Q values so we need them to use the
// same denominator. l_scale is out of 31 and p_scale and q_scale are
// out of 63, so the common denominator is ((63 * 31) << 42) =
// 8589_384836_186112 = 0x001E_8400_0000_0000.
//
// The A channel is not combined with L, P or Q and a_scale is out of
// 15, so we can keep the a_dc denominator at (15 << 42).
//
// Let LDENOM = ((63 * 31) << 14) = 0x01E8_4000.
//
// Let ADENOM = ( 15 << 14) = 0x0003_C000.
l_dc : base.u64, // Fixed-point denominator is (LDENOM << 28).
p_dc : base.u64, // Fixed-point denominator is (LDENOM << 28).
q_dc : base.u64, // Fixed-point denominator is (LDENOM << 28).
a_dc : base.u64, // Fixed-point denominator is (ADENOM << 28).
quirk_just_raw_thumbhash : base.bool,
l_scale : base.u8[..= 31],
p_scale : base.u8[..= 63],
q_scale : base.u8[..= 63],
a_scale : base.u8[..= 15],
// The first three fields determine lx and ly: the exclusive max of the
// (cx, cy) pairs indexing two-dimensional AC coefficients. The (0, 0)
// pair is the DC coefficient. (lx / ly) is also the image's aspect
// ratio, after rounding width and height to a whole number of pixels
// such that the longest dimension is 32.
//
// Let lminor and lmajor alias lx and ly if is_landscape is 0 (false).
// If is_landscape is 1 (true) then these are swapped.
//
// lminor equals max(3, l_count). lmajor equals 7 or 5, depending on
// whether has_alpha is 0 or 1. For example, if has_alpha = 0, l_count
// = 5 and is_landscape = 1 then lx = 7 and ly = 5, so that width = 32
// and height = 23.
//
// lx and ly then detemine the number of L AC coefficients (the number
// of lac elements that are used), ranging in 10 ..= 27. The number for
// P and Q is always 5 and the number for A is 0 or 14, depending on
// has_alpha. Total file size is an optional 3-byte magic identifier
// plus (5 + has_alpha) bytes of header plus 4 bits per AC coefficient.
// As a table:
//
// When has_alpha = 0 and is_landscape = 0:
// l_count: 3 lx / ly = 3 / 7 w = 14 h = 32 #lac = 14 #pac = #qac = 5 #aac = 0 file_size = 3 + 17
// l_count: 4 lx / ly = 4 / 7 w = 18 h = 32 #lac = 18 #pac = #qac = 5 #aac = 0 file_size = 3 + 19
// l_count: 5 lx / ly = 5 / 7 w = 23 h = 32 #lac = 22 #pac = #qac = 5 #aac = 0 file_size = 3 + 21
// l_count: 6 lx / ly = 6 / 7 w = 27 h = 32 #lac = 26 #pac = #qac = 5 #aac = 0 file_size = 3 + 23
// l_count: 7 lx / ly = 7 / 7 w = 32 h = 32 #lac = 27 #pac = #qac = 5 #aac = 0 file_size = 3 + 24
//
// When has_alpha = 1 and is_landscape = 0:
// l_count: 3 lx / ly = 3 / 5 w = 19 h = 32 #lac = 10 #pac = #qac = 5 #aac = 14 file_size = 3 + 23
// l_count: 4 lx / ly = 4 / 5 w = 26 h = 32 #lac = 13 #pac = #qac = 5 #aac = 14 file_size = 3 + 25
// l_count: 5 lx / ly = 5 / 5 w = 32 h = 32 #lac = 14 #pac = #qac = 5 #aac = 14 file_size = 3 + 25
// l_count: 6 lx / ly = 6 / 5 w = 32 h = 27 #lac = 19 #pac = #qac = 5 #aac = 14 file_size = 3 + 28
// l_count: 7 lx / ly = 7 / 5 w = 32 h = 23 #lac = 22 #pac = #qac = 5 #aac = 14 file_size = 3 + 29
//
// A "(cx * ly) < (lx * (ly - cy))" constraint determines which L AC
// coefficients are used. Here are some visualizations, where 'D' is
// the DC coefficient. When has_alpha = 0:
// - the 14 '3' coefficients are always used,
// - the (18 - 14) '4' coefficients are also used when (l_count >= 4),
// - the (22 - 18) '5' coefficients are also used when (l_count >= 5),
// - the (26 - 22) '6' coefficients are also used when (l_count >= 6),
// - the (27 - 26) '7' coefficients are also used when (l_count >= 7),
//
// When has_alpha = 0:
// D334567
// 333456
// 33356
// 3346
// 335
// 34
// 3
//
// When has_alpha = 1:
// D334567
// 333467
// 33467
// 336
// 36
//
// The same visualization for P and Q:
// D33
// 33
// 3
//
// The same visualization for A (when has_alpha = 1):
// D3333
// 3333
// 333
// 33
// 3
has_alpha : base.u8[..= 1],
l_count : base.u8[..= 7],
is_landscape : base.u8[..= 1],
lx : base.u32[..= 7],
ly : base.u32[..= 7],
swizzler : base.pixel_swizzler,
util : base.utility,
) + (
// AC coefficients, doubled (†) when stored here to simplify the later
// (fx[cx] * fy[cy]) calculation in from_coeffs_to_pixels.
//
// Before doubling, these conceptually range from -1 to +1 (for L and
// A) or from -1.25 to +1.25 (for P and Q, boosted "to compensate for
// quantization" in the original JavaScript reference implementation).
//
// These AC values will eventually be multiplied by fx[cx] and fy[cy],
// both of which are 2.14 signed fixed point, so these fixed point
// values use the DC value denominators right-shifted by 28: LDENOM =
// ((63 * 31) << 14) for L, P and Q and ADENOM = (15 << 14) for A.
//
// For example, if lac[10] was 23998464 as a base.u32 here in Wuffs
// code, the corresponding undoubled floating point value in JavaScript
// code would be (23998464.0 / (2 * LDENOM)) = 0.375.
//
// Not every element is used, only the first up-to-27 (lac), 5 (pac and
// qac) or 14 (aac). But we round up the array sizes up to a power of 2
// (and bitwise-and the array indexes) to simplify bounds checking.
lac : array[32] base.u32, // Fixed-point denominator is LDENOM.
pac : array[8] base.u32, // Fixed-point denominator is LDENOM.
qac : array[8] base.u32, // Fixed-point denominator is LDENOM.
aac : array[16] base.u32, // Fixed-point denominator is ADENOM.
// 32 rows, 32 BGRA pixels per row.
pixels : array[32] array[128] base.u8,
)
pub func decoder.get_quirk(key: base.u32) base.u64 {
if (args.key == QUIRK_JUST_RAW_THUMBHASH) and this.quirk_just_raw_thumbhash {
return 1
}
return 0
}
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
if args.key == QUIRK_JUST_RAW_THUMBHASH {
this.quirk_just_raw_thumbhash = args.value > 0
return ok
}
return base."#unsupported option"
}
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_decode_image_config?(dst: args.dst, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
var c32 : base.u32
var swap : base.u8[..= 7]
if this.call_sequence <> 0x00 {
return base."#bad call sequence"
}
if not this.quirk_just_raw_thumbhash {
c32 = args.src.read_u24le_as_u32?()
if c32 <> '\xC3\xBE\xFE'le {
return "#bad header"
}
}
c32 = args.src.read_u24le_as_u32?()
this.l_dc = (((c32 >> 0x00) & 63) as base.u64) * (31 << 42)
this.p_dc = ((((c32 >> 0x06) & 63) as base.u64) * (31 << 43)) ~mod- ((63 * 31) << 42)
this.q_dc = ((((c32 >> 0x0C) & 63) as base.u64) * (31 << 43)) ~mod- ((63 * 31) << 42)
this.l_scale = ((c32 >> 0x12) & 31) as base.u8
this.has_alpha = ((c32 >> 0x17) & 1) as base.u8
c32 = args.src.read_u16le_as_u32?()
this.l_count = ((c32 >> 0x00) & 7) as base.u8
this.p_scale = ((c32 >> 0x03) & 63) as base.u8
this.q_scale = ((c32 >> 0x09) & 63) as base.u8
this.is_landscape = ((c32 >> 0x0F) & 1) as base.u8
this.w_dimension_code = (DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[this.has_alpha][this.l_count] >> 4) & 7
this.h_dimension_code = (DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT[this.has_alpha][this.l_count] >> 0) & 7
if this.is_landscape <> 0 {
swap = this.w_dimension_code
this.w_dimension_code = this.h_dimension_code
this.h_dimension_code = swap
}
if this.is_landscape <> 0 {
this.lx = (7 - (2 * this.has_alpha)) as base.u32
this.ly = (this.l_count.max(no_less_than: 3)) as base.u32
} else {
this.lx = (this.l_count.max(no_less_than: 3)) as base.u32
this.ly = (7 - (2 * this.has_alpha)) as base.u32
}
this.frame_config_io_position = 8
assert this.frame_config_io_position >= 8
if this.has_alpha <> 0 {
c32 = args.src.read_u8_as_u32?()
this.a_dc = (((c32 >> 0x00) & 15) as base.u64) << 42
this.a_scale = ((c32 >> 0x04) & 15) as base.u8
this.frame_config_io_position = 9
assert this.frame_config_io_position >= 8
}
if this.quirk_just_raw_thumbhash {
this.frame_config_io_position -= 3
}
this.pixfmt = base.PIXEL_FORMAT__BGRX
if this.has_alpha <> 0 {
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
}
if args.dst <> nullptr {
args.dst.set!(
pixfmt: this.pixfmt,
pixsub: 0,
width: DIMENSIONS_FROM_DIMENSION_CODES[this.w_dimension_code] as base.u32,
height: DIMENSIONS_FROM_DIMENSION_CODES[this.h_dimension_code] as base.u32,
first_frame_io_position: this.frame_config_io_position as base.u64,
first_frame_is_opaque: this.has_alpha == 0)
}
this.call_sequence = 0x20
}
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
var status : base.status
while true {
status =? this.do_decode_frame_config?(dst: args.dst, src: args.src)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
if this.call_sequence == 0x20 {
// No-op.
} else if this.call_sequence < 0x20 {
this.do_decode_image_config?(dst: nullptr, src: args.src)
} else if this.call_sequence == 0x28 {
if (this.frame_config_io_position as base.u64) <> args.src.position() {
return base."#bad restart"
}
} else if this.call_sequence == 0x40 {
this.call_sequence = 0x60
return base."@end of data"
} else {
return base."@end of data"
}
if args.dst <> nullptr {
args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: DIMENSIONS_FROM_DIMENSION_CODES[this.w_dimension_code] as base.u32,
max_excl_y: DIMENSIONS_FROM_DIMENSION_CODES[this.h_dimension_code] as base.u32),
duration: 0,
index: 0,
io_position: this.frame_config_io_position as base.u64,
disposal: 0,
opaque_within_bounds: this.has_alpha == 0,
overwrite_instead_of_blend: false,
background_color: 0x0000_0000)
}
this.call_sequence = 0x40
}
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var status : base.status
while true {
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
if (status == base."$short read") and args.src.is_closed() {
return "#truncated input"
}
yield? status
}
}
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
var status : base.status
if this.call_sequence == 0x40 {
// No-op.
} else if this.call_sequence < 0x40 {
this.do_decode_frame_config?(dst: nullptr, src: args.src)
} else {
return base."@end of data"
}
status = this.swizzler.prepare!(
dst_pixfmt: args.dst.pixel_format(),
dst_palette: args.dst.palette(),
src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
src_palette: this.util.empty_slice_u8(),
blend: args.blend)
if not status.is_ok() {
return status
}
this.from_src_to_coeffs?(src: args.src)
this.from_coeffs_to_pixels!()
status = this.from_pixels_to_dst!(dst: args.dst)
if not status.is_ok() {
return status
}
this.call_sequence = 0x60
}
pri func decoder.from_src_to_coeffs?(src: base.io_reader) {
var c8 : base.u8
var cy : base.u32
var cx : base.u32
var i : base.u32
var has_bits : base.bool
// Read L AC coefficients.
i = 0
cy = 0
while cy < this.ly {
cx = 0
if cy == 0 {
cx = 1
}
while (cx ~mod* this.ly) < (this.lx ~mod* (this.ly ~mod- cy)) {
if has_bits {
has_bits = false
c8 >>= 4
} else {
has_bits = true
c8 = args.src.read_u8?()
}
// Multiply by (63 * 2) to double (†) and get to LDENOM.
this.lac[i & 31] = ((this.l_scale as base.u32) ~mod* 126) ~mod*
this.util.sign_extend_convert_u16_u32(a: FROM_4_BITS_TO_PLUS_MINUS_1_00[c8 & 15])
i ~mod+= 1
cx ~mod+= 1
}
cy ~mod+= 1
}
// Read P AC coefficients.
i = 0
cx = 0
while cx < 5 {
if has_bits {
has_bits = false
c8 >>= 4
} else {
has_bits = true
c8 = args.src.read_u8?()
}
// Multiply by (31 * 2) to double (†) and get to LDENOM.
this.pac[i & 7] = ((this.p_scale as base.u32) ~mod* 62) ~mod*
this.util.sign_extend_convert_u16_u32(a: FROM_4_BITS_TO_PLUS_MINUS_1_25[c8 & 15])
i ~mod+= 1
cx ~mod+= 1
}
// Read Q AC coefficients.
i = 0
cx = 0
while cx < 5 {
if has_bits {
has_bits = false
c8 >>= 4
} else {
has_bits = true
c8 = args.src.read_u8?()
}
// Multiply by (31 * 2) to double (†) and get to LDENOM.
this.qac[i & 7] = ((this.q_scale as base.u32) ~mod* 62) ~mod*
this.util.sign_extend_convert_u16_u32(a: FROM_4_BITS_TO_PLUS_MINUS_1_25[c8 & 15])
i ~mod+= 1
cx ~mod+= 1
}
// Read A AC coefficients.
if this.has_alpha == 0 {
return ok
}
i = 0
cx = 0
while cx < 14 {
if has_bits {
has_bits = false
c8 >>= 4
} else {
has_bits = true
c8 = args.src.read_u8?()
}
// Multiply by 2 to double (†). We're already at ADENOM.
this.aac[i & 15] = ((this.a_scale as base.u32) ~mod* 2) ~mod*
this.util.sign_extend_convert_u16_u32(a: FROM_4_BITS_TO_PLUS_MINUS_1_00[c8 & 15])
i ~mod+= 1
cx ~mod+= 1
}
}
pri func decoder.from_coeffs_to_pixels!() {
var h : base.u32[..= 32]
var w : base.u32[..= 32]
// fx[7] and fy[7] are unused but we round up the array sizes up to a power
// of 2 (and bitwise-and the array indexes) to simplify bounds checking.
var fy : array[8] base.u32
var fx : array[8] base.u32
var cosines_base_y : base.u32[..= 127]
var cosines_base_x : base.u32[..= 127]
var y : base.u32
var x : base.u32
var f : base.u32
var l : base.u64
var p : base.u64
var q : base.u64
var b : base.u64
var g : base.u64
var r : base.u64
var a : base.u64
var i : base.u32
var cy : base.u32
var cx : base.u32
h = DIMENSIONS_FROM_DIMENSION_CODES[this.h_dimension_code] as base.u32
w = DIMENSIONS_FROM_DIMENSION_CODES[this.w_dimension_code] as base.u32
fy[0] = 0x4000 // This is always cos(0), scaled by 0x4000 = (1 << 14).
fx[0] = 0x4000 // This is always cos(0), scaled by 0x4000 = (1 << 14).
a = 0xFF
y = 0
while y < h {
assert y < 32 via "a < b: a < c; c <= b"(c: h)
cosines_base_y = CUMULATIVE_DIMENSIONS[this.h_dimension_code] as base.u32
fy[1] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_y + y][0])
fy[2] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_y + y][1])
fy[3] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_y + y][2])
fy[4] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_y + y][3])
fy[5] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_y + y][4])
fy[6] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_y + y][5])
// The original JavaScript reference implementation also multiplied
// fy[cy] by 2 but we have already adjusted for that (†).
x = 0
while x < w,
inv y < 32,
{
assert x < 32 via "a < b: a < c; c <= b"(c: w)
cosines_base_x = CUMULATIVE_DIMENSIONS[this.w_dimension_code] as base.u32
fx[1] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_x + x][0])
fx[2] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_x + x][1])
fx[3] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_x + x][2])
fx[4] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_x + x][3])
fx[5] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_x + x][4])
fx[6] = this.util.sign_extend_convert_u16_u32(a: COSINES[cosines_base_x + x][5])
// Accumulate L.
l = this.l_dc
i = 0
cy = 0
while cy < this.ly,
inv y < 32,
inv x < 32,
{
cx = 0
if cy == 0 {
cx = 1
}
while (cx ~mod* this.ly) < (this.lx ~mod* (this.ly ~mod- cy)),
inv y < 32,
inv x < 32,
{
f = fx[cx & 7] ~mod* fy[cy & 7]
l ~mod+= this.util.sign_extend_convert_u32_u64(a: f) ~mod*
this.util.sign_extend_convert_u32_u64(a: this.lac[i & 31])
i ~mod+= 1
cx ~mod+= 1
}
cy ~mod+= 1
}
// Accumulate P and Q.
p = this.p_dc
q = this.q_dc
i = 0
cy = 0
while cy < 3,
inv y < 32,
inv x < 32,
{
cx = 0
if cy == 0 {
cx = 1
}
while cx < (3 - cy),
inv y < 32,
inv x < 32,
inv cy < 3,
{
assert cx < 3 via "a < b: a < c; c <= b"(c: 3 - cy)
f = fx[cx] ~mod* fy[cy]
p ~mod+= this.util.sign_extend_convert_u32_u64(a: f) ~mod*
this.util.sign_extend_convert_u32_u64(a: this.pac[i & 7])
q ~mod+= this.util.sign_extend_convert_u32_u64(a: f) ~mod*
this.util.sign_extend_convert_u32_u64(a: this.qac[i & 7])
i ~mod+= 1
cx ~mod+= 1
}
cy ~mod+= 1
}
// Convert LPQ to RGB. The code is the i64 equivalents of:
// b = l - ((2 * p) / 3)
// r = (((3 * l) + q) - b) / 2
// g = r - q
b = l ~mod- this.util.i64_divide(a: 2 ~mod* p, b: 3)
r = this.util.sign_extend_rshift_u64(a: ((3 ~mod* l) ~mod+ q) ~mod- b, n: 1)
g = r ~mod- q
// Rescale from (LDENOM << 28) to 255 and clamp.
//
// (LDENOM << 28) = 8589_384836_186112 = (33_683862_102690 * 255) + 162
//
// Rounding down (instead of rounding to nearest) more closely
// matches the original JavaScript reference implementation. The
// two implementations aren't a 100% match, due to floating point
// versus fixed point rounding errors, but they're pretty close.
if (b >> 63) <> 0 {
b = 0
} else if b >= (33_683862_102690 * 255) {
b = 255
} else {
b /= 33_683862_102690
}
if (g >> 63) <> 0 {
g = 0
} else if g >= (33_683862_102690 * 255) {
g = 255
} else {
g /= 33_683862_102690
}
if (r >> 63) <> 0 {
r = 0
} else if r >= (33_683862_102690 * 255) {
r = 255
} else {
r /= 33_683862_102690
}
// Accumulate, rescale from (ADENOM << 28) and clamp A.
if this.has_alpha <> 0 {
a = this.a_dc
i = 0
cy = 0
while cy < 5,
inv y < 32,
inv x < 32,
{
cx = 0
if cy == 0 {
cx = 1
}
while cx < (5 - cy),
inv y < 32,
inv x < 32,
inv cy < 5,
{
assert cx < 5 via "a < b: a < c; c <= b"(c: 5 - cy)
f = fx[cx] ~mod* fy[cy]
a ~mod+= this.util.sign_extend_convert_u32_u64(a: f) ~mod*
this.util.sign_extend_convert_u32_u64(a: this.aac[i & 15])
i ~mod+= 1
cx ~mod+= 1
}
cy ~mod+= 1
}
// (ADENOM << 28) = 65_970697_666560 = (258708_618300 * 255) + 60
if (a >> 63) <> 0 {
a = 0
} else if a >= (258708_618300 * 255) {
a = 255
} else {
a /= 258708_618300
}
}
// Store the BGRA pixel.
this.pixels[y][(4 * x) + 0] = (b & 0xFF) as base.u8
this.pixels[y][(4 * x) + 1] = (g & 0xFF) as base.u8
this.pixels[y][(4 * x) + 2] = (r & 0xFF) as base.u8
this.pixels[y][(4 * x) + 3] = (a & 0xFF) as base.u8
x += 1
}
y += 1
}
}
pri func decoder.from_pixels_to_dst!(dst: ptr base.pixel_buffer) base.status {
var h : base.u32[..= 32]
var w : base.u32[..= 32]
var dst_pixfmt : base.pixel_format
var dst_bits_per_pixel : base.u32[..= 256]
var dst_bytes_per_pixel : base.u32[..= 32]
var dst_bytes_per_row : base.u64
var tab : table base.u8
var y : base.u32
var dst : slice base.u8
var src : slice base.u8
h = DIMENSIONS_FROM_DIMENSION_CODES[this.h_dimension_code] as base.u32
w = DIMENSIONS_FROM_DIMENSION_CODES[this.w_dimension_code] as base.u32
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
dst_pixfmt = args.dst.pixel_format()
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
if (dst_bits_per_pixel & 7) <> 0 {
return base."#unsupported option"
}
dst_bytes_per_pixel = dst_bits_per_pixel / 8
dst_bytes_per_row = (w * dst_bytes_per_pixel) as base.u64
tab = args.dst.plane(p: 0)
while y < h {
assert y < 32 via "a < b: a < c; c <= b"(c: h)
src = this.pixels[y][.. w * 4]
dst = tab.row_u32(y: y)
if dst_bytes_per_row < dst.length() {
dst = dst[.. dst_bytes_per_row]
}
this.swizzler.swizzle_interleaved_from_slice!(
dst: dst,
dst_palette: args.dst.palette(),
src: src)
y += 1
}
return ok
}
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
return this.util.make_rect_ie_u32(
min_incl_x: 0,
min_incl_y: 0,
max_excl_x: DIMENSIONS_FROM_DIMENSION_CODES[this.w_dimension_code] as base.u32,
max_excl_y: DIMENSIONS_FROM_DIMENSION_CODES[this.h_dimension_code] as base.u32)
}
pub func decoder.num_animation_loops() base.u32 {
return 0
}
pub func decoder.num_decoded_frame_configs() base.u64 {
if this.call_sequence > 0x20 {
return 1
}
return 0
}
pub func decoder.num_decoded_frames() base.u64 {
if this.call_sequence > 0x40 {
return 1
}
return 0
}
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
if this.call_sequence < 0x20 {
return base."#bad call sequence"
}
if (args.index <> 0) or (args.io_position <> (this.frame_config_io_position as base.u64)) {
return base."#bad argument"
}
this.call_sequence = 0x28
return ok
}
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
// No-op. Thumbhash doesn't support metadata.
}
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
return base."#no more information"
}
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
}
// DIMENSIONS_FROM_DIMENSION_CODES enumerates all possible widths and heights.
pri const DIMENSIONS_FROM_DIMENSION_CODES : roarray[8] base.u8[..= 32] = [
0, 14, 18, 19, 23, 26, 27, 32,
]
// CUMULATIVE_DIMENSIONS is the sum-table of DIMENSIONS_FROM_DIMENSION_CODES.
pri const CUMULATIVE_DIMENSIONS : roarray[8] base.u8[..= 127] = [
0, 0, 14, 32, 51, 74, 100, 127,
]
// DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT holds the width (high 4 bits) and
// height (low 4 bits) codes. For example, if has_alpha is 0 and l_count is 5
// then the 0x47 value means that the image is 23×32 (so the aspect ratio is
// 0.71875), because:
// - the width is DIMENSIONS_FROM_DIMENSION_CODES[4] = 23
// - the height is DIMENSIONS_FROM_DIMENSION_CODES[7] = 32
//
// If is_landscape is 1 (true) then the width and height are swapped.
pri const DIMENSION_CODES_FROM_HAS_ALPHA_AND_L_COUNT : roarray[2] roarray[8] base.u8 = [
[0x17, 0x17, 0x17, 0x17, 0x27, 0x47, 0x67, 0x77],
[0x37, 0x37, 0x37, 0x37, 0x57, 0x77, 0x76, 0x74],
]
// FROM_4_BITS_TO_PLUS_MINUS_1_00 converts AC coefficients to 2.14 fixed point.
pri const FROM_4_BITS_TO_PLUS_MINUS_1_00 : roarray[16] base.u16 = [
0xC000, // -1.000
0xC889, // -0.867
0xD111, // -0.733
0xD99A, // -0.600
0xE222, // -0.467
0xEAAB, // -0.333
0xF333, // -0.200
0xFBBC, // -0.067
0x0444, // +0.067
0x0CCD, // +0.200
0x1555, // +0.333
0x1DDE, // +0.467
0x2666, // +0.600
0x2EEF, // +0.733
0x3777, // +0.867
0x4000, // +1.000
]
// FROM_4_BITS_TO_PLUS_MINUS_1_25 converts AC coefficients to 2.14 fixed point.
pri const FROM_4_BITS_TO_PLUS_MINUS_1_25 : roarray[16] base.u16 = [
0xB000, // -1.250
0xBAAB, // -1.083
0xC555, // -0.917
0xD000, // -0.750
0xDAAB, // -0.583
0xE555, // -0.417
0xF000, // -0.250
0xFAAB, // -0.083
0x0555, // +0.083
0x1000, // +0.250
0x1AAB, // +0.417
0x2555, // +0.583
0x3000, // +0.750
0x3AAB, // +0.917
0x4555, // +1.083
0x5000, // +1.250
]
// COSINES[etc][cx - 1] holds cos(π * cx * (x + 0.5) / w) as 2.14 fixed point.
// Each 6-element row is copied to fx[1 .. 7] and fy[1 .. 7]. fx[0] and fy[0]
// are always equal to 0x4000, which is cos(0) as 2.14 fixed point. fx[7] and
// fy[7] are unused.
//
// (x + 0.5) ranges from (0 + 0.5) to (w - 0.5). Valid w values are given by
// the positive elements of DIMENSIONS_FROM_DIMENSION_CODES.
pri const COSINES : roarray[159] roarray[6] base.u16 = [
// w = 14
[0x3F99, 0x3E65, 0x3C69, 0x39A9, 0x3631, 0x320A], // x = 0
[0x3C69, 0x320A, 0x220D, 0x0E3E, 0xF8D6, 0xE43B], // x = 1
[0x3631, 0x1BC5, 0xF8D6, 0xD819, 0xC397, 0xC19B], // x = 2
[0x2D41, 0x0000, 0xD2BF, 0xC000, 0xD2BF, 0x0000], // x = 3
[0x220D, 0xE43B, 0xC067, 0xD819, 0x1523, 0x3E65], // x = 4
[0x1523, 0xCDF6, 0xC9CF, 0x0E3E, 0x3F99, 0x1BC5], // x = 5
[0x072A, 0xC19B, 0xEADD, 0x39A9, 0x220D, 0xCDF6], // x = 6
[0xF8D6, 0xC19B, 0x1523, 0x39A9, 0xDDF3, 0xCDF6], // x = 7
[0xEADD, 0xCDF6, 0x3631, 0x0E3E, 0xC067, 0x1BC5], // x = 8
[0xDDF3, 0xE43B, 0x3F99, 0xD819, 0xEADD, 0x3E65], // x = 9
[0xD2BF, 0x0000, 0x2D41, 0xC000, 0x2D41, 0x0000], // x = 10
[0xC9CF, 0x1BC5, 0x072A, 0xD819, 0x3C69, 0xC19B], // x = 11
[0xC397, 0x320A, 0xDDF3, 0x0E3E, 0x072A, 0xE43B], // x = 12
[0xC067, 0x3E65, 0xC397, 0x39A9, 0xC9CF, 0x320A], // x = 13
// w = 18
[0x3FC2, 0x3F07, 0x3DD2, 0x3C24, 0x3A01, 0x376D], // x = 0
[0x3DD2, 0x376D, 0x2D41, 0x2000, 0x1090, 0x0000], // x = 1
[0x3A01, 0x2923, 0x1090, 0xF4E3, 0xDB4B, 0xC893], // x = 2
[0x346D, 0x15E4, 0xEF70, 0xCEF9, 0xC03E, 0xC893], // x = 3
[0x2D41, 0x0000, 0xD2BF, 0xC000, 0xD2BF, 0x0000], // x = 4
[0x24B5, 0xEA1C, 0xC22E, 0xCEF9, 0x0594, 0x376D], // x = 5
[0x1B0C, 0xD6DD, 0xC22E, 0xF4E3, 0x346D, 0x376D], // x = 6
[0x1090, 0xC893, 0xD2BF, 0x2000, 0x3DD2, 0x0000], // x = 7
[0x0594, 0xC0F9, 0xEF70, 0x3C24, 0x1B0C, 0xC893], // x = 8
[0xFA6C, 0xC0F9, 0x1090, 0x3C24, 0xE4F4, 0xC893], // x = 9
[0xEF70, 0xC893, 0x2D41, 0x2000, 0xC22E, 0x0000], // x = 10
[0xE4F4, 0xD6DD, 0x3DD2, 0xF4E3, 0xCB93, 0x376D], // x = 11
[0xDB4B, 0xEA1C, 0x3DD2, 0xCEF9, 0xFA6C, 0x376D], // x = 12
[0xD2BF, 0x0000, 0x2D41, 0xC000, 0x2D41, 0x0000], // x = 13
[0xCB93, 0x15E4, 0x1090, 0xCEF9, 0x3FC2, 0xC893], // x = 14
[0xC5FF, 0x2923, 0xEF70, 0xF4E3, 0x24B5, 0xC893], // x = 15
[0xC22E, 0x376D, 0xD2BF, 0x2000, 0xEF70, 0x0000], // x = 16
[0xC03E, 0x3F07, 0xC22E, 0x3C24, 0xC5FF, 0x376D], // x = 17
// w = 19
[0x3FC8, 0x3F21, 0x3E0B, 0x3C88, 0x3A9C, 0x3849], // x = 0
[0x3E0B, 0x3849, 0x2F16, 0x2301, 0x14C8, 0x0549], // x = 1
[0x3A9C, 0x2B59, 0x14C8, 0xFAB7, 0xE18A, 0xCD7F], // x = 2
[0x3594, 0x19B5, 0xF577, 0xD4A7, 0xC1F5, 0xC378], // x = 3
[0x2F16, 0x0549, 0xD8B1, 0xC0DF, 0xCA6C, 0xF04A], // x = 4
[0x274F, 0xF04A, 0xC564, 0xC7B7, 0xF577, 0x2B59], // x = 5
[0x1E76, 0xDCFF, 0xC038, 0xE64B, 0x274F, 0x3F21], // x = 6
[0x14C8, 0xCD7F, 0xCA6C, 0x0FB6, 0x3FC8, 0x19B5], // x = 7
[0x0A89, 0xC378, 0xE18A, 0x3281, 0x2F16, 0xDCFF], // x = 8
[0x0000, 0xC000, 0x0000, 0x4000, 0x0000, 0xC000], // x = 9
[0xF577, 0xC378, 0x1E76, 0x3281, 0xD0EA, 0xDCFF], // x = 10
[0xEB38, 0xCD7F, 0x3594, 0x0FB6, 0xC038, 0x19B5], // x = 11
[0xE18A, 0xDCFF, 0x3FC8, 0xE64B, 0xD8B1, 0x3F21], // x = 12
[0xD8B1, 0xF04A, 0x3A9C, 0xC7B7, 0x0A89, 0x2B59], // x = 13
[0xD0EA, 0x0549, 0x274F, 0xC0DF, 0x3594, 0xF04A], // x = 14
[0xCA6C, 0x19B5, 0x0A89, 0xD4A7, 0x3E0B, 0xC378], // x = 15
[0xC564, 0x2B59, 0xEB38, 0xFAB7, 0x1E76, 0xCD7F], // x = 16
[0xC1F5, 0x3849, 0xD0EA, 0x2301, 0xEB38, 0x0549], // x = 17
[0xC038, 0x3F21, 0xC1F5, 0x3C88, 0xC564, 0x3849], // x = 18
// w = 23
[0x3FDA, 0x3F67, 0x3EA9, 0x3DA0, 0x3C4E, 0x3AB4], // x = 0
[0x3EA9, 0x3AB4, 0x3449, 0x2BAF, 0x2141, 0x156F], // x = 1
[0x3C4E, 0x31A5, 0x2141, 0x0D05, 0xF749, 0xE28E], // x = 2
[0x38D3, 0x24E8, 0x08B7, 0xEA91, 0xD13A, 0xC260], // x = 3
[0x3449, 0x156F, 0xEEBC, 0xCE5B, 0xC026, 0xC951], // x = 4
[0x2EC6, 0x045E, 0xD79C, 0xC099, 0xCBB7, 0xF2FB], // x = 5
[0x2864, 0xF2FB, 0xC72D, 0xC54C, 0xEEBC, 0x24E8], // x = 6
[0x2141, 0xE28E, 0xC026, 0xDB18, 0x197F, 0x3F67], // x = 7
[0x197F, 0xD451, 0xC3B2, 0xFBA2, 0x38D3, 0x31A5], // x = 8
[0x1144, 0xC951, 0xD13A, 0x1D72, 0x3EA9, 0x045E], // x = 9
[0x08B7, 0xC260, 0xE681, 0x36AF, 0x2864, 0xD451], // x = 10
[0x0000, 0xC000, 0x0000, 0x4000, 0x0000, 0xC000], // x = 11
[0xF749, 0xC260, 0x197F, 0x36AF, 0xD79C, 0xD451], // x = 12
[0xEEBC, 0xC951, 0x2EC6, 0x1D72, 0xC157, 0x045E], // x = 13
[0xE681, 0xD451, 0x3C4E, 0xFBA2, 0xC72D, 0x31A5], // x = 14
[0xDEBF, 0xE28E, 0x3FDA, 0xDB18, 0xE681, 0x3F67], // x = 15
[0xD79C, 0xF2FB, 0x38D3, 0xC54C, 0x1144, 0x24E8], // x = 16
[0xD13A, 0x045E, 0x2864, 0xC099, 0x3449, 0xF2FB], // x = 17
[0xCBB7, 0x156F, 0x1144, 0xCE5B, 0x3FDA, 0xC951], // x = 18
[0xC72D, 0x24E8, 0xF749, 0xEA91, 0x2EC6, 0xC260], // x = 19
[0xC3B2, 0x31A5, 0xDEBF, 0x0D05, 0x08B7, 0xE28E], // x = 20
[0xC157, 0x3AB4, 0xCBB7, 0x2BAF, 0xDEBF, 0x156F], // x = 21
[0xC026, 0x3F67, 0xC157, 0x3DA0, 0xC3B2, 0x3AB4], // x = 22
// w = 26
[0x3FE2, 0x3F89, 0x3EF4, 0x3E24, 0x3D1A, 0x3BD7], // x = 0
[0x3EF4, 0x3BD7, 0x36C5, 0x2FE8, 0x2778, 0x1DBE], // x = 1
[0x3D1A, 0x34AC, 0x2778, 0x16B2, 0x03DD, 0xF0AF], // x = 2
[0x3A5D, 0x2A71, 0x130A, 0xF849, 0xDEE4, 0xCB54], // x = 3
[0x36C5, 0x1DBE, 0xFC23, 0xDBA5, 0xC5A3, 0xC077], // x = 4
[0x3261, 0x0F51, 0xE5BC, 0xC755, 0xC10C, 0xD58F], // x = 5
[0x2D41, 0x0000, 0xD2BF, 0xC000, 0xD2BF, 0x0000], // x = 6
[0x2778, 0xF0AF, 0xC5A3, 0xC755, 0xF477, 0x2A71], // x = 7
[0x211C, 0xE242, 0xC01E, 0xDBA5, 0x1A44, 0x3F89], // x = 8
[0x1A44, 0xD58F, 0xC2E6, 0xF849, 0x36C5, 0x34AC], // x = 9
[0x130A, 0xCB54, 0xCD9F, 0x16B2, 0x3FE2, 0x0F51], // x = 10
[0x0B89, 0xC429, 0xDEE4, 0x2FE8, 0x3261, 0xE242], // x = 11
[0x03DD, 0xC077, 0xF477, 0x3E24, 0x130A, 0xC429], // x = 12
[0xFC23, 0xC077, 0x0B89, 0x3E24, 0xECF6, 0xC429], // x = 13
[0xF477, 0xC429, 0x211C, 0x2FE8, 0xCD9F, 0xE242], // x = 14
[0xECF6, 0xCB54, 0x3261, 0x16B2, 0xC01E, 0x0F51], // x = 15
[0xE5BC, 0xD58F, 0x3D1A, 0xF849, 0xC93B, 0x34AC], // x = 16
[0xDEE4, 0xE242, 0x3FE2, 0xDBA5, 0xE5BC, 0x3F89], // x = 17
[0xD888, 0xF0AF, 0x3A5D, 0xC755, 0x0B89, 0x2A71], // x = 18
[0xD2BF, 0x0000, 0x2D41, 0xC000, 0x2D41, 0x0000], // x = 19
[0xCD9F, 0x0F51, 0x1A44, 0xC755, 0x3EF4, 0xD58F], // x = 20
[0xC93B, 0x1DBE, 0x03DD, 0xDBA5, 0x3A5D, 0xC077], // x = 21
[0xC5A3, 0x2A71, 0xECF6, 0xF849, 0x211C, 0xCB54], // x = 22
[0xC2E6, 0x34AC, 0xD888, 0x16B2, 0xFC23, 0xF0AF], // x = 23
[0xC10C, 0x3BD7, 0xC93B, 0x2FE8, 0xD888, 0x1DBE], // x = 24
[0xC01E, 0x3F89, 0xC10C, 0x3E24, 0xC2E6, 0x3BD7], // x = 25
// w = 27
[0x3FE4, 0x3F91, 0x3F07, 0x3E46, 0x3D50, 0x3C24], // x = 0
[0x3F07, 0x3C24, 0x376D, 0x3107, 0x2923, 0x2000], // x = 1
[0x3D50, 0x3579, 0x2923, 0x1959, 0x076E, 0xF4E3], // x = 2
[0x3AC4, 0x2BEB, 0x15E4, 0xFC47, 0xE347, 0xCEF9], // x = 3
[0x376D, 0x2000, 0x0000, 0xE000, 0xC893, 0xC000], // x = 4
[0x3356, 0x125B, 0xEA1C, 0xCA87, 0xC01C, 0xCEF9], // x = 5
[0x2E8D, 0x03B9, 0xD6DD, 0xC06F, 0xCCAA, 0xF4E3], // x = 6
[0x2923, 0xF4E3, 0xC893, 0xC3DC, 0xEA1C, 0x2000], // x = 7
[0x232B, 0xE6A7, 0xC0F9, 0xD415, 0x0EC2, 0x3C24], // x = 8
[0x1CB9, 0xD9C8, 0xC0F9, 0xEDA5, 0x2E8D, 0x3C24], // x = 9
[0x15E4, 0xCEF9, 0xC893, 0x0B1D, 0x3F07, 0x2000], // x = 10
[0x0EC2, 0xC6CF, 0xD6DD, 0x2638, 0x3AC4, 0xF4E3], // x = 11
[0x076E, 0xC1BA, 0xEA1C, 0x3931, 0x232B, 0xCEF9], // x = 12
[0x0000, 0xC000, 0x0000, 0x4000, 0x0000, 0xC000], // x = 13
[0xF892, 0xC1BA, 0x15E4, 0x3931, 0xDCD5, 0xCEF9], // x = 14
[0xF13E, 0xC6CF, 0x2923, 0x2638, 0xC53C, 0xF4E3], // x = 15
[0xEA1C, 0xCEF9, 0x376D, 0x0B1D, 0xC0F9, 0x2000], // x = 16
[0xE347, 0xD9C8, 0x3F07, 0xEDA5, 0xD173, 0x3C24], // x = 17
[0xDCD5, 0xE6A7, 0x3F07, 0xD415, 0xF13E, 0x3C24], // x = 18
[0xD6DD, 0xF4E3, 0x376D, 0xC3DC, 0x15E4, 0x2000], // x = 19
[0xD173, 0x03B9, 0x2923, 0xC06F, 0x3356, 0xF4E3], // x = 20
[0xCCAA, 0x125B, 0x15E4, 0xCA87, 0x3FE4, 0xCEF9], // x = 21
[0xC893, 0x2000, 0x0000, 0xE000, 0x376D, 0xC000], // x = 22
[0xC53C, 0x2BEB, 0xEA1C, 0xFC47, 0x1CB9, 0xCEF9], // x = 23
[0xC2B0, 0x3579, 0xD6DD, 0x1959, 0xF892, 0xF4E3], // x = 24
[0xC0F9, 0x3C24, 0xC893, 0x3107, 0xD6DD, 0x2000], // x = 25
[0xC01C, 0x3F91, 0xC0F9, 0x3E46, 0xC2B0, 0x3C24], // x = 26
// w = 32
[0x3FEC, 0x3FB1, 0x3F4F, 0x3EC5, 0x3E15, 0x3D3F], // x = 0
[0x3F4F, 0x3D3F, 0x39DB, 0x3537, 0x2F6C, 0x289A], // x = 1
[0x3E15, 0x3871, 0x2F6C, 0x238E, 0x1590, 0x0646], // x = 2
[0x3C42, 0x3179, 0x20E7, 0x0C7C, 0xF69C, 0xE1D5], // x = 3
[0x39DB, 0x289A, 0x0F8D, 0xF384, 0xD9E0, 0xC78F], // x = 4
[0x36E5, 0x1E2B, 0xFCDC, 0xDC72, 0xC625, 0xC04F], // x = 5
[0x3368, 0x1294, 0xEA70, 0xCAC9, 0xC014, 0xCE87], // x = 6
[0x2F6C, 0x0646, 0xD9E0, 0xC13B, 0xC91B, 0xED6C], // x = 7
[0x2AFB, 0xF9BA, 0xCC98, 0xC13B, 0xDF19, 0x1294], // x = 8
[0x2620, 0xED6C, 0xC3BE, 0xCAC9, 0xFCDC, 0x3179], // x = 9
[0x20E7, 0xE1D5, 0xC014, 0xDC72, 0x1B5D, 0x3FB1], // x = 10
[0x1B5D, 0xD766, 0xC1EB, 0xF384, 0x3368, 0x3871], // x = 11
[0x1590, 0xCE87, 0xC91B, 0x0C7C, 0x3F4F, 0x1E2B], // x = 12
[0x0F8D, 0xC78F, 0xD505, 0x238E, 0x3C42, 0xF9BA], // x = 13
[0x0964, 0xC2C1, 0xE4A3, 0x3537, 0x2AFB, 0xD766], // x = 14
[0x0324, 0xC04F, 0xF69C, 0x3EC5, 0x0F8D, 0xC2C1], // x = 15
[0xFCDC, 0xC04F, 0x0964, 0x3EC5, 0xF073, 0xC2C1], // x = 16
[0xF69C, 0xC2C1, 0x1B5D, 0x3537, 0xD505, 0xD766], // x = 17
[0xF073, 0xC78F, 0x2AFB, 0x238E, 0xC3BE, 0xF9BA], // x = 18
[0xEA70, 0xCE87, 0x36E5, 0x0C7C, 0xC0B1, 0x1E2B], // x = 19
[0xE4A3, 0xD766, 0x3E15, 0xF384, 0xCC98, 0x3871], // x = 20
[0xDF19, 0xE1D5, 0x3FEC, 0xDC72, 0xE4A3, 0x3FB1], // x = 21
[0xD9E0, 0xED6C, 0x3C42, 0xCAC9, 0x0324, 0x3179], // x = 22
[0xD505, 0xF9BA, 0x3368, 0xC13B, 0x20E7, 0x1294], // x = 23
[0xD094, 0x0646, 0x2620, 0xC13B, 0x36E5, 0xED6C], // x = 24
[0xCC98, 0x1294, 0x1590, 0xCAC9, 0x3FEC, 0xCE87], // x = 25
[0xC91B, 0x1E2B, 0x0324, 0xDC72, 0x39DB, 0xC04F], // x = 26
[0xC625, 0x289A, 0xF073, 0xF384, 0x2620, 0xC78F], // x = 27
[0xC3BE, 0x3179, 0xDF19, 0x0C7C, 0x0964, 0xE1D5], // x = 28
[0xC1EB, 0x3871, 0xD094, 0x238E, 0xEA70, 0x0646], // x = 29
[0xC0B1, 0x3D3F, 0xC625, 0x3537, 0xD094, 0x289A], // x = 30
[0xC014, 0x3FB1, 0xC0B1, 0x3EC5, 0xC1EB, 0x3D3F], // x = 31
]
+4 -4
View File
@@ -12,9 +12,9 @@
// Quirks are discussed in (/doc/note/quirks.md).
//
// The base38 encoding of "xz " is 0x1E1EBC. Left shifting by 10 gives
// 0x787A_F000.
pri const QUIRKS_BASE : base.u32 = 0x787A_F000
// The base38 encoding of "xz.." is 0x1D_42C0. Left shifting by 10 gives
// 0x750B_0000.
pri const QUIRKS_BASE : base.u32 = 0x750B_0000
// --------
@@ -37,4 +37,4 @@ pri const QUIRKS_BASE : base.u32 = 0x787A_F000
// XZ-as-part-of-something-else format, not the XZ-standalone format. Like most
// of Wuffs' other std/foobar quirks, decoding a more lenient variant of the
// foobar format is opt-in, not opt-out.
pub const QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS : base.u32 = 0x787A_F000 | 0x00
pub const QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS : base.u32 = 0x750B_0000 | 0x00
+4 -4
View File
@@ -12,9 +12,9 @@
// 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
// The base38 encoding of "zlib" is 0x1E_A356. Left shifting by 10 gives
// 0x7A8D_5800.
pri const QUIRKS_BASE : base.u32 = 0x7A8D_5800
// --------
@@ -24,6 +24,6 @@ pri const QUIRKS_BASE : base.u32 = 0x7DFD_E400
// 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
pub const QUIRK_JUST_RAW_DEFLATE : base.u32 = 0x7A8D_5800 | 0x00
pri const QUIRKS_COUNT : base.u32 = 0x01
@@ -6,7 +6,7 @@ test files for which Wuffs' `example/convert-to-nia` and libjpeg-turbo's
```
Differ (other) test/3pdata/blinksuite/182.jpg
Differ (other) test/3pdata/blinksuite/large-size-image-crash.jpeg
Differ (large) test/3pdata/blinksuite/large-size-image-crash.jpeg
Differ (trunc) test/3pdata/blinksuite/missing-eoi.jpg
Differ (trunc) test/3pdata/blinksuite/non-interleaved_progressive-1.jpg
Differ (trunc) test/3pdata/blinksuite/non-interleaved_progressive.jpg
@@ -167,7 +167,7 @@ pos = 0x00000059 = 89 marker = 0xFF 0xDB DQT
pos = 0x0000009E = 158 marker = 0xFF 0xC0 SOF0 (Sequential/Baseline)
pos = 0x000000B1 = 177 marker = 0xFF 0xC4 DHT
pos = 0x000000CB = 203 marker = 0xFF 0xC4 DHT
pos = 0x000000E3 = 227 marker = 0xFE 0xDA SOS *** corrupted ***
pos = 0x000000E3 = 227 marker = 0xFE 0xDA SOS corrupted: note the FE
pos = 0x00000100 = 256 marker = 0xFF 0xC4 DHT
pos = 0x00000120 = 288 marker = 0xFF 0xDA SOS
pos = 0x0000014B = 331 marker = 0xFF 0xC4 DHT
+189
View File
@@ -0,0 +1,189 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// ----------------
/*
This test program is typically run indirectly, by the "wuffs test" or "wuffs
bench" commands. These commands take an optional "-mimic" flag to check that
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
giflib for GIF, libpng for PNG, etc.
To manually run this test:
for CC in clang gcc; do
$CC -std=c99 -Wall -Werror etc2.c && ./a.out
rm -f a.out
done
Each edition should print "PASS", amongst other information, and exit(0).
Add the "wuffs mimic cflags" (everything after the colon below) to the C
compiler flags (after the .c file) to run the mimic tests.
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
the first "./a.out" with "./a.out -bench". Combine these changes with the
"wuffs mimic cflags" to run the mimic benchmarks.
*/
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__ETC2
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
// No mimic library.
#endif
// ---------------- ETC2 Tests
const char* //
test_wuffs_etc2_decode_interface() {
CHECK_FOCUS(__func__);
wuffs_etc2__decoder dec;
CHECK_STATUS("initialize",
wuffs_etc2__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_etc2__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-color.etc1.pkm", 0, SIZE_MAX, 160, 120, 0xFF022365);
}
const char* //
test_wuffs_etc2_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_etc2__decoder dec;
CHECK_STATUS("initialize",
wuffs_etc2__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_etc2__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_base__suspension__short_read) {
RETURN_FAIL("closed=false: have \"%s\", want \"%s\"", status.repr,
wuffs_base__suspension__short_read);
}
src.meta.closed = true;
status = wuffs_etc2__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_etc2__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_etc2__error__truncated_input);
}
return NULL;
}
const char* //
test_wuffs_etc2_decode_frame_config() {
CHECK_FOCUS(__func__);
wuffs_etc2__decoder dec;
CHECK_STATUS("initialize",
wuffs_etc2__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/bricks-color.etc1.pkm"));
CHECK_STATUS("decode_frame_config #0",
wuffs_etc2__decoder__decode_frame_config(&dec, &fc, &src));
wuffs_base__status status =
wuffs_etc2__decoder__decode_frame_config(&dec, &fc, &src);
if (status.repr != wuffs_base__note__end_of_data) {
RETURN_FAIL("decode_frame_config #1: have \"%s\", want \"%s\"", status.repr,
wuffs_base__note__end_of_data);
}
return NULL;
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
// ---------------- ETC2 Benches
// No ETC2 benches.
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_etc2_decode_frame_config,
test_wuffs_etc2_decode_interface,
test_wuffs_etc2_decode_truncated_input,
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
// No ETC2 benches.
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/etc2";
return test_main(argc, argv, g_tests, g_benches);
}
+189
View File
@@ -0,0 +1,189 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// ----------------
/*
This test program is typically run indirectly, by the "wuffs test" or "wuffs
bench" commands. These commands take an optional "-mimic" flag to check that
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
giflib for GIF, libpng for PNG, etc.
To manually run this test:
for CC in clang gcc; do
$CC -std=c99 -Wall -Werror qoi.c && ./a.out
rm -f a.out
done
Each edition should print "PASS", amongst other information, and exit(0).
Add the "wuffs mimic cflags" (everything after the colon below) to the C
compiler flags (after the .c file) to run the mimic tests.
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
the first "./a.out" with "./a.out -bench". Combine these changes with the
"wuffs mimic cflags" to run the mimic benchmarks.
*/
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__QOI
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
// No mimic library.
#endif
// ---------------- QOI Tests
const char* //
test_wuffs_qoi_decode_interface() {
CHECK_FOCUS(__func__);
wuffs_qoi__decoder dec;
CHECK_STATUS("initialize",
wuffs_qoi__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_qoi__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-color.qoi", 0, SIZE_MAX, 160, 120, 0xFF022460);
}
const char* //
test_wuffs_qoi_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_qoi__decoder dec;
CHECK_STATUS("initialize",
wuffs_qoi__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_qoi__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_base__suspension__short_read) {
RETURN_FAIL("closed=false: have \"%s\", want \"%s\"", status.repr,
wuffs_base__suspension__short_read);
}
src.meta.closed = true;
status = wuffs_qoi__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_qoi__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_qoi__error__truncated_input);
}
return NULL;
}
const char* //
test_wuffs_qoi_decode_frame_config() {
CHECK_FOCUS(__func__);
wuffs_qoi__decoder dec;
CHECK_STATUS("initialize",
wuffs_qoi__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
.data = g_src_slice_u8,
});
CHECK_STRING(read_file(&src, "test/data/bricks-color.qoi"));
CHECK_STATUS("decode_frame_config #0",
wuffs_qoi__decoder__decode_frame_config(&dec, &fc, &src));
wuffs_base__status status =
wuffs_qoi__decoder__decode_frame_config(&dec, &fc, &src);
if (status.repr != wuffs_base__note__end_of_data) {
RETURN_FAIL("decode_frame_config #1: have \"%s\", want \"%s\"", status.repr,
wuffs_base__note__end_of_data);
}
return NULL;
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
// ---------------- QOI Benches
// No QOI benches.
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_qoi_decode_frame_config,
test_wuffs_qoi_decode_interface,
test_wuffs_qoi_decode_truncated_input,
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
// No QOI benches.
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/qoi";
return test_main(argc, argv, g_tests, g_benches);
}
+37 -35
View File
@@ -19,7 +19,7 @@ giflib for GIF, libpng for PNG, etc.
To manually run this test:
for CC in clang gcc; do
$CC -std=c99 -Wall -Werror tga.c && ./a.out
$CC -std=c99 -Wall -Werror targa.c && ./a.out
rm -f a.out
done
@@ -52,7 +52,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__TGA
#define WUFFS_CONFIG__MODULE__TARGA
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
@@ -63,62 +63,62 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// No mimic library.
#endif
// ---------------- TGA Tests
// ---------------- TARGA Tests
const char* //
wuffs_tga_decode(uint64_t* n_bytes_out,
wuffs_base__io_buffer* dst,
uint32_t wuffs_initialize_flags,
wuffs_base__pixel_format pixfmt,
uint32_t* quirks_ptr,
size_t quirks_len,
wuffs_base__io_buffer* src) {
wuffs_tga__decoder dec;
wuffs_targa_decode(uint64_t* n_bytes_out,
wuffs_base__io_buffer* dst,
uint32_t wuffs_initialize_flags,
wuffs_base__pixel_format pixfmt,
uint32_t* quirks_ptr,
size_t quirks_len,
wuffs_base__io_buffer* src) {
wuffs_targa__decoder dec;
CHECK_STATUS("initialize",
wuffs_tga__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
wuffs_initialize_flags));
wuffs_targa__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
wuffs_initialize_flags));
return do_run__wuffs_base__image_decoder(
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec),
wuffs_targa__decoder__upcast_as__wuffs_base__image_decoder(&dec),
n_bytes_out, dst, pixfmt, quirks_ptr, quirks_len, src);
}
const char* //
test_wuffs_tga_decode_interface() {
test_wuffs_targa_decode_interface() {
CHECK_FOCUS(__func__);
wuffs_tga__decoder dec;
wuffs_targa__decoder dec;
CHECK_STATUS("initialize",
wuffs_tga__decoder__initialize(
wuffs_targa__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec),
wuffs_targa__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-color.tga", 0, SIZE_MAX, 160, 120, 0xFF022460);
}
const char* //
test_wuffs_tga_decode_truncated_input() {
test_wuffs_targa_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_tga__decoder dec;
wuffs_targa__decoder dec;
CHECK_STATUS("initialize",
wuffs_tga__decoder__initialize(
wuffs_targa__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_tga__decoder__decode_image_config(&dec, NULL, &src);
wuffs_targa__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_base__suspension__short_read) {
RETURN_FAIL("closed=false: have \"%s\", want \"%s\"", status.repr,
wuffs_base__suspension__short_read);
}
src.meta.closed = true;
status = wuffs_tga__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_tga__error__truncated_input) {
status = wuffs_targa__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_targa__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_tga__error__truncated_input);
wuffs_targa__error__truncated_input);
}
return NULL;
}
@@ -131,23 +131,25 @@ test_wuffs_tga_decode_truncated_input() {
#endif // WUFFS_MIMIC
// ---------------- TGA Benches
// ---------------- TARGA Benches
const char* //
bench_wuffs_tga_decode_19k_8bpp() {
bench_wuffs_targa_decode_19k_8bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_tga_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
&wuffs_targa_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL),
NULL, 0, "test/data/bricks-nodither.tga", 0, SIZE_MAX, 1000);
}
const char* //
bench_wuffs_tga_decode_77k_24bpp() {
bench_wuffs_targa_decode_77k_24bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_tga_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
&wuffs_targa_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/bricks-color.tga", 0, SIZE_MAX, 200);
}
@@ -164,8 +166,8 @@ bench_wuffs_tga_decode_77k_24bpp() {
proc g_tests[] = {
test_wuffs_tga_decode_interface,
test_wuffs_tga_decode_truncated_input,
test_wuffs_targa_decode_interface,
test_wuffs_targa_decode_truncated_input,
#ifdef WUFFS_MIMIC
@@ -178,8 +180,8 @@ proc g_tests[] = {
proc g_benches[] = {
bench_wuffs_tga_decode_19k_8bpp,
bench_wuffs_tga_decode_77k_24bpp,
bench_wuffs_targa_decode_19k_8bpp,
bench_wuffs_targa_decode_77k_24bpp,
#ifdef WUFFS_MIMIC
@@ -192,6 +194,6 @@ proc g_benches[] = {
int //
main(int argc, char** argv) {
g_proc_package_name = "std/tga";
g_proc_package_name = "std/targa";
return test_main(argc, argv, g_tests, g_benches);
}
+219
View File
@@ -0,0 +1,219 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
// ----------------
/*
This test program is typically run indirectly, by the "wuffs test" or "wuffs
bench" commands. These commands take an optional "-mimic" flag to check that
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
giflib for GIF, libpng for PNG, etc.
To manually run this test:
for CC in clang gcc; do
$CC -std=c99 -Wall -Werror thumbhash.c && ./a.out
rm -f a.out
done
Each edition should print "PASS", amongst other information, and exit(0).
Add the "wuffs mimic cflags" (everything after the colon below) to the C
compiler flags (after the .c file) to run the mimic tests.
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
the first "./a.out" with "./a.out -bench". Combine these changes with the
"wuffs mimic cflags" to run the mimic benchmarks.
*/
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__THUMBHASH
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
// No mimic library.
#endif
// ---------------- Thumbhash Tests
const char* //
test_wuffs_thumbhash_decode_interface() {
CHECK_FOCUS(__func__);
wuffs_thumbhash__decoder dec;
CHECK_STATUS("initialize",
wuffs_thumbhash__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_thumbhash__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th", 0,
SIZE_MAX, 32, 23, 0xFF56632E);
}
const char* //
test_wuffs_thumbhash_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_thumbhash__decoder dec;
CHECK_STATUS("initialize",
wuffs_thumbhash__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_thumbhash__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_base__suspension__short_read) {
RETURN_FAIL("closed=false: have \"%s\", want \"%s\"", status.repr,
wuffs_base__suspension__short_read);
}
src.meta.closed = true;
status = wuffs_thumbhash__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_thumbhash__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_thumbhash__error__truncated_input);
}
return NULL;
}
const char* //
do_test_wuffs_thumbhash_decode_frame_config(bool raw) {
wuffs_thumbhash__decoder dec;
CHECK_STATUS("initialize",
wuffs_thumbhash__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/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th"));
if (raw) {
if ((src.meta.wi <= src.meta.ri) || ((src.meta.wi - src.meta.ri) < 3)) {
return "could not skip 3 bytes";
}
src.meta.ri += 3; // The number of bytes in "\xC3\xBE\xFE".
wuffs_thumbhash__decoder__set_quirk(
&dec, WUFFS_THUMBHASH__QUIRK_JUST_RAW_THUMBHASH, 1);
}
CHECK_STATUS("decode_frame_config #0",
wuffs_thumbhash__decoder__decode_frame_config(&dec, &fc, &src));
uint32_t have = wuffs_base__frame_config__height(&fc);
uint32_t want = 23;
if (have != want) {
RETURN_FAIL("height: have %u, want %u", have, want);
}
wuffs_base__status status =
wuffs_thumbhash__decoder__decode_frame_config(&dec, &fc, &src);
if (status.repr != wuffs_base__note__end_of_data) {
RETURN_FAIL("decode_frame_config #1: have \"%s\", want \"%s\"", status.repr,
wuffs_base__note__end_of_data);
}
return NULL;
}
const char* //
test_wuffs_thumbhash_decode_frame_config_cooked() {
CHECK_FOCUS(__func__);
return do_test_wuffs_thumbhash_decode_frame_config(false);
}
const char* //
test_wuffs_thumbhash_decode_frame_config_raw() {
CHECK_FOCUS(__func__);
return do_test_wuffs_thumbhash_decode_frame_config(true);
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
// ---------------- Thumbhash Benches
// No Thumbhash benches.
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_thumbhash_decode_frame_config_cooked,
test_wuffs_thumbhash_decode_frame_config_raw,
test_wuffs_thumbhash_decode_interface,
test_wuffs_thumbhash_decode_truncated_input,
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
// No Thumbhash benches.
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/thumbhash";
return test_main(argc, argv, g_tests, g_benches);
}
+8 -21
View File
@@ -349,6 +349,10 @@ test_wuffs_pixel_swizzler_swizzle() {
.color = 0x55443300,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL,
},
{
.color = 0xFF443300,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY,
},
{
.color = 0xFF443300,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__BGRX,
@@ -374,10 +378,10 @@ test_wuffs_pixel_swizzler_swizzle() {
// When updating this list, also consider updating the pixel formats that
// fuzz/c/std/pixel_swizzler_fuzzer.c exercises and those that
// wuffs_aux::DecodeImageCallbacks::SelectPixfmt accepts.
//
// SelectPixfmt excludes WUFFS_BASE__PIXEL_FORMAT__Y, even though we test
// it here, since it doesn't support every source pixel format in the
// srcs array. See "dst WUFFS_BASE__PIXEL_FORMAT__Y allow-list" below.
{
.color = 0xFF999999,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__Y,
},
{
.color = 0xFF000010,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__BGR_565,
@@ -410,10 +414,6 @@ test_wuffs_pixel_swizzler_swizzle() {
.color = 0x33002233,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL,
},
{
.color = 0xFF999999,
.pixfmt_repr = WUFFS_BASE__PIXEL_FORMAT__Y,
},
};
const wuffs_base__pixel_blend blends[] = {
@@ -451,19 +451,6 @@ test_wuffs_pixel_swizzler_swizzle() {
}
for (size_t d = 0; d < WUFFS_TESTLIB_ARRAY_SIZE(dsts); d++) {
// See "dst WUFFS_BASE__PIXEL_FORMAT__Y allow-list" above.
if (dsts[d].pixfmt_repr == WUFFS_BASE__PIXEL_FORMAT__Y) {
switch (srcs[s].pixfmt_repr) {
case WUFFS_BASE__PIXEL_FORMAT__Y:
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
break;
default:
continue;
}
}
// Allocate the dst_pixbuf.
wuffs_base__pixel_config dst_pixcfg = ((wuffs_base__pixel_config){});
wuffs_base__pixel_config__set(&dst_pixcfg, dsts[d].pixfmt_repr,
+7 -1
View File
@@ -11,7 +11,10 @@ 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 `*.qoi` files were generated by the qoiconv command line tool. The `*.pkm`
files were generated by the ETCPACK command line tool, except the `*.etc1s.pkm`
files were generated by a [custom
etc1tool](https://github.com/nigeltao/etc1tool).
The `*.apng` files were generated by `gif2apng`. Those with finite animation
loop counts were manually patched to correct for a `gif2apng` bug.
@@ -117,6 +120,9 @@ Museum."
copied from
[shakespeare.mit.edu](http://shakespeare.mit.edu/midsummer/midsummer.1.1.html).
`mona-lisa.*` is derived from a Wikimedia Commons [photo of the Mona
Lisa](https://en.wikipedia.org/wiki/File:Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg).
`muybridge.gif` is derived from
[en.wikipedia.org](https://en.wikipedia.org/wiki/File:Muybridge_race_horse_animated.gif)
which is in the public domain.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -0,0 +1,77 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//go:build ignore
// +build ignore
package main
// Usage: go run make-hippopotamus-bad-comment-length.go
//
// This program inserts a four-byte "FF FE 00 00" fragment into the
// test/data/hippopotamus.jpeg file. The "FF FE" is a COM (comment) marker. The
// "00 00" payload length is technically invalid (the minimum length is 2, per
// the itu-t81.pdf spec section B.1.1.4 "Marker segments") but libjpeg-turbo is
// more lenient and allows less-than-2 (for COM and APPn markers).
//
// https://www.w3.org/Graphics/JPEG/itu-t81.pdf
//
// https://github.com/libjpeg-turbo/libjpeg-turbo/blob/2192560d74e6e6cf99dd05928885573be00a8208/jdmarker.c#L869-L876
//
// $ go run script/print-jpeg-markers.go test/data/hippopotamus.jpeg
// pos = 0x00000000 = 0 marker = 0xFF 0xD8 SOI
// pos = 0x00000002 = 2 marker = 0xFF 0xE0 APP0
// pos = 0x00000014 = 20 marker = 0xFF 0xDB DQT
// pos = 0x00000059 = 89 marker = 0xFF 0xDB DQT
// pos = 0x0000009E = 158 marker = 0xFF 0xC0 SOF0 (Sequential/Baseline)
// pos = 0x000000B1 = 177 marker = 0xFF 0xC4 DHT
// pos = 0x000000CC = 204 marker = 0xFF 0xC4 DHT
// pos = 0x000000FC = 252 marker = 0xFF 0xC4 DHT
// pos = 0x00000119 = 281 marker = 0xFF 0xC4 DHT
// pos = 0x0000014B = 331 marker = 0xFF 0xDA SOS
// pos = 0x000004C1 = 1217 marker = 0xFF 0xD9 EOI
//
// $ go run script/print-jpeg-markers.go test/data/artificial-jpeg/hippopotamus-bad-comment-length.jpeg
// pos = 0x00000000 = 0 marker = 0xFF 0xD8 SOI
// pos = 0x00000002 = 2 marker = 0xFF 0xE0 APP0
// pos = 0x00000014 = 20 marker = 0xFF 0xDB DQT
// pos = 0x00000059 = 89 marker = 0xFF 0xFE COM
// bad JPEG, pos = 0x0000005B = 91, len(src) = 0x000004C7 = 1223
import (
"fmt"
"os"
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
src, err := os.ReadFile("../hippopotamus.jpeg")
if err != nil {
return err
} else if len(src) != 0x4C3 {
return fmt.Errorf("bad input length: 0x%X", len(src))
}
part0 := src[0x000:0x059]
part1 := src[0x059:0x4C3]
dst := []byte(nil)
dst = append(dst, part0...)
dst = append(dst, 0xFF, 0xFE, 0x00, 0x00)
dst = append(dst, part1...)
return os.WriteFile("hippopotamus-bad-comment-length.jpeg", dst, 0666)
}
@@ -0,0 +1,80 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//go:build ignore
// +build ignore
package main
// Usage: go run make-hippopotamus-sof-dht-swap.go
//
// The test/data/hippopotamus.jpeg file has one SOF0 (Start Of Frame type 0)
// and then four DHT (Define Huffman Table) markers. This program swaps the
// order of the SOF0 and first DHT fragments.
//
// $ go run script/print-jpeg-markers.go test/data/hippopotamus.jpeg
// pos = 0x00000000 = 0 marker = 0xFF 0xD8 SOI
// pos = 0x00000002 = 2 marker = 0xFF 0xE0 APP0
// pos = 0x00000014 = 20 marker = 0xFF 0xDB DQT
// pos = 0x00000059 = 89 marker = 0xFF 0xDB DQT
// pos = 0x0000009E = 158 marker = 0xFF 0xC0 SOF0 (Sequential/Baseline)
// pos = 0x000000B1 = 177 marker = 0xFF 0xC4 DHT
// pos = 0x000000CC = 204 marker = 0xFF 0xC4 DHT
// pos = 0x000000FC = 252 marker = 0xFF 0xC4 DHT
// pos = 0x00000119 = 281 marker = 0xFF 0xC4 DHT
// pos = 0x0000014B = 331 marker = 0xFF 0xDA SOS
// pos = 0x000004C1 = 1217 marker = 0xFF 0xD9 EOI
//
// $ go run script/print-jpeg-markers.go test/data/artificial-jpeg/hippopotamus-sof-dht-swap.jpeg
// pos = 0x00000000 = 0 marker = 0xFF 0xD8 SOI
// pos = 0x00000002 = 2 marker = 0xFF 0xE0 APP0
// pos = 0x00000014 = 20 marker = 0xFF 0xDB DQT
// pos = 0x00000059 = 89 marker = 0xFF 0xDB DQT
// pos = 0x0000009E = 158 marker = 0xFF 0xC4 DHT
// pos = 0x000000B9 = 185 marker = 0xFF 0xC0 SOF0 (Sequential/Baseline)
// pos = 0x000000CC = 204 marker = 0xFF 0xC4 DHT
// pos = 0x000000FC = 252 marker = 0xFF 0xC4 DHT
// pos = 0x00000119 = 281 marker = 0xFF 0xC4 DHT
// pos = 0x0000014B = 331 marker = 0xFF 0xDA SOS
// pos = 0x000004C1 = 1217 marker = 0xFF 0xD9 EOI
import (
"fmt"
"os"
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
src, err := os.ReadFile("../hippopotamus.jpeg")
if err != nil {
return err
} else if len(src) != 0x4C3 {
return fmt.Errorf("bad input length: 0x%X", len(src))
}
part0 := src[0x000:0x09E]
part1 := src[0x09E:0x0B1] // SOF0
part2 := src[0x0B1:0x0CC] // DHT
part3 := src[0x0CC:0x4C3]
dst := []byte(nil)
dst = append(dst, part0...)
dst = append(dst, part2...) // Note the re-order: it's not part1.
dst = append(dst, part1...) // Note the re-order: it's not part2.
dst = append(dst, part3...)
return os.WriteFile("hippopotamus-sof-dht-swap.jpeg", dst, 0666)
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1 @@
テセ�ユg㍼wW⑨㊦裸Xx枢
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@@ -0,0 +1 @@
þþØŠƒ'Æxô&‚ØtÍßñ¨i¸7‡ˆwpg
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

@@ -0,0 +1 @@
ĂľţŮ÷€w�‡‡x‰‡†�`ť•ň
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1 @@
þþÜç%€xwxˆ‡‡xHwxˆpú=À
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1 @@
þþÜ÷ 5„…yxww¥wH‡f†`Wv
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1 @@
þþ„ˆxx�ˆx|x—xy3tD
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1 @@
Ăľţ!-†z�wʇ�uxW‡‡‡p�7
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@@ -0,0 +1,2 @@
ĂľţV
€ęVou‡zwh™‡úxOä
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@@ -0,0 +1 @@
þþ`š†= ;°Yl–¨Eiô„ù¨'XvˆpvG
+94
View File
@@ -0,0 +1,94 @@
// Copyright 2024 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//go:build ignore
// +build ignore
package main
// make.go writes the https://evanw.github.io/thumbhash/ examples to individual
// files, prepending a 3-byte magic string so that /usr/bin/file or similar
// programs can identify the data as thumbhash-formatted data.
//
// That 3-byte magic string is "\xC3\xBE\xFE", which is arbitrary and not part
// of the original thumbhash description or implementation. But "\xC3\xBE" is
// the UTF-8 encoding of 'þ' (U+00FE LATIN SMALL LETTER THORN) and "\xFE" is
// invalid UTF-8 but is the ISO-8859-1 encoding of 'þ'. The Old English letter
// 'þ' is pronounced like the "th" that starts "thumbhash".
//
// The filenames are the base64.RawURLEncoding of the data (similar to but
// slightly different from the base64.RawStdEncoding used on that web page)
// plus a ".th" extension.
//
// The foobar.png files that correspond to each foobar.th file were manually
// scraped from the https://evanw.github.io/thumbhash/ page. These PNG files
// were written by thumbhash's original JavaScript reference implementation,
// exercised by that page. This small JavaScript library favors implementation
// simplicity over maximizing the compression ratio.
//
// For any given foobar.th input file, that library's RGBA output and Wuffs'
// RGBA output may differ slightly, due to floating point versus fixed point
// rounding errors, but they're pretty close.
//
// Usage: go run make.go
import (
"encoding/base64"
"os"
)
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
func main1() error {
for _, d := range data {
filename := convertBase64StdToBase64URL(d) + ".th"
in, err := base64.RawStdEncoding.DecodeString(d)
if err != nil {
return err
}
out := append([]byte(magic), in...)
if err := os.WriteFile(filename, out, 0666); err != nil {
return err
}
}
return nil
}
func convertBase64StdToBase64URL(s string) string {
b := []byte(s)
for i, c := range b {
if c == '+' {
b[i] = '-'
} else if c == '/' {
b[i] = '_'
}
}
return string(b)
}
const magic = "\xC3\xBE\xFE"
var data = []string{
"1QcSHQRnh493V4dIh4eXh1h4kJUI",
"3PcNNYSFeXh/d3eld0iHZoZgVwh2",
"3OcRJYB4d3h/iIeHeEh3eIhw+j3A",
"HBkSHYSIeHiPiHh8eJd4eTN0EEQG",
"VggKDYAW6lZvdYd6d2iZh/p4GE/k",
"2fcZFIB3iId/h3iJh4aIYJ2V8g",
"IQgSLYZ6iHePh4h1eFeHh4dwgwg3",
"YJqGPQw7sFlslqhFafSE+Q6oJ1h2iHB2Rw",
"2IqDBQQnxnj0JoLYdM3f8ahpuDeHiHdwZw",
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

+2
View File
@@ -0,0 +1,2 @@
ĂľţŃ
x•�‡�‡�w‡GI¦
+31
View File
@@ -21,13 +21,37 @@ BAD 2342e3fc test/data/artificial-gif/pixel-data-too-much-good-lzw.gif
OK. 39a71dce test/data/artificial-gif/small-frame-interlaced.gif
OK. beaec397 test/data/artificial-gif/transparent-index.gif
BAD f33b9bc1 test/data/artificial-gif/zero-width-frame.gif
OK. 96bdbbb3 test/data/artificial-jpeg/hippopotamus-bad-comment-length.jpeg
OK. 96bdbbb3 test/data/artificial-jpeg/hippopotamus-sof-dht-swap.jpeg
OK. 0564b364 test/data/artificial-png/apng-skip-idat.png
OK. e08a7cc8 test/data/artificial-png/exif.png
OK. e08a7cc8 test/data/artificial-png/key-value-pairs.png
OK. 755ee422 test/data/artificial-thumbhash/1QcSHQRnh493V4dIh4eXh1h4kJUI.png
OK. 2b606fe3 test/data/artificial-thumbhash/1QcSHQRnh493V4dIh4eXh1h4kJUI.th
OK. 90f3bc13 test/data/artificial-thumbhash/2IqDBQQnxnj0JoLYdM3f8ahpuDeHiHdwZw.png
OK. 70203d96 test/data/artificial-thumbhash/2IqDBQQnxnj0JoLYdM3f8ahpuDeHiHdwZw.th
OK. 93cb6b2e test/data/artificial-thumbhash/2fcZFIB3iId_h3iJh4aIYJ2V8g.png
OK. 025631eb test/data/artificial-thumbhash/2fcZFIB3iId_h3iJh4aIYJ2V8g.th
OK. 2160c22d test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.png
OK. 4ab0d622 test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th
OK. d84de1fc test/data/artificial-thumbhash/3PcNNYSFeXh_d3eld0iHZoZgVwh2.png
OK. 4ba04a51 test/data/artificial-thumbhash/3PcNNYSFeXh_d3eld0iHZoZgVwh2.th
OK. d97db52c test/data/artificial-thumbhash/HBkSHYSIeHiPiHh8eJd4eTN0EEQG.png
OK. 5b7fd9b7 test/data/artificial-thumbhash/HBkSHYSIeHiPiHh8eJd4eTN0EEQG.th
OK. 2a7a3f54 test/data/artificial-thumbhash/IQgSLYZ6iHePh4h1eFeHh4dwgwg3.png
OK. 69ad2c3d test/data/artificial-thumbhash/IQgSLYZ6iHePh4h1eFeHh4dwgwg3.th
OK. c37b7991 test/data/artificial-thumbhash/VggKDYAW6lZvdYd6d2iZh_p4GE_k.png
OK. 27a6e456 test/data/artificial-thumbhash/VggKDYAW6lZvdYd6d2iZh_p4GE_k.th
OK. d9ce0e57 test/data/artificial-thumbhash/YJqGPQw7sFlslqhFafSE-Q6oJ1h2iHB2Rw.png
OK. 4965134c test/data/artificial-thumbhash/YJqGPQw7sFlslqhFafSE-Q6oJ1h2iHB2Rw.th
OK. 076cb375 test/data/bricks-color.bmp
OK. bdbbfadb test/data/bricks-color.etc1.pkm
OK. 41e6110e test/data/bricks-color.etc1s.pkm
OK. 5670f263 test/data/bricks-color.etc2.pkm
OK. 72a1f9cc test/data/bricks-color.jpeg
OK. 076cb375 test/data/bricks-color.lossless.webp
OK. 076cb375 test/data/bricks-color.png
OK. 076cb375 test/data/bricks-color.qoi
OK. 076cb375 test/data/bricks-color.tga
OK. f36c2e80 test/data/bricks-dither.bmp
OK. f36c2e80 test/data/bricks-dither.gif
@@ -79,6 +103,8 @@ BAD c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
BAD 7c6a771b test/data/hippopotamus.interlaced.truncated.png
OK. 96bdbbb3 test/data/hippopotamus.jpeg
OK. dcbb225a test/data/hippopotamus.lossless.webp
OK. 45979d1b test/data/hippopotamus.masked-with-muybridge.etc2.bgra-binary.pkm
OK. b51ed7e8 test/data/hippopotamus.masked-with-muybridge.etc2.bgra-nonpremul.pkm
OK. d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
OK. 7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
OK. dcbb225a test/data/hippopotamus.nie
@@ -87,6 +113,11 @@ OK. dcbb225a test/data/hippopotamus.ppm
OK. ed4b78fc test/data/hippopotamus.regular.gif
OK. dcbb225a test/data/hippopotamus.regular.png
BAD 888b1c04 test/data/hippopotamus.regular.truncated.png
OK. f6bb81e2 test/data/mona-lisa.21x32.etc2.pkm
OK. 012ce4cf test/data/mona-lisa.21x32.png
OK. 0a22e689 test/data/mona-lisa.21x32.q50.jpeg
OK. 059ecb80 test/data/mona-lisa.21x32.q90.jpeg
OK. 12fc69a5 test/data/mona-lisa.21x32.th
OK. 2dccfe56 test/data/muybridge-frame-000.wbmp
OK. db2733f5 test/data/muybridge.apng
OK. db2733f5 test/data/muybridge.gif