diff --git a/cmd/wuffs-c/internal/cgen/base/image-public.h b/cmd/wuffs-c/internal/cgen/base/image-public.h index dc4f627f..b2f60212 100644 --- a/cmd/wuffs-c/internal/cgen/base/image-public.h +++ b/cmd/wuffs-c/internal/cgen/base/image-public.h @@ -299,7 +299,7 @@ typedef struct { inline wuffs_base__rect_ie_u32 bounds(); inline uint32_t width(); inline uint32_t height(); - inline size_t pixbuf_size(); + inline size_t pixbuf_len(); #endif // __cplusplus } wuffs_base__pixel_config; @@ -375,7 +375,7 @@ wuffs_base__pixel_config__height(wuffs_base__pixel_config* c) { // decoding into a color model different from the format's intrinsic one? For // example, decoding a JPEG image straight to RGBA instead of to YCbCr? static inline size_t // -wuffs_base__pixel_config__pixbuf_size(wuffs_base__pixel_config* c) { +wuffs_base__pixel_config__pixbuf_len(wuffs_base__pixel_config* c) { if (c) { uint64_t wh = ((uint64_t)c->private_impl.width) * ((uint64_t)c->private_impl.height); @@ -431,8 +431,8 @@ wuffs_base__pixel_config::height() { } inline size_t // -wuffs_base__pixel_config::pixbuf_size() { - return wuffs_base__pixel_config__pixbuf_size(this); +wuffs_base__pixel_config::pixbuf_len() { + return wuffs_base__pixel_config__pixbuf_len(this); } #endif // __cplusplus diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index 0d18b35f..e8a5ebda 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -132,11 +132,11 @@ const baseImagePublicH = "" + "SUBSAMPLING__440 \\\n ((wuffs_base__pixel_subsampling)0x010100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__422 \\\n ((wuffs_base__pixel_subsampling)0x101000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__420 \\\n ((wuffs_base__pixel_subsampling)0x111100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__411 \\\n ((wuffs_base__pixel_subsampling)0x202000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__410 \\\n ((wuffs_base__pixel_subsampling)0x212100)\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 6;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 4;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_y(wuffs_base__pixel_subsampling s,\n ui" + "nt32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 2;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_y(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 0;\n return (s >> shift) & 0x03;\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__pixel_format pixfmt;\n wuffs_base__pixel_subsampling pixsub;\n uint32_t width;\n uint32_t height;\n } private_impl;\n\n#ifdef __cplusplus\n inline void initialize(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height);\n inline void invalidate();\n inline bool is_valid();\n inline wuffs_base__pixel_format pixel_format();\n inline wuffs_base__pixel_subsampling pixel_subsampling();\n inline wuffs_base__rect_ie_u32 bounds();\n inline uint32_t width();\n inline uint32_t height();\n inline size_t pixbuf_size();\n#endif // __cplusplus\n\n} wuffs_base__pixel_config;\n\n// TODO: Should this function return bool? An error type?\nstatic inline void //\nwuffs_base__pixel_config__initialize(wuffs_base__pixel_config* c," + - "\n wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n if (!c) {\n return;\n }\n if (pixfmt) {\n uint64_t wh = ((uint64_t)width) * ((uint64_t)height);\n // TODO: handle things other than 1 byte per pixel.\n if (wh <= ((uint64_t)SIZE_MAX)) {\n c->private_impl.pixfmt = pixfmt;\n c->private_impl.pixsub = pixsub;\n c->private_impl.width = width;\n c->private_impl.height = height;\n return;\n }\n }\n *c = ((wuffs_base__pixel_config){});\n}\n\nstatic inline void //\nwuffs_base__pixel_config__invalidate(wuffs_base__pixel_config* c) {\n if (c) {\n *c = ((wuffs_base__pixel_config){});\n }\n}\n\nstatic inline bool //\nwuffs_base__pixel_config__is_valid(wuffs_base__pixel_config* c) {\n return c && c->private_impl.pixfmt;\n}\n\nstatic inline wuffs_base__pixel_format //\nwuffs_base__pixel_config__pixe" + - "l_format(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.pixfmt : 0;\n}\n\nstatic inline wuffs_base__pixel_subsampling //\nwuffs_base__pixel_config__pixel_subsampling(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.pixsub : 0;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__pixel_config__bounds(wuffs_base__pixel_config* c) {\n return c ? ((wuffs_base__rect_ie_u32){\n .min_incl_x = 0,\n .min_incl_y = 0,\n .max_excl_x = c->private_impl.width,\n .max_excl_y = c->private_impl.height,\n })\n : ((wuffs_base__rect_ie_u32){});\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_config__width(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.width : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_config__height(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.height : 0;\n}\n\n// TODO: this is the right API for planar (not packed) pixbufs? Should it allow\n// decoding into a color model differe" + - "nt from the format's intrinsic one? For\n// example, decoding a JPEG image straight to RGBA instead of to YCbCr?\nstatic inline size_t //\nwuffs_base__pixel_config__pixbuf_size(wuffs_base__pixel_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#ifdef __cplusplus\n\ninline void //\nwuffs_base__pixel_config::initialize(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n wuffs_base__pixel_config__initialize(this, pixfmt, pixsub, width, height);\n}\n\ninline void //\nwuffs_base__pixel_config::invalidate() {\n wuffs_base__pixel_config__invalidate(this);\n}\n\ninline bool //\nwuffs_base__pixel_config::is_valid() {\n return wuffs_base__pixel_config__is_valid(this);\n}\n\ninline wuffs_base__pixel_f" + - "ormat //\nwuffs_base__pixel_config::pixel_format() {\n return wuffs_base__pixel_config__pixel_format(this);\n}\n\ninline wuffs_base__pixel_subsampling //\nwuffs_base__pixel_config::pixel_subsampling() {\n return wuffs_base__pixel_config__pixel_subsampling(this);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__pixel_config::bounds() {\n return wuffs_base__pixel_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__pixel_config::width() {\n return wuffs_base__pixel_config__width(this);\n}\n\ninline uint32_t //\nwuffs_base__pixel_config::height() {\n return wuffs_base__pixel_config__height(this);\n}\n\ninline size_t //\nwuffs_base__pixel_config::pixbuf_size() {\n return wuffs_base__pixel_config__pixbuf_size(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__pixel_format pixfmt;\n wuffs_base__pixel_subsampling pixsub;\n uint32_t width;\n uint32_t height;\n } private_impl;\n\n#ifdef __cplusplus\n inline void initialize(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height);\n inline void invalidate();\n inline bool is_valid();\n inline wuffs_base__pixel_format pixel_format();\n inline wuffs_base__pixel_subsampling pixel_subsampling();\n inline wuffs_base__rect_ie_u32 bounds();\n inline uint32_t width();\n inline uint32_t height();\n inline size_t pixbuf_len();\n#endif // __cplusplus\n\n} wuffs_base__pixel_config;\n\n// TODO: Should this function return bool? An error type?\nstatic inline void //\nwuffs_base__pixel_config__initialize(wuffs_base__pixel_config* c,\n" + + " wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n if (!c) {\n return;\n }\n if (pixfmt) {\n uint64_t wh = ((uint64_t)width) * ((uint64_t)height);\n // TODO: handle things other than 1 byte per pixel.\n if (wh <= ((uint64_t)SIZE_MAX)) {\n c->private_impl.pixfmt = pixfmt;\n c->private_impl.pixsub = pixsub;\n c->private_impl.width = width;\n c->private_impl.height = height;\n return;\n }\n }\n *c = ((wuffs_base__pixel_config){});\n}\n\nstatic inline void //\nwuffs_base__pixel_config__invalidate(wuffs_base__pixel_config* c) {\n if (c) {\n *c = ((wuffs_base__pixel_config){});\n }\n}\n\nstatic inline bool //\nwuffs_base__pixel_config__is_valid(wuffs_base__pixel_config* c) {\n return c && c->private_impl.pixfmt;\n}\n\nstatic inline wuffs_base__pixel_format //\nwuffs_base__pixel_config__pixel" + + "_format(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.pixfmt : 0;\n}\n\nstatic inline wuffs_base__pixel_subsampling //\nwuffs_base__pixel_config__pixel_subsampling(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.pixsub : 0;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__pixel_config__bounds(wuffs_base__pixel_config* c) {\n return c ? ((wuffs_base__rect_ie_u32){\n .min_incl_x = 0,\n .min_incl_y = 0,\n .max_excl_x = c->private_impl.width,\n .max_excl_y = c->private_impl.height,\n })\n : ((wuffs_base__rect_ie_u32){});\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_config__width(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.width : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_config__height(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.height : 0;\n}\n\n// TODO: this is the right API for planar (not packed) pixbufs? Should it allow\n// decoding into a color model differen" + + "t from the format's intrinsic one? For\n// example, decoding a JPEG image straight to RGBA instead of to YCbCr?\nstatic inline size_t //\nwuffs_base__pixel_config__pixbuf_len(wuffs_base__pixel_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#ifdef __cplusplus\n\ninline void //\nwuffs_base__pixel_config::initialize(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n wuffs_base__pixel_config__initialize(this, pixfmt, pixsub, width, height);\n}\n\ninline void //\nwuffs_base__pixel_config::invalidate() {\n wuffs_base__pixel_config__invalidate(this);\n}\n\ninline bool //\nwuffs_base__pixel_config::is_valid() {\n return wuffs_base__pixel_config__is_valid(this);\n}\n\ninline wuffs_base__pixel_for" + + "mat //\nwuffs_base__pixel_config::pixel_format() {\n return wuffs_base__pixel_config__pixel_format(this);\n}\n\ninline wuffs_base__pixel_subsampling //\nwuffs_base__pixel_config::pixel_subsampling() {\n return wuffs_base__pixel_config__pixel_subsampling(this);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__pixel_config::bounds() {\n return wuffs_base__pixel_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__pixel_config::width() {\n return wuffs_base__pixel_config__width(this);\n}\n\ninline uint32_t //\nwuffs_base__pixel_config::height() {\n return wuffs_base__pixel_config__height(this);\n}\n\ninline size_t //\nwuffs_base__pixel_config::pixbuf_len() {\n return wuffs_base__pixel_config__pixbuf_len(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__range_ii_u64 work_buffer_size;\n uint64_t first_frame_io_position;\n uint32_t num_loops;\n bool first_frame_is_opaque;\n } private_impl;\n\n#ifdef __cplusplus\n inline void initialize(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint64_t work_buffer_size0,\n uint64_t work_buffer_size1,\n uint32_t num_loops,\n uint64_t first_frame_io_position,\n bool first_frame_is_opaque);\n inline void invalidate();\n inline bool is_valid();\n inline wuffs_base__range_ii_u64 work_buffer_size();\n inline uint32_t num_loops();\n inline uint64_t first_frame_io_" + "position();\n inline bool first_frame_is_opaque();\n#endif // __cplusplus\n\n} wuffs_base__image_config;\n\n// TODO: Should this function return bool? An error type?\nstatic inline void //\nwuffs_base__image_config__initialize(wuffs_base__image_config* c,\n wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint64_t work_buffer_size0,\n uint64_t work_buffer_size1,\n uint32_t num_loops,\n uint64_t first_frame_io_position,\n bool first_frame_is_opaque) {\n if (!c) {\n return;\n }\n if (wuffs_base__pixel_format__is_valid(pixfmt)) {\n c->pixcfg.private_impl.pixfmt = pixfmt;\n c->pixcfg.private_impl.pixsub = pixsub;\n c->pixcfg.private_impl.w" + diff --git a/example/gifplayer/gifplayer.c b/example/gifplayer/gifplayer.c index 032f7896..895d2400 100644 --- a/example/gifplayer/gifplayer.c +++ b/example/gifplayer/gifplayer.c @@ -225,7 +225,7 @@ size_t print_color_art(wuffs_base__pixel_buffer* pb) { // ---- const char* allocate(wuffs_base__image_config* ic) { - image_len = wuffs_base__pixel_config__pixbuf_size(&ic->pixcfg); + image_len = wuffs_base__pixel_config__pixbuf_len(&ic->pixcfg); if (image_len > (SIZE_MAX / sizeof(wuffs_base__color_u32argb))) { return "could not allocate dst buffer"; } diff --git a/fuzz/c/std/gif_fuzzer.c b/fuzz/c/std/gif_fuzzer.c index cd9ccd69..e18562d5 100644 --- a/fuzz/c/std/gif_fuzzer.c +++ b/fuzz/c/std/gif_fuzzer.c @@ -48,7 +48,7 @@ It should print "PASS", amongst other information, and exit(0). const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) { const char* ret = NULL; - void* pixbuf = NULL; + void* pixbuf_ptr = NULL; void* workbuf = NULL; // Use a {} code block so that "goto exit" doesn't trigger "jump bypasses @@ -86,22 +86,24 @@ const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) { goto exit; } - size_t pixbuf_size = wuffs_base__pixel_config__pixbuf_size(&ic.pixcfg); + size_t pixbuf_len = wuffs_base__pixel_config__pixbuf_len(&ic.pixcfg); // Don't try to allocate more than 64 MiB. - if (pixbuf_size > 64 * 1024 * 1024) { + if (pixbuf_len > 64 * 1024 * 1024) { ret = "image too large"; goto exit; } - pixbuf = malloc(pixbuf_size); - if (!pixbuf) { + pixbuf_ptr = malloc(pixbuf_len); + if (!pixbuf_ptr) { ret = "out of memory"; goto exit; } wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){}); - z = wuffs_base__pixel_buffer__set_from_slice( - &pb, &ic.pixcfg, - ((wuffs_base__slice_u8){.ptr = pixbuf, .len = pixbuf_size})); + z = wuffs_base__pixel_buffer__set_from_slice(&pb, &ic.pixcfg, + ((wuffs_base__slice_u8){ + .ptr = pixbuf_ptr, + .len = pixbuf_len, + })); if (z) { ret = z; goto exit; @@ -129,8 +131,8 @@ exit: if (workbuf) { free(workbuf); } - if (pixbuf) { - free(pixbuf); + if (pixbuf_ptr) { + free(pixbuf_ptr); } return ret; } diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index eac7dda9..33b1f0b1 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -1427,7 +1427,7 @@ typedef struct { inline wuffs_base__rect_ie_u32 bounds(); inline uint32_t width(); inline uint32_t height(); - inline size_t pixbuf_size(); + inline size_t pixbuf_len(); #endif // __cplusplus } wuffs_base__pixel_config; @@ -1503,7 +1503,7 @@ wuffs_base__pixel_config__height(wuffs_base__pixel_config* c) { // decoding into a color model different from the format's intrinsic one? For // example, decoding a JPEG image straight to RGBA instead of to YCbCr? static inline size_t // -wuffs_base__pixel_config__pixbuf_size(wuffs_base__pixel_config* c) { +wuffs_base__pixel_config__pixbuf_len(wuffs_base__pixel_config* c) { if (c) { uint64_t wh = ((uint64_t)c->private_impl.width) * ((uint64_t)c->private_impl.height); @@ -1559,8 +1559,8 @@ wuffs_base__pixel_config::height() { } inline size_t // -wuffs_base__pixel_config::pixbuf_size() { - return wuffs_base__pixel_config__pixbuf_size(this); +wuffs_base__pixel_config::pixbuf_len() { + return wuffs_base__pixel_config__pixbuf_len(this); } #endif // __cplusplus