Fix std/png Paeth filter for the top row
diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c
index d66fb17..e80aa47 100644
--- a/release/c/wuffs-unsupported-snapshot.c
+++ b/release/c/wuffs-unsupported-snapshot.c
@@ -30872,6 +30872,10 @@
if (self->private_impl.f_workbuf_wi != self->private_impl.f_workbuf_length) {
status = wuffs_base__make_status(wuffs_base__error__not_enough_data);
goto exit;
+ } else if (0 < ((uint64_t)(a_workbuf.len))) {
+ if (a_workbuf.ptr[0] == 4) {
+ a_workbuf.ptr[0] = 1;
+ }
}
v_swizzler_status = wuffs_base__pixel_swizzler__prepare(&self->private_impl.f_swizzler,
wuffs_base__pixel_buffer__pixel_format(a_dst),
diff --git a/std/png/decode_png.wuffs b/std/png/decode_png.wuffs
index 3a66889..6298704 100644
--- a/std/png/decode_png.wuffs
+++ b/std/png/decode_png.wuffs
@@ -365,7 +365,15 @@
if this.workbuf_wi <> this.workbuf_length {
return base."#not enough data"
+ } else if 0 < args.workbuf.length() {
+ // For the top row, the Paeth filter (4) is equivalent to the Sub
+ // filter (1), but the Paeth implementation is simpler if it can assume
+ // that there is a previous row.
+ if args.workbuf[0] == 4 {
+ args.workbuf[0] = 1
+ }
}
+
swizzler_status = this.swizzler.prepare!(
dst_pixfmt: args.dst.pixel_format(),
dst_palette: args.dst.palette_or_else(fallback: this.dst_palette[..]),