From aaebb17a0183b750954e082700da5ad18de6c75e Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 5 Oct 2019 11:45:14 +1000 Subject: [PATCH] Tweak how std/gif does interlace row replication --- release/c/wuffs-unsupported-snapshot.c | 28 ++++++++++++-------------- std/gif/decode_gif.wuffs | 19 ++++++++--------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index bdd505e3..9dcb62ad 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -8625,7 +8625,7 @@ static const uint8_t // static const uint8_t // wuffs_gif__interlace_count[5] // WUFFS_BASE__POTENTIALLY_UNUSED = { - 0, 0, 1, 3, 7, + 0, 1, 2, 4, 8, }; static const uint8_t // @@ -11112,7 +11112,8 @@ wuffs_gif__decoder__copy_to_image_buffer(wuffs_gif__decoder* self, wuffs_base__table_u8 v_tab = {0}; uint64_t v_i = 0; uint64_t v_j = 0; - uint32_t v_replicate_count = 0; + uint32_t v_replicate_y0 = 0; + uint32_t v_replicate_y1 = 0; wuffs_base__slice_u8 v_replicate_dst = {0}; wuffs_base__slice_u8 v_replicate_src = {0}; @@ -11174,25 +11175,22 @@ label_0_continue:; if ((self->private_impl.f_num_decoded_frames_value == 0) && !self->private_impl.f_gc_has_transparent_index && (self->private_impl.f_interlace > 1)) { - v_replicate_count = ((uint32_t)( - wuffs_gif__interlace_count[self->private_impl.f_interlace])); v_replicate_src = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y); - while (v_replicate_count > 0) { - v_replicate_dst = wuffs_base__table_u8__row( - v_tab, wuffs_base__u32__sat_add(self->private_impl.f_dst_y, - v_replicate_count)); + v_replicate_y0 = + wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1); + v_replicate_y1 = wuffs_base__u32__sat_add( + self->private_impl.f_dst_y, + ((uint32_t)( + wuffs_gif__interlace_count[self->private_impl.f_interlace]))); + while (v_replicate_y0 < v_replicate_y1) { + v_replicate_dst = wuffs_base__table_u8__row(v_tab, v_replicate_y0); wuffs_base__slice_u8__copy_from_slice(v_replicate_dst, v_replicate_src); - v_replicate_count -= 1; + v_replicate_y0 += 1; } self->private_impl.f_dirty_max_excl_y = wuffs_base__u32__max( - self->private_impl.f_dirty_max_excl_y, - wuffs_base__u32__sat_add( - self->private_impl.f_dst_y, - (((uint32_t)(wuffs_gif__interlace_count[self->private_impl - .f_interlace])) + - 1))); + self->private_impl.f_dirty_max_excl_y, v_replicate_y1); } wuffs_base__u32__sat_add_indirect( &self->private_impl.f_dst_y, diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 83e6d255..c06f21ab 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -118,7 +118,7 @@ pub const quirk_reject_empty_palette base.u32 = (0xF8586 << 10) | 6 // to that maximum value (and therefore outside the frame rect). pri const interlace_start array[5] base.u32 = [0xFFFFFFFF, 1, 2, 4, 0] pri const interlace_delta array[5] base.u8 = [1, 2, 4, 8, 8] -pri const interlace_count array[5] base.u8 = [0, 0, 1, 3, 7] +pri const interlace_count array[5] base.u8 = [0, 1, 2, 4, 8] pub struct decoder?( width base.u32, @@ -1104,7 +1104,8 @@ pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base. var tab table base.u8 var i base.u64 var j base.u64 - var replicate_count base.u32 + var replicate_y0 base.u32 + var replicate_y1 base.u32 var replicate_dst slice base.u8 var replicate_src slice base.u8 @@ -1178,16 +1179,16 @@ pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base. (not this.gc_has_transparent_index) and (this.interlace > 1) { - replicate_count = interlace_count[this.interlace] as base.u32 replicate_src = tab.row(y:this.dst_y) - while replicate_count > 0 { - replicate_dst = tab.row(y:this.dst_y ~sat+ replicate_count) + replicate_y0 = this.dst_y ~sat+ 1 + replicate_y1 = this.dst_y ~sat+ (interlace_count[this.interlace] as base.u32) + while replicate_y0 < replicate_y1 { + assert replicate_y0 < 0xFFFFFFFF via "a < b: a < c; c <= b"(c:replicate_y1) + replicate_dst = tab.row(y:replicate_y0) replicate_dst.copy_from_slice!(s:replicate_src) - replicate_count -= 1 + replicate_y0 += 1 } - - this.dirty_max_excl_y = this.dirty_max_excl_y.max( - a:this.dst_y ~sat+ ((interlace_count[this.interlace] as base.u32) + 1)) + this.dirty_max_excl_y = this.dirty_max_excl_y.max(a:replicate_y1) } this.dst_y ~sat+= interlace_delta[this.interlace] as base.u32