diff --git a/cmd/wuffs-c/internal/cgen/base/image-public.h b/cmd/wuffs-c/internal/cgen/base/image-public.h index 0ca285c1..3c3780af 100644 --- a/cmd/wuffs-c/internal/cgen/base/image-public.h +++ b/cmd/wuffs-c/internal/cgen/base/image-public.h @@ -547,6 +547,26 @@ wuffs_base__image_config::first_frame_is_opaque() { // -------- +// wuffs_base__animation_blend encodes, for an animated image, how to blend the +// transparent pixels of this frame with the existing canvas. In Porter-Duff +// compositing operator terminology: +// - 0 means the frame may be transparent, and should be blended "src over +// dst", also known as just "over". +// - 1 means the frame may be transparent, and should be blended "src". +// - 2 means the frame is completely opaque, so that "src over dst" and "src" +// are equivalent. +// +// These semantics are conservative. It is valid for a completely opaque frame +// to have a blend value other than 2. +typedef uint8_t wuffs_base__animation_blend; + +#define WUFFS_BASE__ANIMATION_BLEND__SRC_OVER_DST \ + ((wuffs_base__animation_blend)0) +#define WUFFS_BASE__ANIMATION_BLEND__SRC ((wuffs_base__animation_blend)1) +#define WUFFS_BASE__ANIMATION_BLEND__OPAQUE ((wuffs_base__animation_blend)2) + +// -------- + // wuffs_base__animation_disposal encodes, for an animated image, how to // dispose of a frame after displaying it: // - None means to draw the next frame on top of this one. @@ -571,7 +591,7 @@ typedef struct { struct { wuffs_base__rect_ie_u32 bounds; wuffs_base__flicks duration; - bool blend; + wuffs_base__animation_blend blend; wuffs_base__animation_disposal disposal; bool palette_changed; } private_impl; @@ -579,14 +599,14 @@ typedef struct { #ifdef __cplusplus inline void update(wuffs_base__rect_ie_u32 bounds, wuffs_base__flicks duration, - bool blend, + wuffs_base__animation_blend blend, wuffs_base__animation_disposal disposal, bool palette_changed); inline wuffs_base__rect_ie_u32 bounds(); inline uint32_t width(); inline uint32_t height(); inline wuffs_base__flicks duration(); - inline bool blend(); + inline wuffs_base__animation_blend blend(); inline wuffs_base__animation_disposal disposal(); inline bool palette_changed(); #endif // __cplusplus @@ -597,7 +617,7 @@ static inline void // wuffs_base__frame_config__update(wuffs_base__frame_config* c, wuffs_base__rect_ie_u32 bounds, wuffs_base__flicks duration, - bool blend, + wuffs_base__animation_blend blend, wuffs_base__animation_disposal disposal, bool palette_changed) { if (!c) { @@ -633,12 +653,9 @@ wuffs_base__frame_config__duration(wuffs_base__frame_config* c) { return c ? c->private_impl.duration : 0; } -// wuffs_base__frame_config__blend returns, for a transparent image, whether to -// blend this frame with the existing canvas. -// -// In Porter-Duff compositing operator terminology, false means "src" and true -// means "src over dst". -static inline bool // +// wuffs_base__frame_config__blend returns, for an animated image, how to blend +// the transparent pixels of this frame with the existing canvas. +static inline wuffs_base__animation_blend // wuffs_base__frame_config__blend(wuffs_base__frame_config* c) { return c && c->private_impl.blend; } @@ -663,7 +680,7 @@ wuffs_base__frame_config__palette_changed(wuffs_base__frame_config* c) { inline void // wuffs_base__frame_config::update(wuffs_base__rect_ie_u32 bounds, wuffs_base__flicks duration, - bool blend, + wuffs_base__animation_blend blend, wuffs_base__animation_disposal disposal, bool palette_changed) { wuffs_base__frame_config__update(this, bounds, duration, blend, disposal, @@ -690,7 +707,7 @@ wuffs_base__frame_config::duration() { return wuffs_base__frame_config__duration(this); } -inline bool // +inline wuffs_base__animation_blend // wuffs_base__frame_config::blend() { return wuffs_base__frame_config__blend(this); } diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index 6e60875d..12d69553 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -142,13 +142,15 @@ const baseImagePublicH = "" + "uint32_t //\nwuffs_base__image_config__num_loops(wuffs_base__image_config* c) {\n return c ? c->private_impl.num_loops : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__image_config__first_frame_is_opaque(wuffs_base__image_config* c) {\n return c ? c->private_impl.first_frame_is_opaque : false;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__image_config::initialize(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint32_t num_loops,\n bool first_frame_is_opaque) {\n wuffs_base__image_config__initialize(this, pixfmt, pixsub, width, height,\n num_loops, first_frame_is_opaque);\n}\n\ninline void //\nwuffs_base__image_config::invalidate() {\n wuffs_base__image_config__invalidate(this);\n}\n\ninline bool //\nwuffs_base__image_config::is_valid() {\n " + "return wuffs_base__image_config__is_valid(this);\n}\n\ninline uint32_t //\nwuffs_base__image_config::num_loops() {\n return wuffs_base__image_config__num_loops(this);\n}\n\ninline uint32_t //\nwuffs_base__image_config::first_frame_is_opaque() {\n return wuffs_base__image_config__first_frame_is_opaque(this);\n}\n\n#endif // __cplusplus\n\n" + "" + + "// --------\n\n// wuffs_base__animation_blend encodes, for an animated image, how to blend the\n// transparent pixels of this frame with the existing canvas. In Porter-Duff\n// compositing operator terminology:\n// - 0 means the frame may be transparent, and should be blended \"src over\n// dst\", also known as just \"over\".\n// - 1 means the frame may be transparent, and should be blended \"src\".\n// - 2 means the frame is completely opaque, so that \"src over dst\" and \"src\"\n// are equivalent.\n//\n// These semantics are conservative. It is valid for a completely opaque frame\n// to have a blend value other than 2.\ntypedef uint8_t wuffs_base__animation_blend;\n\n#define WUFFS_BASE__ANIMATION_BLEND__SRC_OVER_DST \\\n ((wuffs_base__animation_blend)0)\n#define WUFFS_BASE__ANIMATION_BLEND__SRC ((wuffs_base__animation_blend)1)\n#define WUFFS_BASE__ANIMATION_BLEND__OPAQUE ((wuffs_base__animation_blend)2)\n\n" + + "" + "// --------\n\n// wuffs_base__animation_disposal encodes, for an animated image, how to\n// dispose of a frame after displaying it:\n// - None means to draw the next frame on top of this one.\n// - Restore Background means to clear the frame's dirty rectangle to \"the\n// background color\" (in practice, this means transparent black) before\n// drawing the next frame.\n// - Restore Previous means to undo the current frame, so that the next frame\n// is drawn on top of the previous one.\ntypedef uint8_t wuffs_base__animation_disposal;\n\n#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0)\n#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \\\n ((wuffs_base__animation_disposal)1)\n#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \\\n ((wuffs_base__animation_disposal)2)\n\n" + "" + - "// --------\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 bool blend;\n wuffs_base__animation_disposal disposal;\n bool palette_changed;\n } private_impl;\n\n#ifdef __cplusplus\n inline void update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n bool blend,\n wuffs_base__animation_disposal disposal,\n bool palette_changed);\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 bool blend();\n inline wuffs_base__animation_disposal disposal();\n inline bool palette_changed();\n#endif // __cplusplus\n\n} wuffs_base__frame_config;\n\nstatic inline void //\nwuffs_base__frame_config__update(wuffs_base__frame_config* c,\n wu" + - "ffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n bool blend,\n wuffs_base__animation_disposal disposal,\n bool palette_changed) {\n if (!c) {\n return;\n }\n\n c->private_impl.bounds = bounds;\n c->private_impl.duration = duration;\n c->private_impl.blend = blend;\n c->private_impl.disposal = disposal;\n c->private_impl.palette_changed = palette_changed;\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 return 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_ba" + - "se__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__blend returns, for a transparent image, whether to\n// blend this frame with the existing canvas.\n//\n// In Porter-Duff compositing operator terminology, false means \"src\" and true\n// means \"src over dst\".\nstatic inline bool //\nwuffs_base__frame_config__blend(wuffs_base__frame_config* c) {\n return c && c->private_impl.blend;\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// wuffs_base__frame_config__palette_changed returns whether this frame's\n// palette diffe" + - "rs from the previous frame. It is conservative and may return\n// false positives (but never false negatives).\nstatic inline bool //\nwuffs_base__frame_config__palette_changed(wuffs_base__frame_config* c) {\n return c && c->private_impl.palette_changed;\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 bool blend,\n wuffs_base__animation_disposal disposal,\n bool palette_changed) {\n wuffs_base__frame_config__update(this, bounds, duration, blend, disposal,\n palette_changed);\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 bool //\nwuffs_base__frame_config::blend() {\n return wuffs_base__frame_config__blend(this);\n}\n\ninline wuffs_base__animation_disposal //\nwuffs_base__frame_config::disposal() {\n return wuffs_base__frame_config__disposal(this);\n}\n\ninline bool //\nwuffs_base__frame_config::palette_changed() {\n return wuffs_base__frame_config__palette_changed(this);\n}\n\n#endif // __cplusplus\n\n" + + "// --------\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 wuffs_base__animation_blend blend;\n wuffs_base__animation_disposal disposal;\n bool palette_changed;\n } private_impl;\n\n#ifdef __cplusplus\n inline void update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal,\n bool palette_changed);\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 wuffs_base__animation_blend blend();\n inline wuffs_base__animation_disposal disposal();\n inline bool palette_changed();\n#endif // __cplusplus\n\n} wuffs_base__frame_config;\n\nstatic inline void //\nwuffs_base__frame_config__up" + + "date(wuffs_base__frame_config* c,\n wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal,\n bool palette_changed) {\n if (!c) {\n return;\n }\n\n c->private_impl.bounds = bounds;\n c->private_impl.duration = duration;\n c->private_impl.blend = blend;\n c->private_impl.disposal = disposal;\n c->private_impl.palette_changed = palette_changed;\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 return 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__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;\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// wuffs_base__frame_config__palette_changed returns whether t" + + "his frame's\n// palette differs from the previous frame. It is conservative and may return\n// false positives (but never false negatives).\nstatic inline bool //\nwuffs_base__frame_config__palette_changed(wuffs_base__frame_config* c) {\n return c && c->private_impl.palette_changed;\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 wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal,\n bool palette_changed) {\n wuffs_base__frame_config__update(this, bounds, duration, blend, disposal,\n palette_changed);\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 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__frame_config::disposal() {\n return wuffs_base__frame_config__disposal(this);\n}\n\ninline bool //\nwuffs_base__frame_config::palette_changed() {\n return wuffs_base__frame_config__palette_changed(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 83969d41..da59f29e 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -228,7 +228,7 @@ var Funcs = []string{ // Duration's upper bound is the maximum possible i64 value. "frame_config.update!(bounds rect_ie_u32, duration u64[..0x7FFFFFFFFFFFFFFF], " + - "blend bool, disposal u8, palette_changed bool)", + "blend u8, disposal u8, palette_changed bool)", // ---- image_config diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index aaf9fd1e..1bbd6587 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -1643,6 +1643,26 @@ wuffs_base__image_config::first_frame_is_opaque() { // -------- +// wuffs_base__animation_blend encodes, for an animated image, how to blend the +// transparent pixels of this frame with the existing canvas. In Porter-Duff +// compositing operator terminology: +// - 0 means the frame may be transparent, and should be blended "src over +// dst", also known as just "over". +// - 1 means the frame may be transparent, and should be blended "src". +// - 2 means the frame is completely opaque, so that "src over dst" and "src" +// are equivalent. +// +// These semantics are conservative. It is valid for a completely opaque frame +// to have a blend value other than 2. +typedef uint8_t wuffs_base__animation_blend; + +#define WUFFS_BASE__ANIMATION_BLEND__SRC_OVER_DST \ + ((wuffs_base__animation_blend)0) +#define WUFFS_BASE__ANIMATION_BLEND__SRC ((wuffs_base__animation_blend)1) +#define WUFFS_BASE__ANIMATION_BLEND__OPAQUE ((wuffs_base__animation_blend)2) + +// -------- + // wuffs_base__animation_disposal encodes, for an animated image, how to // dispose of a frame after displaying it: // - None means to draw the next frame on top of this one. @@ -1667,7 +1687,7 @@ typedef struct { struct { wuffs_base__rect_ie_u32 bounds; wuffs_base__flicks duration; - bool blend; + wuffs_base__animation_blend blend; wuffs_base__animation_disposal disposal; bool palette_changed; } private_impl; @@ -1675,14 +1695,14 @@ typedef struct { #ifdef __cplusplus inline void update(wuffs_base__rect_ie_u32 bounds, wuffs_base__flicks duration, - bool blend, + wuffs_base__animation_blend blend, wuffs_base__animation_disposal disposal, bool palette_changed); inline wuffs_base__rect_ie_u32 bounds(); inline uint32_t width(); inline uint32_t height(); inline wuffs_base__flicks duration(); - inline bool blend(); + inline wuffs_base__animation_blend blend(); inline wuffs_base__animation_disposal disposal(); inline bool palette_changed(); #endif // __cplusplus @@ -1693,7 +1713,7 @@ static inline void // wuffs_base__frame_config__update(wuffs_base__frame_config* c, wuffs_base__rect_ie_u32 bounds, wuffs_base__flicks duration, - bool blend, + wuffs_base__animation_blend blend, wuffs_base__animation_disposal disposal, bool palette_changed) { if (!c) { @@ -1729,12 +1749,9 @@ wuffs_base__frame_config__duration(wuffs_base__frame_config* c) { return c ? c->private_impl.duration : 0; } -// wuffs_base__frame_config__blend returns, for a transparent image, whether to -// blend this frame with the existing canvas. -// -// In Porter-Duff compositing operator terminology, false means "src" and true -// means "src over dst". -static inline bool // +// wuffs_base__frame_config__blend returns, for an animated image, how to blend +// the transparent pixels of this frame with the existing canvas. +static inline wuffs_base__animation_blend // wuffs_base__frame_config__blend(wuffs_base__frame_config* c) { return c && c->private_impl.blend; } @@ -1759,7 +1776,7 @@ wuffs_base__frame_config__palette_changed(wuffs_base__frame_config* c) { inline void // wuffs_base__frame_config::update(wuffs_base__rect_ie_u32 bounds, wuffs_base__flicks duration, - bool blend, + wuffs_base__animation_blend blend, wuffs_base__animation_disposal disposal, bool palette_changed) { wuffs_base__frame_config__update(this, bounds, duration, blend, disposal, @@ -1786,7 +1803,7 @@ wuffs_base__frame_config::duration() { return wuffs_base__frame_config__duration(this); } -inline bool // +inline wuffs_base__animation_blend // wuffs_base__frame_config::blend() { return wuffs_base__frame_config__blend(this); } @@ -2401,6 +2418,7 @@ typedef struct { } c_decode_image_config[1]; struct { uint32_t coro_susp_point; + uint8_t v_blend; } c_decode_frame_config[1]; struct { uint32_t coro_susp_point; @@ -6424,9 +6442,12 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self, } wuffs_base__status status = NULL; + uint8_t v_blend; + uint32_t coro_susp_point = self->private_impl.c_decode_frame_config[0].coro_susp_point; if (coro_susp_point) { + v_blend = self->private_impl.c_decode_frame_config[0].v_blend; } else { } switch (coro_susp_point) { @@ -6471,6 +6492,10 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self, self->private_impl.f_previous_use_global_palette = !(self->private_impl.f_use_local_palette || self->private_impl.f_gc_has_transparent_index); + v_blend = 0; + if (!self->private_impl.f_gc_has_transparent_index) { + v_blend = 2; + } if (a_dst != NULL) { wuffs_base__frame_config__update( a_dst, @@ -6479,7 +6504,7 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self, 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_duration, v_blend, self->private_impl.f_gc_disposal, (self->private_impl.f_which_palette != 2)); } @@ -6496,6 +6521,7 @@ wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self, goto suspend; suspend: self->private_impl.c_decode_frame_config[0].coro_susp_point = coro_susp_point; + self->private_impl.c_decode_frame_config[0].v_blend = v_blend; goto exit; exit: diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 5a4c9d3f..fe56aec9 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -147,8 +147,13 @@ pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_ // // TODO: a Wuffs (not just C) name for the // WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED magic pixfmt constant. - args.dst.initialize!(pixfmt:0x22088888, pixsub:0, - width:this.width, height:this.height, num_loops:num_loops, first_frame_is_opaque:ffio) + args.dst.initialize!( + pixfmt:0x22088888, + pixsub:0, + width:this.width, + height:this.height, + num_loops:num_loops, + first_frame_is_opaque:ffio) } this.call_sequence = 1 @@ -199,13 +204,20 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_ this.previous_use_global_palette = not (this.use_local_palette or this.gc_has_transparent_index) + var blend base.u8 = 0 + if not this.gc_has_transparent_index { + blend = 2 // 2 is WUFFS_BASE__ANIMATION_BLEND__OPAQUE. + } + if args.dst != nullptr { args.dst.update!(bounds:this.util.make_rect_ie_u32( min_incl_x:this.frame_rect_x0, min_incl_y:this.frame_rect_y0, max_excl_x:this.frame_rect_x1, max_excl_y:this.frame_rect_y1), - duration:this.gc_duration, blend:true, disposal:this.gc_disposal, + duration:this.gc_duration, + blend:blend, + disposal:this.gc_disposal, palette_changed:this.which_palette != 2) } @@ -309,6 +321,9 @@ pri func decoder.decode_lsd!??(src base.io_reader) { } this.has_full_global_palette = i == 256 // Set the remaining palette entries to transparent black. + // + // TODO: opaque black?? Is this consistent with frame_config.blend? + // Should we mask the LZW-decoded data if num_palette_entries < 256? while i < 256 { this.palettes[0][(4 * i) + 0] = 0x00 this.palettes[0][(4 * i) + 1] = 0x00