mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Compare commits
71
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
418847fe94 | ||
|
|
adfd2965cc | ||
|
|
3fa3928c68 | ||
|
|
03e6188bea | ||
|
|
2f61d7dbd4 | ||
|
|
c203818556 | ||
|
|
6d35660651 | ||
|
|
c82793a984 | ||
|
|
ed4d556721 | ||
|
|
fd69133c5d | ||
|
|
f4002c5b21 | ||
|
|
fc77dc35ff | ||
|
|
c997066a2a | ||
|
|
2c10bc32b0 | ||
|
|
5aa7a9339f | ||
|
|
d17fc6e6eb | ||
|
|
4c09c77bb9 | ||
|
|
db0a5a4f3a | ||
|
|
15c174634e | ||
|
|
510f4581c6 | ||
|
|
792d05bd9c | ||
|
|
e5ead0218e | ||
|
|
f0412122be | ||
|
|
546af5a7c3 | ||
|
|
b64b2ff09a | ||
|
|
c104ae296c | ||
|
|
42de49a938 | ||
|
|
92ea631055 | ||
|
|
58608c4ee5 | ||
|
|
4aa672af48 | ||
|
|
f86c80e425 | ||
|
|
dda01f1a77 | ||
|
|
f3a7288357 | ||
|
|
0a8bded7f3 | ||
|
|
918b4e4535 | ||
|
|
92f74e91a7 | ||
|
|
bcecdef66b | ||
|
|
2f1b1a5311 | ||
|
|
425eefeb35 | ||
|
|
e1a6a7cd8c | ||
|
|
4e85543d9c | ||
|
|
4c04ac1127 | ||
|
|
8ef4c062d9 | ||
|
|
38b101d170 | ||
|
|
5d1473a2ca | ||
|
|
72d4a9e769 | ||
|
|
5f6a522563 | ||
|
|
4dedbedbbc | ||
|
|
a1aa15cacf | ||
|
|
ae6b366edb | ||
|
|
6acb5a4fdd | ||
|
|
3a9933f2a0 | ||
|
|
c2eb4f5b93 | ||
|
|
8397a35a50 | ||
|
|
e53497abe3 | ||
|
|
15285a6ab9 | ||
|
|
ac4d3e6420 | ||
|
|
8bd52a8791 | ||
|
|
1d8fb411ba | ||
|
|
ccbec18330 | ||
|
|
55cad41d6c | ||
|
|
f5c68a13cb | ||
|
|
f5d6ce3797 | ||
|
|
5e8b448c12 | ||
|
|
49a431f98d | ||
|
|
ede0590ead | ||
|
|
bb8623b472 | ||
|
|
010e0a69f4 | ||
|
|
a684928240 | ||
|
|
cdf3bbfb26 | ||
|
|
fe15c471df |
No files matched your search
@@ -13,6 +13,8 @@
|
||||
Andrew Dassonville <dassonville.andrew@gmail.com>
|
||||
Google Inc.
|
||||
Jimmy Casey <casey.jimmy@gmail.com>
|
||||
Magnus Anderson <magnus@iastate.edu>
|
||||
Michael Mc Donnell <michael@mcdonnell.dk>
|
||||
Mike Kaufman <mkaufman@microsoft.com>
|
||||
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
|
||||
Přemysl Eric Janouch <p@janouch.name>
|
||||
@@ -36,6 +36,8 @@ Andrew Dassonville <dassonville.andrew@gmail.com>
|
||||
Chris Palmer <chris@noncombatant.org>
|
||||
Jimmy Casey <casey.jimmy@gmail.com>
|
||||
Leo Neat <lneat@google.com>
|
||||
Magnus Anderson <magnus@iastate.edu>
|
||||
Michael Mc Donnell <michael@mcdonnell.dk>
|
||||
Mike Kaufman <mkaufman@microsoft.com>
|
||||
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
|
||||
Nigel Tao <nigeltao@golang.org>
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CcompilersDefault = "clang-9,gcc"
|
||||
CcompilersDefault = "clang,gcc"
|
||||
CcompilersUsage = `comma-separated list of C compilers`
|
||||
|
||||
FocusDefault = ""
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ Installation:
|
||||
|
||||
Like any other implemented-in-Go program, to install the ractool program:
|
||||
|
||||
go get github.com/google/wuffs/cmd/ractool
|
||||
go install github.com/google/wuffs/cmd/ractool
|
||||
|
||||
Extended Example:
|
||||
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ Installation:
|
||||
|
||||
Like any other implemented-in-Go program, to install the ractool program:
|
||||
|
||||
go get github.com/google/wuffs/cmd/ractool
|
||||
go install github.com/google/wuffs/cmd/ractool
|
||||
|
||||
Extended Example:
|
||||
|
||||
|
||||
+6
-1
@@ -37,7 +37,12 @@ func doGen(wuffsRoot string, args []string) error { return doGenGenlib(wuffsR
|
||||
func doGenlib(wuffsRoot string, args []string) error { return doGenGenlib(wuffsRoot, args, true) }
|
||||
|
||||
func doGenGenlib(wuffsRoot string, args []string, genlib bool) error {
|
||||
flags := flag.NewFlagSet("gen", flag.ExitOnError)
|
||||
flagSetName := `"wuffs gen <flags> std/pkg1 std/pkg2 etc"`
|
||||
if genlib {
|
||||
flagSetName = `"wuffs genlib <flags> std/pkg1 std/pkg2 etc"`
|
||||
}
|
||||
|
||||
flags := flag.NewFlagSet(flagSetName, flag.ExitOnError)
|
||||
genlinenumFlag := flags.Bool("genlinenum", cf.GenlinenumDefault, cf.GenlinenumUsage)
|
||||
langsFlag := flags.String("langs", langsDefault, langsUsage)
|
||||
skipgendepsFlag := flags.Bool("skipgendeps", skipgendepsDefault, skipgendepsUsage)
|
||||
|
||||
@@ -52,6 +52,8 @@ The commands are:
|
||||
gen generate code for packages and dependencies
|
||||
genlib generate software libraries
|
||||
test test packages
|
||||
|
||||
Use "wuffs help <command>" for more information about a command.
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -76,6 +78,13 @@ func main1() error {
|
||||
return c.do(wuffsRoot, args[1:])
|
||||
}
|
||||
}
|
||||
if (len(args) == 2) && (args[0] == "help") {
|
||||
for _, c := range commands {
|
||||
if args[1] == c.name {
|
||||
return c.do(wuffsRoot, []string{"-help"})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
usage()
|
||||
os.Exit(1)
|
||||
|
||||
+22
-10
@@ -29,16 +29,26 @@ func doBench(wuffsRoot string, args []string) error { return doBenchTest(wuffsRo
|
||||
func doTest(wuffsRoot string, args []string) error { return doBenchTest(wuffsRoot, args, false) }
|
||||
|
||||
func doBenchTest(wuffsRoot string, args []string, bench bool) error {
|
||||
flags := flag.NewFlagSet("test", flag.ExitOnError)
|
||||
flagSetName := `"wuffs test <flags> std/pkg1 std/pkg2 etc"`
|
||||
if bench {
|
||||
flagSetName = `"wuffs bench <flags> std/pkg1 std/pkg2 etc"`
|
||||
}
|
||||
|
||||
flags := flag.NewFlagSet(flagSetName, flag.ExitOnError)
|
||||
ccompilersFlag := flags.String("ccompilers", cf.CcompilersDefault, cf.CcompilersUsage)
|
||||
focusFlag := flags.String("focus", cf.FocusDefault, cf.FocusUsage)
|
||||
iterscaleFlag := flags.Int("iterscale", cf.IterscaleDefault, cf.IterscaleUsage)
|
||||
langsFlag := flags.String("langs", langsDefault, langsUsage)
|
||||
mimicFlag := flags.Bool("mimic", cf.MimicDefault, cf.MimicUsage)
|
||||
repsFlag := flags.Int("reps", cf.RepsDefault, cf.RepsUsage)
|
||||
skipgenFlag := flags.Bool("skipgen", skipgenDefault, skipgenUsage)
|
||||
skipgendepsFlag := flags.Bool("skipgendeps", skipgendepsDefault, skipgendepsUsage)
|
||||
|
||||
iterscaleFlag := (*int)(nil)
|
||||
repsFlag := (*int)(nil)
|
||||
if bench {
|
||||
iterscaleFlag = flags.Int("iterscale", cf.IterscaleDefault, cf.IterscaleUsage)
|
||||
repsFlag = flags.Int("reps", cf.RepsDefault, cf.RepsUsage)
|
||||
}
|
||||
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -53,13 +63,15 @@ func doBenchTest(wuffsRoot string, args []string, bench bool) error {
|
||||
if !cf.IsAlphaNumericIsh(*focusFlag) {
|
||||
return fmt.Errorf("bad -focus flag value %q", *focusFlag)
|
||||
}
|
||||
if *iterscaleFlag < cf.IterscaleMin || cf.IterscaleMax < *iterscaleFlag {
|
||||
return fmt.Errorf("bad -iterscale flag value %d, outside the range [%d ..= %d]",
|
||||
*iterscaleFlag, cf.IterscaleMin, cf.IterscaleMax)
|
||||
}
|
||||
if *repsFlag < cf.RepsMin || cf.RepsMax < *repsFlag {
|
||||
return fmt.Errorf("bad -reps flag value %d, outside the range [%d ..= %d]",
|
||||
*repsFlag, cf.RepsMin, cf.RepsMax)
|
||||
if bench {
|
||||
if *iterscaleFlag < cf.IterscaleMin || cf.IterscaleMax < *iterscaleFlag {
|
||||
return fmt.Errorf("bad -iterscale flag value %d, outside the range [%d ..= %d]",
|
||||
*iterscaleFlag, cf.IterscaleMin, cf.IterscaleMax)
|
||||
}
|
||||
if *repsFlag < cf.RepsMin || cf.RepsMax < *repsFlag {
|
||||
return fmt.Errorf("bad -reps flag value %d, outside the range [%d ..= %d]",
|
||||
*repsFlag, cf.RepsMin, cf.RepsMax)
|
||||
}
|
||||
}
|
||||
|
||||
args = flags.Args()
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ The output of those benchmark programs is compatible with the
|
||||
[benchstat](https://godoc.org/golang.org/x/perf/cmd/benchstat) tool. For
|
||||
example, that tool can calculate confidence intervals based on multiple
|
||||
benchmark runs, or calculate p-values when comparing numbers before and after a
|
||||
code change. To install it, first install Go, then run `go get
|
||||
code change. To install it, first install Go, then run `go install
|
||||
golang.org/x/perf/cmd/benchstat`.
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@
|
||||
- Added `std/json`.
|
||||
- Added `std/nie`.
|
||||
- Added `std/png`.
|
||||
- Added `std/tga`.
|
||||
- Added `std/wbmp`.
|
||||
- Added `tell_me_more?` mechanism.
|
||||
- Added SIMD.
|
||||
@@ -40,7 +41,7 @@
|
||||
- Added slice `uintptr_low_12_bits` method.
|
||||
- Added tokens.
|
||||
- Changed `gif.decoder_workbuf_len_max_incl_worst_case` from 1 to 0.
|
||||
- Changed default C compilers from `clang-5.0,gcc` to `clang-9,gcc`.
|
||||
- Changed default C compilers from `clang-5.0,gcc` to `clang,gcc`.
|
||||
- Changed the C formatting style; removed the `-cformatter` flag.
|
||||
- Changed what the `std/gif` benchmarks actually measure.
|
||||
- Made `wuffs_base__pixel_format` a struct.
|
||||
|
||||
+16
-6
@@ -22,15 +22,25 @@ test suite, you might also have to install C compilers like clang and gcc, as
|
||||
well as C libraries (and their .h files) like libjpeg and libpng, as some tests
|
||||
compare that Wuffs produces exactly the same output as these other libraries.
|
||||
|
||||
Running `go get -v github.com/google/wuffs/cmd/...` will download and install
|
||||
the Wuffs tools. Change `get` to `install` to re-install those programs without
|
||||
downloading, e.g. after you've modified their source code, or after a manually
|
||||
issued `git pull`. The Wuffs tools that you'll most often use are `wuffsfmt`
|
||||
Run `git clone https://github.com/google/wuffs.git` to get the latest Wuffs
|
||||
code, `cd` into its directory and run `go install -v ./cmd/wuffs*` to install
|
||||
the Wuffs tools. The Wuffs tools that you'll most often use are `wuffsfmt`
|
||||
(analogous to `clang-format`, `gofmt` or `rustfmt`) and `wuffs` (roughly
|
||||
analogous to `make`, `go` or `cargo`).
|
||||
|
||||
You should now be able to run `wuffs test`. If all goes well, you should see
|
||||
some output containing the word "PASS" multiple times.
|
||||
You should now be able to run `wuffs test`. If you only have the `gcc` C
|
||||
compiler installed, but not `clang`, then you can run `wuffs
|
||||
test -ccompilers=gcc` instead. If all goes well, you should see some output
|
||||
containing the word "PASS" multiple times.
|
||||
|
||||
Remember to re-run `go install etc` whenever you've modified the Wuffs *tools'*
|
||||
source code (i.e. `*.go` files) or after a manually issued `git pull`. If
|
||||
you're only modifying the Wuffs *standard library's* source code (i.e.
|
||||
`*.wuffs` files), re-running `go install etc` is unnecessary.
|
||||
|
||||
If you're modifying just one particular codec in the standard library, such as
|
||||
the `std/png/*.wuffs` files, then you can exclude unrelated tests by running
|
||||
`wuffs test std/png`.
|
||||
|
||||
|
||||
## Poking Around
|
||||
|
||||
@@ -61,3 +61,4 @@ Package-specific quirks:
|
||||
|
||||
- [GIF image decoder quirks](/std/gif/decode_quirks.wuffs)
|
||||
- [JSON decoder quirks](/std/json/decode_quirks.wuffs)
|
||||
- [ZLIB decoder quirks](/std/zlib/decode_quirks.wuffs)
|
||||
@@ -1,6 +1,6 @@
|
||||
# Naïve Image Formats: NIE, NII, NIA
|
||||
|
||||
Status: Draft (as of December 2020). There is no compatibility guarantee yet.
|
||||
Status: Draft (as of November 2021). There is no compatibility guarantee yet.
|
||||
|
||||
A companion document has further discussion of [NIE related
|
||||
work](/doc/spec/nie-related-work.md).
|
||||
@@ -18,13 +18,14 @@ images. The 16 byte header:
|
||||
is not valid UTF-8) denotes version 1. There are no other valid versions at
|
||||
this time.
|
||||
- The second byte must be an ASCII 'b'. This denotes that the payload is in
|
||||
BGRA order (in terms of the wire format, independent of CPU endianness).
|
||||
BGRA order (not RGBA), in terms of the wire format, independent of CPU
|
||||
endianness.
|
||||
- The third byte, either an ASCII 'n' or an ASCII 'p', denotes whether the
|
||||
payload contains non-premultiplied or premultiplied alpha.
|
||||
- The fourth byte, either an ASCII '4' or an ASCII '8', denotes whether there
|
||||
are 4 or 8 bytes per pixel.
|
||||
- Future format versions may allow other byte values, but in version 1, it
|
||||
must be '\xFF', then 'b' or 'r', then 'n' or 'p', then '4' or '8'.
|
||||
must be '\xFF', then 'b', then 'n' or 'p', then '4' or '8'.
|
||||
- 4 bytes little-endian `uint32` width. The high bit must not be set.
|
||||
- 4 bytes little-endian `uint32` height. The high bit must not be set.
|
||||
|
||||
@@ -352,7 +353,7 @@ synonymous with `octet` and `uint8`.
|
||||
|
||||
The recommended filename extensions are `.nie`, `.nii` and `.nia`.
|
||||
|
||||
The recommended MIME types are `image/nie`, `image/nii` and `image/nia`.
|
||||
The recommended MIME types are `image/x-nie`, `image/x-nii` and `image/x-nia`.
|
||||
|
||||
|
||||
## Why NIE and not NIF (for Naïve Image Format)?
|
||||
@@ -369,4 +370,4 @@ in a long "E", "I" or "A" sound. It's definitely a hard "N", not a soft one.
|
||||
|
||||
---
|
||||
|
||||
Updated on December 2020.
|
||||
Updated on January 2022.
|
||||
@@ -661,7 +661,7 @@ Go programming language libraries:
|
||||
- [RAC](https://godoc.org/github.com/google/wuffs/lib/rac)
|
||||
- [RAC + Zlib](https://godoc.org/github.com/google/wuffs/lib/raczlib)
|
||||
|
||||
Command line tool, installable via `go get
|
||||
Command line tool, installable via `go install
|
||||
github.com/google/wuffs/cmd/ractool`:
|
||||
|
||||
- [ractool](https://godoc.org/github.com/google/wuffs/cmd/ractool)
|
||||
|
||||
@@ -66,6 +66,7 @@ https://skia-review.googlesource.com/c/skia/+/290618
|
||||
#define WUFFS_CONFIG__MODULE__LZW
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
@@ -129,6 +130,8 @@ wuffs_base__frame_config g_frame_config = {0};
|
||||
int32_t g_fourcc = 0;
|
||||
uint32_t g_width = 0;
|
||||
uint32_t g_height = 0;
|
||||
uint32_t g_num_animation_loops = 0;
|
||||
uint64_t g_num_printed_frames = 0;
|
||||
|
||||
wuffs_base__image_decoder* g_image_decoder = NULL;
|
||||
union {
|
||||
@@ -136,6 +139,7 @@ union {
|
||||
wuffs_gif__decoder gif;
|
||||
wuffs_nie__decoder nie;
|
||||
wuffs_png__decoder png;
|
||||
wuffs_tga__decoder tga;
|
||||
wuffs_wbmp__decoder wbmp;
|
||||
} g_potential_decoders;
|
||||
|
||||
@@ -152,7 +156,7 @@ union {
|
||||
#endif
|
||||
|
||||
#ifndef WORKBUF_ARRAY_SIZE
|
||||
#define WORKBUF_ARRAY_SIZE (1024 * 1024)
|
||||
#define WORKBUF_ARRAY_SIZE (256 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef PIXBUF_ARRAY_SIZE
|
||||
@@ -244,7 +248,7 @@ load_image_type() {
|
||||
g_fourcc = 0;
|
||||
while (true) {
|
||||
g_fourcc = wuffs_base__magic_number_guess_fourcc(
|
||||
wuffs_base__io_buffer__reader_slice(&g_src));
|
||||
wuffs_base__io_buffer__reader_slice(&g_src), g_src.meta.closed);
|
||||
if ((g_fourcc >= 0) ||
|
||||
(wuffs_base__io_buffer__reader_length(&g_src) == g_src.data.len)) {
|
||||
break;
|
||||
@@ -298,6 +302,16 @@ initialize_image_decoder() {
|
||||
&g_potential_decoders.png);
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
status = wuffs_tga__decoder__initialize(
|
||||
&g_potential_decoders.tga, sizeof g_potential_decoders.tga,
|
||||
WUFFS_VERSION, WUFFS_INITIALIZE__DEFAULT_OPTIONS);
|
||||
TRY(wuffs_base__status__message(&status));
|
||||
g_image_decoder =
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
&g_potential_decoders.tga);
|
||||
return NULL;
|
||||
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
status = wuffs_wbmp__decoder__initialize(
|
||||
&g_potential_decoders.wbmp, sizeof g_potential_decoders.wbmp,
|
||||
@@ -466,6 +480,7 @@ print_nia_duration(wuffs_base__flicks duration) {
|
||||
|
||||
void //
|
||||
print_nie_frame() {
|
||||
g_num_printed_frames++;
|
||||
print_nix_header(0x45AFC36E); // "nïE" as a u32le.
|
||||
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(&g_pixbuf, 0);
|
||||
if (tab.width == tab.stride) {
|
||||
@@ -490,30 +505,29 @@ print_nia_padding() {
|
||||
|
||||
void //
|
||||
print_nia_footer() {
|
||||
// For still (non-animated) images, the number of animation loops has no
|
||||
// practical effect: the pixels on screen do not change over time regardless
|
||||
// of its value. In the wire format encoding, there might be no explicit
|
||||
// "number of animation loops" value listed in the source bytes. Various
|
||||
// codec implementations may therefore choose an implicit default of 0 ("loop
|
||||
// forever") or 1 ("loop exactly once"). Either is equally valid.
|
||||
//
|
||||
// However, when comparing the output of this convert-to-NIA program (backed
|
||||
// by Wuffs' image codecs) with other convert-to-NIA programs, it is useful
|
||||
// to canonicalize still images' "number of animation loops" to 0.
|
||||
uint32_t n = g_num_animation_loops;
|
||||
if (g_num_printed_frames <= 1) {
|
||||
n = 0;
|
||||
}
|
||||
|
||||
uint8_t data[8];
|
||||
wuffs_base__poke_u32le__no_bounds_check(
|
||||
data + 0x00,
|
||||
wuffs_base__image_decoder__num_animation_loops(g_image_decoder));
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x00, n);
|
||||
wuffs_base__poke_u32le__no_bounds_check(data + 0x04, 0x80000000);
|
||||
ignore_return_value(write(STDOUT_FD, &data[0], 8));
|
||||
}
|
||||
|
||||
const char* //
|
||||
main1(int argc, char** argv) {
|
||||
TRY(parse_flags(argc, argv));
|
||||
if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
return "main: unsandboxed";
|
||||
}
|
||||
|
||||
g_src.data.ptr = g_src_buffer_array;
|
||||
g_src.data.len = SRC_BUFFER_ARRAY_SIZE;
|
||||
|
||||
TRY(load_image_type());
|
||||
TRY(load_image_config());
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nix_header(0x41AFC36E); // "nïA" as a u32le.
|
||||
}
|
||||
|
||||
convert_frames() {
|
||||
wuffs_base__flicks total_duration = 0;
|
||||
while (true) {
|
||||
// Decode the wuffs_base__frame_config.
|
||||
@@ -524,7 +538,7 @@ main1(int argc, char** argv) {
|
||||
if (dfc_status.repr == NULL) {
|
||||
break;
|
||||
} else if (dfc_status.repr == wuffs_base__note__end_of_data) {
|
||||
goto done;
|
||||
return NULL;
|
||||
} else if (dfc_status.repr != wuffs_base__suspension__short_read) {
|
||||
return wuffs_base__status__message(&dfc_status);
|
||||
}
|
||||
@@ -539,9 +553,6 @@ main1(int argc, char** argv) {
|
||||
return "main: animation frame duration overflow";
|
||||
}
|
||||
total_duration += duration;
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nia_duration(total_duration);
|
||||
}
|
||||
|
||||
if (wuffs_base__frame_config__index(&g_frame_config) == 0) {
|
||||
fill_rectangle(
|
||||
@@ -562,6 +573,7 @@ main1(int argc, char** argv) {
|
||||
|
||||
// Decode the frame (the pixels).
|
||||
wuffs_base__status df_status;
|
||||
const char* decode_frame_io_error_message = NULL;
|
||||
while (true) {
|
||||
df_status = wuffs_base__image_decoder__decode_frame(
|
||||
g_image_decoder, &g_pixbuf, &g_src,
|
||||
@@ -572,18 +584,57 @@ main1(int argc, char** argv) {
|
||||
if (df_status.repr != wuffs_base__suspension__short_read) {
|
||||
break;
|
||||
}
|
||||
TRY(read_more_src());
|
||||
decode_frame_io_error_message = read_more_src();
|
||||
if (decode_frame_io_error_message != NULL) {
|
||||
// Neuter the "short read" df_status so that convert_frames returns the
|
||||
// I/O error message instead.
|
||||
df_status.repr = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
print_nie_frame();
|
||||
// Update g_num_animation_loops. It's rare in practice, but the animation
|
||||
// loop count can change over the course of decoding an image file.
|
||||
//
|
||||
// This program updates the global once per frame (even though the Wuffs
|
||||
// API also lets you call wuffs_base__image_decoder__num_animation_loops
|
||||
// just once, after the decoding is complete) to more closely match the
|
||||
// Chromium web browser. This program emits (via print_nia_footer) the
|
||||
// value from the final animation frame's update.
|
||||
//
|
||||
// Chromium image decoding uses two passes. (Wuffs' API lets you use a
|
||||
// single pass but Chromium also wraps other libraries). Its first pass
|
||||
// counts the number of animation frames (call it N). The second pass
|
||||
// decodes exactly N frames. In particular, if the animation loop count
|
||||
// would change between the end of frame N and the end of the file then
|
||||
// Chromium's design will not pick up that change, even if it's a valid
|
||||
// change in terms of the image file format.
|
||||
//
|
||||
// Specifically, for the test/data/artificial-gif/multiple-loop-counts.gif
|
||||
// file this program emits 31 (0x1F) to match Chromium, even though the
|
||||
// file arguably has a 41 (0x29) loop count after a complete decode.
|
||||
g_num_animation_loops =
|
||||
wuffs_base__image_decoder__num_animation_loops(g_image_decoder);
|
||||
|
||||
// Print a complete NIE frame (and surrounding bytes, for NIA).
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nia_duration(total_duration);
|
||||
}
|
||||
print_nie_frame();
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nia_padding();
|
||||
}
|
||||
|
||||
// Return early if there was an error decoding the frame.
|
||||
if (df_status.repr != NULL) {
|
||||
return wuffs_base__status__message(&df_status);
|
||||
} else if (decode_frame_io_error_message != NULL) {
|
||||
return decode_frame_io_error_message;
|
||||
} else if (g_flags.first_frame_only) {
|
||||
return NULL;
|
||||
}
|
||||
print_nia_padding();
|
||||
|
||||
// Dispose the frame.
|
||||
switch (wuffs_base__frame_config__disposal(&g_frame_config)) {
|
||||
case WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND: {
|
||||
fill_rectangle(
|
||||
@@ -601,10 +652,29 @@ main1(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return "main: unreachable";
|
||||
}
|
||||
|
||||
done:
|
||||
print_nia_footer();
|
||||
return NULL;
|
||||
const char* //
|
||||
main1(int argc, char** argv) {
|
||||
TRY(parse_flags(argc, argv));
|
||||
if (g_flags.fail_if_unsandboxed && !g_sandboxed) {
|
||||
return "main: unsandboxed";
|
||||
}
|
||||
|
||||
g_src.data.ptr = g_src_buffer_array;
|
||||
g_src.data.len = SRC_BUFFER_ARRAY_SIZE;
|
||||
|
||||
TRY(load_image_type());
|
||||
TRY(load_image_config());
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nix_header(0x41AFC36E); // "nïA" as a u32le.
|
||||
}
|
||||
const char* ret = convert_frames();
|
||||
if (!g_flags.first_frame_only) {
|
||||
print_nia_footer();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int //
|
||||
|
||||
@@ -80,6 +80,7 @@ The Escape key quits.
|
||||
#define WUFFS_CONFIG__MODULE__LZW
|
||||
#define WUFFS_CONFIG__MODULE__NIE
|
||||
#define WUFFS_CONFIG__MODULE__PNG
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
#define WUFFS_CONFIG__MODULE__WBMP
|
||||
#define WUFFS_CONFIG__MODULE__ZLIB
|
||||
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
bmp: test/data/*.bmp ../bmpsuite_corpus/*.bmp
|
||||
cbor: test/data/*.cbor
|
||||
gif: test/data/*.gif test/data/artificial/*.gif
|
||||
gzip: test/data/*.gz test/data/artificial/*.gz
|
||||
gif: test/data/*.gif test/data/artificial-gif/*.gif
|
||||
gzip: test/data/*.gz
|
||||
json: test/data/*.json ../rapidjson_corpus/* ../simdjson_corpus/* ../JSONTestSuite/test_*/*.json
|
||||
png: test/data/*.png ../pngsuite_corpus/*.png
|
||||
png: test/data/*.png test/data/artificial-png/*.png ../pngsuite_corpus/*.png
|
||||
tga: test/data/*.tga
|
||||
wbmp: test/data/*.wbmp
|
||||
zlib: test/data/*.zlib
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// Copyright 2020 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
// Silence the nested slash-star warning for the next comment's command line.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcomment"
|
||||
|
||||
/*
|
||||
This fuzzer (the fuzz function) is typically run indirectly, by a framework
|
||||
such as https://github.com/google/oss-fuzz calling LLVMFuzzerTestOneInput.
|
||||
|
||||
When working on the fuzz implementation, or as a coherence check, defining
|
||||
WUFFS_CONFIG__FUZZLIB_MAIN will let you manually run fuzz over a set of files:
|
||||
|
||||
gcc -DWUFFS_CONFIG__FUZZLIB_MAIN tga_fuzzer.c
|
||||
./a.out ../../../test/data/*.tga
|
||||
rm -f ./a.out
|
||||
|
||||
It should print "PASS", amongst other information, and exit(0).
|
||||
*/
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
#if defined(WUFFS_CONFIG__FUZZLIB_MAIN)
|
||||
// Defining the WUFFS_CONFIG__STATIC_FUNCTIONS macro is optional, but when
|
||||
// combined with WUFFS_IMPLEMENTATION, it demonstrates making all of Wuffs'
|
||||
// functions have static storage.
|
||||
//
|
||||
// This can help the compiler ignore or discard unused code, which can produce
|
||||
// faster compiles and smaller binaries. Other motivations are discussed in the
|
||||
// "ALLOW STATIC IMPLEMENTATION" section of
|
||||
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
|
||||
#define WUFFS_CONFIG__STATIC_FUNCTIONS
|
||||
#endif // defined(WUFFS_CONFIG__FUZZLIB_MAIN)
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../fuzzlib/fuzzlib.c"
|
||||
#include "../fuzzlib/fuzzlib_image_decoder.c"
|
||||
|
||||
const char* //
|
||||
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_tga__decoder dec;
|
||||
wuffs_base__status status = wuffs_tga__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
return fuzz_image_decoder(
|
||||
src, hash,
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec));
|
||||
}
|
||||
@@ -20,13 +20,14 @@ pointer. Anyway, here's what the output should look like:
|
||||
|
||||
```
|
||||
$ ./run.sh
|
||||
--- C Implementation Prints ---
|
||||
0
|
||||
12
|
||||
56789
|
||||
4294967295
|
||||
0
|
||||
3197704724
|
||||
--------
|
||||
------ Wuffs Impl Prints ------
|
||||
0
|
||||
12
|
||||
56789
|
||||
|
||||
+2
-57
@@ -12,67 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef USE_WUFFS
|
||||
uint32_t parse(char* p, size_t n) {
|
||||
uint32_t ret = 0;
|
||||
for (size_t i = 0; (i < n) && p[i]; i++) {
|
||||
ret = (10 * ret) + (p[i] - '0');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else // #ifndef USE_WUFFS
|
||||
|
||||
// TODO: this 'rough edge' shouldn't be necessary. See
|
||||
// https://github.com/google/wuffs/issues/24
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
#include "./parse.c"
|
||||
|
||||
uint32_t parse(char* p, size_t n) {
|
||||
wuffs_base__status status;
|
||||
wuffs_demo__parser* parser =
|
||||
(wuffs_demo__parser*)(malloc(sizeof__wuffs_demo__parser()));
|
||||
if (!parser) {
|
||||
printf("malloc failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = wuffs_demo__parser__initialize(parser, sizeof__wuffs_demo__parser(),
|
||||
WUFFS_VERSION, 0);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
printf("initialize: %s\n", wuffs_base__status__message(&status));
|
||||
free(parser);
|
||||
return 0;
|
||||
}
|
||||
|
||||
wuffs_base__io_buffer iobuf;
|
||||
iobuf.data.ptr = (uint8_t*)p;
|
||||
iobuf.data.len = n;
|
||||
iobuf.meta.wi = n;
|
||||
iobuf.meta.ri = 0;
|
||||
iobuf.meta.pos = 0;
|
||||
iobuf.meta.closed = true;
|
||||
|
||||
status = wuffs_demo__parser__parse(parser, &iobuf);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
printf("parse: %s\n", wuffs_base__status__message(&status));
|
||||
free(parser);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t ret = wuffs_demo__parser__value(parser);
|
||||
free(parser);
|
||||
return ret;
|
||||
}
|
||||
#endif // #ifndef USE_WUFFS
|
||||
// See naive-parse.c and wuffs-parse.c for implementations of this function.
|
||||
uint32_t parse(char*, size_t);
|
||||
|
||||
void run(char* p) {
|
||||
size_t n = strlen(p) + 1; // +1 for the trailing NUL that ends a C string.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2019 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
uint32_t parse(char* p, size_t n) {
|
||||
uint32_t ret = 0;
|
||||
for (size_t i = 0; (i < n) && p[i]; i++) {
|
||||
ret = (10 * ret) + (p[i] - '0');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -18,16 +18,14 @@
|
||||
CC=${CC:-gcc}
|
||||
|
||||
# You may need to run
|
||||
# go get github.com/google/wuffs/cmd/wuffs-c
|
||||
# go install github.com/google/wuffs/cmd/wuffs-c
|
||||
# beforehand, to install the wuffs-c compiler.
|
||||
wuffs-c gen -package_name demo < parse.wuffs > parse.c
|
||||
|
||||
$CC main.c
|
||||
./a.out
|
||||
echo --- C Implementation Prints ---
|
||||
$CC main.c naive-parse.c -o n.out
|
||||
./n.out
|
||||
|
||||
echo --------
|
||||
|
||||
$CC main.c -DUSE_WUFFS
|
||||
./a.out
|
||||
|
||||
rm a.out parse.c
|
||||
echo ------ Wuffs Impl Prints ------
|
||||
$CC main.c wuffs-parse.c -o w.out
|
||||
./w.out
|
||||
@@ -0,0 +1,87 @@
|
||||
// Copyright 2019 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// TODO: this 'rough edge' shouldn't be necessary. See
|
||||
// https://github.com/google/wuffs/issues/24
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
#include "./parse.c"
|
||||
|
||||
uint32_t parse(char* p, size_t n) {
|
||||
wuffs_base__status status;
|
||||
|
||||
// This next line of code allocates a wuffs_demo__parser on the stack. Stack
|
||||
// allocation in C means uninitialized memory, so we need to call
|
||||
// wuffs_demo__parser__initialize afterwards.
|
||||
//
|
||||
// An alternative, allocating on the heap and initializing in a single
|
||||
// function call, is to say:
|
||||
//
|
||||
// wuffs_demo__parser* parser = wuffs_demo__parser__alloc();
|
||||
// if (!parser) {
|
||||
// // Out of memory.
|
||||
// return 0;
|
||||
// }
|
||||
// // No need to call wuffs_demo__parser__initialize, but don't forget to
|
||||
// // free(parser) before this function returns, taking extra care if this
|
||||
// // function has multiple return points. Wuffs has no destructor functions
|
||||
// // and Wuffs types never hold or own any resources in the RAII sense.
|
||||
// // Just free the memory.
|
||||
//
|
||||
// For stack allocation, the C compiler needs to know
|
||||
// sizeof(wuffs_demo__parser), but that compile-time value isn't guaranteed
|
||||
// to be stable across Wuffs versions. Stack allocation is therefore only
|
||||
// valid when the C file also #define's WUFFS_IMPLEMENTATION. When linking
|
||||
// against a separately built Wuffs library (and the Wuffs types in this
|
||||
// compilation are incomplete types), you'll have to use heap allocation.
|
||||
wuffs_demo__parser parser;
|
||||
|
||||
// Initialize (and check status). An error here means that bad arguments were
|
||||
// passed to wuffs_demo__parser__initialize.
|
||||
//
|
||||
// There are two other categories of not-OK status values, notes and
|
||||
// suspensions, but they won't be encountered in this example.
|
||||
status = wuffs_demo__parser__initialize(&parser, sizeof__wuffs_demo__parser(),
|
||||
WUFFS_VERSION, 0);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
printf("initialize: %s\n", wuffs_base__status__message(&status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// True means that the wuffs_base__io_buffer is closed - we are at the end of
|
||||
// the input. False would mean that there might be additional data in the
|
||||
// byte stream (that this buffer is not large enough to hold all at once).
|
||||
//
|
||||
// In general, Wuffs' coroutine and suspension status mechanisms let it parse
|
||||
// arbitrarily large data streams using fixed sized buffers, but that won't
|
||||
// be encountered in this example.
|
||||
wuffs_base__io_buffer iobuf =
|
||||
wuffs_base__ptr_u8__reader((uint8_t*)p, n, true);
|
||||
|
||||
// Parse (and check status). An error here means that we had invalid input
|
||||
// (i.e. "#not a digit" or "#too large").
|
||||
//
|
||||
// There are two other categories of not-OK status values, notes and
|
||||
// suspensions, but they won't be encountered in this example.
|
||||
status = wuffs_demo__parser__parse(&parser, &iobuf);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
printf("parse: %s\n", wuffs_base__status__message(&status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return wuffs_demo__parser__value(&parser);
|
||||
}
|
||||
@@ -58,7 +58,8 @@ DecodeImageCallbacks::AllocWorkbufResult::AllocWorkbufResult(
|
||||
|
||||
wuffs_base__image_decoder::unique_ptr //
|
||||
DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
switch (fourcc) {
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
|
||||
case WUFFS_BASE__FOURCC__BMP:
|
||||
@@ -84,6 +85,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
@@ -311,10 +317,17 @@ redirect:
|
||||
// Determine the image format.
|
||||
if (!redirected) {
|
||||
while (true) {
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice());
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice(),
|
||||
io_buf.meta.closed);
|
||||
if (fourcc > 0) {
|
||||
break;
|
||||
} else if ((fourcc == 0) && (io_buf.reader_length() >= 64)) {
|
||||
// Having (fourcc == 0) means that Wuffs' built in MIME sniffer
|
||||
// didn't recognize the image format. Nonetheless, custom callbacks
|
||||
// may still be able to do their own MIME sniffing, for exotic image
|
||||
// types. We try to give them at least 64 bytes of prefix data when
|
||||
// one-shot-calling callbacks.SelectDecoder. There is no mechanism
|
||||
// for the callbacks to request a longer prefix.
|
||||
break;
|
||||
} else if (io_buf.meta.closed || (io_buf.writer_length() == 0)) {
|
||||
fourcc = 0;
|
||||
@@ -355,8 +368,7 @@ redirect:
|
||||
|
||||
// Select the image decoder.
|
||||
image_decoder = callbacks.SelectDecoder(
|
||||
(uint32_t)fourcc,
|
||||
fourcc ? wuffs_base__empty_slice_u8() : io_buf.reader_slice());
|
||||
(uint32_t)fourcc, io_buf.reader_slice(), io_buf.meta.closed);
|
||||
if (!image_decoder) {
|
||||
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
|
||||
}
|
||||
@@ -371,6 +383,9 @@ redirect:
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
|
||||
}
|
||||
|
||||
@@ -70,9 +70,13 @@ class DecodeImageCallbacks {
|
||||
// Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).
|
||||
//
|
||||
// Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the
|
||||
// caller is responsible for examining the opening bytes (a prefix) of the
|
||||
// input data. SelectDecoder implementations should not modify those bytes.
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that Wuffs'
|
||||
// standard library did not recognize the image format but if SelectDecoder
|
||||
// was overridden, it may examine the input data's starting bytes and still
|
||||
// provide its own image decoder, e.g. for an exotic image file format that's
|
||||
// not in Wuffs' standard library. The prefix_etc fields have the same
|
||||
// meaning as wuffs_base__magic_number_guess_fourcc arguments. SelectDecoder
|
||||
// implementations should not modify prefix_data's contents.
|
||||
//
|
||||
// SelectDecoder might be called more than once, since some image file
|
||||
// formats can wrap others. For example, a nominal BMP file can actually
|
||||
@@ -87,9 +91,12 @@ class DecodeImageCallbacks {
|
||||
// - WUFFS_BASE__FOURCC__GIF
|
||||
// - WUFFS_BASE__FOURCC__NIE
|
||||
// - WUFFS_BASE__FOURCC__PNG
|
||||
// - WUFFS_BASE__FOURCC__TGA
|
||||
// - WUFFS_BASE__FOURCC__WBMP
|
||||
virtual wuffs_base__image_decoder::unique_ptr //
|
||||
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
|
||||
SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
|
||||
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
|
||||
@@ -209,8 +216,8 @@ struct DecodeImageArgFlags {
|
||||
// DefaultValue returns 0.
|
||||
static DecodeImageArgFlags DefaultValue();
|
||||
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, GAMA,
|
||||
// ICCP, KVP, SRGB and XMP.
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
|
||||
// GAMA, ICCP, KVP, SRGB and XMP.
|
||||
|
||||
// Background Color.
|
||||
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
|
||||
|
||||
@@ -1418,13 +1418,19 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// wuffs_base__magic_number_guess_fourcc guesses the file format of some data,
|
||||
// given its opening bytes. It returns a positive FourCC value on success.
|
||||
// given its starting bytes (the prefix_data argument) and whether or not there
|
||||
// may be further bytes (the prefix_closed argument; true means that
|
||||
// prefix_data is the entire data).
|
||||
//
|
||||
// It returns a positive FourCC value on success.
|
||||
//
|
||||
// It returns zero if nothing matches its hard-coded list of 'magic numbers'.
|
||||
//
|
||||
// It returns a negative value if a longer prefix is required for a conclusive
|
||||
// result. For example, seeing a single 'B' byte is not enough to discriminate
|
||||
// the BMP and BPG image file formats.
|
||||
// It returns a negative value if prefix_closed is false and a longer prefix is
|
||||
// required for a conclusive result. For example, a single 'B' byte (without
|
||||
// further data) is not enough to discriminate the BMP and BPG image file
|
||||
// formats. Similarly, a single '\xFF' byte might be the start of JPEG data or
|
||||
// it might be the start of some other binary data.
|
||||
//
|
||||
// It does not do a full validity check. Like any guess made from a short
|
||||
// prefix of the data, it may return false positives. Data that starts with 99
|
||||
@@ -1439,4 +1445,5 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// function requires the WUFFS_CONFIG__MODULE__BASE__MAGIC sub-module, not just
|
||||
// WUFFS_CONFIG__MODULE__BASE__CORE.
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix);
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
@@ -160,7 +160,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -168,7 +168,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
return 0;
|
||||
}
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
if ((size_t)(p - io1_w) < (size_t)(distance)) {
|
||||
if ((size_t)(p - io0_w) < (size_t)(distance)) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t* q = p - distance;
|
||||
@@ -205,10 +205,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -240,11 +240,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -280,11 +280,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 8
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
|
||||
@@ -14,8 +14,127 @@
|
||||
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// ICO doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly ICO.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// first two bytes are 0x00.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/ico/
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[3] != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01: // ICO
|
||||
case 0x02: // CUR
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The Number Of Images should be positive.
|
||||
if (prefix_data.len < 6) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[4] == 0) && (prefix_data.ptr[5] == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The first ICONDIRENTRY's fourth byte should be zero.
|
||||
if (prefix_data.len < 10) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[9] != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: have a separate FourCC for CUR?
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
|
||||
// TGA doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly TGA.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// second byte (prefix_data.ptr[1], the Color Map Type byte), is either 0x00 or
|
||||
// 0x01.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/tga/
|
||||
// - https://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 3) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
case 0x09:
|
||||
case 0x0A:
|
||||
case 0x0B:
|
||||
break;
|
||||
default:
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Color Map Entry Size field (if the Color Map Type field
|
||||
// is non-zero) or else all the Color Map fields should be zero.
|
||||
if (prefix_data.len < 8) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[1] != 0x00) {
|
||||
switch (prefix_data.ptr[7]) {
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else if ((prefix_data.ptr[3] | prefix_data.ptr[4] | prefix_data.ptr[5] |
|
||||
prefix_data.ptr[6] | prefix_data.ptr[7]) != 0x00) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Pixel Depth field.
|
||||
if (prefix_data.len < 17) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[16]) {
|
||||
case 0x01:
|
||||
case 0x08:
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0x54474120; // 'TGA 'be
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// This is similar to (but different from):
|
||||
// - the magic/Magdir tables under https://github.com/file/file
|
||||
// - the MIME Sniffing algorithm at https://mimesniff.spec.whatwg.org/
|
||||
|
||||
// table holds the 'magic numbers' (which are actually variable length
|
||||
// strings). The strings may contain NUL bytes, so the "const char* magic"
|
||||
// value starts with the length-minus-1 of the 'magic number'.
|
||||
@@ -36,15 +155,16 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
|
||||
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
||||
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
|
||||
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||
};
|
||||
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
||||
|
||||
if (prefix.len == 0) {
|
||||
return -1;
|
||||
if (prefix_data.len == 0) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint8_t pre_first_byte = prefix.ptr[0];
|
||||
uint8_t pre_first_byte = prefix_data.ptr[0];
|
||||
|
||||
int32_t fourcc = 0;
|
||||
size_t i;
|
||||
@@ -63,11 +183,11 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
|
||||
const char* mag_remaining_ptr = table[i].magic + 2;
|
||||
uint8_t* pre_remaining_ptr = prefix.ptr + 1;
|
||||
size_t pre_remaining_len = prefix.len - 1;
|
||||
uint8_t* pre_remaining_ptr = prefix_data.ptr + 1;
|
||||
size_t pre_remaining_len = prefix_data.len - 1;
|
||||
if (pre_remaining_len < mag_remaining_len) {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, pre_remaining_len)) {
|
||||
return -1;
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
} else {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, mag_remaining_len)) {
|
||||
@@ -75,6 +195,14 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix_data.len < 2) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[1] == 0x00) || (prefix_data.ptr[1] == 0x01)) {
|
||||
return wuffs_base__magic_number_guess_fourcc__maybe_tga(prefix_data,
|
||||
prefix_closed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
match:
|
||||
@@ -83,31 +211,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 16) {
|
||||
return -1;
|
||||
if (prefix_data.len < 12) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix_data.ptr + 8);
|
||||
if (x == 0x57454250) { // 'WEBP'be
|
||||
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
|
||||
if (y == 0x56503820) { // 'VP8 'be
|
||||
return 0x57503820; // 'WP8 'be
|
||||
} else if (y == 0x5650384C) { // 'VP8L'be
|
||||
return 0x5750384C; // 'WP8L'be
|
||||
}
|
||||
return 0x57454250; // 'WEBP'be
|
||||
}
|
||||
|
||||
} else if (fourcc == 0x30302020) { // '00 'be
|
||||
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
||||
if (prefix.len < 4) {
|
||||
return -1;
|
||||
} else if ((prefix.ptr[2] != 0x00) &&
|
||||
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
|
||||
// Unfortunately, some file formats also don't start with a magic
|
||||
// identifier, so we have to use heuristics (where the order matters, the
|
||||
// same as /usr/bin/file's magic/Magdir tables) as best we can. Maybe
|
||||
// it's TGA, ICO/CUR, etc. Maybe it's something else.
|
||||
int32_t tga = wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
prefix_data, prefix_closed);
|
||||
if (tga != 0) {
|
||||
return tga;
|
||||
}
|
||||
int32_t ico = wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
prefix_data, prefix_closed);
|
||||
if (ico != 0) {
|
||||
return ico;
|
||||
}
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[2] != 0x00) &&
|
||||
((prefix_data.ptr[2] >= 0x80) ||
|
||||
(prefix_data.ptr[3] != 0x00))) {
|
||||
// Roughly speaking, this could be a non-degenerate (non-0-width and
|
||||
// non-0-height) WBMP image.
|
||||
return 0x57424D50; // 'WBMP'be
|
||||
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
|
||||
(prefix.ptr[3] == 0x00)) {
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -501,14 +501,23 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -545,14 +554,23 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -583,14 +601,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -627,14 +645,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_premul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -665,14 +683,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -697,14 +715,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_premul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_premul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_premul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_premul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint64_t ia = 0xFFFF - sa;
|
||||
@@ -723,14 +741,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -1790,13 +1808,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -1838,13 +1856,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
|
||||
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
|
||||
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
|
||||
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -1913,13 +1931,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -1991,13 +2009,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -2066,13 +2084,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
|
||||
@@ -66,6 +66,7 @@ var FourCCs = [...][2]string{
|
||||
{"PNG ", "Portable Network Graphics"},
|
||||
{"PNM ", "Portable Anymap"},
|
||||
{"PS ", "PostScript"},
|
||||
{"QOI ", "Quite OK Image"},
|
||||
{"RAC ", "Random Access Compression"},
|
||||
{"RAW ", "Raw"},
|
||||
{"RIFF", "Resource Interchange File Format"},
|
||||
@@ -75,13 +76,13 @@ var FourCCs = [...][2]string{
|
||||
{"SVG ", "Scalable Vector Graphics"},
|
||||
{"TAR ", "Tape Archive"},
|
||||
{"TEXT", "Text"},
|
||||
{"TGA ", "Truevision Advanced Raster Graphics Adapter"},
|
||||
{"TIFF", "Tagged Image File Format"},
|
||||
{"TOML", "Tom's Obvious Minimal Language"},
|
||||
{"WAVE", "Waveform"},
|
||||
{"WBMP", "Wireless Bitmap"},
|
||||
{"WEBP", "Web Picture"},
|
||||
{"WOFF", "Web Open Font Format"},
|
||||
{"WP8 ", "Web Picture (VP8)"},
|
||||
{"WP8L", "Web Picture (VP8 Lossless)"},
|
||||
{"XML ", "Extensible Markup Language"},
|
||||
{"XMP ", "Extensible Metadata Platform"},
|
||||
{"XZ ", "Xz"},
|
||||
|
||||
+2405
-546
@@ -686,6 +686,9 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// PostScript.
|
||||
#define WUFFS_BASE__FOURCC__PS 0x50532020
|
||||
|
||||
// Quite OK Image.
|
||||
#define WUFFS_BASE__FOURCC__QOI 0x514F4920
|
||||
|
||||
// Random Access Compression.
|
||||
#define WUFFS_BASE__FOURCC__RAC 0x52414320
|
||||
|
||||
@@ -713,6 +716,9 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// Text.
|
||||
#define WUFFS_BASE__FOURCC__TEXT 0x54455854
|
||||
|
||||
// Truevision Advanced Raster Graphics Adapter.
|
||||
#define WUFFS_BASE__FOURCC__TGA 0x54474120
|
||||
|
||||
// Tagged Image File Format.
|
||||
#define WUFFS_BASE__FOURCC__TIFF 0x54494646
|
||||
|
||||
@@ -725,15 +731,12 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// Wireless Bitmap.
|
||||
#define WUFFS_BASE__FOURCC__WBMP 0x57424D50
|
||||
|
||||
// Web Picture.
|
||||
#define WUFFS_BASE__FOURCC__WEBP 0x57454250
|
||||
|
||||
// Web Open Font Format.
|
||||
#define WUFFS_BASE__FOURCC__WOFF 0x574F4646
|
||||
|
||||
// Web Picture (VP8).
|
||||
#define WUFFS_BASE__FOURCC__WP8 0x57503820
|
||||
|
||||
// Web Picture (VP8 Lossless).
|
||||
#define WUFFS_BASE__FOURCC__WP8L 0x5750384C
|
||||
|
||||
// Extensible Markup Language.
|
||||
#define WUFFS_BASE__FOURCC__XML 0x584D4C20
|
||||
|
||||
@@ -1682,13 +1685,19 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// wuffs_base__magic_number_guess_fourcc guesses the file format of some data,
|
||||
// given its opening bytes. It returns a positive FourCC value on success.
|
||||
// given its starting bytes (the prefix_data argument) and whether or not there
|
||||
// may be further bytes (the prefix_closed argument; true means that
|
||||
// prefix_data is the entire data).
|
||||
//
|
||||
// It returns a positive FourCC value on success.
|
||||
//
|
||||
// It returns zero if nothing matches its hard-coded list of 'magic numbers'.
|
||||
//
|
||||
// It returns a negative value if a longer prefix is required for a conclusive
|
||||
// result. For example, seeing a single 'B' byte is not enough to discriminate
|
||||
// the BMP and BPG image file formats.
|
||||
// It returns a negative value if prefix_closed is false and a longer prefix is
|
||||
// required for a conclusive result. For example, a single 'B' byte (without
|
||||
// further data) is not enough to discriminate the BMP and BPG image file
|
||||
// formats. Similarly, a single '\xFF' byte might be the start of JPEG data or
|
||||
// it might be the start of some other binary data.
|
||||
//
|
||||
// It does not do a full validity check. Like any guess made from a short
|
||||
// prefix of the data, it may return false positives. Data that starts with 99
|
||||
@@ -1703,7 +1712,8 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// function requires the WUFFS_CONFIG__MODULE__BASE__MAGIC sub-module, not just
|
||||
// WUFFS_CONFIG__MODULE__BASE__CORE.
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix);
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// ---------------- Ranges and Rects
|
||||
|
||||
@@ -7361,7 +7371,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_length;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
@@ -8931,6 +8940,8 @@ extern const char wuffs_zlib__error__incorrect_dictionary[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976
|
||||
|
||||
#define WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
@@ -9042,6 +9053,7 @@ struct wuffs_zlib__decoder__struct {
|
||||
bool f_header_complete;
|
||||
bool f_got_dictionary;
|
||||
bool f_want_dictionary;
|
||||
bool f_quirks[1];
|
||||
bool f_ignore_checksum;
|
||||
uint32_t f_dict_id_got;
|
||||
uint32_t f_dict_id_want;
|
||||
@@ -9330,6 +9342,7 @@ struct wuffs_png__decoder__struct {
|
||||
uint64_t f_pass_workbuf_length;
|
||||
uint8_t f_call_sequence;
|
||||
bool f_report_metadata_chrm;
|
||||
bool f_report_metadata_exif;
|
||||
bool f_report_metadata_gama;
|
||||
bool f_report_metadata_iccp;
|
||||
bool f_report_metadata_kvp;
|
||||
@@ -9342,6 +9355,7 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_actl;
|
||||
bool f_seen_chrm;
|
||||
bool f_seen_fctl;
|
||||
bool f_seen_exif;
|
||||
bool f_seen_gama;
|
||||
bool f_seen_iccp;
|
||||
bool f_seen_idat;
|
||||
@@ -9626,6 +9640,351 @@ struct wuffs_png__decoder__struct {
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_tga__error__bad_header[];
|
||||
extern const char wuffs_tga__error__bad_run_length_encoding[];
|
||||
extern const char wuffs_tga__error__unsupported_tga_file[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_TGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
|
||||
typedef struct wuffs_tga__decoder__struct wuffs_tga__decoder;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
|
||||
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
|
||||
//
|
||||
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
|
||||
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_tga__decoder__initialize(
|
||||
wuffs_tga__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options);
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_tga__decoder();
|
||||
|
||||
// ---------------- Allocs
|
||||
|
||||
// These functions allocate and initialize Wuffs structs. They return NULL if
|
||||
// memory allocation fails. If they return non-NULL, there is no need to call
|
||||
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
|
||||
// calling free on the returned pointer. That pointer is effectively a C++
|
||||
// std::unique_ptr<T, decltype(&free)>.
|
||||
|
||||
wuffs_tga__decoder*
|
||||
wuffs_tga__decoder__alloc();
|
||||
|
||||
static inline wuffs_base__image_decoder*
|
||||
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder() {
|
||||
return (wuffs_base__image_decoder*)(wuffs_tga__decoder__alloc());
|
||||
}
|
||||
|
||||
// ---------------- Upcasts
|
||||
|
||||
static inline wuffs_base__image_decoder*
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
wuffs_tga__decoder* p) {
|
||||
return (wuffs_base__image_decoder*)p;
|
||||
}
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_quirk_enabled(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_image_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
|
||||
wuffs_tga__decoder__frame_dirty_rect(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint32_t
|
||||
wuffs_tga__decoder__num_animation_loops(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frame_configs(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frames(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__restart_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_report_metadata(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_fourcc,
|
||||
bool a_report);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__tell_me_more(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_tga__decoder__workbuf_len(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------- Struct Definitions
|
||||
|
||||
// These structs' fields, and the sizeof them, are private implementation
|
||||
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||
//
|
||||
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||
|
||||
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
struct wuffs_tga__decoder__struct {
|
||||
// Do not access the private_impl's or private_data's fields directly. There
|
||||
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
|
||||
// the wuffs_foo__bar__baz functions.
|
||||
//
|
||||
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
|
||||
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
|
||||
|
||||
struct {
|
||||
uint32_t magic;
|
||||
uint32_t active_coroutine;
|
||||
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
|
||||
wuffs_base__vtable null_vtable;
|
||||
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
uint8_t f_header_id_length;
|
||||
uint8_t f_header_color_map_type;
|
||||
uint8_t f_header_image_type;
|
||||
uint16_t f_header_color_map_first_entry_index;
|
||||
uint16_t f_header_color_map_length;
|
||||
uint8_t f_header_color_map_entry_size;
|
||||
uint8_t f_header_pixel_depth;
|
||||
uint8_t f_header_image_descriptor;
|
||||
bool f_opaque;
|
||||
uint32_t f_scratch_bytes_per_pixel;
|
||||
uint32_t f_src_bytes_per_pixel;
|
||||
uint32_t f_src_pixfmt;
|
||||
uint64_t f_frame_config_io_position;
|
||||
wuffs_base__pixel_swizzler f_swizzler;
|
||||
|
||||
uint32_t p_decode_image_config[1];
|
||||
uint32_t p_decode_frame_config[1];
|
||||
uint32_t p_decode_frame[1];
|
||||
} private_impl;
|
||||
|
||||
struct {
|
||||
uint8_t f_dst_palette[1024];
|
||||
uint8_t f_src_palette[1024];
|
||||
uint8_t f_scratch[4];
|
||||
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint64_t scratch;
|
||||
} s_decode_image_config[1];
|
||||
struct {
|
||||
uint64_t v_dst_bytes_per_pixel;
|
||||
uint32_t v_dst_x;
|
||||
uint32_t v_dst_y;
|
||||
uint64_t v_mark;
|
||||
uint32_t v_num_pixels32;
|
||||
uint32_t v_lit_length;
|
||||
uint32_t v_run_length;
|
||||
uint64_t v_num_dst_bytes;
|
||||
uint64_t scratch;
|
||||
} s_decode_frame[1];
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
using unique_ptr = std::unique_ptr<wuffs_tga__decoder, decltype(&free)>;
|
||||
|
||||
// On failure, the alloc_etc functions return nullptr. They don't throw.
|
||||
|
||||
static inline unique_ptr
|
||||
alloc() {
|
||||
return unique_ptr(wuffs_tga__decoder__alloc(), &free);
|
||||
}
|
||||
|
||||
static inline wuffs_base__image_decoder::unique_ptr
|
||||
alloc_as__wuffs_base__image_decoder() {
|
||||
return wuffs_base__image_decoder::unique_ptr(
|
||||
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder(), &free);
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
|
||||
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
// Disallow constructing or copying an object via standard C++ mechanisms,
|
||||
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
|
||||
// size and field layout is not part of the public, stable, memory-safe API.
|
||||
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
|
||||
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
|
||||
// their first argument) rather than tweaking bar.private_impl.qux fields.
|
||||
//
|
||||
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
|
||||
// order to provide convenience methods. These forward on "this", so that you
|
||||
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
|
||||
wuffs_tga__decoder__struct() = delete;
|
||||
wuffs_tga__decoder__struct(const wuffs_tga__decoder__struct&) = delete;
|
||||
wuffs_tga__decoder__struct& operator=(
|
||||
const wuffs_tga__decoder__struct&) = delete;
|
||||
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
#if !defined(WUFFS_IMPLEMENTATION)
|
||||
// As above, the size of the struct is not part of the public API, and unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
|
||||
// allocated, not stack allocated. Its size is not intended to be known at
|
||||
// compile time, but it is unfortunately divulged as a side effect of
|
||||
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
|
||||
// instead of "sizeof T", invoking the operator. To make the two values
|
||||
// different, so that passing the latter will be rejected by the initialize
|
||||
// function, we add an arbitrary amount of dead weight.
|
||||
uint8_t dead_weight[123000000]; // 123 MB.
|
||||
#endif // !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
initialize(
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options) {
|
||||
return wuffs_tga__decoder__initialize(
|
||||
this, sizeof_star_self, wuffs_version, options);
|
||||
}
|
||||
|
||||
inline wuffs_base__image_decoder*
|
||||
upcast_as__wuffs_base__image_decoder() {
|
||||
return (wuffs_base__image_decoder*)this;
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_quirk_enabled(
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_tga__decoder__set_quirk_enabled(this, a_quirk, a_enabled);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_image_config(
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__decode_image_config(this, a_dst, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_frame_config(
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__decode_frame_config(this, a_dst, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_frame(
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts) {
|
||||
return wuffs_tga__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
|
||||
}
|
||||
|
||||
inline wuffs_base__rect_ie_u32
|
||||
frame_dirty_rect() const {
|
||||
return wuffs_tga__decoder__frame_dirty_rect(this);
|
||||
}
|
||||
|
||||
inline uint32_t
|
||||
num_animation_loops() const {
|
||||
return wuffs_tga__decoder__num_animation_loops(this);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
num_decoded_frame_configs() const {
|
||||
return wuffs_tga__decoder__num_decoded_frame_configs(this);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
num_decoded_frames() const {
|
||||
return wuffs_tga__decoder__num_decoded_frames(this);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
restart_frame(
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position) {
|
||||
return wuffs_tga__decoder__restart_frame(this, a_index, a_io_position);
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_report_metadata(
|
||||
uint32_t a_fourcc,
|
||||
bool a_report) {
|
||||
return wuffs_tga__decoder__set_report_metadata(this, a_fourcc, a_report);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
tell_me_more(
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__range_ii_u64
|
||||
workbuf_len() const {
|
||||
return wuffs_tga__decoder__workbuf_len(this);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
}; // struct wuffs_tga__decoder__struct
|
||||
|
||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_wbmp__error__bad_header[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
@@ -10231,9 +10590,13 @@ class DecodeImageCallbacks {
|
||||
// Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).
|
||||
//
|
||||
// Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the
|
||||
// caller is responsible for examining the opening bytes (a prefix) of the
|
||||
// input data. SelectDecoder implementations should not modify those bytes.
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that Wuffs'
|
||||
// standard library did not recognize the image format but if SelectDecoder
|
||||
// was overridden, it may examine the input data's starting bytes and still
|
||||
// provide its own image decoder, e.g. for an exotic image file format that's
|
||||
// not in Wuffs' standard library. The prefix_etc fields have the same
|
||||
// meaning as wuffs_base__magic_number_guess_fourcc arguments. SelectDecoder
|
||||
// implementations should not modify prefix_data's contents.
|
||||
//
|
||||
// SelectDecoder might be called more than once, since some image file
|
||||
// formats can wrap others. For example, a nominal BMP file can actually
|
||||
@@ -10248,9 +10611,12 @@ class DecodeImageCallbacks {
|
||||
// - WUFFS_BASE__FOURCC__GIF
|
||||
// - WUFFS_BASE__FOURCC__NIE
|
||||
// - WUFFS_BASE__FOURCC__PNG
|
||||
// - WUFFS_BASE__FOURCC__TGA
|
||||
// - WUFFS_BASE__FOURCC__WBMP
|
||||
virtual wuffs_base__image_decoder::unique_ptr //
|
||||
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
|
||||
SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
|
||||
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
|
||||
@@ -10370,8 +10736,8 @@ struct DecodeImageArgFlags {
|
||||
// DefaultValue returns 0.
|
||||
static DecodeImageArgFlags DefaultValue();
|
||||
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, GAMA,
|
||||
// ICCP, KVP, SRGB and XMP.
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
|
||||
// GAMA, ICCP, KVP, SRGB and XMP.
|
||||
|
||||
// Background Color.
|
||||
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
|
||||
@@ -11036,7 +11402,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11044,7 +11410,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
return 0;
|
||||
}
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
if ((size_t)(p - io1_w) < (size_t)(distance)) {
|
||||
if ((size_t)(p - io0_w) < (size_t)(distance)) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t* q = p - distance;
|
||||
@@ -11081,10 +11447,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11116,11 +11482,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11156,11 +11522,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 8
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -15568,8 +15934,127 @@ done:
|
||||
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// ICO doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly ICO.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// first two bytes are 0x00.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/ico/
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[3] != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01: // ICO
|
||||
case 0x02: // CUR
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The Number Of Images should be positive.
|
||||
if (prefix_data.len < 6) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[4] == 0) && (prefix_data.ptr[5] == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The first ICONDIRENTRY's fourth byte should be zero.
|
||||
if (prefix_data.len < 10) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[9] != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: have a separate FourCC for CUR?
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
|
||||
// TGA doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly TGA.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// second byte (prefix_data.ptr[1], the Color Map Type byte), is either 0x00 or
|
||||
// 0x01.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/tga/
|
||||
// - https://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 3) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
case 0x09:
|
||||
case 0x0A:
|
||||
case 0x0B:
|
||||
break;
|
||||
default:
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Color Map Entry Size field (if the Color Map Type field
|
||||
// is non-zero) or else all the Color Map fields should be zero.
|
||||
if (prefix_data.len < 8) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[1] != 0x00) {
|
||||
switch (prefix_data.ptr[7]) {
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else if ((prefix_data.ptr[3] | prefix_data.ptr[4] | prefix_data.ptr[5] |
|
||||
prefix_data.ptr[6] | prefix_data.ptr[7]) != 0x00) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Pixel Depth field.
|
||||
if (prefix_data.len < 17) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[16]) {
|
||||
case 0x01:
|
||||
case 0x08:
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0x54474120; // 'TGA 'be
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// This is similar to (but different from):
|
||||
// - the magic/Magdir tables under https://github.com/file/file
|
||||
// - the MIME Sniffing algorithm at https://mimesniff.spec.whatwg.org/
|
||||
|
||||
// table holds the 'magic numbers' (which are actually variable length
|
||||
// strings). The strings may contain NUL bytes, so the "const char* magic"
|
||||
// value starts with the length-minus-1 of the 'magic number'.
|
||||
@@ -15590,15 +16075,16 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
|
||||
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
||||
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
|
||||
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||
};
|
||||
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
||||
|
||||
if (prefix.len == 0) {
|
||||
return -1;
|
||||
if (prefix_data.len == 0) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint8_t pre_first_byte = prefix.ptr[0];
|
||||
uint8_t pre_first_byte = prefix_data.ptr[0];
|
||||
|
||||
int32_t fourcc = 0;
|
||||
size_t i;
|
||||
@@ -15617,11 +16103,11 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
|
||||
const char* mag_remaining_ptr = table[i].magic + 2;
|
||||
uint8_t* pre_remaining_ptr = prefix.ptr + 1;
|
||||
size_t pre_remaining_len = prefix.len - 1;
|
||||
uint8_t* pre_remaining_ptr = prefix_data.ptr + 1;
|
||||
size_t pre_remaining_len = prefix_data.len - 1;
|
||||
if (pre_remaining_len < mag_remaining_len) {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, pre_remaining_len)) {
|
||||
return -1;
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
} else {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, mag_remaining_len)) {
|
||||
@@ -15629,6 +16115,14 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix_data.len < 2) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[1] == 0x00) || (prefix_data.ptr[1] == 0x01)) {
|
||||
return wuffs_base__magic_number_guess_fourcc__maybe_tga(prefix_data,
|
||||
prefix_closed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
match:
|
||||
@@ -15637,31 +16131,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 16) {
|
||||
return -1;
|
||||
if (prefix_data.len < 12) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix_data.ptr + 8);
|
||||
if (x == 0x57454250) { // 'WEBP'be
|
||||
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
|
||||
if (y == 0x56503820) { // 'VP8 'be
|
||||
return 0x57503820; // 'WP8 'be
|
||||
} else if (y == 0x5650384C) { // 'VP8L'be
|
||||
return 0x5750384C; // 'WP8L'be
|
||||
}
|
||||
return 0x57454250; // 'WEBP'be
|
||||
}
|
||||
|
||||
} else if (fourcc == 0x30302020) { // '00 'be
|
||||
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
||||
if (prefix.len < 4) {
|
||||
return -1;
|
||||
} else if ((prefix.ptr[2] != 0x00) &&
|
||||
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
|
||||
// Unfortunately, some file formats also don't start with a magic
|
||||
// identifier, so we have to use heuristics (where the order matters, the
|
||||
// same as /usr/bin/file's magic/Magdir tables) as best we can. Maybe
|
||||
// it's TGA, ICO/CUR, etc. Maybe it's something else.
|
||||
int32_t tga = wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
prefix_data, prefix_closed);
|
||||
if (tga != 0) {
|
||||
return tga;
|
||||
}
|
||||
int32_t ico = wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
prefix_data, prefix_closed);
|
||||
if (ico != 0) {
|
||||
return ico;
|
||||
}
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[2] != 0x00) &&
|
||||
((prefix_data.ptr[2] >= 0x80) ||
|
||||
(prefix_data.ptr[3] != 0x00))) {
|
||||
// Roughly speaking, this could be a non-degenerate (non-0-width and
|
||||
// non-0-height) WBMP image.
|
||||
return 0x57424D50; // 'WBMP'be
|
||||
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
|
||||
(prefix.ptr[3] == 0x00)) {
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -16165,14 +16666,23 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16209,14 +16719,23 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16247,14 +16766,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16291,14 +16810,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_premul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16329,14 +16848,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -16361,14 +16880,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_premul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_premul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_premul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_premul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint64_t ia = 0xFFFF - sa;
|
||||
@@ -16387,14 +16906,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17454,13 +17973,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17502,13 +18021,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
|
||||
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
|
||||
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
|
||||
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17577,13 +18096,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17655,13 +18174,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17730,13 +18249,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -26990,14 +27509,17 @@ wuffs_deflate__decoder__init_huff(
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_remaining != 0) {
|
||||
if ((a_which == 1) &&
|
||||
(v_counts[1] == 1) &&
|
||||
(self->private_data.f_code_lengths[a_n_codes0] == 1) &&
|
||||
((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
|
||||
self->private_impl.f_n_huffs_bits[1] = 1;
|
||||
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[0] | 1);
|
||||
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
|
||||
return wuffs_base__make_status(NULL);
|
||||
if ((a_which == 1) && (v_counts[1] == 1) && ((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
|
||||
v_i = 0;
|
||||
while (v_i <= 29) {
|
||||
if (self->private_data.f_code_lengths[(a_n_codes0 + v_i)] == 1) {
|
||||
self->private_impl.f_n_huffs_bits[1] = 1;
|
||||
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[v_i] | 1);
|
||||
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code_under_subscribed);
|
||||
}
|
||||
@@ -27335,9 +27857,8 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27601,9 +28122,8 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27814,9 +28334,8 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27937,7 +28456,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_length = self->private_data.s_decode_huffman_slow[0].v_length;
|
||||
v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
|
||||
v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
|
||||
v_hdist = self->private_data.s_decode_huffman_slow[0].v_hdist;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -28134,55 +28652,29 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
label__inner__continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) {
|
||||
v_hdist = ((uint32_t)((((uint64_t)((v_dist_minus_1 + 1))) - ((uint64_t)(iop_a_dst - io0_a_dst)))));
|
||||
if (v_length > v_hdist) {
|
||||
v_length -= v_hdist;
|
||||
if (v_hdist < v_length) {
|
||||
v_hlen = v_hdist;
|
||||
} else {
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295)));
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
while (true) {
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767)));
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label__4__break;
|
||||
}
|
||||
if (v_n_copied > 0) {
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist = (((uint32_t)(v_hdist + v_n_copied)) & 32767);
|
||||
if (v_hdist == 0) {
|
||||
goto label__4__break;
|
||||
}
|
||||
}
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
if (v_n_copied < v_hlen) {
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__inner__continue;
|
||||
}
|
||||
label__4__break:;
|
||||
if (v_hlen > 0) {
|
||||
while (true) {
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767)));
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label__5__break;
|
||||
}
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist += v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label__5__break:;
|
||||
}
|
||||
v_length -= v_hlen;
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28190,14 +28682,12 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_history(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
if (v_length <= v_n_copied) {
|
||||
v_length = 0;
|
||||
goto label__6__break;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label__6__break:;
|
||||
}
|
||||
label__loop__break:;
|
||||
self->private_impl.f_bits = v_bits;
|
||||
@@ -28226,7 +28716,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
self->private_data.s_decode_huffman_slow[0].v_length = v_length;
|
||||
self->private_data.s_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
|
||||
self->private_data.s_decode_huffman_slow[0].v_hlen = v_hlen;
|
||||
self->private_data.s_decode_huffman_slow[0].v_hdist = v_hdist;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -29314,7 +29803,10 @@ wuffs_gif__decoder__num_animation_loops(
|
||||
if (self->private_impl.f_seen_num_animation_loops_value) {
|
||||
return self->private_impl.f_num_animation_loops_value;
|
||||
}
|
||||
return 1;
|
||||
if (self->private_impl.f_num_decoded_frame_configs_value > 1) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func gif.decoder.num_decoded_frame_configs
|
||||
@@ -34913,6 +35405,10 @@ const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect diction
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
#define WUFFS_ZLIB__QUIRKS_BASE 2113790976
|
||||
|
||||
#define WUFFS_ZLIB__QUIRKS_COUNT 1
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
@@ -35076,8 +35572,15 @@ wuffs_zlib__decoder__set_quirk_enabled(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
if (a_quirk == 1) {
|
||||
if (self->private_impl.f_header_complete) {
|
||||
self->private_impl.f_bad_call_sequence = true;
|
||||
} else if (a_quirk == 1) {
|
||||
self->private_impl.f_ignore_checksum = a_enabled;
|
||||
} else if (a_quirk >= 2113790976) {
|
||||
a_quirk -= 2113790976;
|
||||
if (a_quirk < 1) {
|
||||
self->private_impl.f_quirks[a_quirk] = a_enabled;
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
@@ -35167,6 +35670,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
if (self->private_impl.f_bad_call_sequence) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_quirks[0]) {
|
||||
} else if ( ! self->private_impl.f_want_dictionary) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
@@ -35274,7 +35778,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum) {
|
||||
if ( ! self->private_impl.f_ignore_checksum && ! self->private_impl.f_quirks[0]) {
|
||||
v_checksum_got = wuffs_adler32__hasher__update_u32(&self->private_data.f_checksum, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst));
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
@@ -35284,38 +35788,40 @@ wuffs_zlib__decoder__transform_io(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
label__0__break:;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_transform_io[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
if ( ! self->private_impl.f_quirks[0]) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_transform_io[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
|
||||
*scratch >>= 8;
|
||||
*scratch <<= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch >> 32));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3));
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
|
||||
*scratch >>= 8;
|
||||
*scratch <<= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch >> 32));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3));
|
||||
}
|
||||
v_checksum_want = t_3;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
v_checksum_want = t_3;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ok:
|
||||
@@ -35614,6 +36120,11 @@ wuffs_png__decoder__decode_chrm(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_exif(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_fctl(
|
||||
wuffs_png__decoder* self,
|
||||
@@ -37785,8 +38296,13 @@ wuffs_png__decoder__assign_filter_distance(
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_filter_distance = 1;
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
if (self->private_impl.f_interlace_pass == 0) {
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
} else {
|
||||
self->private_impl.f_dst_pixfmt = 2164308923;
|
||||
self->private_impl.f_src_pixfmt = 2164308923;
|
||||
}
|
||||
self->private_impl.f_filter_distance = 2;
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 2) {
|
||||
@@ -37927,20 +38443,25 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_chunk_type == 1163152464) {
|
||||
if (self->private_impl.f_seen_plte || (self->private_impl.f_color_type != 3)) {
|
||||
if (self->private_impl.f_seen_plte) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_color_type == 3) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_png__decoder__decode_plte(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if ((self->private_impl.f_color_type == 2) || (self->private_impl.f_color_type == 6)) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_png__decoder__decode_plte(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_plte = true;
|
||||
} else if ((self->private_impl.f_chunk_type & 32) == 0) {
|
||||
@@ -37984,6 +38505,25 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
if (self->private_impl.f_report_metadata_exif) {
|
||||
if (self->private_impl.f_seen_exif) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
status = wuffs_png__decoder__decode_exif(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_exif = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
@@ -37992,7 +38532,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38010,7 +38550,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38029,7 +38569,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38048,7 +38588,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38066,7 +38606,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38086,7 +38626,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc == 0) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
if (self->private_data.s_decode_other_chunk[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -38525,6 +39065,47 @@ wuffs_png__decoder__decode_chrm(
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func png.decoder.decode_exif
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_exif(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_chunk_length < 4) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_flavor = 3;
|
||||
self->private_impl.f_metadata_fourcc = 1163413830;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_metadata_z = wuffs_base__u64__sat_add(self->private_impl.f_metadata_y, ((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
self->private_impl.f_chunk_length = 0;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func png.decoder.decode_fctl
|
||||
|
||||
static wuffs_base__status
|
||||
@@ -40479,6 +41060,8 @@ wuffs_png__decoder__set_report_metadata(
|
||||
|
||||
if (a_fourcc == 1128813133) {
|
||||
self->private_impl.f_report_metadata_chrm = a_report;
|
||||
} else if (a_fourcc == 1163413830) {
|
||||
self->private_impl.f_report_metadata_exif = a_report;
|
||||
} else if (a_fourcc == 1195461953) {
|
||||
self->private_impl.f_report_metadata_gama = a_report;
|
||||
} else if (a_fourcc == 1229144912) {
|
||||
@@ -40572,395 +41155,422 @@ wuffs_png__decoder__tell_me_more(
|
||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_zlib_is_dirty) {
|
||||
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
|
||||
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
if (self->private_impl.f_ignore_checksum) {
|
||||
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||
while (true) {
|
||||
if (self->private_impl.f_metadata_flavor == 3) {
|
||||
while (true) {
|
||||
if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_y) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
} else if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_y >= self->private_impl.f_metadata_z) {
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
self->private_impl.f_metadata_y = self->private_impl.f_metadata_z;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__even_more_information);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
}
|
||||
self->private_impl.f_zlib_is_dirty = true;
|
||||
self->private_impl.f_ztxt_hist_pos = 0;
|
||||
}
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_flavor != 4) {
|
||||
goto label__loop__break;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
if (self->private_impl.f_zlib_is_dirty) {
|
||||
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
|
||||
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
if (self->private_impl.f_ignore_checksum) {
|
||||
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||
}
|
||||
}
|
||||
self->private_impl.f_zlib_is_dirty = true;
|
||||
self->private_impl.f_ztxt_hist_pos = 0;
|
||||
}
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_flavor != 4) {
|
||||
goto label__loop__break;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_0;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
|
||||
{
|
||||
wuffs_base__io_buffer* o_2_v_w = v_w;
|
||||
uint8_t *o_2_iop_v_w = iop_v_w;
|
||||
uint8_t *o_2_io0_v_w = io0_v_w;
|
||||
uint8_t *o_2_io1_v_w = io1_v_w;
|
||||
uint8_t *o_2_io2_v_w = io2_v_w;
|
||||
v_w = wuffs_base__io_writer__set(
|
||||
&u_w,
|
||||
&iop_v_w,
|
||||
&io0_v_w,
|
||||
&io1_v_w,
|
||||
&io2_v_w,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
|
||||
self->private_impl.f_ztxt_hist_pos);
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
const uint8_t *o_3_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
iop_v_w = u_w.data.ptr + u_w.meta.wi;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
|
||||
io2_a_src = o_3_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_0;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
v_w = o_2_v_w;
|
||||
iop_v_w = o_2_iop_v_w;
|
||||
io0_v_w = o_2_io0_v_w;
|
||||
io1_v_w = o_2_io1_v_w;
|
||||
io2_v_w = o_2_io2_v_w;
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (v_num_written > 1024) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri = 0;
|
||||
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
|
||||
{
|
||||
wuffs_base__io_buffer* o_2_v_w = v_w;
|
||||
uint8_t *o_2_iop_v_w = iop_v_w;
|
||||
uint8_t *o_2_io0_v_w = io0_v_w;
|
||||
uint8_t *o_2_io1_v_w = io1_v_w;
|
||||
uint8_t *o_2_io2_v_w = io2_v_w;
|
||||
v_w = wuffs_base__io_writer__set(
|
||||
&u_w,
|
||||
&iop_v_w,
|
||||
&io0_v_w,
|
||||
&io1_v_w,
|
||||
&io2_v_w,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
|
||||
self->private_impl.f_ztxt_hist_pos);
|
||||
{
|
||||
const uint8_t *o_3_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
iop_v_w = u_w.data.ptr + u_w.meta.wi;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
|
||||
io2_a_src = o_3_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
v_w = o_2_v_w;
|
||||
iop_v_w = o_2_iop_v_w;
|
||||
io0_v_w = o_2_io0_v_w;
|
||||
io1_v_w = o_2_io1_v_w;
|
||||
io2_v_w = o_2_io2_v_w;
|
||||
}
|
||||
if (v_num_written > 1024) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri = 0;
|
||||
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
|
||||
}
|
||||
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
|
||||
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
|
||||
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
goto label__loop__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
goto label__loop__continue;
|
||||
} else if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
} else {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
goto label__loop__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__loop__break;
|
||||
}
|
||||
v_c2 = WUFFS_PNG__LATIN_1[v_c];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
|
||||
while (true) {
|
||||
}
|
||||
label__loop__break:;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
goto label__loop__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
goto label__loop__continue;
|
||||
} else if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
goto label__loop__continue;
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
} else {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
goto label__loop__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__loop__continue;
|
||||
uint8_t t_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__loop__break;
|
||||
}
|
||||
v_c2 = WUFFS_PNG__LATIN_1[v_c];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
label__loop__break:;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
|
||||
self->private_impl.f_metadata_flavor = 0;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
label__goto_done__break:;
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
|
||||
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
|
||||
self->private_impl.f_metadata_flavor = 0;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
@@ -41372,6 +41982,1240 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
|
||||
const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding";
|
||||
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
// ---------------- VTables
|
||||
|
||||
const wuffs_base__image_decoder__func_ptrs
|
||||
wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder = {
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__pixel_buffer*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__pixel_blend,
|
||||
wuffs_base__slice_u8,
|
||||
wuffs_base__decode_frame_options*))(&wuffs_tga__decoder__decode_frame),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__frame_config*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_frame_config),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__image_config*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_image_config),
|
||||
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_tga__decoder__frame_dirty_rect),
|
||||
(uint32_t(*)(const void*))(&wuffs_tga__decoder__num_animation_loops),
|
||||
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frame_configs),
|
||||
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frames),
|
||||
(wuffs_base__status(*)(void*,
|
||||
uint64_t,
|
||||
uint64_t))(&wuffs_tga__decoder__restart_frame),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_tga__decoder__set_quirk_enabled),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_tga__decoder__set_report_metadata),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__more_information*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__tell_me_more),
|
||||
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_tga__decoder__workbuf_len),
|
||||
};
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_tga__decoder__initialize(
|
||||
wuffs_tga__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options){
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (sizeof(*self) != sizeof_star_self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
|
||||
}
|
||||
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
||||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
|
||||
}
|
||||
|
||||
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
|
||||
// The whole point of this if-check is to detect an uninitialized *self.
|
||||
// We disable the warning on GCC. Clang-5.0 does not have this warning.
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
if (self->private_impl.magic != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
|
||||
}
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
} else {
|
||||
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
|
||||
} else {
|
||||
memset(&(self->private_impl), 0, sizeof(self->private_impl));
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
|
||||
wuffs_base__image_decoder__vtable_name;
|
||||
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
|
||||
(const void*)(&wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
wuffs_tga__decoder*
|
||||
wuffs_tga__decoder__alloc() {
|
||||
wuffs_tga__decoder* x =
|
||||
(wuffs_tga__decoder*)(calloc(sizeof(wuffs_tga__decoder), 1));
|
||||
if (!x) {
|
||||
return NULL;
|
||||
}
|
||||
if (wuffs_tga__decoder__initialize(
|
||||
x, sizeof(wuffs_tga__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
|
||||
free(x);
|
||||
return NULL;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_tga__decoder() {
|
||||
return sizeof(wuffs_tga__decoder);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func tga.decoder.set_quirk_enabled
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_quirk_enabled(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_image_config
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_image_config(
|
||||
wuffs_tga__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);
|
||||
|
||||
uint32_t v_c = 0;
|
||||
uint32_t v_c5 = 0;
|
||||
uint32_t v_i = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_decode_image_config[0].v_i;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
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_header_id_length = t_0;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
self->private_impl.f_header_color_map_type = t_1;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type > 1) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_type = t_2;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type == 1) ||
|
||||
(self->private_impl.f_header_image_type == 2) ||
|
||||
(self->private_impl.f_header_image_type == 3) ||
|
||||
(self->private_impl.f_header_image_type == 9) ||
|
||||
(self->private_impl.f_header_image_type == 10) ||
|
||||
(self->private_impl.f_header_image_type == 11)) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
uint16_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_3 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3;
|
||||
if (num_bits_3 == 8) {
|
||||
t_3 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_color_map_first_entry_index = t_3;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint16_t t_4;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
|
||||
if (num_bits_4 == 8) {
|
||||
t_4 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_4 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_4)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_color_map_length = t_4;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
self->private_impl.f_header_color_map_entry_size = t_5;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length > 256)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
} else if ((self->private_impl.f_header_color_map_entry_size != 15) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 16) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 24) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length != 0) || (self->private_impl.f_header_color_map_entry_size != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
uint32_t t_6;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_6 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_6;
|
||||
if (num_bits_6 == 8) {
|
||||
t_6 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_6 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_6)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_width = t_6;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
uint32_t t_7;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_7 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_7 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_7;
|
||||
if (num_bits_7 == 8) {
|
||||
t_7 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_7 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_7)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_height = t_7;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_8 = *iop_a_src++;
|
||||
self->private_impl.f_header_pixel_depth = t_8;
|
||||
}
|
||||
if ((self->private_impl.f_header_pixel_depth != 1) &&
|
||||
(self->private_impl.f_header_pixel_depth != 8) &&
|
||||
(self->private_impl.f_header_pixel_depth != 15) &&
|
||||
(self->private_impl.f_header_pixel_depth != 16) &&
|
||||
(self->private_impl.f_header_pixel_depth != 24) &&
|
||||
(self->private_impl.f_header_pixel_depth != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type | 8) == 9) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_pixfmt = 2164523016;
|
||||
self->private_impl.f_opaque = ((self->private_impl.f_header_color_map_entry_size == 15) || (self->private_impl.f_header_color_map_entry_size == 24));
|
||||
} else if ((self->private_impl.f_header_image_type | 8) == 10) {
|
||||
if ((self->private_impl.f_header_pixel_depth == 15) || (self->private_impl.f_header_pixel_depth == 16)) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_bytes_per_pixel = 0;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
} else if (self->private_impl.f_header_pixel_depth == 24) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 3;
|
||||
self->private_impl.f_src_bytes_per_pixel = 3;
|
||||
self->private_impl.f_src_pixfmt = 2147485832;
|
||||
self->private_impl.f_opaque = true;
|
||||
} else if (self->private_impl.f_header_pixel_depth == 32) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_header_pixel_depth == 8) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_opaque = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_9 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_descriptor = t_9;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_descriptor & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
while (v_i < ((uint32_t)(self->private_impl.f_header_color_map_length))) {
|
||||
if (self->private_impl.f_header_color_map_entry_size == 24) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17);
|
||||
uint32_t t_10;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
|
||||
t_10 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 3;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(18);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_10 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_10;
|
||||
if (num_bits_10 == 16) {
|
||||
t_10 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_10 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_10)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_10;
|
||||
}
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c >> 0) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c >> 8) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c >> 16) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = 255;
|
||||
} else if (self->private_impl.f_header_color_map_entry_size == 32) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19);
|
||||
uint32_t t_11;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(20);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_11 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_11;
|
||||
if (num_bits_11 == 24) {
|
||||
t_11 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_11 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_11)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_11;
|
||||
}
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c >> 0) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c >> 8) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c >> 16) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = ((uint8_t)(((v_c >> 24) & 255)));
|
||||
} else {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(21);
|
||||
uint32_t t_12;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_12 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(22);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_12 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_12;
|
||||
if (num_bits_12 == 8) {
|
||||
t_12 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_12 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_12)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_12;
|
||||
}
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = 255;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_src_palette[((v_i * 4) + 0)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 1)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 2)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 3)] = 255;
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
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(
|
||||
a_dst,
|
||||
self->private_impl.f_src_pixfmt,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
self->private_impl.f_opaque);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_decode_image_config[0].v_i = v_i;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_frame_config
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame_config(
|
||||
wuffs_tga__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);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_tga__decoder__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 == 3) {
|
||||
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 == 4) {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__frame_config__set(
|
||||
a_dst,
|
||||
wuffs_base__utility__make_rect_ie_u32(
|
||||
0,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height),
|
||||
((wuffs_base__flicks)(0)),
|
||||
0,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
0,
|
||||
self->private_impl.f_opaque,
|
||||
false,
|
||||
4278190080);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_frame
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts) {
|
||||
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);
|
||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||
uint32_t v_dst_bits_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_pixel = 0;
|
||||
uint32_t v_dst_x = 0;
|
||||
uint32_t v_dst_y = 0;
|
||||
wuffs_base__table_u8 v_tab = {0};
|
||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint64_t v_dst_start = 0;
|
||||
wuffs_base__slice_u8 v_src_palette = {0};
|
||||
uint64_t v_mark = 0;
|
||||
uint64_t v_num_pixels64 = 0;
|
||||
uint32_t v_num_pixels32 = 0;
|
||||
uint32_t v_lit_length = 0;
|
||||
uint32_t v_run_length = 0;
|
||||
uint64_t v_num_dst_bytes = 0;
|
||||
uint32_t v_num_src_bytes = 0;
|
||||
uint32_t v_c = 0;
|
||||
uint32_t v_c5 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
|
||||
if (coro_susp_point) {
|
||||
v_dst_bytes_per_pixel = self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel;
|
||||
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
|
||||
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
|
||||
v_mark = self->private_data.s_decode_frame[0].v_mark;
|
||||
v_num_pixels32 = self->private_data.s_decode_frame[0].v_num_pixels32;
|
||||
v_lit_length = self->private_data.s_decode_frame[0].v_lit_length;
|
||||
v_run_length = self->private_data.s_decode_frame[0].v_run_length;
|
||||
v_num_dst_bytes = self->private_data.s_decode_frame[0].v_num_dst_bytes;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 4) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_tga__decoder__decode_frame_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
v_src_palette = wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024);
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
|
||||
wuffs_base__pixel_buffer__pixel_format(a_dst),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)),
|
||||
wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt),
|
||||
v_src_palette,
|
||||
a_blend);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = v_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
|
||||
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
|
||||
if ((v_dst_bits_per_pixel & 7) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
goto exit;
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y = ((uint32_t)(self->private_impl.f_height - 1));
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type & 8) == 0) {
|
||||
v_lit_length = self->private_impl.f_width;
|
||||
}
|
||||
label__resume__continue:;
|
||||
while (true) {
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024));
|
||||
while (v_dst_y < self->private_impl.f_height) {
|
||||
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
|
||||
v_dst_start = (((uint64_t)(v_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_dst_start <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_start);
|
||||
} else {
|
||||
v_dst = wuffs_base__utility__empty_slice_u8();
|
||||
}
|
||||
while (v_dst_x < self->private_impl.f_width) {
|
||||
if (self->private_impl.f_src_bytes_per_pixel > 0) {
|
||||
if (v_lit_length > 0) {
|
||||
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
v_num_pixels64 = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(self->private_impl.f_src_bytes_per_pixel)));
|
||||
v_num_pixels32 = ((uint32_t)(wuffs_base__u64__min(v_num_pixels64, ((uint64_t)(v_lit_length)))));
|
||||
v_num_dst_bytes = (((uint64_t)(v_num_pixels32)) * v_dst_bytes_per_pixel);
|
||||
v_num_src_bytes = (v_num_pixels32 * self->private_impl.f_src_bytes_per_pixel);
|
||||
self->private_data.s_decode_frame[0].scratch = v_num_src_bytes;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_frame[0].scratch;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
|
||||
if (v_num_dst_bytes <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_num_dst_bytes);
|
||||
} else {
|
||||
v_dst = wuffs_base__utility__empty_slice_u8();
|
||||
}
|
||||
v_dst_x += v_num_pixels32;
|
||||
v_lit_length = (((uint32_t)(v_lit_length - v_num_pixels32)) & 65535);
|
||||
if (v_lit_length > 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
} else if (v_run_length > 0) {
|
||||
v_run_length -= 1;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 4), self->private_impl.f_scratch_bytes_per_pixel));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128) {
|
||||
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1);
|
||||
iop_a_src += 1;
|
||||
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_src_bytes_per_pixel == 1) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
} else if (self->private_impl.f_src_bytes_per_pixel == 3) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[1] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[2] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 5) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[1] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[2] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[3] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
}
|
||||
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (v_lit_length > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_c = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_scratch[0] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_scratch[1] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_scratch[2] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_scratch[3] = 255;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, 4));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
v_lit_length -= 1;
|
||||
} else if (v_run_length > 0) {
|
||||
v_run_length -= 1;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 4), self->private_impl.f_scratch_bytes_per_pixel));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128) {
|
||||
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1);
|
||||
iop_a_src += 1;
|
||||
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 3) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
v_c = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_scratch[0] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_scratch[1] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_scratch[2] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_scratch[3] = 255;
|
||||
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
v_dst_x = 0;
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y -= 1;
|
||||
} else {
|
||||
v_dst_y += 1;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type & 8) == 0) {
|
||||
v_lit_length = self->private_impl.f_width;
|
||||
}
|
||||
}
|
||||
goto label__resume__break;
|
||||
}
|
||||
label__resume__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
|
||||
self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
|
||||
self->private_data.s_decode_frame[0].v_dst_x = v_dst_x;
|
||||
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
|
||||
self->private_data.s_decode_frame[0].v_mark = v_mark;
|
||||
self->private_data.s_decode_frame[0].v_num_pixels32 = v_num_pixels32;
|
||||
self->private_data.s_decode_frame[0].v_lit_length = v_lit_length;
|
||||
self->private_data.s_decode_frame[0].v_run_length = v_run_length;
|
||||
self->private_data.s_decode_frame[0].v_num_dst_bytes = v_num_dst_bytes;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.frame_dirty_rect
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
|
||||
wuffs_tga__decoder__frame_dirty_rect(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_rect_ie_u32(
|
||||
0,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height);
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_animation_loops
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint32_t
|
||||
wuffs_tga__decoder__num_animation_loops(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_decoded_frame_configs
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frame_configs(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 3) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_decoded_frames
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frames(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 4) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.restart_frame
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__restart_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if (a_index != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.set_report_metadata
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_report_metadata(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_fourcc,
|
||||
bool a_report) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.tell_me_more
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__tell_me_more(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_dst || !a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 4)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||
goto exit;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.workbuf_len
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_tga__decoder__workbuf_len(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_range_ii_u64(0, 0);
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
@@ -42818,7 +44662,8 @@ DecodeImageCallbacks::AllocWorkbufResult::AllocWorkbufResult(
|
||||
|
||||
wuffs_base__image_decoder::unique_ptr //
|
||||
DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
switch (fourcc) {
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
|
||||
case WUFFS_BASE__FOURCC__BMP:
|
||||
@@ -42844,6 +44689,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
@@ -43071,10 +44921,17 @@ redirect:
|
||||
// Determine the image format.
|
||||
if (!redirected) {
|
||||
while (true) {
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice());
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice(),
|
||||
io_buf.meta.closed);
|
||||
if (fourcc > 0) {
|
||||
break;
|
||||
} else if ((fourcc == 0) && (io_buf.reader_length() >= 64)) {
|
||||
// Having (fourcc == 0) means that Wuffs' built in MIME sniffer
|
||||
// didn't recognize the image format. Nonetheless, custom callbacks
|
||||
// may still be able to do their own MIME sniffing, for exotic image
|
||||
// types. We try to give them at least 64 bytes of prefix data when
|
||||
// one-shot-calling callbacks.SelectDecoder. There is no mechanism
|
||||
// for the callbacks to request a longer prefix.
|
||||
break;
|
||||
} else if (io_buf.meta.closed || (io_buf.writer_length() == 0)) {
|
||||
fourcc = 0;
|
||||
@@ -43115,8 +44972,7 @@ redirect:
|
||||
|
||||
// Select the image decoder.
|
||||
image_decoder = callbacks.SelectDecoder(
|
||||
(uint32_t)fourcc,
|
||||
fourcc ? wuffs_base__empty_slice_u8() : io_buf.reader_slice());
|
||||
(uint32_t)fourcc, io_buf.reader_slice(), io_buf.meta.closed);
|
||||
if (!image_decoder) {
|
||||
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
|
||||
}
|
||||
@@ -43131,6 +44987,9 @@ redirect:
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
|
||||
}
|
||||
|
||||
+2410
-551
@@ -85,15 +85,15 @@ extern "C" {
|
||||
// each major.minor branch, the commit count should increase monotonically.
|
||||
//
|
||||
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
|
||||
// e44920d382c9b542e17287664937e547becc7148 committed on 2021-11-19.
|
||||
// adfd2965cc104f3de6cccaed5095721d042c1251 committed on 2022-01-18.
|
||||
#define WUFFS_VERSION 0x000030000
|
||||
#define WUFFS_VERSION_MAJOR 0
|
||||
#define WUFFS_VERSION_MINOR 3
|
||||
#define WUFFS_VERSION_PATCH 0
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.12"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3202
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20211119
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.12+3202.20211119"
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.14"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3273
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20220118
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.14+3273.20220118"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
@@ -687,6 +687,9 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// PostScript.
|
||||
#define WUFFS_BASE__FOURCC__PS 0x50532020
|
||||
|
||||
// Quite OK Image.
|
||||
#define WUFFS_BASE__FOURCC__QOI 0x514F4920
|
||||
|
||||
// Random Access Compression.
|
||||
#define WUFFS_BASE__FOURCC__RAC 0x52414320
|
||||
|
||||
@@ -714,6 +717,9 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// Text.
|
||||
#define WUFFS_BASE__FOURCC__TEXT 0x54455854
|
||||
|
||||
// Truevision Advanced Raster Graphics Adapter.
|
||||
#define WUFFS_BASE__FOURCC__TGA 0x54474120
|
||||
|
||||
// Tagged Image File Format.
|
||||
#define WUFFS_BASE__FOURCC__TIFF 0x54494646
|
||||
|
||||
@@ -726,15 +732,12 @@ typedef struct wuffs_base__transform__output__struct {
|
||||
// Wireless Bitmap.
|
||||
#define WUFFS_BASE__FOURCC__WBMP 0x57424D50
|
||||
|
||||
// Web Picture.
|
||||
#define WUFFS_BASE__FOURCC__WEBP 0x57454250
|
||||
|
||||
// Web Open Font Format.
|
||||
#define WUFFS_BASE__FOURCC__WOFF 0x574F4646
|
||||
|
||||
// Web Picture (VP8).
|
||||
#define WUFFS_BASE__FOURCC__WP8 0x57503820
|
||||
|
||||
// Web Picture (VP8 Lossless).
|
||||
#define WUFFS_BASE__FOURCC__WP8L 0x5750384C
|
||||
|
||||
// Extensible Markup Language.
|
||||
#define WUFFS_BASE__FOURCC__XML 0x584D4C20
|
||||
|
||||
@@ -1683,13 +1686,19 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// wuffs_base__magic_number_guess_fourcc guesses the file format of some data,
|
||||
// given its opening bytes. It returns a positive FourCC value on success.
|
||||
// given its starting bytes (the prefix_data argument) and whether or not there
|
||||
// may be further bytes (the prefix_closed argument; true means that
|
||||
// prefix_data is the entire data).
|
||||
//
|
||||
// It returns a positive FourCC value on success.
|
||||
//
|
||||
// It returns zero if nothing matches its hard-coded list of 'magic numbers'.
|
||||
//
|
||||
// It returns a negative value if a longer prefix is required for a conclusive
|
||||
// result. For example, seeing a single 'B' byte is not enough to discriminate
|
||||
// the BMP and BPG image file formats.
|
||||
// It returns a negative value if prefix_closed is false and a longer prefix is
|
||||
// required for a conclusive result. For example, a single 'B' byte (without
|
||||
// further data) is not enough to discriminate the BMP and BPG image file
|
||||
// formats. Similarly, a single '\xFF' byte might be the start of JPEG data or
|
||||
// it might be the start of some other binary data.
|
||||
//
|
||||
// It does not do a full validity check. Like any guess made from a short
|
||||
// prefix of the data, it may return false positives. Data that starts with 99
|
||||
@@ -1704,7 +1713,8 @@ wuffs_base__table__flattened_length(size_t width,
|
||||
// function requires the WUFFS_CONFIG__MODULE__BASE__MAGIC sub-module, not just
|
||||
// WUFFS_CONFIG__MODULE__BASE__CORE.
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix);
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// ---------------- Ranges and Rects
|
||||
|
||||
@@ -7362,7 +7372,6 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t v_length;
|
||||
uint32_t v_dist_minus_1;
|
||||
uint32_t v_hlen;
|
||||
uint32_t v_hdist;
|
||||
uint64_t scratch;
|
||||
} s_decode_huffman_slow[1];
|
||||
} private_data;
|
||||
@@ -8932,6 +8941,8 @@ extern const char wuffs_zlib__error__incorrect_dictionary[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE 2113790976
|
||||
|
||||
#define WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
@@ -9043,6 +9054,7 @@ struct wuffs_zlib__decoder__struct {
|
||||
bool f_header_complete;
|
||||
bool f_got_dictionary;
|
||||
bool f_want_dictionary;
|
||||
bool f_quirks[1];
|
||||
bool f_ignore_checksum;
|
||||
uint32_t f_dict_id_got;
|
||||
uint32_t f_dict_id_want;
|
||||
@@ -9331,6 +9343,7 @@ struct wuffs_png__decoder__struct {
|
||||
uint64_t f_pass_workbuf_length;
|
||||
uint8_t f_call_sequence;
|
||||
bool f_report_metadata_chrm;
|
||||
bool f_report_metadata_exif;
|
||||
bool f_report_metadata_gama;
|
||||
bool f_report_metadata_iccp;
|
||||
bool f_report_metadata_kvp;
|
||||
@@ -9343,6 +9356,7 @@ struct wuffs_png__decoder__struct {
|
||||
bool f_seen_actl;
|
||||
bool f_seen_chrm;
|
||||
bool f_seen_fctl;
|
||||
bool f_seen_exif;
|
||||
bool f_seen_gama;
|
||||
bool f_seen_iccp;
|
||||
bool f_seen_idat;
|
||||
@@ -9627,6 +9641,351 @@ struct wuffs_png__decoder__struct {
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_tga__error__bad_header[];
|
||||
extern const char wuffs_tga__error__bad_run_length_encoding[];
|
||||
extern const char wuffs_tga__error__unsupported_tga_file[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
#define WUFFS_TGA__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
|
||||
typedef struct wuffs_tga__decoder__struct wuffs_tga__decoder;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
|
||||
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
|
||||
//
|
||||
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
|
||||
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_tga__decoder__initialize(
|
||||
wuffs_tga__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options);
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_tga__decoder();
|
||||
|
||||
// ---------------- Allocs
|
||||
|
||||
// These functions allocate and initialize Wuffs structs. They return NULL if
|
||||
// memory allocation fails. If they return non-NULL, there is no need to call
|
||||
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
|
||||
// calling free on the returned pointer. That pointer is effectively a C++
|
||||
// std::unique_ptr<T, decltype(&free)>.
|
||||
|
||||
wuffs_tga__decoder*
|
||||
wuffs_tga__decoder__alloc();
|
||||
|
||||
static inline wuffs_base__image_decoder*
|
||||
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder() {
|
||||
return (wuffs_base__image_decoder*)(wuffs_tga__decoder__alloc());
|
||||
}
|
||||
|
||||
// ---------------- Upcasts
|
||||
|
||||
static inline wuffs_base__image_decoder*
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(
|
||||
wuffs_tga__decoder* p) {
|
||||
return (wuffs_base__image_decoder*)p;
|
||||
}
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_quirk_enabled(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_image_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame_config(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
|
||||
wuffs_tga__decoder__frame_dirty_rect(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint32_t
|
||||
wuffs_tga__decoder__num_animation_loops(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frame_configs(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frames(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__restart_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_report_metadata(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_fourcc,
|
||||
bool a_report);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__tell_me_more(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_tga__decoder__workbuf_len(
|
||||
const wuffs_tga__decoder* self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------- Struct Definitions
|
||||
|
||||
// These structs' fields, and the sizeof them, are private implementation
|
||||
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||
//
|
||||
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||
|
||||
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
struct wuffs_tga__decoder__struct {
|
||||
// Do not access the private_impl's or private_data's fields directly. There
|
||||
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
|
||||
// the wuffs_foo__bar__baz functions.
|
||||
//
|
||||
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
|
||||
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
|
||||
|
||||
struct {
|
||||
uint32_t magic;
|
||||
uint32_t active_coroutine;
|
||||
wuffs_base__vtable vtable_for__wuffs_base__image_decoder;
|
||||
wuffs_base__vtable null_vtable;
|
||||
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_call_sequence;
|
||||
uint8_t f_header_id_length;
|
||||
uint8_t f_header_color_map_type;
|
||||
uint8_t f_header_image_type;
|
||||
uint16_t f_header_color_map_first_entry_index;
|
||||
uint16_t f_header_color_map_length;
|
||||
uint8_t f_header_color_map_entry_size;
|
||||
uint8_t f_header_pixel_depth;
|
||||
uint8_t f_header_image_descriptor;
|
||||
bool f_opaque;
|
||||
uint32_t f_scratch_bytes_per_pixel;
|
||||
uint32_t f_src_bytes_per_pixel;
|
||||
uint32_t f_src_pixfmt;
|
||||
uint64_t f_frame_config_io_position;
|
||||
wuffs_base__pixel_swizzler f_swizzler;
|
||||
|
||||
uint32_t p_decode_image_config[1];
|
||||
uint32_t p_decode_frame_config[1];
|
||||
uint32_t p_decode_frame[1];
|
||||
} private_impl;
|
||||
|
||||
struct {
|
||||
uint8_t f_dst_palette[1024];
|
||||
uint8_t f_src_palette[1024];
|
||||
uint8_t f_scratch[4];
|
||||
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
uint64_t scratch;
|
||||
} s_decode_image_config[1];
|
||||
struct {
|
||||
uint64_t v_dst_bytes_per_pixel;
|
||||
uint32_t v_dst_x;
|
||||
uint32_t v_dst_y;
|
||||
uint64_t v_mark;
|
||||
uint32_t v_num_pixels32;
|
||||
uint32_t v_lit_length;
|
||||
uint32_t v_run_length;
|
||||
uint64_t v_num_dst_bytes;
|
||||
uint64_t scratch;
|
||||
} s_decode_frame[1];
|
||||
} private_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
using unique_ptr = std::unique_ptr<wuffs_tga__decoder, decltype(&free)>;
|
||||
|
||||
// On failure, the alloc_etc functions return nullptr. They don't throw.
|
||||
|
||||
static inline unique_ptr
|
||||
alloc() {
|
||||
return unique_ptr(wuffs_tga__decoder__alloc(), &free);
|
||||
}
|
||||
|
||||
static inline wuffs_base__image_decoder::unique_ptr
|
||||
alloc_as__wuffs_base__image_decoder() {
|
||||
return wuffs_base__image_decoder::unique_ptr(
|
||||
wuffs_tga__decoder__alloc_as__wuffs_base__image_decoder(), &free);
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
|
||||
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
// Disallow constructing or copying an object via standard C++ mechanisms,
|
||||
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
|
||||
// size and field layout is not part of the public, stable, memory-safe API.
|
||||
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
|
||||
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
|
||||
// their first argument) rather than tweaking bar.private_impl.qux fields.
|
||||
//
|
||||
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
|
||||
// order to provide convenience methods. These forward on "this", so that you
|
||||
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
|
||||
wuffs_tga__decoder__struct() = delete;
|
||||
wuffs_tga__decoder__struct(const wuffs_tga__decoder__struct&) = delete;
|
||||
wuffs_tga__decoder__struct& operator=(
|
||||
const wuffs_tga__decoder__struct&) = delete;
|
||||
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
#if !defined(WUFFS_IMPLEMENTATION)
|
||||
// As above, the size of the struct is not part of the public API, and unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
|
||||
// allocated, not stack allocated. Its size is not intended to be known at
|
||||
// compile time, but it is unfortunately divulged as a side effect of
|
||||
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
|
||||
// instead of "sizeof T", invoking the operator. To make the two values
|
||||
// different, so that passing the latter will be rejected by the initialize
|
||||
// function, we add an arbitrary amount of dead weight.
|
||||
uint8_t dead_weight[123000000]; // 123 MB.
|
||||
#endif // !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
initialize(
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options) {
|
||||
return wuffs_tga__decoder__initialize(
|
||||
this, sizeof_star_self, wuffs_version, options);
|
||||
}
|
||||
|
||||
inline wuffs_base__image_decoder*
|
||||
upcast_as__wuffs_base__image_decoder() {
|
||||
return (wuffs_base__image_decoder*)this;
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_quirk_enabled(
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_tga__decoder__set_quirk_enabled(this, a_quirk, a_enabled);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_image_config(
|
||||
wuffs_base__image_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__decode_image_config(this, a_dst, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_frame_config(
|
||||
wuffs_base__frame_config* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__decode_frame_config(this, a_dst, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
decode_frame(
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts) {
|
||||
return wuffs_tga__decoder__decode_frame(this, a_dst, a_src, a_blend, a_workbuf, a_opts);
|
||||
}
|
||||
|
||||
inline wuffs_base__rect_ie_u32
|
||||
frame_dirty_rect() const {
|
||||
return wuffs_tga__decoder__frame_dirty_rect(this);
|
||||
}
|
||||
|
||||
inline uint32_t
|
||||
num_animation_loops() const {
|
||||
return wuffs_tga__decoder__num_animation_loops(this);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
num_decoded_frame_configs() const {
|
||||
return wuffs_tga__decoder__num_decoded_frame_configs(this);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
num_decoded_frames() const {
|
||||
return wuffs_tga__decoder__num_decoded_frames(this);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
restart_frame(
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position) {
|
||||
return wuffs_tga__decoder__restart_frame(this, a_index, a_io_position);
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
set_report_metadata(
|
||||
uint32_t a_fourcc,
|
||||
bool a_report) {
|
||||
return wuffs_tga__decoder__set_report_metadata(this, a_fourcc, a_report);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
tell_me_more(
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return wuffs_tga__decoder__tell_me_more(this, a_dst, a_minfo, a_src);
|
||||
}
|
||||
|
||||
inline wuffs_base__range_ii_u64
|
||||
workbuf_len() const {
|
||||
return wuffs_tga__decoder__workbuf_len(this);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
}; // struct wuffs_tga__decoder__struct
|
||||
|
||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
extern const char wuffs_wbmp__error__bad_header[];
|
||||
|
||||
// ---------------- Public Consts
|
||||
@@ -10232,9 +10591,13 @@ class DecodeImageCallbacks {
|
||||
// Returning a nullptr means failure (DecodeImage_UnsupportedImageFormat).
|
||||
//
|
||||
// Common formats will have a FourCC value in the range [1 ..= 0x7FFF_FFFF],
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that the
|
||||
// caller is responsible for examining the opening bytes (a prefix) of the
|
||||
// input data. SelectDecoder implementations should not modify those bytes.
|
||||
// such as WUFFS_BASE__FOURCC__JPEG. A zero FourCC value means that Wuffs'
|
||||
// standard library did not recognize the image format but if SelectDecoder
|
||||
// was overridden, it may examine the input data's starting bytes and still
|
||||
// provide its own image decoder, e.g. for an exotic image file format that's
|
||||
// not in Wuffs' standard library. The prefix_etc fields have the same
|
||||
// meaning as wuffs_base__magic_number_guess_fourcc arguments. SelectDecoder
|
||||
// implementations should not modify prefix_data's contents.
|
||||
//
|
||||
// SelectDecoder might be called more than once, since some image file
|
||||
// formats can wrap others. For example, a nominal BMP file can actually
|
||||
@@ -10249,9 +10612,12 @@ class DecodeImageCallbacks {
|
||||
// - WUFFS_BASE__FOURCC__GIF
|
||||
// - WUFFS_BASE__FOURCC__NIE
|
||||
// - WUFFS_BASE__FOURCC__PNG
|
||||
// - WUFFS_BASE__FOURCC__TGA
|
||||
// - WUFFS_BASE__FOURCC__WBMP
|
||||
virtual wuffs_base__image_decoder::unique_ptr //
|
||||
SelectDecoder(uint32_t fourcc, wuffs_base__slice_u8 prefix);
|
||||
SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed);
|
||||
|
||||
// HandleMetadata acknowledges image metadata. minfo.flavor will be one of:
|
||||
// - WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
|
||||
@@ -10371,8 +10737,8 @@ struct DecodeImageArgFlags {
|
||||
// DefaultValue returns 0.
|
||||
static DecodeImageArgFlags DefaultValue();
|
||||
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, GAMA,
|
||||
// ICCP, KVP, SRGB and XMP.
|
||||
// TODO: support all of the REPORT_METADATA_ETC flags, not just CHRM, EXIF,
|
||||
// GAMA, ICCP, KVP, SRGB and XMP.
|
||||
|
||||
// Background Color.
|
||||
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
|
||||
@@ -11037,7 +11403,7 @@ wuffs_base__io_writer__limit(uint8_t** ptr_io2_w,
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11045,7 +11411,7 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
return 0;
|
||||
}
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
if ((size_t)(p - io1_w) < (size_t)(distance)) {
|
||||
if ((size_t)(p - io0_w) < (size_t)(distance)) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t* q = p - distance;
|
||||
@@ -11082,10 +11448,10 @@ wuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11117,11 +11483,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -11157,11 +11523,11 @@ wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fa
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance >= 8
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - distance <= (*ptr_iop_w - io0_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io0_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
@@ -15569,8 +15935,127 @@ done:
|
||||
|
||||
// ---------------- Magic Numbers
|
||||
|
||||
// ICO doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly ICO.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// first two bytes are 0x00.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/ico/
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[3] != 0) {
|
||||
return 0;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01: // ICO
|
||||
case 0x02: // CUR
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The Number Of Images should be positive.
|
||||
if (prefix_data.len < 6) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[4] == 0) && (prefix_data.ptr[5] == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The first ICONDIRENTRY's fourth byte should be zero.
|
||||
if (prefix_data.len < 10) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[9] != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: have a separate FourCC for CUR?
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
|
||||
// TGA doesn't start with a magic identifier. Instead, see if the opening bytes
|
||||
// are plausibly TGA.
|
||||
//
|
||||
// Callers should have already verified that (prefix_data.len >= 2) and the
|
||||
// second byte (prefix_data.ptr[1], the Color Map Type byte), is either 0x00 or
|
||||
// 0x01.
|
||||
//
|
||||
// See:
|
||||
// - https://docs.fileformat.com/image/tga/
|
||||
// - https://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf
|
||||
static int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// Allow-list for the Image Type field.
|
||||
if (prefix_data.len < 3) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[2]) {
|
||||
case 0x01:
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
case 0x09:
|
||||
case 0x0A:
|
||||
case 0x0B:
|
||||
break;
|
||||
default:
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Color Map Entry Size field (if the Color Map Type field
|
||||
// is non-zero) or else all the Color Map fields should be zero.
|
||||
if (prefix_data.len < 8) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if (prefix_data.ptr[1] != 0x00) {
|
||||
switch (prefix_data.ptr[7]) {
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
} else if ((prefix_data.ptr[3] | prefix_data.ptr[4] | prefix_data.ptr[5] |
|
||||
prefix_data.ptr[6] | prefix_data.ptr[7]) != 0x00) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allow-list for the Pixel Depth field.
|
||||
if (prefix_data.len < 17) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
switch (prefix_data.ptr[16]) {
|
||||
case 0x01:
|
||||
case 0x08:
|
||||
case 0x0F:
|
||||
case 0x10:
|
||||
case 0x18:
|
||||
case 0x20:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0x54474120; // 'TGA 'be
|
||||
}
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC int32_t //
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
// This is similar to (but different from):
|
||||
// - the magic/Magdir tables under https://github.com/file/file
|
||||
// - the MIME Sniffing algorithm at https://mimesniff.spec.whatwg.org/
|
||||
|
||||
// table holds the 'magic numbers' (which are actually variable length
|
||||
// strings). The strings may contain NUL bytes, so the "const char* magic"
|
||||
// value starts with the length-minus-1 of the 'magic number'.
|
||||
@@ -15591,15 +16076,16 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
|
||||
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
||||
{+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI
|
||||
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||
};
|
||||
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
||||
|
||||
if (prefix.len == 0) {
|
||||
return -1;
|
||||
if (prefix_data.len == 0) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint8_t pre_first_byte = prefix.ptr[0];
|
||||
uint8_t pre_first_byte = prefix_data.ptr[0];
|
||||
|
||||
int32_t fourcc = 0;
|
||||
size_t i;
|
||||
@@ -15618,11 +16104,11 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
|
||||
const char* mag_remaining_ptr = table[i].magic + 2;
|
||||
uint8_t* pre_remaining_ptr = prefix.ptr + 1;
|
||||
size_t pre_remaining_len = prefix.len - 1;
|
||||
uint8_t* pre_remaining_ptr = prefix_data.ptr + 1;
|
||||
size_t pre_remaining_len = prefix_data.len - 1;
|
||||
if (pre_remaining_len < mag_remaining_len) {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, pre_remaining_len)) {
|
||||
return -1;
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
} else {
|
||||
if (!memcmp(pre_remaining_ptr, mag_remaining_ptr, mag_remaining_len)) {
|
||||
@@ -15630,6 +16116,14 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix_data.len < 2) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[1] == 0x00) || (prefix_data.ptr[1] == 0x01)) {
|
||||
return wuffs_base__magic_number_guess_fourcc__maybe_tga(prefix_data,
|
||||
prefix_closed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
match:
|
||||
@@ -15638,31 +16132,38 @@ match:
|
||||
fourcc = -fourcc;
|
||||
|
||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||
if (prefix.len < 16) {
|
||||
return -1;
|
||||
if (prefix_data.len < 12) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
}
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 8);
|
||||
uint32_t x = wuffs_base__peek_u32be__no_bounds_check(prefix_data.ptr + 8);
|
||||
if (x == 0x57454250) { // 'WEBP'be
|
||||
uint32_t y = wuffs_base__peek_u32be__no_bounds_check(prefix.ptr + 12);
|
||||
if (y == 0x56503820) { // 'VP8 'be
|
||||
return 0x57503820; // 'WP8 'be
|
||||
} else if (y == 0x5650384C) { // 'VP8L'be
|
||||
return 0x5750384C; // 'WP8L'be
|
||||
}
|
||||
return 0x57454250; // 'WEBP'be
|
||||
}
|
||||
|
||||
} else if (fourcc == 0x30302020) { // '00 'be
|
||||
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
||||
if (prefix.len < 4) {
|
||||
return -1;
|
||||
} else if ((prefix.ptr[2] != 0x00) &&
|
||||
((prefix.ptr[2] >= 0x80) || (prefix.ptr[3] != 0x00))) {
|
||||
// Unfortunately, some file formats also don't start with a magic
|
||||
// identifier, so we have to use heuristics (where the order matters, the
|
||||
// same as /usr/bin/file's magic/Magdir tables) as best we can. Maybe
|
||||
// it's TGA, ICO/CUR, etc. Maybe it's something else.
|
||||
int32_t tga = wuffs_base__magic_number_guess_fourcc__maybe_tga(
|
||||
prefix_data, prefix_closed);
|
||||
if (tga != 0) {
|
||||
return tga;
|
||||
}
|
||||
int32_t ico = wuffs_base__magic_number_guess_fourcc__maybe_ico(
|
||||
prefix_data, prefix_closed);
|
||||
if (ico != 0) {
|
||||
return ico;
|
||||
}
|
||||
if (prefix_data.len < 4) {
|
||||
return prefix_closed ? 0 : -1;
|
||||
} else if ((prefix_data.ptr[2] != 0x00) &&
|
||||
((prefix_data.ptr[2] >= 0x80) ||
|
||||
(prefix_data.ptr[3] != 0x00))) {
|
||||
// Roughly speaking, this could be a non-degenerate (non-0-width and
|
||||
// non-0-height) WBMP image.
|
||||
return 0x57424D50; // 'WBMP'be
|
||||
} else if (((prefix.ptr[2] == 0x01) || (prefix.ptr[2] == 0x02)) &&
|
||||
(prefix.ptr[3] == 0x00)) {
|
||||
return 0x49434F20; // 'ICO 'be
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -16166,14 +16667,23 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16210,14 +16720,23 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_nonpremul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
//
|
||||
// If the destination is transparent then SRC_OVER is equivalent to SRC: just
|
||||
// return src_nonpremul. This isn't just an optimization (skipping the rest
|
||||
// of the function's computation). It also preserves the nonpremul
|
||||
// distinction between e.g. transparent red and transparent blue that would
|
||||
// otherwise be lost by converting from nonpremul to premul and back.
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
if (da == 0) {
|
||||
return src_nonpremul;
|
||||
}
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16248,14 +16767,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_nonpremul_premul_u32_axxx(uint32_t dst_nonpremul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_nonpremul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_nonpremul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_nonpremul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_nonpremul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16292,14 +16811,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_nonpremul_premul_u64_axxx(uint64_t dst_nonpremul,
|
||||
uint64_t src_premul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_nonpremul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_nonpremul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_nonpremul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_nonpremul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_premul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_premul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_premul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_premul >> 0);
|
||||
|
||||
// Convert dst from nonpremul to premul.
|
||||
dr = (dr * da) / 0xFFFF;
|
||||
@@ -16330,14 +16849,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_nonpremul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_nonpremul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_nonpremul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_nonpremul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_nonpremul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_nonpremul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -16362,14 +16881,14 @@ static inline uint64_t //
|
||||
wuffs_base__composite_premul_nonpremul_u64_axxx(uint64_t dst_premul,
|
||||
uint64_t src_nonpremul) {
|
||||
// Extract components.
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
uint64_t da = 0xFFFF & (dst_premul >> 48);
|
||||
uint64_t dr = 0xFFFF & (dst_premul >> 32);
|
||||
uint64_t dg = 0xFFFF & (dst_premul >> 16);
|
||||
uint64_t db = 0xFFFF & (dst_premul >> 0);
|
||||
uint64_t sa = 0xFFFF & (src_nonpremul >> 48);
|
||||
uint64_t sr = 0xFFFF & (src_nonpremul >> 32);
|
||||
uint64_t sg = 0xFFFF & (src_nonpremul >> 16);
|
||||
uint64_t sb = 0xFFFF & (src_nonpremul >> 0);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint64_t ia = 0xFFFF - sa;
|
||||
@@ -16388,14 +16907,14 @@ static inline uint32_t //
|
||||
wuffs_base__composite_premul_premul_u32_axxx(uint32_t dst_premul,
|
||||
uint32_t src_premul) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
uint32_t da = 0x101 * (0xFF & (dst_premul >> 24));
|
||||
uint32_t dr = 0x101 * (0xFF & (dst_premul >> 16));
|
||||
uint32_t dg = 0x101 * (0xFF & (dst_premul >> 8));
|
||||
uint32_t db = 0x101 * (0xFF & (dst_premul >> 0));
|
||||
uint32_t sa = 0x101 * (0xFF & (src_premul >> 24));
|
||||
uint32_t sr = 0x101 * (0xFF & (src_premul >> 16));
|
||||
uint32_t sg = 0x101 * (0xFF & (src_premul >> 8));
|
||||
uint32_t sb = 0x101 * (0xFF & (src_premul >> 0));
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17455,13 +17974,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17503,13 +18022,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 6));
|
||||
uint32_t sr = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 4));
|
||||
uint32_t sg = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 2));
|
||||
uint32_t sb = ((uint32_t)wuffs_base__peek_u16le__no_bounds_check(s + 0));
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17578,13 +18097,13 @@ wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17656,13 +18175,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over(
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -17731,13 +18250,13 @@ wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over(uint8_t* dst_ptr,
|
||||
|
||||
while (n >= 1) {
|
||||
// Extract 16-bit color components.
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
uint32_t sa = 0x101 * ((uint32_t)s[3]);
|
||||
uint32_t sb = 0x101 * ((uint32_t)s[2]);
|
||||
uint32_t sg = 0x101 * ((uint32_t)s[1]);
|
||||
uint32_t sr = 0x101 * ((uint32_t)s[0]);
|
||||
uint32_t dr = 0x101 * ((uint32_t)d[2]);
|
||||
uint32_t dg = 0x101 * ((uint32_t)d[1]);
|
||||
uint32_t db = 0x101 * ((uint32_t)d[0]);
|
||||
|
||||
// Calculate the inverse of the src-alpha: how much of the dst to keep.
|
||||
uint32_t ia = 0xFFFF - sa;
|
||||
@@ -26991,14 +27510,17 @@ wuffs_deflate__decoder__init_huff(
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_remaining != 0) {
|
||||
if ((a_which == 1) &&
|
||||
(v_counts[1] == 1) &&
|
||||
(self->private_data.f_code_lengths[a_n_codes0] == 1) &&
|
||||
((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
|
||||
self->private_impl.f_n_huffs_bits[1] = 1;
|
||||
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[0] | 1);
|
||||
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
|
||||
return wuffs_base__make_status(NULL);
|
||||
if ((a_which == 1) && (v_counts[1] == 1) && ((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
|
||||
v_i = 0;
|
||||
while (v_i <= 29) {
|
||||
if (self->private_data.f_code_lengths[(a_n_codes0 + v_i)] == 1) {
|
||||
self->private_impl.f_n_huffs_bits[1] = 1;
|
||||
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[v_i] | 1);
|
||||
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code_under_subscribed);
|
||||
}
|
||||
@@ -27336,9 +27858,8 @@ wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27602,9 +28123,8 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27815,9 +28335,8 @@ wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -27938,7 +28457,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_length = self->private_data.s_decode_huffman_slow[0].v_length;
|
||||
v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
|
||||
v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
|
||||
v_hdist = self->private_data.s_decode_huffman_slow[0].v_hdist;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
@@ -28135,55 +28653,29 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
label__inner__continue:;
|
||||
while (true) {
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) {
|
||||
v_hdist = ((uint32_t)((((uint64_t)((v_dist_minus_1 + 1))) - ((uint64_t)(iop_a_dst - io0_a_dst)))));
|
||||
if (v_length > v_hdist) {
|
||||
v_length -= v_hdist;
|
||||
if (v_hdist < v_length) {
|
||||
v_hlen = v_hdist;
|
||||
} else {
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295)));
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
while (true) {
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767)));
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label__4__break;
|
||||
}
|
||||
if (v_n_copied > 0) {
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist = (((uint32_t)(v_hdist + v_n_copied)) & 32767);
|
||||
if (v_hdist == 0) {
|
||||
goto label__4__break;
|
||||
}
|
||||
}
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), ((self->private_impl.f_history_index - v_hdist) & 32767)));
|
||||
if (v_n_copied < v_hlen) {
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__inner__continue;
|
||||
}
|
||||
label__4__break:;
|
||||
if (v_hlen > 0) {
|
||||
while (true) {
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 32768), (v_hdist & 32767)));
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label__5__break;
|
||||
}
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist += v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label__5__break:;
|
||||
}
|
||||
v_length -= v_hlen;
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
@@ -28191,14 +28683,12 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_n_copied = wuffs_base__io_writer__limited_copy_u32_from_history(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
if (v_length <= v_n_copied) {
|
||||
v_length = 0;
|
||||
goto label__6__break;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
v_length -= v_n_copied;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label__6__break:;
|
||||
}
|
||||
label__loop__break:;
|
||||
self->private_impl.f_bits = v_bits;
|
||||
@@ -28227,7 +28717,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
self->private_data.s_decode_huffman_slow[0].v_length = v_length;
|
||||
self->private_data.s_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
|
||||
self->private_data.s_decode_huffman_slow[0].v_hlen = v_hlen;
|
||||
self->private_data.s_decode_huffman_slow[0].v_hdist = v_hdist;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -29315,7 +29804,10 @@ wuffs_gif__decoder__num_animation_loops(
|
||||
if (self->private_impl.f_seen_num_animation_loops_value) {
|
||||
return self->private_impl.f_num_animation_loops_value;
|
||||
}
|
||||
return 1;
|
||||
if (self->private_impl.f_num_decoded_frame_configs_value > 1) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func gif.decoder.num_decoded_frame_configs
|
||||
@@ -34914,6 +35406,10 @@ const char wuffs_zlib__error__incorrect_dictionary[] = "#zlib: incorrect diction
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
#define WUFFS_ZLIB__QUIRKS_BASE 2113790976
|
||||
|
||||
#define WUFFS_ZLIB__QUIRKS_COUNT 1
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
@@ -35077,8 +35573,15 @@ wuffs_zlib__decoder__set_quirk_enabled(
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
if (a_quirk == 1) {
|
||||
if (self->private_impl.f_header_complete) {
|
||||
self->private_impl.f_bad_call_sequence = true;
|
||||
} else if (a_quirk == 1) {
|
||||
self->private_impl.f_ignore_checksum = a_enabled;
|
||||
} else if (a_quirk >= 2113790976) {
|
||||
a_quirk -= 2113790976;
|
||||
if (a_quirk < 1) {
|
||||
self->private_impl.f_quirks[a_quirk] = a_enabled;
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
@@ -35168,6 +35671,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
if (self->private_impl.f_bad_call_sequence) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_quirks[0]) {
|
||||
} else if ( ! self->private_impl.f_want_dictionary) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
@@ -35275,7 +35779,7 @@ wuffs_zlib__decoder__transform_io(
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum) {
|
||||
if ( ! self->private_impl.f_ignore_checksum && ! self->private_impl.f_quirks[0]) {
|
||||
v_checksum_got = wuffs_adler32__hasher__update_u32(&self->private_data.f_checksum, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst));
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_status)) {
|
||||
@@ -35285,38 +35789,40 @@ wuffs_zlib__decoder__transform_io(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
label__0__break:;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_transform_io[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
if ( ! self->private_impl.f_quirks[0]) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_transform_io[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
|
||||
*scratch >>= 8;
|
||||
*scratch <<= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch >> 32));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3));
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_transform_io[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
|
||||
*scratch >>= 8;
|
||||
*scratch <<= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
|
||||
if (num_bits_3 == 24) {
|
||||
t_3 = ((uint32_t)(*scratch >> 32));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3));
|
||||
}
|
||||
v_checksum_want = t_3;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
v_checksum_want = t_3;
|
||||
}
|
||||
if ( ! self->private_impl.f_ignore_checksum && (v_checksum_got != v_checksum_want)) {
|
||||
status = wuffs_base__make_status(wuffs_zlib__error__bad_checksum);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ok:
|
||||
@@ -35615,6 +36121,11 @@ wuffs_png__decoder__decode_chrm(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_exif(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_fctl(
|
||||
wuffs_png__decoder* self,
|
||||
@@ -37786,8 +38297,13 @@ wuffs_png__decoder__assign_filter_distance(
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_filter_distance = 1;
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
if (self->private_impl.f_interlace_pass == 0) {
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
} else {
|
||||
self->private_impl.f_dst_pixfmt = 2164308923;
|
||||
self->private_impl.f_src_pixfmt = 2164308923;
|
||||
}
|
||||
self->private_impl.f_filter_distance = 2;
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 2) {
|
||||
@@ -37928,20 +38444,25 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_chunk_type == 1163152464) {
|
||||
if (self->private_impl.f_seen_plte || (self->private_impl.f_color_type != 3)) {
|
||||
if (self->private_impl.f_seen_plte) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
} else if (self->private_impl.f_color_type == 3) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_png__decoder__decode_plte(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if ((self->private_impl.f_color_type == 2) || (self->private_impl.f_color_type == 6)) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_png__decoder__decode_plte(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_plte = true;
|
||||
} else if ((self->private_impl.f_chunk_type & 32) == 0) {
|
||||
@@ -37985,6 +38506,25 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
}
|
||||
self->private_impl.f_seen_chrm = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1716082789) {
|
||||
if (self->private_impl.f_report_metadata_exif) {
|
||||
if (self->private_impl.f_seen_exif) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
status = wuffs_png__decoder__decode_exif(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
self->private_impl.f_seen_exif = true;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1280598886) {
|
||||
if (self->private_impl.f_seen_fctl) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
@@ -37993,7 +38533,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
status = wuffs_png__decoder__decode_fctl(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38011,7 +38551,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_png__decoder__decode_gama(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38030,7 +38570,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_png__decoder__decode_iccp(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38049,7 +38589,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_png__decoder__decode_srgb(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38067,7 +38607,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
status = wuffs_png__decoder__decode_trns(self, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
@@ -38087,7 +38627,7 @@ wuffs_png__decoder__decode_other_chunk(
|
||||
}
|
||||
if (self->private_impl.f_metadata_fourcc == 0) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch = self->private_impl.f_chunk_length;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
if (self->private_data.s_decode_other_chunk[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_other_chunk[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
@@ -38526,6 +39066,47 @@ wuffs_png__decoder__decode_chrm(
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func png.decoder.decode_exif
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_png__decoder__decode_exif(
|
||||
wuffs_png__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_chunk_length < 4) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_flavor = 3;
|
||||
self->private_impl.f_metadata_fourcc = 1163413830;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_metadata_z = wuffs_base__u64__sat_add(self->private_impl.f_metadata_y, ((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
self->private_impl.f_chunk_length = 0;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func png.decoder.decode_fctl
|
||||
|
||||
static wuffs_base__status
|
||||
@@ -40480,6 +41061,8 @@ wuffs_png__decoder__set_report_metadata(
|
||||
|
||||
if (a_fourcc == 1128813133) {
|
||||
self->private_impl.f_report_metadata_chrm = a_report;
|
||||
} else if (a_fourcc == 1163413830) {
|
||||
self->private_impl.f_report_metadata_exif = a_report;
|
||||
} else if (a_fourcc == 1195461953) {
|
||||
self->private_impl.f_report_metadata_gama = a_report;
|
||||
} else if (a_fourcc == 1229144912) {
|
||||
@@ -40573,395 +41156,422 @@ wuffs_png__decoder__tell_me_more(
|
||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_zlib_is_dirty) {
|
||||
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
|
||||
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
if (self->private_impl.f_ignore_checksum) {
|
||||
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||
while (true) {
|
||||
if (self->private_impl.f_metadata_flavor == 3) {
|
||||
while (true) {
|
||||
if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_y) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
} else if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_y >= self->private_impl.f_metadata_z) {
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
self->private_impl.f_metadata_y = self->private_impl.f_metadata_z;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__even_more_information);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
}
|
||||
self->private_impl.f_zlib_is_dirty = true;
|
||||
self->private_impl.f_ztxt_hist_pos = 0;
|
||||
}
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_flavor != 4) {
|
||||
goto label__loop__break;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
if (self->private_impl.f_zlib_is_dirty) {
|
||||
wuffs_base__ignore_status(wuffs_zlib__decoder__initialize(&self->private_data.f_zlib,
|
||||
sizeof (wuffs_zlib__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
if (self->private_impl.f_ignore_checksum) {
|
||||
wuffs_zlib__decoder__set_quirk_enabled(&self->private_data.f_zlib, 1, true);
|
||||
}
|
||||
}
|
||||
self->private_impl.f_zlib_is_dirty = true;
|
||||
self->private_impl.f_ztxt_hist_pos = 0;
|
||||
}
|
||||
label__loop__continue:;
|
||||
while (true) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
self->private_impl.f_metadata_flavor,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
self->private_impl.f_metadata_x,
|
||||
self->private_impl.f_metadata_y,
|
||||
self->private_impl.f_metadata_z);
|
||||
}
|
||||
if (self->private_impl.f_metadata_flavor != 4) {
|
||||
goto label__loop__break;
|
||||
}
|
||||
if (self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
if (self->private_impl.f_chunk_type == 1346585449) {
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
const uint8_t *o_0_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_0;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
|
||||
{
|
||||
wuffs_base__io_buffer* o_2_v_w = v_w;
|
||||
uint8_t *o_2_iop_v_w = iop_v_w;
|
||||
uint8_t *o_2_io0_v_w = io0_v_w;
|
||||
uint8_t *o_2_io1_v_w = io1_v_w;
|
||||
uint8_t *o_2_io2_v_w = io2_v_w;
|
||||
v_w = wuffs_base__io_writer__set(
|
||||
&u_w,
|
||||
&iop_v_w,
|
||||
&io0_v_w,
|
||||
&io1_v_w,
|
||||
&io2_v_w,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
|
||||
self->private_impl.f_ztxt_hist_pos);
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
const uint8_t *o_3_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
iop_v_w = u_w.data.ptr + u_w.meta.wi;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
|
||||
io2_a_src = o_3_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_0 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_0;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
v_w = o_2_v_w;
|
||||
iop_v_w = o_2_iop_v_w;
|
||||
io0_v_w = o_2_io0_v_w;
|
||||
io1_v_w = o_2_io1_v_w;
|
||||
io2_v_w = o_2_io2_v_w;
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_0_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (v_num_written > 1024) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri = 0;
|
||||
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_1 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, a_dst, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_1;
|
||||
if (a_dst) {
|
||||
iop_a_dst = a_dst->data.ptr + a_dst->meta.wi;
|
||||
}
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
io2_a_src = o_1_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_ztxt_ri == self->private_impl.f_ztxt_wi) {
|
||||
{
|
||||
wuffs_base__io_buffer* o_2_v_w = v_w;
|
||||
uint8_t *o_2_iop_v_w = iop_v_w;
|
||||
uint8_t *o_2_io0_v_w = io0_v_w;
|
||||
uint8_t *o_2_io1_v_w = io1_v_w;
|
||||
uint8_t *o_2_io2_v_w = io2_v_w;
|
||||
v_w = wuffs_base__io_writer__set(
|
||||
&u_w,
|
||||
&iop_v_w,
|
||||
&io0_v_w,
|
||||
&io1_v_w,
|
||||
&io2_v_w,
|
||||
wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
|
||||
self->private_impl.f_ztxt_hist_pos);
|
||||
{
|
||||
const uint8_t *o_3_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
((uint64_t)(self->private_impl.f_chunk_length)));
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
v_w_mark = ((uint64_t)(iop_v_w - io0_v_w));
|
||||
v_r_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
{
|
||||
u_w.meta.wi = ((size_t)(iop_v_w - u_w.data.ptr));
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
wuffs_base__status t_2 = wuffs_zlib__decoder__transform_io(&self->private_data.f_zlib, v_w, a_src, wuffs_base__utility__empty_slice_u8());
|
||||
v_zlib_status = t_2;
|
||||
iop_v_w = u_w.data.ptr + u_w.meta.wi;
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
}
|
||||
wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295))));
|
||||
v_num_written = wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)));
|
||||
io2_a_src = o_3_io2_a_src;
|
||||
if (a_src) {
|
||||
a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr));
|
||||
}
|
||||
}
|
||||
v_w = o_2_v_w;
|
||||
iop_v_w = o_2_iop_v_w;
|
||||
io0_v_w = o_2_io0_v_w;
|
||||
io1_v_w = o_2_io1_v_w;
|
||||
io2_v_w = o_2_io2_v_w;
|
||||
}
|
||||
if (v_num_written > 1024) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri = 0;
|
||||
self->private_impl.f_ztxt_wi = ((uint32_t)(v_num_written));
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_ztxt_hist_pos, v_num_written);
|
||||
}
|
||||
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
|
||||
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
while (self->private_impl.f_ztxt_ri < self->private_impl.f_ztxt_wi) {
|
||||
v_c2 = WUFFS_PNG__LATIN_1[self->private_data.f_dst_palette[self->private_impl.f_ztxt_ri]];
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
goto label__loop__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
goto label__loop__continue;
|
||||
} else if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
} else {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
goto label__loop__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__loop__continue;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__loop__break;
|
||||
}
|
||||
v_c2 = WUFFS_PNG__LATIN_1[v_c];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_ztxt_ri += 1;
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
if (wuffs_base__status__is_ok(&v_zlib_status)) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
goto label__loop__break;
|
||||
} else if ( ! wuffs_base__status__is_suspension(&v_zlib_status)) {
|
||||
status = v_zlib_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
} else if (v_zlib_status.repr != wuffs_base__suspension__short_write) {
|
||||
status = v_zlib_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__internal_error_inconsistent_chunk_type);
|
||||
goto exit;
|
||||
}
|
||||
} else if ((self->private_impl.f_chunk_type == 1951945833) && (self->private_impl.f_metadata_fourcc == 1263947862)) {
|
||||
while (true) {
|
||||
}
|
||||
label__loop__break:;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
goto label__loop__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
goto label__loop__continue;
|
||||
} else if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
goto label__loop__continue;
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_c), iop_a_dst += 1);
|
||||
}
|
||||
} else {
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
goto label__loop__break;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__loop__continue;
|
||||
uint8_t t_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
goto label__loop__break;
|
||||
}
|
||||
v_c2 = WUFFS_PNG__LATIN_1[v_c];
|
||||
if (v_c2 == 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_text_chunk_not_latin_1);
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
} else if (v_c2 <= 127) {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(v_c2))), iop_a_dst += 1);
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_dst - iop_a_dst)) <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
v_c2 = 0;
|
||||
goto label__loop__continue;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
iop_a_src += 1;
|
||||
(wuffs_base__poke_u16le__no_bounds_check(iop_a_dst, v_c2), iop_a_dst += 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
label__loop__break:;
|
||||
if (self->private_impl.f_metadata_fourcc == 1263947851) {
|
||||
self->private_impl.f_metadata_fourcc = 1263947862;
|
||||
if (self->private_impl.f_chunk_type == 1951945833) {
|
||||
if (self->private_impl.f_chunk_length <= 1) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 2;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_3 = *iop_a_src++;
|
||||
v_c = t_3;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = false;
|
||||
} else if (v_c == 1) {
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_4 = *iop_a_src++;
|
||||
v_c = t_4;
|
||||
}
|
||||
if ((v_c != 0) && self->private_impl.f_metadata_is_zlib_compressed) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_fourcc -= 2;
|
||||
while (self->private_impl.f_metadata_fourcc != 1263947862) {
|
||||
self->private_impl.f_metadata_fourcc += 1;
|
||||
while (true) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
v_c = t_5;
|
||||
}
|
||||
if (v_c == 0) {
|
||||
goto label__0__break;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
} else if (self->private_impl.f_chunk_type == 1951945850) {
|
||||
if (self->private_impl.f_chunk_length <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_chunk_length -= 1;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_6 = *iop_a_src++;
|
||||
v_c = t_6;
|
||||
}
|
||||
if (v_c != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__unsupported_png_compression_method);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_metadata_is_zlib_compressed = true;
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
|
||||
self->private_impl.f_metadata_flavor = 0;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
label__goto_done__break:;
|
||||
if (self->private_impl.f_chunk_length != 0) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_tell_me_more[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
|
||||
if (self->private_data.s_tell_me_more[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_tell_me_more[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_tell_me_more[0].scratch;
|
||||
self->private_impl.f_metadata_flavor = 0;
|
||||
self->private_impl.f_metadata_fourcc = 0;
|
||||
self->private_impl.f_metadata_x = 0;
|
||||
self->private_impl.f_metadata_y = 0;
|
||||
self->private_impl.f_metadata_z = 0;
|
||||
self->private_impl.f_call_sequence = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
@@ -41373,6 +41983,1240 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__PNG)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
const char wuffs_tga__error__bad_header[] = "#tga: bad header";
|
||||
const char wuffs_tga__error__bad_run_length_encoding[] = "#tga: bad run length encoding";
|
||||
const char wuffs_tga__error__unsupported_tga_file[] = "#tga: unsupported TGA file";
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
// ---------------- VTables
|
||||
|
||||
const wuffs_base__image_decoder__func_ptrs
|
||||
wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder = {
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__pixel_buffer*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__pixel_blend,
|
||||
wuffs_base__slice_u8,
|
||||
wuffs_base__decode_frame_options*))(&wuffs_tga__decoder__decode_frame),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__frame_config*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_frame_config),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__image_config*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__decode_image_config),
|
||||
(wuffs_base__rect_ie_u32(*)(const void*))(&wuffs_tga__decoder__frame_dirty_rect),
|
||||
(uint32_t(*)(const void*))(&wuffs_tga__decoder__num_animation_loops),
|
||||
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frame_configs),
|
||||
(uint64_t(*)(const void*))(&wuffs_tga__decoder__num_decoded_frames),
|
||||
(wuffs_base__status(*)(void*,
|
||||
uint64_t,
|
||||
uint64_t))(&wuffs_tga__decoder__restart_frame),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_tga__decoder__set_quirk_enabled),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
uint32_t,
|
||||
bool))(&wuffs_tga__decoder__set_report_metadata),
|
||||
(wuffs_base__status(*)(void*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__more_information*,
|
||||
wuffs_base__io_buffer*))(&wuffs_tga__decoder__tell_me_more),
|
||||
(wuffs_base__range_ii_u64(*)(const void*))(&wuffs_tga__decoder__workbuf_len),
|
||||
};
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_tga__decoder__initialize(
|
||||
wuffs_tga__decoder* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options){
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (sizeof(*self) != sizeof_star_self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
|
||||
}
|
||||
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
||||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
|
||||
}
|
||||
|
||||
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
|
||||
// The whole point of this if-check is to detect an uninitialized *self.
|
||||
// We disable the warning on GCC. Clang-5.0 does not have this warning.
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
if (self->private_impl.magic != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
|
||||
}
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
} else {
|
||||
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
|
||||
} else {
|
||||
memset(&(self->private_impl), 0, sizeof(self->private_impl));
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__image_decoder.vtable_name =
|
||||
wuffs_base__image_decoder__vtable_name;
|
||||
self->private_impl.vtable_for__wuffs_base__image_decoder.function_pointers =
|
||||
(const void*)(&wuffs_tga__decoder__func_ptrs_for__wuffs_base__image_decoder);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
wuffs_tga__decoder*
|
||||
wuffs_tga__decoder__alloc() {
|
||||
wuffs_tga__decoder* x =
|
||||
(wuffs_tga__decoder*)(calloc(sizeof(wuffs_tga__decoder), 1));
|
||||
if (!x) {
|
||||
return NULL;
|
||||
}
|
||||
if (wuffs_tga__decoder__initialize(
|
||||
x, sizeof(wuffs_tga__decoder), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
|
||||
free(x);
|
||||
return NULL;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_tga__decoder() {
|
||||
return sizeof(wuffs_tga__decoder);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func tga.decoder.set_quirk_enabled
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_quirk_enabled(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_quirk,
|
||||
bool a_enabled) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_image_config
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_image_config(
|
||||
wuffs_tga__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);
|
||||
|
||||
uint32_t v_c = 0;
|
||||
uint32_t v_c5 = 0;
|
||||
uint32_t v_i = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
|
||||
if (coro_susp_point) {
|
||||
v_i = self->private_data.s_decode_image_config[0].v_i;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
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_header_id_length = t_0;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_1 = *iop_a_src++;
|
||||
self->private_impl.f_header_color_map_type = t_1;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type > 1) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_2 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_type = t_2;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type == 1) ||
|
||||
(self->private_impl.f_header_image_type == 2) ||
|
||||
(self->private_impl.f_header_image_type == 3) ||
|
||||
(self->private_impl.f_header_image_type == 9) ||
|
||||
(self->private_impl.f_header_image_type == 10) ||
|
||||
(self->private_impl.f_header_image_type == 11)) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
uint16_t t_3;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_3 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3;
|
||||
if (num_bits_3 == 8) {
|
||||
t_3 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_3 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_3)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_color_map_first_entry_index = t_3;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint16_t t_4;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_4 = wuffs_base__peek_u16le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
|
||||
if (num_bits_4 == 8) {
|
||||
t_4 = ((uint16_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_4 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_4)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_header_color_map_length = t_4;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_5 = *iop_a_src++;
|
||||
self->private_impl.f_header_color_map_entry_size = t_5;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length > 256)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
} else if ((self->private_impl.f_header_color_map_entry_size != 15) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 16) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 24) &&
|
||||
(self->private_impl.f_header_color_map_entry_size != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if ((self->private_impl.f_header_color_map_first_entry_index != 0) || (self->private_impl.f_header_color_map_length != 0) || (self->private_impl.f_header_color_map_entry_size != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = 4;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
|
||||
uint32_t t_6;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_6 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_6 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_6;
|
||||
if (num_bits_6 == 8) {
|
||||
t_6 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_6 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_6)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_width = t_6;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(12);
|
||||
uint32_t t_7;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_7 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(13);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_7 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_7;
|
||||
if (num_bits_7 == 8) {
|
||||
t_7 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_7 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_7)) << 56;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_height = t_7;
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_8 = *iop_a_src++;
|
||||
self->private_impl.f_header_pixel_depth = t_8;
|
||||
}
|
||||
if ((self->private_impl.f_header_pixel_depth != 1) &&
|
||||
(self->private_impl.f_header_pixel_depth != 8) &&
|
||||
(self->private_impl.f_header_pixel_depth != 15) &&
|
||||
(self->private_impl.f_header_pixel_depth != 16) &&
|
||||
(self->private_impl.f_header_pixel_depth != 24) &&
|
||||
(self->private_impl.f_header_pixel_depth != 32)) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_header);
|
||||
goto exit;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type | 8) == 9) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_pixfmt = 2164523016;
|
||||
self->private_impl.f_opaque = ((self->private_impl.f_header_color_map_entry_size == 15) || (self->private_impl.f_header_color_map_entry_size == 24));
|
||||
} else if ((self->private_impl.f_header_image_type | 8) == 10) {
|
||||
if ((self->private_impl.f_header_pixel_depth == 15) || (self->private_impl.f_header_pixel_depth == 16)) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_bytes_per_pixel = 0;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
} else if (self->private_impl.f_header_pixel_depth == 24) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 3;
|
||||
self->private_impl.f_src_bytes_per_pixel = 3;
|
||||
self->private_impl.f_src_pixfmt = 2147485832;
|
||||
self->private_impl.f_opaque = true;
|
||||
} else if (self->private_impl.f_header_pixel_depth == 32) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_bytes_per_pixel = 4;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_header_pixel_depth == 8) {
|
||||
self->private_impl.f_scratch_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_bytes_per_pixel = 1;
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_opaque = true;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint8_t t_9 = *iop_a_src++;
|
||||
self->private_impl.f_header_image_descriptor = t_9;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_descriptor & 16) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__unsupported_tga_file);
|
||||
goto exit;
|
||||
}
|
||||
self->private_data.s_decode_image_config[0].scratch = ((uint32_t)(self->private_impl.f_header_id_length));
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
|
||||
if (self->private_data.s_decode_image_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_image_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_image_config[0].scratch;
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
while (v_i < ((uint32_t)(self->private_impl.f_header_color_map_length))) {
|
||||
if (self->private_impl.f_header_color_map_entry_size == 24) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(17);
|
||||
uint32_t t_10;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 3)) {
|
||||
t_10 = ((uint32_t)(wuffs_base__peek_u24le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 3;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(18);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_10 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_10;
|
||||
if (num_bits_10 == 16) {
|
||||
t_10 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_10 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_10)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_10;
|
||||
}
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c >> 0) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c >> 8) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c >> 16) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = 255;
|
||||
} else if (self->private_impl.f_header_color_map_entry_size == 32) {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(19);
|
||||
uint32_t t_11;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) {
|
||||
t_11 = wuffs_base__peek_u32le__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 4;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(20);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_11 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_11;
|
||||
if (num_bits_11 == 24) {
|
||||
t_11 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_11 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_11)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_11;
|
||||
}
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c >> 0) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c >> 8) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c >> 16) & 255)));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = ((uint8_t)(((v_c >> 24) & 255)));
|
||||
} else {
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(21);
|
||||
uint32_t t_12;
|
||||
if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 2)) {
|
||||
t_12 = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
} else {
|
||||
self->private_data.s_decode_image_config[0].scratch = 0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(22);
|
||||
while (true) {
|
||||
if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
uint64_t* scratch = &self->private_data.s_decode_image_config[0].scratch;
|
||||
uint32_t num_bits_12 = ((uint32_t)(*scratch >> 56));
|
||||
*scratch <<= 8;
|
||||
*scratch >>= 8;
|
||||
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_12;
|
||||
if (num_bits_12 == 8) {
|
||||
t_12 = ((uint32_t)(*scratch));
|
||||
break;
|
||||
}
|
||||
num_bits_12 += 8;
|
||||
*scratch |= ((uint64_t)(num_bits_12)) << 56;
|
||||
}
|
||||
}
|
||||
v_c = t_12;
|
||||
}
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 0)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 1)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 2)] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_src_palette[(((v_i & 255) * 4) + 3)] = 255;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_src_palette[((v_i * 4) + 0)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 1)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 2)] = 0;
|
||||
self->private_data.f_src_palette[((v_i * 4) + 3)] = 255;
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
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(
|
||||
a_dst,
|
||||
self->private_impl.f_src_pixfmt,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
self->private_impl.f_opaque);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_image_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 1 : 0;
|
||||
self->private_data.s_decode_image_config[0].v_i = v_i;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_frame_config
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame_config(
|
||||
wuffs_tga__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);
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_tga__decoder__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 == 3) {
|
||||
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 == 4) {
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__frame_config__set(
|
||||
a_dst,
|
||||
wuffs_base__utility__make_rect_ie_u32(
|
||||
0,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height),
|
||||
((wuffs_base__flicks)(0)),
|
||||
0,
|
||||
self->private_impl.f_frame_config_io_position,
|
||||
0,
|
||||
self->private_impl.f_opaque,
|
||||
false,
|
||||
4278190080);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame_config[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 2 : 0;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.decode_frame
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__decode_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__pixel_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src,
|
||||
wuffs_base__pixel_blend a_blend,
|
||||
wuffs_base__slice_u8 a_workbuf,
|
||||
wuffs_base__decode_frame_options* a_opts) {
|
||||
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);
|
||||
wuffs_base__pixel_format v_dst_pixfmt = {0};
|
||||
uint32_t v_dst_bits_per_pixel = 0;
|
||||
uint64_t v_dst_bytes_per_pixel = 0;
|
||||
uint32_t v_dst_x = 0;
|
||||
uint32_t v_dst_y = 0;
|
||||
wuffs_base__table_u8 v_tab = {0};
|
||||
wuffs_base__slice_u8 v_dst_palette = {0};
|
||||
wuffs_base__slice_u8 v_dst = {0};
|
||||
uint64_t v_dst_start = 0;
|
||||
wuffs_base__slice_u8 v_src_palette = {0};
|
||||
uint64_t v_mark = 0;
|
||||
uint64_t v_num_pixels64 = 0;
|
||||
uint32_t v_num_pixels32 = 0;
|
||||
uint32_t v_lit_length = 0;
|
||||
uint32_t v_run_length = 0;
|
||||
uint64_t v_num_dst_bytes = 0;
|
||||
uint32_t v_num_src_bytes = 0;
|
||||
uint32_t v_c = 0;
|
||||
uint32_t v_c5 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
|
||||
if (coro_susp_point) {
|
||||
v_dst_bytes_per_pixel = self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel;
|
||||
v_dst_x = self->private_data.s_decode_frame[0].v_dst_x;
|
||||
v_dst_y = self->private_data.s_decode_frame[0].v_dst_y;
|
||||
v_mark = self->private_data.s_decode_frame[0].v_mark;
|
||||
v_num_pixels32 = self->private_data.s_decode_frame[0].v_num_pixels32;
|
||||
v_lit_length = self->private_data.s_decode_frame[0].v_lit_length;
|
||||
v_run_length = self->private_data.s_decode_frame[0].v_run_length;
|
||||
v_num_dst_bytes = self->private_data.s_decode_frame[0].v_num_dst_bytes;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if (self->private_impl.f_call_sequence < 4) {
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_tga__decoder__decode_frame_config(self, NULL, a_src);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 4) {
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_base__note__end_of_data);
|
||||
goto ok;
|
||||
}
|
||||
if (self->private_impl.f_header_color_map_type != 0) {
|
||||
v_src_palette = wuffs_base__make_slice_u8(self->private_data.f_src_palette, 1024);
|
||||
}
|
||||
v_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
|
||||
wuffs_base__pixel_buffer__pixel_format(a_dst),
|
||||
wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024)),
|
||||
wuffs_base__utility__make_pixel_format(self->private_impl.f_src_pixfmt),
|
||||
v_src_palette,
|
||||
a_blend);
|
||||
if ( ! wuffs_base__status__is_ok(&v_status)) {
|
||||
status = v_status;
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
goto exit;
|
||||
} else if (wuffs_base__status__is_suspension(&status)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);
|
||||
goto exit;
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
v_dst_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_dst);
|
||||
v_dst_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_dst_pixfmt);
|
||||
if ((v_dst_bits_per_pixel & 7) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
goto exit;
|
||||
}
|
||||
v_dst_bytes_per_pixel = ((uint64_t)((v_dst_bits_per_pixel / 8)));
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y = ((uint32_t)(self->private_impl.f_height - 1));
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type & 8) == 0) {
|
||||
v_lit_length = self->private_impl.f_width;
|
||||
}
|
||||
label__resume__continue:;
|
||||
while (true) {
|
||||
v_tab = wuffs_base__pixel_buffer__plane(a_dst, 0);
|
||||
v_dst_palette = wuffs_base__pixel_buffer__palette_or_else(a_dst, wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024));
|
||||
while (v_dst_y < self->private_impl.f_height) {
|
||||
v_dst = wuffs_base__table_u8__row_u32(v_tab, v_dst_y);
|
||||
v_dst_start = (((uint64_t)(v_dst_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_dst_start <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_start);
|
||||
} else {
|
||||
v_dst = wuffs_base__utility__empty_slice_u8();
|
||||
}
|
||||
while (v_dst_x < self->private_impl.f_width) {
|
||||
if (self->private_impl.f_src_bytes_per_pixel > 0) {
|
||||
if (v_lit_length > 0) {
|
||||
v_mark = ((uint64_t)(iop_a_src - io0_a_src));
|
||||
v_num_pixels64 = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(self->private_impl.f_src_bytes_per_pixel)));
|
||||
v_num_pixels32 = ((uint32_t)(wuffs_base__u64__min(v_num_pixels64, ((uint64_t)(v_lit_length)))));
|
||||
v_num_dst_bytes = (((uint64_t)(v_num_pixels32)) * v_dst_bytes_per_pixel);
|
||||
v_num_src_bytes = (v_num_pixels32 * self->private_impl.f_src_bytes_per_pixel);
|
||||
self->private_data.s_decode_frame[0].scratch = v_num_src_bytes;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) {
|
||||
self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src));
|
||||
iop_a_src = io2_a_src;
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
goto suspend;
|
||||
}
|
||||
iop_a_src += self->private_data.s_decode_frame[0].scratch;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src));
|
||||
if (v_num_dst_bytes <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_num_dst_bytes);
|
||||
} else {
|
||||
v_dst = wuffs_base__utility__empty_slice_u8();
|
||||
}
|
||||
v_dst_x += v_num_pixels32;
|
||||
v_lit_length = (((uint32_t)(v_lit_length - v_num_pixels32)) & 65535);
|
||||
if (v_lit_length > 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
} else if (v_run_length > 0) {
|
||||
v_run_length -= 1;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 4), self->private_impl.f_scratch_bytes_per_pixel));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128) {
|
||||
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1);
|
||||
iop_a_src += 1;
|
||||
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (self->private_impl.f_src_bytes_per_pixel == 1) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
} else if (self->private_impl.f_src_bytes_per_pixel == 3) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 4) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[1] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[2] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 5) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[0] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[1] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[2] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
self->private_data.f_scratch[3] = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
iop_a_src += 1;
|
||||
}
|
||||
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (v_lit_length > 0) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 2) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_c = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_scratch[0] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_scratch[1] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_scratch[2] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_scratch[3] = 255;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__make_slice_u8(self->private_data.f_scratch, 4));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
v_lit_length -= 1;
|
||||
} else if (v_run_length > 0) {
|
||||
v_run_length -= 1;
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, v_dst, v_dst_palette, wuffs_base__slice_u8__subslice_j(wuffs_base__make_slice_u8(self->private_data.f_scratch, 4), self->private_impl.f_scratch_bytes_per_pixel));
|
||||
if (v_dst_bytes_per_pixel <= ((uint64_t)(v_dst.len))) {
|
||||
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_dst_bytes_per_pixel);
|
||||
}
|
||||
v_dst_x += 1;
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
if (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) < 128) {
|
||||
v_lit_length = (((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) + 1);
|
||||
iop_a_src += 1;
|
||||
if ((v_lit_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) < 3) {
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
goto label__resume__continue;
|
||||
}
|
||||
v_run_length = ((((uint32_t)(wuffs_base__peek_u8be__no_bounds_check(iop_a_src))) & 127) + 1);
|
||||
iop_a_src += 1;
|
||||
v_c = ((uint32_t)(wuffs_base__peek_u16le__no_bounds_check(iop_a_src)));
|
||||
iop_a_src += 2;
|
||||
v_c5 = (31 & (v_c >> 0));
|
||||
self->private_data.f_scratch[0] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 5));
|
||||
self->private_data.f_scratch[1] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
v_c5 = (31 & (v_c >> 10));
|
||||
self->private_data.f_scratch[2] = ((uint8_t)(((v_c5 << 3) | (v_c5 >> 2))));
|
||||
self->private_data.f_scratch[3] = 255;
|
||||
if ((v_run_length + v_dst_x) > self->private_impl.f_width) {
|
||||
status = wuffs_base__make_status(wuffs_tga__error__bad_run_length_encoding);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
v_dst_x = 0;
|
||||
if ((self->private_impl.f_header_image_descriptor & 32) == 0) {
|
||||
v_dst_y -= 1;
|
||||
} else {
|
||||
v_dst_y += 1;
|
||||
}
|
||||
if ((self->private_impl.f_header_image_type & 8) == 0) {
|
||||
v_lit_length = self->private_impl.f_width;
|
||||
}
|
||||
}
|
||||
goto label__resume__break;
|
||||
}
|
||||
label__resume__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
suspend:
|
||||
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
|
||||
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
|
||||
self->private_data.s_decode_frame[0].v_dst_bytes_per_pixel = v_dst_bytes_per_pixel;
|
||||
self->private_data.s_decode_frame[0].v_dst_x = v_dst_x;
|
||||
self->private_data.s_decode_frame[0].v_dst_y = v_dst_y;
|
||||
self->private_data.s_decode_frame[0].v_mark = v_mark;
|
||||
self->private_data.s_decode_frame[0].v_num_pixels32 = v_num_pixels32;
|
||||
self->private_data.s_decode_frame[0].v_lit_length = v_lit_length;
|
||||
self->private_data.s_decode_frame[0].v_run_length = v_run_length;
|
||||
self->private_data.s_decode_frame[0].v_num_dst_bytes = v_num_dst_bytes;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.frame_dirty_rect
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32
|
||||
wuffs_tga__decoder__frame_dirty_rect(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_rect_ie_u32();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_rect_ie_u32(
|
||||
0,
|
||||
0,
|
||||
self->private_impl.f_width,
|
||||
self->private_impl.f_height);
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_animation_loops
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint32_t
|
||||
wuffs_tga__decoder__num_animation_loops(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_decoded_frame_configs
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frame_configs(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 3) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.num_decoded_frames
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_tga__decoder__num_decoded_frames(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence > 4) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.restart_frame
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__restart_frame(
|
||||
wuffs_tga__decoder* self,
|
||||
uint64_t a_index,
|
||||
uint64_t a_io_position) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
if (self->private_impl.f_call_sequence < 3) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
if (a_index != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
self->private_impl.f_frame_config_io_position = a_io_position;
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.set_report_metadata
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_tga__decoder__set_report_metadata(
|
||||
wuffs_tga__decoder* self,
|
||||
uint32_t a_fourcc,
|
||||
bool a_report) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.tell_me_more
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_tga__decoder__tell_me_more(
|
||||
wuffs_tga__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__more_information* a_minfo,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
if (!a_dst || !a_src) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_argument);
|
||||
}
|
||||
if ((self->private_impl.active_coroutine != 0) &&
|
||||
(self->private_impl.active_coroutine != 4)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);
|
||||
}
|
||||
self->private_impl.active_coroutine = 0;
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
status = wuffs_base__make_status(wuffs_base__error__no_more_information);
|
||||
goto exit;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (wuffs_base__status__is_error(&status)) {
|
||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func tga.decoder.workbuf_len
|
||||
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64
|
||||
wuffs_tga__decoder__workbuf_len(
|
||||
const wuffs_tga__decoder* self) {
|
||||
if (!self) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return wuffs_base__utility__empty_range_ii_u64();
|
||||
}
|
||||
|
||||
return wuffs_base__utility__make_range_ii_u64(0, 0);
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
@@ -42819,7 +44663,8 @@ DecodeImageCallbacks::AllocWorkbufResult::AllocWorkbufResult(
|
||||
|
||||
wuffs_base__image_decoder::unique_ptr //
|
||||
DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
wuffs_base__slice_u8 prefix) {
|
||||
wuffs_base__slice_u8 prefix_data,
|
||||
bool prefix_closed) {
|
||||
switch (fourcc) {
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BMP)
|
||||
case WUFFS_BASE__FOURCC__BMP:
|
||||
@@ -42845,6 +44690,11 @@ DecodeImageCallbacks::SelectDecoder(uint32_t fourcc,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__TGA)
|
||||
case WUFFS_BASE__FOURCC__TGA:
|
||||
return wuffs_tga__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
#endif
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__WBMP)
|
||||
case WUFFS_BASE__FOURCC__WBMP:
|
||||
return wuffs_wbmp__decoder::alloc_as__wuffs_base__image_decoder();
|
||||
@@ -43072,10 +44922,17 @@ redirect:
|
||||
// Determine the image format.
|
||||
if (!redirected) {
|
||||
while (true) {
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice());
|
||||
fourcc = wuffs_base__magic_number_guess_fourcc(io_buf.reader_slice(),
|
||||
io_buf.meta.closed);
|
||||
if (fourcc > 0) {
|
||||
break;
|
||||
} else if ((fourcc == 0) && (io_buf.reader_length() >= 64)) {
|
||||
// Having (fourcc == 0) means that Wuffs' built in MIME sniffer
|
||||
// didn't recognize the image format. Nonetheless, custom callbacks
|
||||
// may still be able to do their own MIME sniffing, for exotic image
|
||||
// types. We try to give them at least 64 bytes of prefix data when
|
||||
// one-shot-calling callbacks.SelectDecoder. There is no mechanism
|
||||
// for the callbacks to request a longer prefix.
|
||||
break;
|
||||
} else if (io_buf.meta.closed || (io_buf.writer_length() == 0)) {
|
||||
fourcc = 0;
|
||||
@@ -43116,8 +44973,7 @@ redirect:
|
||||
|
||||
// Select the image decoder.
|
||||
image_decoder = callbacks.SelectDecoder(
|
||||
(uint32_t)fourcc,
|
||||
fourcc ? wuffs_base__empty_slice_u8() : io_buf.reader_slice());
|
||||
(uint32_t)fourcc, io_buf.reader_slice(), io_buf.meta.closed);
|
||||
if (!image_decoder) {
|
||||
return DecodeImageResult(DecodeImage_UnsupportedImageFormat);
|
||||
}
|
||||
@@ -43132,6 +44988,9 @@ redirect:
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
|
||||
}
|
||||
if (flags & DecodeImageArgFlags::REPORT_METADATA_GAMA) {
|
||||
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__GAMA, true);
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ main(int argc, char** argv) {
|
||||
"compatible with the\n"
|
||||
"# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install "
|
||||
"it, first\n"
|
||||
"# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
|
||||
"# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
msg = decode(true, true);
|
||||
|
||||
@@ -81,7 +81,7 @@ func main1() error {
|
||||
fmt.Printf("#\n")
|
||||
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
|
||||
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
|
||||
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
|
||||
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
|
||||
|
||||
for i := -1; i < reps; i++ {
|
||||
for _, tc := range testCases {
|
||||
|
||||
@@ -106,7 +106,7 @@ func main1() error {
|
||||
fmt.Printf("#\n")
|
||||
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
|
||||
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
|
||||
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
|
||||
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
|
||||
|
||||
for i := -1; i < reps; i++ {
|
||||
for _, tc := range testCases {
|
||||
|
||||
@@ -90,7 +90,7 @@ func main1() error {
|
||||
fmt.Printf("#\n")
|
||||
fmt.Printf("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n")
|
||||
fmt.Printf("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n")
|
||||
fmt.Printf("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n")
|
||||
fmt.Printf("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n")
|
||||
|
||||
for i := -1; i < reps; i++ {
|
||||
for _, tc := range testCases {
|
||||
|
||||
+12
-2
@@ -32,9 +32,19 @@ save=`git log -1 --pretty=format:"%H"`
|
||||
|
||||
i=0
|
||||
while [ $i -lt $num_commits ]; do
|
||||
this_hash=`git log -1 --pretty=format:"%h"`
|
||||
set +e
|
||||
$cc -O3 -o bench-history.out test/c/std/$package.c
|
||||
this_metric=`./bench-history.out -bench -focus=$focus -iterscale=$iterscale -reps=$reps | benchstat /dev/stdin | sed -ne '/^name.*speed$/,$ p' | grep $focus`
|
||||
if [ $? -ne 0 ]; then
|
||||
this_metric='compile_failed'
|
||||
else
|
||||
this_metric=`./bench-history.out -bench -focus=$focus -iterscale=$iterscale -reps=$reps | benchstat /dev/stdin | sed -ne '/^name.*speed$/,$ p' | grep $focus`
|
||||
if [ $? -ne 0 ]; then
|
||||
this_metric='bench_failed'
|
||||
fi
|
||||
fi
|
||||
set -e
|
||||
|
||||
this_hash=`git log -1 --pretty=format:"%h"`
|
||||
echo $this_hash $this_metric
|
||||
git checkout --quiet HEAD^
|
||||
i=$((i + 1))
|
||||
|
||||
@@ -47,7 +47,7 @@ fn main() {
|
||||
print!("#\n");
|
||||
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
|
||||
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
|
||||
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
|
||||
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
|
||||
let mut dst = vec![0u8; 64 * 1024 * 1024];
|
||||
|
||||
|
||||
@@ -4,5 +4,5 @@ version = "0.0.1"
|
||||
authors = ["Nigel Tao <nigeltao@golang.org>"]
|
||||
|
||||
[dependencies]
|
||||
gif = "*"
|
||||
gif = "0.11"
|
||||
rustc_version_runtime = "*"
|
||||
@@ -35,7 +35,6 @@
|
||||
extern crate gif;
|
||||
extern crate rustc_version_runtime;
|
||||
|
||||
use gif::SetParameter;
|
||||
use std::time::Instant;
|
||||
|
||||
const ITERSCALE: u64 = 10;
|
||||
@@ -52,7 +51,7 @@ fn main() {
|
||||
print!("#\n");
|
||||
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
|
||||
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
|
||||
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
|
||||
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
|
||||
let mut dst = vec![0u8; 64 * 1024 * 1024];
|
||||
|
||||
@@ -183,15 +182,14 @@ fn bench(
|
||||
// decode returns the number of bytes processed.
|
||||
fn decode(dst: &mut [u8], src: &[u8], output_32_bit_color: bool) -> u64 {
|
||||
let mut num_bytes = 0u64;
|
||||
let mut decoder = gif::Decoder::new(src);
|
||||
let mut options = gif::DecodeOptions::new();
|
||||
if output_32_bit_color {
|
||||
decoder.set(gif::ColorOutput::RGBA);
|
||||
options.set_color_output(gif::ColorOutput::RGBA);
|
||||
}
|
||||
|
||||
let mut reader = decoder.read_info().unwrap();
|
||||
while let Some(_) = reader.next_frame_info().unwrap() {
|
||||
num_bytes += reader.buffer_size() as u64;
|
||||
reader.read_into_buffer(dst).unwrap();
|
||||
let mut decoder = options.read_info(src).unwrap();
|
||||
while let Some(_) = decoder.next_frame_info().unwrap() {
|
||||
num_bytes += decoder.buffer_size() as u64;
|
||||
decoder.read_into_buffer(dst).unwrap();
|
||||
}
|
||||
num_bytes
|
||||
}
|
||||
@@ -4,5 +4,5 @@ version = "0.0.1"
|
||||
authors = ["Nigel Tao <nigeltao@golang.org>"]
|
||||
|
||||
[dependencies]
|
||||
png = "*"
|
||||
png = "0.17"
|
||||
rustc_version_runtime = "*"
|
||||
@@ -45,7 +45,7 @@ fn main() {
|
||||
print!("#\n");
|
||||
print!("# The output format, including the \"Benchmark\" prefixes, is compatible with the\n");
|
||||
print!("# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install it, first\n");
|
||||
print!("# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
|
||||
print!("# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
|
||||
let mut dst0 = vec![0u8; 64 * 1024 * 1024];
|
||||
let mut dst1 = vec![0u8; 64 * 1024 * 1024];
|
||||
@@ -145,19 +145,20 @@ fn bench(
|
||||
|
||||
// decode returns the number of bytes processed.
|
||||
fn decode(dst0: &mut [u8], dst1: &mut [u8], src: &[u8]) -> u64 {
|
||||
let decoder = png::Decoder::new(src);
|
||||
let (info, mut reader) = decoder.read_info().unwrap();
|
||||
let mut decoder = png::Decoder::new(src);
|
||||
decoder.set_transformations(png::Transformations::normalize_to_color8());
|
||||
let mut reader = decoder.read_info().unwrap();
|
||||
let info = reader.next_frame(dst0).unwrap();
|
||||
let num_bytes = info.buffer_size() as u64;
|
||||
reader.next_frame(dst0).unwrap();
|
||||
if info.color_type == png::ColorType::Grayscale {
|
||||
// No conversion necessary.
|
||||
return num_bytes;
|
||||
} else if info.color_type == png::ColorType::RGB {
|
||||
} else if info.color_type == png::ColorType::Rgb {
|
||||
// Convert RGB => BGRA.
|
||||
let new_size = ((num_bytes / 3) * 4) as usize;
|
||||
rgb_to_bgra(&dst0[..num_bytes as usize], &mut dst1[..new_size]);
|
||||
return new_size as u64;
|
||||
} else if info.color_type == png::ColorType::RGBA {
|
||||
} else if info.color_type == png::ColorType::Rgba {
|
||||
// Convert RGBA => BGRA.
|
||||
for i in 0..((num_bytes / 4) as usize) {
|
||||
let d = dst0[(4 * i) + 0];
|
||||
|
||||
+95
-13
@@ -31,6 +31,7 @@ import (
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -244,20 +245,28 @@ var deflateCodeOrder = [19]uint32{
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
|
||||
}
|
||||
|
||||
var deflateHuffmanNames = [4]string{
|
||||
0: "Unused",
|
||||
1: "CodeLength",
|
||||
2: "Literal/Length",
|
||||
3: "Distance",
|
||||
}
|
||||
|
||||
type deflateHuffmanTable map[uint32]string
|
||||
|
||||
var deflateGlobals struct {
|
||||
bncData []byte
|
||||
stream deflateBitStream
|
||||
|
||||
// Dynamic Huffman state.
|
||||
// Dynamic Huffman state. whichHuffman indexes the huffmans array. See also
|
||||
// deflateHuffmanNames.
|
||||
whichHuffman uint32
|
||||
// 0=Unused, 1=CodeLength, 2=Literal/Length, 3=Distance.
|
||||
huffmans [4]deflateHuffmanTable
|
||||
huffmans [4]deflateHuffmanTable
|
||||
|
||||
// DHH (Dynamic Huffman, inside a Huffman table) state.
|
||||
prevLine string
|
||||
etcetera bool
|
||||
prevLine string
|
||||
etcetera bool
|
||||
incomplete bool
|
||||
}
|
||||
|
||||
func deflateGlobalsClearDynamicHuffmanState() {
|
||||
@@ -265,6 +274,7 @@ func deflateGlobalsClearDynamicHuffmanState() {
|
||||
deflateGlobals.huffmans = [4]deflateHuffmanTable{}
|
||||
deflateGlobals.prevLine = ""
|
||||
deflateGlobals.etcetera = false
|
||||
deflateGlobals.incomplete = false
|
||||
}
|
||||
|
||||
func deflateGlobalsCountCodes() (numLCodes uint32, numDCodes uint32, numCLCodeLengths uint32, retErr error) {
|
||||
@@ -299,6 +309,70 @@ func deflateGlobalsCountCodes() (numLCodes uint32, numDCodes uint32, numCLCodeLe
|
||||
return numLCodes, numDCodes, numCLCodeLengths, nil
|
||||
}
|
||||
|
||||
func deflateGlobalsIsHuffmanCanonical() bool {
|
||||
g := &deflateGlobals
|
||||
|
||||
// Gather the code+bitstring pairs. Deflate bitstrings cannot be longer
|
||||
// than 15 bits.
|
||||
type pair struct {
|
||||
k uint32
|
||||
v string
|
||||
}
|
||||
pairs := []pair{}
|
||||
for k, v := range g.huffmans[g.whichHuffman] {
|
||||
if len(v) > 15 {
|
||||
return false
|
||||
}
|
||||
pairs = append(pairs, pair{k, v})
|
||||
}
|
||||
if len(pairs) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Sort by bitstring-length and then code.
|
||||
sort.Slice(pairs, func(i, j int) bool {
|
||||
pi, pj := &pairs[i], &pairs[j]
|
||||
if len(pi.v) != len(pj.v) {
|
||||
return len(pi.v) < len(pj.v)
|
||||
}
|
||||
return pi.k < pj.k
|
||||
})
|
||||
|
||||
// Set up a generator for the canonical bitstrings.
|
||||
buf := [15]byte{'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'}
|
||||
prevV := ""
|
||||
next := func() bool {
|
||||
if i := len(prevV); i > 0 {
|
||||
for {
|
||||
i--
|
||||
if i < 0 {
|
||||
return false
|
||||
}
|
||||
if buf[i] == '0' {
|
||||
buf[i] = '1'
|
||||
break
|
||||
}
|
||||
buf[i] = '0'
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Verify the bitstrings.
|
||||
for _, p := range pairs {
|
||||
if !next() {
|
||||
return false // Over-subscribed.
|
||||
} else if p.v != string(buf[:len(p.v)]) {
|
||||
return false // Non-canonical.
|
||||
}
|
||||
prevV = p.v
|
||||
}
|
||||
if next() != g.incomplete {
|
||||
return false // Under-subscribed.
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func deflateGlobalsWriteDynamicHuffmanTables() error {
|
||||
g := &deflateGlobals
|
||||
numLCodes, numDCodes, numCLCodeLengths, err := deflateGlobalsCountCodes()
|
||||
@@ -587,20 +661,20 @@ func stateDeflateDynamicHuffman(line string) (stateFunc, error) {
|
||||
return stateDeflateDynamicHuffman, nil
|
||||
|
||||
} else if l, d, ok := deflateParseLenDist(line); ok {
|
||||
if (l != 3) || (d != 2) {
|
||||
return nil, fmt.Errorf("TODO: support len/dist pairs for dynamic Huffman blocks")
|
||||
if (l > 10) || (d > 4) {
|
||||
return nil, fmt.Errorf("TODO: support len/dist ExtraBits > 0 for dynamic Huffman blocks")
|
||||
}
|
||||
// len 3 is code 257, with no extra bits.
|
||||
if s := g.huffmans[2][257]; s != "" {
|
||||
// len 3 is code 257, len 4 is code 258, etc. All with no ExtraBits.
|
||||
if s := g.huffmans[2][l+254]; s != "" {
|
||||
deflateGlobalsWriteDynamicHuffmanBits(s)
|
||||
} else {
|
||||
return nil, fmt.Errorf("no code for literal/length symbol 257")
|
||||
return nil, fmt.Errorf("no code for literal/length symbol %d", l+254)
|
||||
}
|
||||
// dist 2 is code 1, with no extra bits.
|
||||
if s := g.huffmans[3][1]; s != "" {
|
||||
// dist 1 is code 0, dist 2 is code 1, etc. All with no ExtraBits.
|
||||
if s := g.huffmans[3][d-1]; s != "" {
|
||||
deflateGlobalsWriteDynamicHuffmanBits(s)
|
||||
} else {
|
||||
return nil, fmt.Errorf("no code for distance symbol 2")
|
||||
return nil, fmt.Errorf("no code for distance symbol %d", d-1)
|
||||
}
|
||||
return stateDeflateDynamicHuffman, nil
|
||||
|
||||
@@ -621,9 +695,13 @@ func stateDeflateDynamicHuffmanHuffman(line string) (stateFunc, error) {
|
||||
outer:
|
||||
switch {
|
||||
case line == "}":
|
||||
if !deflateGlobalsIsHuffmanCanonical() {
|
||||
return nil, fmt.Errorf(`"huffman %s" is non-canonical`, deflateHuffmanNames[g.whichHuffman])
|
||||
}
|
||||
g.whichHuffman = 0
|
||||
g.prevLine = ""
|
||||
g.etcetera = false
|
||||
g.incomplete = false
|
||||
|
||||
// If we have all three Huffman tables, write them.
|
||||
for i := 1; ; i++ {
|
||||
@@ -644,6 +722,10 @@ outer:
|
||||
g.etcetera = true
|
||||
return stateDeflateDynamicHuffmanHuffman, nil
|
||||
|
||||
case line == "incomplete":
|
||||
g.incomplete = true
|
||||
return stateDeflateDynamicHuffmanHuffman, nil
|
||||
|
||||
default:
|
||||
s := line
|
||||
n, s, ok := parseNum(s)
|
||||
|
||||
@@ -64,7 +64,7 @@ for f in $sources; do
|
||||
if [ -f $f ]; then
|
||||
handle $f
|
||||
elif [ -d $f ]; then
|
||||
for g in `find $f -type f | sort`; do
|
||||
for g in `find $f -type f | LANG=C sort`; do
|
||||
handle $g
|
||||
done
|
||||
else
|
||||
|
||||
@@ -628,17 +628,21 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
} endwhile
|
||||
if remaining <> 0 {
|
||||
// As a special case, allow a degenerate H-D Huffman table, with only
|
||||
// one 1-bit code, for the smallest possible distance.
|
||||
// one 1-bit code.
|
||||
if (args.which == 1) and (counts[1] == 1) and
|
||||
(this.code_lengths[args.n_codes0] == 1) and
|
||||
(((counts[0] as base.u32) + args.n_codes0 + 1) == args.n_codes1) {
|
||||
|
||||
this.n_huffs_bits[1] = 1
|
||||
this.huffs[1][0] = DCODE_MAGIC_NUMBERS[0] | 1
|
||||
this.huffs[1][1] = DCODE_MAGIC_NUMBERS[31] | 1
|
||||
return ok
|
||||
i = 0
|
||||
while i <= 29 {
|
||||
if this.code_lengths[args.n_codes0 + i] == 1 {
|
||||
this.n_huffs_bits[1] = 1
|
||||
this.huffs[1][0] = DCODE_MAGIC_NUMBERS[i] | 1
|
||||
this.huffs[1][1] = DCODE_MAGIC_NUMBERS[31] | 1
|
||||
return ok
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
|
||||
|
||||
@@ -219,18 +219,14 @@ pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader)
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
//
|
||||
// This copying is simpler than the decode_huffman_slow version
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
|
||||
@@ -324,18 +324,14 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
//
|
||||
// This copying is simpler than the decode_huffman_slow version
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
|
||||
@@ -218,18 +218,14 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
//
|
||||
// This copying is simpler than the decode_huffman_slow version
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
|
||||
@@ -201,63 +201,38 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
n_bits -= table_entry_n_bits
|
||||
}
|
||||
|
||||
while true {
|
||||
while.inner true {
|
||||
// Copy from this.history.
|
||||
if ((dist_minus_1 + 1) as base.u64) > args.dst.history_length() {
|
||||
// Set (hlen, hdist) to be the length-distance pair to copy
|
||||
// from this.history, and (length, distance) to be the
|
||||
// remaining length-distance pair to copy from args.dst.
|
||||
// from this.history.
|
||||
hdist = (((dist_minus_1 + 1) as base.u64) - args.dst.history_length()) as base.u32
|
||||
if length > hdist {
|
||||
assert hdist < length via "a < b: b > a"()
|
||||
if hdist < length {
|
||||
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c: length)
|
||||
length -= hdist
|
||||
hlen = hdist
|
||||
assert hlen <= length via "a <= b: a == c; c <= b"(c: hdist)
|
||||
} else {
|
||||
hlen = length
|
||||
length = 0
|
||||
assert hlen <= length via "a <= b: a == b"()
|
||||
}
|
||||
|
||||
hdist ~mod+= ((this.transformed_history_count ~mod- args.dst.history_position()) & 0xFFFF_FFFF) as base.u32
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
while true {
|
||||
n_copied = args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF .. 0x8000])
|
||||
if hlen <= n_copied {
|
||||
hlen = 0
|
||||
break
|
||||
}
|
||||
if n_copied > 0 {
|
||||
hlen -= n_copied
|
||||
hdist = (hdist ~mod+ n_copied) & 0x7FFF
|
||||
if hdist == 0 {
|
||||
// Wrap around the this.history ringbuffer.
|
||||
break
|
||||
}
|
||||
}
|
||||
// Copy from this.history[(this.history_index - hdist) ..].
|
||||
n_copied = args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[(this.history_index - hdist) & 0x7FFF ..])
|
||||
if n_copied < hlen {
|
||||
assert n_copied < length via "a < b: a < c; c <= b"(c: hlen)
|
||||
assert length > n_copied via "a > b: b < a"()
|
||||
length -= n_copied
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
// Copy from the start of this.history, if we wrapped around.
|
||||
if hlen > 0 {
|
||||
while true {
|
||||
n_copied = args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF .. 0x8000])
|
||||
if hlen <= n_copied {
|
||||
hlen = 0
|
||||
break
|
||||
}
|
||||
hlen -= n_copied
|
||||
hdist ~mod+= n_copied
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
continue.inner
|
||||
}
|
||||
|
||||
assert length >= hlen via "a >= b: b <= a"()
|
||||
length -= hlen
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
@@ -268,12 +243,11 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
n_copied = args.dst.limited_copy_u32_from_history!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
if length <= n_copied {
|
||||
length = 0
|
||||
break
|
||||
continue.loop
|
||||
}
|
||||
length -= n_copied
|
||||
yield? base."$short write"
|
||||
} endwhile
|
||||
} endwhile.inner
|
||||
} endwhile.loop
|
||||
|
||||
// TODO: "assert n_bits < 8"? What about (bits >> n_bits)?
|
||||
|
||||
@@ -277,7 +277,21 @@ pub func decoder.num_animation_loops() base.u32 {
|
||||
if this.seen_num_animation_loops_value {
|
||||
return this.num_animation_loops_value
|
||||
}
|
||||
return 1
|
||||
// Absent an explicit animation loop count, default to 1 meaning "play each
|
||||
// frame exactly once" for animated GIFs and 0 meaning "loop forever" for
|
||||
// still (non-animated) GIFs.
|
||||
//
|
||||
// In practice, returning 1 or 0 has no difference for still GIFs, in that
|
||||
// either way, the pixels on screen do not change over time. However,
|
||||
// returning 0 here matches other Wuffs image decoders (e.g. BMP, PNG)
|
||||
// returning 0 for their still images.
|
||||
//
|
||||
// As a consequence, if a still GIF is losslessly converted to a still BMP
|
||||
// and both of those are then converted to NIA, the two NIA outputs match.
|
||||
if this.num_decoded_frame_configs_value > 1 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
|
||||
@@ -56,7 +56,6 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
swizzler : base.pixel_swizzler,
|
||||
util : base.utility,
|
||||
)(
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
|
||||
+81
-17
@@ -75,6 +75,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
call_sequence : base.u8,
|
||||
|
||||
report_metadata_chrm : base.bool,
|
||||
report_metadata_exif : base.bool,
|
||||
report_metadata_gama : base.bool,
|
||||
report_metadata_iccp : base.bool,
|
||||
report_metadata_kvp : base.bool,
|
||||
@@ -90,6 +91,7 @@ pub struct decoder? implements base.image_decoder(
|
||||
seen_actl : base.bool,
|
||||
seen_chrm : base.bool,
|
||||
seen_fctl : base.bool,
|
||||
seen_exif : base.bool,
|
||||
seen_gama : base.bool,
|
||||
seen_iccp : base.bool,
|
||||
seen_idat : base.bool,
|
||||
@@ -441,8 +443,14 @@ pri func decoder.assign_filter_distance!() {
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y
|
||||
this.filter_distance = 1
|
||||
} else if this.depth == 16 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__Y_16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y_16BE
|
||||
if this.interlace_pass == 0 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__Y_16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y_16BE
|
||||
} else {
|
||||
// Interlaced means choosing filter_and_swizzle_tricky.
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
}
|
||||
this.filter_distance = 2
|
||||
}
|
||||
|
||||
@@ -535,10 +543,18 @@ pri func decoder.choose_filter_implementations!() {
|
||||
|
||||
pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
if this.chunk_type == 'PLTE'le {
|
||||
if this.seen_plte or (this.color_type <> 3) {
|
||||
if this.seen_plte {
|
||||
return "#bad chunk"
|
||||
} else if this.color_type == 3 {
|
||||
// Color type 3 means paletted.
|
||||
this.decode_plte?(src: args.src)
|
||||
} else if (this.color_type == 2) or (this.color_type == 6) {
|
||||
// Color types 2 and 6 means RGB and RGBA. In these cases, the PLTE
|
||||
// chunk is merely a hint, like a sPLT "suggested palette" chunk.
|
||||
// We ignore it.
|
||||
} else {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_plte?(src: args.src)
|
||||
this.seen_plte = true
|
||||
|
||||
} else if (this.chunk_type & ANCILLARY_BIT) == 0 {
|
||||
@@ -562,6 +578,15 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
|
||||
this.seen_chrm = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'eXIf'le {
|
||||
if this.report_metadata_exif {
|
||||
if this.seen_exif {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.decode_exif?(src: args.src)
|
||||
this.seen_exif = true
|
||||
}
|
||||
|
||||
} else if this.chunk_type == 'fcTL'le {
|
||||
if this.seen_fctl {
|
||||
return "#bad chunk"
|
||||
@@ -675,6 +700,18 @@ pri func decoder.decode_chrm?(src: base.io_reader) {
|
||||
this.metadata_z |= (0xFF_FFFF & u) << 40
|
||||
}
|
||||
|
||||
pri func decoder.decode_exif?(src: base.io_reader) {
|
||||
if this.chunk_length < 4 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
this.metadata_flavor = base.MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH
|
||||
this.metadata_fourcc = 'EXIF'be
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = args.src.position()
|
||||
this.metadata_z = this.metadata_y ~sat+ (this.chunk_length as base.u64)
|
||||
this.chunk_length = 0
|
||||
}
|
||||
|
||||
pri func decoder.decode_fctl?(src: base.io_reader) {
|
||||
var x0 : base.u32
|
||||
var y0 : base.u32
|
||||
@@ -1324,6 +1361,8 @@ 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) {
|
||||
if args.fourcc == 'CHRM'be {
|
||||
this.report_metadata_chrm = args.report
|
||||
} else if args.fourcc == 'EXIF'be {
|
||||
this.report_metadata_exif = args.report
|
||||
} else if args.fourcc == 'GAMA'be {
|
||||
this.report_metadata_gama = args.report
|
||||
} else if args.fourcc == 'ICCP'be {
|
||||
@@ -1351,6 +1390,27 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
while.goto_done true {{
|
||||
if this.metadata_flavor == base.MORE_INFORMATION__FLAVOR__METADATA_RAW_PASSTHROUGH {
|
||||
while true {
|
||||
if args.src.position() <> this.metadata_y {
|
||||
return base."#bad I/O position"
|
||||
} else if args.minfo <> nullptr {
|
||||
args.minfo.set!(
|
||||
flavor: this.metadata_flavor,
|
||||
w: this.metadata_fourcc,
|
||||
x: this.metadata_x,
|
||||
y: this.metadata_y,
|
||||
z: this.metadata_z)
|
||||
}
|
||||
if this.metadata_y >= this.metadata_z {
|
||||
break.goto_done
|
||||
}
|
||||
this.metadata_y = this.metadata_z
|
||||
yield? base."$even more information"
|
||||
} endwhile
|
||||
}
|
||||
|
||||
if this.metadata_is_zlib_compressed {
|
||||
if this.zlib_is_dirty {
|
||||
this.zlib.reset!()
|
||||
@@ -1589,20 +1649,24 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform
|
||||
this.metadata_is_zlib_compressed = true
|
||||
}
|
||||
|
||||
} else {
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
|
||||
// Skip the ancillary chunk's CRC-32 checksum.
|
||||
args.src.skip?(n: 4)
|
||||
|
||||
this.metadata_flavor = 0
|
||||
this.metadata_fourcc = 0
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
this.call_sequence = 2
|
||||
return ok
|
||||
}
|
||||
break.goto_done
|
||||
}} endwhile.goto_done
|
||||
|
||||
if this.chunk_length <> 0 {
|
||||
return "#bad chunk"
|
||||
}
|
||||
|
||||
// Skip the ancillary chunk's CRC-32 checksum.
|
||||
args.src.skip?(n: 4)
|
||||
|
||||
this.metadata_flavor = 0
|
||||
this.metadata_fourcc = 0
|
||||
this.metadata_x = 0
|
||||
this.metadata_y = 0
|
||||
this.metadata_z = 0
|
||||
|
||||
this.call_sequence = 2
|
||||
return ok
|
||||
|
||||
@@ -0,0 +1,599 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub status "#bad header"
|
||||
pub status "#bad run length encoding"
|
||||
pub status "#unsupported TGA file"
|
||||
|
||||
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
|
||||
|
||||
pub struct decoder? implements base.image_decoder(
|
||||
width : base.u32[..= 0xFFFF],
|
||||
height : base.u32[..= 0xFFFF],
|
||||
|
||||
// Call sequence states:
|
||||
// - 0x00: initial state.
|
||||
// - 0x03: image config decoded.
|
||||
// - 0x04: frame config decoded.
|
||||
// - 0xFF: end-of-data, usually after (the non-animated) frame decoded.
|
||||
//
|
||||
// State transitions:
|
||||
//
|
||||
// - 0x00 -> 0x03: via DIC
|
||||
// - 0x00 -> 0x04: via DFC with implicit DIC
|
||||
// - 0x00 -> 0xFF: via DF with implicit DIC and DFC
|
||||
//
|
||||
// - 0x03 -> 0x04: via DFC
|
||||
// - 0x03 -> 0xFF: via DF with implicit DFC
|
||||
//
|
||||
// - 0x04 -> 0xFF: via DFC
|
||||
// - 0x04 -> 0xFF: via DF
|
||||
//
|
||||
// - ???? -> 0x03: via RF for ???? > 0x00
|
||||
//
|
||||
// Where:
|
||||
// - DF is decode_frame
|
||||
// - DFC is decode_frame_config, implicit means nullptr args.dst
|
||||
// - DIC is decode_image_config, implicit means nullptr args.dst
|
||||
// - RF is restart_frame
|
||||
call_sequence : base.u8,
|
||||
|
||||
header_id_length : base.u8,
|
||||
header_color_map_type : base.u8,
|
||||
header_image_type : base.u8,
|
||||
header_color_map_first_entry_index : base.u16,
|
||||
header_color_map_length : base.u16,
|
||||
header_color_map_entry_size : base.u8,
|
||||
header_pixel_depth : base.u8,
|
||||
header_image_descriptor : base.u8,
|
||||
|
||||
opaque : base.bool,
|
||||
|
||||
scratch_bytes_per_pixel : base.u32[..= 4],
|
||||
src_bytes_per_pixel : base.u32[..= 4],
|
||||
src_pixfmt : base.u32,
|
||||
|
||||
frame_config_io_position : base.u64,
|
||||
|
||||
swizzler : base.pixel_swizzler,
|
||||
util : base.utility,
|
||||
)(
|
||||
dst_palette : array[4 * 256] base.u8,
|
||||
src_palette : array[4 * 256] base.u8,
|
||||
scratch : array[4] base.u8,
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
}
|
||||
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var c : base.u32
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
var i : base.u32
|
||||
|
||||
if this.call_sequence <> 0 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
|
||||
this.header_id_length = args.src.read_u8?()
|
||||
this.header_color_map_type = args.src.read_u8?()
|
||||
if this.header_color_map_type > 1 {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
this.header_image_type = args.src.read_u8?()
|
||||
if (this.header_image_type == 0x01) or
|
||||
(this.header_image_type == 0x02) or
|
||||
(this.header_image_type == 0x03) or
|
||||
(this.header_image_type == 0x09) or
|
||||
(this.header_image_type == 0x0A) or
|
||||
(this.header_image_type == 0x0B) {
|
||||
// No-op.
|
||||
} else {
|
||||
// TODO: 0x20 and 0x21 are invalid, according to the spec, but are
|
||||
// apparently unofficial extensions.
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
this.header_color_map_first_entry_index = args.src.read_u16le?()
|
||||
this.header_color_map_length = args.src.read_u16le?()
|
||||
this.header_color_map_entry_size = args.src.read_u8?()
|
||||
if this.header_color_map_type <> 0 {
|
||||
// We have a color-mapped image (in Wuffs, an indexed pixel format).
|
||||
if (this.header_color_map_first_entry_index <> 0) or
|
||||
(this.header_color_map_length > 0x100) {
|
||||
return "#unsupported TGA file"
|
||||
} else if (this.header_color_map_entry_size <> 0x0F) and
|
||||
(this.header_color_map_entry_size <> 0x10) and
|
||||
(this.header_color_map_entry_size <> 0x18) and
|
||||
(this.header_color_map_entry_size <> 0x20) {
|
||||
return "#bad header"
|
||||
}
|
||||
} else {
|
||||
// The color-map fields must be zero.
|
||||
if (this.header_color_map_first_entry_index <> 0) or
|
||||
(this.header_color_map_length <> 0) or
|
||||
(this.header_color_map_entry_size <> 0) {
|
||||
return "#bad header"
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore the X-Origin and Y-Origin fields.
|
||||
args.src.skip_u32?(n: 4)
|
||||
|
||||
this.width = args.src.read_u16le_as_u32?()
|
||||
this.height = args.src.read_u16le_as_u32?()
|
||||
|
||||
this.header_pixel_depth = args.src.read_u8?()
|
||||
if (this.header_pixel_depth <> 0x01) and
|
||||
(this.header_pixel_depth <> 0x08) and
|
||||
(this.header_pixel_depth <> 0x0F) and
|
||||
(this.header_pixel_depth <> 0x10) and
|
||||
(this.header_pixel_depth <> 0x18) and
|
||||
(this.header_pixel_depth <> 0x20) {
|
||||
return "#bad header"
|
||||
}
|
||||
|
||||
if (this.header_image_type | 8) == 0x09 {
|
||||
this.scratch_bytes_per_pixel = 1
|
||||
this.src_bytes_per_pixel = 1
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL
|
||||
this.opaque =
|
||||
(this.header_color_map_entry_size == 0x0F) or
|
||||
(this.header_color_map_entry_size == 0x18)
|
||||
|
||||
} else if (this.header_image_type | 8) == 0x0A {
|
||||
if (this.header_pixel_depth == 0x0F) or
|
||||
(this.header_pixel_depth == 0x10) {
|
||||
// Wuffs' base.pixel_swizzler doesn't support BGRX5551, so
|
||||
// scratch_bytes_per_pixel and src_bytes_per_pixel are different.
|
||||
this.scratch_bytes_per_pixel = 4
|
||||
this.src_bytes_per_pixel = 0
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
} else if this.header_pixel_depth == 0x18 {
|
||||
this.scratch_bytes_per_pixel = 3
|
||||
this.src_bytes_per_pixel = 3
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGR
|
||||
this.opaque = true
|
||||
} else if this.header_pixel_depth == 0x20 {
|
||||
this.scratch_bytes_per_pixel = 4
|
||||
this.src_bytes_per_pixel = 4
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
} else {
|
||||
return "#unsupported TGA file"
|
||||
}
|
||||
|
||||
} else {
|
||||
if this.header_pixel_depth == 0x08 {
|
||||
this.scratch_bytes_per_pixel = 1
|
||||
this.src_bytes_per_pixel = 1
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y
|
||||
this.opaque = true
|
||||
} else {
|
||||
return "#unsupported TGA file"
|
||||
}
|
||||
}
|
||||
|
||||
this.header_image_descriptor = args.src.read_u8?()
|
||||
if (this.header_image_descriptor & 0x10) <> 0 {
|
||||
// We don't support right-to-left, only left-to-right pixel order.
|
||||
return "#unsupported TGA file"
|
||||
}
|
||||
|
||||
// Skip the Image ID.
|
||||
args.src.skip_u32?(n: this.header_id_length as base.u32)
|
||||
|
||||
// Read the color map.
|
||||
if this.header_color_map_type <> 0 {
|
||||
while i < (this.header_color_map_length as base.u32) {
|
||||
assert i <= 0xFFFF via "a <= b: a <= c; c <= b"(c: this.header_color_map_length as base.u32)
|
||||
if this.header_color_map_entry_size == 0x18 {
|
||||
c = args.src.read_u24le_as_u32?()
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c >> 0x00) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c >> 0x08) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c >> 0x10) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = 0xFF
|
||||
} else if this.header_color_map_entry_size == 0x20 {
|
||||
c = args.src.read_u32le?()
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c >> 0x00) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c >> 0x08) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c >> 0x10) & 0xFF) as base.u8
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = ((c >> 0x18) & 0xFF) as base.u8
|
||||
} else {
|
||||
// Expand 15-bit or 16-bit color map entries.
|
||||
c = args.src.read_u16le_as_u32?()
|
||||
c5 = 0x1F & (c >> 0)
|
||||
this.src_palette[((i & 0xFF) * 4) + 0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
this.src_palette[((i & 0xFF) * 4) + 1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
this.src_palette[((i & 0xFF) * 4) + 2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
this.src_palette[((i & 0xFF) * 4) + 3] = 0xFF
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
while i < 0x100 {
|
||||
this.src_palette[(i * 4) + 0] = 0x00
|
||||
this.src_palette[(i * 4) + 1] = 0x00
|
||||
this.src_palette[(i * 4) + 2] = 0x00
|
||||
this.src_palette[(i * 4) + 3] = 0xFF
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.frame_config_io_position = args.src.position()
|
||||
|
||||
if args.dst <> nullptr {
|
||||
args.dst.set!(
|
||||
pixfmt: this.src_pixfmt,
|
||||
pixsub: 0,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
first_frame_io_position: this.frame_config_io_position,
|
||||
first_frame_is_opaque: this.opaque)
|
||||
}
|
||||
|
||||
this.call_sequence = 3
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) {
|
||||
if this.call_sequence < 3 {
|
||||
this.decode_image_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 3 {
|
||||
if this.frame_config_io_position <> args.src.position() {
|
||||
return base."#bad restart"
|
||||
}
|
||||
} else if this.call_sequence == 4 {
|
||||
this.call_sequence = 0xFF
|
||||
return base."@end of data"
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
args.dst.set!(bounds: this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
max_excl_x: this.width,
|
||||
max_excl_y: this.height),
|
||||
duration: 0,
|
||||
index: 0,
|
||||
io_position: this.frame_config_io_position,
|
||||
disposal: 0,
|
||||
opaque_within_bounds: this.opaque,
|
||||
overwrite_instead_of_blend: false,
|
||||
background_color: 0xFF00_0000)
|
||||
}
|
||||
|
||||
this.call_sequence = 4
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) {
|
||||
var status : base.status
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
||||
var dst_x : base.u32
|
||||
var dst_y : base.u32
|
||||
var tab : table base.u8
|
||||
var dst_palette : slice base.u8
|
||||
var dst : slice base.u8
|
||||
var dst_start : base.u64
|
||||
var src_palette : slice base.u8
|
||||
var mark : base.u64
|
||||
var num_pixels64 : base.u64
|
||||
var num_pixels32 : base.u32[..= 0xFFFF]
|
||||
var lit_length : base.u32[..= 0xFFFF]
|
||||
var run_length : base.u32[..= 0xFFFF]
|
||||
var num_dst_bytes : base.u64[..= 0x1F_FFE0]
|
||||
var num_src_bytes : base.u32[..= 0x3_FFFC]
|
||||
var c : base.u32
|
||||
var c5 : base.u32[..= 0x1F]
|
||||
|
||||
if this.call_sequence < 4 {
|
||||
this.decode_frame_config?(dst: nullptr, src: args.src)
|
||||
} else if this.call_sequence == 4 {
|
||||
// No-op.
|
||||
} else {
|
||||
return base."@end of data"
|
||||
}
|
||||
|
||||
if this.header_color_map_type <> 0 {
|
||||
src_palette = this.src_palette[..]
|
||||
}
|
||||
status = this.swizzler.prepare!(
|
||||
dst_pixfmt: args.dst.pixel_format(),
|
||||
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),
|
||||
src_pixfmt: this.util.make_pixel_format(repr: this.src_pixfmt),
|
||||
src_palette: src_palette,
|
||||
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) as base.u64
|
||||
|
||||
if (this.header_image_descriptor & 0x20) == 0 { // Bottom-to-top.
|
||||
dst_y = this.height ~mod- 1
|
||||
}
|
||||
if (this.header_image_type & 8) == 0 {
|
||||
// No RLE (run length encoding) means that the entire row is
|
||||
// effectively literals.
|
||||
lit_length = this.width
|
||||
}
|
||||
|
||||
while.resume true {
|
||||
tab = args.dst.plane(p: 0)
|
||||
dst_palette = args.dst.palette_or_else(fallback: this.dst_palette[..])
|
||||
|
||||
while dst_y < this.height {
|
||||
dst = tab.row_u32(y: dst_y)
|
||||
dst_start = (dst_x as base.u64) * dst_bytes_per_pixel
|
||||
if dst_start <= dst.length() {
|
||||
dst = dst[dst_start ..]
|
||||
} else {
|
||||
dst = this.util.empty_slice_u8()
|
||||
}
|
||||
|
||||
while dst_x < this.width {
|
||||
assert dst_x <= 0xFFFF via "a <= b: a <= c; c <= b"(c: this.width)
|
||||
|
||||
if this.src_bytes_per_pixel > 0 {
|
||||
if lit_length > 0 {
|
||||
mark = args.src.mark()
|
||||
num_pixels64 = args.src.length() / (this.src_bytes_per_pixel as base.u64)
|
||||
num_pixels32 = num_pixels64.min(a: lit_length as base.u64) as base.u32
|
||||
num_dst_bytes = (num_pixels32 as base.u64) * dst_bytes_per_pixel
|
||||
num_src_bytes = num_pixels32 * this.src_bytes_per_pixel
|
||||
args.src.skip_u32?(n: num_src_bytes)
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: args.src.since(mark: mark))
|
||||
if num_dst_bytes <= dst.length() {
|
||||
dst = dst[num_dst_bytes ..]
|
||||
} else {
|
||||
dst = this.util.empty_slice_u8()
|
||||
}
|
||||
dst_x += num_pixels32
|
||||
lit_length = (lit_length ~mod- num_pixels32) & 0xFFFF
|
||||
if lit_length > 0 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
|
||||
} else if run_length > 0 {
|
||||
run_length -= 1
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: this.scratch[.. this.scratch_bytes_per_pixel])
|
||||
if dst_bytes_per_pixel <= dst.length() {
|
||||
dst = dst[dst_bytes_per_pixel ..]
|
||||
}
|
||||
dst_x += 1
|
||||
|
||||
} else {
|
||||
// Handle Raw vs RLE packets.
|
||||
if args.src.length() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
if args.src.peek_u8_as_u32() < 0x80 {
|
||||
lit_length = args.src.peek_u8_as_u32() + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if (lit_length + dst_x) > this.width {
|
||||
return "#bad run length encoding"
|
||||
}
|
||||
|
||||
} else {
|
||||
if this.src_bytes_per_pixel == 1 {
|
||||
if args.src.length() < 2 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[0] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} else if this.src_bytes_per_pixel == 3 {
|
||||
if args.src.length() < 4 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[0] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[1] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[2] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
} else { // this.src_bytes_per_pixel == 4
|
||||
if args.src.length() < 5 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[0] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[1] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[2] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
this.scratch[3] = args.src.peek_u8()
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
}
|
||||
|
||||
if (run_length + dst_x) > this.width {
|
||||
return "#bad run length encoding"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Wuffs' base.pixel_swizzler doesn't support BGRX5551, so
|
||||
// we manually convert to BGRX8888, one pixel at a time.
|
||||
|
||||
if lit_length > 0 {
|
||||
if args.src.length() < 2 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
c = args.src.peek_u16le_as_u32()
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
c5 = 0x1F & (c >> 0)
|
||||
this.scratch[0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
this.scratch[1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
this.scratch[2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
this.scratch[3] = 0xFF
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: this.scratch[.. 4])
|
||||
if dst_bytes_per_pixel <= dst.length() {
|
||||
dst = dst[dst_bytes_per_pixel ..]
|
||||
}
|
||||
dst_x += 1
|
||||
lit_length -= 1
|
||||
|
||||
} else if run_length > 0 {
|
||||
run_length -= 1
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
src: this.scratch[.. this.scratch_bytes_per_pixel])
|
||||
if dst_bytes_per_pixel <= dst.length() {
|
||||
dst = dst[dst_bytes_per_pixel ..]
|
||||
}
|
||||
dst_x += 1
|
||||
|
||||
} else {
|
||||
// Handle Raw vs RLE packets.
|
||||
if args.src.length() <= 0 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
if args.src.peek_u8_as_u32() < 0x80 {
|
||||
lit_length = args.src.peek_u8_as_u32() + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
if (lit_length + dst_x) > this.width {
|
||||
return "#bad run length encoding"
|
||||
}
|
||||
|
||||
} else {
|
||||
if args.src.length() < 3 {
|
||||
yield? base."$short read"
|
||||
continue.resume
|
||||
}
|
||||
run_length = (args.src.peek_u8_as_u32() & 0x7F) + 1
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
c = args.src.peek_u16le_as_u32()
|
||||
args.src.skip_u32_fast!(actual: 2, worst_case: 2)
|
||||
c5 = 0x1F & (c >> 0)
|
||||
this.scratch[0] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 5)
|
||||
this.scratch[1] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
c5 = 0x1F & (c >> 10)
|
||||
this.scratch[2] = ((c5 << 3) | (c5 >> 2)) as base.u8
|
||||
// TODO: can the alpha value be zero (BGRA5551 not BGRX5551)?
|
||||
this.scratch[3] = 0xFF
|
||||
|
||||
if (run_length + dst_x) > this.width {
|
||||
return "#bad run length encoding"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} endwhile
|
||||
dst_x = 0
|
||||
|
||||
if (this.header_image_descriptor & 0x20) == 0 { // Bottom-to-top.
|
||||
dst_y ~mod-= 1
|
||||
} else { // Top-to-bottom.
|
||||
dst_y ~mod+= 1
|
||||
}
|
||||
if (this.header_image_type & 8) == 0 {
|
||||
// No RLE (run length encoding) means that the entire row is
|
||||
// effectively literals.
|
||||
lit_length = this.width
|
||||
}
|
||||
} endwhile
|
||||
break.resume
|
||||
} endwhile.resume
|
||||
|
||||
this.call_sequence = 0xFF
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
return this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
min_incl_y: 0,
|
||||
max_excl_x: this.width,
|
||||
max_excl_y: this.height)
|
||||
}
|
||||
|
||||
pub func decoder.num_animation_loops() base.u32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
if this.call_sequence > 3 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
if this.call_sequence > 4 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.status {
|
||||
if this.call_sequence < 3 {
|
||||
return base."#bad call sequence"
|
||||
}
|
||||
if args.index <> 0 {
|
||||
return base."#bad argument"
|
||||
}
|
||||
this.call_sequence = 3
|
||||
this.frame_config_io_position = args.io_position
|
||||
return ok
|
||||
}
|
||||
|
||||
pub func decoder.set_report_metadata!(fourcc: base.u32, report: base.bool) {
|
||||
// TODO: implement.
|
||||
}
|
||||
|
||||
pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_information, src: base.io_reader) {
|
||||
return base."#no more information"
|
||||
}
|
||||
|
||||
pub func decoder.workbuf_len() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl: 0, max_incl: 0)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2021 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// --------
|
||||
|
||||
// Quirks are discussed in (/doc/note/quirks.md).
|
||||
//
|
||||
// The base38 encoding of "zlib" is 0x1F_7F79. Left shifting by 10 gives
|
||||
// 0x7DFD_E400.
|
||||
pri const QUIRKS_BASE : base.u32 = 0x7DFD_E400
|
||||
|
||||
// --------
|
||||
|
||||
// When this quirk is enabled, the decoder speaks just raw deflate, without
|
||||
// zlib's configuration prefix and checksum suffix wrapped around that.
|
||||
//
|
||||
// A zlib.decoder basically becomes a deflate.decoder. This is useful when the
|
||||
// caller might want to choose between the two related-but-slightly-different
|
||||
// formats at run time but would rather not allocate two separate decoders.
|
||||
pub const QUIRK_JUST_RAW_DEFLATE : base.u32 = 0x7DFD_E400 | 0x00
|
||||
|
||||
pri const QUIRKS_COUNT : base.u32 = 0x01
|
||||
@@ -33,6 +33,8 @@ pub struct decoder? implements base.io_transformer(
|
||||
got_dictionary : base.bool,
|
||||
want_dictionary : base.bool,
|
||||
|
||||
quirks : array[QUIRKS_COUNT] base.bool,
|
||||
|
||||
ignore_checksum : base.bool,
|
||||
checksum : adler32.hasher,
|
||||
|
||||
@@ -60,8 +62,15 @@ pub func decoder.add_dictionary!(dict: slice base.u8) {
|
||||
}
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
|
||||
if this.header_complete {
|
||||
this.bad_call_sequence = true
|
||||
} else if args.quirk == base.QUIRK_IGNORE_CHECKSUM {
|
||||
this.ignore_checksum = args.enabled
|
||||
} else if args.quirk >= QUIRKS_BASE {
|
||||
args.quirk -= QUIRKS_BASE
|
||||
if args.quirk < QUIRKS_COUNT {
|
||||
this.quirks[args.quirk] = args.enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +89,8 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
|
||||
if this.bad_call_sequence {
|
||||
return base."#bad call sequence"
|
||||
} else if this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE] {
|
||||
// No-op.
|
||||
} else if not this.want_dictionary {
|
||||
x = args.src.read_u16be?()
|
||||
if ((x >> 8) & 0x0F) <> 0x08 {
|
||||
@@ -112,7 +123,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
while true {
|
||||
mark = args.dst.mark()
|
||||
status =? this.flate.transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
||||
if not this.ignore_checksum {
|
||||
if (not this.ignore_checksum) and (not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE]) {
|
||||
checksum_got = this.checksum.update_u32!(x: args.dst.since(mark: mark))
|
||||
}
|
||||
if status.is_ok() {
|
||||
@@ -120,9 +131,12 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
}
|
||||
yield? status
|
||||
} endwhile
|
||||
checksum_want = args.src.read_u32be?()
|
||||
if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
|
||||
if not this.quirks[QUIRK_JUST_RAW_DEFLATE - QUIRKS_BASE] {
|
||||
checksum_want = args.src.read_u32be?()
|
||||
if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
|
||||
return "#bad checksum"
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: reset state (e.g. want_dictionary), so that we can read concat'ed
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Ignore everything without a dot.
|
||||
#
|
||||
# This ignores "pngsuite" but not "fetch-pngsuite.sh".
|
||||
*
|
||||
!*.*
|
||||
@@ -0,0 +1,5 @@
|
||||
This directory contains third party test data, not checked into the repository
|
||||
directly for download size and copyright reasons.
|
||||
|
||||
It also contains derived summary data files (such as `nia-checksums-of-*.txt`)
|
||||
which *are* checked into the repository, for regression testing.
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2021 The Wuffs Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# ----------------
|
||||
|
||||
# This script fetches the PngSuite collection of PNG images.
|
||||
|
||||
if [ ! -e ../../wuffs-root-directory.txt ]; then
|
||||
echo "$0 should be run from the Wuffs test/3pdata directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p pngsuite
|
||||
curl --silent http://www.schaik.com/pngsuite/PngSuite-2017jul19.tgz | tar -xzf /dev/stdin -C pngsuite
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2022 The Wuffs Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# ----------------
|
||||
|
||||
# This script fetches the TrueVision TGA test suite.
|
||||
|
||||
if [ ! -e ../../wuffs-root-directory.txt ]; then
|
||||
echo "$0 should be run from the Wuffs test/3pdata directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check out a specific commit (from January 2022).
|
||||
git clone --quiet https://github.com/image-rs/image.git
|
||||
cd image
|
||||
git reset --quiet --hard 2e1d2e5928077eae7a92f8b5cac83ca1ae0db0cd
|
||||
cd ..
|
||||
|
||||
# Copy out the *.tga files.
|
||||
mkdir -p tgasuite
|
||||
cp image/tests/images/tga/testsuite/*.tga tgasuite
|
||||
cp image/tests/regression/tga/*.tga tgasuite
|
||||
rm -rf image
|
||||
@@ -0,0 +1,29 @@
|
||||
As per [the PngSuite page](http://www.schaik.com/pngsuite/#corrupted), every
|
||||
`x*.png` file in the test suite is invalid PNG.
|
||||
|
||||
Nonetheless, `nia-checksums-of-pngsuite.txt` contains an entry for
|
||||
`xcsn0g01.png`, meaning that `convert-to-nia` decoded *some* pixels for it.
|
||||
This is working as intended, because the `xcsn0g01.png` invalidity is in its
|
||||
`IDAT` chunk's checksum (compared to `xhdn0g08.png`'s corruption in its `IHDR`
|
||||
chunk's checksum).
|
||||
|
||||
The `convert-to-nia` semantics are that, provided that it can decode a complete
|
||||
image configuration (width, height, pixel format, etc which, for PNG, comes
|
||||
from the `IHDR` chunk), it outputs *as many pixels as possible* (even if that's
|
||||
zero pixels) so that it gives a 'best effort' decoding for truncated images.
|
||||
Indeed, the NIA conversion for `xcsn0g01.png` holds all-zero pixels (and a
|
||||
"png: bad checksum" error message on stderr) but also a zero exit code.
|
||||
|
||||
```
|
||||
$ gen/bin/example-convert-to-nia < test/3pdata/pngsuite/xcsn0g01.png | hd
|
||||
00000000 6e c3 af 41 ff 62 6e 34 20 00 00 00 20 00 00 00 |n..A.bn4 ... ...|
|
||||
00000010 00 00 00 00 00 00 00 00 6e c3 af 45 ff 62 6e 34 |........n..E.bn4|
|
||||
00000020 20 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 | ... ...........|
|
||||
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
|
||||
*
|
||||
00001020 00 00 00 00 00 00 00 00 |........|
|
||||
00001028
|
||||
png: bad checksum
|
||||
$ echo $?
|
||||
0
|
||||
```
|
||||
@@ -0,0 +1,164 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
aac44167 test/3pdata/pngsuite/PngSuite.png
|
||||
926d3aa2 test/3pdata/pngsuite/basi0g01.png
|
||||
8f50bdc6 test/3pdata/pngsuite/basi0g02.png
|
||||
6d612626 test/3pdata/pngsuite/basi0g04.png
|
||||
024cf410 test/3pdata/pngsuite/basi0g08.png
|
||||
bb956205 test/3pdata/pngsuite/basi0g16.png
|
||||
d1ae61d3 test/3pdata/pngsuite/basi2c08.png
|
||||
84bc9be8 test/3pdata/pngsuite/basi2c16.png
|
||||
49bc6b98 test/3pdata/pngsuite/basi3p01.png
|
||||
ad12897b test/3pdata/pngsuite/basi3p02.png
|
||||
81c22b59 test/3pdata/pngsuite/basi3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/basi3p08.png
|
||||
1b468494 test/3pdata/pngsuite/basi4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/basi4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/basi6a08.png
|
||||
b039babf test/3pdata/pngsuite/basi6a16.png
|
||||
926d3aa2 test/3pdata/pngsuite/basn0g01.png
|
||||
8f50bdc6 test/3pdata/pngsuite/basn0g02.png
|
||||
6d612626 test/3pdata/pngsuite/basn0g04.png
|
||||
024cf410 test/3pdata/pngsuite/basn0g08.png
|
||||
bb956205 test/3pdata/pngsuite/basn0g16.png
|
||||
d1ae61d3 test/3pdata/pngsuite/basn2c08.png
|
||||
84bc9be8 test/3pdata/pngsuite/basn2c16.png
|
||||
49bc6b98 test/3pdata/pngsuite/basn3p01.png
|
||||
ad12897b test/3pdata/pngsuite/basn3p02.png
|
||||
81c22b59 test/3pdata/pngsuite/basn3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/basn3p08.png
|
||||
1b468494 test/3pdata/pngsuite/basn4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/basn4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/basn6a08.png
|
||||
b039babf test/3pdata/pngsuite/basn6a16.png
|
||||
1b468494 test/3pdata/pngsuite/bgai4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/bgai4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/bgan6a08.png
|
||||
b039babf test/3pdata/pngsuite/bgan6a16.png
|
||||
1b468494 test/3pdata/pngsuite/bgbn4a08.png
|
||||
8a6dd244 test/3pdata/pngsuite/bggn4a16.png
|
||||
2b1044ce test/3pdata/pngsuite/bgwn6a08.png
|
||||
b039babf test/3pdata/pngsuite/bgyn6a16.png
|
||||
b58985e2 test/3pdata/pngsuite/ccwn2c08.png
|
||||
b7f7127d test/3pdata/pngsuite/ccwn3p08.png
|
||||
c7b4c0fa test/3pdata/pngsuite/cdfn2c08.png
|
||||
dabf7a40 test/3pdata/pngsuite/cdhn2c08.png
|
||||
8491ddf5 test/3pdata/pngsuite/cdsn2c08.png
|
||||
d9282a90 test/3pdata/pngsuite/cdun2c08.png
|
||||
81c22b59 test/3pdata/pngsuite/ch1n3p04.png
|
||||
e59ecea5 test/3pdata/pngsuite/ch2n3p08.png
|
||||
b3334ede test/3pdata/pngsuite/cm0n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/cm7n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/cm9n0g04.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs3n2c16.png
|
||||
d565507c test/3pdata/pngsuite/cs3n3p08.png
|
||||
2f5a21b9 test/3pdata/pngsuite/cs5n2c08.png
|
||||
2f5a21b9 test/3pdata/pngsuite/cs5n3p08.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs8n2c08.png
|
||||
8ce6e28c test/3pdata/pngsuite/cs8n3p08.png
|
||||
b3334ede test/3pdata/pngsuite/ct0n0g04.png
|
||||
b3334ede test/3pdata/pngsuite/ct1n0g04.png
|
||||
1bfcb6e6 test/3pdata/pngsuite/cten0g04.png
|
||||
8e493daf test/3pdata/pngsuite/ctfn0g04.png
|
||||
417a539e test/3pdata/pngsuite/ctgn0g04.png
|
||||
28033324 test/3pdata/pngsuite/cthn0g04.png
|
||||
71a82501 test/3pdata/pngsuite/ctjn0g04.png
|
||||
b3334ede test/3pdata/pngsuite/ctzn0g04.png
|
||||
aa5328d3 test/3pdata/pngsuite/exif2c08.png
|
||||
b81f03cc test/3pdata/pngsuite/f00n0g08.png
|
||||
4a12368c test/3pdata/pngsuite/f00n2c08.png
|
||||
7fe4a9d8 test/3pdata/pngsuite/f01n0g08.png
|
||||
36758edc test/3pdata/pngsuite/f01n2c08.png
|
||||
e0ab5774 test/3pdata/pngsuite/f02n0g08.png
|
||||
5e613513 test/3pdata/pngsuite/f02n2c08.png
|
||||
0719e3fa test/3pdata/pngsuite/f03n0g08.png
|
||||
c4709cc1 test/3pdata/pngsuite/f03n2c08.png
|
||||
457f1dab test/3pdata/pngsuite/f04n0g08.png
|
||||
7ec3c986 test/3pdata/pngsuite/f04n2c08.png
|
||||
1f319e46 test/3pdata/pngsuite/f99n0g04.png
|
||||
6000bb5b test/3pdata/pngsuite/g03n0g16.png
|
||||
aa019a24 test/3pdata/pngsuite/g03n2c08.png
|
||||
8f0a3383 test/3pdata/pngsuite/g03n3p04.png
|
||||
f3a44153 test/3pdata/pngsuite/g04n0g16.png
|
||||
3e852c56 test/3pdata/pngsuite/g04n2c08.png
|
||||
edb3555b test/3pdata/pngsuite/g04n3p04.png
|
||||
6b105de1 test/3pdata/pngsuite/g05n0g16.png
|
||||
938803a0 test/3pdata/pngsuite/g05n2c08.png
|
||||
9f7ad612 test/3pdata/pngsuite/g05n3p04.png
|
||||
28816978 test/3pdata/pngsuite/g07n0g16.png
|
||||
fedb8920 test/3pdata/pngsuite/g07n2c08.png
|
||||
9373010e test/3pdata/pngsuite/g07n3p04.png
|
||||
58eb5aca test/3pdata/pngsuite/g10n0g16.png
|
||||
8c5550d0 test/3pdata/pngsuite/g10n2c08.png
|
||||
a6120550 test/3pdata/pngsuite/g10n3p04.png
|
||||
14cc7e1c test/3pdata/pngsuite/g25n0g16.png
|
||||
fd0f349f test/3pdata/pngsuite/g25n2c08.png
|
||||
eb13812a test/3pdata/pngsuite/g25n3p04.png
|
||||
bb956205 test/3pdata/pngsuite/oi1n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi1n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi2n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi2n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi4n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi4n2c16.png
|
||||
bb956205 test/3pdata/pngsuite/oi9n0g16.png
|
||||
84bc9be8 test/3pdata/pngsuite/oi9n2c16.png
|
||||
84bc9be8 test/3pdata/pngsuite/pp0n2c16.png
|
||||
8ed1f246 test/3pdata/pngsuite/pp0n6a08.png
|
||||
024cf410 test/3pdata/pngsuite/ps1n0g08.png
|
||||
84bc9be8 test/3pdata/pngsuite/ps1n2c16.png
|
||||
024cf410 test/3pdata/pngsuite/ps2n0g08.png
|
||||
84bc9be8 test/3pdata/pngsuite/ps2n2c16.png
|
||||
7cf2b7b2 test/3pdata/pngsuite/s01i3p01.png
|
||||
7cf2b7b2 test/3pdata/pngsuite/s01n3p01.png
|
||||
ffa30c78 test/3pdata/pngsuite/s02i3p01.png
|
||||
ffa30c78 test/3pdata/pngsuite/s02n3p01.png
|
||||
ad298c62 test/3pdata/pngsuite/s03i3p01.png
|
||||
ad298c62 test/3pdata/pngsuite/s03n3p01.png
|
||||
2c30132c test/3pdata/pngsuite/s04i3p01.png
|
||||
2c30132c test/3pdata/pngsuite/s04n3p01.png
|
||||
5fb20358 test/3pdata/pngsuite/s05i3p02.png
|
||||
5fb20358 test/3pdata/pngsuite/s05n3p02.png
|
||||
764e90bd test/3pdata/pngsuite/s06i3p02.png
|
||||
764e90bd test/3pdata/pngsuite/s06n3p02.png
|
||||
9eebca92 test/3pdata/pngsuite/s07i3p02.png
|
||||
9eebca92 test/3pdata/pngsuite/s07n3p02.png
|
||||
d57f2e84 test/3pdata/pngsuite/s08i3p02.png
|
||||
d57f2e84 test/3pdata/pngsuite/s08n3p02.png
|
||||
7585127f test/3pdata/pngsuite/s09i3p02.png
|
||||
7585127f test/3pdata/pngsuite/s09n3p02.png
|
||||
034051a8 test/3pdata/pngsuite/s32i3p04.png
|
||||
034051a8 test/3pdata/pngsuite/s32n3p04.png
|
||||
a377dcdd test/3pdata/pngsuite/s33i3p04.png
|
||||
a377dcdd test/3pdata/pngsuite/s33n3p04.png
|
||||
5bcd998d test/3pdata/pngsuite/s34i3p04.png
|
||||
5bcd998d test/3pdata/pngsuite/s34n3p04.png
|
||||
1cefbbe2 test/3pdata/pngsuite/s35i3p04.png
|
||||
1cefbbe2 test/3pdata/pngsuite/s35n3p04.png
|
||||
97c763a3 test/3pdata/pngsuite/s36i3p04.png
|
||||
97c763a3 test/3pdata/pngsuite/s36n3p04.png
|
||||
2d6bd687 test/3pdata/pngsuite/s37i3p04.png
|
||||
2d6bd687 test/3pdata/pngsuite/s37n3p04.png
|
||||
169951e5 test/3pdata/pngsuite/s38i3p04.png
|
||||
169951e5 test/3pdata/pngsuite/s38n3p04.png
|
||||
17a92eb2 test/3pdata/pngsuite/s39i3p04.png
|
||||
17a92eb2 test/3pdata/pngsuite/s39n3p04.png
|
||||
8cc6b93d test/3pdata/pngsuite/s40i3p04.png
|
||||
8cc6b93d test/3pdata/pngsuite/s40n3p04.png
|
||||
4e406947 test/3pdata/pngsuite/tbbn0g04.png
|
||||
c6e83019 test/3pdata/pngsuite/tbbn2c16.png
|
||||
46deef3b test/3pdata/pngsuite/tbbn3p08.png
|
||||
c6e83019 test/3pdata/pngsuite/tbgn2c16.png
|
||||
46deef3b test/3pdata/pngsuite/tbgn3p08.png
|
||||
c6e83019 test/3pdata/pngsuite/tbrn2c08.png
|
||||
2289ed1e test/3pdata/pngsuite/tbwn0g16.png
|
||||
46deef3b test/3pdata/pngsuite/tbwn3p08.png
|
||||
46deef3b test/3pdata/pngsuite/tbyn3p08.png
|
||||
59b23555 test/3pdata/pngsuite/tm3n3p02.png
|
||||
f2457b64 test/3pdata/pngsuite/tp0n0g08.png
|
||||
05846c5f test/3pdata/pngsuite/tp0n2c08.png
|
||||
3d7708a8 test/3pdata/pngsuite/tp0n3p08.png
|
||||
46deef3b test/3pdata/pngsuite/tp1n3p08.png
|
||||
f286cbfc test/3pdata/pngsuite/xcsn0g01.png
|
||||
9098c4d8 test/3pdata/pngsuite/z00n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z03n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z06n2c08.png
|
||||
9098c4d8 test/3pdata/pngsuite/z09n2c08.png
|
||||
@@ -0,0 +1,9 @@
|
||||
# Generated by script/print-nia-checksums.sh
|
||||
9fbe866a test/3pdata/tgasuite/cbw8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ccm8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ctc24.tga
|
||||
9fbe866a test/3pdata/tgasuite/ubw8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/ucm8.tga
|
||||
5d75ef41 test/3pdata/tgasuite/utc16.tga
|
||||
5d75ef41 test/3pdata/tgasuite/utc24.tga
|
||||
79781cfb test/3pdata/tgasuite/utc32.tga
|
||||
@@ -89,13 +89,13 @@ golden_test g_deflate_deflate_backref_crosses_blocks_gt = {
|
||||
"backref-crosses-blocks.deflate",
|
||||
};
|
||||
|
||||
golden_test g_deflate_deflate_degenerate_huffman_unused_gt = {
|
||||
golden_test g_deflate_deflate_degenerate_huffman_gt = {
|
||||
.want_filename =
|
||||
"test/data/artificial-deflate/"
|
||||
"degenerate-huffman-unused.deflate.decompressed",
|
||||
"degenerate-huffman.deflate.decompressed",
|
||||
.src_filename =
|
||||
"test/data/artificial-deflate/"
|
||||
"degenerate-huffman-unused.deflate",
|
||||
"degenerate-huffman.deflate",
|
||||
};
|
||||
|
||||
golden_test g_deflate_deflate_distance_32768_gt = {
|
||||
@@ -213,10 +213,10 @@ test_wuffs_deflate_decode_deflate_backref_crosses_blocks() {
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_deflate_decode_deflate_degenerate_huffman_unused() {
|
||||
test_wuffs_deflate_decode_deflate_degenerate_huffman() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_deflate_decode,
|
||||
&g_deflate_deflate_degenerate_huffman_unused_gt,
|
||||
&g_deflate_deflate_degenerate_huffman_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
@@ -722,10 +722,10 @@ test_mimic_deflate_decode_deflate_backref_crosses_blocks() {
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_deflate_decode_deflate_degenerate_huffman_unused() {
|
||||
test_mimic_deflate_decode_deflate_degenerate_huffman() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(mimic_deflate_decode,
|
||||
&g_deflate_deflate_degenerate_huffman_unused_gt,
|
||||
&g_deflate_deflate_degenerate_huffman_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
@@ -890,7 +890,7 @@ proc g_tests[] = {
|
||||
|
||||
test_wuffs_deflate_decode_256_bytes,
|
||||
test_wuffs_deflate_decode_deflate_backref_crosses_blocks,
|
||||
test_wuffs_deflate_decode_deflate_degenerate_huffman_unused,
|
||||
test_wuffs_deflate_decode_deflate_degenerate_huffman,
|
||||
test_wuffs_deflate_decode_deflate_distance_32768,
|
||||
test_wuffs_deflate_decode_deflate_distance_code_31,
|
||||
test_wuffs_deflate_decode_deflate_huffman_primlen_9,
|
||||
@@ -911,7 +911,7 @@ proc g_tests[] = {
|
||||
|
||||
test_mimic_deflate_decode_256_bytes,
|
||||
test_mimic_deflate_decode_deflate_backref_crosses_blocks,
|
||||
test_mimic_deflate_decode_deflate_degenerate_huffman_unused,
|
||||
test_mimic_deflate_decode_deflate_degenerate_huffman,
|
||||
test_mimic_deflate_decode_deflate_distance_32768,
|
||||
test_mimic_deflate_decode_deflate_distance_code_31,
|
||||
test_mimic_deflate_decode_deflate_huffman_primlen_9,
|
||||
|
||||
+11
-6
@@ -252,11 +252,6 @@ do_test_wuffs_gif_decode(const char* filename,
|
||||
|
||||
CHECK_STATUS("set_from_slice", wuffs_base__pixel_buffer__set_from_slice(
|
||||
&pb, &ic.pixcfg, g_pixel_slice_u8));
|
||||
|
||||
uint32_t have = wuffs_gif__decoder__num_animation_loops(&dec);
|
||||
if (have != 1) {
|
||||
RETURN_FAIL("num_animation_loops: have %" PRIu32 ", want 1", have);
|
||||
}
|
||||
}
|
||||
|
||||
int num_iters = 0;
|
||||
@@ -422,6 +417,16 @@ do_test_wuffs_gif_decode(const char* filename,
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
uint32_t have = wuffs_gif__decoder__num_animation_loops(&dec);
|
||||
uint32_t want =
|
||||
(wuffs_gif__decoder__num_decoded_frame_configs(&dec) > 1) ? 1 : 0;
|
||||
if (have != want) {
|
||||
RETURN_FAIL("num_animation_loops: have %" PRIu32 ", want %" PRIu32, have,
|
||||
want);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1510,7 +1515,7 @@ test_wuffs_gif_decode_multiple_loop_counts() {
|
||||
// loop counts are the number of animation loops *after* the first play
|
||||
// through, and Wuffs' are the number *including* the first play through.
|
||||
|
||||
uint32_t want_num_animation_loops[4] = {1, 1, 51, 31};
|
||||
uint32_t want_num_animation_loops[4] = {0, 1, 51, 31};
|
||||
|
||||
uint32_t i = 0;
|
||||
while (true) {
|
||||
|
||||
@@ -634,6 +634,71 @@ test_wuffs_png_decode_metadata_chrm_gama_srgb() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_png_decode_metadata_exif() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, "test/data/artificial-png/exif.png"));
|
||||
|
||||
wuffs_png__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_png__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
wuffs_png__decoder__set_report_metadata(&dec, WUFFS_BASE__FOURCC__EXIF, true);
|
||||
|
||||
wuffs_base__image_config ic = ((wuffs_base__image_config){});
|
||||
wuffs_base__io_buffer empty = wuffs_base__empty_io_buffer();
|
||||
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
|
||||
|
||||
wuffs_base__status status =
|
||||
wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
|
||||
if (status.repr != wuffs_base__note__metadata_reported) {
|
||||
RETURN_FAIL("decode_image_config #0: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__note__metadata_reported);
|
||||
}
|
||||
|
||||
status = wuffs_png__decoder__tell_me_more(&dec, &empty, &minfo, &src);
|
||||
if (status.repr != wuffs_base__suspension__even_more_information) {
|
||||
RETURN_FAIL("tell_me_more #0: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__suspension__even_more_information);
|
||||
}
|
||||
|
||||
// "hd test/data/artificial-png/exif.png" says 0x29..0x33 holds "LoremIpsum".
|
||||
wuffs_base__range_ie_u64 have =
|
||||
wuffs_base__more_information__metadata_raw_passthrough__range(&minfo);
|
||||
wuffs_base__range_ie_u64 want = wuffs_base__make_range_ie_u64(0x29, 0x33);
|
||||
if (!wuffs_base__range_ie_u64__equals(&have, want)) {
|
||||
RETURN_FAIL("range #0: have 0x%" PRIx64 "..0x%" PRIX64 ", want 0x%" PRIx64
|
||||
"..0x%" PRIX64,
|
||||
have.min_incl, have.max_excl, want.min_incl, want.max_excl);
|
||||
} else if ((src.meta.ri == 0x29) && (src.meta.wi >= 0x33)) {
|
||||
src.meta.ri = 0x33;
|
||||
}
|
||||
|
||||
status = wuffs_png__decoder__tell_me_more(&dec, &empty, &minfo, &src);
|
||||
if (status.repr != NULL) {
|
||||
RETURN_FAIL("tell_me_more #1: have \"%s\", want \"(null)\"", status.repr);
|
||||
}
|
||||
have = wuffs_base__more_information__metadata_raw_passthrough__range(&minfo);
|
||||
if (!wuffs_base__range_ie_u64__is_empty(&have)) {
|
||||
RETURN_FAIL("tell_me_more #1: non-empty range");
|
||||
}
|
||||
|
||||
status = wuffs_png__decoder__decode_image_config(&dec, &ic, &src);
|
||||
if (status.repr != NULL) {
|
||||
RETURN_FAIL("decode_image_config #1: have \"%s\", want \"(null)\"",
|
||||
status.repr);
|
||||
} else if (wuffs_base__pixel_config__width(&ic.pixcfg) != 1) {
|
||||
RETURN_FAIL("decode_image_config #1: have %" PRIu32 ", want 1",
|
||||
wuffs_base__pixel_config__width(&ic.pixcfg));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_png_decode_metadata_iccp() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -1201,6 +1266,7 @@ proc g_tests[] = {
|
||||
test_wuffs_png_decode_frame_config,
|
||||
test_wuffs_png_decode_interface,
|
||||
test_wuffs_png_decode_metadata_chrm_gama_srgb,
|
||||
test_wuffs_png_decode_metadata_exif,
|
||||
test_wuffs_png_decode_metadata_iccp,
|
||||
test_wuffs_png_decode_metadata_kvp,
|
||||
test_wuffs_png_decode_restart_frame,
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
// Copyright 2022 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
This test program is typically run indirectly, by the "wuffs test" or "wuffs
|
||||
bench" commands. These commands take an optional "-mimic" flag to check that
|
||||
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
|
||||
giflib for GIF, libpng for PNG, etc.
|
||||
|
||||
To manually run this test:
|
||||
|
||||
for CC in clang gcc; do
|
||||
$CC -std=c99 -Wall -Werror tga.c && ./a.out
|
||||
rm -f a.out
|
||||
done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__TGA
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../testlib/testlib.c"
|
||||
#ifdef WUFFS_MIMIC
|
||||
// No mimic library.
|
||||
#endif
|
||||
|
||||
// ---------------- TGA Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_tga_decode_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_tga__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_tga__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__image_decoder(
|
||||
wuffs_tga__decoder__upcast_as__wuffs_base__image_decoder(&dec),
|
||||
"test/data/bricks-color.tga", 0, SIZE_MAX, 160, 120, 0xFF022460);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- TGA Benches
|
||||
|
||||
// No TGA benches.
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_tga_decode_interface,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic tests.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
// No TGA benches.
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/tga";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
@@ -71,6 +71,11 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
|
||||
// ---------------- Golden Tests
|
||||
|
||||
golden_test g_deflate_romeo_gt = {
|
||||
.want_filename = "test/data/romeo.txt",
|
||||
.src_filename = "test/data/romeo.txt.deflate",
|
||||
};
|
||||
|
||||
golden_test g_zlib_midsummer_gt = {
|
||||
.want_filename = "test/data/midsummer.txt",
|
||||
.src_filename = "test/data/midsummer.txt.zlib",
|
||||
@@ -107,6 +112,42 @@ test_wuffs_zlib_decode_interface() {
|
||||
"test/data/romeo.txt.zlib", 0, SIZE_MAX, 942, 0x0A);
|
||||
}
|
||||
|
||||
const char* //
|
||||
wuffs_raw_deflate_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
wuffs_zlib__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
|
||||
// This wuffs_zlib__decoder__set_quirk_enabled call is the only difference
|
||||
// between wuffs_raw_deflate_decode and wuffs_zlib_decode immediately below.
|
||||
wuffs_zlib__decoder__set_quirk_enabled(
|
||||
&dec, WUFFS_ZLIB__QUIRK_JUST_RAW_DEFLATE, true);
|
||||
|
||||
while (true) {
|
||||
wuffs_base__io_buffer limited_dst = make_limited_writer(*dst, wlimit);
|
||||
wuffs_base__io_buffer limited_src = make_limited_reader(*src, rlimit);
|
||||
|
||||
wuffs_base__status status = wuffs_zlib__decoder__transform_io(
|
||||
&dec, &limited_dst, &limited_src, g_work_slice_u8);
|
||||
|
||||
dst->meta.wi += limited_dst.meta.wi;
|
||||
src->meta.ri += limited_src.meta.ri;
|
||||
|
||||
if (((wlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_write)) ||
|
||||
((rlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_read))) {
|
||||
continue;
|
||||
}
|
||||
return status.repr;
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
wuffs_zlib_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
@@ -240,6 +281,13 @@ test_wuffs_zlib_decode_pi() {
|
||||
UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_zlib_decode_raw_deflate_romeo() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_io_buffers(wuffs_raw_deflate_decode, &g_deflate_romeo_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_zlib_decode_sheep() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -376,6 +424,7 @@ proc g_tests[] = {
|
||||
test_wuffs_zlib_decode_interface,
|
||||
test_wuffs_zlib_decode_midsummer,
|
||||
test_wuffs_zlib_decode_pi,
|
||||
test_wuffs_zlib_decode_raw_deflate_romeo,
|
||||
test_wuffs_zlib_decode_sheep,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
@@ -422,7 +422,7 @@ test_main(int argc, char** argv, proc* tests, proc* benches) {
|
||||
"compatible with the\n"
|
||||
"# https://godoc.org/golang.org/x/perf/cmd/benchstat tool. To install "
|
||||
"it, first\n"
|
||||
"# install Go, then run \"go get golang.org/x/perf/cmd/benchstat\".\n");
|
||||
"# install Go, then run \"go install golang.org/x/perf/cmd/benchstat\".\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < reps; i++) {
|
||||
|
||||
@@ -11,6 +11,7 @@ ImageMagick's `convert` command line tool. The `*.wbmp` versions were generated
|
||||
by the `script/convert-png-to-wbmp.go` command line tool. The `*.webp` versions
|
||||
were generated by the cwebp command line tool. The `*.no-ancillary.png` files
|
||||
were generated by the `script/strip-png-ancillary-chunks.go` command line tool.
|
||||
The `*.qoi` files were generated by the qoiconv command line tool.
|
||||
|
||||
The `*.apng` files were generated by `gif2apng`. Those with finite animation
|
||||
loop counts were manually patched to correct for a `gif2apng` bug.
|
||||
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
foo
|
||||
@@ -1,27 +0,0 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make deflate
|
||||
|
||||
blockDynamicHuffman (final) {
|
||||
huffman CodeLength {
|
||||
1 00
|
||||
2 01
|
||||
17 10
|
||||
18 11
|
||||
}
|
||||
|
||||
huffman Literal/Length {
|
||||
# 102='f', 111='o', 256=EOB
|
||||
111 0
|
||||
102 10
|
||||
256 11
|
||||
}
|
||||
|
||||
huffman Distance {
|
||||
# Incomplete. There is no key/value pair whose value starts with "1".
|
||||
0 0
|
||||
}
|
||||
|
||||
literal "foo"
|
||||
endOfBlock
|
||||
}
|
||||
Binary file not shown.
+8
-5
@@ -1,9 +1,9 @@
|
||||
Running degenerate-huffman-unused.deflate through script/print-bits.go and
|
||||
adding commentary:
|
||||
Running degenerate-huffman.deflate through script/print-bits.go and adding
|
||||
commentary:
|
||||
|
||||
offset xoffset ASCII hex binary
|
||||
000000 0x0000 . 0x05 0b_...._.101 Dynamic Huffman block, final
|
||||
000000 0x0000 . 0x05 0b_0000_0... NumLCodes: 257
|
||||
000000 0x0000 . 0x04 0b_...._.100 Dynamic Huffman block, non-final
|
||||
000000 0x0000 . 0x04 0b_0000_0... NumLCodes: 257
|
||||
000001 0x0001 . 0xC0 0b_...0_0000 NumDCodes: 1
|
||||
000001 0x0001 . 0xC0 0b_110._.... NumCLCodeLengths: 18
|
||||
000002 0x0002 ! 0x21 0b_...._...1
|
||||
@@ -63,4 +63,7 @@ Apply H-L and H-D.
|
||||
000013 0x000D . 0x89 0b_..0._.... lcode: 111 literal 'o'
|
||||
000013 0x000D . 0x89 0b_.0.._.... lcode: 111 literal 'o'
|
||||
000013 0x000D . 0x89 0b_1..._.... lcode: 256 end of block
|
||||
000014 0x000E . 0x01 0b_...._...1
|
||||
000014 0x000E . 0x1B 0b_...._...1
|
||||
|
||||
The second Dynamic Huffman block (the final one) continues after that, but this
|
||||
commentary stops here.
|
||||
@@ -0,0 +1 @@
|
||||
fooABCDABC
|
||||
@@ -0,0 +1,66 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make deflate
|
||||
|
||||
blockDynamicHuffman (nonFinal) {
|
||||
huffman CodeLength {
|
||||
1 00
|
||||
2 01
|
||||
17 10
|
||||
18 11
|
||||
}
|
||||
|
||||
huffman Literal/Length {
|
||||
# 102='f', 111='o', 256=EOB
|
||||
111 0
|
||||
102 10
|
||||
256 11
|
||||
}
|
||||
|
||||
huffman Distance {
|
||||
# Incomplete. There is no key/value pair whose value starts with "1".
|
||||
#
|
||||
# The sole key/value pair is also unused. (The one below is used.)
|
||||
0 0
|
||||
incomplete
|
||||
}
|
||||
|
||||
literal "foo"
|
||||
endOfBlock
|
||||
}
|
||||
|
||||
blockDynamicHuffman (final) {
|
||||
huffman CodeLength {
|
||||
0 00
|
||||
1 01
|
||||
2 100
|
||||
3 101
|
||||
17 110
|
||||
18 111
|
||||
}
|
||||
|
||||
huffman Literal/Length {
|
||||
# 65='A', 66='B', 67='C', 68='D', 256=EOB, 257=Length3
|
||||
256 00
|
||||
257 01
|
||||
65 100
|
||||
66 101
|
||||
67 110
|
||||
68 111
|
||||
}
|
||||
|
||||
huffman Distance {
|
||||
# Incomplete. There is no key/value pair whose value starts with "1".
|
||||
#
|
||||
# The sole key/value pair is also used. (The one above is unused.)
|
||||
#
|
||||
# Per the second table in RFC 1951 section 3.2.5. "Compressed blocks
|
||||
# (length and distance codes)", code 3 means a distance of 4.
|
||||
3 0
|
||||
incomplete
|
||||
}
|
||||
|
||||
literal "ABCD"
|
||||
len 3 dist 4
|
||||
endOfBlock
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 93 B |
@@ -0,0 +1,32 @@
|
||||
# Feed this file to script/make-artificial.go
|
||||
|
||||
make png
|
||||
|
||||
magic
|
||||
|
||||
IHDR {
|
||||
raw {
|
||||
# Width, height.
|
||||
0x00 0x00 0x00 0x01
|
||||
0x00 0x00 0x00 0x01
|
||||
# Depth, color, compression, filter, interlace.
|
||||
0x08 0x00 0x00 0x00 0x00
|
||||
}
|
||||
}
|
||||
|
||||
eXIf {
|
||||
raw {
|
||||
# "LoremIpsum" isn't valid EXIF data. It's just a placeholder.
|
||||
0x4C 0x6F 0x72 0x65 0x6D 0x49 0x70 0x73 0x75 0x6D
|
||||
}
|
||||
}
|
||||
|
||||
IDAT {
|
||||
zlib {
|
||||
# 1x1 gray pixels (with filter bytes).
|
||||
0x00 0x80
|
||||
}
|
||||
}
|
||||
|
||||
IEND {
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
Binary file not shown.
Binary file not shown.
@@ -9,64 +9,69 @@ e651a889 test/data/animated-red-blue.000002.nie
|
||||
f9a10dac test/data/artificial-gif/background-color.gif
|
||||
36e7d9c7 test/data/artificial-gif/empty-palette.gif
|
||||
db4c30eb test/data/artificial-gif/frame-out-of-bounds.gif
|
||||
fdcc644f test/data/artificial-gif/metadata-empty.gif
|
||||
fdcc644f test/data/artificial-gif/metadata-full.gif
|
||||
6d03b5f3 test/data/artificial-gif/multiple-graphic-controls.gif
|
||||
47c877fd test/data/artificial-gif/multiple-loop-counts.gif
|
||||
76c44866 test/data/artificial-gif/no-frames.gif
|
||||
6ec818c3 test/data/artificial-gif/pixel-data-none.gif
|
||||
5e57adb2 test/data/artificial-gif/pixel-data-not-enough.gif
|
||||
3e29f88a test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif
|
||||
3e29f88a test/data/artificial-gif/pixel-data-too-much-good-lzw.gif
|
||||
f50d1d50 test/data/artificial-gif/small-frame-interlaced.gif
|
||||
f2dc2c43 test/data/artificial-gif/metadata-empty.gif
|
||||
f2dc2c43 test/data/artificial-gif/metadata-full.gif
|
||||
a1a9b56d test/data/artificial-gif/multiple-graphic-controls.gif
|
||||
046a2d07 test/data/artificial-gif/multiple-loop-counts.gif
|
||||
ba6e48f8 test/data/artificial-gif/no-frames.gif
|
||||
f33b9bc1 test/data/artificial-gif/pixel-data-none.gif
|
||||
ac9d76d8 test/data/artificial-gif/pixel-data-not-enough.gif
|
||||
2342e3fc test/data/artificial-gif/pixel-data-too-much-bad-lzw.gif
|
||||
2342e3fc test/data/artificial-gif/pixel-data-too-much-good-lzw.gif
|
||||
39a71dce test/data/artificial-gif/small-frame-interlaced.gif
|
||||
beaec397 test/data/artificial-gif/transparent-index.gif
|
||||
6ec818c3 test/data/artificial-gif/zero-width-frame.gif
|
||||
f33b9bc1 test/data/artificial-gif/zero-width-frame.gif
|
||||
0564b364 test/data/artificial-png/apng-skip-idat.png
|
||||
e08a7cc8 test/data/artificial-png/exif.png
|
||||
e08a7cc8 test/data/artificial-png/key-value-pairs.png
|
||||
076cb375 test/data/bricks-color.bmp
|
||||
076cb375 test/data/bricks-color.png
|
||||
076cb375 test/data/bricks-color.tga
|
||||
f36c2e80 test/data/bricks-dither.bmp
|
||||
3fc62e1e test/data/bricks-dither.gif
|
||||
f36c2e80 test/data/bricks-dither.gif
|
||||
f36c2e80 test/data/bricks-dither.no-ancillary.png
|
||||
f36c2e80 test/data/bricks-dither.png
|
||||
c2bce675 test/data/bricks-gray.bmp
|
||||
0e16e6eb test/data/bricks-gray.gif
|
||||
c2bce675 test/data/bricks-gray.gif
|
||||
c2bce675 test/data/bricks-gray.no-ancillary.png
|
||||
c2bce675 test/data/bricks-gray.png
|
||||
c2bce675 test/data/bricks-gray.tga
|
||||
7aebfe6c test/data/bricks-nodither.bmp
|
||||
b641fef2 test/data/bricks-nodither.gif
|
||||
7aebfe6c test/data/bricks-nodither.gif
|
||||
7aebfe6c test/data/bricks-nodither.png
|
||||
7aebfe6c test/data/bricks-nodither.tga
|
||||
ae2e547d test/data/bricks-nodither.wbmp
|
||||
b47730a2 test/data/checkerboard.gamma1dot0.png
|
||||
b47730a2 test/data/checkerboard.gamma2dot2.png
|
||||
aa3e6c7c test/data/crude-flag.nie
|
||||
3014b4c0 test/data/gifplayer-muybridge.gif
|
||||
030f5a48 test/data/harvesters.bmp
|
||||
0d213dc4 test/data/harvesters.gif
|
||||
c18b3d5a test/data/harvesters.gif
|
||||
030f5a48 test/data/harvesters.png
|
||||
e776c90f test/data/hat.bmp
|
||||
a161a63a test/data/hat.gif
|
||||
6dcba6a4 test/data/hat.gif
|
||||
e776c90f test/data/hat.png
|
||||
d30bfe5d test/data/hat.wbmp
|
||||
33a44f22 test/data/hibiscus.primitive.bmp
|
||||
e948122d test/data/hibiscus.primitive.gif
|
||||
25e212b3 test/data/hibiscus.primitive.gif
|
||||
33a44f22 test/data/hibiscus.primitive.png
|
||||
60040742 test/data/hibiscus.regular.bmp
|
||||
7b8dda15 test/data/hibiscus.regular.gif
|
||||
b727da8b test/data/hibiscus.regular.gif
|
||||
60040742 test/data/hibiscus.regular.png
|
||||
dcbb225a test/data/hippopotamus.bmp
|
||||
21e17862 test/data/hippopotamus.interlaced.gif
|
||||
ed4b78fc test/data/hippopotamus.interlaced.gif
|
||||
dcbb225a test/data/hippopotamus.interlaced.png
|
||||
a80781a1 test/data/hippopotamus.interlaced.truncated.gif
|
||||
1f11edb9 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
|
||||
d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
|
||||
7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
|
||||
dcbb225a test/data/hippopotamus.nie
|
||||
21e17862 test/data/hippopotamus.regular.gif
|
||||
ed4b78fc test/data/hippopotamus.regular.gif
|
||||
dcbb225a test/data/hippopotamus.regular.png
|
||||
2dccfe56 test/data/muybridge-frame-000.wbmp
|
||||
db2733f5 test/data/muybridge.apng
|
||||
db2733f5 test/data/muybridge.gif
|
||||
bf7e8c96 test/data/pjw-thumbnail.bmp
|
||||
73d48c08 test/data/pjw-thumbnail.gif
|
||||
bf7e8c96 test/data/pjw-thumbnail.gif
|
||||
bf7e8c96 test/data/pjw-thumbnail.png
|
||||
38cb4cbf test/data/red-blue-gradient.dcip3d65-no-chrm-no-gama.png
|
||||
38cb4cbf test/data/red-blue-gradient.gamma1dot0.png
|
||||
|
||||
Reference in new issue
Block a user