diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 639c7580..14aee5c1 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -1408,12 +1408,12 @@ typedef struct { uint8_t f_gc_transparent_index; uint8_t f_gc_disposal; uint64_t f_gc_duration; + uint32_t f_frame_rect_x0; + uint32_t f_frame_rect_y0; + uint32_t f_frame_rect_x1; + uint32_t f_frame_rect_y1; uint32_t f_dst_x; uint32_t f_dst_y; - uint32_t f_dst_x0; - uint32_t f_dst_y0; - uint32_t f_dst_x1; - uint32_t f_dst_y1; uint32_t f_uncompressed_ri; uint32_t f_uncompressed_wi; uint8_t f_uncompressed[4096]; @@ -3347,7 +3347,7 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part0( *scratch |= ((uint64_t)(t_0)) << 56; } } - self->private_impl.f_dst_x0 = ((uint32_t)(t_1)); + self->private_impl.f_frame_rect_x0 = ((uint32_t)(t_1)); } { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); @@ -3375,7 +3375,7 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part0( *scratch |= ((uint64_t)(t_2)) << 56; } } - self->private_impl.f_dst_y0 = ((uint32_t)(t_3)); + self->private_impl.f_frame_rect_y0 = ((uint32_t)(t_3)); } { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); @@ -3403,8 +3403,8 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part0( *scratch |= ((uint64_t)(t_4)) << 56; } } - self->private_impl.f_dst_x1 = - (self->private_impl.f_dst_x0 + ((uint32_t)(t_5))); + self->private_impl.f_frame_rect_x1 = + (self->private_impl.f_frame_rect_x0 + ((uint32_t)(t_5))); } { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7); @@ -3432,16 +3432,16 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part0( *scratch |= ((uint64_t)(t_6)) << 56; } } - self->private_impl.f_dst_y1 = - (self->private_impl.f_dst_y0 + ((uint32_t)(t_7))); + self->private_impl.f_frame_rect_y1 = + (self->private_impl.f_frame_rect_y0 + ((uint32_t)(t_7))); } - self->private_impl.f_dst_x = self->private_impl.f_dst_x0; - self->private_impl.f_dst_y = self->private_impl.f_dst_y0; + self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; + self->private_impl.f_dst_y = self->private_impl.f_frame_rect_y0; if (self->private_impl.f_call_sequence == 0) { self->private_impl.f_width = wuffs_base__u32__max( - self->private_impl.f_width, self->private_impl.f_dst_x1); + self->private_impl.f_width, self->private_impl.f_frame_rect_x1); self->private_impl.f_height = wuffs_base__u32__max( - self->private_impl.f_height, self->private_impl.f_dst_y1); + self->private_impl.f_height, self->private_impl.f_frame_rect_y1); } goto ok; @@ -3743,9 +3743,10 @@ static wuffs_base__status wuffs_gif__decoder__decode_id_part1( wuffs_base__image_buffer__update( a_dst, wuffs_base__utility__make_rect_ie_u32( - &self->private_impl.f_util, self->private_impl.f_dst_x0, - self->private_impl.f_dst_y0, self->private_impl.f_dst_x1, - self->private_impl.f_dst_y1), + &self->private_impl.f_util, self->private_impl.f_frame_rect_x0, + self->private_impl.f_frame_rect_y0, + self->private_impl.f_frame_rect_x1, + self->private_impl.f_frame_rect_y1), self->private_impl.f_gc_duration, true, self->private_impl.f_gc_disposal, v_palette); self->private_impl.f_previous_use_global_palette = @@ -3819,19 +3820,19 @@ label_0_continue:; .len = 4096}), self->private_impl.f_uncompressed_ri, self->private_impl.f_uncompressed_wi); - if (self->private_impl.f_dst_y >= self->private_impl.f_dst_y1) { + if (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) { status = WUFFS_GIF__ERROR_TOO_MUCH_PIXEL_DATA; goto exit; } v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y); if (((uint64_t)(self->private_impl.f_dst_x)) < ((uint64_t)(v_dst.len))) { if ((((uint64_t)(self->private_impl.f_dst_x)) <= - ((uint64_t)(self->private_impl.f_dst_x1))) && - (((uint64_t)(self->private_impl.f_dst_x1)) <= + ((uint64_t)(self->private_impl.f_frame_rect_x1))) && + (((uint64_t)(self->private_impl.f_frame_rect_x1)) <= ((uint64_t)(v_dst.len)))) { v_dst = wuffs_base__slice_u8__subslice_ij( v_dst, ((uint64_t)(self->private_impl.f_dst_x)), - ((uint64_t)(self->private_impl.f_dst_x1))); + ((uint64_t)(self->private_impl.f_frame_rect_x1))); } else { v_dst = wuffs_base__slice_u8__subslice_i( v_dst, ((uint64_t)(self->private_impl.f_dst_x))); @@ -3844,17 +3845,18 @@ label_0_continue:; wuffs_base__u32__min(v_new_ri, 4096); wuffs_base__u32__sat_add_indirect(&self->private_impl.f_dst_x, v_n); } - if (self->private_impl.f_dst_x1 <= self->private_impl.f_dst_x) { - self->private_impl.f_dst_x = self->private_impl.f_dst_x0; + if (self->private_impl.f_frame_rect_x1 <= self->private_impl.f_dst_x) { + self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; wuffs_base__u32__sat_add_indirect( &self->private_impl.f_dst_y, ((uint32_t)( wuffs_gif__interlace_delta[self->private_impl.f_interlace]))); - while ((self->private_impl.f_interlace > 0) && - (self->private_impl.f_dst_y >= self->private_impl.f_dst_y1)) { + while ( + (self->private_impl.f_interlace > 0) && + (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) { self->private_impl.f_interlace -= 1; self->private_impl.f_dst_y = wuffs_base__u32__sat_add( - self->private_impl.f_dst_y0, + self->private_impl.f_frame_rect_y0, wuffs_gif__interlace_start[self->private_impl.f_interlace]); } goto label_0_continue; @@ -3867,24 +3869,25 @@ label_0_continue:; status = WUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_RI_WI; goto exit; } - v_n = (self->private_impl.f_dst_x1 - self->private_impl.f_dst_x); + v_n = (self->private_impl.f_frame_rect_x1 - self->private_impl.f_dst_x); v_n = wuffs_base__u32__min(v_n, (self->private_impl.f_uncompressed_wi - self->private_impl.f_uncompressed_ri)); v_new_ri = wuffs_base__u32__sat_add(self->private_impl.f_uncompressed_ri, v_n); self->private_impl.f_uncompressed_ri = wuffs_base__u32__min(v_new_ri, 4096); wuffs_base__u32__sat_add_indirect(&self->private_impl.f_dst_x, v_n); - if (self->private_impl.f_dst_x1 <= self->private_impl.f_dst_x) { - self->private_impl.f_dst_x = self->private_impl.f_dst_x0; + if (self->private_impl.f_frame_rect_x1 <= self->private_impl.f_dst_x) { + self->private_impl.f_dst_x = self->private_impl.f_frame_rect_x0; wuffs_base__u32__sat_add_indirect( &self->private_impl.f_dst_y, ((uint32_t)( wuffs_gif__interlace_delta[self->private_impl.f_interlace]))); - while ((self->private_impl.f_interlace > 0) && - (self->private_impl.f_dst_y >= self->private_impl.f_dst_y1)) { + while ( + (self->private_impl.f_interlace > 0) && + (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) { self->private_impl.f_interlace -= 1; self->private_impl.f_dst_y = wuffs_base__u32__sat_add( - self->private_impl.f_dst_y0, + self->private_impl.f_frame_rect_y0, wuffs_gif__interlace_start[self->private_impl.f_interlace]); } goto label_0_continue; diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index f853d1f0..f2aa79a2 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -1408,12 +1408,12 @@ typedef struct { uint8_t f_gc_transparent_index; uint8_t f_gc_disposal; uint64_t f_gc_duration; + uint32_t f_frame_rect_x0; + uint32_t f_frame_rect_y0; + uint32_t f_frame_rect_x1; + uint32_t f_frame_rect_y1; uint32_t f_dst_x; uint32_t f_dst_y; - uint32_t f_dst_x0; - uint32_t f_dst_y0; - uint32_t f_dst_x1; - uint32_t f_dst_y1; uint32_t f_uncompressed_ri; uint32_t f_uncompressed_wi; uint8_t f_uncompressed[4096]; diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index ad9ab267..725ff0a0 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -79,13 +79,14 @@ pub struct decoder?( // There are 7056000 flicks per centisecond. gc_duration base.u64[..0xFFFF * 7056000], + frame_rect_x0 base.u32, + frame_rect_y0 base.u32, + frame_rect_x1 base.u32, + frame_rect_y1 base.u32, + // The dst_etc fields are the output cursor during copy_to_image_buffer. dst_x base.u32, dst_y base.u32, - dst_x0 base.u32, - dst_y0 base.u32, - dst_x1 base.u32, - dst_y1 base.u32, uncompressed_ri base.u32[..4096], uncompressed_wi base.u32[..4096], @@ -381,12 +382,12 @@ pri func decoder.decode_gc?(src base.io_reader)() { // overall image's width and height also requires decoding the first frame's // bounds (but doesn't require decoding the first frame's pixels). pri func decoder.decode_id_part0?(src base.io_reader)() { - this.dst_x0 = in.src.read_u16le?() as base.u32 - this.dst_y0 = in.src.read_u16le?() as base.u32 - this.dst_x1 = this.dst_x0 ~mod+ (in.src.read_u16le?() as base.u32) - this.dst_y1 = this.dst_y0 ~mod+ (in.src.read_u16le?() as base.u32) - this.dst_x = this.dst_x0 - this.dst_y = this.dst_y0 + this.frame_rect_x0 = in.src.read_u16le?() as base.u32 + this.frame_rect_y0 = in.src.read_u16le?() as base.u32 + this.frame_rect_x1 = this.frame_rect_x0 ~mod+ (in.src.read_u16le?() as base.u32) + this.frame_rect_y1 = this.frame_rect_y0 ~mod+ (in.src.read_u16le?() as base.u32) + this.dst_x = this.frame_rect_x0 + this.dst_y = this.frame_rect_y0 // Set the image's overall width and height to be the maximum of the // nominal image width and height (given in the Logical Screen Descriptor) @@ -394,8 +395,8 @@ pri func decoder.decode_id_part0?(src base.io_reader)() { // test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt for // more discussion. if this.call_sequence == 0 { - this.width = this.width.max(x:this.dst_x1) - this.height = this.height.max(x:this.dst_y1) + this.width = this.width.max(x:this.frame_rect_x1) + this.height = this.height.max(x:this.frame_rect_y1) } } @@ -529,10 +530,10 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader) // palette update is necessary. } in.dst.update!(dirty_rect:this.util.make_rect_ie_u32( - min_inclusive_x:this.dst_x0, - min_inclusive_y:this.dst_y0, - max_exclusive_x:this.dst_x1, - max_exclusive_y:this.dst_y1), + min_inclusive_x:this.frame_rect_x0, + min_inclusive_y:this.frame_rect_y0, + max_exclusive_x:this.frame_rect_x1, + max_exclusive_y:this.frame_rect_y1), duration:this.gc_duration, blend:true, disposal:this.gc_disposal, palette:palette) this.previous_use_global_palette = not (use_local_palette or this.gc_has_transparent_index) @@ -560,7 +561,7 @@ pri func decoder.copy_to_image_buffer?(ib ptr base.image_buffer)() { assert this.uncompressed_ri < this.uncompressed_wi via "a < b: b > a"() src = this.uncompressed[this.uncompressed_ri:this.uncompressed_wi] - if this.dst_y >= this.dst_y1 { + if this.dst_y >= this.frame_rect_y1 { return error "too much pixel data" } @@ -569,10 +570,10 @@ pri func decoder.copy_to_image_buffer?(ib ptr base.image_buffer)() { dst = tab.row(y:this.dst_y) if (this.dst_x as base.u64) < dst.length() { - if ((this.dst_x as base.u64) <= (this.dst_x1 as base.u64)) and - ((this.dst_x1 as base.u64) <= dst.length()) { + if ((this.dst_x as base.u64) <= (this.frame_rect_x1 as base.u64)) and + ((this.frame_rect_x1 as base.u64) <= dst.length()) { // TODO: drop the "as base.u64"s on the next line? - dst = dst[this.dst_x as base.u64:this.dst_x1 as base.u64] + dst = dst[this.dst_x as base.u64:this.frame_rect_x1 as base.u64] } else { dst = dst[this.dst_x as base.u64:] } @@ -583,12 +584,12 @@ pri func decoder.copy_to_image_buffer?(ib ptr base.image_buffer)() { this.dst_x ~sat+= n } - if this.dst_x1 <= this.dst_x { - this.dst_x = this.dst_x0 + if this.frame_rect_x1 <= this.dst_x { + this.dst_x = this.frame_rect_x0 this.dst_y ~sat+= interlace_delta[this.interlace] as base.u32 - while (this.interlace > 0) and (this.dst_y >= this.dst_y1) { + while (this.interlace > 0) and (this.dst_y >= this.frame_rect_y1) { this.interlace -= 1 - this.dst_y = this.dst_y0 ~sat+ interlace_start[this.interlace] + this.dst_y = this.frame_rect_y0 ~sat+ interlace_start[this.interlace] } continue } @@ -603,19 +604,19 @@ pri func decoder.copy_to_image_buffer?(ib ptr base.image_buffer)() { // outside in.ib's bounds. This second step should be infrequent. // Set n to the number of pixels (i.e. the number of bytes) to skip. - n = this.dst_x1 - this.dst_x + n = this.frame_rect_x1 - this.dst_x n = n.min(x:this.uncompressed_wi - this.uncompressed_ri) new_ri = this.uncompressed_ri ~sat+ n this.uncompressed_ri = new_ri.min(x:4096) this.dst_x ~sat+= n - if this.dst_x1 <= this.dst_x { - this.dst_x = this.dst_x0 + if this.frame_rect_x1 <= this.dst_x { + this.dst_x = this.frame_rect_x0 this.dst_y ~sat+= interlace_delta[this.interlace] as base.u32 - while (this.interlace > 0) and (this.dst_y >= this.dst_y1) { + while (this.interlace > 0) and (this.dst_y >= this.frame_rect_y1) { this.interlace -= 1 - this.dst_y = this.dst_y0 ~sat+ interlace_start[this.interlace] + this.dst_y = this.frame_rect_y0 ~sat+ interlace_start[this.interlace] } continue }