diff --git a/cmd/wuffs-c/internal/cgen/base/base-private.h b/cmd/wuffs-c/internal/cgen/base/base-private.h index f5886bab..a628bf3d 100644 --- a/cmd/wuffs-c/internal/cgen/base/base-private.h +++ b/cmd/wuffs-c/internal/cgen/base/base-private.h @@ -736,26 +736,6 @@ wuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) { return ((wuffs_base__empty_struct){}); } -static inline uint32_t // -wuffs_base__frame_config__rect_x0(wuffs_base__frame_config* c) { - return c ? c->private_impl.bounds.min_incl_x : 0; -} - -static inline uint32_t // -wuffs_base__frame_config__rect_y0(wuffs_base__frame_config* c) { - return c ? c->private_impl.bounds.min_incl_y : 0; -} - -static inline uint32_t // -wuffs_base__frame_config__rect_x1(wuffs_base__frame_config* c) { - return c ? c->private_impl.bounds.max_excl_x : 0; -} - -static inline uint32_t // -wuffs_base__frame_config__rect_y1(wuffs_base__frame_config* c) { - return c ? c->private_impl.bounds.max_excl_y : 0; -} - #ifdef __cplusplus } // extern "C" #endif diff --git a/cmd/wuffs-c/internal/cgen/base/image-public.h b/cmd/wuffs-c/internal/cgen/base/image-public.h index b771ae0f..699c3274 100644 --- a/cmd/wuffs-c/internal/cgen/base/image-public.h +++ b/cmd/wuffs-c/internal/cgen/base/image-public.h @@ -665,8 +665,8 @@ wuffs_base__frame_config__index(wuffs_base__frame_config* c) { return c ? c->private_impl.index : 0; } -// wuffs_base__frame_config__io_position returns the I/O stream position after -// the frame config but before the frame's pixel data. +// wuffs_base__frame_config__io_position returns the I/O stream position before +// the frame config. static inline uint64_t // wuffs_base__frame_config__io_position(wuffs_base__frame_config* c) { return c ? c->private_impl.io_position : 0; diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index a3a86050..72d234ab 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -104,7 +104,7 @@ const baseBasePrivateH = "" + "tart++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n uint8_t** ptr_ioptr_r,\n uint8_t* iobounds1_r) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = length;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n uint8_t* ioptr_r = *ptr_ioptr_r;\n if (n > ((size_t)(iobounds1_r - ioptr_r))) {\n n = iobounds1_r - ioptr_r;\n }\n if (n > 0) {\n memmove(ioptr_w, ioptr_r, n);\n *ptr_ioptr_w += n;\n *ptr_ioptr_r += n;\n }\n return n;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n wuffs_base__slice_u8 src" + ") {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_limit(wuffs_base__io_reader* o,\n uint8_t* ioptr_r,\n uint64_t limit) {\n if (o && (((size_t)(o->private_im" + "pl.limit - ioptr_r)) > limit)) {\n o->private_impl.limit = ioptr_r + limit;\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set(wuffs_base__io_writer* o,\n wuffs_base__io_buffer* b,\n uint8_t** ioptr1_ptr,\n uint8_t** ioptr2_ptr,\n wuffs_base__slice_u8 s) {\n b->ptr = s.ptr;\n b->len = s.len;\n b->wi = 0;\n b->ri = 0;\n b->closed = false;\n o->private_impl.buf = b;\n o->private_impl.mark = s.ptr;\n o->private_impl.limit = s.ptr + s.len;\n *ioptr1_ptr = s.ptr;\n *ioptr2_ptr = s.ptr + s.len;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {\n o->p" + - "rivate_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__rect_x0(wuffs_base__frame_config* c) {\n return c ? c->private_impl.bounds.min_incl_x : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__rect_y0(wuffs_base__frame_config* c) {\n return c ? c->private_impl.bounds.min_incl_y : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__rect_x1(wuffs_base__frame_config* c) {\n return c ? c->private_impl.bounds.max_excl_x : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__rect_y1(wuffs_base__frame_config* c) {\n return c ? c->private_impl.bounds.max_excl_y : 0;\n}\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif // WUFFS_INCLUDE_GUARD__BASE_PRIVATE\n" + + "rivate_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif // WUFFS_INCLUDE_GUARD__BASE_PRIVATE\n" + "" const baseBaseImplC = "" + @@ -148,10 +148,10 @@ const baseImagePublicH = "" + "" + "// --------\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__rect_ie_u32 bounds;\n wuffs_base__flicks duration;\n uint64_t index;\n uint64_t io_position;\n wuffs_base__animation_blend blend;\n wuffs_base__animation_disposal disposal;\n } private_impl;\n\n#ifdef __cplusplus\n inline void update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal);\n inline wuffs_base__rect_ie_u32 bounds();\n inline uint32_t width();\n inline uint32_t height();\n inline wuffs_base__flicks duration();\n inline uint64_t index();\n inline uint64_t io_position();\n inline wuffs_base__animation_blend blend();\n inline wuffs_base__animation_disposal disposal();\n#endif // __cpluspl" + "us\n\n} wuffs_base__frame_config;\n\nstatic inline void //\nwuffs_base__frame_config__update(wuffs_base__frame_config* c,\n wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal) {\n if (!c) {\n return;\n }\n\n c->private_impl.bounds = bounds;\n c->private_impl.duration = duration;\n c->private_impl.index = index;\n c->private_impl.io_position = io_position;\n c->private_impl.blend = blend;\n c->private_impl.disposal = disposal;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__frame_config__bounds(wuffs_base__frame_config* c) {\n return c ? c->private_impl.bounds : ((wuffs_base__rect_ie_u32){});\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__width(wuffs_base__frame_config* c) {\n retur" + - "n c ? wuffs_base__rect_ie_u32__width(&c->private_impl.bounds) : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__height(wuffs_base__frame_config* c) {\n return c ? wuffs_base__rect_ie_u32__height(&c->private_impl.bounds) : 0;\n}\n\n// wuffs_base__frame_config__duration returns the amount of time to display\n// this frame. Zero means to display forever - a still (non-animated) image.\nstatic inline wuffs_base__flicks //\nwuffs_base__frame_config__duration(wuffs_base__frame_config* c) {\n return c ? c->private_impl.duration : 0;\n}\n\n// wuffs_base__frame_config__index returns the index of this frame. The first\n// frame in an image has index 0, the second frame has index 1, and so on.\nstatic inline uint64_t //\nwuffs_base__frame_config__index(wuffs_base__frame_config* c) {\n return c ? c->private_impl.index : 0;\n}\n\n// wuffs_base__frame_config__io_position returns the I/O stream position after\n// the frame config but before the frame's pixel data.\nstatic inline uint64_t //\nwuffs_base__frame_config__io_positio" + - "n(wuffs_base__frame_config* c) {\n return c ? c->private_impl.io_position : 0;\n}\n\n// wuffs_base__frame_config__blend returns, for an animated image, how to blend\n// the transparent pixels of this frame with the existing canvas.\nstatic inline wuffs_base__animation_blend //\nwuffs_base__frame_config__blend(wuffs_base__frame_config* c) {\n return c ? c->private_impl.blend : 0;\n}\n\n// wuffs_base__frame_config__disposal returns, for an animated image, how to\n// dispose of this frame after displaying it.\nstatic inline wuffs_base__animation_disposal //\nwuffs_base__frame_config__disposal(wuffs_base__frame_config* c) {\n return c ? c->private_impl.disposal : 0;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__frame_config::update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n " + - " wuffs_base__animation_disposal disposal) {\n wuffs_base__frame_config__update(this, bounds, duration, index, io_position,\n blend, disposal);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__frame_config::bounds() {\n return wuffs_base__frame_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::width() {\n return wuffs_base__frame_config__width(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::height() {\n return wuffs_base__frame_config__height(this);\n}\n\ninline wuffs_base__flicks //\nwuffs_base__frame_config::duration() {\n return wuffs_base__frame_config__duration(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::index() {\n return wuffs_base__frame_config__index(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::io_position() {\n return wuffs_base__frame_config__io_position(this);\n}\n\ninline wuffs_base__animation_blend //\nwuffs_base__frame_config::blend() {\n return wuffs_base__frame_config__blend(this);\n}\n\ninline wuffs_base__anim" + - "ation_disposal //\nwuffs_base__frame_config::disposal() {\n return wuffs_base__frame_config__disposal(this);\n}\n\n#endif // __cplusplus\n\n" + + "n c ? wuffs_base__rect_ie_u32__width(&c->private_impl.bounds) : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__height(wuffs_base__frame_config* c) {\n return c ? wuffs_base__rect_ie_u32__height(&c->private_impl.bounds) : 0;\n}\n\n// wuffs_base__frame_config__duration returns the amount of time to display\n// this frame. Zero means to display forever - a still (non-animated) image.\nstatic inline wuffs_base__flicks //\nwuffs_base__frame_config__duration(wuffs_base__frame_config* c) {\n return c ? c->private_impl.duration : 0;\n}\n\n// wuffs_base__frame_config__index returns the index of this frame. The first\n// frame in an image has index 0, the second frame has index 1, and so on.\nstatic inline uint64_t //\nwuffs_base__frame_config__index(wuffs_base__frame_config* c) {\n return c ? c->private_impl.index : 0;\n}\n\n// wuffs_base__frame_config__io_position returns the I/O stream position before\n// the frame config.\nstatic inline uint64_t //\nwuffs_base__frame_config__io_position(wuffs_base__frame_config* c) {\n" + + " return c ? c->private_impl.io_position : 0;\n}\n\n// wuffs_base__frame_config__blend returns, for an animated image, how to blend\n// the transparent pixels of this frame with the existing canvas.\nstatic inline wuffs_base__animation_blend //\nwuffs_base__frame_config__blend(wuffs_base__frame_config* c) {\n return c ? c->private_impl.blend : 0;\n}\n\n// wuffs_base__frame_config__disposal returns, for an animated image, how to\n// dispose of this frame after displaying it.\nstatic inline wuffs_base__animation_disposal //\nwuffs_base__frame_config__disposal(wuffs_base__frame_config* c) {\n return c ? c->private_impl.disposal : 0;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__frame_config::update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_dis" + + "posal disposal) {\n wuffs_base__frame_config__update(this, bounds, duration, index, io_position,\n blend, disposal);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__frame_config::bounds() {\n return wuffs_base__frame_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::width() {\n return wuffs_base__frame_config__width(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::height() {\n return wuffs_base__frame_config__height(this);\n}\n\ninline wuffs_base__flicks //\nwuffs_base__frame_config::duration() {\n return wuffs_base__frame_config__duration(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::index() {\n return wuffs_base__frame_config__index(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::io_position() {\n return wuffs_base__frame_config__io_position(this);\n}\n\ninline wuffs_base__animation_blend //\nwuffs_base__frame_config::blend() {\n return wuffs_base__frame_config__blend(this);\n}\n\ninline wuffs_base__animation_disposal //\nwuffs_base__fr" + + "ame_config::disposal() {\n return wuffs_base__frame_config__disposal(this);\n}\n\n#endif // __cplusplus\n\n" + "" + "// --------\n\ntypedef struct {\n wuffs_base__pixel_config pixcfg;\n\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX];\n uint8_t palette[1024];\n // TODO: color spaces.\n } private_impl;\n\n#ifdef __cplusplus\n inline wuffs_base__status set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory);\n inline void set_palette(wuffs_base__slice_u8 palette);\n inline wuffs_base__table_u8 plane(uint32_t p);\n inline wuffs_base__slice_u8 palette();\n#endif // __cplusplus\n\n} wuffs_base__pixel_buffer;\n\nstatic inline wuffs_base__status //\nwuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,\n wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n if (!b) {\n return wuffs_base_" + "_error__bad_receiver;\n }\n *b = ((wuffs_base__pixel_buffer){});\n if (!pixcfg) {\n return wuffs_base__error__bad_argument;\n }\n // TODO: don't assume 1 byte per pixel. Don't assume packed.\n uint64_t wh = ((uint64_t)pixcfg->private_impl.width) *\n ((uint64_t)pixcfg->private_impl.height);\n if (wh > pixbuf_memory.len) {\n return wuffs_base__error__bad_argument_length_too_short;\n }\n b->pixcfg = *pixcfg;\n wuffs_base__table_u8* tab = &b->private_impl.planes[0];\n tab->ptr = pixbuf_memory.ptr;\n tab->width = pixcfg->private_impl.width;\n tab->height = pixcfg->private_impl.height;\n tab->stride = pixcfg->private_impl.width;\n return NULL;\n}\n\n// The palette argument is ignored unless its length is exactly 1024.\nstatic inline void //\nwuffs_base__pixel_buffer__set_palette(wuffs_base__pixel_buffer* b,\n wuffs_base__slice_u8 palette) {\n if (b && palette.ptr && (palette.len == 1024)) {\n memmove(b->private_impl.palette, palette.ptr, 1024);\n }\n}\n\nstatic inlin" + diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go index e41718c1..2b834e46 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -239,12 +239,6 @@ var Funcs = []string{ "frame_config.update!(bounds rect_ie_u32, duration u64[..0x7FFFFFFFFFFFFFFF], " + "index u64, io_position u64, blend u8, disposal u8)", - // TODO: delete these hacks. - "frame_config.rect_x0() u32", - "frame_config.rect_y0() u32", - "frame_config.rect_x1() u32", - "frame_config.rect_y1() u32", - // ---- image_config "image_config.initialize!(pixfmt u32, pixsub u32, width u32, height u32, " + diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index 89e8eeb9..31025e3e 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -1769,8 +1769,8 @@ wuffs_base__frame_config__index(wuffs_base__frame_config* c) { return c ? c->private_impl.index : 0; } -// wuffs_base__frame_config__io_position returns the I/O stream position after -// the frame config but before the frame's pixel data. +// wuffs_base__frame_config__io_position returns the I/O stream position before +// the frame config. static inline uint64_t // wuffs_base__frame_config__io_position(wuffs_base__frame_config* c) { return c ? c->private_impl.io_position : 0; @@ -2417,6 +2417,7 @@ typedef struct { uint8_t f_gc_transparent_index; uint8_t f_gc_disposal; uint64_t f_gc_duration; + uint64_t f_frame_config_io_position; uint64_t f_num_decoded_frame_configs_value; uint64_t f_num_decoded_frames_value; uint32_t f_frame_rect_x0; @@ -2515,8 +2516,7 @@ typedef struct { inline uint64_t num_decoded_frame_configs(); inline uint64_t num_decoded_frames(); inline wuffs_base__range_ii_u64 work_buffer_size(); - inline wuffs_base__status reset_for_decode_frame( - wuffs_base__frame_config* a_fc); + inline wuffs_base__status reset_before(wuffs_base__frame_config* a_fc); inline wuffs_base__status decode_frame_config(wuffs_base__frame_config* a_dst, wuffs_base__io_reader a_src); inline wuffs_base__status decode_frame(wuffs_base__pixel_buffer* a_dst, @@ -2557,8 +2557,8 @@ WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 // wuffs_gif__decoder__work_buffer_size(wuffs_gif__decoder* self); WUFFS_BASE__MAYBE_STATIC wuffs_base__status // -wuffs_gif__decoder__reset_for_decode_frame(wuffs_gif__decoder* self, - wuffs_base__frame_config* a_fc); +wuffs_gif__decoder__reset_before(wuffs_gif__decoder* self, + wuffs_base__frame_config* a_fc); WUFFS_BASE__MAYBE_STATIC wuffs_base__status // wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self, @@ -2606,8 +2606,8 @@ wuffs_gif__decoder::work_buffer_size() { } inline wuffs_base__status // -wuffs_gif__decoder::reset_for_decode_frame(wuffs_base__frame_config* a_fc) { - return wuffs_gif__decoder__reset_for_decode_frame(this, a_fc); +wuffs_gif__decoder::reset_before(wuffs_base__frame_config* a_fc) { + return wuffs_gif__decoder__reset_before(this, a_fc); } inline wuffs_base__status // @@ -3595,26 +3595,6 @@ wuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) { return ((wuffs_base__empty_struct){}); } -static inline uint32_t // -wuffs_base__frame_config__rect_x0(wuffs_base__frame_config* c) { - return c ? c->private_impl.bounds.min_incl_x : 0; -} - -static inline uint32_t // -wuffs_base__frame_config__rect_y0(wuffs_base__frame_config* c) { - return c ? c->private_impl.bounds.min_incl_y : 0; -} - -static inline uint32_t // -wuffs_base__frame_config__rect_x1(wuffs_base__frame_config* c) { - return c ? c->private_impl.bounds.max_excl_x : 0; -} - -static inline uint32_t // -wuffs_base__frame_config__rect_y1(wuffs_base__frame_config* c) { - return c ? c->private_impl.bounds.max_excl_y : 0; -} - #ifdef __cplusplus } // extern "C" #endif @@ -6277,6 +6257,9 @@ static wuffs_base__status // wuffs_gif__decoder__skip_frame(wuffs_gif__decoder* self, wuffs_base__io_reader a_src); +static void // +wuffs_gif__decoder__reset_gc(wuffs_gif__decoder* self); + static wuffs_base__status // wuffs_gif__decoder__decode_up_to_id_part1(wuffs_gif__decoder* self, wuffs_base__io_reader a_src); @@ -6480,11 +6463,11 @@ wuffs_gif__decoder__work_buffer_size(wuffs_gif__decoder* self) { 0); } -// -------- func gif.decoder.reset_for_decode_frame +// -------- func gif.decoder.reset_before WUFFS_BASE__MAYBE_STATIC wuffs_base__status // -wuffs_gif__decoder__reset_for_decode_frame(wuffs_gif__decoder* self, - wuffs_base__frame_config* a_fc) { +wuffs_gif__decoder__reset_before(wuffs_gif__decoder* self, + wuffs_base__frame_config* a_fc) { if (!self) { return wuffs_base__error__bad_receiver; } @@ -6503,18 +6486,12 @@ wuffs_gif__decoder__reset_for_decode_frame(wuffs_gif__decoder* self, status = wuffs_base__error__bad_call_sequence; goto exit; } - self->private_impl.f_num_decoded_frame_configs_value = - wuffs_base__u64__sat_add(wuffs_base__frame_config__index(a_fc), 1); - self->private_impl.f_num_decoded_frames_value = - wuffs_base__frame_config__index(a_fc); - self->private_impl.f_frame_rect_x0 = wuffs_base__frame_config__rect_x0(a_fc); - self->private_impl.f_frame_rect_y0 = wuffs_base__frame_config__rect_y0(a_fc); - self->private_impl.f_frame_rect_x1 = wuffs_base__frame_config__rect_x1(a_fc); - self->private_impl.f_frame_rect_y1 = wuffs_base__frame_config__rect_y1(a_fc); - 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; self->private_impl.f_end_of_data = false; - self->private_impl.f_call_sequence = 2; + self->private_impl.f_num_decoded_frame_configs_value = + wuffs_base__frame_config__index(a_fc); + self->private_impl.f_num_decoded_frames_value = + self->private_impl.f_num_decoded_frame_configs_value; + wuffs_gif__decoder__reset_gc(self); goto exit; exit: if (wuffs_base__status__is_error(status)) { @@ -6541,22 +6518,6 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self, uint8_t v_blend; - uint8_t* iop_a_src = NULL; - uint8_t* io0_a_src = NULL; - uint8_t* io1_a_src = NULL; - WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src); - WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src); - if (a_src.private_impl.buf) { - iop_a_src = a_src.private_impl.buf->ptr + a_src.private_impl.buf->ri; - if (!a_src.private_impl.mark) { - a_src.private_impl.mark = iop_a_src; - a_src.private_impl.limit = - a_src.private_impl.buf->ptr + a_src.private_impl.buf->wi; - } - io0_a_src = a_src.private_impl.mark; - io1_a_src = a_src.private_impl.limit; - } - uint32_t coro_susp_point = self->private_impl.c_decode_frame_config[0].coro_susp_point; if (coro_susp_point) { @@ -6569,40 +6530,20 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self, if (!self->private_impl.f_end_of_data) { if (self->private_impl.f_call_sequence == 0) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); - if (a_src.private_impl.buf) { - a_src.private_impl.buf->ri = iop_a_src - a_src.private_impl.buf->ptr; - } status = wuffs_gif__decoder__decode_image_config(self, NULL, a_src); - if (a_src.private_impl.buf) { - iop_a_src = a_src.private_impl.buf->ptr + a_src.private_impl.buf->ri; - } if (status) { goto suspend; } } else if (self->private_impl.f_call_sequence != 1) { if (self->private_impl.f_call_sequence == 2) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); - if (a_src.private_impl.buf) { - a_src.private_impl.buf->ri = - iop_a_src - a_src.private_impl.buf->ptr; - } status = wuffs_gif__decoder__skip_frame(self, a_src); - if (a_src.private_impl.buf) { - iop_a_src = - a_src.private_impl.buf->ptr + a_src.private_impl.buf->ri; - } if (status) { goto suspend; } } WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - if (a_src.private_impl.buf) { - a_src.private_impl.buf->ri = iop_a_src - a_src.private_impl.buf->ptr; - } status = wuffs_gif__decoder__decode_up_to_id_part1(self, a_src); - if (a_src.private_impl.buf) { - iop_a_src = a_src.private_impl.buf->ptr + a_src.private_impl.buf->ri; - } if (status) { goto suspend; } @@ -6626,11 +6567,8 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self, self->private_impl.f_frame_rect_y1), self->private_impl.f_gc_duration, self->private_impl.f_num_decoded_frame_configs_value, - (a_src.private_impl.buf ? wuffs_base__u64__sat_add( - a_src.private_impl.buf->pos, - iop_a_src - a_src.private_impl.buf->ptr) - : 0), - v_blend, self->private_impl.f_gc_disposal); + self->private_impl.f_frame_config_io_position, v_blend, + self->private_impl.f_gc_disposal); } wuffs_base__u64__sat_add_indirect( &self->private_impl.f_num_decoded_frame_configs_value, 1); @@ -6649,10 +6587,6 @@ suspend: goto exit; exit: - if (a_src.private_impl.buf) { - a_src.private_impl.buf->ri = iop_a_src - a_src.private_impl.buf->ptr; - } - if (wuffs_base__status__is_error(status)) { self->private_impl.magic = WUFFS_BASE__DISABLED; } @@ -6737,14 +6671,9 @@ wuffs_gif__decoder__skip_frame(wuffs_gif__decoder* self, if (status) { goto suspend; } - self->private_impl.f_seen_graphic_control = false; - self->private_impl.f_gc_has_transparent_index = false; - self->private_impl.f_gc_transparent_index = 0; - self->private_impl.f_gc_disposal = 0; - self->private_impl.f_gc_duration = 0; wuffs_base__u64__sat_add_indirect( &self->private_impl.f_num_decoded_frames_value, 1); - self->private_impl.f_call_sequence = 3; + wuffs_gif__decoder__reset_gc(self); goto ok; ok: @@ -6810,14 +6739,9 @@ wuffs_gif__decoder__decode_frame(wuffs_gif__decoder* self, if (status) { goto suspend; } - self->private_impl.f_seen_graphic_control = false; - self->private_impl.f_gc_has_transparent_index = false; - self->private_impl.f_gc_transparent_index = 0; - self->private_impl.f_gc_disposal = 0; - self->private_impl.f_gc_duration = 0; wuffs_base__u64__sat_add_indirect( &self->private_impl.f_num_decoded_frames_value, 1); - self->private_impl.f_call_sequence = 3; + wuffs_gif__decoder__reset_gc(self); goto ok; ok: @@ -6837,6 +6761,18 @@ exit: return status; } +// -------- func gif.decoder.reset_gc + +static void // +wuffs_gif__decoder__reset_gc(wuffs_gif__decoder* self) { + self->private_impl.f_call_sequence = 3; + self->private_impl.f_seen_graphic_control = false; + self->private_impl.f_gc_has_transparent_index = false; + self->private_impl.f_gc_transparent_index = 0; + self->private_impl.f_gc_disposal = 0; + self->private_impl.f_gc_duration = 0; +} + // -------- func gif.decoder.decode_up_to_id_part1 static wuffs_base__status // @@ -6871,6 +6807,11 @@ wuffs_gif__decoder__decode_up_to_id_part1(wuffs_gif__decoder* self, switch (coro_susp_point) { WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0; + self->private_impl.f_frame_config_io_position = + (a_src.private_impl.buf + ? wuffs_base__u64__sat_add(a_src.private_impl.buf->pos, + iop_a_src - a_src.private_impl.buf->ptr) + : 0); while (true) { { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 1fcea164..0d45870e 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -92,6 +92,7 @@ pub struct decoder?( // There are 7056000 flicks per centisecond. gc_duration base.u64[..0xFFFF * 7056000], + frame_config_io_position base.u64, num_decoded_frame_configs_value base.u64, num_decoded_frames_value base.u64, @@ -165,29 +166,15 @@ pub func decoder.work_buffer_size() base.range_ii_u64 { return this.util.make_range_ii_u64(min_incl:0, max_incl:0) } -pub func decoder.reset_for_decode_frame!??(fc ptr base.frame_config) { +pub func decoder.reset_before!??(fc ptr base.frame_config) { if this.call_sequence == 0 { return status "?bad call sequence" } - // TODO: change ~sat+ to + or change the semantics so that the io_position - // is before, not after, the frame config. - this.num_decoded_frame_configs_value = args.fc.index() ~sat+ 1 - this.num_decoded_frames_value = args.fc.index() - - this.frame_rect_x0 = args.fc.rect_x0() - this.frame_rect_y0 = args.fc.rect_y0() - this.frame_rect_x1 = args.fc.rect_x1() - this.frame_rect_y1 = args.fc.rect_y1() - this.dst_x = this.frame_rect_x0 - this.dst_y = this.frame_rect_y0 - + // TODO: take an io_reader and check that its pos equals fc's pos? this.end_of_data = false - - // TODO: delete this hack. - this.call_sequence = 2 - - // TODO: restoring the state above isn't enough. We also need to restore - // gc_etc fields like gc_transparent_index, but they're not in args.fc. + this.num_decoded_frame_configs_value = args.fc.index() + this.num_decoded_frames_value = this.num_decoded_frame_configs_value + this.reset_gc!() } pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_reader) { @@ -221,7 +208,7 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_ max_excl_y:this.frame_rect_y1), duration:this.gc_duration, index:this.num_decoded_frame_configs_value, - io_position:args.src.position(), + io_position:this.frame_config_io_position, blend:blend, disposal:this.gc_disposal) } @@ -236,20 +223,11 @@ pri func decoder.skip_frame!??(src base.io_reader) { if (flags & 0x80) != 0 { args.src.skip!??(n:(3 as base.u32) << (1 + (flags & 0x07))) } - var lw base.u8 = args.src.read_u8!??() this.skip_blocks!??(src:args.src) - // The Image Descriptor is mandatory, but the Graphic Control extension is - // optional. Reset the GC related fields for the next decode_frame call. - this.seen_graphic_control = false - this.gc_has_transparent_index = false - this.gc_transparent_index = 0 - this.gc_disposal = 0 - this.gc_duration = 0 - this.num_decoded_frames_value ~sat+= 1 - this.call_sequence = 3 + this.reset_gc!() } // TODO: honor pixbuf_origin_x and pixbuf_origin_y args. @@ -257,9 +235,14 @@ pub func decoder.decode_frame!??(dst ptr base.pixel_buffer, pixbuf_origin_x base if this.call_sequence != 2 { this.decode_frame_config!??(dst:nullptr, src:args.src) } - this.decode_id_part1!??(dst:args.dst, src:args.src) + this.num_decoded_frames_value ~sat+= 1 + this.reset_gc!() +} + +pri func decoder.reset_gc!() { + this.call_sequence = 3 // The Image Descriptor is mandatory, but the Graphic Control extension is // optional. Reset the GC related fields for the next decode_frame call. this.seen_graphic_control = false @@ -267,12 +250,10 @@ pub func decoder.decode_frame!??(dst ptr base.pixel_buffer, pixbuf_origin_x base this.gc_transparent_index = 0 this.gc_disposal = 0 this.gc_duration = 0 - - this.num_decoded_frames_value ~sat+= 1 - this.call_sequence = 3 } pri func decoder.decode_up_to_id_part1!??(src base.io_reader) { + this.frame_config_io_position = args.src.position() while true { var block_type base.u8 = args.src.read_u8!??() if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer". diff --git a/test/c/std/gif.c b/test/c/std/gif.c index 95f5b45c..e8295285 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -849,7 +849,7 @@ bool do_test_wuffs_gif_io_position(bool chunked) { wuffs_base__frame_config fcs[4]; uint32_t width_wants[4] = {64, 37, 49, 49}; - uint64_t pos_wants[4] = {817, 2143, 2204, 2559}; + uint64_t pos_wants[4] = {781, 2126, 2187, 2542}; int i; for (i = 0; i < 4; i++) { fcs[i] = ((wuffs_base__frame_config){}); @@ -883,19 +883,20 @@ bool do_test_wuffs_gif_io_position(bool chunked) { return false; } - // Look for the 0x2C byte that's the start of a GIF's Image Descriptor, 9 - // bytes before the frame_config's I/O position. - if ((pos_got < 9) || (pos_got - 9 < src.pos)) { + // Look for the 0x21 byte that's a GIF's Extension Introducer. Not every + // GIF's frame_config's I/O position will point to 0x21, as an 0x2C Image + // Separator is also valid. But for animated-red-blue.gif, it'll be 0x21. + if (pos_got < src.pos) { FAIL("io_position #%d: got %" PRIu64 ", was too small", i, pos_got); return false; } - uint64_t src_ptr_offset = pos_got - 9 - src.pos; + uint64_t src_ptr_offset = pos_got - src.pos; if (src_ptr_offset >= src.wi) { FAIL("io_position #%d: got %" PRIu64 ", was too large", i, pos_got); return false; } uint8_t x = src.ptr[src_ptr_offset]; - if (x != 0x2C) { + if (x != 0x21) { FAIL("Image Descriptor byte #%d: got 0x%02X, want 0x2C", i, (int)x); return false; } @@ -909,7 +910,7 @@ bool do_test_wuffs_gif_io_position(bool chunked) { // If we're chunked, we've discarded some source bytes due to an earlier // wuffs_base__io_buffer__compact call. We won't bother testing - // reset_for_decode_frame in that case. + // wuffs_gif__decoder__reset_before in that case. if (chunked) { return true; } @@ -917,14 +918,14 @@ bool do_test_wuffs_gif_io_position(bool chunked) { for (i = 0; i < 4; i++) { src.ri = pos_wants[i]; - z = wuffs_gif__decoder__reset_for_decode_frame(&dec, &fcs[i]); + z = wuffs_gif__decoder__reset_before(&dec, &fcs[i]); if (z) { - FAIL("reset_for_decode_frame #%d: \"%s\"", i, z); + FAIL("reset_before #%d: \"%s\"", i, z); return false; } int j; - for (j = i + 1; j < 4; j++) { + for (j = i; j < 4; j++) { wuffs_base__frame_config fc = ((wuffs_base__frame_config){}); z = wuffs_gif__decoder__decode_frame_config(&dec, &fc, src_reader); if (z) {