diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 1cd4e564..a440682b 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -4236,11 +4236,14 @@ struct wuffs_wbmp__decoder__struct { uint32_t f_width; uint32_t f_height; - uint64_t f_frame_config_io_position; + uint8_t f_call_sequence; bool f_seen_frame; bool f_seen_frame_config; + uint64_t f_frame_config_io_position; uint32_t p_decode_image_config[1]; + uint32_t p_decode_frame_config[1]; + uint32_t p_decode_frame[1]; } private_impl; struct { @@ -13099,6 +13102,10 @@ wuffs_wbmp__decoder__decode_image_config(wuffs_wbmp__decoder* self, switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + if (self->private_impl.f_call_sequence != 0) { + status = wuffs_base__make_status(wuffs_base__error__bad_call_sequence); + goto exit; + } v_i = 0; while (v_i < 2) { { @@ -13157,6 +13164,7 @@ wuffs_wbmp__decoder__decode_image_config(wuffs_wbmp__decoder* self, self->private_impl.f_height, self->private_impl.f_frame_config_io_position, true); } + self->private_impl.f_call_sequence = 1; goto ok; ok: @@ -13213,8 +13221,51 @@ wuffs_wbmp__decoder__decode_frame_config(wuffs_wbmp__decoder* self, self->private_impl.active_coroutine = 0; wuffs_base__status status = wuffs_base__make_status(NULL); - goto ok; -ok: + uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0]; + if (coro_susp_point) { + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if (self->private_impl.f_call_sequence < 1) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_wbmp__decoder__decode_image_config(self, NULL, a_src); + if (status.repr) { + goto suspend; + } + } else if (self->private_impl.f_call_sequence == 1) { + } else if (self->private_impl.f_call_sequence == 2) { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } else { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } + if (a_dst != NULL) { + wuffs_base__frame_config__update( + a_dst, + wuffs_base__utility__make_rect_ie_u32( + 0, 0, self->private_impl.f_width, self->private_impl.f_height), + ((wuffs_base__flicks)(0)), 0, + self->private_impl.f_frame_config_io_position, 0, true, false, + 4278190080); + } + self->private_impl.f_seen_frame_config = true; + self->private_impl.f_call_sequence = 2; + + goto ok; + ok: + self->private_impl.p_decode_frame_config[0] = 0; + goto exit; + } + + goto suspend; +suspend: + self->private_impl.p_decode_frame_config[0] = + wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.active_coroutine = + wuffs_base__status__is_suspension(&status) ? 2 : 0; + goto exit; exit: if (wuffs_base__status__is_error(&status)) { @@ -13254,8 +13305,39 @@ wuffs_wbmp__decoder__decode_frame(wuffs_wbmp__decoder* self, self->private_impl.active_coroutine = 0; wuffs_base__status status = wuffs_base__make_status(NULL); - goto ok; -ok: + uint32_t coro_susp_point = self->private_impl.p_decode_frame[0]; + if (coro_susp_point) { + } + switch (coro_susp_point) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + + if (self->private_impl.f_call_sequence < 2) { + WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); + status = wuffs_wbmp__decoder__decode_frame_config(self, NULL, a_src); + if (status.repr) { + goto suspend; + } + } else if (self->private_impl.f_call_sequence == 2) { + } else { + status = wuffs_base__make_status(wuffs_base__note__end_of_data); + goto ok; + } + self->private_impl.f_seen_frame = true; + self->private_impl.f_call_sequence = 3; + + goto ok; + ok: + self->private_impl.p_decode_frame[0] = 0; + goto exit; + } + + goto suspend; +suspend: + self->private_impl.p_decode_frame[0] = + wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0; + self->private_impl.active_coroutine = + wuffs_base__status__is_suspension(&status) ? 3 : 0; + goto exit; exit: if (wuffs_base__status__is_error(&status)) { @@ -13420,9 +13502,10 @@ wuffs_wbmp__decoder__restart_frame(wuffs_wbmp__decoder* self, if (a_index != 0) { return wuffs_base__make_status(wuffs_base__error__bad_argument); } - self->private_impl.f_frame_config_io_position = a_io_position; + self->private_impl.f_call_sequence = 1; self->private_impl.f_seen_frame = false; self->private_impl.f_seen_frame_config = false; + self->private_impl.f_frame_config_io_position = a_io_position; return wuffs_base__make_status(NULL); } diff --git a/std/wbmp/decode_wbmp.wuffs b/std/wbmp/decode_wbmp.wuffs index 71aa3699..1114b8d0 100644 --- a/std/wbmp/decode_wbmp.wuffs +++ b/std/wbmp/decode_wbmp.wuffs @@ -20,9 +20,11 @@ pub struct decoder? implements base.image_decoder( width : base.u32, height : base.u32, - frame_config_io_position : base.u64, + call_sequence : base.u8, + seen_frame : base.bool, seen_frame_config : base.bool, + frame_config_io_position : base.u64, util : base.utility, ) @@ -33,6 +35,10 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_ var x32 : base.u32 var x64 : base.u64 + if this.call_sequence <> 0 { + return base."#bad call sequence" + } + // TypeField, FixHeaderField. i = 0 while i < 2 { @@ -84,12 +90,54 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_ first_frame_io_position: this.frame_config_io_position, first_frame_is_opaque: true) } + + this.call_sequence = 1 } pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_reader) { + if this.call_sequence < 1 { + this.decode_image_config?(dst: nullptr, src: args.src) + } else if this.call_sequence == 1 { + // No-op. + } else if this.call_sequence == 2 { + // TODO: skip frame. + return base."@end of data" + } else { + return base."@end of data" + } + + if args.dst <> nullptr { + args.dst.update!(bounds: this.util.make_rect_ie_u32( + min_incl_x: 0, + min_incl_y: 0, + max_excl_x: this.width, + max_excl_y: this.height), + duration: 0, + index: 0, + io_position: this.frame_config_io_position, + disposal: 0, + opaque_within_bounds: true, + overwrite_instead_of_blend: false, + background_color: 0xFF000000) + } + + this.seen_frame_config = true + this.call_sequence = 2 } pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, blend: base.pixel_blend, workbuf: slice base.u8, opts: nptr base.decode_frame_options) { + if this.call_sequence < 2 { + this.decode_frame_config?(dst: nullptr, src: args.src) + } else if this.call_sequence == 2 { + // No-op. + } else { + return base."@end of data" + } + + // TODO. + + this.seen_frame = true + this.call_sequence = 3 } pub func decoder.ack_metadata_chunk?(src: base.io_reader) { @@ -136,9 +184,10 @@ pub func decoder.restart_frame!(index: base.u64, io_position: base.u64) base.sta if args.index <> 0 { return base."#bad argument" } - this.frame_config_io_position = args.io_position + this.call_sequence = 1 this.seen_frame = false this.seen_frame_config = false + this.frame_config_io_position = args.io_position return ok }