diff --git a/cmd/wuffs-c/internal/cgen/base/image-public.h b/cmd/wuffs-c/internal/cgen/base/image-public.h index 0a716f5e..172b0547 100644 --- a/cmd/wuffs-c/internal/cgen/base/image-public.h +++ b/cmd/wuffs-c/internal/cgen/base/image-public.h @@ -33,11 +33,13 @@ typedef uint32_t wuffs_base__color_u32argb; // - bits 30 .. 28 encodes color (and channel order, in terms of memory). // - bits 27 .. 26 are reserved. // - bits 25 .. 24 encodes transparency. -// - bit 23 indicates big-endian/MSB-first (as opposed to little/LSB). -// - bit 22 indicates floating point (as opposed to integer). -// - bits 21 .. 20 are the number of planes, minus 1. Zero means packed. -// - bits 19 .. 16 encodes the number of bits (depth) in an index value. -// Zero means direct, not palette-indexed. +// - bits 23 .. 21 are reserved. +// - bit 20 indicates big-endian/MSB-first (as opposed to little/LSB). +// - bit 19 indicates floating point (as opposed to integer). +// - bit 18 indicates palette-indexed. The number-of-planes (the next +// field) will be zero, as the format is considered packed, +// but the 8-bit N-BGRA color data is stored in plane 3. +// - bits 17 .. 16 are the number of planes, minus 1. Zero means packed. // - bits 15 .. 12 encodes the number of bits (depth) in the 3rd channel. // - bits 11 .. 8 encodes the number of bits (depth) in the 2nd channel. // - bits 7 .. 4 encodes the number of bits (depth) in the 1st channel. @@ -56,10 +58,12 @@ typedef uint32_t wuffs_base__color_u32argb; // For direct formats with N > 1 channels, those channels can be laid out in // either 1 (packed) or N (planar) planes. For example, RGBA data is usually // packed, but YUV data is usually planar, due to chroma subsampling (for -// details, see the wuffs_base__pixel_subsampling type). For indexed formats, -// the palette (always 256 × 4 bytes) holds up to 4 packed bytes of color data -// per index value, and there is only 1 plane (for the index). The distance -// between successive palette elements is always 4 bytes. +// details, see the wuffs_base__pixel_subsampling type). +// +// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bits per +// channel non-alpha-premultiplied BGRA color data. There is only 1 plane (for +// the index), as the format is considered packed. Plane 0 holds the per-pixel +// indices. Plane 3 is re-purposed to hold the per-index colors. // // The color field is encoded in 3 bits: // - 0 means A (Alpha). @@ -98,7 +102,7 @@ typedef uint32_t wuffs_base__color_u32argb; // - 14 means a bit depth of 48. // - 15 means a bit depth of 64. // -// For example, wuffs_base__pixel_format 0x3280BBBB is a natural format for +// For example, wuffs_base__pixel_format 0x3210BBBB is a natural format for // decoding a PNG image - network byte order (also known as big-endian), // packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor // with alpha (RGBA). In memory order: @@ -148,35 +152,30 @@ typedef uint32_t wuffs_base__pixel_format; #define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \ ((wuffs_base__pixel_format)0x13000008) +#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \ + ((wuffs_base__pixel_format)0x22040008) + #define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x20000888) #define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x21008888) -#define WUFFS_BASE__PIXEL_FORMAT__BGRX_INDEXED \ - ((wuffs_base__pixel_format)0x21088888) #define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \ ((wuffs_base__pixel_format)0x22008888) -#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED \ - ((wuffs_base__pixel_format)0x22088888) #define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \ ((wuffs_base__pixel_format)0x23008888) #define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x30000888) #define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x31008888) -#define WUFFS_BASE__PIXEL_FORMAT__RGBX_INDEXED \ - ((wuffs_base__pixel_format)0x31088888) #define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL \ ((wuffs_base__pixel_format)0x32008888) -#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_INDEXED \ - ((wuffs_base__pixel_format)0x32088888) #define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \ ((wuffs_base__pixel_format)0x33008888) -#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40200888) -#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41308888) +#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40020888) +#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41038888) #define WUFFS_BASE__PIXEL_FORMAT__YUVA_NONPREMUL \ - ((wuffs_base__pixel_format)0x42308888) + ((wuffs_base__pixel_format)0x42038888) -#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50200888) -#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51308888) +#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50020888) +#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51038888) static inline bool // wuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) { @@ -185,15 +184,18 @@ wuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) { static inline bool // wuffs_base__pixel_format__is_indexed(wuffs_base__pixel_format f) { - return ((f >> 16) & 0x0F) != 0; + return (f >> 18) & 0x01; +} + +static inline uint32_t // +wuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) { + return f ? (((f >> 16) & 0x03) + 1) : 0; } #define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4 -static inline uint32_t // -wuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) { - return f ? (((f >> 20) & 0x03) + 1) : 0; -} +#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__INDEX_PLANE 0 +#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE 3 // -------- @@ -379,7 +381,11 @@ 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); - // TODO: handle things other than 1 byte per pixel. + // TODO: handle things other than 1 byte per pixel. When doing so, consider + // that the +1024 below could overflow. + if (wuffs_base__pixel_format__is_indexed(c->private_impl.pixfmt)) { + wh += 1024; + } return (size_t)wh; } return 0; @@ -787,16 +793,15 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX]; - uint8_t palette[1024]; // TODO: color spaces. } private_impl; #ifdef __cplusplus inline wuffs_base__status set_from_slice(wuffs_base__pixel_config* pixcfg, wuffs_base__slice_u8 pixbuf_memory); - inline void set_palette(wuffs_base__slice_u8 palette); inline wuffs_base__table_u8 plane(uint32_t p); inline wuffs_base__slice_u8 palette(); + inline void set_palette(wuffs_base__slice_u8 palette); #endif // __cplusplus } wuffs_base__pixel_buffer; @@ -812,30 +817,42 @@ wuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b, if (!pixcfg) { return wuffs_base__error__bad_argument; } + + uint8_t* ptr = pixbuf_memory.ptr; + size_t len = pixbuf_memory.len; + if (wuffs_base__pixel_format__is_indexed(pixcfg->private_impl.pixfmt)) { + // Split a 1024 byte chunk (256 palette entries × 4 bytes per entry) from + // the start of pixbuf_memory. We split from the start, not the end, so + // that the remaining ptr has the same alignment as the original ptr, up to + // an alignment of 1024. + if (len < 1024) { + return wuffs_base__error__bad_argument_length_too_short; + } + wuffs_base__table_u8* tab = + &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE]; + tab->ptr = ptr; + tab->width = 1024; + tab->height = 1; + tab->stride = 1024; + ptr += 1024; + len -= 1024; + } + // TODO: don't assume 1 byte per pixel. Don't assume packed. uint64_t wh = ((uint64_t)pixcfg->private_impl.width) * ((uint64_t)pixcfg->private_impl.height); - if (wh > pixbuf_memory.len) { + if (wh > len) { return wuffs_base__error__bad_argument_length_too_short; } b->pixcfg = *pixcfg; wuffs_base__table_u8* tab = &b->private_impl.planes[0]; - tab->ptr = pixbuf_memory.ptr; + tab->ptr = ptr; tab->width = pixcfg->private_impl.width; tab->height = pixcfg->private_impl.height; tab->stride = pixcfg->private_impl.width; return NULL; } -// The palette argument is ignored unless its length is exactly 1024. -static inline void // -wuffs_base__pixel_buffer__set_palette(wuffs_base__pixel_buffer* b, - wuffs_base__slice_u8 palette) { - if (b && palette.ptr && (palette.len == 1024)) { - memmove(b->private_impl.palette, palette.ptr, 1024); - } -} - static inline wuffs_base__table_u8 // wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) { return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX)) @@ -843,13 +860,32 @@ wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) { : ((wuffs_base__table_u8){}); } -// wuffs_base__pixel_buffer__palette returns the palette that the pixel data -// can index. The backing array is inside b and has length 1024. +// wuffs_base__pixel_buffer__palette returns the palette color data. If +// non-empty, it will have length 1024. static inline wuffs_base__slice_u8 // wuffs_base__pixel_buffer__palette(wuffs_base__pixel_buffer* b) { - return b ? ((wuffs_base__slice_u8){.ptr = b->private_impl.palette, - .len = 1024}) - : ((wuffs_base__slice_u8){}); + if (b && + wuffs_base__pixel_format__is_indexed(b->pixcfg.private_impl.pixfmt)) { + wuffs_base__table_u8* tab = + &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE]; + if ((tab->width == 1024) && (tab->height == 1)) { + return ((wuffs_base__slice_u8){ + .ptr = tab->ptr, + .len = 1024, + }); + } + } + return ((wuffs_base__slice_u8){}); +} + +// The palette argument is ignored unless its length is exactly 1024. +static inline void // +wuffs_base__pixel_buffer__set_palette(wuffs_base__pixel_buffer* b, + wuffs_base__slice_u8 palette) { + wuffs_base__slice_u8 dst = wuffs_base__pixel_buffer__palette(b); + if ((dst.len == 1024) && (palette.len == 1024)) { + memmove(dst.ptr, palette.ptr, 1024); + } } #ifdef __cplusplus @@ -860,11 +896,6 @@ wuffs_base__pixel_buffer::set_from_slice(wuffs_base__pixel_config* pixcfg, return wuffs_base__pixel_buffer__set_from_slice(this, pixcfg, pixbuf_memory); } -inline void // -wuffs_base__pixel_buffer::set_palette(wuffs_base__slice_u8 palette) { - wuffs_base__pixel_buffer__set_palette(this, palette); -} - inline wuffs_base__table_u8 // wuffs_base__pixel_buffer::plane(uint32_t p) { return wuffs_base__pixel_buffer__plane(this, p); @@ -875,6 +906,11 @@ wuffs_base__pixel_buffer::palette() { return wuffs_base__pixel_buffer__palette(this); } +inline void // +wuffs_base__pixel_buffer::set_palette(wuffs_base__slice_u8 palette) { + wuffs_base__pixel_buffer__set_palette(this, palette); +} + #endif // __cplusplus // -------- diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index 46d484f6..bba3de9a 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -117,15 +117,15 @@ const baseImagePublicH = "" + "" + "// ---------------- Images\n\n// wuffs_base__color_u32argb is an 8 bit per channel Alpha, Red, Green, Blue\n// color, as a uint32_t value. It is in word order, not byte order: its value\n// is always 0xAARRGGBB, regardless of endianness. It uses premultiplied alpha.\ntypedef uint32_t wuffs_base__color_u32argb;\n\n" + "" + - "// --------\n\n// wuffs_base__pixel_format encodes the format of the bytes that constitute an\n// image frame's pixel data. Its bits:\n// - bit 31 is reserved.\n// - bits 30 .. 28 encodes color (and channel order, in terms of memory).\n// - bits 27 .. 26 are reserved.\n// - bits 25 .. 24 encodes transparency.\n// - bit 23 indicates big-endian/MSB-first (as opposed to little/LSB).\n// - bit 22 indicates floating point (as opposed to integer).\n// - bits 21 .. 20 are the number of planes, minus 1. Zero means packed.\n// - bits 19 .. 16 encodes the number of bits (depth) in an index value.\n// Zero means direct, not palette-indexed.\n// - bits 15 .. 12 encodes the number of bits (depth) in the 3rd channel.\n// - bits 11 .. 8 encodes the number of bits (depth) in the 2nd channel.\n// - bits 7 .. 4 encodes the number of bits (depth) in the 1st channel.\n// - bits 3 .. 0 encodes the number of bits (depth) in the 0th channel.\n//\n// The bit fields of a wuffs_base__pixel_format " + - "are not independent. For\n// example, the number of planes should not be greater than the number of\n// channels. Similarly, bits 15..4 are unused (and should be zero) if bits\n// 31..24 (color and transparency) together imply only 1 channel (gray, no\n// alpha) and floating point samples should mean a bit depth of 16, 32 or 64.\n//\n// Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA\n// (2 channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4\n// channels: cyan, magenta, yellow, black).\n//\n// For direct formats with N > 1 channels, those channels can be laid out in\n// either 1 (packed) or N (planar) planes. For example, RGBA data is usually\n// packed, but YUV data is usually planar, due to chroma subsampling (for\n// details, see the wuffs_base__pixel_subsampling type). For indexed formats,\n// the palette (always 256 × 4 bytes) holds up to 4 packed bytes of color data\n// per index value, and there is only 1 plane (for the index). The distance\n// between successive palet" + - "te elements is always 4 bytes.\n//\n// The color field is encoded in 3 bits:\n// - 0 means A (Alpha).\n// - 1 means Y or YA (Gray, Alpha).\n// - 2 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).\n// - 3 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).\n// - 4 means YUV or YUVA (Luma, Chroma-blue, Chroma-red, Alpha).\n// - 5 means CMY or CMYK (Cyan, Magenta, Yellow, Black).\n// - all other values are reserved.\n//\n// In Wuffs, channels are given in memory order (also known as byte order),\n// regardless of endianness, since the C type for the pixel data is an array of\n// bytes, not an array of uint32_t. For example, packed BGRA with 8 bits per\n// channel means that the bytes in memory are always Blue, Green, Red then\n// Alpha. On big-endian systems, that is the uint32_t 0xBBGGRRAA. On\n// little-endian, 0xAARRGGBB.\n//\n// When the color field (3 bits) encodes multiple options, the transparency\n// field (2 bits) distinguishes them:\n// - 0 means ful" + - "ly opaque, no extra channels\n// - 1 means fully opaque, one extra channel (X or K, padding or black).\n// - 2 means one extra alpha channel, other channels are non-premultiplied.\n// - 3 means one extra alpha channel, other channels are premultiplied.\n//\n// The zero wuffs_base__pixel_format value is an invalid pixel format, as it is\n// invalid to combine the zero color (alpha only) with the zero transparency.\n//\n// Bit depth is encoded in 4 bits:\n// - 0 means the channel or index is unused.\n// - x means a bit depth of x, for x in the range 1..8.\n// - 9 means a bit depth of 10.\n// - 10 means a bit depth of 12.\n// - 11 means a bit depth of 16.\n// - 12 means a bit depth of 24.\n// - 13 means a bit depth of 32.\n// - 14 means a bit depth of 48.\n// - 15 means a bit depth of 64.\n//\n// For example, wuffs_base__pixel_format 0x3280BBBB is a natural format for\n// decoding a PNG image - network byte order (also known as big-endian),\n// packed, non-premultiplied alpha - that happens to be 16-bit-depth tru" + - "ecolor\n// with alpha (RGBA). In memory order:\n//\n// ptr+0 ptr+1 ptr+2 ptr+3 ptr+4 ptr+5 ptr+6 ptr+7\n// Rhi Rlo Ghi Glo Bhi Blo Ahi Alo\n//\n// For example, the value wuffs_base__pixel_format 0x20000565 means BGR with no\n// alpha or padding, 5/6/5 bits for blue/green/red, packed 2 bytes per pixel,\n// laid out LSB-first in memory order:\n//\n// ptr+0........... ptr+1...........\n// MSB LSB MSB LSB\n// G₂G₁G₀B₄B₃B₂B₁B₀ R₄R₃R₂R₁R₀G₅G₄G₃\n//\n// On little-endian systems (but not big-endian), this Wuffs pixel format value\n// (0x20000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the\n// SDL2 (Simple DirectMedia Layer 2) library's SDL_PIXELFORMAT_RGB565 and the\n// Skia library's kRGB_565_SkColorType. Note BGR in Wuffs versus RGB in the\n// other libraries.\n//\n// Regardless of endianness, this Wuffs pixel format value (0x20000565)\n// corresponds to the V4L2 (Video For Linux 2) library's V4L2_PIX_FMT_RGB565\n// and the Wayland-" + - "DRM library's WL_DRM_FORMAT_RGB565.\n//\n// Different software libraries name their pixel formats (and especially their\n// channel order) either according to memory layout or as bits of a native\n// integer type like uint32_t. The two conventions differ because of a system's\n// endianness. As mentioned earlier, Wuffs pixel formats are always in memory\n// order. More detail of other software libraries' naming conventions is in the\n// Pixel Format Guide at https://afrantzis.github.io/pixel-format-guide/\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_format__num_planes instead.\ntypedef uint32_t wuffs_base__pixel_format;\n\n// Common 8-bit-depth pixel formats. This list is not exhaustive; not all valid\n// wuffs_base__pixel_format values are present.\n\n#define WUFFS_BASE__PIXEL_FORMAT__INVALID ((wuffs_base__pixel_format)0x00000000)\n\n#define WUFFS_BASE__PIXEL_FORMAT__A ((wuffs_base__pixel_format)0x02000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__" + - "Y ((wuffs_base__pixel_format)0x10000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x12000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \\\n ((wuffs_base__pixel_format)0x13000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x20000888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x21008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRX_INDEXED \\\n ((wuffs_base__pixel_format)0x21088888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x22008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED \\\n ((wuffs_base__pixel_format)0x22088888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \\\n ((wuffs_base__pixel_format)0x23008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x30000888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x31008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBX_INDEXED \\\n ((wuffs_base__pixel_format)0x31088888)\n#define WUFFS_BASE__PIXEL_FORMAT_" + - "_RGBA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x32008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_INDEXED \\\n ((wuffs_base__pixel_format)0x32088888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \\\n ((wuffs_base__pixel_format)0x33008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40200888)\n#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41308888)\n#define WUFFS_BASE__PIXEL_FORMAT__YUVA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x42308888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50200888)\n#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51308888)\n\nstatic inline bool //\nwuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) {\n return f != 0;\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_indexed(wuffs_base__pixel_format f) {\n return ((f >> 16) & 0x0F) != 0;\n}\n\n#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4\n\nstatic inline uint32_t //\nwuffs_base__pixel_format__num_planes(wuffs_base__pixel_fo" + - "rmat f) {\n return f ? (((f >> 20) & 0x03) + 1) : 0;\n}\n\n" + + "// --------\n\n// wuffs_base__pixel_format encodes the format of the bytes that constitute an\n// image frame's pixel data. Its bits:\n// - bit 31 is reserved.\n// - bits 30 .. 28 encodes color (and channel order, in terms of memory).\n// - bits 27 .. 26 are reserved.\n// - bits 25 .. 24 encodes transparency.\n// - bits 23 .. 21 are reserved.\n// - bit 20 indicates big-endian/MSB-first (as opposed to little/LSB).\n// - bit 19 indicates floating point (as opposed to integer).\n// - bit 18 indicates palette-indexed. The number-of-planes (the next\n// field) will be zero, as the format is considered packed,\n// but the 8-bit N-BGRA color data is stored in plane 3.\n// - bits 17 .. 16 are the number of planes, minus 1. Zero means packed.\n// - bits 15 .. 12 encodes the number of bits (depth) in the 3rd channel.\n// - bits 11 .. 8 encodes the number of bits (depth) in the 2nd channel.\n// - bits 7 .. 4 encodes the number of bits (depth) in the 1st channe" + + "l.\n// - bits 3 .. 0 encodes the number of bits (depth) in the 0th channel.\n//\n// The bit fields of a wuffs_base__pixel_format are not independent. For\n// example, the number of planes should not be greater than the number of\n// channels. Similarly, bits 15..4 are unused (and should be zero) if bits\n// 31..24 (color and transparency) together imply only 1 channel (gray, no\n// alpha) and floating point samples should mean a bit depth of 16, 32 or 64.\n//\n// Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA\n// (2 channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4\n// channels: cyan, magenta, yellow, black).\n//\n// For direct formats with N > 1 channels, those channels can be laid out in\n// either 1 (packed) or N (planar) planes. For example, RGBA data is usually\n// packed, but YUV data is usually planar, due to chroma subsampling (for\n// details, see the wuffs_base__pixel_subsampling type).\n//\n// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bits" + + " per\n// channel non-alpha-premultiplied BGRA color data. There is only 1 plane (for\n// the index), as the format is considered packed. Plane 0 holds the per-pixel\n// indices. Plane 3 is re-purposed to hold the per-index colors.\n//\n// The color field is encoded in 3 bits:\n// - 0 means A (Alpha).\n// - 1 means Y or YA (Gray, Alpha).\n// - 2 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).\n// - 3 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).\n// - 4 means YUV or YUVA (Luma, Chroma-blue, Chroma-red, Alpha).\n// - 5 means CMY or CMYK (Cyan, Magenta, Yellow, Black).\n// - all other values are reserved.\n//\n// In Wuffs, channels are given in memory order (also known as byte order),\n// regardless of endianness, since the C type for the pixel data is an array of\n// bytes, not an array of uint32_t. For example, packed BGRA with 8 bits per\n// channel means that the bytes in memory are always Blue, Green, Red then\n// Alpha. On big-endian systems, tha" + + "t is the uint32_t 0xBBGGRRAA. On\n// little-endian, 0xAARRGGBB.\n//\n// When the color field (3 bits) encodes multiple options, the transparency\n// field (2 bits) distinguishes them:\n// - 0 means fully opaque, no extra channels\n// - 1 means fully opaque, one extra channel (X or K, padding or black).\n// - 2 means one extra alpha channel, other channels are non-premultiplied.\n// - 3 means one extra alpha channel, other channels are premultiplied.\n//\n// The zero wuffs_base__pixel_format value is an invalid pixel format, as it is\n// invalid to combine the zero color (alpha only) with the zero transparency.\n//\n// Bit depth is encoded in 4 bits:\n// - 0 means the channel or index is unused.\n// - x means a bit depth of x, for x in the range 1..8.\n// - 9 means a bit depth of 10.\n// - 10 means a bit depth of 12.\n// - 11 means a bit depth of 16.\n// - 12 means a bit depth of 24.\n// - 13 means a bit depth of 32.\n// - 14 means a bit depth of 48.\n// - 15 means a bit depth of 64.\n//\n// For example, wuffs_ba" + + "se__pixel_format 0x3210BBBB is a natural format for\n// decoding a PNG image - network byte order (also known as big-endian),\n// packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor\n// with alpha (RGBA). In memory order:\n//\n// ptr+0 ptr+1 ptr+2 ptr+3 ptr+4 ptr+5 ptr+6 ptr+7\n// Rhi Rlo Ghi Glo Bhi Blo Ahi Alo\n//\n// For example, the value wuffs_base__pixel_format 0x20000565 means BGR with no\n// alpha or padding, 5/6/5 bits for blue/green/red, packed 2 bytes per pixel,\n// laid out LSB-first in memory order:\n//\n// ptr+0........... ptr+1...........\n// MSB LSB MSB LSB\n// G₂G₁G₀B₄B₃B₂B₁B₀ R₄R₃R₂R₁R₀G₅G₄G₃\n//\n// On little-endian systems (but not big-endian), this Wuffs pixel format value\n// (0x20000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the\n// SDL2 (Simple DirectMedia Layer 2) library's SDL_PIXELFORMAT_RGB565 and the\n// Skia library's kRGB_565_SkColorType. Note BGR in Wuffs versus RGB i" + + "n the\n// other libraries.\n//\n// Regardless of endianness, this Wuffs pixel format value (0x20000565)\n// corresponds to the V4L2 (Video For Linux 2) library's V4L2_PIX_FMT_RGB565\n// and the Wayland-DRM library's WL_DRM_FORMAT_RGB565.\n//\n// Different software libraries name their pixel formats (and especially their\n// channel order) either according to memory layout or as bits of a native\n// integer type like uint32_t. The two conventions differ because of a system's\n// endianness. As mentioned earlier, Wuffs pixel formats are always in memory\n// order. More detail of other software libraries' naming conventions is in the\n// Pixel Format Guide at https://afrantzis.github.io/pixel-format-guide/\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_format__num_planes instead.\ntypedef uint32_t wuffs_base__pixel_format;\n\n// Common 8-bit-depth pixel formats. This list is not exhaustive; not all valid\n// wuffs_base__pixel_format values are prese" + + "nt.\n\n#define WUFFS_BASE__PIXEL_FORMAT__INVALID ((wuffs_base__pixel_format)0x00000000)\n\n#define WUFFS_BASE__PIXEL_FORMAT__A ((wuffs_base__pixel_format)0x02000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__Y ((wuffs_base__pixel_format)0x10000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x12000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \\\n ((wuffs_base__pixel_format)0x13000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x22040008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x20000888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x21008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x22008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \\\n ((wuffs_base__pixel_format)0x23008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x30000888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x31008888)\n#define WUFFS_" + + "BASE__PIXEL_FORMAT__RGBA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x32008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \\\n ((wuffs_base__pixel_format)0x33008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40020888)\n#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41038888)\n#define WUFFS_BASE__PIXEL_FORMAT__YUVA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x42038888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50020888)\n#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51038888)\n\nstatic inline bool //\nwuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) {\n return f != 0;\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_indexed(wuffs_base__pixel_format f) {\n return (f >> 18) & 0x01;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) {\n return f ? (((f >> 16) & 0x03) + 1) : 0;\n}\n\n#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4\n\n#define WUFFS_BASE__PIXEL_FORMAT" + + "__INDEXED__INDEX_PLANE 0\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE 3\n\n" + "" + "// --------\n\n// wuffs_base__pixel_subsampling encodes the mapping of pixel space coordinates\n// (x, y) to pixel buffer indices (i, j). That mapping can differ for each\n// plane p. For a depth of 8 bits (1 byte), the p'th plane's sample starts at\n// (planes[p].ptr + (j * planes[p].stride) + i).\n//\n// For packed pixel formats, the mapping is trivial: i = x and j = y. For\n// planar pixel formats, the mapping can differ due to chroma subsampling. For\n// example, consider a three plane YUV pixel format with 4:2:2 subsampling. For\n// the luma (Y) channel, there is one sample for every pixel, but for the\n// chroma (U, V) channels, there is one sample for every two pixels: pairs of\n// horizontally adjacent pixels form one macropixel, i = x / 2 and j == y. In\n// general, for a given p:\n// - i = (x + bias_x) >> shift_x.\n// - j = (y + bias_y) >> shift_y.\n// where biases and shifts are in the range 0..3 and 0..2 respectively.\n//\n// In general, the biases will be zero after decoding an image. However, making\n// a sub-im" + "age may change the bias, since the (x, y) coordinates are relative\n// to the sub-image's top-left origin, but the backing pixel buffers were\n// created relative to the original image's origin.\n//\n// For each plane p, each of those four numbers (biases and shifts) are encoded\n// in two bits, which combine to form an 8 bit unsigned integer:\n//\n// e_p = (bias_x << 6) | (shift_x << 4) | (bias_y << 2) | (shift_y << 0)\n//\n// Those e_p values (e_0 for the first plane, e_1 for the second plane, etc)\n// combine to form a wuffs_base__pixel_subsampling value:\n//\n// pixsub = (e_3 << 24) | (e_2 << 16) | (e_1 << 8) | (e_0 << 0)\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_subsampling__bias_x instead.\ntypedef uint32_t wuffs_base__pixel_subsampling;\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__NONE ((wuffs_base__pixel_subsampling)0)\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__444 \\\n ((wuffs_base__pixel_subsampling)0x000000)\n#define WUFFS_BASE__PIXEL_" + @@ -135,8 +135,8 @@ const baseImagePublicH = "" + "// --------\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__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" + + "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. When doing so, consider\n // that the +1024 below could overflow.\n if (wuffs_base__pixel_format__is_indexed(c->private_impl.pixfmt)) {\n wh += 1024;\n }\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_co" + + "nfig__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_format //\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 workbuf_len;\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 workbuf_len0,\n uint64_t workbuf_len1,\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 workbuf_len();\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 workbuf_len0,\n uint64_t workbuf_len1,\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.width = width;\n c->pixcfg.pr" + @@ -155,10 +155,11 @@ const baseImagePublicH = "" + "posal disposal) {\n wuffs_base__frame_config__update(this, bounds, duration, index, io_position,\n blend, disposal);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__frame_config::bounds() {\n return wuffs_base__frame_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::width() {\n return wuffs_base__frame_config__width(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::height() {\n return wuffs_base__frame_config__height(this);\n}\n\ninline wuffs_base__flicks //\nwuffs_base__frame_config::duration() {\n return wuffs_base__frame_config__duration(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::index() {\n return wuffs_base__frame_config__index(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::io_position() {\n return wuffs_base__frame_config__io_position(this);\n}\n\ninline wuffs_base__animation_blend //\nwuffs_base__frame_config::blend() {\n return wuffs_base__frame_config__blend(this);\n}\n\ninline wuffs_base__animation_disposal //\nwuffs_base__fr" + "ame_config::disposal() {\n return wuffs_base__frame_config__disposal(this);\n}\n\n#endif // __cplusplus\n\n" + "" + - "// --------\n\ntypedef struct {\n wuffs_base__pixel_config pixcfg;\n\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX];\n uint8_t palette[1024];\n // TODO: color spaces.\n } private_impl;\n\n#ifdef __cplusplus\n inline wuffs_base__status set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory);\n inline void set_palette(wuffs_base__slice_u8 palette);\n inline wuffs_base__table_u8 plane(uint32_t p);\n inline wuffs_base__slice_u8 palette();\n#endif // __cplusplus\n\n} wuffs_base__pixel_buffer;\n\nstatic inline wuffs_base__status //\nwuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,\n wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n if (!b) {\n return wuffs_base_" + - "_error__bad_receiver;\n }\n *b = ((wuffs_base__pixel_buffer){});\n if (!pixcfg) {\n return wuffs_base__error__bad_argument;\n }\n // TODO: don't assume 1 byte per pixel. Don't assume packed.\n uint64_t wh = ((uint64_t)pixcfg->private_impl.width) *\n ((uint64_t)pixcfg->private_impl.height);\n if (wh > pixbuf_memory.len) {\n return wuffs_base__error__bad_argument_length_too_short;\n }\n b->pixcfg = *pixcfg;\n wuffs_base__table_u8* tab = &b->private_impl.planes[0];\n tab->ptr = pixbuf_memory.ptr;\n tab->width = pixcfg->private_impl.width;\n tab->height = pixcfg->private_impl.height;\n tab->stride = pixcfg->private_impl.width;\n return NULL;\n}\n\n// The palette argument is ignored unless its length is exactly 1024.\nstatic inline void //\nwuffs_base__pixel_buffer__set_palette(wuffs_base__pixel_buffer* b,\n wuffs_base__slice_u8 palette) {\n if (b && palette.ptr && (palette.len == 1024)) {\n memmove(b->private_impl.palette, palette.ptr, 1024);\n }\n}\n\nstatic inlin" + - "e wuffs_base__table_u8 //\nwuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {\n return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))\n ? b->private_impl.planes[p]\n : ((wuffs_base__table_u8){});\n}\n\n// wuffs_base__pixel_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 //\nwuffs_base__pixel_buffer__palette(wuffs_base__pixel_buffer* b) {\n return b ? ((wuffs_base__slice_u8){.ptr = b->private_impl.palette,\n .len = 1024})\n : ((wuffs_base__slice_u8){});\n}\n\n#ifdef __cplusplus\n\ninline wuffs_base__status //\nwuffs_base__pixel_buffer::set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n return wuffs_base__pixel_buffer__set_from_slice(this, pixcfg, pixbuf_memory);\n}\n\ninline void //\nwuffs_base__pixel_buffer::set_palette(wuffs_base__slice_u8 " + - "palette) {\n wuffs_base__pixel_buffer__set_palette(this, palette);\n}\n\ninline wuffs_base__table_u8 //\nwuffs_base__pixel_buffer::plane(uint32_t p) {\n return wuffs_base__pixel_buffer__plane(this, p);\n}\n\ninline wuffs_base__slice_u8 //\nwuffs_base__pixel_buffer::palette() {\n return wuffs_base__pixel_buffer__palette(this);\n}\n\n#endif // __cplusplus\n\n" + + "// --------\n\ntypedef struct {\n wuffs_base__pixel_config pixcfg;\n\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX];\n // TODO: color spaces.\n } private_impl;\n\n#ifdef __cplusplus\n inline wuffs_base__status set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory);\n inline wuffs_base__table_u8 plane(uint32_t p);\n inline wuffs_base__slice_u8 palette();\n inline void set_palette(wuffs_base__slice_u8 palette);\n#endif // __cplusplus\n\n} wuffs_base__pixel_buffer;\n\nstatic inline wuffs_base__status //\nwuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,\n wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n if (!b) {\n return wuffs_base__error__bad_receiver;\n }\n " + + " *b = ((wuffs_base__pixel_buffer){});\n if (!pixcfg) {\n return wuffs_base__error__bad_argument;\n }\n\n uint8_t* ptr = pixbuf_memory.ptr;\n size_t len = pixbuf_memory.len;\n if (wuffs_base__pixel_format__is_indexed(pixcfg->private_impl.pixfmt)) {\n // Split a 1024 byte chunk (256 palette entries × 4 bytes per entry) from\n // the start of pixbuf_memory. We split from the start, not the end, so\n // that the remaining ptr has the same alignment as the original ptr, up to\n // an alignment of 1024.\n if (len < 1024) {\n return wuffs_base__error__bad_argument_length_too_short;\n }\n wuffs_base__table_u8* tab =\n &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];\n tab->ptr = ptr;\n tab->width = 1024;\n tab->height = 1;\n tab->stride = 1024;\n ptr += 1024;\n len -= 1024;\n }\n\n // TODO: don't assume 1 byte per pixel. Don't assume packed.\n uint64_t wh = ((uint64_t)pixcfg->private_impl.width) *\n ((uint64_t)pixcfg->private_impl.height);\n i" + + "f (wh > len) {\n return wuffs_base__error__bad_argument_length_too_short;\n }\n b->pixcfg = *pixcfg;\n wuffs_base__table_u8* tab = &b->private_impl.planes[0];\n tab->ptr = ptr;\n tab->width = pixcfg->private_impl.width;\n tab->height = pixcfg->private_impl.height;\n tab->stride = pixcfg->private_impl.width;\n return NULL;\n}\n\nstatic inline wuffs_base__table_u8 //\nwuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {\n return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))\n ? b->private_impl.planes[p]\n : ((wuffs_base__table_u8){});\n}\n\n// wuffs_base__pixel_buffer__palette returns the palette color data. If\n// non-empty, it will have length 1024.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__pixel_buffer__palette(wuffs_base__pixel_buffer* b) {\n if (b &&\n wuffs_base__pixel_format__is_indexed(b->pixcfg.private_impl.pixfmt)) {\n wuffs_base__table_u8* tab =\n &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];\n if ((tab->" + + "width == 1024) && (tab->height == 1)) {\n return ((wuffs_base__slice_u8){\n .ptr = tab->ptr,\n .len = 1024,\n });\n }\n }\n return ((wuffs_base__slice_u8){});\n}\n\n// The palette argument is ignored unless its length is exactly 1024.\nstatic inline void //\nwuffs_base__pixel_buffer__set_palette(wuffs_base__pixel_buffer* b,\n wuffs_base__slice_u8 palette) {\n wuffs_base__slice_u8 dst = wuffs_base__pixel_buffer__palette(b);\n if ((dst.len == 1024) && (palette.len == 1024)) {\n memmove(dst.ptr, palette.ptr, 1024);\n }\n}\n\n#ifdef __cplusplus\n\ninline wuffs_base__status //\nwuffs_base__pixel_buffer::set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n return wuffs_base__pixel_buffer__set_from_slice(this, pixcfg, pixbuf_memory);\n}\n\ninline wuffs_base__table_u8 //\nwuffs_base__pixel_buffer::plane(uint32_t p) {\n return wuffs_base__pixel_buffer__plane(this, p);\n}\n\ninline wuffs_base__s" + + "lice_u8 //\nwuffs_base__pixel_buffer::palette() {\n return wuffs_base__pixel_buffer__palette(this);\n}\n\ninline void //\nwuffs_base__pixel_buffer::set_palette(wuffs_base__slice_u8 palette) {\n wuffs_base__pixel_buffer__set_palette(this, palette);\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 uint8_t TODO;\n } private_impl;\n\n#ifdef __cplusplus\n#endif // __cplusplus\n\n} wuffs_base__decode_frame_options;\n\n#ifdef __cplusplus\n\n#endif // __cplusplus\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n" + "" diff --git a/example/gifplayer/gifplayer.c b/example/gifplayer/gifplayer.c index 9830d235..9f38c4ef 100644 --- a/example/gifplayer/gifplayer.c +++ b/example/gifplayer/gifplayer.c @@ -153,15 +153,16 @@ void compose(wuffs_base__pixel_buffer* pb, wuffs_base__rect_ie_u32 bounds) { if (palette.len != 1024) { return; } + wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(pb, 0); size_t width = wuffs_base__pixel_config__width(&pb->pixcfg); size_t y; for (y = bounds.min_incl_y; y < bounds.max_excl_y; y++) { size_t x; wuffs_base__color_u32argb* d = dst_buffer + (y * width) + bounds.min_incl_x; - uint8_t* s = image_buffer + (y * width) + bounds.min_incl_x; + uint8_t* s = tab.ptr + (y * tab.stride) + bounds.min_incl_x; for (x = bounds.min_incl_x; x < bounds.max_excl_x; x++) { uint32_t index = *s++; - wuffs_base__color_u32argb c = load_u32le(palette.ptr + 4 * index); + wuffs_base__color_u32argb c = load_u32le(palette.ptr + (4 * index)); if (c) { *d = c; } diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index f87ee2fc..aa2adf16 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -1161,11 +1161,13 @@ typedef uint32_t wuffs_base__color_u32argb; // - bits 30 .. 28 encodes color (and channel order, in terms of memory). // - bits 27 .. 26 are reserved. // - bits 25 .. 24 encodes transparency. -// - bit 23 indicates big-endian/MSB-first (as opposed to little/LSB). -// - bit 22 indicates floating point (as opposed to integer). -// - bits 21 .. 20 are the number of planes, minus 1. Zero means packed. -// - bits 19 .. 16 encodes the number of bits (depth) in an index value. -// Zero means direct, not palette-indexed. +// - bits 23 .. 21 are reserved. +// - bit 20 indicates big-endian/MSB-first (as opposed to little/LSB). +// - bit 19 indicates floating point (as opposed to integer). +// - bit 18 indicates palette-indexed. The number-of-planes (the next +// field) will be zero, as the format is considered packed, +// but the 8-bit N-BGRA color data is stored in plane 3. +// - bits 17 .. 16 are the number of planes, minus 1. Zero means packed. // - bits 15 .. 12 encodes the number of bits (depth) in the 3rd channel. // - bits 11 .. 8 encodes the number of bits (depth) in the 2nd channel. // - bits 7 .. 4 encodes the number of bits (depth) in the 1st channel. @@ -1184,10 +1186,12 @@ typedef uint32_t wuffs_base__color_u32argb; // For direct formats with N > 1 channels, those channels can be laid out in // either 1 (packed) or N (planar) planes. For example, RGBA data is usually // packed, but YUV data is usually planar, due to chroma subsampling (for -// details, see the wuffs_base__pixel_subsampling type). For indexed formats, -// the palette (always 256 × 4 bytes) holds up to 4 packed bytes of color data -// per index value, and there is only 1 plane (for the index). The distance -// between successive palette elements is always 4 bytes. +// details, see the wuffs_base__pixel_subsampling type). +// +// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bits per +// channel non-alpha-premultiplied BGRA color data. There is only 1 plane (for +// the index), as the format is considered packed. Plane 0 holds the per-pixel +// indices. Plane 3 is re-purposed to hold the per-index colors. // // The color field is encoded in 3 bits: // - 0 means A (Alpha). @@ -1226,7 +1230,7 @@ typedef uint32_t wuffs_base__color_u32argb; // - 14 means a bit depth of 48. // - 15 means a bit depth of 64. // -// For example, wuffs_base__pixel_format 0x3280BBBB is a natural format for +// For example, wuffs_base__pixel_format 0x3210BBBB is a natural format for // decoding a PNG image - network byte order (also known as big-endian), // packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor // with alpha (RGBA). In memory order: @@ -1276,35 +1280,30 @@ typedef uint32_t wuffs_base__pixel_format; #define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \ ((wuffs_base__pixel_format)0x13000008) +#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \ + ((wuffs_base__pixel_format)0x22040008) + #define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x20000888) #define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x21008888) -#define WUFFS_BASE__PIXEL_FORMAT__BGRX_INDEXED \ - ((wuffs_base__pixel_format)0x21088888) #define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \ ((wuffs_base__pixel_format)0x22008888) -#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED \ - ((wuffs_base__pixel_format)0x22088888) #define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \ ((wuffs_base__pixel_format)0x23008888) #define WUFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x30000888) #define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x31008888) -#define WUFFS_BASE__PIXEL_FORMAT__RGBX_INDEXED \ - ((wuffs_base__pixel_format)0x31088888) #define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL \ ((wuffs_base__pixel_format)0x32008888) -#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_INDEXED \ - ((wuffs_base__pixel_format)0x32088888) #define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \ ((wuffs_base__pixel_format)0x33008888) -#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40200888) -#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41308888) +#define WUFFS_BASE__PIXEL_FORMAT__YUV ((wuffs_base__pixel_format)0x40020888) +#define WUFFS_BASE__PIXEL_FORMAT__YUVK ((wuffs_base__pixel_format)0x41038888) #define WUFFS_BASE__PIXEL_FORMAT__YUVA_NONPREMUL \ - ((wuffs_base__pixel_format)0x42308888) + ((wuffs_base__pixel_format)0x42038888) -#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50200888) -#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51308888) +#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x50020888) +#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x51038888) static inline bool // wuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) { @@ -1313,15 +1312,18 @@ wuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) { static inline bool // wuffs_base__pixel_format__is_indexed(wuffs_base__pixel_format f) { - return ((f >> 16) & 0x0F) != 0; + return (f >> 18) & 0x01; +} + +static inline uint32_t // +wuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) { + return f ? (((f >> 16) & 0x03) + 1) : 0; } #define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4 -static inline uint32_t // -wuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) { - return f ? (((f >> 20) & 0x03) + 1) : 0; -} +#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__INDEX_PLANE 0 +#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE 3 // -------- @@ -1507,7 +1509,11 @@ 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); - // TODO: handle things other than 1 byte per pixel. + // TODO: handle things other than 1 byte per pixel. When doing so, consider + // that the +1024 below could overflow. + if (wuffs_base__pixel_format__is_indexed(c->private_impl.pixfmt)) { + wh += 1024; + } return (size_t)wh; } return 0; @@ -1915,16 +1921,15 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX]; - uint8_t palette[1024]; // TODO: color spaces. } private_impl; #ifdef __cplusplus inline wuffs_base__status set_from_slice(wuffs_base__pixel_config* pixcfg, wuffs_base__slice_u8 pixbuf_memory); - inline void set_palette(wuffs_base__slice_u8 palette); inline wuffs_base__table_u8 plane(uint32_t p); inline wuffs_base__slice_u8 palette(); + inline void set_palette(wuffs_base__slice_u8 palette); #endif // __cplusplus } wuffs_base__pixel_buffer; @@ -1940,30 +1945,42 @@ wuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b, if (!pixcfg) { return wuffs_base__error__bad_argument; } + + uint8_t* ptr = pixbuf_memory.ptr; + size_t len = pixbuf_memory.len; + if (wuffs_base__pixel_format__is_indexed(pixcfg->private_impl.pixfmt)) { + // Split a 1024 byte chunk (256 palette entries × 4 bytes per entry) from + // the start of pixbuf_memory. We split from the start, not the end, so + // that the remaining ptr has the same alignment as the original ptr, up to + // an alignment of 1024. + if (len < 1024) { + return wuffs_base__error__bad_argument_length_too_short; + } + wuffs_base__table_u8* tab = + &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE]; + tab->ptr = ptr; + tab->width = 1024; + tab->height = 1; + tab->stride = 1024; + ptr += 1024; + len -= 1024; + } + // TODO: don't assume 1 byte per pixel. Don't assume packed. uint64_t wh = ((uint64_t)pixcfg->private_impl.width) * ((uint64_t)pixcfg->private_impl.height); - if (wh > pixbuf_memory.len) { + if (wh > len) { return wuffs_base__error__bad_argument_length_too_short; } b->pixcfg = *pixcfg; wuffs_base__table_u8* tab = &b->private_impl.planes[0]; - tab->ptr = pixbuf_memory.ptr; + tab->ptr = ptr; tab->width = pixcfg->private_impl.width; tab->height = pixcfg->private_impl.height; tab->stride = pixcfg->private_impl.width; return NULL; } -// The palette argument is ignored unless its length is exactly 1024. -static inline void // -wuffs_base__pixel_buffer__set_palette(wuffs_base__pixel_buffer* b, - wuffs_base__slice_u8 palette) { - if (b && palette.ptr && (palette.len == 1024)) { - memmove(b->private_impl.palette, palette.ptr, 1024); - } -} - static inline wuffs_base__table_u8 // wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) { return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX)) @@ -1971,13 +1988,32 @@ wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) { : ((wuffs_base__table_u8){}); } -// wuffs_base__pixel_buffer__palette returns the palette that the pixel data -// can index. The backing array is inside b and has length 1024. +// wuffs_base__pixel_buffer__palette returns the palette color data. If +// non-empty, it will have length 1024. static inline wuffs_base__slice_u8 // wuffs_base__pixel_buffer__palette(wuffs_base__pixel_buffer* b) { - return b ? ((wuffs_base__slice_u8){.ptr = b->private_impl.palette, - .len = 1024}) - : ((wuffs_base__slice_u8){}); + if (b && + wuffs_base__pixel_format__is_indexed(b->pixcfg.private_impl.pixfmt)) { + wuffs_base__table_u8* tab = + &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE]; + if ((tab->width == 1024) && (tab->height == 1)) { + return ((wuffs_base__slice_u8){ + .ptr = tab->ptr, + .len = 1024, + }); + } + } + return ((wuffs_base__slice_u8){}); +} + +// The palette argument is ignored unless its length is exactly 1024. +static inline void // +wuffs_base__pixel_buffer__set_palette(wuffs_base__pixel_buffer* b, + wuffs_base__slice_u8 palette) { + wuffs_base__slice_u8 dst = wuffs_base__pixel_buffer__palette(b); + if ((dst.len == 1024) && (palette.len == 1024)) { + memmove(dst.ptr, palette.ptr, 1024); + } } #ifdef __cplusplus @@ -1988,11 +2024,6 @@ wuffs_base__pixel_buffer::set_from_slice(wuffs_base__pixel_config* pixcfg, return wuffs_base__pixel_buffer__set_from_slice(this, pixcfg, pixbuf_memory); } -inline void // -wuffs_base__pixel_buffer::set_palette(wuffs_base__slice_u8 palette) { - wuffs_base__pixel_buffer__set_palette(this, palette); -} - inline wuffs_base__table_u8 // wuffs_base__pixel_buffer::plane(uint32_t p) { return wuffs_base__pixel_buffer__plane(this, p); @@ -2003,6 +2034,11 @@ wuffs_base__pixel_buffer::palette() { return wuffs_base__pixel_buffer__palette(this); } +inline void // +wuffs_base__pixel_buffer::set_palette(wuffs_base__slice_u8 palette) { + wuffs_base__pixel_buffer__set_palette(this, palette); +} + #endif // __cplusplus // -------- @@ -6477,7 +6513,7 @@ wuffs_gif__decoder__decode_image_config(wuffs_gif__decoder* self, (self->private_impl.f_frame_rect_y1 == self->private_impl.f_height)); if (a_dst != NULL) { wuffs_base__image_config__initialize( - a_dst, 570984584, 0, self->private_impl.f_width, + a_dst, 570687496, 0, self->private_impl.f_width, self->private_impl.f_height, ((uint64_t)(self->private_impl.f_width)), ((uint64_t)(self->private_impl.f_width)), v_num_loops, self->private_impl.f_frame_config_io_position, v_ffio); diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs index 8f129f79..98b3a5a3 100644 --- a/std/gif/decode_gif.wuffs +++ b/std/gif/decode_gif.wuffs @@ -142,9 +142,9 @@ pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_ // TODO: rename initialize to set? // // TODO: a Wuffs (not just C) name for the - // WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED magic pixfmt constant. + // WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL magic pixfmt constant. args.dst.initialize!( - pixfmt:0x22088888, + pixfmt:0x22040008, pixsub:0, width:this.width, height:this.height, @@ -560,6 +560,8 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 3] = 0x00 } + // TODO: remove the set_palette method. Instead, call palette and + // copy_from_slice. args.dst.set_palette!(palette:this.palettes[this.which_palette][:]) // Other GIF implementations accept GIF files that aren't completely spec diff --git a/test/c/std/gif.c b/test/c/std/gif.c index e6cfbe3e..49489a2a 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -287,10 +287,10 @@ bool do_test_wuffs_gif_decode(const char* filename, return false; } if (wuffs_base__pixel_config__pixel_format(&ic.pixcfg) != - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED) { + WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL) { FAIL("pixel_format: got 0x%08" PRIX32 ", want 0x%08" PRIX32, wuffs_base__pixel_config__pixel_format(&ic.pixcfg), - WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED); + WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL); return false; }