From c6aebf819f4349db53d20601b0d2d09fc91c33a7 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 9 Jul 2024 16:50:58 +1000 Subject: [PATCH] std/webp: re-implement 8-bit color indexing --- release/c/wuffs-unsupported-snapshot.c | 20 ++++++++++++++++++++ std/webp/decode_transform.wuffs | 14 ++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 65718a6f..f157315c 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -71438,6 +71438,26 @@ wuffs_webp__decoder__apply_transform_color_indexing( v_tile_size_log2 = ((uint32_t)(self->private_impl.f_transform_tile_size_log2[3u])); if (v_tile_size_log2 == 0u) { + { + wuffs_base__slice_u8 i_slice_dst = a_pix; + v_dst.ptr = i_slice_dst.ptr; + v_dst.len = 4; + const uint8_t* i_end0_dst = wuffs_private_impl__ptr_u8_plus_len(v_dst.ptr, (((i_slice_dst.len - (size_t)(v_dst.ptr - i_slice_dst.ptr)) / 4) * 4)); + while (v_dst.ptr < i_end0_dst) { + v_p = (((uint32_t)(v_dst.ptr[1u])) * 4u); + v_p0 = self->private_data.f_palette[(v_p + 0u)]; + v_p1 = self->private_data.f_palette[(v_p + 1u)]; + v_p2 = self->private_data.f_palette[(v_p + 2u)]; + v_p3 = self->private_data.f_palette[(v_p + 3u)]; + v_dst.ptr[0u] = v_p0; + v_dst.ptr[1u] = v_p1; + v_dst.ptr[2u] = v_p2; + v_dst.ptr[3u] = v_p3; + v_dst.ptr += 4; + } + v_dst.len = 0; + } + return wuffs_base__make_empty_struct(); } v_bits_per_pixel = (((uint32_t)(8u)) >> v_tile_size_log2); v_x_mask = ((((uint32_t)(1u)) << v_tile_size_log2) - 1u); diff --git a/std/webp/decode_transform.wuffs b/std/webp/decode_transform.wuffs index dae5be31..c883a708 100644 --- a/std/webp/decode_transform.wuffs +++ b/std/webp/decode_transform.wuffs @@ -379,8 +379,18 @@ pri func decoder.apply_transform_color_indexing!(pix: slice base.u8) { tile_size_log2 = this.transform_tile_size_log2[3] as base.u32 if tile_size_log2 == 0 { - // TODO: the code below is correct, but we could possibly simplify the - // case where the src and dst pixel counts are 1:1. + iterate (dst = args.pix)(length: 4, advance: 4, unroll: 1) { + p = (dst[1] as base.u32) * 4 + p0 = this.palette[p + 0] + p1 = this.palette[p + 1] + p2 = this.palette[p + 2] + p3 = this.palette[p + 3] + dst[0] = p0 + dst[1] = p1 + dst[2] = p2 + dst[3] = p3 + } + return nothing } bits_per_pixel = (8 as base.u32) >> tile_size_log2