mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 00:47:28 +01:00
Compare commits
35
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dbf7d0d5c | ||
|
|
5049107b90 | ||
|
|
193d0354b4 | ||
|
|
26ce8600a1 | ||
|
|
05a8209fa7 | ||
|
|
0f214ba59c | ||
|
|
504f8485f4 | ||
|
|
ce863060d6 | ||
|
|
2f7e714ab0 | ||
|
|
e772ccd47a | ||
|
|
1230506e7c | ||
|
|
b89fd2fa03 | ||
|
|
aad70fdfa5 | ||
|
|
466cf6f15d | ||
|
|
c4df79d82e | ||
|
|
59176bb0c7 | ||
|
|
16d6267451 | ||
|
|
5d5fb1d6d9 | ||
|
|
0fe5509f1b | ||
|
|
7b71d6840a | ||
|
|
d9cf0751ca | ||
|
|
5f398130e8 | ||
|
|
e7f6c79752 | ||
|
|
2a97911e02 | ||
|
|
9d8285b52e | ||
|
|
8e909c8ccf | ||
|
|
6e9e2e00c2 | ||
|
|
be6327a548 | ||
|
|
bd3b33770e | ||
|
|
e3bda4efc9 | ||
|
|
8515165bee | ||
|
|
183beab481 | ||
|
|
c2f44c84d1 | ||
|
|
0918f99bc1 | ||
|
|
30835a0132 |
No files matched your search
@@ -1,5 +1,7 @@
|
||||
name: CIFuzz
|
||||
on: [pull_request]
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
Fuzzing:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -16,7 +18,7 @@ jobs:
|
||||
fuzz-seconds: 600
|
||||
dry-run: false
|
||||
- name: Upload Crash
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: artifacts
|
||||
|
||||
@@ -117,6 +117,39 @@ Some more examples:
|
||||
- `0x197816_7DF74000 = "text/html/.." = "text/html"`
|
||||
- `0x197816_B215E800 = "text/plai/.." = "text/plain"`
|
||||
|
||||
For another fits-in-53-bits example, BCP 47 language tags can use base38
|
||||
3+1/2+2/1+1 encoding, `lllx/ssrr/yz`, where the l, s and r base-38 digits hold
|
||||
the commonly-used language, script and region subtags. The x, y and z base-38
|
||||
digits hold the rarely-used extlang, variant and extension or other subtags.
|
||||
|
||||
- `0x0B2084_000004C0 = "ca../..../v." = ca-valencia`
|
||||
- `0x0D1688_00000000 = "en../..../.." = en`
|
||||
- `0x0D32BC_00060000 = "es../..41/.." = es-419`
|
||||
- `0x0E0370_000FC800 = "fr../..ca/.." = fr-CA`
|
||||
- `0x138442_00000000 = "mas./..../.." = mas`
|
||||
- `0x1DFF1E_7DF14800 = "yue./hthk/.." = yue-Hant-HK`
|
||||
- `0x1E89E8_7DAE2000 = "zh../hs../.." = zh-Hans`
|
||||
|
||||
|
||||
### Powers of 38
|
||||
|
||||
In case you want to roll your own bit-packing.
|
||||
|
||||
```
|
||||
38 ** 1 = 38 = 0x________________26 ≈ 6 bits
|
||||
38 ** 2 = 1444 = 0x_______________5A4 ≈ 11 bits
|
||||
38 ** 3 = 54872 = 0x______________D658 ≈ 16 bits
|
||||
38 ** 4 = 2_085136 = 0x____________1FD110 ≈ 21 bits
|
||||
38 ** 5 = 79_235168 = 0x___________4B90860 ≈ 27 bits
|
||||
38 ** 6 = 3010_936384 = 0x__________B3773E40 ≈ 32 bits
|
||||
38 ** 7 = 114415_582592 = 0x_______1A_A3B33D80 ≈ 37 bits
|
||||
38 ** 8 = 4_347792_138496 = 0x______3F4_4C9B2100 ≈ 42 bits
|
||||
38 ** 9 = 165_216101_262848 = 0x_____9643_5F06E600 ≈ 48 bits
|
||||
38 ** 10 = 6278_211847_988224 = 0x___164E00_1B062400 ≈ 53 bits
|
||||
38 ** 11 = 238572_050223_552512 = 0x__34F9404_02E95800 ≈ 58 bits
|
||||
38 ** 12 = 9_065737_908494_995456 = 0x_7DCFF898_6EA31000 ≈ 63 bits
|
||||
```
|
||||
|
||||
|
||||
### Base38 Alphabet
|
||||
|
||||
|
||||
+3
-2
@@ -76,11 +76,12 @@ Common quirks:
|
||||
|
||||
Package-specific quirks:
|
||||
|
||||
- [GIF image decoder quirks](/std/gif/decode_quirks.wuffs)
|
||||
- [GIF 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)
|
||||
- [THUMBHASH decoder quirks](/std/thumbhash/decode_quirks.wuffs)
|
||||
- [VP8 decoder quirks](/std/vp8/decode_quirks.wuffs)
|
||||
- [XZ decoder quirks](/std/xz/decode_quirks.wuffs)
|
||||
- [ZLIB decoder quirks](/std/zlib/decode_quirks.wuffs)
|
||||
@@ -3,3 +3,4 @@ Wuffs or stand-alone formats that were invented alongside Wuffs' development.
|
||||
|
||||
- [Naïve Image Formats: NIE, NII, NIA](/doc/spec/nie-spec.md)
|
||||
- [Random Access Compression: RAC](/doc/spec/rac-spec.md)
|
||||
- [Simple Uncompressed Interchange Tape Archive: SUITAR](/doc/spec/suitar-spec.md)
|
||||
@@ -0,0 +1,220 @@
|
||||
# Simple Uncompressed Interchange Tape Archive: SUITAR
|
||||
|
||||
Status: Draft (as of September 2026). There is no compatibility guarantee yet.
|
||||
|
||||
|
||||
## Overview
|
||||
|
||||
SUITAR is a common-denominator, trivial-to-parse interchange format for "the
|
||||
result of decompressing a compressed file or unpacking an archive file", such
|
||||
as ZIP, RAR, 7Z, TAR, GZIP, BZIP2, XZ, ZSTD, etc.
|
||||
|
||||
SUITAR is to archive files (including `foobar.dat.xz` compressed files as an
|
||||
archive containing 1 file) as [Farbfeld](https://tools.suckless.org/farbfeld/)
|
||||
or [NIE](./nie-spec.md) is to image files: an uncompressed, "designed for Unix
|
||||
pipes" format that is trivial to read or write in a few hundred lines of code,
|
||||
ideally in a memory-safe programming language. It's a format for what the
|
||||
Chromium web browser's "Rule of 2" security advice calls
|
||||
[https://chromium.googlesource.com/chromium/src/+/master/docs/security/rule-of-2.md#normalization](Normalization).
|
||||
|
||||
|
||||
## Subset of TAR
|
||||
|
||||
SUITAR is a subset of the well-known and widely-used TAR (Tape Archive, with
|
||||
GNU extensions) archive file format. Every valid SUITAR file is also a valid
|
||||
TAR file. These files work with popular tools like `/usr/bin/tar` and with
|
||||
popular TAR-reading libraries in a variety of programming languages.
|
||||
|
||||
SUITAR is a subset of "pure TAR", not of "TAR wrapped in GZIP", "TAR wrapped in
|
||||
BZIP2", etc. A separate compression step wrapping SUITAR is feasible, just like
|
||||
wrapping TAR, but is out of scope of this document.
|
||||
|
||||
Like TAR, SUITAR files are a sequence of independent entries (files or
|
||||
directories). Independent means that, like JSON map keys, duplicate names are
|
||||
valid, although some decoders may choose to reject them.
|
||||
|
||||
A file's entry does not need to be preceded by explicit entries for that file's
|
||||
parent directories.
|
||||
|
||||
|
||||
### Further Restrictions
|
||||
|
||||
Compared to plain TAR (and refer to [the GNU TAR
|
||||
manual](https://ftp.gnu.org/old-gnu/Manuals/tar-1.12/html_node/tar_123.html)),
|
||||
SUITAR has further restrictions:
|
||||
|
||||
- Entries are either regular files (`REGTYPE`), sparse files (`GNUTYPE_SPARSE`)
|
||||
or directories (`DIRTYPE`). There is no support for hard links, symlinks,
|
||||
device files or other non-standard files.
|
||||
- Sparse files must be completely sparse. Their content must be one contiguous
|
||||
span of NUL (zero) bytes that covers the entire file.
|
||||
- File and directory names must obey the "File Name Validity" rules, below.
|
||||
- These names must be encoded by a `GNUTYPE_LONGNAME` header block, regardless
|
||||
of whether the name's length is over or under 100 or 255 bytes.
|
||||
- File size and modTime (modification time, seconds since Unix epoch) integers
|
||||
must use base-256 encoding (not base-8 octal) and must be non-negative and
|
||||
less than `(1 << 53)`, which is `9007_199254_740992`.
|
||||
- Mode bits are either 0o644 (`rw-r--r--`) or 0o755 (`rwxr-xr-x`), encoded in
|
||||
base-8 octal (not base-256).
|
||||
- UID and GID are hard-coded to 65534 (as a number, equivalent to octal
|
||||
0o0177776) and "nobody" (as a string).
|
||||
- Any other fields are unused and must be NUL bytes.
|
||||
- Padding bytes (as TAR uses 512-byte blocks) must be NUL bytes.
|
||||
|
||||
There is no support for various TAR variants, such as "the PAX extensions to
|
||||
TAR" or "the USTAR extensions to TAR", other than what's implied by the subset
|
||||
of the GNU extensions that SUITAR explicitly uses.
|
||||
|
||||
Encoders have no meaningful choices, bar one exception. There is only one valid
|
||||
SUITAR encoding (unlike full TAR's backwards-compatible choice between base-8
|
||||
or base-256 encoding of various sufficiently small numbers) for any given file
|
||||
or directory entry (its combination of type, name, size, mode, modTime and
|
||||
contents).
|
||||
|
||||
The one exception is that, if a file's contents are all NUL bytes (including
|
||||
zero-sized files), an encoder can choose between a `REGTYPE` regular file (with
|
||||
explicit NULs) or a `GNUTYPE_SPARSE` sparse file (with implicit NULs).
|
||||
|
||||
|
||||
### File Name Validity
|
||||
|
||||
These rules apply to both file names and directory names.
|
||||
|
||||
- Names must be valid UTF-8.
|
||||
- Names must not contain any ASCII control characters, including `'\n'` or
|
||||
`'\x00'`, the "new line" or NUL bytes.
|
||||
- Names must not contain the `'\x7F'` ASCII DEL byte.
|
||||
- Names must be no longer than 4095 bytes, excluding a trailing NUL.
|
||||
- Names must not be `""`, `"."` or `".."`.
|
||||
- Names must not start or end with `"/"`, `"./"` or `"../"`.
|
||||
- Names must not contain `"//"`, `"/./"` or `"/../"` as substrings.
|
||||
|
||||
For example, when converting from ZIP (with Japanese file names) to SUITAR, it
|
||||
is the SUITAR producer's responsibility, not the SUITAR consumer's, to detect
|
||||
and transform Shift-JIS encoded names to equivalent and valid UTF-8.
|
||||
|
||||
|
||||
## File Structure
|
||||
|
||||
SUITAR files are a sequence of entries, followed by a 1024-byte "End Of File"
|
||||
marker. The EOF marker's bytes are all NUL. Each entry occupies an integer
|
||||
number of 512-byte blocks:
|
||||
|
||||
- 1 `GNUTYPE_LONGNAME` header block.
|
||||
- 1 or more payload blocks containing the file or directory name.
|
||||
- 1 `REGTYPE`, `GNUTYPE_SPARSE` or `DIRTYPE` header block.
|
||||
- If `REGTYPE`, 0 or more payload blocks containing the file contents.
|
||||
- If not `REGTYPE`, no further blocks.
|
||||
|
||||
|
||||
### Header Blocks
|
||||
|
||||
Like all blocks, each header block is 512 bytes long. Each header block also
|
||||
starts with a 12-byte magic signature (that is not valid UTF-8), identifying
|
||||
SUITAR version 1. There are no other versions at this time.
|
||||
|
||||
The first 384 out of 512 bytes must match this template (arranged as 24 rows of
|
||||
16 bytes per row, plus commentary):
|
||||
|
||||
@@@@@@@@@@@@.... @@@@@@@@@@@@ = "\x13sUItAR\x00\xFE\xFDv1".
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
....0000???.0177 ??? = mode.
|
||||
776.0177776.$...
|
||||
????????$...???? ???????? = physical size, ???????? = modTime.
|
||||
??????????. ?... ?????? = checksum, ? = type.
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
.ustar .nobody.
|
||||
................
|
||||
.........nobody.
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
|
||||
In this template, `@` indicates the magic signature, `.` indicates a `0x00` NUL
|
||||
byte, `$` indicates a `0x80` byte and `?` indicates parts of the template that
|
||||
are variable, not hard-coded.
|
||||
|
||||
These `?` bytes are the 3-byte mode (`"644"` or `"755"`), physical size or
|
||||
modTime as an 8-byte big-endian `uint64`, 6-byte checksum (see below) or 1-byte
|
||||
type, which must be one of:
|
||||
|
||||
- `'0'` for `REGTYPE`.
|
||||
- `'5'` for `DIRTYPE`, in which case mode must be `"755"` and physical size
|
||||
must be all zeroes.
|
||||
- `'L'` for `GNUTYPE_LONGNAME`, in which case mode must be `"644"` and modTime
|
||||
must be all zeroes.
|
||||
- `'S'` for `GNUTYPE_SPARSE`, in which case physical size must be all zeroes
|
||||
and offset and logical size (see below) must be the same number and, again,
|
||||
within the half-open range `0 .. (1 << 53)`.
|
||||
|
||||
The last 128 out of 512 bytes (8 rows of 16 bytes per row) must be all NUL
|
||||
bytes unless the type is `GNUTYPE_SPARSE`, in which case it must match this
|
||||
template (and `?` again indicates an 8-byte big-endian `uint64`):
|
||||
|
||||
..$...????????$. ???????? = sparse offset.
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
................
|
||||
...$...????????. ???????? = sparse logical size.
|
||||
................
|
||||
|
||||
|
||||
### Header Checksum
|
||||
|
||||
A 512-byte header block's checksum value is simply the sum of each byte (after
|
||||
converting from `uint8` to `uint32`, to avoid overflow) in the block, at
|
||||
offsets in the two half-open ranges `0 .. 148` and `156 .. 512`, which excludes
|
||||
the 8 bytes for the 6-byte checksum itself plus another two hard-coded bytes
|
||||
`"\x00\x20"`.
|
||||
|
||||
That checksum value is written as a 6-byte ASCII octal number in the header.
|
||||
For example, `4853` (decimal) would be encoded as `"011365"` (octal).
|
||||
|
||||
|
||||
### Payload Blocks
|
||||
|
||||
Each entry has one or more payload blocks, between its two header blocks,
|
||||
containing the file or directory name. The name length (including a trailing
|
||||
NUL byte) is the first header block's physical size value, and must be within
|
||||
the half-open range `2 .. 4096`, and so the excluding-a-trailing-NUL length
|
||||
must range within `1 .. 4095`. Rounding up that including-a-trailing-NUL length
|
||||
to a multiple of 512 gives the number of 512-byte payload blocks that contain
|
||||
the name. All padding bytes in the name's final payload block must be NUL.
|
||||
|
||||
For `REGTYPE` entries, the second header block's physical size value gives the
|
||||
reconstructed file's size and rounding that up to a multiple of 512 gives the
|
||||
number of 512-byte payload blocks that contain the file contents. Again, all
|
||||
padding bytes in the contents' final payload block must be NUL.
|
||||
|
||||
For other entries (`DIRTYPE` or `GNUTYPE_SPARSE`), there are no further payload
|
||||
blocks after the second header block.
|
||||
|
||||
For `GNUTYPE_SPARSE` entries, the second header block's logical size value
|
||||
gives the reconstructed file's size and its contents are all NUL bytes.
|
||||
|
||||
|
||||
# Reference Implementation
|
||||
|
||||
The [google/wuffs](https://github.com/google/wuffs) repository, which holds
|
||||
this specification document, also holds a
|
||||
[suitar](https://godoc.org/github.com/google/wuffs/lib/suitar) Go package and
|
||||
some `test/data/*.suitar` example files, readable by that Go package but also
|
||||
by `/usr/bin/tar`.
|
||||
|
||||
|
||||
---
|
||||
|
||||
Updated on September 2026.
|
||||
@@ -132,8 +132,9 @@ In Wuffs syntax, the `base.image_decoder` methods are:
|
||||
- [std/nie](/std/nie)
|
||||
- [std/png](/std/png)
|
||||
- [std/qoi](/std/qoi)
|
||||
- [std/tga](/std/tga)
|
||||
- [std/targa](/std/targa)
|
||||
- [std/thumbhash](/std/thumbhash)
|
||||
- [std/vp8](/std/vp8)
|
||||
- [std/wbmp](/std/wbmp)
|
||||
- [std/webp](/std/webp)
|
||||
|
||||
@@ -160,7 +161,8 @@ Examples in other repositories:
|
||||
|
||||
- [GIF decoder quirks](/std/gif/decode_quirks.wuffs)
|
||||
- [JPEG decoder quirks](/std/jpeg/decode_quirks.wuffs)
|
||||
- [TH decoder quirks](/std/thumbhash/decode_quirks.wuffs)
|
||||
- [THUMBHASH decoder quirks](/std/thumbhash/decode_quirks.wuffs)
|
||||
- [VP8 decoder quirks](/std/vp8/decode_quirks.wuffs)
|
||||
|
||||
|
||||
## Related Documentation
|
||||
|
||||
@@ -609,8 +609,12 @@ redirect:
|
||||
WUFFS_BASE__PIXEL_SUBSAMPLING__NONE, w, h);
|
||||
|
||||
// Configure the work buffer.
|
||||
uint64_t workbuf_len =
|
||||
wuffs_base__image_decoder__workbuf_len(g_image_decoder).max_incl;
|
||||
wuffs_base__range_ii_u64 r =
|
||||
wuffs_base__image_decoder__workbuf_len(g_image_decoder);
|
||||
if (wuffs_base__range_ii_u64__is_empty(&r)) {
|
||||
return "main: unsupported image (indeterminate work buffer length)";
|
||||
}
|
||||
uint64_t workbuf_len = r.max_incl;
|
||||
if (g_workbuf_slice.len < workbuf_len) {
|
||||
return "main: image is too large (to configure work buffer)";
|
||||
}
|
||||
@@ -800,10 +804,10 @@ print_uncompressed_png_frame() {
|
||||
uint32_t h = wuffs_base__pixel_config__height(&g_pixbuf.pixcfg);
|
||||
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(&g_pixbuf, 0);
|
||||
return UNCOMPNG__RESULT__OK ==
|
||||
uncompng__encode(&my_uncompng_write_func, NULL, tab.ptr,
|
||||
uncompng__encode(&my_uncompng_write_func, NULL, pixfmt, w, h, tab.ptr,
|
||||
wuffs_base__table__flattened_length(
|
||||
tab.width, tab.height, tab.stride),
|
||||
w, h, tab.stride, pixfmt);
|
||||
tab.stride);
|
||||
}
|
||||
|
||||
void //
|
||||
|
||||
@@ -312,7 +312,11 @@ try_allocate(wuffs_gif__decoder* dec) {
|
||||
return "could not allocate prev-dst buffer";
|
||||
}
|
||||
|
||||
uint64_t workbuf_len_max_incl = wuffs_gif__decoder__workbuf_len(dec).max_incl;
|
||||
wuffs_base__range_ii_u64 r = wuffs_gif__decoder__workbuf_len(dec);
|
||||
if (wuffs_base__range_ii_u64__is_empty(&r)) {
|
||||
return "indeterminate work buffer length";
|
||||
}
|
||||
uint64_t workbuf_len_max_incl = r.max_incl;
|
||||
if (workbuf_len_max_incl > 0) {
|
||||
g_workbuf = wuffs_base__malloc_slice_u8(malloc, workbuf_len_max_incl);
|
||||
if (!g_workbuf.ptr) {
|
||||
|
||||
@@ -961,7 +961,7 @@ apply_background_color(uint32_t bg_color_premul,
|
||||
|
||||
// ----------------
|
||||
|
||||
#define MAX_INCL_DIMENSION 10000
|
||||
#define MAX_INCL_DIMENSION 16384
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -2,4 +2,4 @@ module github.com/google/wuffs
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require golang.org/x/image v0.38.0
|
||||
require golang.org/x/image v0.41.0
|
||||
@@ -1,2 +1,2 @@
|
||||
golang.org/x/image v0.38.0 h1:5l+q+Y9JDC7mBOMjo4/aPhMDcxEptsX+Tt3GgRQRPuE=
|
||||
golang.org/x/image v0.38.0/go.mod h1:/3f6vaXC+6CEanU4KJxbcUZyEePbyKbaLoDOe4ehFYY=
|
||||
golang.org/x/image v0.41.0 h1:8wS72eGJMJaBxK6okTzd4WaXumUlTVlb753MlsSvTCo=
|
||||
golang.org/x/image v0.41.0/go.mod h1:uIc348UZMSvS5Z65CVZ7iDPaNobNFEPeJ4kbqTOszmA=
|
||||
@@ -507,8 +507,9 @@ redirect:
|
||||
}
|
||||
wuffs_base__pixel_buffer pixel_buffer = alloc_pixbuf_result.pixbuf;
|
||||
if (valid_background_color) {
|
||||
wuffs_base__status pb_scufr_status = pixel_buffer.set_color_u32_fill_rect(
|
||||
pixel_buffer.pixcfg.bounds(), background_color);
|
||||
wuffs_base__status pb_scufr_status =
|
||||
pixel_buffer.set_color_u32_argb_premul_fill_rect(
|
||||
pixel_buffer.pixcfg.bounds(), background_color);
|
||||
if (pb_scufr_status.repr != nullptr) {
|
||||
return DecodeImageResult(pb_scufr_status.message());
|
||||
}
|
||||
@@ -517,6 +518,9 @@ redirect:
|
||||
// Allocate the work buffer. Wuffs' decoders conventionally assume that this
|
||||
// can be uninitialized memory.
|
||||
wuffs_base__range_ii_u64 workbuf_len = image_decoder->workbuf_len();
|
||||
if (workbuf_len.is_empty()) {
|
||||
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
|
||||
}
|
||||
DecodeImageCallbacks::AllocWorkbufResult alloc_workbuf_result =
|
||||
callbacks.AllocWorkbuf(workbuf_len, true);
|
||||
if (!alloc_workbuf_result.error_message.empty()) {
|
||||
|
||||
@@ -162,6 +162,8 @@ class DecodeImageCallbacks {
|
||||
// should be at least len_range.min_incl, but larger allocations (up to
|
||||
// len_range.max_incl) may have better performance (by using more memory).
|
||||
//
|
||||
// The len_range argument will satisfy !len_range.is_empty().
|
||||
//
|
||||
// The default AllocWorkbuf implementation allocates len_range.max_incl bytes
|
||||
// of either uninitialized or zeroed memory.
|
||||
virtual AllocWorkbufResult //
|
||||
|
||||
@@ -1466,7 +1466,7 @@ wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__make_slice_u8_ij(uint8_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u8 ret;
|
||||
ret.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.ptr = i ? (ptr + i) : ptr;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1474,7 +1474,7 @@ wuffs_base__make_slice_u8_ij(uint8_t* ptr, size_t i, size_t j) {
|
||||
static inline wuffs_base__slice_u16 //
|
||||
wuffs_base__make_slice_u16_ij(uint16_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u16 ret;
|
||||
ret.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.ptr = i ? (ptr + i) : ptr;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1482,7 +1482,7 @@ wuffs_base__make_slice_u16_ij(uint16_t* ptr, size_t i, size_t j) {
|
||||
static inline wuffs_base__slice_u32 //
|
||||
wuffs_base__make_slice_u32_ij(uint32_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u32 ret;
|
||||
ret.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.ptr = i ? (ptr + i) : ptr;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1490,7 +1490,7 @@ wuffs_base__make_slice_u32_ij(uint32_t* ptr, size_t i, size_t j) {
|
||||
static inline wuffs_base__slice_u64 //
|
||||
wuffs_base__make_slice_u64_ij(uint64_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u64 ret;
|
||||
ret.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.ptr = i ? (ptr + i) : ptr;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1631,7 +1631,12 @@ wuffs_base__slice_u8__overlaps(wuffs_base__slice_u8 s, wuffs_base__slice_u8 t) {
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__slice_u8__subslice_i(wuffs_base__slice_u8 s, uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return wuffs_base__make_slice_u8(s.ptr + i, ((size_t)(s.len - i)));
|
||||
// The "i ? (s.ptr + i) : s.ptr" expression is equivalent to the plain
|
||||
// "s.ptr + i", except for the fact that in C (prior to C29), but not in
|
||||
// C++, "NULL + 0" is, technically, undefined behavior (and triggers
|
||||
// ubsan). See C29 N3322 and https://reviews.llvm.org/D67122
|
||||
return wuffs_base__make_slice_u8(i ? (s.ptr + i) : s.ptr,
|
||||
((size_t)(s.len - i)));
|
||||
}
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
@@ -1655,7 +1660,12 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
|
||||
uint64_t i,
|
||||
uint64_t j) {
|
||||
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return wuffs_base__make_slice_u8(s.ptr + i, ((size_t)(j - i)));
|
||||
// The "i ? (s.ptr + i) : s.ptr" expression is equivalent to the plain
|
||||
// "s.ptr + i", except for the fact that in C (prior to C29), but not in
|
||||
// C++, "NULL + 0" is, technically, undefined behavior (and triggers
|
||||
// ubsan). See C29 N3322 and https://reviews.llvm.org/D67122
|
||||
return wuffs_base__make_slice_u8(i ? (s.ptr + i) : s.ptr,
|
||||
((size_t)(j - i)));
|
||||
}
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
|
||||
@@ -73,4 +73,10 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
|
||||
// ---------------- Images (Utility)
|
||||
|
||||
#define wuffs_base__utility__make_pixel_blend wuffs_base__make_pixel_blend
|
||||
#define wuffs_base__utility__make_pixel_format wuffs_base__make_pixel_format
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__utility__demake_pixel_blend(wuffs_base__pixel_blend a) {
|
||||
return a;
|
||||
}
|
||||
@@ -32,6 +32,10 @@
|
||||
// 0xAARRGGBB (Alpha most significant, Blue least), regardless of endianness.
|
||||
typedef uint32_t wuffs_base__color_u32_argb_premul;
|
||||
|
||||
// wuffs_base__color_u32_argb_nonpremul is non-premultiplied version of
|
||||
// wuffs_base__color_u32_argb_premul.
|
||||
typedef uint32_t wuffs_base__color_u32_argb_nonpremul;
|
||||
|
||||
// wuffs_base__color_u32_argb_premul__is_valid returns whether c's Red, Green
|
||||
// and Blue channels are all less than or equal to its Alpha channel. c uses
|
||||
// premultiplied alpha, so 50% opaque 100% saturated red is 0x7F7F_0000 and a
|
||||
@@ -251,6 +255,21 @@ wuffs_base__color_u64_argb_premul__as__color_u64_argb_nonpremul(
|
||||
return (a << 48) | (r << 32) | (g << 16) | (b << 0);
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__color_u64_argb_nonpremul__as__color_u64_argb_premul(
|
||||
uint64_t argb_nonpremul) {
|
||||
uint64_t a = 0xFFFF & (argb_nonpremul >> 48);
|
||||
|
||||
uint64_t r = 0xFFFF & (argb_nonpremul >> 32);
|
||||
r = (r * a) / 0xFFFF;
|
||||
uint64_t g = 0xFFFF & (argb_nonpremul >> 16);
|
||||
g = (g * a) / 0xFFFF;
|
||||
uint64_t b = 0xFFFF & (argb_nonpremul >> 0);
|
||||
b = (b * a) / 0xFFFF;
|
||||
|
||||
return (a << 48) | (r << 32) | (g << 16) | (b << 0);
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray(
|
||||
uint64_t argb_nonpremul) {
|
||||
@@ -482,6 +501,11 @@ typedef uint8_t wuffs_base__pixel_blend;
|
||||
#define WUFFS_BASE__PIXEL_BLEND__SRC ((wuffs_base__pixel_blend)0)
|
||||
#define WUFFS_BASE__PIXEL_BLEND__SRC_OVER ((wuffs_base__pixel_blend)1)
|
||||
|
||||
static inline wuffs_base__pixel_blend //
|
||||
wuffs_base__make_pixel_blend(uint8_t repr) {
|
||||
return repr;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__pixel_alpha_transparency is a pixel format's alpha channel
|
||||
@@ -863,13 +887,21 @@ wuffs_base__pixel_subsampling::denominator_y(uint32_t plane) const {
|
||||
//
|
||||
// For CMY, C = (100% - R), M = (100% - G) and Y = (100% - B). Black (K), if
|
||||
// present, then modulates the three RGB values.
|
||||
//
|
||||
// ----
|
||||
//
|
||||
// The 0x02 bit means the fourth channel is an alpha channel and, if set, then
|
||||
// the 0x01 bit gives the blend mode (WUFFS_BASE__PIXEL_BLEND__SRC is 0,
|
||||
// WUFFS_BASE__PIXEL_BLEND__SRC_OVER is 1).
|
||||
|
||||
// clang-format off
|
||||
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_FULL_RANGE 0x00
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE 0x01
|
||||
#define WUFFS_BASE__YCC_MODEL__RGB 0x40
|
||||
#define WUFFS_BASE__YCC_MODEL__CMY 0x80
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_FULL_RANGE 0x00
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE 0x04
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC 0x06
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC_OVER 0x07
|
||||
#define WUFFS_BASE__YCC_MODEL__RGB 0x40
|
||||
#define WUFFS_BASE__YCC_MODEL__CMY 0x80
|
||||
|
||||
// clang-format on
|
||||
|
||||
@@ -1495,15 +1527,32 @@ typedef struct wuffs_base__pixel_buffer__struct {
|
||||
inline wuffs_base__slice_u8 palette_or_else(wuffs_base__slice_u8 fallback);
|
||||
inline wuffs_base__pixel_format pixel_format() const;
|
||||
inline wuffs_base__table_u8 plane(uint32_t p);
|
||||
// Deprecated: use color_u32_argb_premul_at.
|
||||
inline wuffs_base__color_u32_argb_premul color_u32_at(uint32_t x,
|
||||
uint32_t y) const;
|
||||
inline wuffs_base__color_u32_argb_premul color_u32_argb_premul_at(
|
||||
uint32_t x,
|
||||
uint32_t y) const;
|
||||
// Deprecated: use set_color_u32_argb_premul_at.
|
||||
inline wuffs_base__status set_color_u32_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
inline wuffs_base__status set_color_u32_argb_premul_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
// Deprecated: use set_color_u32_argb_premul_fill_rect.
|
||||
inline wuffs_base__status set_color_u32_fill_rect(
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
inline wuffs_base__status set_color_u32_argb_premul_fill_rect(
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
inline wuffs_base__status set_color_u32_argb_nonpremul_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color);
|
||||
inline bool is_opaque();
|
||||
#endif // __cplusplus
|
||||
|
||||
@@ -1698,24 +1747,44 @@ wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* pb, uint32_t p) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Deprecated: use the second name, not the first.
|
||||
#define wuffs_base__pixel_buffer__color_u32_at \
|
||||
wuffs_base__pixel_buffer__color_u32_argb_premul_at
|
||||
|
||||
// Deprecated: use the second name, not the first.
|
||||
#define wuffs_base__pixel_buffer__set_color_u32_at \
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at
|
||||
|
||||
// Deprecated: use the second name, not the first.
|
||||
#define wuffs_base__pixel_buffer__set_color_u32_fill_rect \
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__color_u32_argb_premul //
|
||||
wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y);
|
||||
wuffs_base__pixel_buffer__color_u32_argb_premul_at(
|
||||
const wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_nonpremul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC bool //
|
||||
wuffs_base__pixel_buffer__is_opaque(const wuffs_base__pixel_buffer* pb);
|
||||
|
||||
@@ -1760,7 +1829,13 @@ wuffs_base__pixel_buffer::plane(uint32_t p) {
|
||||
|
||||
inline wuffs_base__color_u32_argb_premul //
|
||||
wuffs_base__pixel_buffer::color_u32_at(uint32_t x, uint32_t y) const {
|
||||
return wuffs_base__pixel_buffer__color_u32_at(this, x, y);
|
||||
return wuffs_base__pixel_buffer__color_u32_argb_premul_at(this, x, y);
|
||||
}
|
||||
|
||||
inline wuffs_base__color_u32_argb_premul //
|
||||
wuffs_base__pixel_buffer::color_u32_argb_premul_at(uint32_t x,
|
||||
uint32_t y) const {
|
||||
return wuffs_base__pixel_buffer__color_u32_argb_premul_at(this, x, y);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
@@ -1768,14 +1843,42 @@ wuffs_base__pixel_buffer::set_color_u32_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_at(this, x, y, color);
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(this, x, y,
|
||||
color);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer::set_color_u32_argb_premul_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(this, x, y,
|
||||
color);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer::set_color_u32_fill_rect(
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_fill_rect(this, rect, color);
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
this, rect, color);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer::set_color_u32_argb_premul_fill_rect(
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
this, rect, color);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer::set_color_u32_argb_nonpremul_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_nonpremul_at(this, x, y,
|
||||
color);
|
||||
}
|
||||
|
||||
inline bool //
|
||||
|
||||
@@ -49,6 +49,26 @@ wuffs_private_impl__swizzle_xxxx__y__x86_sse42(uint8_t* dst_ptr,
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(
|
||||
uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul);
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(
|
||||
uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul);
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul);
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_private_impl__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul);
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__color_u64__as__color_u32__swap_u32_argb_abgr(uint64_t c) {
|
||||
uint32_t a = ((uint32_t)(0xFF & (c >> 56)));
|
||||
@@ -156,7 +176,7 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
// --------
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
@@ -269,6 +289,365 @@ wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_nonpremul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color) {
|
||||
if (!pb) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if ((x >= pb->pixcfg.private_impl.width) ||
|
||||
(y >= pb->pixcfg.private_impl.height)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
|
||||
if (wuffs_base__pixel_format__is_planar(&pb->pixcfg.private_impl.pixfmt)) {
|
||||
// TODO: support planar formats.
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
size_t stride = pb->private_impl.planes[0].stride;
|
||||
uint8_t* row = pb->private_impl.planes[0].ptr + (stride * ((size_t)y));
|
||||
|
||||
switch (pb->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color));
|
||||
break;
|
||||
|
||||
// Common formats above. Rarer formats below.
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
wuffs_base__poke_u8__no_bounds_check(
|
||||
row + ((size_t)x),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u8_gray(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_gray(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
wuffs_base__poke_u16be__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_gray(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
|
||||
wuffs_base__poke_u8__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u8_gray(color |
|
||||
0xFF000000));
|
||||
wuffs_base__poke_u8__no_bounds_check(row + (2 * ((size_t)x)) + 1,
|
||||
((uint8_t)(color >> 24)));
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
|
||||
wuffs_base__poke_u8__no_bounds_check(
|
||||
row + ((size_t)x),
|
||||
wuffs_base__pixel_palette__closest_element(
|
||||
wuffs_base__pixel_buffer__palette(pb),
|
||||
pb->pixcfg.private_impl.pixfmt,
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
row + (3 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
wuffs_base__poke_u32le__no_bounds_check(row + (4 * ((size_t)x)), color);
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
row + (8 * ((size_t)x)), wuffs_base__color_u32__as__color_u64(color));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
row + (8 * ((size_t)x)),
|
||||
wuffs_base__color_u64_argb_nonpremul__as__color_u64_argb_premul(
|
||||
wuffs_base__color_u32__as__color_u64(color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)),
|
||||
(color >> 31)
|
||||
? (wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color) |
|
||||
0xFF000000)
|
||||
: 0);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
row + (3 * ((size_t)x)),
|
||||
wuffs_base__color_swap_u32_argb_abgr(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)), wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)),
|
||||
wuffs_base__color_swap_u32_argb_abgr(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: support more formats.
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
static inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__composite_color_u32_nonpremul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color) {
|
||||
if (!pb) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if ((x >= pb->pixcfg.private_impl.width) ||
|
||||
(y >= pb->pixcfg.private_impl.height)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
|
||||
if (wuffs_base__pixel_format__is_planar(&pb->pixcfg.private_impl.pixfmt)) {
|
||||
// TODO: support planar formats.
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
size_t stride = pb->private_impl.planes[0].stride;
|
||||
uint8_t* row = pb->private_impl.planes[0].ptr + (stride * ((size_t)y));
|
||||
|
||||
switch (pb->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr) | 0xFF000000;
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
// Common formats above. Rarer formats below.
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y: {
|
||||
uint8_t* ptr = row + ((size_t)x);
|
||||
uint32_t dst = 0xFF000000 | (0x00010101 * ((uint32_t)(*ptr)));
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
*ptr = ((uint8_t)(dst));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE: {
|
||||
uint8_t* ptr = row + (2 * ((size_t)x));
|
||||
uint64_t dst =
|
||||
0xFFFF000000000000 |
|
||||
(0x000100010001 *
|
||||
((uint64_t)(wuffs_base__peek_u16le__no_bounds_check(ptr))));
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u64_axxx(
|
||||
dst, wuffs_base__color_u32__as__color_u64(color));
|
||||
wuffs_base__poke_u16le__no_bounds_check(ptr, ((uint16_t)(dst)));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE: {
|
||||
uint8_t* ptr = row + (2 * ((size_t)x));
|
||||
uint64_t dst =
|
||||
0xFFFF000000000000 |
|
||||
(0x000100010001 *
|
||||
((uint64_t)(wuffs_base__peek_u16be__no_bounds_check(ptr))));
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u64_axxx(
|
||||
dst, wuffs_base__color_u32__as__color_u64(color));
|
||||
wuffs_base__poke_u16be__no_bounds_check(ptr, ((uint16_t)(dst)));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL: {
|
||||
uint8_t* ptr = row + (2 * ((size_t)x));
|
||||
uint32_t dst =
|
||||
(((uint32_t)(ptr[1])) << 24) | (((uint32_t)(ptr[0])) * 0x00010101);
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(dst,
|
||||
color);
|
||||
ptr[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(dst |
|
||||
0xFF000000);
|
||||
ptr[1] = ((uint8_t)(dst >> 24));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL: {
|
||||
wuffs_base__slice_u8 palette = wuffs_base__pixel_buffer__palette(pb);
|
||||
if (palette.len) {
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(
|
||||
palette.ptr + (4 * ((size_t)row[x])));
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(dst,
|
||||
color);
|
||||
row[x] = wuffs_base__pixel_palette__closest_element(
|
||||
wuffs_base__pixel_buffer__palette(pb),
|
||||
pb->pixcfg.private_impl.pixfmt,
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
dst));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY: {
|
||||
wuffs_base__slice_u8 palette = wuffs_base__pixel_buffer__palette(pb);
|
||||
if (palette.len) {
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(
|
||||
palette.ptr + (4 * ((size_t)row[x])));
|
||||
dst =
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
row[x] = wuffs_base__pixel_palette__closest_element(
|
||||
wuffs_base__pixel_buffer__palette(pb),
|
||||
pb->pixcfg.private_impl.pixfmt, dst);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565: {
|
||||
uint8_t* ptr = row + (2 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u16le__no_bounds_check(ptr));
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
ptr, wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(dst));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR: {
|
||||
uint8_t* ptr = row + (3 * ((size_t)x));
|
||||
uint32_t dst = 0xFF000000 | wuffs_base__peek_u24le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
wuffs_base__poke_u24le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(dst,
|
||||
color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE: {
|
||||
uint8_t* ptr = row + (8 * ((size_t)x));
|
||||
uint64_t dst = wuffs_base__peek_u64le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(
|
||||
dst, wuffs_base__color_u32__as__color_u64(color));
|
||||
wuffs_base__poke_u64le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE: {
|
||||
uint8_t* ptr = row + (8 * ((size_t)x));
|
||||
uint64_t dst = wuffs_base__peek_u64le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u64_axxx(
|
||||
dst, wuffs_base__color_u32__as__color_u64(color));
|
||||
wuffs_base__poke_u64le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
if (dst) {
|
||||
dst =
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
} else if (color >> 31) {
|
||||
dst = (wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color) |
|
||||
0xFF000000);
|
||||
}
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB: {
|
||||
uint8_t* ptr = row + (3 * ((size_t)x));
|
||||
uint32_t dst = 0xFF000000 | wuffs_base__peek_u24le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
dst, wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
wuffs_base__poke_u24le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(
|
||||
dst, wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
dst, wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr) | 0xFF000000;
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
dst, wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// TODO: support more formats.
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static inline void //
|
||||
@@ -396,7 +775,7 @@ wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxxxxxx(
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
@@ -468,7 +847,7 @@ wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
for (y = rect.min_incl_y; y < rect.max_excl_y; y++) {
|
||||
uint32_t x;
|
||||
for (x = rect.min_incl_x; x < rect.max_excl_x; x++) {
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(pb, x, y, color);
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(pb, x, y, color);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_status(NULL);
|
||||
|
||||
@@ -115,6 +115,102 @@ typedef void (*wuffs_private_impl__swizzle_ycc__convert_4_func)(
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3);
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycca_bt601sr_src__convert_4_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3) {
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
color &= 0xFFFFFFu;
|
||||
color |= ((uint32_t)(*up3++)) << 24;
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_nonpremul_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycca_bt601sr_src__convert_4_bgra_premul(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3) {
|
||||
size_t stride = dst->private_impl.planes[0].stride;
|
||||
uint8_t* row = dst->private_impl.planes[0].ptr + (stride * ((size_t)y));
|
||||
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
color &= 0xFFFFFFu;
|
||||
color |= ((uint32_t)(*up3++)) << 24;
|
||||
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst_color =
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst_color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycca_bt601sr_src_over__convert_4_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3) {
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
color &= 0xFFFFFFu;
|
||||
color |= ((uint32_t)(*up3++)) << 24;
|
||||
wuffs_base__pixel_buffer__composite_color_u32_nonpremul_at(dst, x, y,
|
||||
color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycca_bt601sr_src_over__convert_4_bgra_premul(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3) {
|
||||
size_t stride = dst->private_impl.planes[0].stride;
|
||||
uint8_t* row = dst->private_impl.planes[0].ptr + (stride * ((size_t)y));
|
||||
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
color &= 0xFFFFFFu;
|
||||
color |= ((uint32_t)(*up3++)) << 24;
|
||||
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst_color = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst_color = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
dst_color, color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst_color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_cmyk__convert_4_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
@@ -136,7 +232,7 @@ wuffs_private_impl__swizzle_cmyk__convert_4_general(
|
||||
r = ((r * w) + 0x7Fu) / 0xFFu;
|
||||
g = ((g * w) + 0x7Fu) / 0xFFu;
|
||||
b = ((b * w) + 0x7Fu) / 0xFFu;
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
dst, x, y, 0xFF000000u | (r << 16u) | (g << 8u) | (b << 0u));
|
||||
}
|
||||
}
|
||||
@@ -163,7 +259,7 @@ wuffs_private_impl__swizzle_ycck__convert_4_general(
|
||||
r = ((r * w) + 0x7Fu) / 0xFFu;
|
||||
g = ((g * w) + 0x7Fu) / 0xFFu;
|
||||
b = ((b * w) + 0x7Fu) / 0xFFu;
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
dst, x, y, 0xFF000000u | (r << 16u) | (g << 8u) | (b << 0u));
|
||||
}
|
||||
}
|
||||
@@ -193,7 +289,7 @@ wuffs_private_impl__swizzle_rgb__convert_3_general(
|
||||
(((uint32_t)(*up0++)) << 16u) | //
|
||||
(((uint32_t)(*up1++)) << 8u) | //
|
||||
(((uint32_t)(*up2++)) << 0u);
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +306,7 @@ wuffs_private_impl__swizzle_ycc_bt601fr__convert_3_general(
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601fr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +367,7 @@ wuffs_private_impl__swizzle_ycc_bt601sr__convert_3_general(
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1477,7 +1573,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
}
|
||||
|
||||
if (wuffs_base__pixel_format__is_planar(&dst->pixcfg.private_impl.pixfmt)) {
|
||||
// TODO: see wuffs_base__pixel_buffer__set_color_u32_at's TODO.
|
||||
// TODO: see wuffs_base__pixel_buffer__set_color_u32_argb_premul_at's TODO.
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
}
|
||||
@@ -1552,7 +1648,8 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: see wuffs_base__pixel_buffer__set_color_u32_at's TODO.
|
||||
// TODO: see wuffs_base__pixel_buffer__set_color_u32_argb_premul_at's
|
||||
// TODO.
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
}
|
||||
@@ -1565,7 +1662,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
if (ycc_model >= WUFFS_BASE__YCC_MODEL__RGB) {
|
||||
conv3func = &wuffs_private_impl__swizzle_rgb__convert_3_general;
|
||||
|
||||
} else if (ycc_model == WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE) {
|
||||
} else if (ycc_model >= WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE) {
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
@@ -1710,14 +1807,39 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
}
|
||||
|
||||
if ((h3 != 0u) || (v3 != 0u)) {
|
||||
if (ycc_model == WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE) {
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func = NULL;
|
||||
switch (ycc_model) {
|
||||
case WUFFS_BASE__YCC_MODEL__BT_601_FULL_RANGE:
|
||||
conv4func = &wuffs_private_impl__swizzle_ycck__convert_4_general;
|
||||
break;
|
||||
case WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC:
|
||||
if (dst->pixcfg.private_impl.pixfmt.repr ==
|
||||
WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL) {
|
||||
conv4func =
|
||||
&wuffs_private_impl__swizzle_ycca_bt601sr_src__convert_4_bgra_premul;
|
||||
} else {
|
||||
conv4func =
|
||||
&wuffs_private_impl__swizzle_ycca_bt601sr_src__convert_4_general;
|
||||
}
|
||||
break;
|
||||
case WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC_OVER:
|
||||
if (dst->pixcfg.private_impl.pixfmt.repr ==
|
||||
WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL) {
|
||||
conv4func =
|
||||
&wuffs_private_impl__swizzle_ycca_bt601sr_src_over__convert_4_bgra_premul;
|
||||
} else {
|
||||
conv4func =
|
||||
&wuffs_private_impl__swizzle_ycca_bt601sr_src_over__convert_4_general;
|
||||
}
|
||||
break;
|
||||
case WUFFS_BASE__YCC_MODEL__CMY:
|
||||
conv4func = &wuffs_private_impl__swizzle_cmyk__convert_4_general;
|
||||
break;
|
||||
default:
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
}
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func =
|
||||
(ycc_model >= WUFFS_BASE__YCC_MODEL__RGB)
|
||||
? &wuffs_private_impl__swizzle_cmyk__convert_4_general
|
||||
: &wuffs_private_impl__swizzle_ycck__convert_4_general;
|
||||
|
||||
(*func4)( //
|
||||
dst, x_min_incl, x_max_excl, y_min_incl, y_max_excl, //
|
||||
src0.ptr, src1.ptr, src2.ptr, src3.ptr, //
|
||||
|
||||
@@ -230,7 +230,12 @@ wuffs_drop_in__stb__load1( //
|
||||
}
|
||||
|
||||
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;
|
||||
wuffs_base__range_ii_u64 r = wuffs_base__image_decoder__workbuf_len(dec);
|
||||
if (wuffs_base__range_ii_u64__is_empty(&r)) {
|
||||
wuffs_drop_in__stb__g_failure_reason = "indeterminate workbuf length";
|
||||
return NULL;
|
||||
}
|
||||
uint64_t workbuf_len = r.max_incl;
|
||||
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
|
||||
if ((pixbuf_len > ((uint64_t)SIZE_MAX)) ||
|
||||
(workbuf_len > ((uint64_t)SIZE_MAX))) {
|
||||
|
||||
@@ -551,8 +551,16 @@ func (g *gen) writeExprUserDefinedCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
return fmt.Errorf("cannot generate user-defined method call %q for receiver type %q",
|
||||
n.Str(g.tm), recv.MType().Str(g.tm))
|
||||
}
|
||||
|
||||
qid := recvTyp.QID()
|
||||
b.printf("%s%s__%s(", g.packagePrefix(qid), qid[1].Str(g.tm), method.Ident().Str(g.tm))
|
||||
pkgStr := g.packagePrefix(qid)
|
||||
typStr := qid[1].Str(g.tm)
|
||||
methodStr := method.Ident().Str(g.tm)
|
||||
if (qid[0] == t.IDBase) && qid[1].IsRangeType() && strings.HasPrefix(methodStr, "get_") {
|
||||
pkgStr = "wuffs_private_impl__"
|
||||
}
|
||||
b.printf("%s%s__%s(", pkgStr, typStr, methodStr)
|
||||
|
||||
if !recvTyp.IsEtcUtilityType() {
|
||||
b.writes(addr)
|
||||
if err := g.writeExpr(b, recv, false, depth); err != nil {
|
||||
|
||||
+14
-1
@@ -115,6 +115,11 @@ var Consts = [...]struct {
|
||||
|
||||
// ----
|
||||
|
||||
{t.IDU8, "0", "PIXEL_BLEND__SRC"},
|
||||
{t.IDU8, "1", "PIXEL_BLEND__SRC_OVER"},
|
||||
|
||||
// ----
|
||||
|
||||
{t.IDU32, "0x02000008", "PIXEL_FORMAT__A"},
|
||||
|
||||
{t.IDU32, "0x20000008", "PIXEL_FORMAT__Y"},
|
||||
@@ -245,7 +250,9 @@ var Consts = [...]struct {
|
||||
// ----
|
||||
|
||||
{t.IDU32, "0x00", "YCC_MODEL__BT_601_FULL_RANGE"},
|
||||
{t.IDU32, "0x01", "YCC_MODEL__BT_601_STUDIO_RANGE"},
|
||||
{t.IDU32, "0x04", "YCC_MODEL__BT_601_STUDIO_RANGE"},
|
||||
{t.IDU32, "0x06", "YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC"},
|
||||
{t.IDU32, "0x07", "YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC_OVER"},
|
||||
{t.IDU32, "0x40", "YCC_MODEL__RGB"},
|
||||
{t.IDU32, "0x80", "YCC_MODEL__CMY"},
|
||||
|
||||
@@ -396,6 +403,7 @@ var funcsOther = [...]string{
|
||||
// ---- utility
|
||||
|
||||
"utility.cpu_arch_is_32_bit() bool",
|
||||
"utility.demake_pixel_blend(a: pixel_blend) u8",
|
||||
"utility.empty_io_reader() io_reader",
|
||||
"utility.empty_io_writer() io_writer",
|
||||
"utility.empty_range_ii_u32() range_ii_u32",
|
||||
@@ -408,6 +416,7 @@ var funcsOther = [...]string{
|
||||
"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_blend(repr: u8) pixel_blend",
|
||||
"utility.make_pixel_format(repr: u32) pixel_format",
|
||||
"utility.make_range_ii_u32(min_incl: u32, max_incl: u32) range_ii_u32",
|
||||
"utility.make_range_ie_u32(min_incl: u32, max_excl: u32) range_ie_u32",
|
||||
@@ -431,21 +440,25 @@ var funcsOther = [...]string{
|
||||
"range_ie_u32.get_min_incl() u32",
|
||||
"range_ie_u32.get_max_excl() u32",
|
||||
"range_ie_u32.intersect(r: range_ie_u32) range_ie_u32",
|
||||
"range_ie_u32.is_empty() bool",
|
||||
"range_ie_u32.unite(r: range_ie_u32) range_ie_u32",
|
||||
|
||||
"range_ii_u32.get_min_incl() u32",
|
||||
"range_ii_u32.get_max_incl() u32",
|
||||
"range_ii_u32.intersect(r: range_ii_u32) range_ii_u32",
|
||||
"range_ii_u32.is_empty() bool",
|
||||
"range_ii_u32.unite(r: range_ii_u32) range_ii_u32",
|
||||
|
||||
"range_ie_u64.get_min_incl() u64",
|
||||
"range_ie_u64.get_max_excl() u64",
|
||||
"range_ie_u64.intersect(r: range_ie_u64) range_ie_u64",
|
||||
"range_ie_u64.is_empty() bool",
|
||||
"range_ie_u64.unite(r: range_ie_u64) range_ie_u64",
|
||||
|
||||
"range_ii_u64.get_min_incl() u64",
|
||||
"range_ii_u64.get_max_incl() u64",
|
||||
"range_ii_u64.intersect(r: range_ii_u64) range_ii_u64",
|
||||
"range_ii_u64.is_empty() bool",
|
||||
"range_ii_u64.unite(r: range_ii_u64) range_ii_u64",
|
||||
|
||||
// ---- more_information
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// Copyright 2026 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
|
||||
|
||||
package suitar_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/google/wuffs/lib/suitar"
|
||||
)
|
||||
|
||||
func Example_minimal() {
|
||||
// This mimics Example_minimal from the standard library's archive/tar.
|
||||
//
|
||||
// This package's Writer is a little more strict, rejecting an (implicit)
|
||||
// zero-valued Header.Typeflag or Header.ModTime that archive/tar accepts.
|
||||
// Header.Mode must also be 0o644 (or 0o755), not 0o600.
|
||||
|
||||
// Create and add some files to the archive.
|
||||
var buf bytes.Buffer
|
||||
tw := suitar.NewWriter(&buf)
|
||||
var files = []struct {
|
||||
Name, Body string
|
||||
}{
|
||||
{"readme.txt", "This archive contains some text files."},
|
||||
{"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},
|
||||
{"todo.txt", "Get animal handling license."},
|
||||
}
|
||||
for _, file := range files {
|
||||
hdr := &suitar.Header{
|
||||
Typeflag: suitar.TypeReg,
|
||||
Name: file.Name,
|
||||
Size: int64(len(file.Body)),
|
||||
Mode: suitar.Mode644,
|
||||
ModTime: time.Unix(0, 0),
|
||||
}
|
||||
if err := tw.WriteHeader(hdr); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if _, err := tw.Write([]byte(file.Body)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := tw.Close(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Open and iterate through the files in the archive.
|
||||
tr := suitar.NewReader(&buf)
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
break // End of archive
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("Contents of %s:\n", hdr.Name)
|
||||
if _, err := io.Copy(os.Stdout, tr); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// Output:
|
||||
// Contents of readme.txt:
|
||||
// This archive contains some text files.
|
||||
// Contents of gopher.txt:
|
||||
// Gopher names:
|
||||
// George
|
||||
// Geoffrey
|
||||
// Gonzo
|
||||
// Contents of todo.txt:
|
||||
// Get animal handling license.
|
||||
}
|
||||
@@ -0,0 +1,677 @@
|
||||
// Copyright 2026 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
|
||||
|
||||
// ----------------
|
||||
|
||||
// Package suitar implements the SUITAR archive file format.
|
||||
//
|
||||
// SUITAR is a subset of the TAR archive file format (including its popular
|
||||
// USTAR, PAX and GNU extensions). This package's API is a subset of the
|
||||
// standard library's archive/tar package.
|
||||
//
|
||||
// Being a subset means that this package's implementation is about 600 lines
|
||||
// of Go code, compared to archive/tar being about 3000, a factor of 5×.
|
||||
//
|
||||
// The SUITAR specification is at
|
||||
// https://github.com/google/wuffs/blob/main/doc/spec/suitar-spec.md
|
||||
package suitar
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
var (
|
||||
errBadFileName = errors.New("suitar: bad file name")
|
||||
errBadHeader = errors.New("suitar: bad header")
|
||||
errBadPadding = errors.New("suitar: bad padding")
|
||||
errClosed = errors.New("suitar: closed")
|
||||
errHeaderSize = errors.New("suitar: inconsistent Header.Size and Write length")
|
||||
errHeaderTypeflag = errors.New("suitar: inconsistent Header.Typeflag for Write")
|
||||
)
|
||||
|
||||
// lenMagic makes headerBlockTemplate[:lenMagic] SUITAR's magic signature.
|
||||
const lenMagic = 12
|
||||
|
||||
// headerBlockTemplate is the contents of each 512-byte header block. Each
|
||||
// SUITAR archive entry (a file or directory) consists of: 1 header block (with
|
||||
// typeflag typeGNULongName), the file name, 1 header block (with typeflag
|
||||
// TypeReg or TypeDir or TypeGNUSparse) and the file contents.
|
||||
//
|
||||
// '?' bytes mean that the header block's bytes can vary at that position.
|
||||
// Otherwise, the bytes are hard-coded. SUITAR is a stricter subset of TAR.
|
||||
const headerBlockTemplate = "\x13sUItAR\x00\xFE\xFDv1\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x000000???\x000177" + // ??? = mode bits, 0177776 = uid("nobody").
|
||||
"776\x000177776\x00\x80\x00\x00\x00" +
|
||||
|
||||
"????????\x80\x00\x00\x00????" + // ???????? = physical file size, ???????? = modTime.
|
||||
"??????????\x00 ?\x00\x00\x00" + // ?????? = checksum, ? = typeflag.
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
|
||||
"\x00ustar \x00nobody\x00" + // "ustar " mid-block magic signature, "nobody" ≈ uid.
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00nobody\x00" + // "nobody" ≈ gid.
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
|
||||
// The 128-byte tail of this headerBlockTemplate only applies to
|
||||
// TypeGNUSparse blocks. Otherwise, the final 128 bytes must be NUL.
|
||||
"\x00\x00\x80\x00\x00\x00????????\x80\x00" + // ???????? = sparse anti-hole offset (and its length is 0).
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x80\x00\x00\x00????????\x00" + // ???????? = sparse logical file size.
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
|
||||
// Valid values for Header.Typeflag. The zero value is invalid.
|
||||
const (
|
||||
TypeReg = '0' // Regular file (with contents).
|
||||
TypeDir = '5' // Directory (with no contents).
|
||||
TypeGNUSparse = 'S' // Sparse file (its contents are all NUL bytes).
|
||||
|
||||
typeGNULongName = 'L'
|
||||
)
|
||||
|
||||
// Valid values for Header.Mode. The zero value is invalid.
|
||||
const (
|
||||
Mode644 = int64(0o644) // "rw-r--r--" mode bits, also known as permission bits.
|
||||
Mode755 = int64(0o755) // "rwxr-xr-x" mode bits, also known as permission bits.
|
||||
)
|
||||
|
||||
// IsValidHeaderName returns whether name is a valid Header.Name field value.
|
||||
func IsValidHeaderName(name string) bool {
|
||||
return (len(name) < 4096) &&
|
||||
(name != "") &&
|
||||
(name != ".") &&
|
||||
(name != "..") &&
|
||||
(name[0] != '/') &&
|
||||
(name[len(name)-1] != '/') &&
|
||||
!strings.HasPrefix(name, "./") &&
|
||||
!strings.HasPrefix(name, "../") &&
|
||||
!strings.Contains(name, "//") &&
|
||||
!strings.Contains(name, "/./") &&
|
||||
!strings.Contains(name, "/../") &&
|
||||
!containsASCIIControlCharactersOrDel(name) &&
|
||||
utf8.ValidString(name)
|
||||
}
|
||||
|
||||
func containsASCIIControlCharactersOrDel(s string) bool {
|
||||
for i := range len(s) {
|
||||
if c := s[i]; (c < 0x20) || (c == 0x7F) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isAllZeroes(b []byte) bool {
|
||||
for _, c := range b {
|
||||
if c != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func readFullNoEOF(r io.Reader, b []byte) (int, error) {
|
||||
n, err := io.ReadFull(r, b)
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func u64le(b []byte) uint64 {
|
||||
return (uint64(b[0]) << 56) |
|
||||
(uint64(b[1]) << 48) |
|
||||
(uint64(b[2]) << 40) |
|
||||
(uint64(b[3]) << 32) |
|
||||
(uint64(b[4]) << 24) |
|
||||
(uint64(b[5]) << 16) |
|
||||
(uint64(b[6]) << 8) |
|
||||
(uint64(b[7]) << 0)
|
||||
}
|
||||
|
||||
func roundUp512(n uint64) uint64 {
|
||||
return (n + 511) &^ 511
|
||||
}
|
||||
|
||||
type block [512]byte
|
||||
|
||||
func (b *block) calculateChecksum() uint32 {
|
||||
checksum := uint32(0)
|
||||
|
||||
for _, c := range b[0x000:0x094] {
|
||||
checksum += uint32(c)
|
||||
}
|
||||
|
||||
// The 8 checksum bytes have value 32 when calculating the checksum itself.
|
||||
checksum += 256
|
||||
|
||||
for _, c := range b[0x09C:0x200] {
|
||||
checksum += uint32(c)
|
||||
}
|
||||
|
||||
return checksum
|
||||
}
|
||||
|
||||
func (b *block) setChecksum() {
|
||||
checksum := b.calculateChecksum()
|
||||
|
||||
b[0x09B] = ' '
|
||||
b[0x09A] = '\x00'
|
||||
for i := range 6 {
|
||||
b[0x099-i] = '0' + byte(checksum&7)
|
||||
checksum >>= 3
|
||||
}
|
||||
}
|
||||
|
||||
func (b *block) isValidHeader(which int) bool {
|
||||
// Compare b to the headerBlockTemplate. Blocks that aren't TypeGNUSparse
|
||||
// must end in 128 NUL bytes.
|
||||
end := 0x200
|
||||
if typeflag := b[0x09C]; typeflag != TypeGNUSparse {
|
||||
end = 0x180
|
||||
}
|
||||
for i := range end {
|
||||
if c := headerBlockTemplate[i]; (c != '?') && (c != b[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if (end == 0x180) && !isAllZeroes(b[0x180:0x200]) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check the mode bits.
|
||||
if (b[0x0068] == '6') && (b[0x0069] == '4') && (b[0x006A] == '4') {
|
||||
// No-op.
|
||||
} else if (b[0x0068] == '7') && (b[0x0069] == '5') && (b[0x006A] == '5') && (which == 1) {
|
||||
// No-op.
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check the checksum.
|
||||
checksum := b.calculateChecksum()
|
||||
for i := range 6 {
|
||||
if b[0x099-i] != ('0' + byte(checksum&7)) {
|
||||
return false
|
||||
}
|
||||
checksum >>= 3
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Header is a single header in a SUITAR archive.
|
||||
//
|
||||
// It is a subset of tar.Header from the standard library's archive/tar
|
||||
// package, but it is stricter about what field values are valid.
|
||||
type Header struct {
|
||||
Typeflag byte
|
||||
Name string
|
||||
Size int64
|
||||
Mode int64
|
||||
ModTime time.Time
|
||||
}
|
||||
|
||||
// Valid returns whether h is valid to pass to a Writer. Specifically:
|
||||
//
|
||||
// - Typeflag must be one of three values (TypeReg, TypeDir, TypeGNUSparse).
|
||||
// In particular, it cannot be zero.
|
||||
// - Name must satisfy IsValidHeaderName.
|
||||
// - Size must be non-negative. It must be 0 if Typeflag is TypeDir.
|
||||
// - Mode must be one of two values (Mode644, Mode755). It must be Mode755 if
|
||||
// Typeflag is TypeDir.
|
||||
// - ModTime.Unix() must be a non-negative int64. In particular, ModTime must
|
||||
// be on or after 1 January 1970 and so cannot be the zero time.Time (which
|
||||
// is 1 January Year-1).
|
||||
// - Size and ModTime.Unix() must also be less than (1 << 53).
|
||||
//
|
||||
// A Header returned (without error) by a Reader will always be valid.
|
||||
func (h *Header) Valid() bool {
|
||||
if h == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
switch h.Typeflag {
|
||||
default:
|
||||
return false
|
||||
case TypeDir:
|
||||
if (h.Size != 0) || (h.Mode != Mode755) {
|
||||
return false
|
||||
}
|
||||
case TypeReg, TypeGNUSparse:
|
||||
if (h.Mode != Mode644) && (h.Mode != Mode755) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const maxExcl = 1 << 53
|
||||
m := h.ModTime.Unix()
|
||||
return (0 <= h.Size) && (h.Size < maxExcl) &&
|
||||
(0 <= m) && (m < maxExcl) &&
|
||||
IsValidHeaderName(h.Name)
|
||||
}
|
||||
|
||||
// NewWriter creates a new Writer writing to w.
|
||||
func NewWriter(w io.Writer) *Writer {
|
||||
return &Writer{w: w}
|
||||
}
|
||||
|
||||
// Writer provides sequential writing of a SUITAR archive.
|
||||
type Writer struct {
|
||||
err error
|
||||
w io.Writer
|
||||
header Header
|
||||
remaining int64
|
||||
bIndex int32
|
||||
block block
|
||||
nameBuf [4096]byte
|
||||
}
|
||||
|
||||
func (w *Writer) flush() error {
|
||||
if w.err != nil {
|
||||
return w.err
|
||||
} else if w.remaining != 0 {
|
||||
w.err = errHeaderSize
|
||||
return w.err
|
||||
} else if w.bIndex != 0 {
|
||||
clear(w.block[w.bIndex:])
|
||||
if _, err := w.w.Write(w.block[:]); err != nil {
|
||||
w.err = err
|
||||
return w.err
|
||||
}
|
||||
w.bIndex = 0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteHeader writes h and prepares to accept the file's contents (as w is
|
||||
// also an io.Writer).
|
||||
func (w *Writer) WriteHeader(h *Header) error {
|
||||
if err := w.flush(); err != nil {
|
||||
return err
|
||||
} else if !h.Valid() {
|
||||
w.err = errBadHeader
|
||||
return w.err
|
||||
}
|
||||
w.header = *h
|
||||
|
||||
n := len(w.header.Name)
|
||||
copy(w.nameBuf[:], w.header.Name)
|
||||
w.nameBuf[n] = 0
|
||||
|
||||
initBlock(&w.block, typeGNULongName, int64(n+1), Mode644, 0)
|
||||
if _, err := w.w.Write(w.block[:]); err != nil {
|
||||
w.err = err
|
||||
return w.err
|
||||
}
|
||||
|
||||
w.remaining = int64(n + 1)
|
||||
|
||||
if _, err := w.Write(w.nameBuf[:n+1]); err != nil {
|
||||
w.err = err
|
||||
return w.err
|
||||
} else if err = w.flush(); err != nil {
|
||||
w.err = err
|
||||
return w.err
|
||||
}
|
||||
|
||||
initBlock(&w.block, w.header.Typeflag, w.header.Size, w.header.Mode, w.header.ModTime.Unix())
|
||||
if _, err := w.w.Write(w.block[:]); err != nil {
|
||||
w.err = err
|
||||
return w.err
|
||||
}
|
||||
|
||||
w.remaining = w.header.Size
|
||||
if w.header.Typeflag == TypeGNUSparse {
|
||||
w.remaining = 0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initBlock(b *block, typeflag byte, size int64, mode int64, modTime int64) {
|
||||
// 0o0177776 octal is 65534, which is Debian's UID/GID for "nobody".
|
||||
const uidForNobody = "0177776"
|
||||
|
||||
clear(b[:])
|
||||
copy(b[:], headerBlockTemplate[:lenMagic])
|
||||
|
||||
modeBits := "0000644"
|
||||
if mode == Mode755 {
|
||||
modeBits = "0000755"
|
||||
}
|
||||
copy(b[0x064:], modeBits)
|
||||
copy(b[0x06C:], uidForNobody)
|
||||
copy(b[0x074:], uidForNobody)
|
||||
|
||||
physicalSize := size
|
||||
if typeflag == TypeGNUSparse {
|
||||
physicalSize = 0
|
||||
}
|
||||
setI64(b, 0x07C, physicalSize)
|
||||
|
||||
setI64(b, 0x088, modTime)
|
||||
b[0x09C] = typeflag
|
||||
copy(b[0x101:], "ustar ")
|
||||
copy(b[0x109:], "nobody")
|
||||
copy(b[0x129:], "nobody")
|
||||
|
||||
if typeflag == TypeGNUSparse {
|
||||
setI64(b, 0x182, size)
|
||||
setI64(b, 0x18E, 0)
|
||||
setI64(b, 0x1E3, size)
|
||||
}
|
||||
|
||||
b.setChecksum()
|
||||
}
|
||||
|
||||
func setI64(b *block, offset int, value int64) {
|
||||
// The 0x80 uses base-256 instead of octal, allowing file sizes >= 8GiB.
|
||||
b[offset] = 0x80
|
||||
for i := range 8 {
|
||||
b[(offset+11)-i] = byte(value)
|
||||
value >>= 8
|
||||
}
|
||||
}
|
||||
|
||||
// Write satisfies io.Writer.
|
||||
func (w *Writer) Write(b []byte) (int, error) {
|
||||
if w.err != nil {
|
||||
return 0, w.err
|
||||
} else if (w.header.Typeflag != TypeReg) && (w.header.Typeflag != TypeGNUSparse) {
|
||||
w.err = errHeaderTypeflag
|
||||
return 0, w.err
|
||||
} else if len(b) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
tooMuch := int64(len(b)) > w.remaining
|
||||
if tooMuch {
|
||||
b = b[:w.remaining]
|
||||
}
|
||||
|
||||
ret := 0
|
||||
for len(b) > 0 {
|
||||
if w.bIndex == 0 {
|
||||
split := len(b) &^ 511
|
||||
prefix, suffix := b[:split], b[split:]
|
||||
|
||||
if len(prefix) > 0 {
|
||||
n, err := w.w.Write(prefix)
|
||||
w.remaining -= int64(n)
|
||||
ret += n
|
||||
if err != nil {
|
||||
w.err = err
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(suffix) > 0 {
|
||||
w.bIndex = int32(copy(w.block[:], suffix))
|
||||
w.remaining -= int64(w.bIndex)
|
||||
ret += int(w.bIndex)
|
||||
}
|
||||
|
||||
b = nil
|
||||
break
|
||||
}
|
||||
|
||||
n := copy(w.block[w.bIndex:], b)
|
||||
w.bIndex += int32(n)
|
||||
w.remaining -= int64(n)
|
||||
ret += n
|
||||
b = b[n:]
|
||||
|
||||
if int(w.bIndex) < len(w.block) {
|
||||
continue
|
||||
} else if _, err := w.w.Write(w.block[:]); err != nil {
|
||||
w.err = err
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if tooMuch && (w.err == nil) {
|
||||
w.err = errHeaderSize
|
||||
}
|
||||
|
||||
return ret, w.err
|
||||
}
|
||||
|
||||
// Close satisfies io.Closer. It closes the entire archive, not just one entry.
|
||||
func (w *Writer) Close() error {
|
||||
if err := w.flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
clear(w.nameBuf[:1024])
|
||||
if _, err := w.w.Write(w.nameBuf[:1024]); err != nil {
|
||||
w.err = err
|
||||
return err
|
||||
}
|
||||
w.err = errClosed
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewReader creates a new Reader reading from r.
|
||||
func NewReader(r io.Reader) *Reader {
|
||||
return &Reader{r: r}
|
||||
}
|
||||
|
||||
// Reader provides sequential reading of a SUITAR archive.
|
||||
type Reader struct {
|
||||
err error
|
||||
r io.Reader
|
||||
remaining int64
|
||||
numPadding int32
|
||||
sparse bool
|
||||
block block
|
||||
nameBuf [4096]byte
|
||||
}
|
||||
|
||||
// Next advances to the next entry in the SUITAR archive, preparing to read the
|
||||
// file's contents (as r is also an io.Reader).
|
||||
func (r *Reader) Next() (Header, error) {
|
||||
if r.err != nil {
|
||||
return Header{}, r.err
|
||||
} else if r.remaining > 0 {
|
||||
if _, err := io.Copy(io.Discard, r); err != nil {
|
||||
r.err = err
|
||||
return Header{}, r.err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := readFullNoEOF(r.r, r.block[:]); err != nil {
|
||||
r.err = err
|
||||
return Header{}, r.err
|
||||
} else if r.block[0x09C] == 0 {
|
||||
// SUITAR ends with 2 blocks (1024 bytes) of zeroes.
|
||||
if !isAllZeroes(r.block[:]) {
|
||||
r.err = errBadHeader
|
||||
return Header{}, r.err
|
||||
} else if _, err := readFullNoEOF(r.r, r.block[:]); err != nil {
|
||||
r.err = err
|
||||
return Header{}, r.err
|
||||
} else if !isAllZeroes(r.block[:]) {
|
||||
r.err = errBadHeader
|
||||
return Header{}, r.err
|
||||
}
|
||||
r.err = io.EOF
|
||||
return Header{}, r.err
|
||||
}
|
||||
|
||||
nameLenInclNul, err := parseBlock0(&r.block)
|
||||
if err != nil {
|
||||
r.err = err
|
||||
return Header{}, r.err
|
||||
}
|
||||
|
||||
n1 := nameLenInclNul - 1
|
||||
n2 := roundUp512(nameLenInclNul)
|
||||
if _, err := readFullNoEOF(r.r, r.nameBuf[:n2]); err != nil {
|
||||
r.err = err
|
||||
return Header{}, r.err
|
||||
}
|
||||
name := string(r.nameBuf[:n1])
|
||||
if !IsValidHeaderName(name) || !isAllZeroes(r.nameBuf[n1:n2]) {
|
||||
r.err = errBadFileName
|
||||
return Header{}, r.err
|
||||
}
|
||||
|
||||
if _, err := readFullNoEOF(r.r, r.block[:0x200]); err != nil {
|
||||
return Header{}, err
|
||||
}
|
||||
typeflag, size, mode, modTime, err := parseBlock1(&r.block)
|
||||
if err != nil {
|
||||
return Header{}, err
|
||||
}
|
||||
|
||||
r.remaining = size
|
||||
r.numPadding = int32(roundUp512(uint64(size)) - uint64(size))
|
||||
r.sparse = typeflag == TypeGNUSparse
|
||||
|
||||
return Header{
|
||||
Typeflag: typeflag,
|
||||
Name: name,
|
||||
Size: size,
|
||||
Mode: mode,
|
||||
ModTime: time.Unix(modTime, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func parseBlock0(b *block) (uint64, error) {
|
||||
if !b.isValidHeader(0) {
|
||||
return 0, errBadHeader
|
||||
}
|
||||
|
||||
size := u64le(b[0x080:])
|
||||
modTime := u64le(b[0x08C:])
|
||||
if (size < 2) || (4097 <= size) {
|
||||
return 0, errBadFileName
|
||||
} else if (modTime != 0) || (b[0x09C] != 'L') {
|
||||
return 0, errBadHeader
|
||||
}
|
||||
|
||||
return size, nil
|
||||
}
|
||||
|
||||
func parseBlock1(b *block) (byte, int64, int64, int64, error) {
|
||||
if !b.isValidHeader(1) {
|
||||
return 0, 0, 0, 0, errBadHeader
|
||||
}
|
||||
|
||||
typeflag := b[0x09C]
|
||||
if (typeflag != TypeReg) && (typeflag != TypeDir) && (typeflag != TypeGNUSparse) {
|
||||
return 0, 0, 0, 0, errBadHeader
|
||||
}
|
||||
|
||||
mode := Mode644
|
||||
if b[0x068] == '7' {
|
||||
mode = Mode755
|
||||
}
|
||||
size := int64(u64le(b[0x080:]))
|
||||
if size < 0 {
|
||||
return 0, 0, 0, 0, errBadHeader
|
||||
}
|
||||
modTime := int64(u64le(b[0x08C:]))
|
||||
if modTime < 0 {
|
||||
return 0, 0, 0, 0, errBadHeader
|
||||
}
|
||||
|
||||
if typeflag == TypeDir {
|
||||
if (size != 0) || (mode != Mode755) {
|
||||
return 0, 0, 0, 0, errBadHeader
|
||||
}
|
||||
} else if typeflag == TypeGNUSparse {
|
||||
if size != 0 {
|
||||
return 0, 0, 0, 0, errBadHeader
|
||||
}
|
||||
size0 := int64(u64le(b[0x186:]))
|
||||
size1 := int64(u64le(b[0x1E7:]))
|
||||
if (size0 != size1) || (size1 < 0) {
|
||||
return 0, 0, 0, 0, errBadHeader
|
||||
}
|
||||
size = size1
|
||||
}
|
||||
|
||||
return typeflag, size, mode, modTime, nil
|
||||
}
|
||||
|
||||
// Read satisfies io.Reader.
|
||||
func (r *Reader) Read(b []byte) (int, error) {
|
||||
if r.err != nil {
|
||||
return 0, r.err
|
||||
} else if r.remaining == 0 {
|
||||
return 0, io.EOF
|
||||
} else if len(b) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
b = b[:int(min(r.remaining, int64(len(b))))]
|
||||
if r.sparse {
|
||||
n := len(b)
|
||||
clear(b)
|
||||
r.remaining -= int64(n)
|
||||
if r.remaining == 0 {
|
||||
return n, io.EOF
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
n, err := r.r.Read(b)
|
||||
r.remaining -= int64(n)
|
||||
if r.remaining == 0 {
|
||||
if r.numPadding > 0 {
|
||||
padding := r.block[:r.numPadding]
|
||||
_, readFullErr := readFullNoEOF(r.r, padding)
|
||||
if err == nil {
|
||||
err = readFullErr
|
||||
if err == nil {
|
||||
for _, c := range padding {
|
||||
if c != 0 {
|
||||
err = errBadPadding
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
r.numPadding = 0
|
||||
}
|
||||
if (err == nil) || (err == io.EOF) {
|
||||
return n, io.EOF
|
||||
}
|
||||
|
||||
} else if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
r.err = err
|
||||
return n, r.err
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
// Copyright 2026 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
|
||||
|
||||
package suitar
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type crcWriter uint32
|
||||
|
||||
func (c *crcWriter) Write(b []byte) (int, error) {
|
||||
state := uint32(*c)
|
||||
state = crc32.Update(state, crc32.IEEETable, b)
|
||||
*c = crcWriter(state)
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func testWriter(tt *testing.T, sparse bool) {
|
||||
f, err := os.Open("../../test/data/archive.tar")
|
||||
if err != nil {
|
||||
tt.Fatalf("os.Open: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Convert from t (tar, using the standard library) to s (suitar, using
|
||||
// this package).
|
||||
buf := bytes.Buffer{}
|
||||
sWriter := NewWriter(&buf)
|
||||
for tReader := tar.NewReader(f); ; {
|
||||
tHeader, err := tReader.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
tt.Fatalf("Next: %v", err)
|
||||
}
|
||||
|
||||
sHeader := &Header{
|
||||
Typeflag: tHeader.Typeflag,
|
||||
Name: tHeader.Name,
|
||||
Size: tHeader.Size,
|
||||
Mode: tHeader.Mode,
|
||||
ModTime: tHeader.ModTime,
|
||||
}
|
||||
if sparse && (sHeader.Typeflag == TypeReg) {
|
||||
sHeader.Typeflag = TypeGNUSparse
|
||||
}
|
||||
if err := sWriter.WriteHeader(sHeader); err != nil {
|
||||
tt.Fatalf("WriteHeader: %v", err)
|
||||
}
|
||||
|
||||
dstWriter := (io.Writer)(sWriter)
|
||||
if sparse {
|
||||
dstWriter = io.Discard
|
||||
}
|
||||
if _, err := io.Copy(dstWriter, tReader); err != nil {
|
||||
tt.Fatalf("io.Copy: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := sWriter.Close(); err != nil {
|
||||
tt.Fatalf("Close: %v", err)
|
||||
}
|
||||
|
||||
got := buf.Bytes()
|
||||
wantFilename := "../../test/data/archive"
|
||||
if sparse {
|
||||
wantFilename += ".sparse.suitar"
|
||||
} else {
|
||||
wantFilename += ".dense.suitar"
|
||||
}
|
||||
want, err := os.ReadFile(wantFilename)
|
||||
if err != nil {
|
||||
tt.Fatalf("os.ReadFile: %v", err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(got, want) {
|
||||
tt.Fatalf("did not recreate golden test file")
|
||||
}
|
||||
}
|
||||
|
||||
func testReader(tt *testing.T, sparse bool, ignore bool) {
|
||||
filename, wantTypeflag := "../../test/data/archive.dense.suitar", " T:'0'"
|
||||
if sparse {
|
||||
filename, wantTypeflag = "../../test/data/archive.sparse.suitar", " T:'S'"
|
||||
}
|
||||
|
||||
wantChecksums := []string(nil)
|
||||
if ignore {
|
||||
wantChecksums = []string{
|
||||
"C:0x00000000",
|
||||
"C:0x00000000",
|
||||
"C:0x00000000",
|
||||
"C:0x00000000",
|
||||
"C:0x00000000",
|
||||
"C:0x00000000",
|
||||
"C:0x00000000",
|
||||
"C:0x00000000",
|
||||
}
|
||||
|
||||
} else if sparse {
|
||||
wantChecksums = []string{
|
||||
"C:0x00000000",
|
||||
"C:0xB69F8E37",
|
||||
"C:0x73FF3CAE",
|
||||
"C:0xD71F022F",
|
||||
"C:0xC446EAB8",
|
||||
"C:0x5F228EB9",
|
||||
"C:0x7BA7D011",
|
||||
"C:0x48792A7F",
|
||||
}
|
||||
|
||||
} else {
|
||||
wantChecksums = []string{
|
||||
"C:0x00000000",
|
||||
"C:0xFEDD8F35",
|
||||
"C:0x87EE5E05",
|
||||
"C:0x703E9270",
|
||||
"C:0xC37CB538",
|
||||
"C:0x2B0B23B0",
|
||||
"C:0xABE507EF",
|
||||
"C:0x67FABE9C",
|
||||
}
|
||||
}
|
||||
|
||||
want := "" +
|
||||
wantChecksums[0] + wantTypeflag + " S:0x0000 M:644 MT:0x5E3A5C50 N:artificial/0.bytes\n" +
|
||||
wantChecksums[1] + wantTypeflag + " S:0x0355 M:644 MT:0x5F33F6E6 N:github-tags.json\n" +
|
||||
wantChecksums[2] + wantTypeflag + " S:0x02B5 M:755 MT:0x608F960B N:hello.sh\n" +
|
||||
wantChecksums[3] + wantTypeflag + " S:0x0068 M:644 MT:0x608F954D N:non-ascii/αβ.txt\n" +
|
||||
wantChecksums[4] + wantTypeflag + " S:0x0097 M:644 MT:0x608F96C7 N:non-ascii/😻.txt\n" +
|
||||
wantChecksums[5] + wantTypeflag + " S:0x00D0 M:644 MT:0x5E3A5C50 N:pjw-thumbnail.png\n" +
|
||||
wantChecksums[6] + wantTypeflag + " S:0x03AE M:644 MT:0x5E3A5C50 N:romeo.txt\n" +
|
||||
wantChecksums[7] + wantTypeflag + " S:0x022E M:644 MT:0x5E3A5C50 N:romeo.txt.gz\n" +
|
||||
""
|
||||
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
tt.Fatalf("os.Open: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
for r := NewReader(f); ; {
|
||||
h, err := r.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
tt.Fatalf("Next: %v", err)
|
||||
}
|
||||
|
||||
checksum := crcWriter(0)
|
||||
if !ignore {
|
||||
if _, err := io.Copy(&checksum, r); err != nil {
|
||||
tt.Fatalf("io.Copy: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(&buf, "C:0x%08X T:'%c' S:0x%04X M:%3o MT:0x%08X N:%s\n",
|
||||
checksum, h.Typeflag, h.Size, h.Mode, h.ModTime.Unix(), h.Name)
|
||||
}
|
||||
|
||||
if got := buf.String(); got != want {
|
||||
tt.Fatalf("\ngot:\n%s\nwant:\n%s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriterDense(tt *testing.T) { testWriter(tt, false) }
|
||||
func TestWriterSparse(tt *testing.T) { testWriter(tt, true) }
|
||||
func TestReaderDenseCheck(tt *testing.T) { testReader(tt, false, false) }
|
||||
func TestReaderDenseIgnore(tt *testing.T) { testReader(tt, false, true) }
|
||||
func TestReaderSparseCheck(tt *testing.T) { testReader(tt, true, false) }
|
||||
func TestReaderSparseIgnore(tt *testing.T) { testReader(tt, true, true) }
|
||||
+460
-89
@@ -35,11 +35,11 @@
|
||||
// may be better (faster) overall to skip any compression and decompression on
|
||||
// either side of the communication channel.
|
||||
//
|
||||
// The Encoder.Encode method also makes no further memory allocations (above
|
||||
// whatever its given io.Writer makes, if any). It is a lower-level API. See
|
||||
// the encodeImage function in this package's test code for a higher-level API
|
||||
// (with more dependencies and without the no-allocation guarantee) that takes
|
||||
// an image.Image argument.
|
||||
// The Encoder and AnimationEncoder methods also make no further memory
|
||||
// allocations (above whatever its given io.Writer makes, if any). They are
|
||||
// lower-level APIs. See the encodeImage function in this package's test code
|
||||
// for a higher-level API (with more dependencies and without the no-allocation
|
||||
// guarantee) that takes an image.Image argument.
|
||||
package uncompng
|
||||
|
||||
import (
|
||||
@@ -101,7 +101,7 @@ const (
|
||||
)
|
||||
|
||||
// Encoder is an opaque type that can convert a slice of pixel data to
|
||||
// PNG-formatted bytes.
|
||||
// PNG-formatted bytes. For APNG (Animated PNG), see AnimationEncoder.
|
||||
//
|
||||
// It contains all of the buffers needed for the Encode method. Once the
|
||||
// Encoder itself is allocated, Encoder.Encode makes no further allocations
|
||||
@@ -155,19 +155,58 @@ type Encoder struct {
|
||||
//
|
||||
// After that long preamble, here's the data layout of the buf field. Each
|
||||
// time a slice of buf is passed to an io.Writer, it contains exactly one
|
||||
// IDAT chunk. The final time will also contain an IEND chunk after the
|
||||
// IDAT chunk, unless it won't fit, in which case there will be one more
|
||||
// Write call with just the 12-byte IEND chunk (and no IDAT chunk).
|
||||
// IDAT chunk (or fdAT chunk, for animated PNG). The final time will also
|
||||
// contain an IEND chunk after the IDAT/fdAT chunk, unless it won't fit, in
|
||||
// which case there will be one more Write call with just the 12-byte IEND
|
||||
// chunk (and no IDAT/fdAT chunk).
|
||||
//
|
||||
// For all but the first Write, the 4-byte IDAT chunk length starts at
|
||||
// buf[0x0000:]. For the first Write, it will start at buf[0x0021:], since
|
||||
// it is preceded by the magic signature and the IHDR chunk.
|
||||
// When Encode'ing still PNGs, for all but the first Write, the 4-byte
|
||||
// IDAT/fdAT chunk length starts at buf[0x0000:]. For the first Write, it
|
||||
// will start at buf[0x0021:], since it is preceded by the magic signature
|
||||
// and the IHDR chunk.
|
||||
//
|
||||
// Either way, each IDAT chunk contains exactly one DEFLATE block (an
|
||||
// Either way, each IDAT/fdAT chunk contains exactly one DEFLATE block (an
|
||||
// uncompressed block). The very first IDAT (in the very first Write) also
|
||||
// contains the 2-byte ZLIB header. The very last IDAT also contains the
|
||||
// 4-byte Adler-32 checksum.
|
||||
//
|
||||
// For example, here's how buf might be filled (four times) and shipped out
|
||||
// to an io.Writer, when calling Encode to produce a still image.
|
||||
//
|
||||
// +--------------------------------------+
|
||||
// | MAGIC | IHDR | IDAT | Encode
|
||||
// +--------------------------------------+ :
|
||||
// | IDAT | :
|
||||
// +--------------------------------------+ :
|
||||
// | IDAT | :
|
||||
// +--------------------------------------+ :
|
||||
// | IDAT | IEND | unused | :
|
||||
// +--------------------------------------+
|
||||
//
|
||||
// The buf-packing is more complicated for an animated PNG. Reference (§).
|
||||
//
|
||||
// +--------------------------------------+
|
||||
// | MAGIC | IHDR | acTL | unused | EncodeHeader
|
||||
// +--------------------------------------+
|
||||
// | fcTL | IDAT | EncodeFrame
|
||||
// +--------------------------------------+ :
|
||||
// | IDAT | :
|
||||
// +--------------------------------------+ :
|
||||
// | IDAT | unused | :
|
||||
// +--------------------------------------+
|
||||
// | fcTL | fdAT | EncodeFrame
|
||||
// +--------------------------------------+ :
|
||||
// | fdAT | :
|
||||
// +--------------------------------------+ :
|
||||
// | fdAT | unused | :
|
||||
// +--------------------------------------+
|
||||
// | fcTL | fdAT | EncodeFrame
|
||||
// +--------------------------------------+ :
|
||||
// | fdAT | :
|
||||
// +--------------------------------------+ :
|
||||
// | fdAT | IEND | unused | :
|
||||
// +--------------------------------------+
|
||||
//
|
||||
// Each DEFLATE uncompressed block's payload spans e.buf[ei:ej], for two
|
||||
// indexes ei and ej, either explicit local variables or implicit state.
|
||||
// Writing pixel data to the Encoder increments ej, flushing to the
|
||||
@@ -182,12 +221,47 @@ type Encoder struct {
|
||||
// checksum state, as these 4 bytes won't be overwritten unless emitting
|
||||
// the final IDAT chunk (containing the final DEFLATE block).
|
||||
buf [65536]byte
|
||||
|
||||
// For still PNG images, there's 1 Encode call, which leads to:
|
||||
//
|
||||
// - 1 encodeImageHeader call. This sets buf to hold the magic signature,
|
||||
// IHDR chunk and the start of the first IDAT chunk, but does not write
|
||||
// to the io.Writer yet.
|
||||
// - 1 encodeFramePayload call, with frameTypeStill. This fills in the
|
||||
// rest of the first IDAT, and all of any remaining IDATs, and the final
|
||||
// IEND, writing to the io.Writer one or more times (on every flush
|
||||
// call, and possibly once more for the IEND chunk). Each flush is
|
||||
// passed frameTypeStill.
|
||||
//
|
||||
// For animated PNG images, there's 1 EncodeHeader call, which leads to...
|
||||
//
|
||||
// - 1 encodeImageHeader call. This sets buf to hold the magic signature,
|
||||
// IHDR chunk and acTL chunk, but not any part of any IDAT chunks. It
|
||||
// does, however, write to the io.Writer.
|
||||
//
|
||||
// ...and then N EncodeFrame calls, N = numFrames, each of which leads to:
|
||||
//
|
||||
// - 1 encodeFrameHeader call. This sets buf to hold the fcTL chunk and
|
||||
// the start of an IDAT/fdAT chunk, but does not write to the io.Writer.
|
||||
// - 1 encodeFramePayload call. This fills in the rest of the first
|
||||
// IDAT/fdAT, and all of any remaining IDATs/fdATs for that frame (and
|
||||
// the IEND if the last frame), writing to the io.Writer via flush,
|
||||
// similar to the still image case.
|
||||
//
|
||||
// For animated PNG images, the frameType argument, for encodeFramePayload
|
||||
// and flush, will have the frameTypeBitAnimated bit on. Of the N frames,
|
||||
// the frameTypeBitFirstFrame and frameTypeBitLastFrame bits are on for the
|
||||
// first and last frames. If N == 1, both bits are set for the only frame.
|
||||
}
|
||||
|
||||
type frameType byte
|
||||
|
||||
const (
|
||||
eiFirst = 0x0030
|
||||
eiLater = 0x000D
|
||||
ejMax = 0xFFF8
|
||||
frameTypeBitFirstFrame = frameType(1)
|
||||
frameTypeBitLastFrame = frameType(2)
|
||||
frameTypeBitAnimated = frameType(4)
|
||||
|
||||
frameTypeStill = frameTypeBitFirstFrame | frameTypeBitLastFrame
|
||||
)
|
||||
|
||||
// Encode writes the pixel data to w. It makes no allocations above whatever
|
||||
@@ -196,24 +270,50 @@ const (
|
||||
// pix holds the pixel data, either 1 or 4 bytes per pixel (doubled for
|
||||
// Depth16) depending on the colorType. width and height are measured in
|
||||
// pixels. stride is measured in bytes. depth must be either Depth8 or Depth16.
|
||||
func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride int, depth Depth, colorType ColorType) error {
|
||||
if (width < 0) || (height < 0) ||
|
||||
((depth != Depth8) && (depth != Depth16)) ||
|
||||
(colorType.pngFileFormatEncoding() == 0xFF) {
|
||||
return errors.New("uncompng: invalid argument")
|
||||
} else if (width > 0xFFFFFF) || (height > 0xFFFFFF) {
|
||||
return errors.New("uncompng: unsupported image size")
|
||||
func (e *Encoder) Encode(
|
||||
w io.Writer,
|
||||
depth Depth,
|
||||
colorType ColorType,
|
||||
width int,
|
||||
height int,
|
||||
pix []byte,
|
||||
stride int) error {
|
||||
|
||||
if err := checkArguments(depth, colorType, width, height, 1, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
e.init(width, height, depth, colorType)
|
||||
ej := eiFirst
|
||||
ej := e.encodeImageHeader(depth, colorType, width, height, 0, 0)
|
||||
return e.encodeFramePayload(
|
||||
w, frameTypeStill, nil, depth, colorType, width, height, pix, stride, ej)
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeFramePayload(
|
||||
w io.Writer,
|
||||
fType frameType,
|
||||
seqNumPtr *uint32,
|
||||
depth Depth,
|
||||
colorType ColorType,
|
||||
width int,
|
||||
height int,
|
||||
pix []byte,
|
||||
stride int,
|
||||
ej int) (err error) {
|
||||
|
||||
// AdlerB=0, Adler32A=1.
|
||||
e.buf[0xFFFC] = 0
|
||||
e.buf[0xFFFD] = 0
|
||||
e.buf[0xFFFE] = 0
|
||||
e.buf[0xFFFF] = 1
|
||||
|
||||
const ejMax = 0xFFF8
|
||||
|
||||
for y := 0; y < height; y++ {
|
||||
if (ej + 1) > ejMax {
|
||||
if err := e.flush(w, ej, false); err != nil {
|
||||
ej, err = e.flush(w, fType, seqNumPtr, ej, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ej = eiLater
|
||||
}
|
||||
e.buf[ej+0] = 0 // PNG 'none' filter.
|
||||
ej += 1
|
||||
@@ -225,10 +325,10 @@ func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride
|
||||
row = row[:1*width]
|
||||
for x := 0; x < width; x++ {
|
||||
if (ej + 1) > ejMax {
|
||||
if err := e.flush(w, ej, false); err != nil {
|
||||
ej, err = e.flush(w, fType, seqNumPtr, ej, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ej = eiLater
|
||||
}
|
||||
e.buf[ej+0] = row[0]
|
||||
ej += 1
|
||||
@@ -239,10 +339,10 @@ func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride
|
||||
row = row[:4*width]
|
||||
for x := 0; x < width; x++ {
|
||||
if (ej + 3) > ejMax {
|
||||
if err := e.flush(w, ej, false); err != nil {
|
||||
ej, err = e.flush(w, fType, seqNumPtr, ej, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ej = eiLater
|
||||
}
|
||||
e.buf[ej+0] = row[0]
|
||||
e.buf[ej+1] = row[1]
|
||||
@@ -255,10 +355,10 @@ func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride
|
||||
row = row[:4*width]
|
||||
for x := 0; x < width; x++ {
|
||||
if (ej + 4) > ejMax {
|
||||
if err := e.flush(w, ej, false); err != nil {
|
||||
ej, err = e.flush(w, fType, seqNumPtr, ej, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ej = eiLater
|
||||
}
|
||||
e.buf[ej+0] = row[0]
|
||||
e.buf[ej+1] = row[1]
|
||||
@@ -272,10 +372,10 @@ func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride
|
||||
row = row[:2*width]
|
||||
for x := 0; x < width; x++ {
|
||||
if (ej + 2) > ejMax {
|
||||
if err := e.flush(w, ej, false); err != nil {
|
||||
ej, err = e.flush(w, fType, seqNumPtr, ej, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ej = eiLater
|
||||
}
|
||||
e.buf[ej+0] = row[0]
|
||||
e.buf[ej+1] = row[1]
|
||||
@@ -287,10 +387,10 @@ func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride
|
||||
row = row[:8*width]
|
||||
for x := 0; x < width; x++ {
|
||||
if (ej + 6) > ejMax {
|
||||
if err := e.flush(w, ej, false); err != nil {
|
||||
ej, err = e.flush(w, fType, seqNumPtr, ej, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ej = eiLater
|
||||
}
|
||||
e.buf[ej+0] = row[0]
|
||||
e.buf[ej+1] = row[1]
|
||||
@@ -306,10 +406,10 @@ func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride
|
||||
row = row[:8*width]
|
||||
for x := 0; x < width; x++ {
|
||||
if (ej + 8) > ejMax {
|
||||
if err := e.flush(w, ej, false); err != nil {
|
||||
ej, err = e.flush(w, fType, seqNumPtr, ej, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ej = eiLater
|
||||
}
|
||||
e.buf[ej+0] = row[0]
|
||||
e.buf[ej+1] = row[1]
|
||||
@@ -325,10 +425,18 @@ func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride
|
||||
}
|
||||
}
|
||||
|
||||
return e.flush(w, ej, true)
|
||||
_, err = e.flush(w, fType, seqNumPtr, ej, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *Encoder) init(width int, height int, depth Depth, colorType ColorType) {
|
||||
func (e *Encoder) encodeImageHeader(
|
||||
depth Depth,
|
||||
colorType ColorType,
|
||||
width int,
|
||||
height int,
|
||||
numFrames uint32,
|
||||
numPlays uint32) int {
|
||||
|
||||
// PNG magic signature.
|
||||
e.buf[0x0000] = 0x89
|
||||
e.buf[0x0001] = 'P'
|
||||
@@ -370,7 +478,36 @@ func (e *Encoder) init(width int, height int, depth Depth, colorType ColorType)
|
||||
e.buf[0x001F] = byte(ihdrCRC32 >> 8)
|
||||
e.buf[0x0020] = byte(ihdrCRC32 >> 0)
|
||||
|
||||
// IDAT chunk length placeholder.
|
||||
if numFrames > 0 {
|
||||
// acTL chunk length.
|
||||
e.buf[0x0021] = 0
|
||||
e.buf[0x0022] = 0
|
||||
e.buf[0x0023] = 0
|
||||
e.buf[0x0024] = 0x08
|
||||
// acTL chunk type.
|
||||
e.buf[0x0025] = 'a'
|
||||
e.buf[0x0026] = 'c'
|
||||
e.buf[0x0027] = 'T'
|
||||
e.buf[0x0028] = 'L'
|
||||
// acTL chunk payload.
|
||||
e.buf[0x0029] = byte(numFrames >> 24)
|
||||
e.buf[0x002A] = byte(numFrames >> 16)
|
||||
e.buf[0x002B] = byte(numFrames >> 8)
|
||||
e.buf[0x002C] = byte(numFrames >> 0)
|
||||
e.buf[0x002D] = byte(numPlays >> 24)
|
||||
e.buf[0x002E] = byte(numPlays >> 16)
|
||||
e.buf[0x002F] = byte(numPlays >> 8)
|
||||
e.buf[0x0030] = byte(numPlays >> 0)
|
||||
// acTL CRC-32/IEEE checksum.
|
||||
actlCRC32 := crc32IEEE(e.buf[0x0025:0x0031])
|
||||
e.buf[0x0031] = byte(actlCRC32 >> 24)
|
||||
e.buf[0x0032] = byte(actlCRC32 >> 16)
|
||||
e.buf[0x0033] = byte(actlCRC32 >> 8)
|
||||
e.buf[0x0034] = byte(actlCRC32 >> 0)
|
||||
return 0x0035
|
||||
}
|
||||
|
||||
// IDAT chunk length placeholder. idatChunkStart is 0x0021.
|
||||
e.buf[0x0021] = 0
|
||||
e.buf[0x0022] = 0
|
||||
e.buf[0x0023] = 0
|
||||
@@ -389,16 +526,13 @@ func (e *Encoder) init(width int, height int, depth Depth, colorType ColorType)
|
||||
e.buf[0x002D] = 0
|
||||
e.buf[0x002E] = 0
|
||||
e.buf[0x002F] = 0
|
||||
// eiFirst is therefore 0x0030.
|
||||
|
||||
// AdlerB=0, Adler32A=1.
|
||||
e.buf[0xFFFC] = 0
|
||||
e.buf[0xFFFD] = 0
|
||||
e.buf[0xFFFE] = 0
|
||||
e.buf[0xFFFF] = 1
|
||||
return 0x0030
|
||||
}
|
||||
|
||||
func (e *Encoder) updateAdler32(ei int, ej int) {
|
||||
func (e *Encoder) updateAdler32(
|
||||
ei int,
|
||||
ej int) {
|
||||
|
||||
b := (uint32(e.buf[0xFFFC]) << 8) | uint32(e.buf[0xFFFD])
|
||||
a := (uint32(e.buf[0xFFFE]) << 8) | uint32(e.buf[0xFFFF])
|
||||
for ei < ej {
|
||||
@@ -419,34 +553,52 @@ func (e *Encoder) updateAdler32(ei int, ej int) {
|
||||
e.buf[0xFFFF] = byte(a >> 0)
|
||||
}
|
||||
|
||||
func (e *Encoder) flush(w io.Writer, ej int, final bool) error {
|
||||
// Update the IDAT chunk length placeholder.
|
||||
crc32Start, ei := 0, 0
|
||||
if e.buf[0x0004] == 0x0D { // First IDAT chunk.
|
||||
idatChunkLen := ej - 0x0029
|
||||
if final {
|
||||
idatChunkLen += 4
|
||||
}
|
||||
e.buf[0x0021] = byte(idatChunkLen >> 24)
|
||||
e.buf[0x0022] = byte(idatChunkLen >> 16)
|
||||
e.buf[0x0023] = byte(idatChunkLen >> 8)
|
||||
e.buf[0x0024] = byte(idatChunkLen >> 0)
|
||||
crc32Start, ei = 0x0025, eiFirst
|
||||
} else { // Later IDAT chunk.
|
||||
idatChunkLen := ej - 0x0008
|
||||
if final {
|
||||
idatChunkLen += 4
|
||||
}
|
||||
e.buf[0x0000] = byte(idatChunkLen >> 24)
|
||||
e.buf[0x0001] = byte(idatChunkLen >> 16)
|
||||
e.buf[0x0002] = byte(idatChunkLen >> 8)
|
||||
e.buf[0x0003] = byte(idatChunkLen >> 0)
|
||||
crc32Start, ei = 0x0004, eiLater
|
||||
func (e *Encoder) flush(
|
||||
w io.Writer,
|
||||
fType frameType,
|
||||
seqNumPtr *uint32,
|
||||
ej int,
|
||||
finalIDATOfFrame bool) (retEj int, retErr error) {
|
||||
|
||||
// Calculate where the IDAT/fdAT chunk starts, in e.buf. See (§).
|
||||
idatChunkStart := 0
|
||||
if e.buf[0x0007] == 0x0A {
|
||||
// 0x0A is magicSignature[7]. First IDAT chunk of a still image.
|
||||
idatChunkStart = 0x0021
|
||||
} else if e.buf[0x0007] == 0x4C {
|
||||
// 0x4C is "????fcTL"[7]. First IDAT/fdAT chunk of an animated frame.
|
||||
idatChunkStart = 0x0026
|
||||
} else if e.buf[0x0007] == 0x54 {
|
||||
// 0x54 is "??????AT"[7]. Later IDAT/fdAT chunk.
|
||||
idatChunkStart = 0x0000
|
||||
} else {
|
||||
return 0, errors.New("uncompng: unreachable")
|
||||
}
|
||||
|
||||
// 13 is the 0x000D in "Write... 0x000D bytes total" below.
|
||||
ei := idatChunkStart + 13
|
||||
if e.buf[0x0007] != 0x54 {
|
||||
// 2 more bytes for the ZLIB header (CM, CINFO, FDICT, FLEVEL).
|
||||
ei += 2
|
||||
}
|
||||
if (fType & frameTypeBitFirstFrame) == 0 {
|
||||
// fdAT chunks are longer than IDAT chunks by 4 bytes.
|
||||
ei += 4
|
||||
}
|
||||
|
||||
// Update the IDAT/fdAT chunk length placeholder.
|
||||
idatChunkLen := ej - (idatChunkStart + 8)
|
||||
if finalIDATOfFrame {
|
||||
idatChunkLen += 4 // The Adler-32 checksum occupies 4 bytes.
|
||||
}
|
||||
e.buf[idatChunkStart+0] = byte(idatChunkLen >> 24)
|
||||
e.buf[idatChunkStart+1] = byte(idatChunkLen >> 16)
|
||||
e.buf[idatChunkStart+2] = byte(idatChunkLen >> 8)
|
||||
e.buf[idatChunkStart+3] = byte(idatChunkLen >> 0)
|
||||
|
||||
// Update the DEFLATE uncompressed block header placeholder.
|
||||
deflateBlockLen := ej - ei
|
||||
e.buf[ei-5] = btou8(final)
|
||||
e.buf[ei-5] = btou8(finalIDATOfFrame)
|
||||
e.buf[ei-4] = 0x00 ^ byte(deflateBlockLen>>0)
|
||||
e.buf[ei-3] = 0x00 ^ byte(deflateBlockLen>>8)
|
||||
e.buf[ei-2] = 0xFF ^ byte(deflateBlockLen>>0)
|
||||
@@ -454,7 +606,7 @@ func (e *Encoder) flush(w io.Writer, ej int, final bool) error {
|
||||
|
||||
// Update (and maybe write) the Adler-32 checksum.
|
||||
e.updateAdler32(ei, ej)
|
||||
if final {
|
||||
if finalIDATOfFrame {
|
||||
e.buf[ej+0] = e.buf[0xFFFC]
|
||||
e.buf[ej+1] = e.buf[0xFFFD]
|
||||
e.buf[ej+2] = e.buf[0xFFFE]
|
||||
@@ -463,28 +615,44 @@ func (e *Encoder) flush(w io.Writer, ej int, final bool) error {
|
||||
}
|
||||
|
||||
// Write the CRC-32/IEEE checksum.
|
||||
idatCRC32 := crc32IEEE(e.buf[crc32Start:ej])
|
||||
idatCRC32 := crc32IEEE(e.buf[idatChunkStart+4 : ej])
|
||||
e.buf[ej+0] = byte(idatCRC32 >> 24)
|
||||
e.buf[ej+1] = byte(idatCRC32 >> 16)
|
||||
e.buf[ej+2] = byte(idatCRC32 >> 8)
|
||||
e.buf[ej+3] = byte(idatCRC32 >> 0)
|
||||
ej += 4
|
||||
|
||||
if !final {
|
||||
if !finalIDATOfFrame {
|
||||
if _, err := w.Write(e.buf[:ej]); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
// Write (or reserve space for) 0x000D bytes total:
|
||||
// - 4 bytes for the IDAT chunk length placeholder.
|
||||
// - 4 bytes for the IDAT chunk type.
|
||||
// - 4 bytes for the IDAT/fdAT chunk length placeholder.
|
||||
// - 4 bytes for the IDAT/fdAT chunk type.
|
||||
// - 5 bytes for the DEFLATE uncompressed block header placeholder.
|
||||
//
|
||||
// eiLater is therefore 0x000D.
|
||||
e.buf[0x0004] = 'I'
|
||||
e.buf[0x0005] = 'D'
|
||||
t := fType & frameTypeBitFirstFrame
|
||||
e.buf[0x0004] = "fI"[t]
|
||||
e.buf[0x0005] = "dD"[t]
|
||||
e.buf[0x0006] = 'A'
|
||||
e.buf[0x0007] = 'T'
|
||||
return nil
|
||||
if (t != 0) || (seqNumPtr == nil) {
|
||||
return 0x000D + 0, nil
|
||||
}
|
||||
|
||||
seqNum := *seqNumPtr
|
||||
*seqNumPtr++
|
||||
e.buf[0x0008] = byte(seqNum >> 24)
|
||||
e.buf[0x0009] = byte(seqNum >> 16)
|
||||
e.buf[0x000A] = byte(seqNum >> 8)
|
||||
e.buf[0x000B] = byte(seqNum >> 0)
|
||||
return 0x000D + 4, nil
|
||||
}
|
||||
|
||||
if (fType & frameTypeBitLastFrame) == 0 {
|
||||
if _, err := w.Write(e.buf[:ej]); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
const iendChunk = "\x00\x00\x00\x00IEND\xAE\x42\x60\x82"
|
||||
@@ -495,27 +663,230 @@ func (e *Encoder) flush(w io.Writer, ej int, final bool) error {
|
||||
}
|
||||
|
||||
if _, err := w.Write(e.buf[:ej]); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if writeSeparateIENDChunk {
|
||||
copy(e.buf[:], iendChunk)
|
||||
if _, err := w.Write(e.buf[:len(iendChunk)]); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// AnimationEncoder is like Encoder but for APNG (Animated PNG), not still PNG.
|
||||
//
|
||||
// It contains all of the buffers needed for the EncodeXxx methods. Once the
|
||||
// AnimationEncoder itself is allocated, AnimationEncoder.EncodeXxx makes no
|
||||
// further allocations (above whatever its given io.Writer makes, if any).
|
||||
//
|
||||
// To create one APNG, call EncodeHeader once (with a given numFrames > 0
|
||||
// argument) and then EncodeFrame numFrames times.
|
||||
//
|
||||
// It can be re-used (but it is not thread-safe). One AnimationEncoder can make
|
||||
// multiple (1 EncodeHeader + N EncodeFrame) call sequences, potentially with
|
||||
// different N values, each producing a complete, stand-alone APNG image.
|
||||
type AnimationEncoder struct {
|
||||
enc Encoder
|
||||
|
||||
depth Depth
|
||||
colorType ColorType
|
||||
|
||||
width uint32
|
||||
height uint32
|
||||
seqNum uint32
|
||||
numFrames uint32
|
||||
curFrame uint32
|
||||
}
|
||||
|
||||
// EncodeHeader writes the APNG header to w. It makes no allocations above
|
||||
// whatever w.Write makes, if any.
|
||||
//
|
||||
// The arguments are similar to Encoder.Encode, as well as numFrames > 0 being
|
||||
// the number of animation frames and numPlays being the number of times each
|
||||
// animation frame is played (zero means to loop forever).
|
||||
func (e *AnimationEncoder) EncodeHeader(
|
||||
w io.Writer,
|
||||
depth Depth,
|
||||
colorType ColorType,
|
||||
width int,
|
||||
height int,
|
||||
numFrames uint32,
|
||||
numPlays uint32) error {
|
||||
|
||||
if err := checkArguments(depth, colorType, width, height, numFrames, numPlays); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
e.depth = depth
|
||||
e.colorType = colorType
|
||||
|
||||
e.width = uint32(width)
|
||||
e.height = uint32(height)
|
||||
e.seqNum = 0
|
||||
e.numFrames = numFrames
|
||||
e.curFrame = 0
|
||||
|
||||
ej := e.enc.encodeImageHeader(depth, colorType, width, height, numFrames, numPlays)
|
||||
_, err := w.Write(e.enc.buf[:ej])
|
||||
return err
|
||||
}
|
||||
|
||||
// EncodeFrame writes an animation frame to w. It makes no allocations above
|
||||
// whatever w.Write makes, if any.
|
||||
//
|
||||
// The arguments are similar to Encoder.Encode, as well as (delayNumerator /
|
||||
// delayDenominator) being how many seconds to display the frame. For example,
|
||||
// if delayDenominator == 1000, delayNumerator is measured in milliseconds.
|
||||
func (e *AnimationEncoder) EncodeFrame(
|
||||
w io.Writer,
|
||||
pix []byte,
|
||||
stride int,
|
||||
delayNumerator uint16,
|
||||
delayDenominator uint16) error {
|
||||
|
||||
if e.numFrames == 0 {
|
||||
return errors.New("uncompng: EncodeHeader was not called")
|
||||
} else if e.curFrame >= e.numFrames {
|
||||
return errors.New("uncompng: too many EncodeFrame calls")
|
||||
} else if e.seqNum >= 0x80000000 {
|
||||
return errors.New("uncompng: too many frames")
|
||||
}
|
||||
|
||||
fType := frameTypeBitAnimated
|
||||
if e.curFrame == 0 {
|
||||
fType |= frameTypeBitFirstFrame
|
||||
}
|
||||
e.curFrame++
|
||||
if e.curFrame == e.numFrames {
|
||||
fType |= frameTypeBitLastFrame
|
||||
}
|
||||
|
||||
ej := e.encodeFrameHeader(w, delayNumerator, delayDenominator)
|
||||
return e.enc.encodeFramePayload(
|
||||
w, fType, &e.seqNum, e.depth, e.colorType, int(e.width), int(e.height), pix, stride, ej)
|
||||
}
|
||||
|
||||
func (e *AnimationEncoder) encodeFrameHeader(
|
||||
w io.Writer,
|
||||
delayNumerator uint16,
|
||||
delayDenominator uint16) int {
|
||||
|
||||
// fcTL chunk length.
|
||||
e.enc.buf[0x0000] = 0
|
||||
e.enc.buf[0x0001] = 0
|
||||
e.enc.buf[0x0002] = 0
|
||||
e.enc.buf[0x0003] = 0x1A
|
||||
// fcTL chunk type.
|
||||
e.enc.buf[0x0004] = 'f'
|
||||
e.enc.buf[0x0005] = 'c'
|
||||
e.enc.buf[0x0006] = 'T'
|
||||
e.enc.buf[0x0007] = 'L'
|
||||
// fcTL payload.
|
||||
e.enc.buf[0x0008] = byte(e.seqNum >> 24)
|
||||
e.enc.buf[0x0009] = byte(e.seqNum >> 16)
|
||||
e.enc.buf[0x000A] = byte(e.seqNum >> 8)
|
||||
e.enc.buf[0x000B] = byte(e.seqNum >> 0)
|
||||
e.enc.buf[0x000C] = byte(e.width >> 24)
|
||||
e.enc.buf[0x000D] = byte(e.width >> 16)
|
||||
e.enc.buf[0x000E] = byte(e.width >> 8)
|
||||
e.enc.buf[0x000F] = byte(e.width >> 0)
|
||||
e.enc.buf[0x0010] = byte(e.height >> 24)
|
||||
e.enc.buf[0x0011] = byte(e.height >> 16)
|
||||
e.enc.buf[0x0012] = byte(e.height >> 8)
|
||||
e.enc.buf[0x0013] = byte(e.height >> 0)
|
||||
e.enc.buf[0x0014] = 0 // X offset.
|
||||
e.enc.buf[0x0015] = 0
|
||||
e.enc.buf[0x0016] = 0
|
||||
e.enc.buf[0x0017] = 0
|
||||
e.enc.buf[0x0018] = 0 // Y offset.
|
||||
e.enc.buf[0x0019] = 0
|
||||
e.enc.buf[0x001A] = 0
|
||||
e.enc.buf[0x001B] = 0
|
||||
e.enc.buf[0x001C] = byte(delayNumerator >> 8)
|
||||
e.enc.buf[0x001D] = byte(delayNumerator >> 0)
|
||||
e.enc.buf[0x001E] = byte(delayDenominator >> 8)
|
||||
e.enc.buf[0x001F] = byte(delayDenominator >> 0)
|
||||
e.enc.buf[0x0020] = 0 // APNG_DISPOSE_OP_NONE.
|
||||
e.enc.buf[0x0021] = 0 // APNG_BLEND_OP_SOURCE.
|
||||
// fcTL CRC-32/IEEE checksum.
|
||||
fctlCRC32 := crc32IEEE(e.enc.buf[0x0004:0x0022])
|
||||
e.enc.buf[0x0022] = byte(fctlCRC32 >> 24)
|
||||
e.enc.buf[0x0023] = byte(fctlCRC32 >> 16)
|
||||
e.enc.buf[0x0024] = byte(fctlCRC32 >> 8)
|
||||
e.enc.buf[0x0025] = byte(fctlCRC32 >> 0)
|
||||
|
||||
useIDAT := 0
|
||||
if e.seqNum == 0 {
|
||||
useIDAT = 1
|
||||
}
|
||||
e.seqNum++
|
||||
|
||||
// IDAT/fdAT chunk length placeholder. idatChunkStart is 0x0026.
|
||||
e.enc.buf[0x0026] = 0
|
||||
e.enc.buf[0x0027] = 0
|
||||
e.enc.buf[0x0028] = 0
|
||||
e.enc.buf[0x0029] = 0
|
||||
// IDAT/fdAT chunk type.
|
||||
e.enc.buf[0x002A] = "fI"[useIDAT]
|
||||
e.enc.buf[0x002B] = "dD"[useIDAT]
|
||||
e.enc.buf[0x002C] = 'A'
|
||||
e.enc.buf[0x002D] = 'T'
|
||||
ej := 0x002E
|
||||
|
||||
if useIDAT == 0 {
|
||||
e.enc.buf[0x002E] = byte(e.seqNum >> 24)
|
||||
e.enc.buf[0x002F] = byte(e.seqNum >> 16)
|
||||
e.enc.buf[0x0030] = byte(e.seqNum >> 8)
|
||||
e.enc.buf[0x0031] = byte(e.seqNum >> 0)
|
||||
e.seqNum++
|
||||
ej = 0x0032
|
||||
}
|
||||
|
||||
// ZLIB header: CM=8, CINFO=7, FDICT=0, FLEVEL=0. See RFC 1950.
|
||||
e.enc.buf[ej+0x00] = 0x78
|
||||
e.enc.buf[ej+0x01] = 0x01
|
||||
// DEFLATE uncompressed block header, with 4-byte placeholder for length.
|
||||
e.enc.buf[ej+0x02] = 0
|
||||
e.enc.buf[ej+0x03] = 0
|
||||
e.enc.buf[ej+0x04] = 0
|
||||
e.enc.buf[ej+0x05] = 0
|
||||
e.enc.buf[ej+0x06] = 0
|
||||
return ej + 0x07
|
||||
}
|
||||
|
||||
func checkArguments(
|
||||
depth Depth,
|
||||
colorType ColorType,
|
||||
width int,
|
||||
height int,
|
||||
numFrames uint32,
|
||||
numPlays uint32) error {
|
||||
|
||||
if ((depth != Depth8) && (depth != Depth16)) ||
|
||||
(colorType.pngFileFormatEncoding() == 0xFF) ||
|
||||
(width <= 0) || (height <= 0) || (numFrames <= 0) {
|
||||
return errors.New("uncompng: invalid argument")
|
||||
} else if (width > 0xFFFFFF) || (height > 0xFFFFFF) {
|
||||
return errors.New("uncompng: unsupported image size")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func btou8(a bool) uint8 {
|
||||
func btou8(
|
||||
a bool) uint8 {
|
||||
|
||||
if a {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func crc32IEEE(b []byte) uint32 {
|
||||
func crc32IEEE(
|
||||
b []byte) uint32 {
|
||||
|
||||
hash := uint32(0xFFFF_FFFF)
|
||||
for _, v := range b {
|
||||
hash = crc32IEEETable[uint8(hash)^v] ^ (hash >> 8)
|
||||
|
||||
+306
-10
@@ -12,6 +12,8 @@ package uncompng
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"hash/crc32"
|
||||
"image"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
@@ -26,39 +28,39 @@ func encodeImage(w io.Writer, src image.Image) error {
|
||||
|
||||
switch src := src.(type) {
|
||||
case *image.Gray:
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth8, ColorTypeGray)
|
||||
return e.Encode(w, Depth8, ColorTypeGray, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
|
||||
case *image.Gray16:
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth16, ColorTypeGray)
|
||||
return e.Encode(w, Depth16, ColorTypeGray, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
|
||||
case *image.RGBA:
|
||||
if src.Opaque() {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth8, ColorTypeRGBX)
|
||||
return e.Encode(w, Depth8, ColorTypeRGBX, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
}
|
||||
|
||||
case *image.RGBA64:
|
||||
if src.Opaque() {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth16, ColorTypeRGBX)
|
||||
return e.Encode(w, Depth16, ColorTypeRGBX, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
}
|
||||
|
||||
case *image.NRGBA:
|
||||
if src.Opaque() {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth8, ColorTypeRGBX)
|
||||
return e.Encode(w, Depth8, ColorTypeRGBX, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
} else {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth8, ColorTypeNRGBA)
|
||||
return e.Encode(w, Depth8, ColorTypeNRGBA, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
}
|
||||
|
||||
case *image.NRGBA64:
|
||||
if src.Opaque() {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth16, ColorTypeRGBX)
|
||||
return e.Encode(w, Depth16, ColorTypeRGBX, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
} else {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth16, ColorTypeNRGBA)
|
||||
return e.Encode(w, Depth16, ColorTypeNRGBA, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
}
|
||||
}
|
||||
|
||||
tmp := image.NewNRGBA(b)
|
||||
draw.Draw(tmp, b, src, b.Min, draw.Src)
|
||||
return e.Encode(w, tmp.Pix, b.Dx(), b.Dy(), tmp.Stride, Depth8, ColorTypeNRGBA)
|
||||
return e.Encode(w, Depth8, ColorTypeNRGBA, b.Dx(), b.Dy(), tmp.Pix, tmp.Stride)
|
||||
}
|
||||
|
||||
func getPix(m image.Image) []byte {
|
||||
@@ -144,7 +146,7 @@ func TestNoAllocation(tt *testing.T) {
|
||||
enc := Encoder{}
|
||||
pix := make([]byte, 4*3*5)
|
||||
got := testing.AllocsPerRun(100, func() {
|
||||
enc.Encode(io.Discard, pix, 3, 5, 4*3, Depth8, ColorTypeNRGBA)
|
||||
enc.Encode(io.Discard, Depth8, ColorTypeNRGBA, 3, 5, pix, 4*3)
|
||||
})
|
||||
if got != 0 {
|
||||
tt.Errorf("AllocsPerRun: got %v, want 0", got)
|
||||
@@ -184,3 +186,297 @@ func TestWriteSeparateIENDChunk(tt *testing.T) {
|
||||
tt.Fatalf("have not seen a separate IEND chunk")
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnimationEncoder recreates the "Example NIA File" animation from
|
||||
// doc/spec/nie-spec.md, but in APNG format, not NIA format:
|
||||
//
|
||||
// This animated image is 3 pixels wide and 2 pixels high. It consists of 20
|
||||
// frames, being 10 loops of 2 frames. The total animation time of a single
|
||||
// loop is 3 seconds, so the 10 loops will take 30 seconds. The first frame is
|
||||
// a crude approximation to the French flag (blue, white and red) and is shown
|
||||
// for 1 second. The next frame is a crude approximation to the Italian flag
|
||||
// (green, white and red) and is shown for (3 - 1) seconds (i.e., 2 seconds).
|
||||
//
|
||||
// This test just hard-codes the expected golden output (in APNG format).
|
||||
// Saving the output to a file instead, and then transforming its contents via
|
||||
// convert-to-nia, should recover the same bytes (in NIA format) as given in
|
||||
// doc/spec/nie-spec.md.
|
||||
func TestAnimationEncoderSmall(tt *testing.T) {
|
||||
want := "" +
|
||||
"\x89PNG\x0D\x0A\x1A\x0A" + // PNG magic signature.
|
||||
"" +
|
||||
"\x00\x00\x00\x0DIHDR" + // Chunk length and type.
|
||||
"\x00\x00\x00\x03" + // Width.
|
||||
"\x00\x00\x00\x02" + // Height.
|
||||
"\x08\x02\x00\x00\x00" + // Depth and other fields.
|
||||
"\x12\x16\xF1\x4D" + // Chunk checksum (CRC-32).
|
||||
"" +
|
||||
"\x00\x00\x00\x08acTL" + // Chunk length and type.
|
||||
"\x00\x00\x00\x02" + // 2 frames.
|
||||
"\x00\x00\x00\x0A" + // 10 plays.
|
||||
"\x13\x58\x7A\x6E" + // Chunk checksum (CRC-32).
|
||||
"" + //
|
||||
"\x00\x00\x00\x1AfcTL" + // Chunk length and type.
|
||||
"\x00\x00\x00\x00" + // Animation sequence number.
|
||||
"\x00\x00\x00\x03" + // Width.
|
||||
"\x00\x00\x00\x02" + // Height.
|
||||
"\x00\x00\x00\x00" + // XOffset.
|
||||
"\x00\x00\x00\x00" + // YOffset.
|
||||
"\x03\xE8\x03\xE8" + // Delay (numerator = 1000, denominator = 1000).
|
||||
"\x00\x00" + // DisposeOp, BlendOp.
|
||||
"\x24\x35\x20\x78" + // Chunk checksum (CRC-32).
|
||||
"" + //
|
||||
"\x00\x00\x00\x1FIDAT" + // Chunk length and type.
|
||||
"\x78\x01\x01\x14\x00\xEB\xFF" + // ZLIB, final block, 20 bytes.
|
||||
"\x00" + // PNG row filter.
|
||||
"\x00\x00\xFF" + // RGB pixel.
|
||||
"\xFF\xFF\xFF" + // RGB pixel.
|
||||
"\xFF\x00\x00" + // RGB pixel.
|
||||
"\x00" + // PNG row filter.
|
||||
"\x00\x00\xFF" + // RGB pixel.
|
||||
"\xFF\xFF\xFF" + // RGB pixel.
|
||||
"\xFF\x00\x00" + // RGB pixel.
|
||||
"\x63\xB0\x09\xF7" + // ZLIB checksum (Adler32).
|
||||
"\xDD\xD2\x78\x8A" + // Chunk checksum (CRC-32).
|
||||
"" + //
|
||||
"\x00\x00\x00\x1AfcTL" + // Chunk length and type.
|
||||
"\x00\x00\x00\x01" + // Animation sequence number.
|
||||
"\x00\x00\x00\x03" + // Width.
|
||||
"\x00\x00\x00\x02" + // Height.
|
||||
"\x00\x00\x00\x00" + // XOffset.
|
||||
"\x00\x00\x00\x00" + // YOffset.
|
||||
"\x07\xD0\x03\xE8" + // Delay (numerator = 2000, denominator = 1000).
|
||||
"\x00\x00" + // DisposeOp, BlendOp.
|
||||
"\xB5\x86\x7B\xFD" + // Chunk checksum (CRC-32).
|
||||
"" + //
|
||||
"\x00\x00\x00\x23fdAT" + // Chunk length and type.
|
||||
"\x00\x00\x00\x02" + // Animation sequence number.
|
||||
"\x78\x01\x01\x14\x00\xEB\xFF" + // ZLIB, final block, 20 bytes.
|
||||
"\x00" + // PNG row filter.
|
||||
"\x00\xFF\x00" + // RGB pixel.
|
||||
"\xFF\xFF\xFF" + // RGB pixel.
|
||||
"\xFF\x00\x00" + // RGB pixel.
|
||||
"\x00" + // PNG row filter.
|
||||
"\x00\xFF\x00" + // RGB pixel.
|
||||
"\xFF\xFF\xFF" + // RGB pixel.
|
||||
"\xFF\x00\x00" + // RGB pixel.
|
||||
"\x65\xAE\x09\xF7" + // ZLIB checksum (Adler32).
|
||||
"\xFA\x44\x2A\xBE" + // Chunk checksum (CRC-32).
|
||||
"" + //
|
||||
"\x00\x00\x00\x00IEND" + // Chunk length and type.
|
||||
"\xAE\x42\x60\x82" + // Chunk checksum (CRC-32).
|
||||
""
|
||||
|
||||
const bytesPerPixel = 4
|
||||
const width = 3
|
||||
const height = 2
|
||||
const numFrames = 2
|
||||
const numPlays = 10
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
e := AnimationEncoder{}
|
||||
|
||||
pixs := [numFrames][bytesPerPixel * width * height]byte{{
|
||||
0x00, 0x00, 0xFF, 0xFF, // Blue.
|
||||
0xFF, 0xFF, 0xFF, 0xFF, // White.
|
||||
0xFF, 0x00, 0x00, 0xFF, // Red.
|
||||
|
||||
0x00, 0x00, 0xFF, 0xFF, // Blue.
|
||||
0xFF, 0xFF, 0xFF, 0xFF, // White.
|
||||
0xFF, 0x00, 0x00, 0xFF, // Red.
|
||||
|
||||
}, {
|
||||
0x00, 0xFF, 0x00, 0xFF, // Green.
|
||||
0xFF, 0xFF, 0xFF, 0xFF, // White.
|
||||
0xFF, 0x00, 0x00, 0xFF, // Red.
|
||||
|
||||
0x00, 0xFF, 0x00, 0xFF, // Green.
|
||||
0xFF, 0xFF, 0xFF, 0xFF, // White.
|
||||
0xFF, 0x00, 0x00, 0xFF, // Red.
|
||||
}}
|
||||
|
||||
delayMillis := [numFrames]uint16{1000, 2000}
|
||||
|
||||
if err := e.EncodeHeader(&buf, Depth8, ColorTypeRGBX, width, height, numFrames, numPlays); err != nil {
|
||||
tt.Fatalf("EncodeHeader: %v", err)
|
||||
}
|
||||
|
||||
for f := range pixs {
|
||||
if err := e.EncodeFrame(&buf, pixs[f][:], bytesPerPixel*width, delayMillis[f], 1000); err != nil {
|
||||
tt.Fatalf("EncodeFrame(%d): %v", f, err)
|
||||
}
|
||||
}
|
||||
|
||||
asBytes := buf.Bytes()
|
||||
checkAPNGConsistency(tt, asBytes)
|
||||
|
||||
if got := string(asBytes); got != want {
|
||||
for i := range min(len(got), len(want)) {
|
||||
if got[i] != want[i] {
|
||||
tt.Fatalf("compare-to-golden: at byte %d\ngot % 02X\nwant % 02X", i, got, want)
|
||||
}
|
||||
}
|
||||
tt.Fatalf("compare-to-golden:\ngot % 02X\nwant % 02X", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnimationEncoderLarge(tt *testing.T) {
|
||||
srcFile, err := os.Open("../../test/data/hibiscus.regular.png")
|
||||
if err != nil {
|
||||
tt.Fatalf("os.Open: %v", err)
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
srcImage, err := png.Decode(srcFile)
|
||||
if err != nil {
|
||||
tt.Fatalf("png.Decode: %v", err)
|
||||
}
|
||||
srcRGBA := srcImage.(*image.RGBA)
|
||||
if got, want := srcRGBA.Bounds(), image.Rect(0, 0, 312, 442); got != want {
|
||||
tt.Fatalf("Bounds: got %v, want %v", got, want)
|
||||
}
|
||||
srcPix := srcRGBA.Pix
|
||||
|
||||
// Make a copy of srcPix. PNG alpha is non-premul and Go's RGBA alpha is
|
||||
// premul. The fact that Go's png.Decode returned RGBA (instead of NRGBA)
|
||||
// means that all of the alpha values should be 0xFF, so that converting
|
||||
// srcPix (as RGBA) to srcPixAsNRGBA can just be a memcpy.
|
||||
srcPixAsNRGBA := append([]byte(nil), srcPix...)
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
e := AnimationEncoder{}
|
||||
|
||||
const bytesPerPixel = 4
|
||||
const width = 312
|
||||
const height = 442
|
||||
const numFrames = 5
|
||||
const numPlays = 0
|
||||
delayMillis := [numFrames]uint16{300, 500, 600, 400, 200}
|
||||
|
||||
if err := e.EncodeHeader(&buf, Depth8, ColorTypeNRGBA, width, height, numFrames, numPlays); err != nil {
|
||||
tt.Fatalf("EncodeHeader: %v", err)
|
||||
}
|
||||
|
||||
for f, delay := range delayMillis {
|
||||
if err := e.EncodeFrame(&buf, srcPix, bytesPerPixel*width, delay, 1000); err != nil {
|
||||
tt.Fatalf("EncodeFrame(%d): %v", f, err)
|
||||
}
|
||||
|
||||
// Over time, set the R, G, B, A channel values to 0x80.
|
||||
if f < 4 {
|
||||
for i := f; i < len(srcPix); i += 4 {
|
||||
srcPix[i] = 0x80
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
asBytes := buf.Bytes()
|
||||
checkAPNGConsistency(tt, asBytes)
|
||||
|
||||
if got, want := crc32.ChecksumIEEE(asBytes), uint32(0x73B25773); got != want {
|
||||
tt.Fatalf("did not get golden-output hash")
|
||||
}
|
||||
|
||||
// png.Decode from Go's standard library doesn't recover all of the
|
||||
// animation's frames, but it should recover the first frame.
|
||||
//
|
||||
// We also passed ColorTypeNRGBA (not ColorTypeRGBX) to EncodeHeader, so
|
||||
// the decoded image is *image.NRGBA, not *image.RGBA.
|
||||
dstImage, err := png.Decode(bytes.NewReader(asBytes))
|
||||
if err != nil {
|
||||
tt.Fatalf("png.Decode: %v", err)
|
||||
}
|
||||
dstNRGBA := dstImage.(*image.NRGBA)
|
||||
if !bytes.Equal(dstNRGBA.Pix, srcPixAsNRGBA) {
|
||||
tt.Fatal("first frame pixels: round-trip failed")
|
||||
}
|
||||
|
||||
// Change false to true, for manual inspection in a viewer that supports
|
||||
// APNG, such as a web browser.
|
||||
if false {
|
||||
os.WriteFile("/tmp/TestAnimationEncoderLarge.png", asBytes, 0644)
|
||||
}
|
||||
}
|
||||
|
||||
func checkAPNGConsistency(tt *testing.T, pngEncodedBytes []byte) {
|
||||
if !bytes.HasPrefix(pngEncodedBytes, []byte("\x89PNG\x0D\x0A\x1A\x0A")) {
|
||||
tt.Fatalf("bad PNG magic signature")
|
||||
}
|
||||
|
||||
forEachChunk := func(f func(chunk []byte)) {
|
||||
for b := pngEncodedBytes[8:]; len(b) > 0; {
|
||||
if len(b) < 12 {
|
||||
tt.Fatalf("bad chunk structure")
|
||||
}
|
||||
n := int64(u32be(b))
|
||||
if (n + 12) > int64(len(b)) {
|
||||
tt.Fatalf("bad chunk structure")
|
||||
}
|
||||
f(b[:n+12])
|
||||
b = b[n+12:]
|
||||
}
|
||||
}
|
||||
|
||||
forEachChunk(func(chunk []byte) {
|
||||
checksum0 := u32be(chunk[len(chunk)-4:])
|
||||
checksum1 := crc32.ChecksumIEEE(chunk[4 : len(chunk)-4])
|
||||
if checksum0 != checksum1 {
|
||||
tt.Fatalf("bad chunk checksum")
|
||||
}
|
||||
})
|
||||
|
||||
nextSeqNum := uint32(0)
|
||||
forEachChunk(func(chunk []byte) {
|
||||
switch u32be(chunk[4:]) {
|
||||
case 0x6663544C, 0x66644154: // "fcTL"be, "fdAT"be.
|
||||
got := u32be(chunk[8:])
|
||||
want := nextSeqNum
|
||||
nextSeqNum++
|
||||
if got != want {
|
||||
tt.Fatalf("bad animation sequence number")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
idatlikeData := [][]byte{}
|
||||
forEachChunk(func(chunk []byte) {
|
||||
dat := []byte(nil)
|
||||
|
||||
switch u32be(chunk[4:]) {
|
||||
case 0x6663544C: // "fcTL"be.
|
||||
idatlikeData = append(idatlikeData, nil)
|
||||
case 0x66644154: // "fdAT"be.
|
||||
dat = chunk[12 : len(chunk)-4]
|
||||
case 0x49444154: // "IDAT"be.
|
||||
dat = chunk[8 : len(chunk)-4]
|
||||
}
|
||||
|
||||
if dat != nil {
|
||||
last := len(idatlikeData) - 1
|
||||
idatlikeData[last] = append(idatlikeData[last], dat...)
|
||||
}
|
||||
})
|
||||
|
||||
decompressedLen := int64(0)
|
||||
for i, dat := range idatlikeData {
|
||||
r, err := zlib.NewReader(bytes.NewReader(dat))
|
||||
if err != nil {
|
||||
tt.Fatalf("IDAT/fdAT chunk data was not ZLIB-formatted")
|
||||
}
|
||||
defer r.Close()
|
||||
if n, err := io.Copy(io.Discard, r); err != nil {
|
||||
tt.Fatalf("IDAT/fdAT chunk data was not ZLIB-formatted")
|
||||
} else if i == 0 {
|
||||
decompressedLen = n
|
||||
} else if decompressedLen != n {
|
||||
tt.Fatalf("IDAT/fdAT chunk data has inconsistent lengths")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func u32be(b []byte) uint32 {
|
||||
return (uint32(b[0]) << 24) |
|
||||
(uint32(b[1]) << 16) |
|
||||
(uint32(b[2]) << 8) |
|
||||
(uint32(b[3]) << 0)
|
||||
}
|
||||
+2689
-1044
@@ -1752,7 +1752,7 @@ wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__make_slice_u8_ij(uint8_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u8 ret;
|
||||
ret.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.ptr = i ? (ptr + i) : ptr;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1760,7 +1760,7 @@ wuffs_base__make_slice_u8_ij(uint8_t* ptr, size_t i, size_t j) {
|
||||
static inline wuffs_base__slice_u16 //
|
||||
wuffs_base__make_slice_u16_ij(uint16_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u16 ret;
|
||||
ret.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.ptr = i ? (ptr + i) : ptr;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1768,7 +1768,7 @@ wuffs_base__make_slice_u16_ij(uint16_t* ptr, size_t i, size_t j) {
|
||||
static inline wuffs_base__slice_u32 //
|
||||
wuffs_base__make_slice_u32_ij(uint32_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u32 ret;
|
||||
ret.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.ptr = i ? (ptr + i) : ptr;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1776,7 +1776,7 @@ wuffs_base__make_slice_u32_ij(uint32_t* ptr, size_t i, size_t j) {
|
||||
static inline wuffs_base__slice_u64 //
|
||||
wuffs_base__make_slice_u64_ij(uint64_t* ptr, size_t i, size_t j) {
|
||||
wuffs_base__slice_u64 ret;
|
||||
ret.ptr = ptr ? (ptr + i) : NULL;
|
||||
ret.ptr = i ? (ptr + i) : ptr;
|
||||
ret.len = (j >= i) ? (j - i) : 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -1917,7 +1917,12 @@ wuffs_base__slice_u8__overlaps(wuffs_base__slice_u8 s, wuffs_base__slice_u8 t) {
|
||||
static inline wuffs_base__slice_u8 //
|
||||
wuffs_base__slice_u8__subslice_i(wuffs_base__slice_u8 s, uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return wuffs_base__make_slice_u8(s.ptr + i, ((size_t)(s.len - i)));
|
||||
// The "i ? (s.ptr + i) : s.ptr" expression is equivalent to the plain
|
||||
// "s.ptr + i", except for the fact that in C (prior to C29), but not in
|
||||
// C++, "NULL + 0" is, technically, undefined behavior (and triggers
|
||||
// ubsan). See C29 N3322 and https://reviews.llvm.org/D67122
|
||||
return wuffs_base__make_slice_u8(i ? (s.ptr + i) : s.ptr,
|
||||
((size_t)(s.len - i)));
|
||||
}
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
@@ -1941,7 +1946,12 @@ wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,
|
||||
uint64_t i,
|
||||
uint64_t j) {
|
||||
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return wuffs_base__make_slice_u8(s.ptr + i, ((size_t)(j - i)));
|
||||
// The "i ? (s.ptr + i) : s.ptr" expression is equivalent to the plain
|
||||
// "s.ptr + i", except for the fact that in C (prior to C29), but not in
|
||||
// C++, "NULL + 0" is, technically, undefined behavior (and triggers
|
||||
// ubsan). See C29 N3322 and https://reviews.llvm.org/D67122
|
||||
return wuffs_base__make_slice_u8(i ? (s.ptr + i) : s.ptr,
|
||||
((size_t)(j - i)));
|
||||
}
|
||||
return wuffs_base__empty_slice_u8();
|
||||
}
|
||||
@@ -4376,6 +4386,10 @@ wuffs_base__malloc_slice_u64(void* (*malloc_func)(size_t), uint64_t num_u64) {
|
||||
// 0xAARRGGBB (Alpha most significant, Blue least), regardless of endianness.
|
||||
typedef uint32_t wuffs_base__color_u32_argb_premul;
|
||||
|
||||
// wuffs_base__color_u32_argb_nonpremul is non-premultiplied version of
|
||||
// wuffs_base__color_u32_argb_premul.
|
||||
typedef uint32_t wuffs_base__color_u32_argb_nonpremul;
|
||||
|
||||
// wuffs_base__color_u32_argb_premul__is_valid returns whether c's Red, Green
|
||||
// and Blue channels are all less than or equal to its Alpha channel. c uses
|
||||
// premultiplied alpha, so 50% opaque 100% saturated red is 0x7F7F_0000 and a
|
||||
@@ -4595,6 +4609,21 @@ wuffs_base__color_u64_argb_premul__as__color_u64_argb_nonpremul(
|
||||
return (a << 48) | (r << 32) | (g << 16) | (b << 0);
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__color_u64_argb_nonpremul__as__color_u64_argb_premul(
|
||||
uint64_t argb_nonpremul) {
|
||||
uint64_t a = 0xFFFF & (argb_nonpremul >> 48);
|
||||
|
||||
uint64_t r = 0xFFFF & (argb_nonpremul >> 32);
|
||||
r = (r * a) / 0xFFFF;
|
||||
uint64_t g = 0xFFFF & (argb_nonpremul >> 16);
|
||||
g = (g * a) / 0xFFFF;
|
||||
uint64_t b = 0xFFFF & (argb_nonpremul >> 0);
|
||||
b = (b * a) / 0xFFFF;
|
||||
|
||||
return (a << 48) | (r << 32) | (g << 16) | (b << 0);
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__color_u64_argb_nonpremul__as__color_u8_gray(
|
||||
uint64_t argb_nonpremul) {
|
||||
@@ -4826,6 +4855,11 @@ typedef uint8_t wuffs_base__pixel_blend;
|
||||
#define WUFFS_BASE__PIXEL_BLEND__SRC ((wuffs_base__pixel_blend)0)
|
||||
#define WUFFS_BASE__PIXEL_BLEND__SRC_OVER ((wuffs_base__pixel_blend)1)
|
||||
|
||||
static inline wuffs_base__pixel_blend //
|
||||
wuffs_base__make_pixel_blend(uint8_t repr) {
|
||||
return repr;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// wuffs_base__pixel_alpha_transparency is a pixel format's alpha channel
|
||||
@@ -5207,13 +5241,21 @@ wuffs_base__pixel_subsampling::denominator_y(uint32_t plane) const {
|
||||
//
|
||||
// For CMY, C = (100% - R), M = (100% - G) and Y = (100% - B). Black (K), if
|
||||
// present, then modulates the three RGB values.
|
||||
//
|
||||
// ----
|
||||
//
|
||||
// The 0x02 bit means the fourth channel is an alpha channel and, if set, then
|
||||
// the 0x01 bit gives the blend mode (WUFFS_BASE__PIXEL_BLEND__SRC is 0,
|
||||
// WUFFS_BASE__PIXEL_BLEND__SRC_OVER is 1).
|
||||
|
||||
// clang-format off
|
||||
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_FULL_RANGE 0x00
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE 0x01
|
||||
#define WUFFS_BASE__YCC_MODEL__RGB 0x40
|
||||
#define WUFFS_BASE__YCC_MODEL__CMY 0x80
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_FULL_RANGE 0x00
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE 0x04
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC 0x06
|
||||
#define WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC_OVER 0x07
|
||||
#define WUFFS_BASE__YCC_MODEL__RGB 0x40
|
||||
#define WUFFS_BASE__YCC_MODEL__CMY 0x80
|
||||
|
||||
// clang-format on
|
||||
|
||||
@@ -5839,15 +5881,32 @@ typedef struct wuffs_base__pixel_buffer__struct {
|
||||
inline wuffs_base__slice_u8 palette_or_else(wuffs_base__slice_u8 fallback);
|
||||
inline wuffs_base__pixel_format pixel_format() const;
|
||||
inline wuffs_base__table_u8 plane(uint32_t p);
|
||||
// Deprecated: use color_u32_argb_premul_at.
|
||||
inline wuffs_base__color_u32_argb_premul color_u32_at(uint32_t x,
|
||||
uint32_t y) const;
|
||||
inline wuffs_base__color_u32_argb_premul color_u32_argb_premul_at(
|
||||
uint32_t x,
|
||||
uint32_t y) const;
|
||||
// Deprecated: use set_color_u32_argb_premul_at.
|
||||
inline wuffs_base__status set_color_u32_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
inline wuffs_base__status set_color_u32_argb_premul_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
// Deprecated: use set_color_u32_argb_premul_fill_rect.
|
||||
inline wuffs_base__status set_color_u32_fill_rect(
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
inline wuffs_base__status set_color_u32_argb_premul_fill_rect(
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
inline wuffs_base__status set_color_u32_argb_nonpremul_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color);
|
||||
inline bool is_opaque();
|
||||
#endif // __cplusplus
|
||||
|
||||
@@ -6042,24 +6101,44 @@ wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* pb, uint32_t p) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Deprecated: use the second name, not the first.
|
||||
#define wuffs_base__pixel_buffer__color_u32_at \
|
||||
wuffs_base__pixel_buffer__color_u32_argb_premul_at
|
||||
|
||||
// Deprecated: use the second name, not the first.
|
||||
#define wuffs_base__pixel_buffer__set_color_u32_at \
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at
|
||||
|
||||
// Deprecated: use the second name, not the first.
|
||||
#define wuffs_base__pixel_buffer__set_color_u32_fill_rect \
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__color_u32_argb_premul //
|
||||
wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y);
|
||||
wuffs_base__pixel_buffer__color_u32_argb_premul_at(
|
||||
const wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_nonpremul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC bool //
|
||||
wuffs_base__pixel_buffer__is_opaque(const wuffs_base__pixel_buffer* pb);
|
||||
|
||||
@@ -6104,7 +6183,13 @@ wuffs_base__pixel_buffer::plane(uint32_t p) {
|
||||
|
||||
inline wuffs_base__color_u32_argb_premul //
|
||||
wuffs_base__pixel_buffer::color_u32_at(uint32_t x, uint32_t y) const {
|
||||
return wuffs_base__pixel_buffer__color_u32_at(this, x, y);
|
||||
return wuffs_base__pixel_buffer__color_u32_argb_premul_at(this, x, y);
|
||||
}
|
||||
|
||||
inline wuffs_base__color_u32_argb_premul //
|
||||
wuffs_base__pixel_buffer::color_u32_argb_premul_at(uint32_t x,
|
||||
uint32_t y) const {
|
||||
return wuffs_base__pixel_buffer__color_u32_argb_premul_at(this, x, y);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
@@ -6112,14 +6197,42 @@ wuffs_base__pixel_buffer::set_color_u32_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_at(this, x, y, color);
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(this, x, y,
|
||||
color);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer::set_color_u32_argb_premul_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(this, x, y,
|
||||
color);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer::set_color_u32_fill_rect(
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_fill_rect(this, rect, color);
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
this, rect, color);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer::set_color_u32_argb_premul_fill_rect(
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
this, rect, color);
|
||||
}
|
||||
|
||||
inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer::set_color_u32_argb_nonpremul_at(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color) {
|
||||
return wuffs_base__pixel_buffer__set_color_u32_argb_nonpremul_at(this, x, y,
|
||||
color);
|
||||
}
|
||||
|
||||
inline bool //
|
||||
@@ -15457,7 +15570,9 @@ struct wuffs_thumbhash__decoder__struct {
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_vp8__error__bad_quirk_source_length[];
|
||||
extern const char wuffs_vp8__error__bad_quirk_width_and_height[];
|
||||
extern const char wuffs_vp8__error__bad_header[];
|
||||
extern const char wuffs_vp8__error__inconsistent_width_and_height[];
|
||||
extern const char wuffs_vp8__error__missing_quirk_source_length[];
|
||||
extern const char wuffs_vp8__error__truncated_input[];
|
||||
extern const char wuffs_vp8__error__unsupported_quirk_source_length[];
|
||||
@@ -15465,7 +15580,11 @@ extern const char wuffs_vp8__error__unsupported_vp8_file[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_VP8__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 553648127u
|
||||
#define WUFFS_VP8__QUIRK_HAS_ALPHA_SIDE_CHANNEL 1836840960u
|
||||
|
||||
#define WUFFS_VP8__QUIRK_WIDTH_AND_HEIGHT 1836840961u
|
||||
|
||||
#define WUFFS_VP8__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 822050816u
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
|
||||
@@ -15636,8 +15755,10 @@ struct wuffs_vp8__decoder__struct {
|
||||
uint32_t f_mbh;
|
||||
uint8_t f_call_sequence;
|
||||
bool f_is_key_frame;
|
||||
bool f_quirk_has_alpha_side_channel;
|
||||
uint64_t f_frame_config_io_position;
|
||||
uint64_t f_quirk_source_length;
|
||||
uint64_t f_quirk_width_and_height;
|
||||
uint32_t f_partitioned_data_length;
|
||||
uint32_t f_workbuf_yuv_y_stride;
|
||||
uint32_t f_workbuf_yuv_uv_stride;
|
||||
@@ -16214,18 +16335,20 @@ struct wuffs_wbmp__decoder__struct {
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_webp__error__bad_alph_vp8l_combination[];
|
||||
extern const char wuffs_webp__error__bad_huffman_code_over_subscribed[];
|
||||
extern const char wuffs_webp__error__bad_huffman_code_under_subscribed[];
|
||||
extern const char wuffs_webp__error__bad_huffman_code[];
|
||||
extern const char wuffs_webp__error__bad_vp8x_chunk[];
|
||||
extern const char wuffs_webp__error__bad_back_reference[];
|
||||
extern const char wuffs_webp__error__bad_chunk_order[];
|
||||
extern const char wuffs_webp__error__bad_color_cache[];
|
||||
extern const char wuffs_webp__error__bad_header[];
|
||||
extern const char wuffs_webp__error__bad_transform[];
|
||||
extern const char wuffs_webp__error__short_chunk[];
|
||||
extern const char wuffs_webp__error__truncated_input[];
|
||||
extern const char wuffs_webp__error__unsupported_number_of_huffman_groups[];
|
||||
extern const char wuffs_webp__error__unsupported_transform_after_color_indexing_transform[];
|
||||
extern const char wuffs_webp__error__unsupported_webp_file[];
|
||||
extern const char wuffs_webp__error__unsupported_number_of_huffman_groups[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
@@ -16394,16 +16517,19 @@ struct wuffs_webp__decoder__struct {
|
||||
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;
|
||||
uint8_t f_code_length_code_lengths[19];
|
||||
bool f_sub_chunk_has_padding;
|
||||
bool f_is_vp8_lossy;
|
||||
uint8_t f_variant;
|
||||
uint8_t f_vp8x_header_flags;
|
||||
uint8_t f_vp8x_alph_flags;
|
||||
uint64_t f_frame_config_io_position;
|
||||
uint32_t f_riff_chunk_length;
|
||||
uint32_t f_rcl_remaining;
|
||||
uint32_t f_sub_chunk_length;
|
||||
uint32_t f_sub_chunk_type;
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
bool f_seen_transform[4];
|
||||
@@ -16422,24 +16548,28 @@ struct wuffs_webp__decoder__struct {
|
||||
uint32_t f_workbuf_offset_for_color_indexing;
|
||||
wuffs_base__pixel_swizzler f_swizzler;
|
||||
|
||||
uint32_t p_decode_alph;
|
||||
uint32_t p_decode_alph_limited;
|
||||
uint32_t p_decode_huffman_groups;
|
||||
uint32_t p_decode_huffman_tree;
|
||||
uint32_t p_decode_huffman_tree_simple;
|
||||
uint32_t p_decode_code_length_code_lengths;
|
||||
uint32_t p_build_code_lengths;
|
||||
uint32_t p_decode_pixels_slow;
|
||||
uint32_t p_decode_image_config;
|
||||
uint32_t p_do_decode_image_config;
|
||||
uint32_t p_do_decode_image_config_limited;
|
||||
uint32_t p_do_decode_image_config_limited_vp8l;
|
||||
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_do_decode_frame_vp8l;
|
||||
uint32_t p_decode_transform;
|
||||
uint32_t p_decode_color_cache_parameters;
|
||||
uint32_t p_decode_hg_table;
|
||||
uint32_t p_decode_pixels;
|
||||
uint32_t p_decode_image_config;
|
||||
uint32_t p_do_decode_image_config;
|
||||
uint32_t p_do_decode_image_config_limited;
|
||||
uint32_t p_do_decode_image_config_limited_vp8l;
|
||||
uint32_t p_do_decode_image_config_limited_vp8x;
|
||||
uint32_t p_decode_frame_config;
|
||||
uint32_t p_do_decode_frame_config;
|
||||
uint32_t p_decode_frame;
|
||||
uint32_t p_do_decode_frame;
|
||||
} private_impl;
|
||||
|
||||
struct {
|
||||
@@ -16490,6 +16620,16 @@ struct wuffs_webp__decoder__struct {
|
||||
uint32_t v_back_ref_dist_premap_minus_1;
|
||||
uint64_t v_color_cache_p;
|
||||
} s_decode_pixels_slow;
|
||||
struct {
|
||||
uint32_t v_width;
|
||||
} s_do_decode_frame_vp8l;
|
||||
struct {
|
||||
uint32_t v_transform_type;
|
||||
uint32_t v_tile_size_log2;
|
||||
} s_decode_transform;
|
||||
struct {
|
||||
uint32_t v_tile_size_log2;
|
||||
} s_decode_hg_table;
|
||||
struct {
|
||||
uint64_t scratch;
|
||||
} s_do_decode_image_config;
|
||||
@@ -16500,15 +16640,11 @@ struct wuffs_webp__decoder__struct {
|
||||
uint64_t scratch;
|
||||
} s_do_decode_image_config_limited_vp8l;
|
||||
struct {
|
||||
uint32_t v_width;
|
||||
uint64_t scratch;
|
||||
} s_do_decode_image_config_limited_vp8x;
|
||||
struct {
|
||||
uint64_t scratch;
|
||||
} s_do_decode_frame;
|
||||
struct {
|
||||
uint32_t v_transform_type;
|
||||
uint32_t v_tile_size_log2;
|
||||
} s_decode_transform;
|
||||
struct {
|
||||
uint32_t v_tile_size_log2;
|
||||
} s_decode_hg_table;
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -17808,6 +17944,8 @@ class DecodeImageCallbacks {
|
||||
// should be at least len_range.min_incl, but larger allocations (up to
|
||||
// len_range.max_incl) may have better performance (by using more memory).
|
||||
//
|
||||
// The len_range argument will satisfy !len_range.is_empty().
|
||||
//
|
||||
// The default AllocWorkbuf implementation allocates len_range.max_incl bytes
|
||||
// of either uninitialized or zeroed memory.
|
||||
virtual AllocWorkbufResult //
|
||||
@@ -19178,8 +19316,14 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
|
||||
// ---------------- Images (Utility)
|
||||
|
||||
#define wuffs_base__utility__make_pixel_blend wuffs_base__make_pixel_blend
|
||||
#define wuffs_base__utility__make_pixel_format wuffs_base__make_pixel_format
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__utility__demake_pixel_blend(wuffs_base__pixel_blend a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
// ---------------- String Conversions
|
||||
|
||||
// ---------------- Unicode and UTF-8
|
||||
@@ -24318,6 +24462,26 @@ wuffs_private_impl__swizzle_xxxx__y__x86_sse42(uint8_t* dst_ptr,
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(
|
||||
uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul);
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(
|
||||
uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul);
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul);
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_private_impl__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul);
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_private_impl__color_u64__as__color_u32__swap_u32_argb_abgr(uint64_t c) {
|
||||
uint32_t a = ((uint32_t)(0xFF & (c >> 56)));
|
||||
@@ -24425,7 +24589,7 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
// --------
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
@@ -24538,6 +24702,365 @@ wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_nonpremul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color) {
|
||||
if (!pb) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if ((x >= pb->pixcfg.private_impl.width) ||
|
||||
(y >= pb->pixcfg.private_impl.height)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
|
||||
if (wuffs_base__pixel_format__is_planar(&pb->pixcfg.private_impl.pixfmt)) {
|
||||
// TODO: support planar formats.
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
size_t stride = pb->private_impl.planes[0].stride;
|
||||
uint8_t* row = pb->private_impl.planes[0].ptr + (stride * ((size_t)y));
|
||||
|
||||
switch (pb->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color));
|
||||
break;
|
||||
|
||||
// Common formats above. Rarer formats below.
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
wuffs_base__poke_u8__no_bounds_check(
|
||||
row + ((size_t)x),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u8_gray(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_gray(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
wuffs_base__poke_u16be__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_gray(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL:
|
||||
wuffs_base__poke_u8__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u8_gray(color |
|
||||
0xFF000000));
|
||||
wuffs_base__poke_u8__no_bounds_check(row + (2 * ((size_t)x)) + 1,
|
||||
((uint8_t)(color >> 24)));
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
|
||||
wuffs_base__poke_u8__no_bounds_check(
|
||||
row + ((size_t)x),
|
||||
wuffs_base__pixel_palette__closest_element(
|
||||
wuffs_base__pixel_buffer__palette(pb),
|
||||
pb->pixcfg.private_impl.pixfmt,
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
row + (2 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
row + (3 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
wuffs_base__poke_u32le__no_bounds_check(row + (4 * ((size_t)x)), color);
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
row + (8 * ((size_t)x)), wuffs_base__color_u32__as__color_u64(color));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:
|
||||
wuffs_base__poke_u64le__no_bounds_check(
|
||||
row + (8 * ((size_t)x)),
|
||||
wuffs_base__color_u64_argb_nonpremul__as__color_u64_argb_premul(
|
||||
wuffs_base__color_u32__as__color_u64(color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)),
|
||||
(color >> 31)
|
||||
? (wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color) |
|
||||
0xFF000000)
|
||||
: 0);
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
wuffs_base__poke_u24le__no_bounds_check(
|
||||
row + (3 * ((size_t)x)),
|
||||
wuffs_base__color_swap_u32_argb_abgr(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)), wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)),
|
||||
wuffs_base__color_swap_u32_argb_abgr(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color)));
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: support more formats.
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
static inline wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__composite_color_u32_nonpremul_at(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
wuffs_base__color_u32_argb_nonpremul color) {
|
||||
if (!pb) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if ((x >= pb->pixcfg.private_impl.width) ||
|
||||
(y >= pb->pixcfg.private_impl.height)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
|
||||
if (wuffs_base__pixel_format__is_planar(&pb->pixcfg.private_impl.pixfmt)) {
|
||||
// TODO: support planar formats.
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
size_t stride = pb->private_impl.planes[0].stride;
|
||||
uint8_t* row = pb->private_impl.planes[0].ptr + (stride * ((size_t)y));
|
||||
|
||||
switch (pb->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr) | 0xFF000000;
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
// Common formats above. Rarer formats below.
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y: {
|
||||
uint8_t* ptr = row + ((size_t)x);
|
||||
uint32_t dst = 0xFF000000 | (0x00010101 * ((uint32_t)(*ptr)));
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
*ptr = ((uint8_t)(dst));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE: {
|
||||
uint8_t* ptr = row + (2 * ((size_t)x));
|
||||
uint64_t dst =
|
||||
0xFFFF000000000000 |
|
||||
(0x000100010001 *
|
||||
((uint64_t)(wuffs_base__peek_u16le__no_bounds_check(ptr))));
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u64_axxx(
|
||||
dst, wuffs_base__color_u32__as__color_u64(color));
|
||||
wuffs_base__poke_u16le__no_bounds_check(ptr, ((uint16_t)(dst)));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE: {
|
||||
uint8_t* ptr = row + (2 * ((size_t)x));
|
||||
uint64_t dst =
|
||||
0xFFFF000000000000 |
|
||||
(0x000100010001 *
|
||||
((uint64_t)(wuffs_base__peek_u16be__no_bounds_check(ptr))));
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u64_axxx(
|
||||
dst, wuffs_base__color_u32__as__color_u64(color));
|
||||
wuffs_base__poke_u16be__no_bounds_check(ptr, ((uint16_t)(dst)));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL: {
|
||||
uint8_t* ptr = row + (2 * ((size_t)x));
|
||||
uint32_t dst =
|
||||
(((uint32_t)(ptr[1])) << 24) | (((uint32_t)(ptr[0])) * 0x00010101);
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(dst,
|
||||
color);
|
||||
ptr[0] = wuffs_base__color_u32_argb_premul__as__color_u8_gray(dst |
|
||||
0xFF000000);
|
||||
ptr[1] = ((uint8_t)(dst >> 24));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL: {
|
||||
wuffs_base__slice_u8 palette = wuffs_base__pixel_buffer__palette(pb);
|
||||
if (palette.len) {
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(
|
||||
palette.ptr + (4 * ((size_t)row[x])));
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(dst,
|
||||
color);
|
||||
row[x] = wuffs_base__pixel_palette__closest_element(
|
||||
wuffs_base__pixel_buffer__palette(pb),
|
||||
pb->pixcfg.private_impl.pixfmt,
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
dst));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY: {
|
||||
wuffs_base__slice_u8 palette = wuffs_base__pixel_buffer__palette(pb);
|
||||
if (palette.len) {
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(
|
||||
palette.ptr + (4 * ((size_t)row[x])));
|
||||
dst =
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
row[x] = wuffs_base__pixel_palette__closest_element(
|
||||
wuffs_base__pixel_buffer__palette(pb),
|
||||
pb->pixcfg.private_impl.pixfmt, dst);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565: {
|
||||
uint8_t* ptr = row + (2 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(
|
||||
wuffs_base__peek_u16le__no_bounds_check(ptr));
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
wuffs_base__poke_u16le__no_bounds_check(
|
||||
ptr, wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(dst));
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR: {
|
||||
uint8_t* ptr = row + (3 * ((size_t)x));
|
||||
uint32_t dst = 0xFF000000 | wuffs_base__peek_u24le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
wuffs_base__poke_u24le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(dst,
|
||||
color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE: {
|
||||
uint8_t* ptr = row + (8 * ((size_t)x));
|
||||
uint64_t dst = wuffs_base__peek_u64le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u64_axxx(
|
||||
dst, wuffs_base__color_u32__as__color_u64(color));
|
||||
wuffs_base__poke_u64le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE: {
|
||||
uint8_t* ptr = row + (8 * ((size_t)x));
|
||||
uint64_t dst = wuffs_base__peek_u64le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u64_axxx(
|
||||
dst, wuffs_base__color_u32__as__color_u64(color));
|
||||
wuffs_base__poke_u64le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
if (dst) {
|
||||
dst =
|
||||
wuffs_private_impl__composite_premul_nonpremul_u32_axxx(dst, color);
|
||||
} else if (color >> 31) {
|
||||
dst = (wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
color) |
|
||||
0xFF000000);
|
||||
}
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB: {
|
||||
uint8_t* ptr = row + (3 * ((size_t)x));
|
||||
uint32_t dst = 0xFF000000 | wuffs_base__peek_u24le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
dst, wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
wuffs_base__poke_u24le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_nonpremul_nonpremul_u32_axxx(
|
||||
dst, wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
dst, wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX: {
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst = wuffs_base__peek_u32le__no_bounds_check(ptr) | 0xFF000000;
|
||||
dst = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
dst, wuffs_base__color_swap_u32_argb_abgr(color));
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// TODO: support more formats.
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static inline void //
|
||||
@@ -24665,7 +25188,7 @@ wuffs_private_impl__pixel_buffer__set_color_u32_fill_rect__xxxxxxxx(
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
wuffs_base__pixel_buffer* pb,
|
||||
wuffs_base__rect_ie_u32 rect,
|
||||
wuffs_base__color_u32_argb_premul color) {
|
||||
@@ -24737,7 +25260,7 @@ wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
for (y = rect.min_incl_y; y < rect.max_excl_y; y++) {
|
||||
uint32_t x;
|
||||
for (x = rect.min_incl_x; x < rect.max_excl_x; x++) {
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(pb, x, y, color);
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(pb, x, y, color);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_status(NULL);
|
||||
@@ -32440,6 +32963,102 @@ typedef void (*wuffs_private_impl__swizzle_ycc__convert_4_func)(
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3);
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycca_bt601sr_src__convert_4_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3) {
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
color &= 0xFFFFFFu;
|
||||
color |= ((uint32_t)(*up3++)) << 24;
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_nonpremul_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycca_bt601sr_src__convert_4_bgra_premul(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3) {
|
||||
size_t stride = dst->private_impl.planes[0].stride;
|
||||
uint8_t* row = dst->private_impl.planes[0].ptr + (stride * ((size_t)y));
|
||||
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
color &= 0xFFFFFFu;
|
||||
color |= ((uint32_t)(*up3++)) << 24;
|
||||
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst_color =
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst_color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycca_bt601sr_src_over__convert_4_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3) {
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
color &= 0xFFFFFFu;
|
||||
color |= ((uint32_t)(*up3++)) << 24;
|
||||
wuffs_base__pixel_buffer__composite_color_u32_nonpremul_at(dst, x, y,
|
||||
color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_ycca_bt601sr_src_over__convert_4_bgra_premul(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
uint32_t x,
|
||||
uint32_t x_end,
|
||||
uint32_t y,
|
||||
const uint8_t* up0,
|
||||
const uint8_t* up1,
|
||||
const uint8_t* up2,
|
||||
const uint8_t* up3) {
|
||||
size_t stride = dst->private_impl.planes[0].stride;
|
||||
uint8_t* row = dst->private_impl.planes[0].ptr + (stride * ((size_t)y));
|
||||
|
||||
for (; x < x_end; x++) {
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
color &= 0xFFFFFFu;
|
||||
color |= ((uint32_t)(*up3++)) << 24;
|
||||
|
||||
uint8_t* ptr = row + (4 * ((size_t)x));
|
||||
uint32_t dst_color = wuffs_base__peek_u32le__no_bounds_check(ptr);
|
||||
dst_color = wuffs_private_impl__composite_premul_nonpremul_u32_axxx(
|
||||
dst_color, color);
|
||||
wuffs_base__poke_u32le__no_bounds_check(ptr, dst_color);
|
||||
}
|
||||
}
|
||||
|
||||
static void //
|
||||
wuffs_private_impl__swizzle_cmyk__convert_4_general(
|
||||
wuffs_base__pixel_buffer* dst,
|
||||
@@ -32461,7 +33080,7 @@ wuffs_private_impl__swizzle_cmyk__convert_4_general(
|
||||
r = ((r * w) + 0x7Fu) / 0xFFu;
|
||||
g = ((g * w) + 0x7Fu) / 0xFFu;
|
||||
b = ((b * w) + 0x7Fu) / 0xFFu;
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
dst, x, y, 0xFF000000u | (r << 16u) | (g << 8u) | (b << 0u));
|
||||
}
|
||||
}
|
||||
@@ -32488,7 +33107,7 @@ wuffs_private_impl__swizzle_ycck__convert_4_general(
|
||||
r = ((r * w) + 0x7Fu) / 0xFFu;
|
||||
g = ((g * w) + 0x7Fu) / 0xFFu;
|
||||
b = ((b * w) + 0x7Fu) / 0xFFu;
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
dst, x, y, 0xFF000000u | (r << 16u) | (g << 8u) | (b << 0u));
|
||||
}
|
||||
}
|
||||
@@ -32518,7 +33137,7 @@ wuffs_private_impl__swizzle_rgb__convert_3_general(
|
||||
(((uint32_t)(*up0++)) << 16u) | //
|
||||
(((uint32_t)(*up1++)) << 8u) | //
|
||||
(((uint32_t)(*up2++)) << 0u);
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32535,7 +33154,7 @@ wuffs_private_impl__swizzle_ycc_bt601fr__convert_3_general(
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601fr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32596,7 +33215,7 @@ wuffs_private_impl__swizzle_ycc_bt601sr__convert_3_general(
|
||||
uint32_t color = //
|
||||
wuffs_base__color_ycc_bt601sr__as__color_u32( //
|
||||
*up0++, *up1++, *up2++);
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(dst, x, y, color);
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(dst, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33802,7 +34421,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
}
|
||||
|
||||
if (wuffs_base__pixel_format__is_planar(&dst->pixcfg.private_impl.pixfmt)) {
|
||||
// TODO: see wuffs_base__pixel_buffer__set_color_u32_at's TODO.
|
||||
// TODO: see wuffs_base__pixel_buffer__set_color_u32_argb_premul_at's TODO.
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
}
|
||||
@@ -33877,7 +34496,8 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
break;
|
||||
|
||||
default:
|
||||
// TODO: see wuffs_base__pixel_buffer__set_color_u32_at's TODO.
|
||||
// TODO: see wuffs_base__pixel_buffer__set_color_u32_argb_premul_at's
|
||||
// TODO.
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
}
|
||||
@@ -33890,7 +34510,7 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
if (ycc_model >= WUFFS_BASE__YCC_MODEL__RGB) {
|
||||
conv3func = &wuffs_private_impl__swizzle_rgb__convert_3_general;
|
||||
|
||||
} else if (ycc_model == WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE) {
|
||||
} else if (ycc_model >= WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE) {
|
||||
switch (dst->pixcfg.private_impl.pixfmt.repr) {
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
@@ -34035,14 +34655,39 @@ wuffs_base__pixel_swizzler__swizzle_ycck(
|
||||
}
|
||||
|
||||
if ((h3 != 0u) || (v3 != 0u)) {
|
||||
if (ycc_model == WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE) {
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func = NULL;
|
||||
switch (ycc_model) {
|
||||
case WUFFS_BASE__YCC_MODEL__BT_601_FULL_RANGE:
|
||||
conv4func = &wuffs_private_impl__swizzle_ycck__convert_4_general;
|
||||
break;
|
||||
case WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC:
|
||||
if (dst->pixcfg.private_impl.pixfmt.repr ==
|
||||
WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL) {
|
||||
conv4func =
|
||||
&wuffs_private_impl__swizzle_ycca_bt601sr_src__convert_4_bgra_premul;
|
||||
} else {
|
||||
conv4func =
|
||||
&wuffs_private_impl__swizzle_ycca_bt601sr_src__convert_4_general;
|
||||
}
|
||||
break;
|
||||
case WUFFS_BASE__YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC_OVER:
|
||||
if (dst->pixcfg.private_impl.pixfmt.repr ==
|
||||
WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL) {
|
||||
conv4func =
|
||||
&wuffs_private_impl__swizzle_ycca_bt601sr_src_over__convert_4_bgra_premul;
|
||||
} else {
|
||||
conv4func =
|
||||
&wuffs_private_impl__swizzle_ycca_bt601sr_src_over__convert_4_general;
|
||||
}
|
||||
break;
|
||||
case WUFFS_BASE__YCC_MODEL__CMY:
|
||||
conv4func = &wuffs_private_impl__swizzle_cmyk__convert_4_general;
|
||||
break;
|
||||
default:
|
||||
return wuffs_base__make_status(
|
||||
wuffs_base__error__unsupported_pixel_swizzler_option);
|
||||
}
|
||||
wuffs_private_impl__swizzle_ycc__convert_4_func conv4func =
|
||||
(ycc_model >= WUFFS_BASE__YCC_MODEL__RGB)
|
||||
? &wuffs_private_impl__swizzle_cmyk__convert_4_general
|
||||
: &wuffs_private_impl__swizzle_ycck__convert_4_general;
|
||||
|
||||
(*func4)( //
|
||||
dst, x_min_incl, x_max_excl, y_min_incl, y_max_excl, //
|
||||
src0.ptr, src1.ptr, src2.ptr, src3.ptr, //
|
||||
@@ -80933,7 +81578,9 @@ wuffs_thumbhash__decoder__workbuf_len(
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_vp8__error__bad_quirk_source_length[] = "#vp8: bad QUIRK_SOURCE_LENGTH";
|
||||
const char wuffs_vp8__error__bad_quirk_width_and_height[] = "#vp8: bad QUIRK_WIDTH_AND_HEIGHT";
|
||||
const char wuffs_vp8__error__bad_header[] = "#vp8: bad header";
|
||||
const char wuffs_vp8__error__inconsistent_width_and_height[] = "#vp8: inconsistent width and height";
|
||||
const char wuffs_vp8__error__missing_quirk_source_length[] = "#vp8: missing QUIRK_SOURCE_LENGTH";
|
||||
const char wuffs_vp8__error__truncated_input[] = "#vp8: truncated input";
|
||||
const char wuffs_vp8__error__unsupported_quirk_source_length[] = "#vp8: unsupported QUIRK_SOURCE_LENGTH";
|
||||
@@ -81828,6 +82475,8 @@ WUFFS_VP8__ZIGZAG[16] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
9u, 12u, 13u, 10u, 7u, 11u, 14u, 15u,
|
||||
};
|
||||
|
||||
#define WUFFS_VP8__QUIRKS_BASE 1836840960u
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
@@ -82029,7 +82678,6 @@ WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_vp8__decoder__decode_macroblocks(
|
||||
wuffs_vp8__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__slice_u8 a_workbuf);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -82081,6 +82729,7 @@ static wuffs_base__status
|
||||
wuffs_vp8__decoder__swizzle(
|
||||
wuffs_vp8__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -82135,6 +82784,11 @@ wuffs_vp8__decoder__do_decode_image_config(
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_vp8__decoder__calculate_mbw_mbh(
|
||||
wuffs_vp8__decoder* self);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_vp8__decoder__do_decode_frame_config(
|
||||
@@ -83928,11 +84582,9 @@ WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_vp8__decoder__decode_macroblocks(
|
||||
wuffs_vp8__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__slice_u8 a_workbuf) {
|
||||
uint32_t v_mby = 0;
|
||||
uint32_t v_mbx = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
v_mbx = 0u;
|
||||
while (v_mbx < self->private_impl.f_mbw) {
|
||||
@@ -83964,10 +84616,6 @@ wuffs_vp8__decoder__decode_macroblocks(
|
||||
} else {
|
||||
wuffs_vp8__decoder__filter_normal(self, a_workbuf, (self->private_impl.f_mbh - 1u));
|
||||
}
|
||||
v_status = wuffs_vp8__decoder__swizzle(self, a_dst, a_workbuf);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
return wuffs_private_impl__status__ensure_not_a_suspension(v_status);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
@@ -84232,10 +84880,34 @@ static wuffs_base__status
|
||||
wuffs_vp8__decoder__swizzle(
|
||||
wuffs_vp8__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf) {
|
||||
uint64_t v_wh = 0;
|
||||
wuffs_base__slice_u8 v_prefix = {0};
|
||||
wuffs_base__slice_u8 v_suffix = {0};
|
||||
uint32_t v_has_alpha = 0;
|
||||
uint32_t v_ycc_model = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
if ((self->private_impl.f_workbuf_yuv_y_end > self->private_impl.f_workbuf_yuv_u_end) || (self->private_impl.f_workbuf_yuv_u_end > self->private_impl.f_workbuf_yuv_v_end) || (self->private_impl.f_workbuf_yuv_v_end > ((uint64_t)(a_workbuf.len)))) {
|
||||
if (self->private_impl.f_quirk_has_alpha_side_channel) {
|
||||
if (self->private_impl.f_quirk_width_and_height == 0u) {
|
||||
return wuffs_base__make_status(wuffs_vp8__error__inconsistent_width_and_height);
|
||||
}
|
||||
v_wh = ((uint64_t)((self->private_impl.f_width * self->private_impl.f_height)));
|
||||
if (v_wh > ((uint64_t)(a_workbuf.len))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
|
||||
}
|
||||
v_prefix = wuffs_base__slice_u8__subslice_j(a_workbuf, v_wh);
|
||||
v_suffix = wuffs_base__slice_u8__subslice_i(a_workbuf, v_wh);
|
||||
v_has_alpha = 1u;
|
||||
v_ycc_model = (6u | (1u & ((uint32_t)(wuffs_base__utility__demake_pixel_blend(a_blend)))));
|
||||
} else {
|
||||
v_prefix = wuffs_base__utility__empty_slice_u8();
|
||||
v_suffix = a_workbuf;
|
||||
v_has_alpha = 0u;
|
||||
v_ycc_model = 4u;
|
||||
}
|
||||
if ((self->private_impl.f_workbuf_yuv_y_end > self->private_impl.f_workbuf_yuv_u_end) || (self->private_impl.f_workbuf_yuv_u_end > self->private_impl.f_workbuf_yuv_v_end) || (self->private_impl.f_workbuf_yuv_v_end > ((uint64_t)(v_suffix.len)))) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__swizzle_ycck(&self->private_impl.f_swizzler,
|
||||
@@ -84245,35 +84917,35 @@ wuffs_vp8__decoder__swizzle(
|
||||
self->private_impl.f_width,
|
||||
0u,
|
||||
self->private_impl.f_height,
|
||||
wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_yuv_y_end),
|
||||
wuffs_base__slice_u8__subslice_ij(a_workbuf,
|
||||
wuffs_base__slice_u8__subslice_j(v_suffix, self->private_impl.f_workbuf_yuv_y_end),
|
||||
wuffs_base__slice_u8__subslice_ij(v_suffix,
|
||||
self->private_impl.f_workbuf_yuv_y_end,
|
||||
self->private_impl.f_workbuf_yuv_u_end),
|
||||
wuffs_base__slice_u8__subslice_ij(a_workbuf,
|
||||
wuffs_base__slice_u8__subslice_ij(v_suffix,
|
||||
self->private_impl.f_workbuf_yuv_u_end,
|
||||
self->private_impl.f_workbuf_yuv_v_end),
|
||||
wuffs_base__utility__empty_slice_u8(),
|
||||
v_prefix,
|
||||
(self->private_impl.f_mbw * 16u),
|
||||
(self->private_impl.f_mbw * 8u),
|
||||
(self->private_impl.f_mbw * 8u),
|
||||
0u,
|
||||
(self->private_impl.f_width * v_has_alpha),
|
||||
(self->private_impl.f_mbh * 16u),
|
||||
(self->private_impl.f_mbh * 8u),
|
||||
(self->private_impl.f_mbh * 8u),
|
||||
0u,
|
||||
(self->private_impl.f_height * v_has_alpha),
|
||||
(self->private_impl.f_mbw * 16u),
|
||||
(self->private_impl.f_mbw * 8u),
|
||||
(self->private_impl.f_mbw * 8u),
|
||||
0u,
|
||||
(self->private_impl.f_width * v_has_alpha),
|
||||
2u,
|
||||
1u,
|
||||
1u,
|
||||
0u,
|
||||
((uint8_t)((2u * v_has_alpha))),
|
||||
2u,
|
||||
1u,
|
||||
1u,
|
||||
0u,
|
||||
((uint8_t)(1u)),
|
||||
((uint8_t)((2u * v_has_alpha))),
|
||||
((uint8_t)(v_ycc_model)),
|
||||
((uint8_t)(2u)),
|
||||
wuffs_base__make_slice_u8(self->private_data.f_swizzle_ycck_scratch_buffer_2k, 2048));
|
||||
return wuffs_private_impl__status__ensure_not_a_suspension(v_status);
|
||||
@@ -85193,6 +85865,12 @@ wuffs_vp8__decoder__get_quirk(
|
||||
|
||||
if (a_key == 3u) {
|
||||
return self->private_impl.f_quirk_source_length;
|
||||
} else if (a_key == 1836840960u) {
|
||||
if (self->private_impl.f_quirk_has_alpha_side_channel) {
|
||||
return 1u;
|
||||
}
|
||||
} else if (a_key == 1836840961u) {
|
||||
return self->private_impl.f_quirk_width_and_height;
|
||||
}
|
||||
return 0u;
|
||||
}
|
||||
@@ -85215,8 +85893,41 @@ wuffs_vp8__decoder__set_quirk(
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
uint32_t v_w = 0;
|
||||
uint32_t v_h = 0;
|
||||
|
||||
if (a_key == 3u) {
|
||||
self->private_impl.f_quirk_source_length = a_value;
|
||||
if ((a_value & 1u) == 0u) {
|
||||
if (a_value != 0u) {
|
||||
return wuffs_base__make_status(wuffs_vp8__error__bad_quirk_source_length);
|
||||
}
|
||||
self->private_impl.f_quirk_source_length = 0u;
|
||||
self->private_impl.f_partitioned_data_length = 0u;
|
||||
} else if ((a_value >> 1u) < 10u) {
|
||||
return wuffs_base__make_status(wuffs_vp8__error__bad_quirk_source_length);
|
||||
} else if ((a_value >> 1u) > 150994945u) {
|
||||
return wuffs_base__make_status(wuffs_vp8__error__unsupported_quirk_source_length);
|
||||
} else {
|
||||
self->private_impl.f_quirk_source_length = a_value;
|
||||
self->private_impl.f_partitioned_data_length = (((uint32_t)((a_value >> 1u))) - 10u);
|
||||
}
|
||||
return wuffs_base__make_status(NULL);
|
||||
} else if (a_key == 1836840960u) {
|
||||
self->private_impl.f_quirk_has_alpha_side_channel = (a_value != 0u);
|
||||
return wuffs_base__make_status(NULL);
|
||||
} else if (a_key == 1836840961u) {
|
||||
v_w = ((uint32_t)(a_value));
|
||||
v_h = ((uint32_t)((a_value >> 32u)));
|
||||
if ((v_w < 1u) ||
|
||||
(16383u < v_w) ||
|
||||
(v_h < 1u) ||
|
||||
(16383u < v_h)) {
|
||||
return wuffs_base__make_status(wuffs_vp8__error__bad_quirk_width_and_height);
|
||||
}
|
||||
self->private_impl.f_quirk_width_and_height = a_value;
|
||||
self->private_impl.f_width = v_w;
|
||||
self->private_impl.f_height = v_h;
|
||||
wuffs_vp8__decoder__calculate_mbw_mbh(self);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
@@ -85319,17 +86030,10 @@ wuffs_vp8__decoder__do_decode_image_config(
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
if ((self->private_impl.f_quirk_source_length & 1u) == 0u) {
|
||||
if (self->private_impl.f_quirk_source_length == 0u) {
|
||||
status = wuffs_base__make_status(wuffs_vp8__error__missing_quirk_source_length);
|
||||
goto exit;
|
||||
} else if ((self->private_impl.f_quirk_source_length >> 1u) < 10u) {
|
||||
status = wuffs_base__make_status(wuffs_vp8__error__bad_quirk_source_length);
|
||||
goto exit;
|
||||
} else if ((self->private_impl.f_quirk_source_length >> 1u) > 150994945u) {
|
||||
status = wuffs_base__make_status(wuffs_vp8__error__unsupported_quirk_source_length);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_partitioned_data_length = (((uint32_t)((self->private_impl.f_quirk_source_length >> 1u))) - 10u);
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint32_t t_0;
|
||||
@@ -85433,13 +86137,14 @@ wuffs_vp8__decoder__do_decode_image_config(
|
||||
}
|
||||
self->private_impl.f_width = (16383u & v_c32);
|
||||
self->private_impl.f_height = (16383u & (v_c32 >> 16u));
|
||||
self->private_impl.f_mbw = ((self->private_impl.f_width + 15u) / 16u);
|
||||
self->private_impl.f_mbh = ((self->private_impl.f_height + 15u) / 16u);
|
||||
self->private_impl.f_workbuf_yuv_y_stride = (self->private_impl.f_mbw * 16u);
|
||||
self->private_impl.f_workbuf_yuv_uv_stride = (self->private_impl.f_mbw * 8u);
|
||||
self->private_impl.f_workbuf_yuv_y_end = (((uint64_t)(self->private_impl.f_workbuf_yuv_y_stride)) * ((uint64_t)((self->private_impl.f_mbh * 16u))));
|
||||
self->private_impl.f_workbuf_yuv_u_end = (self->private_impl.f_workbuf_yuv_y_end + (((uint64_t)(self->private_impl.f_workbuf_yuv_uv_stride)) * ((uint64_t)((self->private_impl.f_mbh * 8u)))));
|
||||
self->private_impl.f_workbuf_yuv_v_end = (self->private_impl.f_workbuf_yuv_u_end + (((uint64_t)(self->private_impl.f_workbuf_yuv_uv_stride)) * ((uint64_t)((self->private_impl.f_mbh * 8u)))));
|
||||
if ((self->private_impl.f_width == 0u) || (self->private_impl.f_height == 0u)) {
|
||||
status = wuffs_base__make_status(wuffs_vp8__error__bad_header);
|
||||
goto exit;
|
||||
} else if ((self->private_impl.f_quirk_width_and_height != 0u) && (self->private_impl.f_quirk_width_and_height != (((uint64_t)(self->private_impl.f_width)) | (((uint64_t)(self->private_impl.f_height)) << 32u)))) {
|
||||
status = wuffs_base__make_status(wuffs_vp8__error__inconsistent_width_and_height);
|
||||
goto exit;
|
||||
}
|
||||
wuffs_vp8__decoder__calculate_mbw_mbh(self);
|
||||
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)));
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__image_config__set(
|
||||
@@ -85472,6 +86177,22 @@ wuffs_vp8__decoder__do_decode_image_config(
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func vp8.decoder.calculate_mbw_mbh
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_vp8__decoder__calculate_mbw_mbh(
|
||||
wuffs_vp8__decoder* self) {
|
||||
self->private_impl.f_mbw = ((self->private_impl.f_width + 15u) / 16u);
|
||||
self->private_impl.f_mbh = ((self->private_impl.f_height + 15u) / 16u);
|
||||
self->private_impl.f_workbuf_yuv_y_stride = (self->private_impl.f_mbw * 16u);
|
||||
self->private_impl.f_workbuf_yuv_uv_stride = (self->private_impl.f_mbw * 8u);
|
||||
self->private_impl.f_workbuf_yuv_y_end = (((uint64_t)(self->private_impl.f_workbuf_yuv_y_stride)) * ((uint64_t)((self->private_impl.f_mbh * 16u))));
|
||||
self->private_impl.f_workbuf_yuv_u_end = (self->private_impl.f_workbuf_yuv_y_end + (((uint64_t)(self->private_impl.f_workbuf_yuv_uv_stride)) * ((uint64_t)((self->private_impl.f_mbh * 8u)))));
|
||||
self->private_impl.f_workbuf_yuv_v_end = (self->private_impl.f_workbuf_yuv_u_end + (((uint64_t)(self->private_impl.f_workbuf_yuv_uv_stride)) * ((uint64_t)((self->private_impl.f_mbh * 8u)))));
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func vp8.decoder.decode_frame_config
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -85657,37 +86378,65 @@ wuffs_vp8__decoder__decode_frame(
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint64_t v_wh = 0;
|
||||
uint64_t v_wb_len = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
wuffs_base__slice_u8 v_trimmed = {0};
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame;
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
while (true) {
|
||||
v_trimmed = a_workbuf;
|
||||
if (self->private_impl.f_quirk_has_alpha_side_channel) {
|
||||
if (self->private_impl.f_quirk_width_and_height == 0u) {
|
||||
status = wuffs_base__make_status(wuffs_vp8__error__inconsistent_width_and_height);
|
||||
goto exit;
|
||||
}
|
||||
v_wh = ((uint64_t)((self->private_impl.f_width * self->private_impl.f_height)));
|
||||
if (v_wh > ((uint64_t)(a_workbuf.len))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
|
||||
goto exit;
|
||||
}
|
||||
v_trimmed = wuffs_base__slice_u8__subslice_i(a_workbuf, v_wh);
|
||||
}
|
||||
v_wb_len = (self->private_impl.f_workbuf_yuv_v_end + ((uint64_t)(self->private_impl.f_partitioned_data_length)) + 8u);
|
||||
if (v_wb_len > ((uint64_t)(a_workbuf.len))) {
|
||||
if (v_wb_len > ((uint64_t)(v_trimmed.len))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
|
||||
goto exit;
|
||||
} else {
|
||||
a_workbuf = wuffs_base__slice_u8__subslice_j(a_workbuf, v_wb_len);
|
||||
v_trimmed = wuffs_base__slice_u8__subslice_j(v_trimmed, v_wb_len);
|
||||
}
|
||||
{
|
||||
wuffs_base__status t_0 = wuffs_vp8__decoder__do_decode_frame(self,
|
||||
a_dst,
|
||||
a_src,
|
||||
a_blend,
|
||||
a_workbuf,
|
||||
v_trimmed,
|
||||
a_opts);
|
||||
v_status = t_0;
|
||||
}
|
||||
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
break;
|
||||
} else if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
|
||||
status = wuffs_base__make_status(wuffs_vp8__error__truncated_input);
|
||||
goto exit;
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
v_status = wuffs_vp8__decoder__swizzle(self, a_dst, a_blend, a_workbuf);
|
||||
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;
|
||||
}
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame = 0;
|
||||
@@ -85789,7 +86538,7 @@ wuffs_vp8__decoder__do_decode_frame(
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
v_status = wuffs_vp8__decoder__decode_macroblocks(self, a_dst, a_workbuf);
|
||||
v_status = wuffs_vp8__decoder__decode_macroblocks(self, a_workbuf);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = v_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
@@ -85990,10 +86739,17 @@ wuffs_vp8__decoder__workbuf_len(
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
|
||||
uint64_t v_wh = 0;
|
||||
uint64_t v_wb_len = 0;
|
||||
|
||||
if (self->private_impl.f_quirk_source_length == 0u) {
|
||||
return wuffs_base__utility__make_range_ii_u64(1u, 0u);
|
||||
}
|
||||
if (self->private_impl.f_quirk_has_alpha_side_channel) {
|
||||
v_wh = ((uint64_t)((self->private_impl.f_width * self->private_impl.f_height)));
|
||||
}
|
||||
v_wb_len = (self->private_impl.f_workbuf_yuv_v_end + ((uint64_t)(self->private_impl.f_partitioned_data_length)) + 8u);
|
||||
return wuffs_base__utility__make_range_ii_u64(v_wb_len, v_wb_len);
|
||||
return wuffs_base__utility__make_range_ii_u64((v_wh + v_wb_len), (v_wh + v_wb_len));
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__VP8)
|
||||
@@ -86924,18 +87680,20 @@ wuffs_wbmp__decoder__workbuf_len(
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_webp__error__bad_alph_vp8l_combination[] = "#webp: bad ALPH+VP8L combination";
|
||||
const char wuffs_webp__error__bad_huffman_code_over_subscribed[] = "#webp: bad Huffman code (over-subscribed)";
|
||||
const char wuffs_webp__error__bad_huffman_code_under_subscribed[] = "#webp: bad Huffman code (under-subscribed)";
|
||||
const char wuffs_webp__error__bad_huffman_code[] = "#webp: bad Huffman code";
|
||||
const char wuffs_webp__error__bad_vp8x_chunk[] = "#webp: bad VP8X chunk";
|
||||
const char wuffs_webp__error__bad_back_reference[] = "#webp: bad back-reference";
|
||||
const char wuffs_webp__error__bad_chunk_order[] = "#webp: bad chunk order";
|
||||
const char wuffs_webp__error__bad_color_cache[] = "#webp: bad color cache";
|
||||
const char wuffs_webp__error__bad_header[] = "#webp: bad header";
|
||||
const char wuffs_webp__error__bad_transform[] = "#webp: bad transform";
|
||||
const char wuffs_webp__error__short_chunk[] = "#webp: short chunk";
|
||||
const char wuffs_webp__error__truncated_input[] = "#webp: truncated input";
|
||||
const char wuffs_webp__error__unsupported_number_of_huffman_groups[] = "#webp: unsupported number of Huffman groups";
|
||||
const char wuffs_webp__error__unsupported_transform_after_color_indexing_transform[] = "#webp: unsupported transform after color indexing transform";
|
||||
const char wuffs_webp__error__unsupported_webp_file[] = "#webp: unsupported WebP file";
|
||||
const char wuffs_webp__error__unsupported_number_of_huffman_groups[] = "#webp: unsupported number of Huffman groups";
|
||||
const char wuffs_webp__error__internal_error_inconsistent_huffman_code[] = "#webp: internal error: inconsistent Huffman code";
|
||||
const char wuffs_webp__error__internal_error_inconsistent_dst_buffer[] = "#webp: internal error: inconsistent dst buffer";
|
||||
const char wuffs_webp__error__internal_error_inconsistent_n_bits[] = "#webp: internal error: inconsistent n_bits";
|
||||
@@ -86987,6 +87745,44 @@ WUFFS_WEBP__DISTANCE_MAP[120] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__decode_alph(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__decode_alph_limited(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__compact_alph(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_s);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__filter_alph_horizontal(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_s);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__filter_alph_vertical(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_s);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__filter_alph_gradient(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_s);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__decode_huffman_groups(
|
||||
@@ -87050,6 +87846,7 @@ static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_predictor(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width,
|
||||
wuffs_base__slice_u8 a_tile_data);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -87080,6 +87877,7 @@ static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_cross_color(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width,
|
||||
wuffs_base__slice_u8 a_tile_data);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -87092,38 +87890,12 @@ WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_color_indexing(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix);
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited_vp8l(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_frame_config(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_frame(
|
||||
wuffs_webp__decoder__do_decode_frame_vp8l(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
@@ -87171,6 +87943,49 @@ wuffs_webp__decoder__swizzle(
|
||||
wuffs_base__slice_u8 a_src,
|
||||
wuffs_base__pixel_blend a_blend);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited_vp8l(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited_vp8x(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_frame_config(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_frame(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts);
|
||||
|
||||
// ---------------- VTables
|
||||
|
||||
const wuffs_base__image_decoder__func_ptrs
|
||||
@@ -87287,6 +88102,375 @@ sizeof__wuffs_webp__decoder(void) {
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func webp.decoder.decode_alph
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__decode_alph(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint64_t v_r_mark = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_alph;
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
while (true) {
|
||||
{
|
||||
const bool o_0_closed_a_src = a_src->meta.closed;
|
||||
const uint8_t* o_0_io2_a_src = io2_a_src;
|
||||
wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_sub_chunk_length)));
|
||||
if (a_src) {
|
||||
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
|
||||
a_src->meta.wi = n;
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_webp__decoder__decode_alph_limited(self, a_src, a_workbuf);
|
||||
v_status = t_0;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_sub_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.closed = o_0_closed_a_src;
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&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;
|
||||
} else if ((v_status.repr == wuffs_base__suspension__short_read) && (self->private_impl.f_sub_chunk_length == 0u)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__short_chunk);
|
||||
goto exit;
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_alph = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_alph = 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 webp.decoder.decode_alph_limited
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__decode_alph_limited(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__slice_u8 a_workbuf) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint64_t v_n = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && a_src->data.ptr) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_alph_limited;
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_0 = *iop_a_src++;
|
||||
self->private_impl.f_vp8x_alph_flags = t_0;
|
||||
}
|
||||
if (((uint8_t)(self->private_impl.f_vp8x_alph_flags & 3u)) == 0u) {
|
||||
wuffs_private_impl__io_reader__limited_copy_u32_to_slice(
|
||||
&iop_a_src, io2_a_src,(self->private_impl.f_width * self->private_impl.f_height), a_workbuf);
|
||||
} else if (((uint8_t)(self->private_impl.f_vp8x_alph_flags & 3u)) == 1u) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_webp__decoder__do_decode_frame_vp8l(self,
|
||||
NULL,
|
||||
a_src,
|
||||
wuffs_base__utility__make_pixel_blend(0u),
|
||||
a_workbuf,
|
||||
NULL);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
v_n = ((uint64_t)((self->private_impl.f_width * self->private_impl.f_height * 4u)));
|
||||
if (v_n <= ((uint64_t)(a_workbuf.len))) {
|
||||
wuffs_webp__decoder__compact_alph(self, wuffs_base__slice_u8__subslice_j(a_workbuf, v_n));
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_vp8x_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_vp8x_alph_flags |= 2u;
|
||||
v_n = ((uint64_t)((self->private_impl.f_width * self->private_impl.f_height)));
|
||||
if (v_n <= ((uint64_t)(a_workbuf.len))) {
|
||||
if (((uint8_t)(self->private_impl.f_vp8x_alph_flags & 12u)) == 4u) {
|
||||
wuffs_webp__decoder__filter_alph_horizontal(self, wuffs_base__slice_u8__subslice_j(a_workbuf, v_n));
|
||||
} else if (((uint8_t)(self->private_impl.f_vp8x_alph_flags & 12u)) == 8u) {
|
||||
wuffs_webp__decoder__filter_alph_vertical(self, wuffs_base__slice_u8__subslice_j(a_workbuf, v_n));
|
||||
} else if (((uint8_t)(self->private_impl.f_vp8x_alph_flags & 12u)) == 12u) {
|
||||
wuffs_webp__decoder__filter_alph_gradient(self, wuffs_base__slice_u8__subslice_j(a_workbuf, v_n));
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_alph_limited = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_alph_limited = 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 webp.decoder.compact_alph
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__compact_alph(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_s) {
|
||||
uint64_t v_i = 0;
|
||||
uint64_t v_j = 0;
|
||||
|
||||
if (((uint64_t)(a_s.len)) > 1073741824u) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
v_i = 0u;
|
||||
v_j = 1u;
|
||||
while ((v_i < ((uint64_t)(a_s.len))) && (v_j < ((uint64_t)(a_s.len)))) {
|
||||
a_s.ptr[v_i] = a_s.ptr[v_j];
|
||||
v_i += 1u;
|
||||
v_j += 4u;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func webp.decoder.filter_alph_horizontal
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__filter_alph_horizontal(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_s) {
|
||||
uint32_t v_y = 0;
|
||||
uint32_t v_x = 0;
|
||||
uint64_t v_i = 0;
|
||||
uint8_t v_pred = 0;
|
||||
|
||||
v_y = 0u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
v_pred = 0u;
|
||||
if (v_y > 0u) {
|
||||
v_i = ((uint64_t)(((v_y - 1u) * self->private_impl.f_width)));
|
||||
if (v_i >= ((uint64_t)(a_s.len))) {
|
||||
break;
|
||||
}
|
||||
v_pred = a_s.ptr[v_i];
|
||||
}
|
||||
v_x = 0u;
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
v_i = ((uint64_t)(((v_y * self->private_impl.f_width) + v_x)));
|
||||
if (v_i >= ((uint64_t)(a_s.len))) {
|
||||
break;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#endif
|
||||
a_s.ptr[v_i] += v_pred;
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
v_pred = a_s.ptr[v_i];
|
||||
v_x += 1u;
|
||||
}
|
||||
v_y += 1u;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func webp.decoder.filter_alph_vertical
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__filter_alph_vertical(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_s) {
|
||||
uint32_t v_y = 0;
|
||||
uint32_t v_x = 0;
|
||||
uint64_t v_i = 0;
|
||||
uint8_t v_pred = 0;
|
||||
|
||||
v_x = 0u;
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
v_pred = 0u;
|
||||
if (v_x > 0u) {
|
||||
v_i = ((uint64_t)((v_x - 1u)));
|
||||
if (v_i >= ((uint64_t)(a_s.len))) {
|
||||
break;
|
||||
}
|
||||
v_pred = a_s.ptr[v_i];
|
||||
}
|
||||
v_y = 0u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
v_i = ((uint64_t)(((v_y * self->private_impl.f_width) + v_x)));
|
||||
if (v_i >= ((uint64_t)(a_s.len))) {
|
||||
break;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#endif
|
||||
a_s.ptr[v_i] += v_pred;
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
v_pred = a_s.ptr[v_i];
|
||||
v_y += 1u;
|
||||
}
|
||||
v_x += 1u;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func webp.decoder.filter_alph_gradient
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__filter_alph_gradient(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_s) {
|
||||
uint32_t v_y = 0;
|
||||
uint32_t v_x = 0;
|
||||
uint64_t v_i = 0;
|
||||
uint8_t v_pred = 0;
|
||||
uint32_t v_grad = 0;
|
||||
uint8_t v_l = 0;
|
||||
uint8_t v_t = 0;
|
||||
uint8_t v_tl = 0;
|
||||
|
||||
v_x = 0u;
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
v_i = ((uint64_t)(v_x));
|
||||
if (v_i >= ((uint64_t)(a_s.len))) {
|
||||
break;
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#endif
|
||||
a_s.ptr[v_i] += v_pred;
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
v_pred = a_s.ptr[v_i];
|
||||
v_x += 1u;
|
||||
}
|
||||
v_y = 1u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
v_i = ((uint64_t)(((v_y - 1u) * self->private_impl.f_width)));
|
||||
if (v_i >= ((uint64_t)(a_s.len))) {
|
||||
break;
|
||||
}
|
||||
v_t = a_s.ptr[v_i];
|
||||
v_tl = v_t;
|
||||
v_l = v_t;
|
||||
v_x = 0u;
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
v_i = ((uint64_t)((((v_y - 1u) * self->private_impl.f_width) + v_x)));
|
||||
if (v_i >= ((uint64_t)(a_s.len))) {
|
||||
break;
|
||||
}
|
||||
v_t = a_s.ptr[v_i];
|
||||
v_i = ((uint64_t)(((v_y * self->private_impl.f_width) + v_x)));
|
||||
if (v_i >= ((uint64_t)(a_s.len))) {
|
||||
break;
|
||||
}
|
||||
v_grad = ((uint32_t)(((uint32_t)(((uint32_t)(v_l)) + ((uint32_t)(v_t)))) - ((uint32_t)(v_tl))));
|
||||
if (v_grad > 2147483647u) {
|
||||
v_grad = 0u;
|
||||
} else if (v_grad > 255u) {
|
||||
v_grad = 255u;
|
||||
}
|
||||
v_l = ((uint8_t)(a_s.ptr[v_i] + ((uint8_t)(v_grad))));
|
||||
a_s.ptr[v_i] = v_l;
|
||||
v_tl = v_t;
|
||||
v_x += 1u;
|
||||
}
|
||||
v_y += 1u;
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func webp.decoder.decode_huffman_groups
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -88471,6 +89655,7 @@ static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_predictor(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width,
|
||||
wuffs_base__slice_u8 a_tile_data) {
|
||||
uint64_t v_w4 = 0;
|
||||
wuffs_base__slice_u8 v_prev_row = {0};
|
||||
@@ -88498,10 +89683,10 @@ wuffs_webp__decoder__apply_transform_predictor(
|
||||
uint32_t v_sum_l = 0;
|
||||
uint32_t v_sum_t = 0;
|
||||
|
||||
if ((self->private_impl.f_width <= 0u) || (self->private_impl.f_height <= 0u)) {
|
||||
if ((a_width <= 0u) || (self->private_impl.f_height <= 0u)) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
v_w4 = ((uint64_t)((self->private_impl.f_width * 4u)));
|
||||
v_w4 = ((uint64_t)((a_width * 4u)));
|
||||
v_curr_row = wuffs_base__utility__empty_slice_u8();
|
||||
if (v_w4 <= ((uint64_t)(a_pix.len))) {
|
||||
v_curr_row = wuffs_base__slice_u8__subslice_j(a_pix, v_w4);
|
||||
@@ -88531,7 +89716,7 @@ wuffs_webp__decoder__apply_transform_predictor(
|
||||
v_curr_row = wuffs_base__slice_u8__subslice_i(v_curr_row, 4u);
|
||||
}
|
||||
v_tile_size_log2 = ((uint32_t)(self->private_impl.f_transform_tile_size_log2[0u]));
|
||||
v_tiles_per_row = ((self->private_impl.f_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2);
|
||||
v_tiles_per_row = ((a_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2);
|
||||
v_mask = ((((uint32_t)(1u)) << v_tile_size_log2) - 1u);
|
||||
v_y = 1u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
@@ -88563,7 +89748,7 @@ wuffs_webp__decoder__apply_transform_predictor(
|
||||
#endif
|
||||
}
|
||||
v_x = 1u;
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
while (v_x < a_width) {
|
||||
if (((v_x & v_mask) == 0u) && (((uint64_t)(v_tile_data.len)) >= 4u)) {
|
||||
v_mode = ((uint8_t)(v_tile_data.ptr[1u] & 15u));
|
||||
v_tile_data = wuffs_base__slice_u8__subslice_i(v_tile_data, 4u);
|
||||
@@ -88859,6 +90044,7 @@ static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_cross_color(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width,
|
||||
wuffs_base__slice_u8 a_tile_data) {
|
||||
uint32_t v_tile_size_log2 = 0;
|
||||
uint32_t v_tiles_per_row = 0;
|
||||
@@ -88875,7 +90061,7 @@ wuffs_webp__decoder__apply_transform_cross_color(
|
||||
uint8_t v_r = 0;
|
||||
|
||||
v_tile_size_log2 = ((uint32_t)(self->private_impl.f_transform_tile_size_log2[1u]));
|
||||
v_tiles_per_row = ((self->private_impl.f_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2);
|
||||
v_tiles_per_row = ((a_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2);
|
||||
v_mask = ((((uint32_t)(1u)) << v_tile_size_log2) - 1u);
|
||||
v_y = 0u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
@@ -88885,7 +90071,7 @@ wuffs_webp__decoder__apply_transform_cross_color(
|
||||
v_tile_data = wuffs_base__slice_u8__subslice_i(a_tile_data, v_t);
|
||||
}
|
||||
v_x = 0u;
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
while (v_x < a_width) {
|
||||
if (((v_x & v_mask) == 0u) && (((uint64_t)(v_tile_data.len)) >= 4u)) {
|
||||
v_g2r = wuffs_base__utility__sign_extend_convert_u8_u32(v_tile_data.ptr[0u]);
|
||||
v_g2b = wuffs_base__utility__sign_extend_convert_u8_u32(v_tile_data.ptr[1u]);
|
||||
@@ -88956,7 +90142,8 @@ WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_webp__decoder__apply_transform_color_indexing(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__slice_u8 a_pix) {
|
||||
wuffs_base__slice_u8 a_pix,
|
||||
uint32_t a_width) {
|
||||
uint32_t v_tile_size_log2 = 0;
|
||||
uint32_t v_bits_per_pixel = 0;
|
||||
uint32_t v_x_mask = 0;
|
||||
@@ -89003,8 +90190,8 @@ wuffs_webp__decoder__apply_transform_color_indexing(
|
||||
v_src_index = ((uint64_t)((self->private_impl.f_workbuf_offset_for_color_indexing + 1u)));
|
||||
v_y = 0u;
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
v_di = ((uint64_t)((4u * v_y * self->private_impl.f_width)));
|
||||
v_dj = ((uint64_t)((4u * (v_y + 1u) * self->private_impl.f_width)));
|
||||
v_di = ((uint64_t)((4u * v_y * a_width)));
|
||||
v_dj = ((uint64_t)((4u * (v_y + 1u) * a_width)));
|
||||
if ((v_di > v_dj) || (v_dj > ((uint64_t)(a_pix.len)))) {
|
||||
break;
|
||||
}
|
||||
@@ -89033,866 +90220,11 @@ wuffs_webp__decoder__apply_transform_color_indexing(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func webp.decoder.get_quirk
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_webp__decoder__get_quirk(
|
||||
const wuffs_webp__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 webp.decoder.set_quirk
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_webp__decoder__set_quirk(
|
||||
wuffs_webp__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 webp.decoder.decode_image_config
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_webp__decoder__decode_image_config(
|
||||
wuffs_webp__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_webp__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_webp__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 webp.decoder.do_decode_image_config
|
||||
// -------- func webp.decoder.do_decode_frame_vp8l
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config(
|
||||
wuffs_webp__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;
|
||||
uint64_t v_r_mark = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && 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_c32 = t_0;
|
||||
}
|
||||
if (v_c32 != 1179011410u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__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;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_riff_chunk_length = t_1;
|
||||
}
|
||||
if ((self->private_impl.f_riff_chunk_length & 1u) != 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
const bool o_0_closed_a_src = a_src->meta.closed;
|
||||
const uint8_t* o_0_io2_a_src = io2_a_src;
|
||||
wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_riff_chunk_length)));
|
||||
if (a_src) {
|
||||
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
|
||||
a_src->meta.wi = n;
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_webp__decoder__do_decode_image_config_limited(self, a_dst, a_src);
|
||||
v_status = t_2;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_riff_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.closed = o_0_closed_a_src;
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&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;
|
||||
} else if ((v_status.repr == wuffs_base__suspension__short_read) && (self->private_impl.f_riff_chunk_length == 0u)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__short_chunk);
|
||||
goto exit;
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
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)));
|
||||
if ( ! self->private_impl.f_is_vp8_lossy && (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,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
false);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 32u;
|
||||
|
||||
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 webp.decoder.do_decode_image_config_limited
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited(
|
||||
wuffs_webp__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;
|
||||
uint64_t v_r_mark = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && 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_limited;
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint32_t t_0;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_do_decode_image_config_limited.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_limited.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 != 1346520407u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__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_limited.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_limited.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 == 540561494u) {
|
||||
self->private_impl.f_is_vp8_lossy = true;
|
||||
} else if (v_c32 == 1278758998u) {
|
||||
} else if (v_c32 == 1480085590u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__unsupported_webp_file);
|
||||
goto exit;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
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_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_do_decode_image_config_limited.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_limited.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 == 24) {
|
||||
t_2 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_2 += 8u;
|
||||
*scratch |= ((uint64_t)(num_bits_2)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_sub_chunk_length = t_2;
|
||||
}
|
||||
if (self->private_impl.f_sub_chunk_length < 4u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_sub_chunk_has_padding = ((self->private_impl.f_sub_chunk_length & 1u) != 0u);
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
wuffs_vp8__decoder__set_quirk(&self->private_data.f_vp8, 3u, ((((uint64_t)(self->private_impl.f_sub_chunk_length)) << 1u) | 1u));
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
const bool o_0_closed_a_src = a_src->meta.closed;
|
||||
const uint8_t* o_0_io2_a_src = io2_a_src;
|
||||
wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_sub_chunk_length)));
|
||||
if (a_src) {
|
||||
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
|
||||
a_src->meta.wi = n;
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_3 = wuffs_vp8__decoder__decode_image_config(&self->private_data.f_vp8, a_dst, a_src);
|
||||
v_status = t_3;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_4 = wuffs_webp__decoder__do_decode_image_config_limited_vp8l(self, a_src);
|
||||
v_status = t_4;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
}
|
||||
wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_sub_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.closed = o_0_closed_a_src;
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&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;
|
||||
} else if ((v_status.repr == wuffs_base__suspension__short_read) && (self->private_impl.f_sub_chunk_length == 0u)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__short_chunk);
|
||||
goto exit;
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
}
|
||||
|
||||
ok:
|
||||
self->private_impl.p_do_decode_image_config_limited = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_do_decode_image_config_limited = 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 webp.decoder.do_decode_image_config_limited_vp8l
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited_vp8l(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_c32 = 0;
|
||||
uint32_t v_transform_size = 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_limited_vp8l;
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
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;
|
||||
}
|
||||
uint32_t t_0 = *iop_a_src++;
|
||||
v_c32 = t_0;
|
||||
}
|
||||
if (v_c32 != 47u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
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_limited_vp8l.scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_do_decode_image_config_limited_vp8l.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;
|
||||
}
|
||||
self->private_impl.f_width = ((v_c32 & 16383u) + 1u);
|
||||
v_c32 >>= 14u;
|
||||
self->private_impl.f_height = ((v_c32 & 16383u) + 1u);
|
||||
v_c32 >>= 14u;
|
||||
self->private_impl.f_pixfmt = 2415954056u;
|
||||
if ((v_c32 & 1u) != 0u) {
|
||||
self->private_impl.f_pixfmt = 2164295816u;
|
||||
}
|
||||
v_c32 >>= 1u;
|
||||
if (v_c32 != 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
v_transform_size = (4u * ((self->private_impl.f_width + 3u) >> 2u) * ((self->private_impl.f_height + 3u) >> 2u));
|
||||
self->private_impl.f_workbuf_offset_for_transform[0u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + 0u);
|
||||
self->private_impl.f_workbuf_offset_for_transform[1u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + v_transform_size);
|
||||
self->private_impl.f_workbuf_offset_for_transform[2u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + (2u * v_transform_size));
|
||||
self->private_impl.f_workbuf_offset_for_transform[3u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + (3u * v_transform_size));
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_do_decode_image_config_limited_vp8l = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_do_decode_image_config_limited_vp8l = 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 webp.decoder.decode_frame_config
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_webp__decoder__decode_frame_config(
|
||||
wuffs_webp__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) {
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
{
|
||||
wuffs_base__status t_0 = wuffs_vp8__decoder__decode_frame_config(&self->private_data.f_vp8, a_dst, a_src);
|
||||
v_status = t_0;
|
||||
}
|
||||
} else {
|
||||
{
|
||||
wuffs_base__status t_1 = wuffs_webp__decoder__do_decode_frame_config(self, a_dst, a_src);
|
||||
v_status = t_1;
|
||||
}
|
||||
}
|
||||
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__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 webp.decoder.do_decode_frame_config
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_frame_config(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
wuffs_base__pixel_format v_pixfmt = {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_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_webp__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 (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) {
|
||||
v_pixfmt = wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt);
|
||||
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,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
0u,
|
||||
false,
|
||||
false,
|
||||
wuffs_base__pixel_format__default_background_color(&v_pixfmt));
|
||||
}
|
||||
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 webp.decoder.decode_frame
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_webp__decoder__decode_frame(
|
||||
wuffs_webp__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) {
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
{
|
||||
wuffs_base__status t_0 = wuffs_vp8__decoder__decode_frame(&self->private_data.f_vp8,
|
||||
a_dst,
|
||||
a_src,
|
||||
a_blend,
|
||||
a_workbuf,
|
||||
a_opts);
|
||||
v_status = t_0;
|
||||
}
|
||||
} else {
|
||||
{
|
||||
wuffs_base__status t_1 = wuffs_webp__decoder__do_decode_frame(self,
|
||||
a_dst,
|
||||
a_src,
|
||||
a_blend,
|
||||
a_workbuf,
|
||||
a_opts);
|
||||
v_status = t_1;
|
||||
}
|
||||
}
|
||||
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__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 webp.decoder.do_decode_frame
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_frame(
|
||||
wuffs_webp__decoder__do_decode_frame_vp8l(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
@@ -89924,30 +90256,13 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame;
|
||||
uint32_t coro_susp_point = self->private_impl.p_do_decode_frame_vp8l;
|
||||
if (coro_susp_point) {
|
||||
v_width = self->private_data.s_do_decode_frame.v_width;
|
||||
v_width = self->private_data.s_do_decode_frame_vp8l.v_width;
|
||||
}
|
||||
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_webp__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;
|
||||
}
|
||||
self->private_impl.f_seen_transform[0u] = false;
|
||||
self->private_impl.f_seen_transform[1u] = false;
|
||||
self->private_impl.f_seen_transform[2u] = false;
|
||||
@@ -89956,7 +90271,7 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
while (true) {
|
||||
if (self->private_impl.f_n_bits < 1u) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
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;
|
||||
@@ -89976,7 +90291,7 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_webp__decoder__decode_transform(self, a_src, a_workbuf);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -89992,7 +90307,7 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_webp__decoder__decode_color_cache_parameters(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -90004,7 +90319,7 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
status = wuffs_webp__decoder__decode_hg_table(self, a_src, v_width, a_workbuf);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -90016,7 +90331,7 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_webp__decoder__decode_huffman_groups(self, a_src, self->private_impl.f_overall_n_huffman_groups);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -90025,10 +90340,7 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
goto suspend;
|
||||
}
|
||||
while (true) {
|
||||
if ((((uint64_t)(self->private_impl.f_workbuf_offset_for_color_indexing)) > ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u]))) ||
|
||||
(((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])) > ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[1u]))) ||
|
||||
(((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[1u])) > ((uint64_t)(a_workbuf.len))) ||
|
||||
(((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])) > ((uint64_t)(a_workbuf.len)))) {
|
||||
if ((((uint64_t)(self->private_impl.f_workbuf_offset_for_color_indexing)) > ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u]))) || (((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])) > ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[1u]))) || (((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[1u])) > ((uint64_t)(a_workbuf.len)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
|
||||
goto exit;
|
||||
}
|
||||
@@ -90058,13 +90370,18 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
break;
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
if (((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])) > ((uint64_t)(a_workbuf.len))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
|
||||
goto exit;
|
||||
}
|
||||
v_pix = wuffs_base__slice_u8__subslice_j(a_workbuf, ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])));
|
||||
v_width = self->private_impl.f_width;
|
||||
if (self->private_impl.f_seen_transform[3u] && (((uint64_t)(self->private_impl.f_workbuf_offset_for_color_indexing)) <= ((uint64_t)(v_pix.len)))) {
|
||||
v_pix = wuffs_base__slice_u8__subslice_i(v_pix, ((uint64_t)(self->private_impl.f_workbuf_offset_for_color_indexing)));
|
||||
v_width = self->private_impl.f_color_indexing_width;
|
||||
}
|
||||
v_which = self->private_impl.f_n_transforms;
|
||||
while (v_which > 0u) {
|
||||
v_which -= 1u;
|
||||
@@ -90078,14 +90395,15 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
}
|
||||
}
|
||||
if (v_transform_type == 0u) {
|
||||
wuffs_webp__decoder__apply_transform_predictor(self, v_pix, v_tile_data);
|
||||
wuffs_webp__decoder__apply_transform_predictor(self, v_pix, v_width, v_tile_data);
|
||||
} else if (v_transform_type == 1u) {
|
||||
wuffs_webp__decoder__apply_transform_cross_color(self, v_pix, v_tile_data);
|
||||
wuffs_webp__decoder__apply_transform_cross_color(self, v_pix, v_width, v_tile_data);
|
||||
} else if (v_transform_type == 2u) {
|
||||
wuffs_webp__decoder__apply_transform_subtract_green(self, v_pix);
|
||||
} else {
|
||||
wuffs_webp__decoder__apply_transform_color_indexing(self, v_pix);
|
||||
} else if (((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])) <= ((uint64_t)(a_workbuf.len))) {
|
||||
v_pix = wuffs_base__slice_u8__subslice_j(a_workbuf, ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[0u])));
|
||||
v_width = self->private_impl.f_width;
|
||||
wuffs_webp__decoder__apply_transform_color_indexing(self, v_pix, v_width);
|
||||
}
|
||||
}
|
||||
v_status = wuffs_webp__decoder__swizzle(self, a_dst, v_pix, a_blend);
|
||||
@@ -90102,14 +90420,14 @@ wuffs_webp__decoder__do_decode_frame(
|
||||
self->private_impl.f_call_sequence = 96u;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_do_decode_frame = 0;
|
||||
self->private_impl.p_do_decode_frame_vp8l = 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_width = v_width;
|
||||
self->private_impl.p_do_decode_frame_vp8l = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_data.s_do_decode_frame_vp8l.v_width = v_width;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -90134,6 +90452,7 @@ wuffs_webp__decoder__decode_transform(
|
||||
uint8_t v_c8 = 0;
|
||||
uint32_t v_transform_type = 0;
|
||||
uint32_t v_tile_size_log2 = 0;
|
||||
uint32_t v_width = 0;
|
||||
wuffs_base__slice_u8 v_p = {0};
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
@@ -90178,9 +90497,6 @@ wuffs_webp__decoder__decode_transform(
|
||||
if (self->private_impl.f_seen_transform[v_transform_type] || (self->private_impl.f_n_transforms >= 4u)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_transform);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_seen_transform[3u]) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__unsupported_transform_after_color_indexing_transform);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_seen_transform[v_transform_type] = true;
|
||||
self->private_impl.f_transform_type[self->private_impl.f_n_transforms] = ((uint8_t)(v_transform_type));
|
||||
@@ -90230,6 +90546,10 @@ wuffs_webp__decoder__decode_transform(
|
||||
goto suspend;
|
||||
}
|
||||
while (true) {
|
||||
v_width = self->private_impl.f_width;
|
||||
if (self->private_impl.f_seen_transform[3u]) {
|
||||
v_width = self->private_impl.f_color_indexing_width;
|
||||
}
|
||||
if ((((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[(v_transform_type + 1u)])) > ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[(v_transform_type + 2u)]))) || (((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[(v_transform_type + 2u)])) > ((uint64_t)(a_workbuf.len)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length);
|
||||
goto exit;
|
||||
@@ -90243,7 +90563,7 @@ wuffs_webp__decoder__decode_transform(
|
||||
((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[(v_transform_type + 1u)])),
|
||||
((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[(v_transform_type + 2u)]))),
|
||||
a_src,
|
||||
((self->private_impl.f_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2),
|
||||
((v_width + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2),
|
||||
((self->private_impl.f_height + ((((uint32_t)(1u)) << v_tile_size_log2) - 1u)) >> v_tile_size_log2),
|
||||
wuffs_base__utility__empty_slice_u8(),
|
||||
0u);
|
||||
@@ -90729,10 +91049,13 @@ wuffs_webp__decoder__swizzle(
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint32_t v_y = 0;
|
||||
|
||||
if (a_dst == NULL) {
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
|
||||
wuffs_base__pixel_buffer__pixel_format(a_dst),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_palette, 1024)),
|
||||
wuffs_base__utility__make_pixel_format(self->private_impl.f_pixfmt),
|
||||
wuffs_base__utility__make_pixel_format(2164295816u),
|
||||
wuffs_base__utility__empty_slice_u8(),
|
||||
a_blend);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
@@ -90760,6 +91083,1308 @@ wuffs_webp__decoder__swizzle(
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// -------- func webp.decoder.get_quirk
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_webp__decoder__get_quirk(
|
||||
const wuffs_webp__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 webp.decoder.set_quirk
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_webp__decoder__set_quirk(
|
||||
wuffs_webp__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 webp.decoder.decode_image_config
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_webp__decoder__decode_image_config(
|
||||
wuffs_webp__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_webp__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_webp__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 webp.decoder.do_decode_image_config
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config(
|
||||
wuffs_webp__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;
|
||||
uint64_t v_r_mark = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && 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_c32 = t_0;
|
||||
}
|
||||
if (v_c32 != 1179011410u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__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;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_riff_chunk_length = t_1;
|
||||
}
|
||||
if ((self->private_impl.f_riff_chunk_length & 1u) != 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_rcl_remaining = self->private_impl.f_riff_chunk_length;
|
||||
while (true) {
|
||||
{
|
||||
const bool o_0_closed_a_src = a_src->meta.closed;
|
||||
const uint8_t* o_0_io2_a_src = io2_a_src;
|
||||
wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_rcl_remaining)));
|
||||
if (a_src) {
|
||||
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
|
||||
a_src->meta.wi = n;
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_webp__decoder__do_decode_image_config_limited(self, a_dst, a_src);
|
||||
v_status = t_2;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_rcl_remaining, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.closed = o_0_closed_a_src;
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&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;
|
||||
} else if ((v_status.repr == wuffs_base__suspension__short_read) && (self->private_impl.f_rcl_remaining == 0u)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__short_chunk);
|
||||
goto exit;
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
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)));
|
||||
if ((self->private_impl.f_variant != 1u) && (a_dst != NULL)) {
|
||||
wuffs_base__image_config__set(
|
||||
a_dst,
|
||||
2164295816u,
|
||||
0u,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
false);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 32u;
|
||||
|
||||
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 webp.decoder.do_decode_image_config_limited
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited(
|
||||
wuffs_webp__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;
|
||||
uint64_t v_r_mark = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && 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_limited;
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint32_t t_0;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_do_decode_image_config_limited.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_limited.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 != 1346520407u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__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_limited.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_limited.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 == 540561494u) {
|
||||
self->private_impl.f_variant = 1u;
|
||||
} else if (v_c32 == 1278758998u) {
|
||||
self->private_impl.f_variant = 2u;
|
||||
} else if (v_c32 == 1480085590u) {
|
||||
self->private_impl.f_variant = 4u;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
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_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_do_decode_image_config_limited.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_limited.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 == 24) {
|
||||
t_2 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_2 += 8u;
|
||||
*scratch |= ((uint64_t)(num_bits_2)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_sub_chunk_length = t_2;
|
||||
}
|
||||
self->private_impl.f_sub_chunk_has_padding = ((self->private_impl.f_sub_chunk_length & 1u) != 0u);
|
||||
if (self->private_impl.f_variant == 1u) {
|
||||
wuffs_vp8__decoder__set_quirk(&self->private_data.f_vp8, 3u, ((((uint64_t)(self->private_impl.f_sub_chunk_length)) << 1u) | 1u));
|
||||
} else if (self->private_impl.f_variant == 2u) {
|
||||
} else if (self->private_impl.f_sub_chunk_length != 10u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
const bool o_0_closed_a_src = a_src->meta.closed;
|
||||
const uint8_t* o_0_io2_a_src = io2_a_src;
|
||||
wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_sub_chunk_length)));
|
||||
if (a_src) {
|
||||
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
|
||||
a_src->meta.wi = n;
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
if (self->private_impl.f_variant == 1u) {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_3 = wuffs_vp8__decoder__decode_image_config(&self->private_data.f_vp8, a_dst, a_src);
|
||||
v_status = t_3;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
} else if (self->private_impl.f_variant == 2u) {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_4 = wuffs_webp__decoder__do_decode_image_config_limited_vp8l(self, a_src);
|
||||
v_status = t_4;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_5 = wuffs_webp__decoder__do_decode_image_config_limited_vp8x(self, a_src);
|
||||
v_status = t_5;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
}
|
||||
wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_sub_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.closed = o_0_closed_a_src;
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&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;
|
||||
} else if ((v_status.repr == wuffs_base__suspension__short_read) && (self->private_impl.f_sub_chunk_length == 0u)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__short_chunk);
|
||||
goto exit;
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
}
|
||||
|
||||
ok:
|
||||
self->private_impl.p_do_decode_image_config_limited = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_do_decode_image_config_limited = 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 webp.decoder.do_decode_image_config_limited_vp8l
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited_vp8l(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_c32 = 0;
|
||||
uint32_t v_transform_size = 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_limited_vp8l;
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
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;
|
||||
}
|
||||
uint32_t t_0 = *iop_a_src++;
|
||||
v_c32 = t_0;
|
||||
}
|
||||
if (v_c32 != 47u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
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_limited_vp8l.scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_do_decode_image_config_limited_vp8l.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;
|
||||
}
|
||||
self->private_impl.f_width = ((v_c32 & 16383u) + 1u);
|
||||
v_c32 >>= 14u;
|
||||
self->private_impl.f_height = ((v_c32 & 16383u) + 1u);
|
||||
v_c32 >>= 14u;
|
||||
v_c32 >>= 1u;
|
||||
if (v_c32 != 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
v_transform_size = (4u * ((self->private_impl.f_width + 3u) >> 2u) * ((self->private_impl.f_height + 3u) >> 2u));
|
||||
self->private_impl.f_workbuf_offset_for_transform[0u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + 0u);
|
||||
self->private_impl.f_workbuf_offset_for_transform[1u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + v_transform_size);
|
||||
self->private_impl.f_workbuf_offset_for_transform[2u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + (2u * v_transform_size));
|
||||
self->private_impl.f_workbuf_offset_for_transform[3u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + (3u * v_transform_size));
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_do_decode_image_config_limited_vp8l = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_do_decode_image_config_limited_vp8l = 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 webp.decoder.do_decode_image_config_limited_vp8x
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_image_config_limited_vp8x(
|
||||
wuffs_webp__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_c32 = 0;
|
||||
uint32_t v_transform_size = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && 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_limited_vp8x;
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint32_t t_0;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_do_decode_image_config_limited_vp8x.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_limited_vp8x.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 & 4294967233u) != 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__unsupported_webp_file);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_vp8x_header_flags = ((uint8_t)((v_c32 | 1u)));
|
||||
{
|
||||
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_limited_vp8x.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_limited_vp8x.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;
|
||||
}
|
||||
if (v_c32 >= 16383u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__unsupported_webp_file);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_width = ((v_c32 & 16383u) + 1u);
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
uint32_t t_2;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
|
||||
t_2 = ((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_limited_vp8x.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_limited_vp8x.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 == 16) {
|
||||
t_2 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_2 += 8u;
|
||||
*scratch |= ((uint64_t)(num_bits_2)) << 56;
|
||||
}
|
||||
}
|
||||
v_c32 = t_2;
|
||||
}
|
||||
if (v_c32 >= 16383u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__unsupported_webp_file);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_height = ((v_c32 & 16383u) + 1u);
|
||||
v_transform_size = (4u * ((self->private_impl.f_width + 3u) >> 2u) * ((self->private_impl.f_height + 3u) >> 2u));
|
||||
self->private_impl.f_workbuf_offset_for_transform[0u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + 0u);
|
||||
self->private_impl.f_workbuf_offset_for_transform[1u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + v_transform_size);
|
||||
self->private_impl.f_workbuf_offset_for_transform[2u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + (2u * v_transform_size));
|
||||
self->private_impl.f_workbuf_offset_for_transform[3u] = ((4u * self->private_impl.f_width * self->private_impl.f_height) + (3u * v_transform_size));
|
||||
v_status = wuffs_vp8__decoder__set_quirk(&self->private_data.f_vp8, 3u, ((((uint64_t)(self->private_impl.f_riff_chunk_length)) << 1u) | 1u));
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__unsupported_webp_file);
|
||||
goto exit;
|
||||
}
|
||||
v_status = wuffs_vp8__decoder__set_quirk(&self->private_data.f_vp8, 1836840961u, (((uint64_t)(self->private_impl.f_width)) | (((uint64_t)(self->private_impl.f_height)) << 32u)));
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__unsupported_webp_file);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_do_decode_image_config_limited_vp8x = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_do_decode_image_config_limited_vp8x = 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 webp.decoder.decode_frame_config
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_webp__decoder__decode_frame_config(
|
||||
wuffs_webp__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) {
|
||||
if (self->private_impl.f_variant == 1u) {
|
||||
{
|
||||
wuffs_base__status t_0 = wuffs_vp8__decoder__decode_frame_config(&self->private_data.f_vp8, a_dst, a_src);
|
||||
v_status = t_0;
|
||||
}
|
||||
} else {
|
||||
{
|
||||
wuffs_base__status t_1 = wuffs_webp__decoder__do_decode_frame_config(self, a_dst, a_src);
|
||||
v_status = t_1;
|
||||
}
|
||||
}
|
||||
if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__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 webp.decoder.do_decode_frame_config
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_frame_config(
|
||||
wuffs_webp__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_webp__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 (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 ((self->private_impl.f_variant != 1u) && (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,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
0u,
|
||||
false,
|
||||
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 webp.decoder.decode_frame
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_webp__decoder__decode_frame(
|
||||
wuffs_webp__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_webp__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_webp__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 webp.decoder.do_decode_frame
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
static wuffs_base__status
|
||||
wuffs_webp__decoder__do_decode_frame(
|
||||
wuffs_webp__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);
|
||||
|
||||
uint64_t v_r_mark = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src && 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_webp__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;
|
||||
}
|
||||
while (((uint8_t)(self->private_impl.f_variant & 3u)) == 0u) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
uint32_t t_0;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_0 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_do_decode_frame.scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_do_decode_frame.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;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_sub_chunk_type = t_0;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
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_frame.scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_do_decode_frame.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;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_sub_chunk_length = t_1;
|
||||
}
|
||||
self->private_impl.f_sub_chunk_has_padding = ((self->private_impl.f_sub_chunk_length & 1u) != 0u);
|
||||
if (self->private_impl.f_sub_chunk_length > 2147483647u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__unsupported_webp_file);
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_sub_chunk_type == 1346585417u) {
|
||||
if (self->private_impl.f_variant > 4u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_chunk_order);
|
||||
goto exit;
|
||||
} else if (((uint8_t)(self->private_impl.f_vp8x_header_flags & 32u)) == 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_vp8x_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_variant = 8u;
|
||||
} else if (self->private_impl.f_sub_chunk_type == 1296649793u) {
|
||||
if (self->private_impl.f_variant > 8u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_chunk_order);
|
||||
goto exit;
|
||||
} else if (((uint8_t)(self->private_impl.f_vp8x_header_flags & 2u)) == 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_vp8x_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_variant = 16u;
|
||||
} else if (self->private_impl.f_sub_chunk_type == 1179471425u) {
|
||||
if (self->private_impl.f_variant > 16u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_chunk_order);
|
||||
goto exit;
|
||||
} else if (((uint8_t)(self->private_impl.f_vp8x_header_flags & 2u)) == 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_vp8x_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_variant = 32u;
|
||||
} else if (self->private_impl.f_sub_chunk_type == 1213221953u) {
|
||||
if (self->private_impl.f_variant > 32u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_chunk_order);
|
||||
goto exit;
|
||||
} else if (((uint8_t)(self->private_impl.f_vp8x_header_flags & 16u)) == 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_vp8x_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_variant = 64u;
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_webp__decoder__decode_alph(self, a_src, a_workbuf);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
wuffs_vp8__decoder__set_quirk(&self->private_data.f_vp8, 1836840960u, 1u);
|
||||
} else if (self->private_impl.f_sub_chunk_type == 540561494u) {
|
||||
wuffs_vp8__decoder__set_quirk(&self->private_data.f_vp8, 3u, ((((uint64_t)(self->private_impl.f_sub_chunk_length)) << 1u) | 1u));
|
||||
self->private_impl.f_variant = 129u;
|
||||
break;
|
||||
} else if (self->private_impl.f_sub_chunk_type == 1278758998u) {
|
||||
if (((uint8_t)(self->private_impl.f_vp8x_header_flags & 16u)) != 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_alph_vp8l_combination);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_variant = 130u;
|
||||
break;
|
||||
} else if (self->private_impl.f_sub_chunk_type == 542133592u) {
|
||||
if (((uint8_t)(self->private_impl.f_vp8x_header_flags & 4u)) == 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_vp8x_chunk);
|
||||
goto exit;
|
||||
}
|
||||
} else if (self->private_impl.f_sub_chunk_type == 1179211845u) {
|
||||
if (((uint8_t)(self->private_impl.f_vp8x_header_flags & 8u)) == 0u) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__bad_vp8x_chunk);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
self->private_data.s_do_decode_frame.scratch = self->private_impl.f_sub_chunk_length;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
if (self->private_data.s_do_decode_frame.scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_do_decode_frame.scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_do_decode_frame.scratch;
|
||||
if (self->private_impl.f_sub_chunk_has_padding) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
const bool o_0_closed_a_src = a_src->meta.closed;
|
||||
const uint8_t* o_0_io2_a_src = io2_a_src;
|
||||
wuffs_private_impl__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_sub_chunk_length)));
|
||||
if (a_src) {
|
||||
size_t n = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.closed = a_src->meta.closed && (a_src->meta.wi <= n);
|
||||
a_src->meta.wi = n;
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
if (((uint8_t)(self->private_impl.f_variant & 1u)) != 0u) {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_vp8__decoder__decode_frame(&self->private_data.f_vp8,
|
||||
a_dst,
|
||||
a_src,
|
||||
a_blend,
|
||||
a_workbuf,
|
||||
a_opts);
|
||||
v_status = t_2;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
{
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_3 = wuffs_webp__decoder__do_decode_frame_vp8l(self,
|
||||
a_dst,
|
||||
a_src,
|
||||
a_blend,
|
||||
a_workbuf,
|
||||
a_opts);
|
||||
v_status = t_3;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
}
|
||||
wuffs_private_impl__u32__sat_sub_indirect(&self->private_impl.f_sub_chunk_length, ((uint32_t)(wuffs_private_impl__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.closed = o_0_closed_a_src;
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&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;
|
||||
} else if ((v_status.repr == wuffs_base__suspension__short_read) && (self->private_impl.f_sub_chunk_length == 0u)) {
|
||||
status = wuffs_base__make_status(wuffs_webp__error__short_chunk);
|
||||
goto exit;
|
||||
}
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
}
|
||||
|
||||
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 webp.decoder.frame_dirty_rect
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
@@ -90774,7 +92399,7 @@ wuffs_webp__decoder__frame_dirty_rect(
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
if (self->private_impl.f_variant == 1u) {
|
||||
return wuffs_vp8__decoder__frame_dirty_rect(&self->private_data.f_vp8);
|
||||
}
|
||||
return wuffs_base__utility__make_rect_ie_u32(
|
||||
@@ -90815,7 +92440,7 @@ wuffs_webp__decoder__num_decoded_frame_configs(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
if (self->private_impl.f_variant == 1u) {
|
||||
return wuffs_vp8__decoder__num_decoded_frame_configs(&self->private_data.f_vp8);
|
||||
}
|
||||
if (self->private_impl.f_call_sequence > 32u) {
|
||||
@@ -90838,7 +92463,7 @@ wuffs_webp__decoder__num_decoded_frames(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
if (self->private_impl.f_variant == 1u) {
|
||||
return wuffs_vp8__decoder__num_decoded_frames(&self->private_data.f_vp8);
|
||||
}
|
||||
if (self->private_impl.f_call_sequence > 64u) {
|
||||
@@ -90867,7 +92492,7 @@ wuffs_webp__decoder__restart_frame(
|
||||
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
if (self->private_impl.f_variant == 1u) {
|
||||
v_status = wuffs_vp8__decoder__restart_frame(&self->private_data.f_vp8, a_index, a_io_position);
|
||||
return wuffs_private_impl__status__ensure_not_a_suspension(v_status);
|
||||
}
|
||||
@@ -90949,10 +92574,21 @@ wuffs_webp__decoder__workbuf_len(
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
|
||||
if (self->private_impl.f_is_vp8_lossy) {
|
||||
wuffs_base__range_ii_u64 v_r = {0};
|
||||
wuffs_base__range_ii_u64 v_s = {0};
|
||||
|
||||
if (self->private_impl.f_variant == 1u) {
|
||||
return wuffs_vp8__decoder__workbuf_len(&self->private_data.f_vp8);
|
||||
}
|
||||
return wuffs_base__utility__make_range_ii_u64(((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[3u])), ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[3u])));
|
||||
v_r = wuffs_base__utility__make_range_ii_u64(((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[3u])), ((uint64_t)(self->private_impl.f_workbuf_offset_for_transform[3u])));
|
||||
if (self->private_impl.f_variant != 2u) {
|
||||
v_s = wuffs_vp8__decoder__workbuf_len(&self->private_data.f_vp8);
|
||||
if (wuffs_base__range_ii_u64__is_empty(&v_s)) {
|
||||
return v_s;
|
||||
}
|
||||
v_r = wuffs_base__utility__make_range_ii_u64(wuffs_base__u64__max(wuffs_private_impl__range_ii_u64__get_min_incl(&v_s), wuffs_private_impl__range_ii_u64__get_min_incl(&v_r)), wuffs_base__u64__max(wuffs_private_impl__range_ii_u64__get_max_incl(&v_s), wuffs_private_impl__range_ii_u64__get_max_incl(&v_r)));
|
||||
}
|
||||
return v_r;
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WEBP)
|
||||
@@ -95507,8 +97143,9 @@ redirect:
|
||||
}
|
||||
wuffs_base__pixel_buffer pixel_buffer = alloc_pixbuf_result.pixbuf;
|
||||
if (valid_background_color) {
|
||||
wuffs_base__status pb_scufr_status = pixel_buffer.set_color_u32_fill_rect(
|
||||
pixel_buffer.pixcfg.bounds(), background_color);
|
||||
wuffs_base__status pb_scufr_status =
|
||||
pixel_buffer.set_color_u32_argb_premul_fill_rect(
|
||||
pixel_buffer.pixcfg.bounds(), background_color);
|
||||
if (pb_scufr_status.repr != nullptr) {
|
||||
return DecodeImageResult(pb_scufr_status.message());
|
||||
}
|
||||
@@ -95517,6 +97154,9 @@ redirect:
|
||||
// Allocate the work buffer. Wuffs' decoders conventionally assume that this
|
||||
// can be uninitialized memory.
|
||||
wuffs_base__range_ii_u64 workbuf_len = image_decoder->workbuf_len();
|
||||
if (workbuf_len.is_empty()) {
|
||||
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
|
||||
}
|
||||
DecodeImageCallbacks::AllocWorkbufResult alloc_workbuf_result =
|
||||
callbacks.AllocWorkbuf(workbuf_len, true);
|
||||
if (!alloc_workbuf_result.error_message.empty()) {
|
||||
@@ -96457,7 +98097,12 @@ wuffs_drop_in__stb__load1( //
|
||||
}
|
||||
|
||||
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;
|
||||
wuffs_base__range_ii_u64 r = wuffs_base__image_decoder__workbuf_len(dec);
|
||||
if (wuffs_base__range_ii_u64__is_empty(&r)) {
|
||||
wuffs_drop_in__stb__g_failure_reason = "indeterminate workbuf length";
|
||||
return NULL;
|
||||
}
|
||||
uint64_t workbuf_len = r.max_incl;
|
||||
#if SIZE_MAX < 0xFFFFFFFFFFFFFFFFull
|
||||
if ((pixbuf_len > ((uint64_t)SIZE_MAX)) ||
|
||||
(workbuf_len > ((uint64_t)SIZE_MAX))) {
|
||||
|
||||
+29
-12
@@ -60,18 +60,35 @@ func main1() error {
|
||||
}
|
||||
|
||||
} else if len(arg) == 12 {
|
||||
// Assume that arg is of the form "aaaa/bbbb/cc".
|
||||
arg0 := arg[0:4]
|
||||
arg1 := arg[5:9]
|
||||
arg2 := ".." + arg[10:12]
|
||||
c0, ok0 := base38.Encode(arg0)
|
||||
c1, ok1 := base38.Encode(arg1)
|
||||
c2, ok2 := base38.Encode(arg2)
|
||||
if ok0 && ok1 && ok2 {
|
||||
c := (uint64(c0) << 32) | (uint64(c1) << 11) | uint64(c2)
|
||||
code := fmt.Sprintf("0x%014X", c)
|
||||
fmt.Printf("%s\t%16d\t%s\n", underscore8(code), c, arg)
|
||||
continue
|
||||
if (arg[4] == '/') && (arg[7] == '/') {
|
||||
// Assume that arg is of the form "aaaa/bb/cccc".
|
||||
arg0 := arg[0:4]
|
||||
arg1 := ".." + arg[5:7]
|
||||
arg2 := arg[8:12]
|
||||
c0, ok0 := base38.Encode(arg0)
|
||||
c1, ok1 := base38.Encode(arg1)
|
||||
c2, ok2 := base38.Encode(arg2)
|
||||
if ok0 && ok1 && ok2 {
|
||||
c := (uint64(c0) << 32) | (uint64(c1) << 21) | uint64(c2)
|
||||
code := fmt.Sprintf("0x%014X", c)
|
||||
fmt.Printf("%s\t%16d\t%s\n", underscore8(code), c, arg)
|
||||
continue
|
||||
}
|
||||
|
||||
} else if (arg[4] == '/') && (arg[9] == '/') {
|
||||
// Assume that arg is of the form "aaaa/bbbb/cc".
|
||||
arg0 := arg[0:4]
|
||||
arg1 := arg[5:9]
|
||||
arg2 := ".." + arg[10:12]
|
||||
c0, ok0 := base38.Encode(arg0)
|
||||
c1, ok1 := base38.Encode(arg1)
|
||||
c2, ok2 := base38.Encode(arg2)
|
||||
if ok0 && ok1 && ok2 {
|
||||
c := (uint64(c0) << 32) | (uint64(c1) << 11) | uint64(c2)
|
||||
code := fmt.Sprintf("0x%014X", c)
|
||||
fmt.Printf("%s\t%16d\t%s\n", underscore8(code), c, arg)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
} else if len(arg) == 14 {
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// Copyright 2026 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-png-chunks.go prints a PNG's chunks' position and type.
|
||||
//
|
||||
// Usage: go run print-png-chunks.go foo.png
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := main1(); err != nil {
|
||||
os.Stderr.WriteString(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
if len(args) != 1 {
|
||||
return fmt.Errorf("usage: progname filename.png")
|
||||
}
|
||||
src, err := os.ReadFile(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pos := 0
|
||||
if len(src) < 8 {
|
||||
return posError(pos, len(src))
|
||||
} else if len(src) > 0x7FFF_FFFF {
|
||||
return fmt.Errorf("PNG file is too large")
|
||||
}
|
||||
|
||||
pos = 8
|
||||
for pos < len(src) {
|
||||
if pos > (len(src) - 8) {
|
||||
return posError(pos, len(src))
|
||||
}
|
||||
|
||||
pos0 := pos
|
||||
n := int64(u32be(src[pos : pos+4]))
|
||||
name := clean(src[pos+4 : pos+8])
|
||||
pos += 8
|
||||
|
||||
if int64(len(src)-pos) < n {
|
||||
return posError(pos, len(src))
|
||||
}
|
||||
checksumHave := crc32.ChecksumIEEE(src[pos-4 : pos+int(n)])
|
||||
pos += int(n)
|
||||
|
||||
if int64(len(src)-pos) < 4 {
|
||||
return posError(pos, len(src))
|
||||
}
|
||||
checksumWant := u32be(src[pos : pos+4])
|
||||
pos += 4
|
||||
|
||||
badChecksum := ""
|
||||
if checksumHave != checksumWant {
|
||||
badChecksum = " (bad crc32)"
|
||||
}
|
||||
fmt.Printf("pos: 0x%08X %10d +8, len: 0x%08X %10d +4, %s%s\n",
|
||||
pos0, pos0, n, n, name, badChecksum)
|
||||
}
|
||||
|
||||
fmt.Printf("pos: 0x%08X %10d ~~~~\n",
|
||||
pos, pos)
|
||||
return nil
|
||||
}
|
||||
|
||||
func posError(pos int, lenSrc int) error {
|
||||
return fmt.Errorf("bad PNG, pos: 0x%08X %10d, len(src): 0x%08X %10d",
|
||||
pos, pos, lenSrc, lenSrc)
|
||||
}
|
||||
|
||||
func clean(b []byte) string {
|
||||
a := [4]byte{}
|
||||
for i, c := range b[:4] {
|
||||
if (c < '!') || ('~' < c) {
|
||||
c = '.'
|
||||
}
|
||||
a[i] = c
|
||||
}
|
||||
return string(a[:4])
|
||||
}
|
||||
|
||||
func u32be(b []byte) uint32 {
|
||||
return (uint32(b[0]) << 24) |
|
||||
(uint32(b[1]) << 16) |
|
||||
(uint32(b[2]) << 8) |
|
||||
(uint32(b[3]) << 0)
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
// Copyright 2026 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-riff-chunks.go prints a RIFF's chunks' position and type.
|
||||
//
|
||||
// ANI, AVI, WAV and WEBP files are all RIFF files.
|
||||
//
|
||||
// Usage: go run print-riff-chunks.go foo.webp
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := main1(); err != nil {
|
||||
os.Stderr.WriteString(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
if len(args) != 1 {
|
||||
return fmt.Errorf("usage: progname filename.riff")
|
||||
}
|
||||
src, err := os.ReadFile(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pos := 0
|
||||
if len(src) < 12 {
|
||||
return posError(pos, len(src))
|
||||
} else if len(src) > 0x7FFF_FFFF {
|
||||
return fmt.Errorf("RIFF file is too large")
|
||||
}
|
||||
chunkLen := int64(u32le(src[pos+4 : pos+8]))
|
||||
if int64(len(src)-8) < chunkLen {
|
||||
return posError(0, len(src))
|
||||
}
|
||||
isWEBP = string(src[8:12]) == "WEBP"
|
||||
fmt.Printf("pos: 0x%08X %10d +8, len: 0x%08X %10d, dep: %d, %s\n",
|
||||
0, 0, chunkLen, chunkLen, 0, clean(src[8:12]))
|
||||
|
||||
pos, err = do(src, 1, 12)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("pos: 0x%08X %10d ~~~~\n",
|
||||
pos, pos)
|
||||
return nil
|
||||
}
|
||||
|
||||
func do(src []byte, depth int, pos int) (int, error) {
|
||||
for pos < len(src) {
|
||||
if pos > (len(src) - 8) {
|
||||
return 0, posError(pos, len(src))
|
||||
}
|
||||
|
||||
n := int64(u32le(src[pos+4 : pos+8]))
|
||||
isWEBPANMF := isWEBP && (depth == 1) && (string(src[pos:pos+4]) == "ANMF")
|
||||
fmt.Printf("pos: 0x%08X %10d +8, len: 0x%08X %10d, dep: %d, %s\n",
|
||||
pos, pos, n, n, depth, clean(src[pos:pos+4]))
|
||||
pos += 8
|
||||
if (n & 1) != 0 {
|
||||
n++
|
||||
}
|
||||
|
||||
if int64(len(src)-pos) < n {
|
||||
return 0, posError(pos, len(src))
|
||||
|
||||
} else if isWEBPANMF && (n > 16) {
|
||||
pos1, err := do(src[:int64(pos)+n], depth+1, pos+16)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
pos = pos1
|
||||
|
||||
} else {
|
||||
pos += int(n)
|
||||
}
|
||||
}
|
||||
return pos, nil
|
||||
}
|
||||
|
||||
var isWEBP bool
|
||||
|
||||
func posError(pos int, lenSrc int) error {
|
||||
return fmt.Errorf("bad RIFF, pos: 0x%08X %10d, len(src): 0x%08X %10d",
|
||||
pos, pos, lenSrc, lenSrc)
|
||||
}
|
||||
|
||||
func clean(b []byte) string {
|
||||
a := [4]byte{}
|
||||
for i, c := range b[:4] {
|
||||
if (c < '!') || ('~' < c) {
|
||||
c = '.'
|
||||
}
|
||||
a[i] = c
|
||||
}
|
||||
return string(a[:4])
|
||||
}
|
||||
|
||||
func u32le(b []byte) uint32 {
|
||||
return (uint32(b[0]) << 0) |
|
||||
(uint32(b[1]) << 8) |
|
||||
(uint32(b[2]) << 16) |
|
||||
(uint32(b[3]) << 24)
|
||||
}
|
||||
+8
-8
@@ -94,12 +94,12 @@ uncompng__encode(int (*write_func)(void* context,
|
||||
const uint8_t* data_ptr,
|
||||
size_t data_len),
|
||||
void* context,
|
||||
const uint8_t* pixel_ptr,
|
||||
size_t pixel_len,
|
||||
uint32_t pixel_format,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
size_t stride,
|
||||
uint32_t pixel_format);
|
||||
const uint8_t* pixel_ptr,
|
||||
size_t pixel_len,
|
||||
size_t stride);
|
||||
|
||||
// --------
|
||||
|
||||
@@ -581,12 +581,12 @@ uncompng__encode(int (*write_func)(void* context,
|
||||
const uint8_t* data_ptr,
|
||||
size_t data_len),
|
||||
void* context,
|
||||
const uint8_t* pixel_ptr,
|
||||
size_t pixel_len,
|
||||
uint32_t pixel_format,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
size_t stride,
|
||||
uint32_t pixel_format) {
|
||||
const uint8_t* pixel_ptr,
|
||||
size_t pixel_len,
|
||||
size_t stride) {
|
||||
if (!write_func) {
|
||||
return UNCOMPNG__RESULT__INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice base.u8) base.status {
|
||||
var mby : base.u32
|
||||
var mbx : base.u32
|
||||
var status : base.status
|
||||
pri func decoder.decode_macroblocks!(workbuf: slice base.u8) base.status {
|
||||
var mby : base.u32
|
||||
var mbx : base.u32
|
||||
|
||||
mbx = 0
|
||||
while mbx < this.mbw {
|
||||
@@ -55,7 +54,7 @@ pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
mby += 1
|
||||
}
|
||||
|
||||
// Filter the final row, already in args.workbuf, and swizzle to args.dst.
|
||||
// Filter the final row, already in args.workbuf.
|
||||
if this.mbh > 0 {
|
||||
if this.filt_level <= 0 {
|
||||
// No-op.
|
||||
@@ -65,10 +64,6 @@ pri func decoder.decode_macroblocks!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
this.filter_normal!(workbuf: args.workbuf, mby: this.mbh - 1)
|
||||
}
|
||||
|
||||
status = this.swizzle!(dst: args.dst, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
||||
return ok
|
||||
@@ -348,16 +343,43 @@ pri func decoder.copy_from_yuv_cache!(
|
||||
|
||||
pri func decoder.swizzle!(
|
||||
dst: ptr base.pixel_buffer,
|
||||
blend: base.pixel_blend,
|
||||
workbuf: slice base.u8) base.status {
|
||||
var status : base.status
|
||||
var wh : base.u64[..= 0xFFF_8001]
|
||||
var prefix : slice base.u8
|
||||
var suffix : slice base.u8
|
||||
var has_alpha : base.u32[..= 1]
|
||||
var ycc_model : base.u32[..= 0xFF]
|
||||
var status : base.status
|
||||
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
if this.quirk_width_and_height == 0 {
|
||||
return "#inconsistent width and height"
|
||||
}
|
||||
wh = (this.width * this.height) as base.u64
|
||||
if wh > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
prefix = args.workbuf[.. wh]
|
||||
suffix = args.workbuf[wh ..]
|
||||
has_alpha = 1
|
||||
ycc_model = base.YCC_MODEL__BT_601_STUDIO_RANGE__ALPHA__SRC |
|
||||
(0x01 & (this.util.demake_pixel_blend(a: args.blend) as base.u32))
|
||||
|
||||
} else {
|
||||
prefix = this.util.empty_slice_u8()
|
||||
suffix = args.workbuf
|
||||
has_alpha = 0
|
||||
ycc_model = base.YCC_MODEL__BT_601_STUDIO_RANGE
|
||||
}
|
||||
|
||||
if (this.workbuf_yuv_y_end > this.workbuf_yuv_u_end) or
|
||||
(this.workbuf_yuv_u_end > this.workbuf_yuv_v_end) or
|
||||
(this.workbuf_yuv_v_end > args.workbuf.length()) {
|
||||
(this.workbuf_yuv_v_end > suffix.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
assert this.workbuf_yuv_u_end <= args.workbuf.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_v_end)
|
||||
assert this.workbuf_yuv_y_end <= args.workbuf.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_u_end)
|
||||
assert this.workbuf_yuv_u_end <= suffix.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_v_end)
|
||||
assert this.workbuf_yuv_y_end <= suffix.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_yuv_u_end)
|
||||
|
||||
status = this.swizzler.swizzle_ycck!(
|
||||
dst: args.dst,
|
||||
@@ -366,31 +388,31 @@ pri func decoder.swizzle!(
|
||||
x_max_excl: this.width,
|
||||
y_min_incl: 0,
|
||||
y_max_excl: this.height,
|
||||
src0: args.workbuf[.. this.workbuf_yuv_y_end],
|
||||
src1: args.workbuf[this.workbuf_yuv_y_end .. this.workbuf_yuv_u_end],
|
||||
src2: args.workbuf[this.workbuf_yuv_u_end .. this.workbuf_yuv_v_end],
|
||||
src3: this.util.empty_slice_u8(),
|
||||
src0: suffix[.. this.workbuf_yuv_y_end],
|
||||
src1: suffix[this.workbuf_yuv_y_end .. this.workbuf_yuv_u_end],
|
||||
src2: suffix[this.workbuf_yuv_u_end .. this.workbuf_yuv_v_end],
|
||||
src3: prefix,
|
||||
width0: this.mbw * 16,
|
||||
width1: this.mbw * 8,
|
||||
width2: this.mbw * 8,
|
||||
width3: 0,
|
||||
width3: this.width * has_alpha,
|
||||
height0: this.mbh * 16,
|
||||
height1: this.mbh * 8,
|
||||
height2: this.mbh * 8,
|
||||
height3: 0,
|
||||
height3: this.height * has_alpha,
|
||||
stride0: this.mbw * 16,
|
||||
stride1: this.mbw * 8,
|
||||
stride2: this.mbw * 8,
|
||||
stride3: 0,
|
||||
stride3: this.width * has_alpha,
|
||||
h0: 2,
|
||||
h1: 1,
|
||||
h2: 1,
|
||||
h3: 0,
|
||||
h3: (2 * has_alpha) as base.u8,
|
||||
v0: 2,
|
||||
v1: 1,
|
||||
v2: 1,
|
||||
v3: 0,
|
||||
ycc_model: base.YCC_MODEL__BT_601_STUDIO_RANGE as base.u8,
|
||||
v3: (2 * has_alpha) as base.u8,
|
||||
ycc_model: ycc_model as base.u8,
|
||||
ycc_upsampling: base.YCC_UPSAMPLING__FANCY_LIKE_LIBWEBP as base.u8,
|
||||
scratch_buffer_2k: this.swizzle_ycck_scratch_buffer_2k[..])
|
||||
return status
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright 2026 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 "vp8." is 0x1B_5EFE. Left shifting by 10 gives
|
||||
// 0x6D7B_F800.
|
||||
pri const QUIRKS_BASE : base.u32 = 0x6D7B_F800
|
||||
|
||||
// --------
|
||||
|
||||
// When this quirk is enabled, the workbuf starts with (width × height) alpha
|
||||
// samples, decoded out-of-band (from the VP8 decoder's perspective, they are
|
||||
// typically decoded in-band from the surrounding WebP decoder's perspective).
|
||||
pub const QUIRK_HAS_ALPHA_SIDE_CHANNEL : base.u32 = 0x6D7B_F800 | 0x00
|
||||
|
||||
// Gives the image width and height out-of-band, in the u64 quirk value. The
|
||||
// low 32 bits are the width and the high 32 bits are the height. Both
|
||||
// dimensions should range within 0x0001 ..= 0x3FFF.
|
||||
//
|
||||
// A simple WebP file could contain one chunk, a VP8 chunk, that gives the
|
||||
// image width and height. A complex WebP file could contain three chunks:
|
||||
// VP8X, ALPH and VP8. The image dimensions are given in the VP8X chunk and are
|
||||
// then repeated in the VP8 chunk.
|
||||
//
|
||||
// After a webp.decoder decode_image_config call, the caller might next want to
|
||||
// query the workbuf length, to know how much memory to dynamically allocate,
|
||||
// especially before attempting to decode the ALPH chunk. The outer
|
||||
// webp.decoder workbuf_len method can delegate to the inner vp8.decoder
|
||||
// workbuf_len method, but the latter needs to know the image dimensions.
|
||||
//
|
||||
// This quirk mechanism lets the outer webp decoder tell the inner vp8 decoder
|
||||
// those dimensions, after parsing the VP8X chunk but before ALPH or VP8.
|
||||
pub const QUIRK_WIDTH_AND_HEIGHT : base.u32 = 0x6D7B_F800 | 0x01
|
||||
+124
-31
@@ -9,13 +9,15 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pub status "#bad QUIRK_SOURCE_LENGTH"
|
||||
pub status "#bad QUIRK_WIDTH_AND_HEIGHT"
|
||||
pub status "#bad header"
|
||||
pub status "#inconsistent width and height"
|
||||
pub status "#missing QUIRK_SOURCE_LENGTH"
|
||||
pub status "#truncated input"
|
||||
pub status "#unsupported QUIRK_SOURCE_LENGTH"
|
||||
pub status "#unsupported VP8 file"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x20FF_FFFF
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x30FF_8000
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0x3FFF],
|
||||
@@ -31,17 +33,24 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
is_key_frame : base.bool,
|
||||
|
||||
quirk_has_alpha_side_channel : base.bool,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
// This uses the same representation as an wuffs_base__optional_u63:
|
||||
// ((value_as_u63 << 1) | has_value_as_u1).
|
||||
quirk_source_length : base.u64,
|
||||
|
||||
quirk_width_and_height : base.u64,
|
||||
|
||||
// Just under 144 MiB, for 9 partitions each up to 0xFF_FFFF bytes.
|
||||
partitioned_data_length : base.u32[..= 0x08FF_FFF7],
|
||||
|
||||
// args.workbuf strides and offsets.
|
||||
//
|
||||
// The foobar_end offsets are measured after any "prefix trimmed work
|
||||
// buffer" adjustment (if QUIRK_HAS_ALPHA_SIDE_CHANNEL is enabled).
|
||||
//
|
||||
// The workbuf holds the YUV buffers (after decoding from the source
|
||||
// bytes but before converting YUV to RGBX) and then also a copy of
|
||||
// most of the source bytes themselves - the "at least 2, up to 9"
|
||||
@@ -205,15 +214,54 @@ pub struct decoder? implements base.image_decoder(
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
if args.key == base.QUIRK_SOURCE_LENGTH {
|
||||
return this.quirk_source_length
|
||||
} else if args.key == QUIRK_HAS_ALPHA_SIDE_CHANNEL {
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
return 1
|
||||
}
|
||||
} else if args.key == QUIRK_WIDTH_AND_HEIGHT {
|
||||
return this.quirk_width_and_height
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
var w : base.u32
|
||||
var h : base.u32
|
||||
|
||||
if args.key == base.QUIRK_SOURCE_LENGTH {
|
||||
this.quirk_source_length = args.value
|
||||
if (args.value & 1) == 0 {
|
||||
if args.value <> 0 {
|
||||
return "#bad QUIRK_SOURCE_LENGTH"
|
||||
}
|
||||
this.quirk_source_length = 0
|
||||
this.partitioned_data_length = 0
|
||||
} else if (args.value >> 1) < 10 {
|
||||
return "#bad QUIRK_SOURCE_LENGTH"
|
||||
} else if (args.value >> 1) > (0x08FF_FFF7 + 10) {
|
||||
return "#unsupported QUIRK_SOURCE_LENGTH"
|
||||
} else {
|
||||
this.quirk_source_length = args.value
|
||||
this.partitioned_data_length = ((args.value >> 1) as base.u32) - 10
|
||||
}
|
||||
return ok
|
||||
|
||||
} else if args.key == QUIRK_HAS_ALPHA_SIDE_CHANNEL {
|
||||
this.quirk_has_alpha_side_channel = args.value <> 0
|
||||
return ok
|
||||
|
||||
} else if args.key == QUIRK_WIDTH_AND_HEIGHT {
|
||||
w = (args.value & 0xFFFF_FFFF) as base.u32
|
||||
h = (args.value >> 32) as base.u32
|
||||
if (w < 1) or (0x3FFF < w) or (h < 1) or (0x3FFF < h) {
|
||||
return "#bad QUIRK_WIDTH_AND_HEIGHT"
|
||||
}
|
||||
this.quirk_width_and_height = args.value
|
||||
this.width = w
|
||||
this.height = h
|
||||
this.calculate_mbw_mbh!()
|
||||
return ok
|
||||
}
|
||||
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
@@ -236,14 +284,9 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
if (this.quirk_source_length & 1) == 0 {
|
||||
if this.quirk_source_length == 0 {
|
||||
return "#missing QUIRK_SOURCE_LENGTH"
|
||||
} else if (this.quirk_source_length >> 1) < 10 {
|
||||
return "#bad QUIRK_SOURCE_LENGTH"
|
||||
} else if (this.quirk_source_length >> 1) > (0x08FF_FFF7 + 10) {
|
||||
return "#unsupported QUIRK_SOURCE_LENGTH"
|
||||
}
|
||||
this.partitioned_data_length = ((this.quirk_source_length >> 1) as base.u32) - 10
|
||||
|
||||
// RFC 6386 Section 9. Frame Header, up to and including 9.1. Uncompressed
|
||||
// Data Chunk. decode_header_partition handles the rest of section 9.
|
||||
@@ -267,17 +310,13 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
c32 = args.src.read_u32le?()
|
||||
this.width = 0x3FFF & (c32 >> 0)
|
||||
this.height = 0x3FFF & (c32 >> 16)
|
||||
this.mbw = (this.width + 15) / 16
|
||||
this.mbh = (this.height + 15) / 16
|
||||
|
||||
this.workbuf_yuv_y_stride = this.mbw * 16
|
||||
this.workbuf_yuv_uv_stride = this.mbw * 8
|
||||
this.workbuf_yuv_y_end =
|
||||
((this.workbuf_yuv_y_stride as base.u64) * ((this.mbh * 16) as base.u64))
|
||||
this.workbuf_yuv_u_end = this.workbuf_yuv_y_end +
|
||||
((this.workbuf_yuv_uv_stride as base.u64) * ((this.mbh * 8) as base.u64))
|
||||
this.workbuf_yuv_v_end = this.workbuf_yuv_u_end +
|
||||
((this.workbuf_yuv_uv_stride as base.u64) * ((this.mbh * 8) as base.u64))
|
||||
if (this.width == 0) or (this.height == 0) {
|
||||
return "#bad header"
|
||||
} else if (this.quirk_width_and_height <> 0) and
|
||||
(this.quirk_width_and_height <> ((this.width as base.u64) | ((this.height as base.u64) << 32))) {
|
||||
return "#inconsistent width and height"
|
||||
}
|
||||
this.calculate_mbw_mbh!()
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
|
||||
@@ -294,6 +333,20 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
this.call_sequence = 0x20
|
||||
}
|
||||
|
||||
pri func decoder.calculate_mbw_mbh!() {
|
||||
this.mbw = (this.width + 15) / 16
|
||||
this.mbh = (this.height + 15) / 16
|
||||
|
||||
this.workbuf_yuv_y_stride = this.mbw * 16
|
||||
this.workbuf_yuv_uv_stride = this.mbw * 8
|
||||
this.workbuf_yuv_y_end =
|
||||
((this.workbuf_yuv_y_stride as base.u64) * ((this.mbh * 16) as base.u64))
|
||||
this.workbuf_yuv_u_end = this.workbuf_yuv_y_end +
|
||||
((this.workbuf_yuv_uv_stride as base.u64) * ((this.mbh * 8) as base.u64))
|
||||
this.workbuf_yuv_v_end = this.workbuf_yuv_u_end +
|
||||
((this.workbuf_yuv_uv_stride as base.u64) * ((this.mbh * 8) as base.u64))
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
var status : base.status
|
||||
|
||||
@@ -341,23 +394,52 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
}
|
||||
|
||||
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 wh : base.u64[..= 0xFFF_8001]
|
||||
var wb_len : base.u64[..= DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE]
|
||||
var status : base.status
|
||||
|
||||
// The args.workbuf, with a "prefix trimmed work buffer" adjustment, if
|
||||
// QUIRK_HAS_ALPHA_SIDE_CHANNEL is enabled, in which case the first (width
|
||||
// × height) bytes of args.workbuf hold alpha samples that are e.g. part of
|
||||
// WebP, not part of VP8 per se.
|
||||
//
|
||||
// The prefix isn't used when decoding VP8 to YCbCr, but the final swizzle
|
||||
// to the destination pixel buffer should combine YCbCr and Alpha.
|
||||
var trimmed : slice base.u8
|
||||
|
||||
while true {
|
||||
wb_len = this.workbuf_yuv_v_end + (this.partitioned_data_length as base.u64) + 8
|
||||
if wb_len > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
} else {
|
||||
args.workbuf = args.workbuf[.. wb_len]
|
||||
trimmed = args.workbuf
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
if this.quirk_width_and_height == 0 {
|
||||
return "#inconsistent width and height"
|
||||
}
|
||||
wh = (this.width * this.height) as base.u64
|
||||
if wh > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
trimmed = args.workbuf[wh ..]
|
||||
}
|
||||
|
||||
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() {
|
||||
wb_len = this.workbuf_yuv_v_end + (this.partitioned_data_length as base.u64) + 8
|
||||
if wb_len > trimmed.length() {
|
||||
return base."#bad workbuf length"
|
||||
} else {
|
||||
trimmed = trimmed[.. wb_len]
|
||||
}
|
||||
|
||||
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: trimmed, opts: args.opts)
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if (status == base."$short read") and args.src.is_closed() {
|
||||
return "#truncated input"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
status = this.swizzle!(dst: args.dst, blend: args.blend, workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return 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) {
|
||||
@@ -404,7 +486,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return status
|
||||
}
|
||||
|
||||
status = this.decode_macroblocks!(dst: args.dst, workbuf: args.workbuf)
|
||||
status = this.decode_macroblocks!(workbuf: args.workbuf)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
@@ -450,7 +532,7 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta
|
||||
}
|
||||
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
// No-op. VP8 doesn't support metadata (but WEBP does).
|
||||
// No-op. VP8 doesn't support metadata (but WebP does).
|
||||
}
|
||||
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
@@ -458,10 +540,21 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
var wb_len : base.u64[..= DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE]
|
||||
var wh : base.u64[..= 0xFFF_8001]
|
||||
var wb_len : base.u64[..= DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE - 0xFFF_8001]
|
||||
|
||||
if this.quirk_source_length == 0 {
|
||||
// (min_incl > max_incl) means an empty range_ii_u64. The workbuf
|
||||
// length isn't known yet, as we don't know partitioned_data_length.
|
||||
return this.util.make_range_ii_u64(min_incl: 1, max_incl: 0)
|
||||
}
|
||||
|
||||
if this.quirk_has_alpha_side_channel {
|
||||
wh = (this.width * this.height) as base.u64
|
||||
}
|
||||
|
||||
wb_len = this.workbuf_yuv_v_end + (this.partitioned_data_length as base.u64) + 8
|
||||
return this.util.make_range_ii_u64(
|
||||
min_incl: wb_len,
|
||||
max_incl: wb_len)
|
||||
min_incl: wh + wb_len,
|
||||
max_incl: wh + wb_len)
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
WebP is a still image format, described in the [WebP Container
|
||||
Specification](https://developers.google.com/speed/webp/docs/riff_container).
|
||||
It is a container for [VP8 Lossy](https://www.ietf.org/rfc/rfc6386.txt) or [VP8
|
||||
Lossless](https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification).
|
||||
|
||||
The ["Making Software - Image
|
||||
Compression"](https://www.makingsoftware.com/chapters/image-compression) book
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
// Copyright 2026 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.decode_alph?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
var r_mark : base.u64
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
io_limit (io: args.src, limit: this.sub_chunk_length as base.u64) {
|
||||
r_mark = args.src.mark()
|
||||
status =? this.decode_alph_limited?(src: args.src, workbuf: args.workbuf)
|
||||
this.sub_chunk_length ~sat-=
|
||||
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if not status.is_suspension() {
|
||||
return status
|
||||
} else if (status == base."$short read") and (this.sub_chunk_length == 0) {
|
||||
return "#short chunk"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_alph_limited?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
var n : base.u64
|
||||
|
||||
this.vp8x_alph_flags = args.src.read_u8?()
|
||||
|
||||
if (this.vp8x_alph_flags & 3) == 0 {
|
||||
args.src.limited_copy_u32_to_slice!(up_to: this.width * this.height, s: args.workbuf)
|
||||
} else if (this.vp8x_alph_flags & 3) == 1 {
|
||||
this.do_decode_frame_vp8l?(
|
||||
dst: nullptr,
|
||||
src: args.src,
|
||||
blend: this.util.make_pixel_blend(repr: base.PIXEL_BLEND__SRC),
|
||||
workbuf: args.workbuf,
|
||||
opts: nullptr)
|
||||
|
||||
n = (this.width * this.height * 4) as base.u64
|
||||
if n <= args.workbuf.length() {
|
||||
this.compact_alph!(s: args.workbuf[.. n])
|
||||
}
|
||||
} else {
|
||||
return "#bad VP8X chunk"
|
||||
}
|
||||
this.vp8x_alph_flags |= 2
|
||||
|
||||
n = (this.width * this.height) as base.u64
|
||||
if n <= args.workbuf.length() {
|
||||
if (this.vp8x_alph_flags & 0x0C) == 0x04 {
|
||||
this.filter_alph_horizontal!(s: args.workbuf[.. n])
|
||||
} else if (this.vp8x_alph_flags & 0x0C) == 0x08 {
|
||||
this.filter_alph_vertical!(s: args.workbuf[.. n])
|
||||
} else if (this.vp8x_alph_flags & 0x0C) == 0x0C {
|
||||
this.filter_alph_gradient!(s: args.workbuf[.. n])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.compact_alph!(s: slice base.u8) {
|
||||
var i : base.u64[..= 0x4000_0004]
|
||||
var j : base.u64[..= 0x4000_0004]
|
||||
|
||||
if args.s.length() > 0x4000_0000 {
|
||||
return nothing
|
||||
}
|
||||
|
||||
i = 0
|
||||
j = 1
|
||||
while (i < args.s.length()) and (j < args.s.length()),
|
||||
inv args.s.length() <= 0x4000_0000,
|
||||
{
|
||||
assert i <= 0x4000_0000 via "a <= b: a <= c; c <= b"(c: args.s.length())
|
||||
assert j <= 0x4000_0000 via "a <= b: a <= c; c <= b"(c: args.s.length())
|
||||
args.s[i] = args.s[j]
|
||||
i += 1
|
||||
j += 4
|
||||
}
|
||||
}
|
||||
|
||||
// libwebp calls this HorizontalUnfilter_C.
|
||||
pri func decoder.filter_alph_horizontal!(s: slice base.u8) {
|
||||
var y : base.u32
|
||||
var x : base.u32
|
||||
var i : base.u64
|
||||
var pred : base.u8
|
||||
|
||||
y = 0
|
||||
while y < this.height {
|
||||
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
|
||||
|
||||
pred = 0
|
||||
if y > 0 {
|
||||
i = ((y - 1) * this.width) as base.u64
|
||||
if i >= args.s.length() {
|
||||
break
|
||||
}
|
||||
pred = args.s[i]
|
||||
}
|
||||
|
||||
x = 0
|
||||
while x < this.width,
|
||||
inv y < 0x4000,
|
||||
{
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
|
||||
i = ((y * this.width) + x) as base.u64
|
||||
if i >= args.s.length() {
|
||||
break
|
||||
}
|
||||
args.s[i] ~mod+= pred
|
||||
pred = args.s[i]
|
||||
|
||||
x += 1
|
||||
}
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
|
||||
// libwebp calls this VerticalUnfilter_C.
|
||||
pri func decoder.filter_alph_vertical!(s: slice base.u8) {
|
||||
var y : base.u32
|
||||
var x : base.u32
|
||||
var i : base.u64
|
||||
var pred : base.u8
|
||||
|
||||
x = 0
|
||||
while x < this.width {
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
|
||||
pred = 0
|
||||
if x > 0 {
|
||||
i = (x - 1) as base.u64
|
||||
if i >= args.s.length() {
|
||||
break
|
||||
}
|
||||
pred = args.s[i]
|
||||
}
|
||||
|
||||
y = 0
|
||||
while y < this.height,
|
||||
inv x < 0x4000,
|
||||
{
|
||||
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
|
||||
|
||||
i = ((y * this.width) + x) as base.u64
|
||||
if i >= args.s.length() {
|
||||
break
|
||||
}
|
||||
args.s[i] ~mod+= pred
|
||||
pred = args.s[i]
|
||||
|
||||
y += 1
|
||||
}
|
||||
x += 1
|
||||
}
|
||||
}
|
||||
|
||||
// libwebp calls this GradientUnfilter_C.
|
||||
pri func decoder.filter_alph_gradient!(s: slice base.u8) {
|
||||
var y : base.u32
|
||||
var x : base.u32
|
||||
var i : base.u64
|
||||
var pred : base.u8
|
||||
var grad : base.u32
|
||||
var l : base.u8 // Left sample.
|
||||
var t : base.u8 // Top sample.
|
||||
var tl : base.u8 // Top-Left sample.
|
||||
|
||||
// First row.
|
||||
x = 0
|
||||
while x < this.width {
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
|
||||
i = x as base.u64
|
||||
if i >= args.s.length() {
|
||||
break
|
||||
}
|
||||
args.s[i] ~mod+= pred
|
||||
pred = args.s[i]
|
||||
|
||||
x += 1
|
||||
}
|
||||
|
||||
// Other rows.
|
||||
y = 1
|
||||
while y < this.height,
|
||||
inv y >= 1,
|
||||
{
|
||||
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
|
||||
|
||||
i = (((y - 1) * this.width) + 0) as base.u64
|
||||
if i >= args.s.length() {
|
||||
break
|
||||
}
|
||||
t = args.s[i]
|
||||
tl = t
|
||||
l = t
|
||||
|
||||
x = 0
|
||||
while x < this.width,
|
||||
inv y >= 1,
|
||||
inv y < 0x4000,
|
||||
{
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
|
||||
i = (((y - 1) * this.width) + x) as base.u64
|
||||
if i >= args.s.length() {
|
||||
break
|
||||
}
|
||||
t = args.s[i]
|
||||
|
||||
i = ((y * this.width) + x) as base.u64
|
||||
if i >= args.s.length() {
|
||||
break
|
||||
}
|
||||
grad = ((l as base.u32) ~mod+ (t as base.u32)) ~mod- (tl as base.u32)
|
||||
if grad > 0x7FFF_FFFF {
|
||||
grad = 0x00
|
||||
} else if grad > 0xFF {
|
||||
grad = 0xFF
|
||||
}
|
||||
l = args.s[i] ~mod+ ((grad & 0xFF) as base.u8)
|
||||
args.s[i] = l
|
||||
tl = t
|
||||
|
||||
x += 1
|
||||
}
|
||||
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: roslice base.u8) {
|
||||
pri func decoder.apply_transform_predictor!(pix: slice base.u8, width: base.u32[..= 0x4000], tile_data: roslice base.u8) {
|
||||
var w4 : base.u64[..= 0x1_0000]
|
||||
var prev_row : roslice base.u8
|
||||
var curr_row : slice base.u8
|
||||
@@ -37,11 +37,11 @@ pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: rosli
|
||||
var sum_l : base.u32
|
||||
var sum_t : base.u32
|
||||
|
||||
if (this.width <= 0) or (this.height <= 0) {
|
||||
if (args.width <= 0) or (this.height <= 0) {
|
||||
return nothing
|
||||
}
|
||||
|
||||
w4 = (this.width * 4) as base.u64
|
||||
w4 = (args.width * 4) as base.u64
|
||||
curr_row = this.util.empty_slice_u8()
|
||||
if w4 <= args.pix.length() {
|
||||
curr_row = args.pix[.. w4]
|
||||
@@ -62,7 +62,7 @@ pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: rosli
|
||||
}
|
||||
|
||||
tile_size_log2 = this.transform_tile_size_log2[0] as base.u32
|
||||
tiles_per_row = (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
|
||||
tiles_per_row = (args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
|
||||
mask = ((1 as base.u32) << tile_size_log2) - 1
|
||||
|
||||
y = 1
|
||||
@@ -94,10 +94,10 @@ pri func decoder.apply_transform_predictor!(pix: slice base.u8, tile_data: rosli
|
||||
}
|
||||
|
||||
x = 1
|
||||
while x < this.width,
|
||||
while x < args.width,
|
||||
inv y < 0x4000,
|
||||
{
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: args.width)
|
||||
|
||||
if ((x & mask) == 0) and (tile_data.length() >= 4) {
|
||||
mode = tile_data[1] & 0x0F
|
||||
@@ -283,7 +283,7 @@ pri func decoder.mode13(l: base.u8, t: base.u8, tl: base.u8) base.u8 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pri func decoder.apply_transform_cross_color!(pix: slice base.u8, tile_data: roslice base.u8) {
|
||||
pri func decoder.apply_transform_cross_color!(pix: slice base.u8, width: base.u32[..= 0x4000], tile_data: roslice base.u8) {
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var tiles_per_row : base.u32[..= 16895]
|
||||
var mask : base.u32
|
||||
@@ -301,7 +301,7 @@ pri func decoder.apply_transform_cross_color!(pix: slice base.u8, tile_data: ros
|
||||
var r : base.u8
|
||||
|
||||
tile_size_log2 = this.transform_tile_size_log2[1] as base.u32
|
||||
tiles_per_row = (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
|
||||
tiles_per_row = (args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2
|
||||
mask = ((1 as base.u32) << tile_size_log2) - 1
|
||||
|
||||
y = 0
|
||||
@@ -315,10 +315,10 @@ pri func decoder.apply_transform_cross_color!(pix: slice base.u8, tile_data: ros
|
||||
}
|
||||
|
||||
x = 0
|
||||
while x < this.width,
|
||||
while x < args.width,
|
||||
inv y < 0x4000,
|
||||
{
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: this.width)
|
||||
assert x < 0x4000 via "a < b: a < c; c <= b"(c: args.width)
|
||||
|
||||
if ((x & mask) == 0) and (tile_data.length() >= 4) {
|
||||
g2r = this.util.sign_extend_convert_u8_u32(a: tile_data[0])
|
||||
@@ -357,7 +357,7 @@ pri func decoder.apply_transform_subtract_green!(pix: slice base.u8) {
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.apply_transform_color_indexing!(pix: slice base.u8) {
|
||||
pri func decoder.apply_transform_color_indexing!(pix: slice base.u8, width: base.u32[..= 0x4000]) {
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var bits_per_pixel : base.u32[..= 8]
|
||||
var x_mask : base.u32
|
||||
@@ -404,8 +404,8 @@ pri func decoder.apply_transform_color_indexing!(pix: slice base.u8) {
|
||||
while y < this.height {
|
||||
assert y < 0x4000 via "a < b: a < c; c <= b"(c: this.height)
|
||||
|
||||
di = (4 * (y + 0) * this.width) as base.u64
|
||||
dj = (4 * (y + 1) * this.width) as base.u64
|
||||
di = (4 * (y + 0) * args.width) as base.u64
|
||||
dj = (4 * (y + 1) * args.width) as base.u64
|
||||
if (di > dj) or (dj > args.pix.length()) {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -0,0 +1,484 @@
|
||||
// Copyright 2026 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pri func decoder.do_decode_frame_vp8l?(dst: nptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var c8 : base.u8
|
||||
var has_more : base.u32[..= 1]
|
||||
var width : base.u32[..= 0x4000]
|
||||
var dst : slice base.u8
|
||||
var tile_data : roslice base.u8
|
||||
var status : base.status
|
||||
var pix : slice base.u8
|
||||
var which : base.u32[..= 4]
|
||||
var transform_type : base.u32[..= 3]
|
||||
var ti : base.u64
|
||||
var tj : base.u64
|
||||
|
||||
this.seen_transform[0] = false
|
||||
this.seen_transform[1] = false
|
||||
this.seen_transform[2] = false
|
||||
this.seen_transform[3] = false
|
||||
this.n_transforms = 0
|
||||
|
||||
while true {
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
has_more = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if has_more == 0 {
|
||||
break
|
||||
}
|
||||
this.decode_transform?(src: args.src, workbuf: args.workbuf)
|
||||
}
|
||||
|
||||
width = this.width
|
||||
if this.seen_transform[3] {
|
||||
width = this.color_indexing_width
|
||||
}
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.overall_color_cache_bits = this.color_cache_bits
|
||||
this.decode_hg_table?(src: args.src, width: width, workbuf: args.workbuf)
|
||||
this.color_cache_bits = this.overall_color_cache_bits
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: this.overall_n_huffman_groups)
|
||||
|
||||
while true {
|
||||
if ((this.workbuf_offset_for_color_indexing as base.u64) > (this.workbuf_offset_for_transform[0] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
assert (this.workbuf_offset_for_transform[0] as base.u64) <= args.workbuf.length() via "a <= b: a <= c; c <= b"(c: this.workbuf_offset_for_transform[1] as base.u64)
|
||||
|
||||
dst = args.workbuf[
|
||||
(this.workbuf_offset_for_color_indexing as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[0] as base.u64)]
|
||||
tile_data = args.workbuf[
|
||||
(this.workbuf_offset_for_transform[0] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[1] as base.u64)]
|
||||
status =? this.decode_pixels?(
|
||||
dst: dst,
|
||||
src: args.src,
|
||||
width: width,
|
||||
height: this.height,
|
||||
tile_data: tile_data,
|
||||
tile_size_log2: this.overall_tile_size_log2)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
if (this.workbuf_offset_for_transform[0] as base.u64) > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
pix = args.workbuf[.. (this.workbuf_offset_for_transform[0] as base.u64)]
|
||||
width = this.width
|
||||
if this.seen_transform[3] and
|
||||
((this.workbuf_offset_for_color_indexing as base.u64) <= pix.length()) {
|
||||
pix = pix[this.workbuf_offset_for_color_indexing as base.u64 ..]
|
||||
width = this.color_indexing_width
|
||||
}
|
||||
|
||||
which = this.n_transforms
|
||||
while which > 0 {
|
||||
which -= 1
|
||||
transform_type = this.transform_type[which] as base.u32
|
||||
|
||||
tile_data = this.util.empty_slice_u8()
|
||||
if transform_type < 2 {
|
||||
ti = this.workbuf_offset_for_transform[transform_type + 1] as base.u64
|
||||
tj = this.workbuf_offset_for_transform[transform_type + 2] as base.u64
|
||||
if (ti <= tj) and (tj <= args.workbuf.length()) {
|
||||
tile_data = args.workbuf[ti .. tj]
|
||||
}
|
||||
}
|
||||
|
||||
if transform_type == 0 {
|
||||
this.apply_transform_predictor!(pix: pix, width: width, tile_data: tile_data)
|
||||
} else if transform_type == 1 {
|
||||
this.apply_transform_cross_color!(pix: pix, width: width, tile_data: tile_data)
|
||||
} else if transform_type == 2 {
|
||||
this.apply_transform_subtract_green!(pix: pix)
|
||||
} else if (this.workbuf_offset_for_transform[0] as base.u64) <= args.workbuf.length() {
|
||||
pix = args.workbuf[.. (this.workbuf_offset_for_transform[0] as base.u64)]
|
||||
width = this.width
|
||||
this.apply_transform_color_indexing!(pix: pix, width: width)
|
||||
}
|
||||
}
|
||||
|
||||
status = this.swizzle!(
|
||||
dst: args.dst,
|
||||
src: pix,
|
||||
blend: args.blend)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pri func decoder.decode_transform?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
var status : base.status
|
||||
var c8 : base.u8
|
||||
var transform_type : base.u32[..= 3]
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var width : base.u32[..= 0x4000]
|
||||
var p : slice base.u8
|
||||
|
||||
if this.n_bits < 2 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 2 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 2
|
||||
}
|
||||
transform_type = this.bits & 3
|
||||
this.bits >>= 2
|
||||
this.n_bits -= 2
|
||||
|
||||
if this.seen_transform[transform_type] or (this.n_transforms >= 4) {
|
||||
return "#bad transform"
|
||||
}
|
||||
this.seen_transform[transform_type] = true
|
||||
this.transform_type[this.n_transforms] = transform_type as base.u8
|
||||
this.n_transforms += 1
|
||||
|
||||
if transform_type < 2 { // Predictor, Cross Color transform.
|
||||
if this.n_bits < 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 3 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 3
|
||||
}
|
||||
tile_size_log2 = (this.bits & 7) + 2
|
||||
this.transform_tile_size_log2[transform_type] = tile_size_log2 as base.u8
|
||||
this.bits >>= 3
|
||||
this.n_bits -= 3
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
|
||||
while true,
|
||||
inv transform_type < 2,
|
||||
inv tile_size_log2 >= 2,
|
||||
{
|
||||
width = this.width
|
||||
if this.seen_transform[3] {
|
||||
width = this.color_indexing_width
|
||||
}
|
||||
|
||||
if ((this.workbuf_offset_for_transform[transform_type + 1] as base.u64) > (this.workbuf_offset_for_transform[transform_type + 2] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[transform_type + 2] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
status =? this.decode_pixels?(
|
||||
dst: args.workbuf[
|
||||
(this.workbuf_offset_for_transform[transform_type + 1] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[transform_type + 2] as base.u64)],
|
||||
src: args.src,
|
||||
width: (width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
height: (this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
} else if transform_type == 2 { // Subtract Green transform.
|
||||
// No-op.
|
||||
|
||||
} else { // Color Indexing transform.
|
||||
if this.n_bits < 8 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 8 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 8
|
||||
}
|
||||
this.color_indexing_palette_size = (this.bits & 0xFF) + 1
|
||||
this.bits >>= 8
|
||||
this.n_bits -= 8
|
||||
|
||||
if this.color_indexing_palette_size <= 2 {
|
||||
this.color_indexing_width = (this.width + 7) / 8
|
||||
this.transform_tile_size_log2[3] = 3
|
||||
} else if this.color_indexing_palette_size <= 4 {
|
||||
this.color_indexing_width = (this.width + 3) / 4
|
||||
this.transform_tile_size_log2[3] = 2
|
||||
} else if this.color_indexing_palette_size <= 16 {
|
||||
this.color_indexing_width = (this.width + 1) / 2
|
||||
this.transform_tile_size_log2[3] = 1
|
||||
} else {
|
||||
this.color_indexing_width = this.width
|
||||
this.transform_tile_size_log2[3] = 0
|
||||
}
|
||||
|
||||
if this.width >= this.color_indexing_width {
|
||||
this.workbuf_offset_for_color_indexing = 4 * (this.width - this.color_indexing_width) * this.height
|
||||
}
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
|
||||
this.decode_pixels?(
|
||||
dst: this.palette[.. 4 * this.color_indexing_palette_size],
|
||||
src: args.src,
|
||||
width: this.color_indexing_palette_size,
|
||||
height: 1,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
this.palette[4 * this.color_indexing_palette_size .. 1024].bulk_memset!(byte_value: 0)
|
||||
|
||||
p = this.palette[.. 4 * this.color_indexing_palette_size]
|
||||
while p.length() >= 8 {
|
||||
p[4] ~mod+= p[0]
|
||||
p[5] ~mod+= p[1]
|
||||
p[6] ~mod+= p[2]
|
||||
p[7] ~mod+= p[3]
|
||||
p = p[4 ..]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_color_cache_parameters?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var use_color_cache : base.u32[..= 1]
|
||||
var color_cache_bits : base.u32[..= 15]
|
||||
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
use_color_cache = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
this.color_cache_bits = 0
|
||||
if use_color_cache <> 0 {
|
||||
if this.n_bits < 4 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 4 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 4
|
||||
}
|
||||
color_cache_bits = this.bits & 15
|
||||
this.bits >>= 4
|
||||
this.n_bits -= 4
|
||||
|
||||
if (color_cache_bits < 1) or (11 < color_cache_bits) {
|
||||
return "#bad color cache"
|
||||
}
|
||||
this.color_cache_bits = color_cache_bits
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_hg_table?(src: base.io_reader, width: base.u32[..= 0x4000], workbuf: slice base.u8) {
|
||||
var status : base.status
|
||||
var c8 : base.u8
|
||||
var use_hg_table : base.u32[..= 1]
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var hg_pixels : slice base.u8
|
||||
var n : base.u64
|
||||
var p : roslice base.u8
|
||||
var hg_plus_1 : base.u32[..= 256]
|
||||
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
use_hg_table = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if use_hg_table == 0 {
|
||||
this.overall_n_huffman_groups = 1
|
||||
this.overall_tile_size_log2 = 0
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
hg_pixels = args.workbuf[
|
||||
this.workbuf_offset_for_transform[0] as base.u64 ..
|
||||
this.workbuf_offset_for_transform[1] as base.u64]
|
||||
if hg_pixels.length() >= 4 {
|
||||
hg_pixels[0] = 0x00
|
||||
hg_pixels[1] = 0x00
|
||||
hg_pixels[2] = 0x00
|
||||
hg_pixels[3] = 0x00
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
if this.n_bits < 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 3 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 3
|
||||
}
|
||||
tile_size_log2 = (this.bits & 7) + 2
|
||||
this.bits >>= 3
|
||||
this.n_bits -= 3
|
||||
|
||||
this.overall_tile_size_log2 = tile_size_log2
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
while true,
|
||||
inv tile_size_log2 >= 2,
|
||||
{
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
status =? this.decode_pixels?(
|
||||
dst: args.workbuf[
|
||||
(this.workbuf_offset_for_transform[0] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[1] as base.u64)],
|
||||
src: args.src,
|
||||
width: (args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
height: (this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
this.overall_n_huffman_groups = 1
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
hg_pixels = args.workbuf[
|
||||
this.workbuf_offset_for_transform[0] as base.u64 ..
|
||||
this.workbuf_offset_for_transform[1] as base.u64]
|
||||
n = (((args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2) *
|
||||
((this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2) *
|
||||
4) as base.u64
|
||||
if n > hg_pixels.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
p = hg_pixels[.. n]
|
||||
while p.length() >= 4 {
|
||||
if p[2] <> 0 {
|
||||
return "#unsupported number of Huffman groups"
|
||||
}
|
||||
hg_plus_1 = (p[1] as base.u32) + 1
|
||||
if this.overall_n_huffman_groups < hg_plus_1 {
|
||||
this.overall_n_huffman_groups = hg_plus_1
|
||||
}
|
||||
p = p[4 ..]
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_pixels?(dst: slice base.u8, src: base.io_reader, width: base.u32[..= 0x4000], height: base.u32[..= 0x4000], tile_data: roslice base.u8, tile_size_log2: base.u32[..= 9]) {
|
||||
var i : base.u32
|
||||
var n : base.u32[..= 2048]
|
||||
|
||||
i = 0
|
||||
n = (1 as base.u32) << this.color_cache_bits
|
||||
while i < n {
|
||||
assert i < 2048 via "a < b: a < c; c <= b"(c: n)
|
||||
this.color_cache[i] = 0
|
||||
i += 1
|
||||
}
|
||||
|
||||
this.decode_pixels_slow?(
|
||||
dst: args.dst,
|
||||
src: args.src,
|
||||
width: args.width,
|
||||
height: args.height,
|
||||
tile_data: args.tile_data,
|
||||
tile_size_log2: args.tile_size_log2)
|
||||
}
|
||||
|
||||
pri func decoder.swizzle!(dst: nptr base.pixel_buffer, src: roslice base.u8, blend: base.pixel_blend) base.status {
|
||||
var status : base.status
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||
var dst_bytes_per_row : base.u64
|
||||
var dst_palette : slice base.u8
|
||||
var tab : table base.u8
|
||||
var src_bytes_per_row : base.u64
|
||||
var dst : slice base.u8
|
||||
var y : base.u32
|
||||
|
||||
if args.dst == nullptr {
|
||||
return ok
|
||||
}
|
||||
|
||||
status = this.swizzler.prepare!(
|
||||
dst_pixfmt: args.dst.pixel_format(),
|
||||
dst_palette: args.dst.palette_or_else(fallback: this.palette[..]),
|
||||
src_pixfmt: this.util.make_pixel_format(repr: base.PIXEL_FORMAT__BGRA_NONPREMUL),
|
||||
src_palette: this.util.empty_slice_u8(),
|
||||
blend: args.blend)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
||||
dst_pixfmt = args.dst.pixel_format()
|
||||
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
|
||||
if (dst_bits_per_pixel & 7) <> 0 {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||
dst_palette = args.dst.palette_or_else(fallback: this.palette[..])
|
||||
tab = args.dst.plane(p: 0)
|
||||
src_bytes_per_row = (this.width * 4) as base.u64
|
||||
|
||||
while src_bytes_per_row <= args.src.length() {
|
||||
dst = tab.row_u32(y: y)
|
||||
if dst_bytes_per_row < dst.length() {
|
||||
dst = dst[.. dst_bytes_per_row]
|
||||
}
|
||||
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: args.src[.. src_bytes_per_row])
|
||||
|
||||
args.src = args.src[src_bytes_per_row ..]
|
||||
y ~mod+= 1
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
+255
-481
@@ -10,18 +10,20 @@
|
||||
|
||||
use "std/vp8"
|
||||
|
||||
pub status "#bad ALPH+VP8L combination"
|
||||
pub status "#bad Huffman code (over-subscribed)"
|
||||
pub status "#bad Huffman code (under-subscribed)"
|
||||
pub status "#bad Huffman code"
|
||||
pub status "#bad VP8X chunk"
|
||||
pub status "#bad back-reference"
|
||||
pub status "#bad chunk order"
|
||||
pub status "#bad color cache"
|
||||
pub status "#bad header"
|
||||
pub status "#bad transform"
|
||||
pub status "#short chunk"
|
||||
pub status "#truncated input"
|
||||
pub status "#unsupported number of Huffman groups"
|
||||
pub status "#unsupported transform after color indexing transform"
|
||||
pub status "#unsupported WebP file"
|
||||
pub status "#unsupported number of Huffman groups"
|
||||
|
||||
pri status "#internal error: inconsistent Huffman code"
|
||||
pri status "#internal error: inconsistent dst buffer"
|
||||
@@ -32,7 +34,6 @@ pri status "#internal error: inconsistent n_bits"
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x4C00_0000
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
pixfmt : base.u32,
|
||||
width : base.u32[..= 0x4000],
|
||||
height : base.u32[..= 0x4000],
|
||||
|
||||
@@ -44,12 +45,49 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
sub_chunk_has_padding : base.bool,
|
||||
|
||||
is_vp8_lossy : base.bool,
|
||||
// 0x01 = VP8 lossy
|
||||
// 0x02 = VP8L lossless
|
||||
// 0x04 = VP8X and seen VP8X chunks
|
||||
// 0x08 = VP8X and seen VP8X, ICCP chunks
|
||||
// 0x10 = VP8X and seen VP8X, ICCP†, ANIM chunks
|
||||
// 0x20 = VP8X and seen VP8X, ICCP†, ANIM†, ANMF chunks
|
||||
// 0x40 = VP8X and seen VP8X, ICCP†, ANIM†, ANMF†, ALPH chunks
|
||||
// 0x81 = VP8X and seen VP8X, ICCP†, ANIM†, ANMF†, ALPH†, VP8 chunks
|
||||
// 0x82 = VP8X and seen VP8X, ICCP†, ANIM†, ANMF†, ALPH†, VP8L chunks
|
||||
//
|
||||
// Chunks marked with a † are optional.
|
||||
variant : base.u8,
|
||||
|
||||
// The "Rsv|I|L|E|X|A|R" bits from
|
||||
// https://developers.google.com/speed/webp/docs/riff_container#extended_file_format
|
||||
//
|
||||
// We also re-purpose the otherwise-unused 0x01 bit to mean VP8X-ness,
|
||||
// so that (vp8x_header_flags <> 0) is an easy check for VP8X versus
|
||||
// not-VP8X. Similarly, ((vp8x_header_flags & 0x11) == 0x01) is an easy
|
||||
// check for "VP8X without an ALPH chunk".
|
||||
//
|
||||
// See also libwebp's src/webp/mux_types.h:
|
||||
//
|
||||
// ANIMATION_FLAG = 0x00000002,
|
||||
// XMP_FLAG = 0x00000004,
|
||||
// EXIF_FLAG = 0x00000008,
|
||||
// ALPHA_FLAG = 0x00000010,
|
||||
// ICCP_FLAG = 0x00000020,
|
||||
vp8x_header_flags : base.u8,
|
||||
|
||||
// The "Rsv| P | F | C" bits from
|
||||
// https://developers.google.com/speed/webp/docs/riff_container#alpha
|
||||
//
|
||||
// We also re-purpose the otherwise-unused 0x02 bit to mean that we
|
||||
// have seen the ALPH chunk.
|
||||
vp8x_alph_flags : base.u8,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
riff_chunk_length : base.u32,
|
||||
rcl_remaining : base.u32,
|
||||
sub_chunk_length : base.u32,
|
||||
sub_chunk_type : base.u32,
|
||||
|
||||
bits : base.u32,
|
||||
n_bits : base.u32[..= 31],
|
||||
@@ -180,12 +218,13 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
if (this.riff_chunk_length & 1) <> 0 {
|
||||
return "#bad header"
|
||||
}
|
||||
this.rcl_remaining = this.riff_chunk_length
|
||||
|
||||
while true {
|
||||
io_limit (io: args.src, limit: this.riff_chunk_length as base.u64) {
|
||||
io_limit (io: args.src, limit: this.rcl_remaining as base.u64) {
|
||||
r_mark = args.src.mark()
|
||||
status =? this.do_decode_image_config_limited?(dst: args.dst, src: args.src)
|
||||
this.riff_chunk_length ~sat-=
|
||||
this.rcl_remaining ~sat-=
|
||||
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
|
||||
@@ -193,7 +232,7 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
break
|
||||
} else if not status.is_suspension() {
|
||||
return status
|
||||
} else if (status == base."$short read") and (this.riff_chunk_length == 0) {
|
||||
} else if (status == base."$short read") and (this.rcl_remaining == 0) {
|
||||
return "#short chunk"
|
||||
}
|
||||
yield? status
|
||||
@@ -201,9 +240,9 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
|
||||
if (not this.is_vp8_lossy) and (args.dst <> nullptr) {
|
||||
if (this.variant <> 0x01) and (args.dst <> nullptr) {
|
||||
args.dst.set!(
|
||||
pixfmt: this.pixfmt,
|
||||
pixfmt: base.PIXEL_FORMAT__BGRA_NONPREMUL,
|
||||
pixsub: 0,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
@@ -226,35 +265,37 @@ pri func decoder.do_decode_image_config_limited?(dst: nptr base.image_config, sr
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
if c32 == 'VP8 'le {
|
||||
this.is_vp8_lossy = true
|
||||
this.variant = 0x01
|
||||
} else if c32 == 'VP8L'le {
|
||||
// No-op.
|
||||
this.variant = 0x02
|
||||
} else if c32 == 'VP8X'le {
|
||||
return "#unsupported WebP file"
|
||||
this.variant = 0x04
|
||||
} else {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
this.sub_chunk_length = args.src.read_u32le?()
|
||||
if this.sub_chunk_length < 4 {
|
||||
return "#bad header"
|
||||
}
|
||||
this.sub_chunk_has_padding = (this.sub_chunk_length & 1) <> 0
|
||||
|
||||
if this.is_vp8_lossy {
|
||||
if this.variant == 0x01 {
|
||||
this.vp8.set_quirk!(
|
||||
key: base.QUIRK_SOURCE_LENGTH,
|
||||
value: ((this.sub_chunk_length as base.u64) << 1) | 1)
|
||||
|
||||
} else if this.variant == 0x02 {
|
||||
// No-op.
|
||||
} else if this.sub_chunk_length <> 10 {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
while true {
|
||||
io_limit (io: args.src, limit: this.sub_chunk_length as base.u64) {
|
||||
r_mark = args.src.mark()
|
||||
if this.is_vp8_lossy {
|
||||
if this.variant == 0x01 {
|
||||
status =? this.vp8.decode_image_config?(dst: args.dst, src: args.src)
|
||||
} else {
|
||||
} else if this.variant == 0x02 {
|
||||
status =? this.do_decode_image_config_limited_vp8l?(src: args.src)
|
||||
} else {
|
||||
status =? this.do_decode_image_config_limited_vp8x?(src: args.src)
|
||||
}
|
||||
this.sub_chunk_length ~sat-=
|
||||
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
|
||||
@@ -284,10 +325,10 @@ pri func decoder.do_decode_image_config_limited_vp8l?(src: base.io_reader) {
|
||||
c32 >>= 14
|
||||
this.height = (c32 & 0x3FFF) + 1
|
||||
c32 >>= 14
|
||||
this.pixfmt = base.PIXEL_FORMAT__BGRX
|
||||
if (c32 & 1) <> 0 {
|
||||
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
}
|
||||
// In theory, (c32 & 1) would let us discriminate between
|
||||
// base.PIXEL_FORMAT__BGRX and base.PIXEL_FORMAT__BGRA_NONPREMUL, but the
|
||||
// VP8 Lossless spec says that this bit "is a hint only, and *should not
|
||||
// impact decoding* [emphasis added]".
|
||||
c32 >>= 1
|
||||
if c32 <> 0 {
|
||||
return "#bad header"
|
||||
@@ -300,11 +341,90 @@ pri func decoder.do_decode_image_config_limited_vp8l?(src: base.io_reader) {
|
||||
this.workbuf_offset_for_transform[3] = (4 * this.width * this.height) + (3 * transform_size)
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_image_config_limited_vp8x?(src: base.io_reader) {
|
||||
var c32 : base.u32
|
||||
var transform_size : base.u32[..= 0x400_0000]
|
||||
var status : base.status
|
||||
|
||||
c32 = args.src.read_u32le?()
|
||||
if (c32 & 0xFFFF_FFC1) <> 0 {
|
||||
return "#unsupported WebP file"
|
||||
}
|
||||
this.vp8x_header_flags = ((c32 | 0x01) & 0xFF) as base.u8
|
||||
|
||||
c32 = args.src.read_u24le_as_u32?()
|
||||
if c32 >= 0x3FFF {
|
||||
return "#unsupported WebP file"
|
||||
}
|
||||
this.width = (c32 & 0x3FFF) + 1
|
||||
|
||||
c32 = args.src.read_u24le_as_u32?()
|
||||
if c32 >= 0x3FFF {
|
||||
return "#unsupported WebP file"
|
||||
}
|
||||
this.height = (c32 & 0x3FFF) + 1
|
||||
|
||||
// It's valid to call this.workbuf_len after this.decode_image_config
|
||||
// returns, for the caller to know how much dynamically-sized memory
|
||||
// (called workbuf memory) is needed to decode the image file.
|
||||
//
|
||||
// Unfortunately, having only seen the VP8X chunk, we don't know yet
|
||||
// whether it's ultimately a VP8 or VP8L image, but we wouldn't know until
|
||||
// after we've processed the ALPH chunk (if present), and processing the
|
||||
// ALPH chunk requires workbuf memory (as the amount of memory depends on
|
||||
// this.width and this.height).
|
||||
//
|
||||
// Wuffs' "decode an image" API assumes that the caller, not callee, is
|
||||
// responsible for dynamically allocating memory. But also, it only assumes
|
||||
// sequential access (not random access) to the io_reader.
|
||||
//
|
||||
// So, here, we have to cater for the worst case and set aside workbuf
|
||||
// memory just like plain VP8L, even if it might end up being unused, for
|
||||
// example: VP8X+VP8 instead of VP8X+VP8L or VP8X+ALPH+VP8.
|
||||
transform_size = 4 * ((this.width + 3) >> 2) * ((this.height + 3) >> 2)
|
||||
this.workbuf_offset_for_transform[0] = (4 * this.width * this.height) + (0 * transform_size)
|
||||
this.workbuf_offset_for_transform[1] = (4 * this.width * this.height) + (1 * transform_size)
|
||||
this.workbuf_offset_for_transform[2] = (4 * this.width * this.height) + (2 * transform_size)
|
||||
this.workbuf_offset_for_transform[3] = (4 * this.width * this.height) + (3 * transform_size)
|
||||
|
||||
// The RIFF chunk length (which we have seen) is an upper bound for the VP8
|
||||
// sub-chunk length (which we haven't seen yet). Set this now so that
|
||||
// this.vp8.workbuf_len will return something definitive (non-empty).
|
||||
//
|
||||
// TODO: for animated WebP images, this upper bound essentially allocates
|
||||
// O(numberOfAnimationFrames) memory. Ideally, it'd be O(1) instead.
|
||||
//
|
||||
// This might need tweaking the semantics of the wuffs_base__image_decoder
|
||||
// API (which applies to multiple image formats, not just WebP). The API is
|
||||
// that you can call workbuf_len as soon as decode_image_config returns.
|
||||
// workbuf_len returns a range and any value within that range should be a
|
||||
// valid length for the "dynamically allocated, not O(1) in terms of width
|
||||
// and height" workbuf memory passed to decode_frame.
|
||||
//
|
||||
// We could relax this so that decode_frame could return a "$short workbuf"
|
||||
// suspension, if the workbuf length is unknown at the time of the first
|
||||
// decode_frame call, and the caller is expected to essentially realloc the
|
||||
// workbuf, keeping any existing contents when growing it.
|
||||
status = this.vp8.set_quirk!(
|
||||
key: base.QUIRK_SOURCE_LENGTH,
|
||||
value: ((this.riff_chunk_length as base.u64) << 1) | 1)
|
||||
if not status.is_ok() {
|
||||
return "#unsupported WebP file"
|
||||
}
|
||||
|
||||
status = this.vp8.set_quirk!(
|
||||
key: vp8.QUIRK_WIDTH_AND_HEIGHT,
|
||||
value: ((this.width as base.u64) | ((this.height as base.u64) << 32)))
|
||||
if not status.is_ok() {
|
||||
return "#unsupported WebP file"
|
||||
}
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
if this.is_vp8_lossy {
|
||||
if this.variant == 0x01 {
|
||||
status =? this.vp8.decode_frame_config?(dst: args.dst, src: args.src)
|
||||
} else {
|
||||
status =? this.do_decode_frame_config?(dst: args.dst, src: args.src)
|
||||
@@ -317,8 +437,6 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
var pixfmt : base.pixel_format
|
||||
|
||||
if this.call_sequence == 0x20 {
|
||||
// No-op.
|
||||
} else if this.call_sequence < 0x20 {
|
||||
@@ -334,8 +452,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
pixfmt = this.util.make_pixel_format(repr: this.pixfmt)
|
||||
if (this.variant <> 0x01) and (args.dst <> nullptr) {
|
||||
args.dst.set!(bounds: this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
@@ -347,7 +464,7 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
|
||||
disposal: 0,
|
||||
opaque_within_bounds: false,
|
||||
overwrite_instead_of_blend: false,
|
||||
background_color: pixfmt.default_background_color())
|
||||
background_color: 0x0000_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 0x40
|
||||
@@ -357,11 +474,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
var status : base.status
|
||||
|
||||
while true {
|
||||
if this.is_vp8_lossy {
|
||||
status =? this.vp8.decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
||||
} else {
|
||||
status =? this.do_decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
||||
}
|
||||
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"
|
||||
}
|
||||
@@ -370,17 +483,8 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
|
||||
}
|
||||
|
||||
pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var c8 : base.u8
|
||||
var has_more : base.u32[..= 1]
|
||||
var width : base.u32[..= 0x4000]
|
||||
var dst : slice base.u8
|
||||
var tile_data : roslice base.u8
|
||||
var status : base.status
|
||||
var pix : slice base.u8
|
||||
var which : base.u32[..= 4]
|
||||
var transform_type : base.u32[..= 3]
|
||||
var ti : base.u64
|
||||
var tj : base.u64
|
||||
var r_mark : base.u64
|
||||
var status : base.status
|
||||
|
||||
if this.call_sequence == 0x40 {
|
||||
// No-op.
|
||||
@@ -390,454 +494,106 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
this.seen_transform[0] = false
|
||||
this.seen_transform[1] = false
|
||||
this.seen_transform[2] = false
|
||||
this.seen_transform[3] = false
|
||||
this.n_transforms = 0
|
||||
|
||||
while true {
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
while (this.variant & 0x03) == 0 {
|
||||
this.sub_chunk_type = args.src.read_u32le?()
|
||||
this.sub_chunk_length = args.src.read_u32le?()
|
||||
this.sub_chunk_has_padding = (this.sub_chunk_length & 1) <> 0
|
||||
if this.sub_chunk_length > 0x7FFF_FFFF {
|
||||
return "#unsupported WebP file"
|
||||
}
|
||||
has_more = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if has_more == 0 {
|
||||
if this.sub_chunk_type == 'ICCP'le {
|
||||
if this.variant > 0x04 {
|
||||
return "#bad chunk order"
|
||||
} else if (this.vp8x_header_flags & 0x20) == 0 {
|
||||
return "#bad VP8X chunk"
|
||||
}
|
||||
this.variant = 0x08
|
||||
|
||||
} else if this.sub_chunk_type == 'ANIM'le {
|
||||
if this.variant > 0x08 {
|
||||
return "#bad chunk order"
|
||||
} else if (this.vp8x_header_flags & 0x02) == 0 {
|
||||
return "#bad VP8X chunk"
|
||||
}
|
||||
this.variant = 0x10
|
||||
|
||||
} else if this.sub_chunk_type == 'ANMF'le {
|
||||
if this.variant > 0x10 {
|
||||
return "#bad chunk order"
|
||||
} else if (this.vp8x_header_flags & 0x02) == 0 {
|
||||
return "#bad VP8X chunk"
|
||||
}
|
||||
this.variant = 0x20
|
||||
|
||||
} else if this.sub_chunk_type == 'ALPH'le {
|
||||
if this.variant > 0x20 {
|
||||
return "#bad chunk order"
|
||||
} else if (this.vp8x_header_flags & 0x10) == 0 {
|
||||
return "#bad VP8X chunk"
|
||||
}
|
||||
this.variant = 0x40
|
||||
this.decode_alph?(src: args.src, workbuf: args.workbuf)
|
||||
this.vp8.set_quirk!(
|
||||
key: vp8.QUIRK_HAS_ALPHA_SIDE_CHANNEL,
|
||||
value: 1)
|
||||
|
||||
} else if this.sub_chunk_type == 'VP8 'le {
|
||||
this.vp8.set_quirk!(
|
||||
key: base.QUIRK_SOURCE_LENGTH,
|
||||
value: ((this.sub_chunk_length as base.u64) << 1) | 1)
|
||||
this.variant = 0x81
|
||||
break
|
||||
|
||||
} else if this.sub_chunk_type == 'VP8L'le {
|
||||
if (this.vp8x_header_flags & 0x10) <> 0 {
|
||||
return "#bad ALPH+VP8L combination"
|
||||
}
|
||||
this.variant = 0x82
|
||||
break
|
||||
|
||||
} else if this.sub_chunk_type == 'XMP 'le {
|
||||
if (this.vp8x_header_flags & 0x04) == 0 {
|
||||
return "#bad VP8X chunk"
|
||||
}
|
||||
|
||||
} else if this.sub_chunk_type == 'EXIF'le {
|
||||
if (this.vp8x_header_flags & 0x08) == 0 {
|
||||
return "#bad VP8X chunk"
|
||||
}
|
||||
}
|
||||
this.decode_transform?(src: args.src, workbuf: args.workbuf)
|
||||
}
|
||||
|
||||
width = this.width
|
||||
if this.seen_transform[3] {
|
||||
width = this.color_indexing_width
|
||||
args.src.skip_u32?(n: this.sub_chunk_length)
|
||||
if this.sub_chunk_has_padding {
|
||||
args.src.skip_u32?(n: 1)
|
||||
}
|
||||
}
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.overall_color_cache_bits = this.color_cache_bits
|
||||
this.decode_hg_table?(src: args.src, width: width, workbuf: args.workbuf)
|
||||
this.color_cache_bits = this.overall_color_cache_bits
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: this.overall_n_huffman_groups)
|
||||
|
||||
while true {
|
||||
if ((this.workbuf_offset_for_color_indexing as base.u64) > (this.workbuf_offset_for_transform[0] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) or
|
||||
((this.workbuf_offset_for_transform[0] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
io_limit (io: args.src, limit: this.sub_chunk_length as base.u64) {
|
||||
r_mark = args.src.mark()
|
||||
if (this.variant & 0x01) <> 0 {
|
||||
status =? this.vp8.decode_frame?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
||||
} else {
|
||||
status =? this.do_decode_frame_vp8l?(dst: args.dst, src: args.src, blend: args.blend, workbuf: args.workbuf, opts: args.opts)
|
||||
}
|
||||
this.sub_chunk_length ~sat-=
|
||||
(args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32
|
||||
}
|
||||
dst = args.workbuf[
|
||||
(this.workbuf_offset_for_color_indexing as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[0] as base.u64)]
|
||||
tile_data = args.workbuf[
|
||||
(this.workbuf_offset_for_transform[0] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[1] as base.u64)]
|
||||
status =? this.decode_pixels?(
|
||||
dst: dst,
|
||||
src: args.src,
|
||||
width: width,
|
||||
height: this.height,
|
||||
tile_data: tile_data,
|
||||
tile_size_log2: this.overall_tile_size_log2)
|
||||
|
||||
if status.is_ok() {
|
||||
break
|
||||
} else if not status.is_suspension() {
|
||||
return status
|
||||
} else if (status == base."$short read") and (this.sub_chunk_length == 0) {
|
||||
return "#short chunk"
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
if (this.workbuf_offset_for_transform[0] as base.u64) > args.workbuf.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
pix = args.workbuf[.. (this.workbuf_offset_for_transform[0] as base.u64)]
|
||||
|
||||
which = this.n_transforms
|
||||
while which > 0 {
|
||||
which -= 1
|
||||
transform_type = this.transform_type[which] as base.u32
|
||||
|
||||
tile_data = this.util.empty_slice_u8()
|
||||
if transform_type < 2 {
|
||||
ti = this.workbuf_offset_for_transform[transform_type + 1] as base.u64
|
||||
tj = this.workbuf_offset_for_transform[transform_type + 2] as base.u64
|
||||
if (ti <= tj) and (tj <= args.workbuf.length()) {
|
||||
tile_data = args.workbuf[ti .. tj]
|
||||
}
|
||||
}
|
||||
|
||||
if transform_type == 0 {
|
||||
this.apply_transform_predictor!(pix: pix, tile_data: tile_data)
|
||||
} else if transform_type == 1 {
|
||||
this.apply_transform_cross_color!(pix: pix, tile_data: tile_data)
|
||||
} else if transform_type == 2 {
|
||||
this.apply_transform_subtract_green!(pix: pix)
|
||||
} else {
|
||||
this.apply_transform_color_indexing!(pix: pix)
|
||||
width = this.width
|
||||
}
|
||||
}
|
||||
|
||||
status = this.swizzle!(
|
||||
dst: args.dst,
|
||||
src: pix,
|
||||
blend: args.blend)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
this.call_sequence = 0x60
|
||||
}
|
||||
|
||||
pri func decoder.decode_transform?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
var status : base.status
|
||||
var c8 : base.u8
|
||||
var transform_type : base.u32[..= 3]
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var p : slice base.u8
|
||||
|
||||
if this.n_bits < 2 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 2 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 2
|
||||
}
|
||||
transform_type = this.bits & 3
|
||||
this.bits >>= 2
|
||||
this.n_bits -= 2
|
||||
|
||||
if this.seen_transform[transform_type] or (this.n_transforms >= 4) {
|
||||
return "#bad transform"
|
||||
} else if this.seen_transform[3] {
|
||||
return "#unsupported transform after color indexing transform"
|
||||
}
|
||||
this.seen_transform[transform_type] = true
|
||||
this.transform_type[this.n_transforms] = transform_type as base.u8
|
||||
this.n_transforms += 1
|
||||
|
||||
if transform_type < 2 { // Predictor, Cross Color transform.
|
||||
if this.n_bits < 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 3 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 3
|
||||
}
|
||||
tile_size_log2 = (this.bits & 7) + 2
|
||||
this.transform_tile_size_log2[transform_type] = tile_size_log2 as base.u8
|
||||
this.bits >>= 3
|
||||
this.n_bits -= 3
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
|
||||
while true,
|
||||
inv transform_type < 2,
|
||||
inv tile_size_log2 >= 2,
|
||||
{
|
||||
if ((this.workbuf_offset_for_transform[transform_type + 1] as base.u64) > (this.workbuf_offset_for_transform[transform_type + 2] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[transform_type + 2] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
status =? this.decode_pixels?(
|
||||
dst: args.workbuf[
|
||||
(this.workbuf_offset_for_transform[transform_type + 1] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[transform_type + 2] as base.u64)],
|
||||
src: args.src,
|
||||
width: (this.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
height: (this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
} else if transform_type == 2 { // Subtract Green transform.
|
||||
// No-op.
|
||||
|
||||
} else { // Color Indexing transform.
|
||||
if this.n_bits < 8 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 8 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 8
|
||||
}
|
||||
this.color_indexing_palette_size = (this.bits & 0xFF) + 1
|
||||
this.bits >>= 8
|
||||
this.n_bits -= 8
|
||||
|
||||
if this.color_indexing_palette_size <= 2 {
|
||||
this.color_indexing_width = (this.width + 7) / 8
|
||||
this.transform_tile_size_log2[3] = 3
|
||||
} else if this.color_indexing_palette_size <= 4 {
|
||||
this.color_indexing_width = (this.width + 3) / 4
|
||||
this.transform_tile_size_log2[3] = 2
|
||||
} else if this.color_indexing_palette_size <= 16 {
|
||||
this.color_indexing_width = (this.width + 1) / 2
|
||||
this.transform_tile_size_log2[3] = 1
|
||||
} else {
|
||||
this.color_indexing_width = this.width
|
||||
this.transform_tile_size_log2[3] = 0
|
||||
}
|
||||
|
||||
if this.width >= this.color_indexing_width {
|
||||
this.workbuf_offset_for_color_indexing = 4 * (this.width - this.color_indexing_width) * this.height
|
||||
}
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
|
||||
this.decode_pixels?(
|
||||
dst: this.palette[.. 4 * this.color_indexing_palette_size],
|
||||
src: args.src,
|
||||
width: this.color_indexing_palette_size,
|
||||
height: 1,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
this.palette[4 * this.color_indexing_palette_size .. 1024].bulk_memset!(byte_value: 0)
|
||||
|
||||
p = this.palette[.. 4 * this.color_indexing_palette_size]
|
||||
while p.length() >= 8 {
|
||||
p[4] ~mod+= p[0]
|
||||
p[5] ~mod+= p[1]
|
||||
p[6] ~mod+= p[2]
|
||||
p[7] ~mod+= p[3]
|
||||
p = p[4 ..]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_color_cache_parameters?(src: base.io_reader) {
|
||||
var c8 : base.u8
|
||||
var use_color_cache : base.u32[..= 1]
|
||||
var color_cache_bits : base.u32[..= 15]
|
||||
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
use_color_cache = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
this.color_cache_bits = 0
|
||||
if use_color_cache <> 0 {
|
||||
if this.n_bits < 4 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 4 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 4
|
||||
}
|
||||
color_cache_bits = this.bits & 15
|
||||
this.bits >>= 4
|
||||
this.n_bits -= 4
|
||||
|
||||
if (color_cache_bits < 1) or (11 < color_cache_bits) {
|
||||
return "#bad color cache"
|
||||
}
|
||||
this.color_cache_bits = color_cache_bits
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_hg_table?(src: base.io_reader, width: base.u32[..= 0x4000], workbuf: slice base.u8) {
|
||||
var status : base.status
|
||||
var c8 : base.u8
|
||||
var use_hg_table : base.u32[..= 1]
|
||||
var tile_size_log2 : base.u32[..= 9]
|
||||
var hg_pixels : slice base.u8
|
||||
var n : base.u64
|
||||
var p : roslice base.u8
|
||||
var hg_plus_1 : base.u32[..= 256]
|
||||
|
||||
if this.n_bits < 1 {
|
||||
c8 = args.src.read_u8?()
|
||||
this.bits = (c8 as base.u32)
|
||||
this.n_bits = 8
|
||||
assert this.n_bits >= 1
|
||||
}
|
||||
use_hg_table = this.bits & 1
|
||||
this.bits >>= 1
|
||||
this.n_bits -= 1
|
||||
|
||||
if use_hg_table == 0 {
|
||||
this.overall_n_huffman_groups = 1
|
||||
this.overall_tile_size_log2 = 0
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
hg_pixels = args.workbuf[
|
||||
this.workbuf_offset_for_transform[0] as base.u64 ..
|
||||
this.workbuf_offset_for_transform[1] as base.u64]
|
||||
if hg_pixels.length() >= 4 {
|
||||
hg_pixels[0] = 0x00
|
||||
hg_pixels[1] = 0x00
|
||||
hg_pixels[2] = 0x00
|
||||
hg_pixels[3] = 0x00
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
if this.n_bits < 3 {
|
||||
c8 = args.src.read_u8?()
|
||||
if this.n_bits >= 3 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
this.bits |= (c8 as base.u32) << this.n_bits
|
||||
this.n_bits += 8
|
||||
assert this.n_bits >= 3
|
||||
}
|
||||
tile_size_log2 = (this.bits & 7) + 2
|
||||
this.bits >>= 3
|
||||
this.n_bits -= 3
|
||||
|
||||
this.overall_tile_size_log2 = tile_size_log2
|
||||
|
||||
this.decode_color_cache_parameters?(src: args.src)
|
||||
this.decode_huffman_groups?(src: args.src, n_huffman_groups: 1)
|
||||
while true,
|
||||
inv tile_size_log2 >= 2,
|
||||
{
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
status =? this.decode_pixels?(
|
||||
dst: args.workbuf[
|
||||
(this.workbuf_offset_for_transform[0] as base.u64) ..
|
||||
(this.workbuf_offset_for_transform[1] as base.u64)],
|
||||
src: args.src,
|
||||
width: (args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
height: (this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2,
|
||||
tile_data: this.util.empty_slice_u8(),
|
||||
tile_size_log2: 0)
|
||||
if status.is_ok() {
|
||||
break
|
||||
}
|
||||
yield? status
|
||||
}
|
||||
|
||||
this.overall_n_huffman_groups = 1
|
||||
if ((this.workbuf_offset_for_transform[0] as base.u64) > (this.workbuf_offset_for_transform[1] as base.u64)) or
|
||||
((this.workbuf_offset_for_transform[1] as base.u64) > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
hg_pixels = args.workbuf[
|
||||
this.workbuf_offset_for_transform[0] as base.u64 ..
|
||||
this.workbuf_offset_for_transform[1] as base.u64]
|
||||
n = (((args.width + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2) *
|
||||
((this.height + (((1 as base.u32) << tile_size_log2) - 1)) >> tile_size_log2) *
|
||||
4) as base.u64
|
||||
if n > hg_pixels.length() {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
p = hg_pixels[.. n]
|
||||
while p.length() >= 4 {
|
||||
if p[2] <> 0 {
|
||||
return "#unsupported number of Huffman groups"
|
||||
}
|
||||
hg_plus_1 = (p[1] as base.u32) + 1
|
||||
if this.overall_n_huffman_groups < hg_plus_1 {
|
||||
this.overall_n_huffman_groups = hg_plus_1
|
||||
}
|
||||
p = p[4 ..]
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_pixels?(dst: slice base.u8, src: base.io_reader, width: base.u32[..= 0x4000], height: base.u32[..= 0x4000], tile_data: roslice base.u8, tile_size_log2: base.u32[..= 9]) {
|
||||
var i : base.u32
|
||||
var n : base.u32[..= 2048]
|
||||
|
||||
i = 0
|
||||
n = (1 as base.u32) << this.color_cache_bits
|
||||
while i < n {
|
||||
assert i < 2048 via "a < b: a < c; c <= b"(c: n)
|
||||
this.color_cache[i] = 0
|
||||
i += 1
|
||||
}
|
||||
|
||||
this.decode_pixels_slow?(
|
||||
dst: args.dst,
|
||||
src: args.src,
|
||||
width: args.width,
|
||||
height: args.height,
|
||||
tile_data: args.tile_data,
|
||||
tile_size_log2: args.tile_size_log2)
|
||||
}
|
||||
|
||||
pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: roslice base.u8, blend: base.pixel_blend) base.status {
|
||||
var status : base.status
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u32[..= 32]
|
||||
var dst_bytes_per_row : base.u64
|
||||
var dst_palette : slice base.u8
|
||||
var tab : table base.u8
|
||||
var src_bytes_per_row : base.u64
|
||||
var dst : slice base.u8
|
||||
var y : base.u32
|
||||
|
||||
status = this.swizzler.prepare!(
|
||||
dst_pixfmt: args.dst.pixel_format(),
|
||||
dst_palette: args.dst.palette_or_else(fallback: this.palette[..]),
|
||||
src_pixfmt: this.util.make_pixel_format(repr: this.pixfmt),
|
||||
src_palette: this.util.empty_slice_u8(),
|
||||
blend: args.blend)
|
||||
if not status.is_ok() {
|
||||
return status
|
||||
}
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
||||
dst_pixfmt = args.dst.pixel_format()
|
||||
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
|
||||
if (dst_bits_per_pixel & 7) <> 0 {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
dst_bytes_per_pixel = dst_bits_per_pixel / 8
|
||||
dst_bytes_per_row = (this.width * dst_bytes_per_pixel) as base.u64
|
||||
dst_palette = args.dst.palette_or_else(fallback: this.palette[..])
|
||||
tab = args.dst.plane(p: 0)
|
||||
src_bytes_per_row = (this.width * 4) as base.u64
|
||||
|
||||
while src_bytes_per_row <= args.src.length() {
|
||||
dst = tab.row_u32(y: y)
|
||||
if dst_bytes_per_row < dst.length() {
|
||||
dst = dst[.. dst_bytes_per_row]
|
||||
}
|
||||
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: args.src[.. src_bytes_per_row])
|
||||
|
||||
args.src = args.src[src_bytes_per_row ..]
|
||||
y ~mod+= 1
|
||||
}
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
if this.is_vp8_lossy {
|
||||
if this.variant == 0x01 {
|
||||
return this.vp8.frame_dirty_rect()
|
||||
}
|
||||
return this.util.make_rect_ie_u32(
|
||||
@@ -852,7 +608,7 @@ pub func decoder.num_animation_loops() base.u32 {
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.is_vp8_lossy {
|
||||
if this.variant == 0x01 {
|
||||
return this.vp8.num_decoded_frame_configs()
|
||||
}
|
||||
if this.call_sequence > 0x20 {
|
||||
@@ -862,7 +618,7 @@ pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.is_vp8_lossy {
|
||||
if this.variant == 0x01 {
|
||||
return this.vp8.num_decoded_frames()
|
||||
}
|
||||
if this.call_sequence > 0x40 {
|
||||
@@ -874,7 +630,7 @@ pub func decoder.num_decoded_frames() base.u64 {
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
var status : base.status
|
||||
|
||||
if this.is_vp8_lossy {
|
||||
if this.variant == 0x01 {
|
||||
status = this.vp8.restart_frame!(index: args.index, io_position: args.io_position)
|
||||
return status
|
||||
}
|
||||
@@ -897,12 +653,30 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
if this.is_vp8_lossy {
|
||||
var r : base.range_ii_u64
|
||||
var s : base.range_ii_u64
|
||||
|
||||
if this.variant == 0x01 {
|
||||
return this.vp8.workbuf_len()
|
||||
}
|
||||
return this.util.make_range_ii_u64(
|
||||
|
||||
r = this.util.make_range_ii_u64(
|
||||
min_incl: this.workbuf_offset_for_transform[3] as base.u64,
|
||||
max_incl: this.workbuf_offset_for_transform[3] as base.u64)
|
||||
|
||||
if this.variant <> 0x02 {
|
||||
s = this.vp8.workbuf_len()
|
||||
if s.is_empty() {
|
||||
// Empty means that the workbuf_len range isn't known yet.
|
||||
return s
|
||||
}
|
||||
|
||||
r = this.util.make_range_ii_u64(
|
||||
min_incl: s.get_min_incl().max(no_less_than: r.get_min_incl()),
|
||||
max_incl: s.get_max_incl().max(no_less_than: r.get_max_incl()))
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
pri const DISTANCE_MAP : roarray[120] base.u8 = [
|
||||
|
||||
@@ -30,6 +30,7 @@ OK. d9f8441c test/3pdata/blinksuite/blue-10.png
|
||||
OK. 267741e0 test/3pdata/blinksuite/blue-100.png
|
||||
OK. 89449c01 test/3pdata/blinksuite/blue-wheel-srgb-color-profile.jpg
|
||||
OK. 8fce70a9 test/3pdata/blinksuite/blue-wheel-srgb-color-profile.png
|
||||
OK. 426a5623 test/3pdata/blinksuite/blue-wheel-srgb-color-profile.webp
|
||||
OK. 2d7bad9f test/3pdata/blinksuite/border-image-srgb-color-profile.png
|
||||
OK. 9ca73f21 test/3pdata/blinksuite/border-image.png
|
||||
OK. 277600f9 test/3pdata/blinksuite/boston.gif
|
||||
@@ -42,6 +43,8 @@ OK. 5ec78d7c test/3pdata/blinksuite/color-checker-adobe-color-profile.png
|
||||
OK. b3389858 test/3pdata/blinksuite/color-checker-srgb-color-profile.png
|
||||
OK. 10721531 test/3pdata/blinksuite/count-down-color-test.gif
|
||||
OK. 1abc4dc6 test/3pdata/blinksuite/count-down-color-test.png
|
||||
BAD d663b0e6 test/3pdata/blinksuite/count-down-color-test.webp
|
||||
OK. 18fbe8ca test/3pdata/blinksuite/crbug.364830.webp
|
||||
OK. 24ab1efd test/3pdata/blinksuite/crbug779261.gif
|
||||
OK. ae034abe test/3pdata/blinksuite/crbug807324.png
|
||||
OK. 4f50fdb0 test/3pdata/blinksuite/crbug827754.png
|
||||
@@ -66,6 +69,7 @@ OK. d97ce4e8 test/3pdata/blinksuite/cs-uma-ycbcr-other.jpg
|
||||
OK. a2a940bc test/3pdata/blinksuite/cs-uma-ycck.jpg
|
||||
OK. b6000be6 test/3pdata/blinksuite/dice.png
|
||||
BAD 1023c20a test/3pdata/blinksuite/empty-frame.png
|
||||
OK. 4a495d9f test/3pdata/blinksuite/flip.webp
|
||||
OK. eff36075 test/3pdata/blinksuite/flowchart.jpg
|
||||
OK. 20ff1df8 test/3pdata/blinksuite/full2loop.gif
|
||||
OK. dc814e29 test/3pdata/blinksuite/gif-loop-count.gif
|
||||
@@ -89,6 +93,11 @@ OK. 95641cb9 test/3pdata/blinksuite/icc-v2-gbr-420-height-not-whole-mcu.jpg
|
||||
OK. 93f21c2a test/3pdata/blinksuite/icc-v2-gbr-420-width-not-whole-mcu.jpg
|
||||
OK. f37cea44 test/3pdata/blinksuite/icc-v2-gbr-422-whole-mcus.jpg
|
||||
OK. 1de5a906 test/3pdata/blinksuite/icc-v2-gbr.jpg
|
||||
BAD 7c80a001 test/3pdata/blinksuite/invalid-animated-webp.webp
|
||||
BAD 1e37d000 test/3pdata/blinksuite/invalid-animated-webp2.webp
|
||||
BAD 97b2b706 test/3pdata/blinksuite/invalid-animated-webp3.webp
|
||||
BAD 145962c5 test/3pdata/blinksuite/invalid-animated-webp4.webp
|
||||
OK. 2ba1fc10 test/3pdata/blinksuite/invalid_vp8_vp8x.webp
|
||||
OK. 0da5f37e test/3pdata/blinksuite/jpeg-height-exif-orientation.jpg
|
||||
OK. 4409dca6 test/3pdata/blinksuite/large-gif-checkerboard.gif
|
||||
OK. d67648b6 test/3pdata/blinksuite/large.webp
|
||||
@@ -171,9 +180,24 @@ OK. 1b1f5f96 test/3pdata/blinksuite/stripes-large.png
|
||||
OK. 6b85cdb9 test/3pdata/blinksuite/stripes-small.png
|
||||
OK. 16c2c0fe test/3pdata/blinksuite/test-load.jpg
|
||||
OK. 6fbda804 test/3pdata/blinksuite/test.webp
|
||||
OK. eb16e76c test/3pdata/blinksuite/test2.webp
|
||||
OK. 19d3a207 test/3pdata/blinksuite/test3.webp
|
||||
OK. 56224156 test/3pdata/blinksuite/truncated.webp
|
||||
BAD 1dfa35c6 test/3pdata/blinksuite/truncated2.webp
|
||||
BAD b16eb1a2 test/3pdata/blinksuite/webp-animated-icc-xmp.webp
|
||||
BAD 45030792 test/3pdata/blinksuite/webp-animated-large.webp
|
||||
BAD 4519c83d test/3pdata/blinksuite/webp-animated-no-blend.webp
|
||||
BAD 4519c83d test/3pdata/blinksuite/webp-animated-opaque.webp
|
||||
BAD d26b2bd9 test/3pdata/blinksuite/webp-animated-semitransparent1.webp
|
||||
BAD 73e0b22f test/3pdata/blinksuite/webp-animated-semitransparent2.webp
|
||||
BAD d26b2bd9 test/3pdata/blinksuite/webp-animated-semitransparent3.webp
|
||||
BAD 0dba213a test/3pdata/blinksuite/webp-animated-semitransparent4.webp
|
||||
BAD ae7f1fcf test/3pdata/blinksuite/webp-animated.webp
|
||||
OK. eb191e45 test/3pdata/blinksuite/webp-color-no-profile-lossy.webp
|
||||
OK. 60116c2c test/3pdata/blinksuite/webp-color-profile-crash.webp
|
||||
BAD f234aa8a test/3pdata/blinksuite/webp-color-profile-lossless.webp
|
||||
OK. db8c197f test/3pdata/blinksuite/webp-color-profile-lossy-alpha.webp
|
||||
OK. 684e3635 test/3pdata/blinksuite/webp-color-profile-lossy.webp
|
||||
BAD ed67a9a5 test/3pdata/blinksuite/wrong-block-length.gif
|
||||
OK. 577c5c4c test/3pdata/blinksuite/ycbcr-420-fast-int-progressive.jpg
|
||||
OK. bf4cd8e2 test/3pdata/blinksuite/ycbcr-420-float-progressive.jpg
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
OK. ca4c0038 test/3pdata/webpsuite/bad_palette_index.webp
|
||||
OK. a92322d0 test/3pdata/webpsuite/alpha_color_cache.webp
|
||||
OK. 1e7a17bc test/3pdata/webpsuite/alpha_filter_0_method_0.webp
|
||||
OK. 1e7a17bc test/3pdata/webpsuite/alpha_filter_0_method_1.webp
|
||||
OK. d955c04f test/3pdata/webpsuite/alpha_filter_1.webp
|
||||
OK. 1e7a17bc test/3pdata/webpsuite/alpha_filter_1_method_0.webp
|
||||
OK. 1e7a17bc test/3pdata/webpsuite/alpha_filter_1_method_1.webp
|
||||
OK. d955c04f test/3pdata/webpsuite/alpha_filter_2.webp
|
||||
OK. 1e7a17bc test/3pdata/webpsuite/alpha_filter_2_method_0.webp
|
||||
OK. 1e7a17bc test/3pdata/webpsuite/alpha_filter_2_method_1.webp
|
||||
OK. d955c04f test/3pdata/webpsuite/alpha_filter_3.webp
|
||||
OK. 1e7a17bc test/3pdata/webpsuite/alpha_filter_3_method_0.webp
|
||||
OK. 1e7a17bc test/3pdata/webpsuite/alpha_filter_3_method_1.webp
|
||||
OK. d955c04f test/3pdata/webpsuite/alpha_no_compression.webp
|
||||
OK. 0ecfd841 test/3pdata/webpsuite/bad_palette_index.webp
|
||||
OK. 79f9ca4a test/3pdata/webpsuite/big_endian_bug_393.webp
|
||||
OK. 3dd065ab test/3pdata/webpsuite/bryce.webp
|
||||
OK. 7794c8b2 test/3pdata/webpsuite/bug3.webp
|
||||
OK. 6fbda804 test/3pdata/webpsuite/color_cache_bits_11.webp
|
||||
BAD d338aed8 test/3pdata/webpsuite/dual_transform.webp
|
||||
OK. 0fecb95b test/3pdata/webpsuite/dual_transform.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/grid.bmp
|
||||
OK. 33b7a1f3 test/3pdata/webpsuite/grid.pgm
|
||||
OK. f79224e7 test/3pdata/webpsuite/grid.png
|
||||
@@ -20,35 +34,39 @@ OK. 289af407 test/3pdata/webpsuite/lossless_color_transform.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_0.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_1.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_10.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_11.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_11.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_12.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_13.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_13.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_14.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_15.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_15.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_2.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_3.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_3.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_4.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_5.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_6.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_7.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_7.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_8.webp
|
||||
BAD df11692d test/3pdata/webpsuite/lossless_vec_1_9.webp
|
||||
OK. f79224e7 test/3pdata/webpsuite/lossless_vec_1_9.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_0.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_1.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_10.webp
|
||||
BAD 79781cfb test/3pdata/webpsuite/lossless_vec_2_11.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_11.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_12.webp
|
||||
BAD 79781cfb test/3pdata/webpsuite/lossless_vec_2_13.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_13.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_14.webp
|
||||
BAD 79781cfb test/3pdata/webpsuite/lossless_vec_2_15.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_15.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_2.webp
|
||||
BAD 79781cfb test/3pdata/webpsuite/lossless_vec_2_3.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_3.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_4.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_5.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_6.webp
|
||||
BAD 79781cfb test/3pdata/webpsuite/lossless_vec_2_7.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_7.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_8.webp
|
||||
BAD 79781cfb test/3pdata/webpsuite/lossless_vec_2_9.webp
|
||||
OK. 6706e719 test/3pdata/webpsuite/lossless_vec_2_9.webp
|
||||
OK. a62056d3 test/3pdata/webpsuite/lossy_alpha1.webp
|
||||
OK. 7d50b493 test/3pdata/webpsuite/lossy_alpha2.webp
|
||||
OK. 3a84e899 test/3pdata/webpsuite/lossy_alpha3.webp
|
||||
OK. a9d10d15 test/3pdata/webpsuite/lossy_alpha4.webp
|
||||
OK. ac62b1e6 test/3pdata/webpsuite/lossy_extreme_probabilities.webp
|
||||
OK. 84ff1fbf test/3pdata/webpsuite/lossy_q0_f100.webp
|
||||
OK. 6957defa test/3pdata/webpsuite/near_lossless_75.webp
|
||||
|
||||
+5
-1
@@ -126,7 +126,11 @@ test_wuffs_jpeg_decode_lower_quality() {
|
||||
&dec, WUFFS_BASE__QUIRK_QUALITY,
|
||||
WUFFS_BASE__QUIRK_QUALITY__VALUE__LOWER_QUALITY);
|
||||
}
|
||||
uint64_t m = wuffs_jpeg__decoder__workbuf_len(&dec).min_incl;
|
||||
wuffs_base__range_ii_u64 r = wuffs_jpeg__decoder__workbuf_len(&dec);
|
||||
if (wuffs_base__range_ii_u64__is_empty(&r)) {
|
||||
RETURN_FAIL("q=%d: indeterminate workbuf length", q);
|
||||
}
|
||||
uint64_t m = r.min_incl;
|
||||
if ((q == 0) && (m == 0)) {
|
||||
RETURN_FAIL("q=%d: have %" PRIu64 ", want non-zero", q, m);
|
||||
} else if ((q != 0) && (m != 0)) {
|
||||
|
||||
+11
-10
@@ -261,9 +261,9 @@ test_wuffs_pixel_buffer_fill_rect() {
|
||||
// Reset to transparent black (or its closest approximation).
|
||||
for (uint32_t y = 0; y < height; y++) {
|
||||
for (uint32_t x = 0; x < width; x++) {
|
||||
CHECK_STATUS(
|
||||
"set_color_u32_at",
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(&dst_pixbuf, x, y, 0));
|
||||
CHECK_STATUS("set_color_u32_argb_premul_at",
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
&dst_pixbuf, x, y, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,9 +275,10 @@ test_wuffs_pixel_buffer_fill_rect() {
|
||||
1 + (height / 2))
|
||||
: wuffs_base__make_rect_ie_u32(width / 2, 0,
|
||||
1 + (width / 2), height);
|
||||
CHECK_STATUS("set_color_u32_fill_rect",
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
&dst_pixbuf, rect, dsts[d].color));
|
||||
CHECK_STATUS(
|
||||
"set_color_u32_argb_premul_fill_rect",
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
&dst_pixbuf, rect, dsts[d].color));
|
||||
|
||||
// Check the middle dst pixel.
|
||||
wuffs_base__color_u32_argb_premul want_dst_pixel = dsts[d].color;
|
||||
@@ -447,8 +448,8 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
}
|
||||
|
||||
// Set and check the middle src pixel.
|
||||
CHECK_STATUS("set_color_u32_at",
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
CHECK_STATUS("set_color_u32_argb_premul_at",
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
&src_pixbuf, width / 2, height / 2, srcs[s].color));
|
||||
wuffs_base__color_u32_argb_premul have_src_pixel =
|
||||
wuffs_base__pixel_buffer__color_u32_at(&src_pixbuf, width / 2,
|
||||
@@ -483,8 +484,8 @@ test_wuffs_pixel_swizzler_swizzle() {
|
||||
|
||||
for (size_t b = 0; b < WUFFS_TESTLIB_ARRAY_SIZE(blends); b++) {
|
||||
// Set the middle dst pixel.
|
||||
CHECK_STATUS("set_color_u32_at",
|
||||
wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
CHECK_STATUS("set_color_u32_argb_premul_at",
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_at(
|
||||
&dst_pixbuf, width / 2, height / 2, dsts[d].color));
|
||||
|
||||
// Swizzle.
|
||||
|
||||
+204
-2
@@ -114,6 +114,20 @@ test_wuffs_webp_decode_interface_lossy() {
|
||||
"test/data/bricks-color.lossy.webp", 0, SIZE_MAX, 160, 120, 0xFF032665);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_webp_decode_interface_vp8x_alpha_lossy() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_webp__decoder* dec = &g_webp_decoder;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_webp__decoder__initialize(
|
||||
dec, sizeof *dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__image_decoder(
|
||||
wuffs_webp__decoder__upcast_as__wuffs_base__image_decoder(dec),
|
||||
"test/data/hippopotamus.masked-with-muybridge.lossy.webp", 0, SIZE_MAX,
|
||||
36, 28, 0x7D787878);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_webp_decode_many_small_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -159,10 +173,14 @@ test_wuffs_webp_decode_many_small_reads() {
|
||||
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
|
||||
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
|
||||
&pb, &ic.pixcfg, g_pixel_slice_u8));
|
||||
wuffs_base__pixel_buffer__set_color_u32_fill_rect(
|
||||
wuffs_base__pixel_buffer__set_color_u32_argb_premul_fill_rect(
|
||||
&pb, wuffs_base__make_rect_ie_u32(0, 0, w, h), 0xFF234567);
|
||||
|
||||
uint64_t m = wuffs_webp__decoder__workbuf_len(dec).min_incl;
|
||||
wuffs_base__range_ii_u64 r = wuffs_webp__decoder__workbuf_len(dec);
|
||||
if (wuffs_base__range_ii_u64__is_empty(&r)) {
|
||||
RETURN_FAIL("workbuf_len: indeterminate workbuf length");
|
||||
}
|
||||
uint64_t m = r.min_incl;
|
||||
wuffs_base__slice_u8 workbuf = g_work_slice_u8;
|
||||
if (workbuf.len > m) {
|
||||
workbuf.len = m;
|
||||
@@ -207,6 +225,188 @@ test_wuffs_webp_decode_many_small_reads() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_webp_decode_filter_alph() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
const int width = 41;
|
||||
const int height = 6;
|
||||
|
||||
// src is arbitrary bytes, a subset of a noise texture.
|
||||
const uint8_t src[1][246] = {
|
||||
{
|
||||
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,
|
||||
},
|
||||
};
|
||||
|
||||
const uint8_t wants[3][246] = {
|
||||
{
|
||||
0x3C, 0x10, 0xC6, 0x3D, 0xA1, 0x4C, 0x3B, 0x3E, 0xBB, 0xEA, 0xAA,
|
||||
0xCE, 0x47, 0x85, 0x0C, 0xA6, 0xDC, 0x5B, 0x17, 0x07, 0x49, 0xF8,
|
||||
0x25, 0x88, 0xAA, 0x6D, 0xBB, 0xEE, 0xD7, 0x3E, 0xDA, 0xDB, 0x84,
|
||||
0xA7, 0xF7, 0xD4, 0x0A, 0x30, 0x7B, 0x0F, 0xEB,
|
||||
|
||||
0x50, 0x4B, 0x92, 0xF1, 0xE3, 0xF6, 0x49, 0x30, 0x07, 0x2F, 0xB9,
|
||||
0xC0, 0x86, 0xDA, 0xBF, 0x74, 0x82, 0xFA, 0xA8, 0xBC, 0x40, 0x00,
|
||||
0x20, 0x9D, 0x32, 0x1C, 0x22, 0xAC, 0xA6, 0x69, 0xD9, 0x35, 0xDB,
|
||||
0x63, 0x2F, 0x38, 0xF2, 0x98, 0x00, 0x1E, 0xD1,
|
||||
|
||||
0xAA, 0x4F, 0xB7, 0xB4, 0xCC, 0x5C, 0xCC, 0x06, 0xF6, 0x55, 0x1F,
|
||||
0x63, 0x8E, 0xE6, 0xF8, 0xB5, 0xF8, 0x59, 0x09, 0xA6, 0xB4, 0xF3,
|
||||
0xDF, 0x95, 0xCB, 0x39, 0xCD, 0xAB, 0xDA, 0xA8, 0x1F, 0xB1, 0xC2,
|
||||
0xA4, 0xDB, 0x5C, 0xFC, 0x42, 0x0F, 0xEE, 0x91,
|
||||
|
||||
0xAF, 0x46, 0x22, 0x95, 0x79, 0xAE, 0x1B, 0x0D, 0xD4, 0xF1, 0x47,
|
||||
0xC2, 0x90, 0xBA, 0xD1, 0x25, 0x0E, 0x2F, 0xAD, 0xFB, 0xE6, 0x21,
|
||||
0x1A, 0x61, 0x2B, 0xA0, 0x59, 0x32, 0x3D, 0x97, 0xBE, 0x48, 0x95,
|
||||
0x8A, 0xA9, 0x60, 0xEE, 0xBE, 0x62, 0x8A, 0x0B,
|
||||
|
||||
0x88, 0xBA, 0x9E, 0x41, 0xD0, 0x35, 0x0D, 0xA8, 0xEA, 0x9C, 0xA0,
|
||||
0x2B, 0x44, 0x02, 0x9D, 0x9D, 0xEE, 0x10, 0x41, 0x37, 0xB3, 0x72,
|
||||
0x8C, 0xF8, 0xA8, 0xE4, 0x47, 0x51, 0x4A, 0x9D, 0xB2, 0x45, 0xAC,
|
||||
0x64, 0xAF, 0xB0, 0xA4, 0x26, 0xE4, 0xF5, 0xF2,
|
||||
|
||||
0xE9, 0xAD, 0x51, 0xA8, 0x15, 0x41, 0x1E, 0x0B, 0xBC, 0x4E, 0xB1,
|
||||
0x59, 0x3B, 0x70, 0x38, 0xB7, 0x8C, 0x29, 0x72, 0xF7, 0xA5, 0x87,
|
||||
0xC8, 0xD4, 0xD2, 0x48, 0x0D, 0x2D, 0x72, 0x1E, 0x4E, 0x19, 0x8C,
|
||||
0xB0, 0x9F, 0x79, 0xF9, 0xA4, 0x02, 0x8B, 0xF9,
|
||||
},
|
||||
|
||||
{
|
||||
0x3C, 0x10, 0xC6, 0x3D, 0xA1, 0x4C, 0x3B, 0x3E, 0xBB, 0xEA, 0xAA,
|
||||
0xCE, 0x47, 0x85, 0x0C, 0xA6, 0xDC, 0x5B, 0x17, 0x07, 0x49, 0xF8,
|
||||
0x25, 0x88, 0xAA, 0x6D, 0xBB, 0xEE, 0xD7, 0x3E, 0xDA, 0xDB, 0x84,
|
||||
0xA7, 0xF7, 0xD4, 0x0A, 0x30, 0x7B, 0x0F, 0xEB,
|
||||
|
||||
0x50, 0x0B, 0x0D, 0x9C, 0x93, 0x5F, 0x8E, 0x25, 0x92, 0x12, 0x34,
|
||||
0xD5, 0x0D, 0xD9, 0xF1, 0x5B, 0xEA, 0xD3, 0xC5, 0x1B, 0xCD, 0xB8,
|
||||
0x45, 0x05, 0x3F, 0x57, 0xC1, 0x78, 0xD1, 0x01, 0x4A, 0x37, 0x2A,
|
||||
0x2F, 0xC3, 0xDD, 0xC4, 0xD6, 0xE3, 0x2D, 0x9E,
|
||||
|
||||
0xAA, 0xB0, 0x75, 0x99, 0xAB, 0xEF, 0xFE, 0x5F, 0x82, 0x71, 0xFE,
|
||||
0x19, 0x38, 0x31, 0x03, 0x18, 0x2D, 0x34, 0x75, 0xB8, 0xDB, 0xF7,
|
||||
0x31, 0xBB, 0x75, 0xC5, 0x55, 0x56, 0x00, 0xCF, 0xC1, 0xC9, 0x3B,
|
||||
0x11, 0xFA, 0x5E, 0x64, 0x1C, 0xB0, 0x0C, 0x41,
|
||||
|
||||
0xAF, 0x47, 0x51, 0x0C, 0x8F, 0x24, 0x6B, 0x51, 0x49, 0x8E, 0x54,
|
||||
0x94, 0x06, 0x5B, 0x1A, 0x6C, 0x16, 0x55, 0xF3, 0x06, 0xC6, 0x32,
|
||||
0x2A, 0x02, 0x3F, 0x3A, 0x0E, 0x2F, 0x0B, 0x29, 0xE8, 0x53, 0x88,
|
||||
0x06, 0x19, 0x15, 0xF2, 0xEC, 0x54, 0x34, 0xC2,
|
||||
|
||||
0x88, 0x79, 0x35, 0xAF, 0x1E, 0x89, 0x43, 0xEC, 0x8B, 0x40, 0x58,
|
||||
0x1F, 0x1F, 0x19, 0xB5, 0x6C, 0x67, 0x77, 0x24, 0xFC, 0x42, 0xF1,
|
||||
0x44, 0x6E, 0xEF, 0x76, 0x71, 0x39, 0x04, 0x7C, 0xFD, 0xE6, 0xEF,
|
||||
0xBE, 0x64, 0x16, 0xE6, 0x6E, 0x12, 0x45, 0xBF,
|
||||
|
||||
0xE9, 0x3D, 0xD9, 0x06, 0x8B, 0xB5, 0x20, 0xD9, 0x3C, 0xD2, 0xBB,
|
||||
0xC7, 0x01, 0x4E, 0x7D, 0xEB, 0x3C, 0x14, 0x6D, 0x81, 0xF0, 0xD3,
|
||||
0x85, 0x7A, 0xED, 0xEC, 0x36, 0x59, 0x49, 0x28, 0x2D, 0xB1, 0x62,
|
||||
0xE2, 0x53, 0xF0, 0x66, 0x19, 0x70, 0xCE, 0x2D,
|
||||
},
|
||||
|
||||
{
|
||||
0x3C, 0x10, 0xC6, 0x3D, 0xA1, 0x4C, 0x3B, 0x3E, 0xBB, 0xEA, 0xAA,
|
||||
0xCE, 0x47, 0x85, 0x0C, 0xA6, 0xDC, 0x5B, 0x17, 0x07, 0x49, 0xF8,
|
||||
0x25, 0x88, 0xAA, 0x6D, 0xBB, 0xEE, 0xD7, 0x3E, 0xDA, 0xDB, 0x84,
|
||||
0xA7, 0xF7, 0xD4, 0x0A, 0x30, 0x7B, 0x0F, 0xEB,
|
||||
|
||||
0x50, 0x1F, 0x1C, 0x5F, 0xB5, 0x73, 0xB5, 0x9F, 0xD6, 0x27, 0x8A,
|
||||
0xB5, 0xF4, 0x53, 0xE5, 0xB4, 0xF8, 0xEF, 0x59, 0x5D, 0x23, 0x92,
|
||||
0x20, 0x00, 0xB7, 0x64, 0xB8, 0x75, 0x58, 0xC3, 0x6F, 0xCC, 0x1B,
|
||||
0xC6, 0xCB, 0xB1, 0xBA, 0x86, 0x39, 0x1E, 0xAD,
|
||||
|
||||
0xAA, 0x1E, 0x83, 0xC3, 0x17, 0x90, 0x42, 0x66, 0x8D, 0x5F, 0x8C,
|
||||
0xFB, 0x2A, 0x58, 0xFC, 0x88, 0x0F, 0x67, 0xB0, 0x51, 0x25, 0xD3,
|
||||
0x4D, 0xE3, 0x35, 0x6E, 0x56, 0xF1, 0x03, 0x3C, 0x77, 0x66, 0x11,
|
||||
0x9E, 0xDA, 0x41, 0xEA, 0xFC, 0x7C, 0x40, 0x72,
|
||||
|
||||
0xAF, 0xBA, 0xDB, 0x72, 0xE4, 0x34, 0x6D, 0x83, 0x71, 0x60, 0xE3,
|
||||
0x7A, 0xCE, 0x26, 0xE1, 0xC1, 0x31, 0xAA, 0x71, 0x60, 0x1F, 0x08,
|
||||
0xF9, 0x46, 0xCA, 0x74, 0x15, 0x89, 0x0B, 0x9E, 0x00, 0x8A, 0x82,
|
||||
0xF4, 0x1E, 0xB7, 0x8D, 0x6F, 0xA4, 0x90, 0x43,
|
||||
|
||||
0x88, 0xC5, 0xCA, 0x04, 0x05, 0x65, 0x76, 0x27, 0x57, 0xF8, 0x03,
|
||||
0x8B, 0xF8, 0x0E, 0x64, 0x44, 0x51, 0xEC, 0xE4, 0xC9, 0x04, 0xBF,
|
||||
0x19, 0x6C, 0xA0, 0x86, 0x8A, 0x08, 0xF9, 0x52, 0x15, 0x32, 0x91,
|
||||
0xB7, 0x4B, 0xE5, 0xAF, 0x13, 0x06, 0x11, 0xFD,
|
||||
|
||||
0xE9, 0xC3, 0x6C, 0x57, 0xC5, 0x2B, 0x19, 0xED, 0xB0, 0x91, 0x63,
|
||||
0x93, 0xE1, 0x35, 0x53, 0xB2, 0x94, 0x9C, 0xDD, 0x47, 0xAE, 0xE1,
|
||||
0x7C, 0xDB, 0xFD, 0x59, 0x22, 0x20, 0x44, 0xAC, 0x9F, 0x87, 0x59,
|
||||
0xA3, 0x26, 0x9A, 0xE4, 0xF3, 0x44, 0xD8, 0x6D,
|
||||
},
|
||||
};
|
||||
|
||||
wuffs_webp__decoder dec = {0};
|
||||
dec.private_impl.f_width = width;
|
||||
dec.private_impl.f_height = height;
|
||||
|
||||
for (int filter = 0; filter < 3; filter++) {
|
||||
uint8_t buf[246];
|
||||
memcpy(&buf[0], &src[0][0], 246);
|
||||
wuffs_base__slice_u8 s = wuffs_base__make_slice_u8(&buf[0], 246);
|
||||
|
||||
switch (filter) {
|
||||
case 0:
|
||||
wuffs_webp__decoder__filter_alph_horizontal(&dec, s);
|
||||
break;
|
||||
case 1:
|
||||
wuffs_webp__decoder__filter_alph_vertical(&dec, s);
|
||||
break;
|
||||
case 2:
|
||||
wuffs_webp__decoder__filter_alph_gradient(&dec, s);
|
||||
break;
|
||||
}
|
||||
|
||||
if (0 == memcmp(&buf[0], &wants[filter][0], 246)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int i = (y * width) + x;
|
||||
int have = buf[i];
|
||||
int want = wants[filter][i];
|
||||
if (have != want) {
|
||||
RETURN_FAIL("filter=%d, y=%d, x=%d: have 0x%02X, want 0x%02X", filter,
|
||||
y, x, have, want);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "unreachable";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
@@ -518,8 +718,10 @@ bench_mimic_webp_lossy_decode_image_4002k_24bpp() {
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_webp_decode_filter_alph,
|
||||
test_wuffs_webp_decode_interface_lossless,
|
||||
test_wuffs_webp_decode_interface_lossy,
|
||||
test_wuffs_webp_decode_interface_vp8x_alpha_lossy,
|
||||
test_wuffs_webp_decode_many_small_reads,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
@@ -1237,6 +1237,17 @@ do_test__wuffs_base__image_decoder(
|
||||
CHECK_STATUS("decode_image_config",
|
||||
wuffs_base__image_decoder__decode_image_config(b, &ic, &src));
|
||||
|
||||
wuffs_base__slice_u8 workbuf = g_work_slice_u8;
|
||||
wuffs_base__range_ii_u64 workbuf_len =
|
||||
wuffs_base__image_decoder__workbuf_len(b);
|
||||
if (workbuf_len.min_incl > workbuf_len.max_incl) {
|
||||
return "indeterminate workbuf_len";
|
||||
}
|
||||
if (workbuf_len.max_incl > workbuf.len) {
|
||||
return "workbuf_len is too large";
|
||||
}
|
||||
workbuf.len = workbuf_len.max_incl;
|
||||
|
||||
uint32_t have_width = wuffs_base__pixel_config__width(&ic.pixcfg);
|
||||
if (have_width != want_width) {
|
||||
RETURN_FAIL("width: have %" PRIu32 ", want %" PRIu32, have_width,
|
||||
@@ -1254,9 +1265,9 @@ do_test__wuffs_base__image_decoder(
|
||||
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
|
||||
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
|
||||
&pb, &ic.pixcfg, g_pixel_slice_u8));
|
||||
CHECK_STATUS("decode_frame", wuffs_base__image_decoder__decode_frame(
|
||||
b, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC,
|
||||
g_work_slice_u8, NULL));
|
||||
CHECK_STATUS("decode_frame",
|
||||
wuffs_base__image_decoder__decode_frame(
|
||||
b, &pb, &src, WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL));
|
||||
|
||||
uint64_t n = wuffs_base__pixel_config__pixbuf_len(&ic.pixcfg);
|
||||
if (n < 4) {
|
||||
@@ -1297,7 +1308,7 @@ do_test__wuffs_base__io_transformer(wuffs_base__io_transformer* b,
|
||||
wuffs_base__range_ii_u64 workbuf_len =
|
||||
wuffs_base__io_transformer__workbuf_len(b);
|
||||
if (workbuf_len.min_incl > workbuf_len.max_incl) {
|
||||
return "inconsistent workbuf_len";
|
||||
return "indeterminate workbuf_len";
|
||||
}
|
||||
if (workbuf_len.max_incl > IO_BUFFER_ARRAY_SIZE) {
|
||||
return "workbuf_len is too large";
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 836 B |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
@@ -17,6 +17,7 @@ OK. 14a5b4b0 test/data/animated-red-blue.000003.nie
|
||||
OK. 76e40058 test/data/animated-red-blue.apng
|
||||
OK. 76e40058 test/data/animated-red-blue.gif
|
||||
OK. 76e40058 test/data/animated-red-blue.nia
|
||||
BAD c4a44cef test/data/animated-red-blue.webp
|
||||
OK. f9a10dac test/data/artificial-gif/background-color.gif
|
||||
OK. 36e7d9c7 test/data/artificial-gif/empty-palette.gif
|
||||
OK. db4c30eb test/data/artificial-gif/frame-out-of-bounds.gif
|
||||
@@ -134,6 +135,7 @@ OK. 56cf6ae1 test/data/hippopotamus.lossy.webp
|
||||
OK. 2535637e test/data/hippopotamus.masked-with-muybridge.etc2.bgra-binary.pkm
|
||||
OK. 720180ee test/data/hippopotamus.masked-with-muybridge.etc2.bgra-nonpremul.pkm
|
||||
OK. d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
OK. 1d8cd8b2 test/data/hippopotamus.masked-with-muybridge.lossy.webp
|
||||
OK. 7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
|
||||
OK. dcbb225a test/data/hippopotamus.nie
|
||||
OK. 57d9a4dd test/data/hippopotamus.pgm
|
||||
|
||||
Reference in new issue
Block a user