std/nie: support premultiplied alpha formats
diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c
index 5c2cdf8..3f4d94b 100644
--- a/release/c/wuffs-unsupported-snapshot.c
+++ b/release/c/wuffs-unsupported-snapshot.c
@@ -12813,7 +12813,6 @@
extern const char wuffs_nie__error__bad_frame[];
extern const char wuffs_nie__error__bad_header[];
extern const char wuffs_nie__error__truncated_input[];
-extern const char wuffs_nie__error__unsupported_nie_file[];
extern const char wuffs_nie__error__unsupported_restart_frame_index[];
// ---------------- Public Consts
@@ -66756,7 +66755,6 @@
const char wuffs_nie__error__bad_frame[] = "#nie: bad frame";
const char wuffs_nie__error__bad_header[] = "#nie: bad header";
const char wuffs_nie__error__truncated_input[] = "#nie: truncated input";
-const char wuffs_nie__error__unsupported_nie_file[] = "#nie: unsupported NIE file";
const char wuffs_nie__error__unsupported_restart_frame_index[] = "#nie: unsupported restart frame index";
const char wuffs_nie__note__internal_note_short_read[] = "@nie: internal note: short read";
@@ -67125,11 +67123,9 @@
} else if (v_a == 946758399u) {
self->private_impl.f_pixfmt = 2164308923u;
} else if (v_a == 879780607u) {
- status = wuffs_base__make_status(wuffs_nie__error__unsupported_nie_file);
- goto exit;
+ self->private_impl.f_pixfmt = 2181073032u;
} else if (v_a == 946889471u) {
- status = wuffs_base__make_status(wuffs_nie__error__unsupported_nie_file);
- goto exit;
+ self->private_impl.f_pixfmt = 2181086139u;
} else {
status = wuffs_base__make_status(wuffs_nie__error__bad_header);
goto exit;
@@ -67672,7 +67668,7 @@
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
- if (self->private_impl.f_pixfmt == 2164308923u) {
+ if ((self->private_impl.f_pixfmt == 2164308923u) || (self->private_impl.f_pixfmt == 2181086139u)) {
v_src_bytes_per_pixel = 8u;
} else {
v_src_bytes_per_pixel = 4u;
@@ -67967,7 +67963,7 @@
v_i = (((uint64_t)(self->private_impl.f_dst_x)) * ((uint64_t)(v_dst_bytes_per_pixel)));
if (v_i >= ((uint64_t)(v_dst.len))) {
v_src_bytes_per_pixel = 4u;
- if (self->private_impl.f_pixfmt == 2164308923u) {
+ if ((self->private_impl.f_pixfmt == 2164308923u) || (self->private_impl.f_pixfmt == 2181086139u)) {
v_src_bytes_per_pixel = 8u;
}
v_n = (((uint64_t)(io2_a_src - iop_a_src)) / ((uint64_t)(v_src_bytes_per_pixel)));
diff --git a/std/nie/decode_nie.wuffs b/std/nie/decode_nie.wuffs
index a818a8a..fd4e858 100644
--- a/std/nie/decode_nie.wuffs
+++ b/std/nie/decode_nie.wuffs
@@ -11,7 +11,6 @@
pub status "#bad frame"
pub status "#bad header"
pub status "#truncated input"
-pub status "#unsupported NIE file"
pub status "#unsupported restart frame index"
pri status "@internal note: short read"
@@ -88,9 +87,9 @@
} else if a == '\xFFbn8'le {
this.pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
} else if a == '\xFFbp4'le {
- return "#unsupported NIE file"
+ this.pixfmt = base.PIXEL_FORMAT__BGRA_PREMUL
} else if a == '\xFFbp8'le {
- return "#unsupported NIE file"
+ this.pixfmt = base.PIXEL_FORMAT__BGRA_PREMUL_4X16LE
} else {
return "#bad header"
}
@@ -229,7 +228,8 @@
pri func decoder.skip_frame?(src: base.io_reader) {
var src_bytes_per_pixel : base.u64[..= 8]
- if this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE {
+ if (this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE) or
+ (this.pixfmt == base.PIXEL_FORMAT__BGRA_PREMUL_4X16LE) {
src_bytes_per_pixel = 8
} else {
src_bytes_per_pixel = 4
@@ -356,7 +356,8 @@
if i >= dst.length() {
src_bytes_per_pixel = 4
assert src_bytes_per_pixel > 0
- if this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE {
+ if (this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE) or
+ (this.pixfmt == base.PIXEL_FORMAT__BGRA_PREMUL_4X16LE) {
src_bytes_per_pixel = 8
assert src_bytes_per_pixel > 0
}
diff --git a/test/data/49.bn4.nie b/test/data/49.bn4.nie
new file mode 100644
index 0000000..b31fde9
--- /dev/null
+++ b/test/data/49.bn4.nie
Binary files differ
diff --git a/test/data/49.bn8.nie b/test/data/49.bn8.nie
new file mode 100644
index 0000000..920f7ad
--- /dev/null
+++ b/test/data/49.bn8.nie
Binary files differ
diff --git a/test/data/49.bp4.nie b/test/data/49.bp4.nie
new file mode 100644
index 0000000..7bd3967
--- /dev/null
+++ b/test/data/49.bp4.nie
Binary files differ
diff --git a/test/data/49.bp8.nie b/test/data/49.bp8.nie
new file mode 100644
index 0000000..5955a34
--- /dev/null
+++ b/test/data/49.bp8.nie
Binary files differ
diff --git a/test/data/README.md b/test/data/README.md
index 4c7173b..dad20c1 100644
--- a/test/data/README.md
+++ b/test/data/README.md
@@ -39,7 +39,8 @@
---
`36.png` and `49.png` are simple, artificially generated images. The generation
-script is `gen-36-49.go` from https://github.com/nigeltao/etc2
+script is `gen-36-49.go` from https://github.com/nigeltao/etc2 and the
+`49.*.nie` variants were generated from a customized version of that script.
`DCI-P3-D65.icc` comes from
[color.org](https://www.color.org/chardata/rgb/DCIP3.xalter).
diff --git a/test/nia-checksums-of-data.txt b/test/nia-checksums-of-data.txt
index 792b5de..12ca826 100644
--- a/test/nia-checksums-of-data.txt
+++ b/test/nia-checksums-of-data.txt
@@ -1,5 +1,9 @@
# Generated by script/print-nia-checksums.sh
OK. 9720c028 test/data/36.png
+OK. c3528d19 test/data/49.bn4.nie
+OK. c3528d19 test/data/49.bn8.nie
+OK. e3bae566 test/data/49.bp4.nie
+OK. c3528d19 test/data/49.bp8.nie
OK. f2a0a3f6 test/data/49.png
OK. d3bb0beb test/data/DCI-P3-D65.icc
OK. 646e081a test/data/animated-red-blue.000000.nie