From f5c68a13cb6ea0dbe53dd0fa7a2df9369227be0b Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 20 Nov 2021 22:54:21 +1100 Subject: [PATCH] Fix std/png for depth-16 grayscale interlaced --- release/c/wuffs-unsupported-snapshot.c | 9 +++++++-- std/png/decode_png.wuffs | 10 ++++++++-- test/3pdata/nia-checksums-of-pngsuite.txt | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 96c0fb2f..a412641c 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -37751,8 +37751,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) { diff --git a/std/png/decode_png.wuffs b/std/png/decode_png.wuffs index a18d8a0c..93aba497 100644 --- a/std/png/decode_png.wuffs +++ b/std/png/decode_png.wuffs @@ -441,8 +441,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 } diff --git a/test/3pdata/nia-checksums-of-pngsuite.txt b/test/3pdata/nia-checksums-of-pngsuite.txt index 82cf12d3..fe5b7247 100644 --- a/test/3pdata/nia-checksums-of-pngsuite.txt +++ b/test/3pdata/nia-checksums-of-pngsuite.txt @@ -4,7 +4,7 @@ aac44167 test/3pdata/pngsuite/PngSuite.png 8f50bdc6 test/3pdata/pngsuite/basi0g02.png 6d612626 test/3pdata/pngsuite/basi0g04.png 024cf410 test/3pdata/pngsuite/basi0g08.png -5a525ac0 test/3pdata/pngsuite/basi0g16.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