From 67a05d1e25a3829ab6ff5eb85b793a7022d064f6 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 24 Dec 2020 14:25:57 +1100 Subject: [PATCH] Have std/png io_bind the workbuf --- release/c/wuffs-unsupported-snapshot.c | 42 +++++++++++++++++++++++--- std/png/decode_png.wuffs | 12 +++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index e61e476c..796477fa 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -8093,6 +8093,7 @@ struct wuffs_png__decoder__struct { uint32_t f_width; uint32_t f_height; uint64_t f_bytes_per_row; + uint64_t f_workbuf_index; uint64_t f_workbuf_length; uint8_t f_call_sequence; uint8_t f_depth; @@ -30011,6 +30012,13 @@ wuffs_png__decoder__decode_frame( self->private_impl.active_coroutine = 0; wuffs_base__status status = wuffs_base__make_status(NULL); + wuffs_base__io_buffer u_w = wuffs_base__empty_io_buffer(); + wuffs_base__io_buffer* v_w = &u_w; + uint8_t* iop_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io0_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io1_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + uint8_t* io2_v_w WUFFS_BASE__POTENTIALLY_UNUSED = NULL; + const uint8_t* iop_a_src = NULL; const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL; @@ -30043,12 +30051,38 @@ wuffs_png__decoder__decode_frame( status = wuffs_base__make_status(wuffs_base__note__end_of_data); goto ok; } + self->private_impl.f_workbuf_index = 0; while (true) { + if ((self->private_impl.f_workbuf_index >= self->private_impl.f_workbuf_length) || (self->private_impl.f_workbuf_length >= ((uint64_t)(a_workbuf.len)))) { + status = wuffs_base__make_status(wuffs_base__error__bad_workbuf_length); + goto exit; + } { - const uint8_t *o_0_io2_a_src = io2_a_src; - wuffs_base__io_reader__limit(&io2_a_src, iop_a_src, - ((uint64_t)(self->private_impl.f_chunk_length))); - io2_a_src = o_0_io2_a_src; + wuffs_base__io_buffer* o_0_v_w = v_w; + uint8_t *o_0_iop_v_w = iop_v_w; + uint8_t *o_0_io0_v_w = io0_v_w; + uint8_t *o_0_io1_v_w = io1_v_w; + uint8_t *o_0_io2_v_w = io2_v_w; + v_w = wuffs_base__io_writer__set( + &u_w, + &iop_v_w, + &io0_v_w, + &io1_v_w, + &io2_v_w, + wuffs_base__slice_u8__subslice_ij(a_workbuf, + self->private_impl.f_workbuf_index, + self->private_impl.f_workbuf_length)); + { + const uint8_t *o_1_io2_a_src = io2_a_src; + wuffs_base__io_reader__limit(&io2_a_src, iop_a_src, + ((uint64_t)(self->private_impl.f_chunk_length))); + io2_a_src = o_1_io2_a_src; + } + v_w = o_0_v_w; + iop_v_w = o_0_iop_v_w; + io0_v_w = o_0_io0_v_w; + io1_v_w = o_0_io1_v_w; + io2_v_w = o_0_io2_v_w; } goto label__0__break; } diff --git a/std/png/decode_png.wuffs b/std/png/decode_png.wuffs index f99be8e8..1d6459d3 100644 --- a/std/png/decode_png.wuffs +++ b/std/png/decode_png.wuffs @@ -26,6 +26,7 @@ pub struct decoder? implements base.image_decoder( // bytes_per_row doesn't include the 1 byte for the per-row filter. bytes_per_row : base.u64[..= 0x07FF_FFF8], + workbuf_index : base.u64, workbuf_length : base.u64[..= 0x0007_FFFF_F100_0007], // Call sequence states: @@ -223,6 +224,8 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_ } 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) { + var w : base.io_writer + if this.call_sequence < 4 { this.decode_frame_config?(dst: nullptr, src: args.src) } else if this.call_sequence == 4 { @@ -231,8 +234,15 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, return base."@end of data" } + this.workbuf_index = 0 while true { - io_limit (io: args.src, limit: this.chunk_length as base.u64) { + if (this.workbuf_index >= this.workbuf_length) or ( + this.workbuf_length >= args.workbuf.length()) { + return base."#bad workbuf length" + } + io_bind (io: w, data: args.workbuf[this.workbuf_index .. this.workbuf_length]) { + io_limit (io: args.src, limit: this.chunk_length as base.u64) { + } } break } endwhile