From b4cd9b8d3cf255a92f1328f7790826f17af0a2d9 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 27 Mar 2024 21:06:09 +1100 Subject: [PATCH] std/png: decode PNG color type 4 to YA_NONPREMUL Fixes #143 --- release/c/wuffs-unsupported-snapshot.c | 17 +++-------------- std/png/decode_png.wuffs | 5 ++--- std/png/decode_swizzle_tricky.wuffs | 15 +-------------- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 7a9bbe59..9bd7f1d3 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -60644,11 +60644,9 @@ wuffs_png__decoder__assign_filter_distance( } } else if (self->private_impl.f_color_type == 4u) { if (self->private_impl.f_depth == 8u) { - self->private_impl.f_dst_pixfmt = 2164295816u; - self->private_impl.f_src_pixfmt = 2164295816u; + self->private_impl.f_dst_pixfmt = 553648264u; + self->private_impl.f_src_pixfmt = 553648264u; self->private_impl.f_filter_distance = 2u; - self->private_impl.choosy_filter_and_swizzle = ( - &wuffs_png__decoder__filter_and_swizzle_tricky); } else if (self->private_impl.f_depth == 16u) { self->private_impl.f_dst_pixfmt = 2164308923u; self->private_impl.f_src_pixfmt = 2164308923u; @@ -64347,16 +64345,7 @@ wuffs_png__decoder__filter_and_swizzle_tricky( while (v_x < self->private_impl.f_frame_rect_x1) { v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel); if (v_i <= ((uint64_t)(v_dst.len))) { - if (self->private_impl.f_color_type == 4u) { - if (2u <= ((uint64_t)(v_s.len))) { - v_bits_unpacked[0u] = v_s.ptr[0u]; - v_bits_unpacked[1u] = v_s.ptr[0u]; - v_bits_unpacked[2u] = v_s.ptr[0u]; - v_bits_unpacked[3u] = v_s.ptr[1u]; - v_s = wuffs_base__slice_u8__subslice_i(v_s, 2u); - wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 4)); - } - } else if (((uint32_t)(self->private_impl.f_remap_transparency)) != 0u) { + if (((uint32_t)(self->private_impl.f_remap_transparency)) != 0u) { if (self->private_impl.f_color_type == 0u) { if (1u <= ((uint64_t)(v_s.len))) { v_bits_unpacked[0u] = v_s.ptr[0u]; diff --git a/std/png/decode_png.wuffs b/std/png/decode_png.wuffs index 54932101..d18de834 100644 --- a/std/png/decode_png.wuffs +++ b/std/png/decode_png.wuffs @@ -455,10 +455,9 @@ pri func decoder.assign_filter_distance!() { } else if this.color_type == 4 { if this.depth == 8 { - this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL - this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL + this.dst_pixfmt = base.PIXEL_FORMAT__YA_NONPREMUL + this.src_pixfmt = base.PIXEL_FORMAT__YA_NONPREMUL this.filter_distance = 2 - choose filter_and_swizzle = [filter_and_swizzle_tricky] } else if this.depth == 16 { this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE diff --git a/std/png/decode_swizzle_tricky.wuffs b/std/png/decode_swizzle_tricky.wuffs index d99c6c96..4fed6f03 100644 --- a/std/png/decode_swizzle_tricky.wuffs +++ b/std/png/decode_swizzle_tricky.wuffs @@ -101,20 +101,7 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf: assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.frame_rect_x1) i = (x as base.u64) * dst_bytes_per_pixel if i <= dst.length() { - if this.color_type == 4 { - if 2 <= s.length() { - bits_unpacked[0] = s[0] - bits_unpacked[1] = s[0] - bits_unpacked[2] = s[0] - bits_unpacked[3] = s[1] - s = s[2 ..] - this.swizzler.swizzle_interleaved_from_slice!( - dst: dst[i ..], - dst_palette: dst_palette, - src: bits_unpacked[.. 4]) - } - - } else if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) <> 0 { + if ((this.remap_transparency & 0xFFFF_FFFF) as base.u32) <> 0 { if this.color_type == 0 { if 1 <= s.length() { bits_unpacked[0] = s[0]