From 6df342c60c06cc3b59493b2b5798687d832239e8 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 3 Jun 2018 19:27:57 +1000 Subject: [PATCH] Add animation blend and disposal concepts --- cmd/wuffs-c/internal/cgen/base-header.h | 58 ++++++++++++++++++++---- cmd/wuffs-c/internal/cgen/data.go | 13 +++--- gen/c/std/adler32.c | 58 ++++++++++++++++++++---- gen/c/std/crc32.c | 58 ++++++++++++++++++++---- gen/c/std/deflate.c | 58 ++++++++++++++++++++---- gen/c/std/gif.c | 60 +++++++++++++++++++++---- gen/c/std/gzip.c | 58 ++++++++++++++++++++---- gen/c/std/lzw.c | 58 ++++++++++++++++++++---- gen/c/std/zlib.c | 58 ++++++++++++++++++++---- gen/h/std/adler32.h | 58 ++++++++++++++++++++---- gen/h/std/crc32.h | 58 ++++++++++++++++++++---- gen/h/std/deflate.h | 58 ++++++++++++++++++++---- gen/h/std/gif.h | 58 ++++++++++++++++++++---- gen/h/std/gzip.h | 58 ++++++++++++++++++++---- gen/h/std/lzw.h | 58 ++++++++++++++++++++---- gen/h/std/zlib.h | 58 ++++++++++++++++++++---- lang/builtin/builtin.go | 2 +- std/gif/decode_gif.wuffs | 3 +- 18 files changed, 762 insertions(+), 128 deletions(-) diff --git a/cmd/wuffs-c/internal/cgen/base-header.h b/cmd/wuffs-c/internal/cgen/base-header.h index 09953b7f..a65f1237 100644 --- a/cmd/wuffs-c/internal/cgen/base-header.h +++ b/cmd/wuffs-c/internal/cgen/base-header.h @@ -1006,6 +1006,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1016,6 +1034,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1061,6 +1081,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1074,6 +1096,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1099,19 +1123,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1126,6 +1143,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index 5b3d1651..636a61e1 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -77,11 +77,14 @@ const baseHeader = "" + "l.num_loops = num_loops;\n return;\n }\n }\n *c = ((wuffs_base__image_config){});\n}\n\nstatic inline void wuffs_base__image_config__invalidate(\n wuffs_base__image_config* c) {\n if (c) {\n *c = ((wuffs_base__image_config){});\n }\n}\n\nstatic inline bool wuffs_base__image_config__is_valid(\n wuffs_base__image_config* c) {\n return c && c->private_impl.pixfmt;\n}\n\nstatic inline wuffs_base__pixel_format wuffs_base__image_config__pixel_format(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.pixfmt : 0;\n}\n\nstatic inline wuffs_base__pixel_subsampling\nwuffs_base__image_config__pixel_subsampling(wuffs_base__image_config* c) {\n return c ? c->private_impl.pixsub : 0;\n}\n\nstatic inline uint32_t wuffs_base__image_config__width(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.width : 0;\n}\n\nstatic inline uint32_t wuffs_base__image_config__height(\n wuffs_base__image_config* c) {\n return c ? c->private_impl.height : 0;\n}\n\nstatic inline uint32_t wuffs_base__image_config__num_loops(\n" + " wuffs_base__image_config* c) {\n return c ? c->private_impl.num_loops : 0;\n}\n\n// TODO: this is the right API for planar (not packed) pixbufs? Should it allow\n// decoding into a color model different from the format's intrinsic one? For\n// example, decoding a JPEG image straight to RGBA instead of to YCbCr?\nstatic inline size_t wuffs_base__image_config__pixbuf_size(\n wuffs_base__image_config* c) {\n if (c) {\n uint64_t wh =\n ((uint64_t)c->private_impl.width) * ((uint64_t)c->private_impl.height);\n // TODO: handle things other than 1 byte per pixel.\n return (size_t)wh;\n }\n return 0;\n}\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__image_config config;\n uint32_t loop_count; // 0-based count of the current loop.\n wuffs_base__pixel_buffer pixbuf;\n // TODO: color spaces.\n wuffs_base__rect_ie_u32 dirty_rect;\n wuffs_base__flicks duration;\n bool palette_changed;\n uint8_t palette[1024];\n } private_impl;\n} wuffs_base__image_buffer;\n\nstatic inline void wuffs_base__image_buffer__set_from_pixbuf(\n wuffs_base__image_buffer* b,\n wuffs_base__image_config config,\n wuffs_base__pixel_buffer pixbuf) {\n if (!b) {\n return;\n }\n *b = ((wuffs_base__image_buffer){});\n b->private_impl.config = config;\n b->private_impl.pixbuf = pixbuf;\n}\n\n// TODO: Should this function return bool? An error type?\nstatic inline void wuffs_base__image_buffer__set_from_slice(\n wuffs_base__image_buffer* b,\n wuffs_base__image_config config,\n wuffs_base__s" + - "lice_u8 pixbuf_memory) {\n if (!b) {\n return;\n }\n *b = ((wuffs_base__image_buffer){});\n // TODO: don't assume 1 byte per pixel. Don't assume packed.\n uint64_t wh = ((uint64_t)config.private_impl.width) *\n ((uint64_t)config.private_impl.height);\n if (wh > pixbuf_memory.len) {\n return;\n }\n b->private_impl.config = config;\n wuffs_base__table_u8* tab = &b->private_impl.pixbuf.planes[0];\n tab->ptr = pixbuf_memory.ptr;\n tab->width = config.private_impl.width;\n tab->height = config.private_impl.height;\n tab->stride = config.private_impl.width;\n}\n\n// The palette argument is ignored unless its length is exactly 1024.\nstatic inline void wuffs_base__image_buffer__update(\n wuffs_base__image_buffer* b,\n wuffs_base__rect_ie_u32 dirty_rect,\n wuffs_base__flicks duration,\n wuffs_base__slice_u8 palette) {\n if (!b) {\n return;\n }\n\n // Clip the dirty_rect to the image bounds.\n dirty_rect.max_exclusive_x = wuffs_base__u32__min(\n dirty_rect.max_exclusive_x, b->private_impl.co" + - "nfig.private_impl.width);\n dirty_rect.max_exclusive_y = wuffs_base__u32__min(\n dirty_rect.max_exclusive_y, b->private_impl.config.private_impl.height);\n b->private_impl.dirty_rect = dirty_rect;\n\n b->private_impl.duration = duration;\n b->private_impl.palette_changed = palette.ptr && (palette.len == 1024);\n if (b->private_impl.palette_changed) {\n memmove(b->private_impl.palette, palette.ptr, 1024);\n }\n}\n\n// wuffs_base__image_buffer__loop returns whether the image decoder should loop\n// back to the beginning of the animation, assuming that we've reached the end\n// of the encoded stream. If so, it increments b's count of the animation loops\n// played so far.\nstatic inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) {\n if (!b) {\n return false;\n }\n uint32_t n = b->private_impl.config.private_impl.num_loops;\n if (n == 0) {\n return true;\n }\n if (b->private_impl.loop_count < n - 1) {\n b->private_impl.loop_count++;\n return true;\n }\n return false;\n}\n\nstatic inline w" + - "uffs_base__image_config* wuffs_base__image_buffer__image_config(\n wuffs_base__image_buffer* b) {\n return b ? &b->private_impl.config : NULL;\n}\n\n// wuffs_base__image_buffer__palette_changed returns whether this 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 wuffs_base__image_buffer__palette_changed(\n wuffs_base__image_buffer* b) {\n return b && b->private_impl.palette_changed;\n}\n\n// wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of\n// this frame's pixels differs from the previous frame.\nstatic inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect(\n wuffs_base__image_buffer* b) {\n return b ? b->private_impl.dirty_rect : ((wuffs_base__rect_ie_u32){0});\n}\n\n// wuffs_base__image_buffer__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 wuffs_base__image_b" + - "uffer__duration(\n wuffs_base__image_buffer* b) {\n return b ? b->private_impl.duration : 0;\n}\n\n// wuffs_base__image_buffer__palette returns the palette that the pixel data\n// can index. The backing array is inside b and has length 1024.\nstatic inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette(\n wuffs_base__image_buffer* b) {\n return b ? ((wuffs_base__slice_u8){.ptr = b->private_impl.palette,\n .len = 1024})\n : ((wuffs_base__slice_u8){});\n}\n\nstatic inline wuffs_base__table_u8 wuffs_base__image_buffer__plane(\n wuffs_base__image_buffer* b,\n uint32_t p) {\n return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))\n ? b->private_impl.pixbuf.planes[p]\n : ((wuffs_base__table_u8){});\n}\n\n#endif // WUFFS_BASE_HEADER_H\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__image_config config;\n uint32_t loop_count; // 0-based count of the current loop.\n wuffs_base__pixel_buffer pixbuf;\n // TODO: color spaces.\n wuffs_base__rect_ie_u32 dirty_rect;\n wuffs_base__flicks duration;\n bool blend;\n wuffs_base__animation_disposal disposal;\n bool palette_changed;\n uint8_t palette[1024];\n } private_impl;\n} wuffs_base__image_buffer;\n\nstatic inline void wuffs_base__image_buffer__set_from_pixbuf(\n wuffs_base__image_buffer* b,\n wuffs_base__image_config config,\n wuffs_base__pixel_buffer pixbuf) {\n if (!b) {\n return;\n }\n *b = ((wuffs_base__image_buffer){});\n b->private_impl.config = config;\n b->private_impl.pixbuf = pixbuf;\n}\n\n// TODO: Should this function return bool? An error type?\nstatic inline void wuffs_base__image_buffer__set_from_slice(\n wuffs_base__image_buff" + + "er* b,\n wuffs_base__image_config config,\n wuffs_base__slice_u8 pixbuf_memory) {\n if (!b) {\n return;\n }\n *b = ((wuffs_base__image_buffer){});\n // TODO: don't assume 1 byte per pixel. Don't assume packed.\n uint64_t wh = ((uint64_t)config.private_impl.width) *\n ((uint64_t)config.private_impl.height);\n if (wh > pixbuf_memory.len) {\n return;\n }\n b->private_impl.config = config;\n wuffs_base__table_u8* tab = &b->private_impl.pixbuf.planes[0];\n tab->ptr = pixbuf_memory.ptr;\n tab->width = config.private_impl.width;\n tab->height = config.private_impl.height;\n tab->stride = config.private_impl.width;\n}\n\n// The palette argument is ignored unless its length is exactly 1024.\nstatic inline void wuffs_base__image_buffer__update(\n wuffs_base__image_buffer* b,\n wuffs_base__rect_ie_u32 dirty_rect,\n wuffs_base__flicks duration,\n bool blend,\n wuffs_base__animation_disposal disposal,\n wuffs_base__slice_u8 palette) {\n if (!b) {\n return;\n }\n\n // Clip the dirty_rect to t" + + "he image bounds.\n dirty_rect.max_exclusive_x = wuffs_base__u32__min(\n dirty_rect.max_exclusive_x, b->private_impl.config.private_impl.width);\n dirty_rect.max_exclusive_y = wuffs_base__u32__min(\n dirty_rect.max_exclusive_y, b->private_impl.config.private_impl.height);\n b->private_impl.dirty_rect = dirty_rect;\n\n b->private_impl.duration = duration;\n b->private_impl.blend = blend;\n b->private_impl.disposal = disposal;\n b->private_impl.palette_changed = palette.ptr && (palette.len == 1024);\n if (b->private_impl.palette_changed) {\n memmove(b->private_impl.palette, palette.ptr, 1024);\n }\n}\n\n// wuffs_base__image_buffer__loop returns whether the image decoder should loop\n// back to the beginning of the animation, assuming that we've reached the end\n// of the encoded stream. If so, it increments b's count of the animation loops\n// played so far.\nstatic inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) {\n if (!b) {\n return false;\n }\n uint32_t n = b->private_impl.config." + + "private_impl.num_loops;\n if (n == 0) {\n return true;\n }\n if (b->private_impl.loop_count < n - 1) {\n b->private_impl.loop_count++;\n return true;\n }\n return false;\n}\n\n// wuffs_base__image_config returns the overall configuration for this frame.\nstatic inline wuffs_base__image_config* wuffs_base__image_buffer__image_config(\n wuffs_base__image_buffer* b) {\n return b ? &b->private_impl.config : NULL;\n}\n\n// wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of\n// this frame's pixels differs from the previous frame.\nstatic inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect(\n wuffs_base__image_buffer* b) {\n return b ? b->private_impl.dirty_rect : ((wuffs_base__rect_ie_u32){0});\n}\n\n// wuffs_base__image_buffer__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 wuffs_base__image_buffer__duration(\n wuffs_base__image_buffer* b) {\n return b ? b->private" + + "_impl.duration : 0;\n}\n\n// wuffs_base__image_buffer__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 wuffs_base__image_buffer__blend(\n wuffs_base__image_buffer* b) {\n return b && b->private_impl.blend;\n}\n\n// wuffs_base__image_buffer__disposal returns, for an animated image, how to\n// dispose of this frame after displaying it.\nstatic inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal(\n wuffs_base__image_buffer* b) {\n return b ? b->private_impl.disposal : 0;\n}\n\n// wuffs_base__image_buffer__palette_changed returns whether this 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 wuffs_base__image_buffer__palette_changed(\n wuffs_base__image_buffer* b) {\n return b && b->private_impl.palette_changed;\n}\n\n// wuffs_" + + "base__image_buffer__palette returns the palette that the pixel data\n// can index. The backing array is inside b and has length 1024.\nstatic inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette(\n wuffs_base__image_buffer* b) {\n return b ? ((wuffs_base__slice_u8){.ptr = b->private_impl.palette,\n .len = 1024})\n : ((wuffs_base__slice_u8){});\n}\n\nstatic inline wuffs_base__table_u8 wuffs_base__image_buffer__plane(\n wuffs_base__image_buffer* b,\n uint32_t p) {\n return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))\n ? b->private_impl.pixbuf.planes[p]\n : ((wuffs_base__table_u8){});\n}\n\n#endif // WUFFS_BASE_HEADER_H\n" + "" const baseImpl = "" + diff --git a/gen/c/std/adler32.c b/gen/c/std/adler32.c index f2d3e02c..765bdaf6 100644 --- a/gen/c/std/adler32.c +++ b/gen/c/std/adler32.c @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/c/std/crc32.c b/gen/c/std/crc32.c index bd732bed..852c7508 100644 --- a/gen/c/std/crc32.c +++ b/gen/c/std/crc32.c @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/c/std/deflate.c b/gen/c/std/deflate.c index 3497a5bd..acf2aca2 100644 --- a/gen/c/std/deflate.c +++ b/gen/c/std/deflate.c @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 63e5e549..f338b14e 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( @@ -3640,7 +3682,7 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1( .ptr = self->private_impl.f_palettes[0], .len = 1024}); } wuffs_base__image_buffer__update(a_dst, self->private_impl.f_frame_rect, - self->private_impl.f_gc_duration, + self->private_impl.f_gc_duration, true, 0, v_palette); self->private_impl.f_previous_use_global_palette = !v_use_local_palette; self->private_impl.f_seen_graphic_control = false; diff --git a/gen/c/std/gzip.c b/gen/c/std/gzip.c index 824582ee..2100f2d1 100644 --- a/gen/c/std/gzip.c +++ b/gen/c/std/gzip.c @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/c/std/lzw.c b/gen/c/std/lzw.c index 5a224dcd..4bae412a 100644 --- a/gen/c/std/lzw.c +++ b/gen/c/std/lzw.c @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/c/std/zlib.c b/gen/c/std/zlib.c index f383e90e..3e7eeb99 100644 --- a/gen/c/std/zlib.c +++ b/gen/c/std/zlib.c @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/h/std/adler32.h b/gen/h/std/adler32.h index a27b2caf..b85ef54e 100644 --- a/gen/h/std/adler32.h +++ b/gen/h/std/adler32.h @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/h/std/crc32.h b/gen/h/std/crc32.h index feae69e3..d4401f83 100644 --- a/gen/h/std/crc32.h +++ b/gen/h/std/crc32.h @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/h/std/deflate.h b/gen/h/std/deflate.h index 4292568f..2f9a97e1 100644 --- a/gen/h/std/deflate.h +++ b/gen/h/std/deflate.h @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index 9d1f5d4f..274e16da 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/h/std/gzip.h b/gen/h/std/gzip.h index df9d5333..d09f4192 100644 --- a/gen/h/std/gzip.h +++ b/gen/h/std/gzip.h @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/h/std/lzw.h b/gen/h/std/lzw.h index 29e3ca4b..78a20615 100644 --- a/gen/h/std/lzw.h +++ b/gen/h/std/lzw.h @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/gen/h/std/zlib.h b/gen/h/std/zlib.h index 0f99d7c2..5c1edd3e 100644 --- a/gen/h/std/zlib.h +++ b/gen/h/std/zlib.h @@ -1009,6 +1009,24 @@ static inline size_t wuffs_base__image_config__pixbuf_size( // -------- +// 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. +// - Restore Background means to clear the frame's dirty rectangle to "the +// background color" (in practice, this means transparent black) before +// drawing the next frame. +// - Restore Previous means to undo the current frame, so that the next frame +// is drawn on top of the previous one. +typedef uint8_t wuffs_base__animation_disposal; + +#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \ + ((wuffs_base__animation_disposal)1) +#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \ + ((wuffs_base__animation_disposal)2) + +// -------- + typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. @@ -1019,6 +1037,8 @@ typedef struct { // TODO: color spaces. wuffs_base__rect_ie_u32 dirty_rect; wuffs_base__flicks duration; + bool blend; + wuffs_base__animation_disposal disposal; bool palette_changed; uint8_t palette[1024]; } private_impl; @@ -1064,6 +1084,8 @@ static inline void wuffs_base__image_buffer__update( wuffs_base__image_buffer* b, wuffs_base__rect_ie_u32 dirty_rect, wuffs_base__flicks duration, + bool blend, + wuffs_base__animation_disposal disposal, wuffs_base__slice_u8 palette) { if (!b) { return; @@ -1077,6 +1099,8 @@ static inline void wuffs_base__image_buffer__update( b->private_impl.dirty_rect = dirty_rect; b->private_impl.duration = duration; + b->private_impl.blend = blend; + b->private_impl.disposal = disposal; b->private_impl.palette_changed = palette.ptr && (palette.len == 1024); if (b->private_impl.palette_changed) { memmove(b->private_impl.palette, palette.ptr, 1024); @@ -1102,19 +1126,12 @@ static inline bool wuffs_base__image_buffer__loop(wuffs_base__image_buffer* b) { return false; } +// wuffs_base__image_config returns the overall configuration for this frame. static inline wuffs_base__image_config* wuffs_base__image_buffer__image_config( wuffs_base__image_buffer* b) { return b ? &b->private_impl.config : NULL; } -// wuffs_base__image_buffer__palette_changed returns whether this frame's -// palette differs from the previous frame. It is conservative and may return -// false positives (but never false negatives). -static inline bool wuffs_base__image_buffer__palette_changed( - wuffs_base__image_buffer* b) { - return b && b->private_impl.palette_changed; -} - // wuffs_base__image_buffer__dirty_rect returns an upper bound for what part of // this frame's pixels differs from the previous frame. static inline wuffs_base__rect_ie_u32 wuffs_base__image_buffer__dirty_rect( @@ -1129,6 +1146,31 @@ static inline wuffs_base__flicks wuffs_base__image_buffer__duration( return b ? b->private_impl.duration : 0; } +// wuffs_base__image_buffer__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__image_buffer__blend( + wuffs_base__image_buffer* b) { + return b && b->private_impl.blend; +} + +// wuffs_base__image_buffer__disposal returns, for an animated image, how to +// dispose of this frame after displaying it. +static inline wuffs_base__animation_disposal wuffs_base__image_buffer__disposal( + wuffs_base__image_buffer* b) { + return b ? b->private_impl.disposal : 0; +} + +// wuffs_base__image_buffer__palette_changed returns whether this frame's +// palette differs from the previous frame. It is conservative and may return +// false positives (but never false negatives). +static inline bool wuffs_base__image_buffer__palette_changed( + wuffs_base__image_buffer* b) { + return b && b->private_impl.palette_changed; +} + // wuffs_base__image_buffer__palette returns the palette that the pixel data // can index. The backing array is inside b and has length 1024. static inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette( diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go index c34b04dd..00321bdf 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -123,7 +123,7 @@ var Funcs = []string{ // ---- image_buffer "image_buffer.plane(p u32[..3])(ret table u8)", - "image_buffer.update!(dirty_rect rect_ie_u32, duration u64, palette slice u8)()", + "image_buffer.update!(dirty_rect rect_ie_u32, duration u64, blend bool, disposal u8, palette slice u8)()", // ---- image_config diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 0a7c7553..08ecc2c5 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -488,7 +488,8 @@ pri func decoder.decode_id_part1?(dst ptr base.image_buffer, src base.io_reader) // Both this frame and the previous one used the global palette. No // palette update is necessary. } - in.dst.update!(dirty_rect:this.frame_rect, duration:this.gc_duration, palette:palette) + in.dst.update!(dirty_rect:this.frame_rect, duration:this.gc_duration, + blend:true, disposal:0, palette:palette) this.previous_use_global_palette = not use_local_palette