From f43afd8236d5a9435b5096a0b5425687f204ff98 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 26 May 2018 11:27:38 +1000 Subject: [PATCH] Add a (table T).row method --- cmd/wuffs-c/internal/cgen/builtin.go | 9 +++++++++ gen/c/std/gif.c | 13 ++++++++++--- gen/h/std/gif.h | 2 ++ lang/builtin/builtin.go | 1 + lang/token/list.go | 8 +++++--- std/gif/decode_gif.wuffs | 13 +++++++++++-- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/cmd/wuffs-c/internal/cgen/builtin.go b/cmd/wuffs-c/internal/cgen/builtin.go index cf34d468..674ca92c 100644 --- a/cmd/wuffs-c/internal/cgen/builtin.go +++ b/cmd/wuffs-c/internal/cgen/builtin.go @@ -332,6 +332,15 @@ func (g *gen) writeBuiltinTable(b *buffer, recv *a.Expr, method t.ID, args []*a. } b.writeb(')') return nil + + case t.IDRow: + // TODO: don't assume that the table is a table of base.u8. + b.writes("wuffs_base__table_u8__row(") + if err := g.writeExpr(b, recv, rp, depth); err != nil { + return err + } + b.writeb(',') + return g.writeArgs(b, args, rp, depth) } if field != "" { diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index ff75538c..01e6d088 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -1283,6 +1283,8 @@ typedef struct { uint8_t f_gc_disposal; uint64_t f_gc_duration; wuffs_base__rect_ie_u32 f_frame_rect; + uint32_t f_dst_x; + uint32_t f_dst_y; uint32_t f_uncompressed_ri; uint32_t f_uncompressed_wi; uint8_t f_uncompressed[4096]; @@ -3185,6 +3187,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part0( &self->private_impl.f_frame_rect, v_frame_x); wuffs_base__rect_ie_u32__set_min_inclusive_y( &self->private_impl.f_frame_rect, v_frame_y); + self->private_impl.f_dst_x = v_frame_x; + self->private_impl.f_dst_y = v_frame_y; { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); uint16_t t_5; @@ -3609,14 +3613,17 @@ short_read_src: static void wuffs_gif__decoder__copy_to_image_buffer( wuffs_gif__decoder* self, wuffs_base__image_buffer* a_ib) { + wuffs_base__slice_u8 v_dst; wuffs_base__table_u8 v_tab; - wuffs_base__slice_u8 v_pixel_data; + v_dst = ((wuffs_base__slice_u8){}); v_tab = wuffs_base__image_buffer__plane(a_ib, 0); if (((uint64_t)(v_tab.width)) == ((uint64_t)(v_tab.stride))) { - v_pixel_data = wuffs_base__table_u8__linearize(v_tab); - if (((uint64_t)(v_pixel_data.len)) == 0) { + v_dst = wuffs_base__table_u8__linearize(v_tab); + if (((uint64_t)(v_dst.len)) == 0) { } + } else { + v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y); } } diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index 69ee905f..a464582a 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -1283,6 +1283,8 @@ typedef struct { uint8_t f_gc_disposal; uint64_t f_gc_duration; wuffs_base__rect_ie_u32 f_frame_rect; + uint32_t f_dst_x; + uint32_t f_dst_y; uint32_t f_uncompressed_ri; uint32_t f_uncompressed_wi; uint8_t f_uncompressed[4096]; diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go index 5da3a114..cbafdf3a 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -200,4 +200,5 @@ var TableFuncs = []string{ "T2.width()(ret u64)", "T2.linearize()(ret T1)", + "T2.row(y u32)(ret T1)", } diff --git a/lang/token/list.go b/lang/token/list.go index 3ee0c5e2..337afce7 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -491,9 +491,10 @@ const ( IDLength = ID(0x242) IDLinearize = ID(0x243) IDPrefix = ID(0x244) - IDStride = ID(0x245) - IDSuffix = ID(0x246) - IDWidth = ID(0x247) + IDRow = ID(0x245) + IDStride = ID(0x246) + IDSuffix = ID(0x247) + IDWidth = ID(0x248) ) var builtInsByID = [nBuiltInIDs]string{ @@ -713,6 +714,7 @@ var builtInsByID = [nBuiltInIDs]string{ IDLength: "length", IDLinearize: "linearize", IDPrefix: "prefix", + IDRow: "row", IDStride: "stride", IDSuffix: "suffix", IDWidth: "width", diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index dc9a8598..e4d71611 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -57,6 +57,10 @@ pub struct decoder?( frame_rect base.rect_ie_u32, + // The dst_etc fields are the output cursor during copy_to_image_buffer. + dst_x base.u32, + dst_y base.u32, + uncompressed_ri base.u32[..4096], uncompressed_wi base.u32[..4096], uncompressed array[4096] base.u8, @@ -329,6 +333,9 @@ pri func decoder.decode_id_part0?(src base.io_reader)() { var frame_y base.u32 = in.src.read_u16le?() as base.u32 this.frame_rect.set_min_inclusive_x!(x:frame_x) this.frame_rect.set_min_inclusive_y!(y:frame_y) + this.dst_x = frame_x + this.dst_y = frame_y + frame_x ~mod+= in.src.read_u16le?() as base.u32 frame_y ~mod+= in.src.read_u16le?() as base.u32 this.frame_rect.set_max_exclusive_x!(x:frame_x) @@ -491,13 +498,15 @@ pri func decoder.decode_id_part1?(ib ptr base.image_buffer, dst base.io_writer, pri func decoder.copy_to_image_buffer(ib ptr base.image_buffer)() { // TODO: don't assume a packed pixel format. + var dst slice base.u8 var tab table base.u8 = in.ib.plane(p:0) if tab.width() == tab.stride() { - var pixel_data slice base.u8 = tab.linearize() - if pixel_data.length() == 0 { + dst = tab.linearize() + if dst.length() == 0 { // TODO. } } else { + dst = tab.row(y:this.dst_y) // TODO. } }