From 0ccdece50ad0eedbfcdb2480153dfa408c177970 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 4 Dec 2020 22:53:59 +1100 Subject: [PATCH] Add swizzle_interleaved_transparent_black --- internal/cgen/base/image-public.h | 10 +++ internal/cgen/base/pixconv-submodule.c | 74 +++++++++++++++++++++++ internal/cgen/data/data.go | 19 +++--- lang/builtin/builtin.go | 2 + release/c/wuffs-unsupported-snapshot.c | 84 ++++++++++++++++++++++++++ 5 files changed, 181 insertions(+), 8 deletions(-) diff --git a/internal/cgen/base/image-public.h b/internal/cgen/base/image-public.h index f945bee8..2b0c862b 100644 --- a/internal/cgen/base/image-public.h +++ b/internal/cgen/base/image-public.h @@ -1359,11 +1359,21 @@ typedef uint64_t (*wuffs_base__pixel_swizzler__func)(uint8_t* dst_ptr, const uint8_t* src_ptr, size_t src_len); +typedef uint64_t (*wuffs_base__pixel_swizzler__transparent_black_func)( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + uint64_t num_pixels, + uint32_t dst_pixfmt_bytes_per_pixel); + typedef struct wuffs_base__pixel_swizzler__struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. struct { wuffs_base__pixel_swizzler__func func; + wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func; + uint32_t dst_pixfmt_bytes_per_pixel; uint32_t src_pixfmt_bytes_per_pixel; } private_impl; diff --git a/internal/cgen/base/pixconv-submodule.c b/internal/cgen/base/pixconv-submodule.c index 4298b1f1..2089e786 100644 --- a/internal/cgen/base/pixconv-submodule.c +++ b/internal/cgen/base/pixconv-submodule.c @@ -1687,6 +1687,39 @@ wuffs_base__pixel_swizzler__xxxx__y(uint8_t* dst_ptr, // -------- +static uint64_t // +wuffs_base__pixel_swizzler__transparent_black_src( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + uint64_t num_pixels, + uint32_t dst_pixfmt_bytes_per_pixel) { + uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel; + if (n > num_pixels) { + n = num_pixels; + } + memset(dst_ptr, 0, ((size_t)(n * dst_pixfmt_bytes_per_pixel))); + return n; +} + +static uint64_t // +wuffs_base__pixel_swizzler__transparent_black_src_over( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + uint64_t num_pixels, + uint32_t dst_pixfmt_bytes_per_pixel) { + uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel; + if (n > num_pixels) { + n = num_pixels; + } + return n; +} + +// -------- + static wuffs_base__pixel_swizzler__func // wuffs_base__pixel_swizzler__prepare__y(wuffs_base__pixel_swizzler* p, wuffs_base__pixel_format dst_pixfmt, @@ -2002,9 +2035,22 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, return wuffs_base__make_status(wuffs_base__error__bad_receiver); } p->private_impl.func = NULL; + p->private_impl.transparent_black_func = NULL; + p->private_impl.dst_pixfmt_bytes_per_pixel = 0; p->private_impl.src_pixfmt_bytes_per_pixel = 0; wuffs_base__pixel_swizzler__func func = NULL; + wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func = + NULL; + + uint32_t dst_pixfmt_bits_per_pixel = + wuffs_base__pixel_format__bits_per_pixel(&dst_pixfmt); + if ((dst_pixfmt_bits_per_pixel == 0) || + ((dst_pixfmt_bits_per_pixel & 7) != 0)) { + return wuffs_base__make_status( + wuffs_base__error__unsupported_pixel_swizzler_option); + } + uint32_t src_pixfmt_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&src_pixfmt); if ((src_pixfmt_bits_per_pixel == 0) || @@ -2015,6 +2061,18 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, // TODO: support many more formats. + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + transparent_black_func = + wuffs_base__pixel_swizzler__transparent_black_src; + break; + + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + transparent_black_func = + wuffs_base__pixel_swizzler__transparent_black_src_over; + break; + } + switch (src_pixfmt.repr) { case WUFFS_BASE__PIXEL_FORMAT__Y: func = wuffs_base__pixel_swizzler__prepare__y(p, dst_pixfmt, dst_palette, @@ -2048,6 +2106,8 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, } p->private_impl.func = func; + p->private_impl.transparent_black_func = transparent_black_func; + p->private_impl.dst_pixfmt_bytes_per_pixel = dst_pixfmt_bits_per_pixel / 8; p->private_impl.src_pixfmt_bytes_per_pixel = src_pixfmt_bits_per_pixel / 8; return wuffs_base__make_status( func ? NULL : wuffs_base__error__unsupported_pixel_swizzler_option); @@ -2083,3 +2143,17 @@ wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice( } return 0; } + +WUFFS_BASE__MAYBE_STATIC uint64_t // +wuffs_base__pixel_swizzler__swizzle_interleaved_transparent_black( + const wuffs_base__pixel_swizzler* p, + wuffs_base__slice_u8 dst, + wuffs_base__slice_u8 dst_palette, + uint64_t num_pixels) { + if (p && p->private_impl.transparent_black_func) { + return (*p->private_impl.transparent_black_func)( + dst.ptr, dst.len, dst_palette.ptr, dst_palette.len, num_pixels, + p->private_impl.dst_pixfmt_bytes_per_pixel); + } + return 0; +} diff --git a/internal/cgen/data/data.go b/internal/cgen/data/data.go index 8279ce5a..f4ca3cad 100644 --- a/internal/cgen/data/data.go +++ b/internal/cgen/data/data.go @@ -176,10 +176,10 @@ const BaseImagePublicH = "" + "" + "// --------\n\n// wuffs_base__pixel_palette__closest_element returns the index of the palette\n// element that minimizes the sum of squared differences of the four ARGB\n// channels, working in premultiplied alpha. Ties favor the smaller index.\n//\n// The palette_slice.len may equal (N*4), for N less than 256, which means that\n// only the first N palette elements are considered. It returns 0 when N is 0.\n//\n// Applying this function on a per-pixel basis will not produce whole-of-image\n// dithering.\nWUFFS_BASE__MAYBE_STATIC uint8_t //\nwuffs_base__pixel_palette__closest_element(\n wuffs_base__slice_u8 palette_slice,\n wuffs_base__pixel_format palette_format,\n wuffs_base__color_u32_argb_premul c);\n\n" + "" + - "// --------\n\n// TODO: should the func type take restrict pointers?\ntypedef uint64_t (*wuffs_base__pixel_swizzler__func)(uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n const uint8_t* src_ptr,\n size_t src_len);\n\ntypedef struct wuffs_base__pixel_swizzler__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_swizzler__func func;\n uint32_t src_pixfmt_bytes_per_pixel;\n } private_impl;\n\n#ifdef __cplusplus\n inline wuffs_base__status prepare(wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_for" + - "mat src_pixfmt,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend);\n inline uint64_t swizzle_interleaved_from_slice(\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) const;\n#endif // __cplusplus\n\n} wuffs_base__pixel_swizzler;\n\n// wuffs_base__pixel_swizzler__prepare readies the pixel swizzler so that its\n// other methods may be called.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__PIXCONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__status //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_pixfmt,\n " + - " wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend);\n\n// wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice converts pixels\n// from a source format to a destination format.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__PIXCONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC uint64_t //\nwuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(\n const wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src);\n\n#ifdef __cplusplus\n\ninline wuffs_base__status //\nwuffs_base__pixel_swizzler::prepare(wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_pixfmt,\n wuffs_base__slice_u8 src_pal" + - "ette,\n wuffs_base__pixel_blend blend) {\n return wuffs_base__pixel_swizzler__prepare(this, dst_pixfmt, dst_palette,\n src_pixfmt, src_palette, blend);\n}\n\nuint64_t //\nwuffs_base__pixel_swizzler::swizzle_interleaved_from_slice(\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) const {\n return wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(\n this, dst, dst_palette, src);\n}\n\n#endif // __cplusplus\n" + + "// --------\n\n// TODO: should the func type take restrict pointers?\ntypedef uint64_t (*wuffs_base__pixel_swizzler__func)(uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n const uint8_t* src_ptr,\n size_t src_len);\n\ntypedef uint64_t (*wuffs_base__pixel_swizzler__transparent_black_func)(\n uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n uint64_t num_pixels,\n uint32_t dst_pixfmt_bytes_per_pixel);\n\ntypedef struct wuffs_base__pixel_swizzler__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_swizzler__func func;\n wuffs_base__pixel_swizzler__transpa" + + "rent_black_func transparent_black_func;\n uint32_t dst_pixfmt_bytes_per_pixel;\n uint32_t src_pixfmt_bytes_per_pixel;\n } private_impl;\n\n#ifdef __cplusplus\n inline wuffs_base__status prepare(wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_pixfmt,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend);\n inline uint64_t swizzle_interleaved_from_slice(\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) const;\n#endif // __cplusplus\n\n} wuffs_base__pixel_swizzler;\n\n// wuffs_base__pixel_swizzler__prepare readies the pixel swizzler so that its\n// other methods may be called.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__PIXCONV sub-module, not\n// just WUFFS_CONFIG__MOD" + + "ULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC wuffs_base__status //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_pixfmt,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend);\n\n// wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice converts pixels\n// from a source format to a destination format.\n//\n// For modular builds that divide the base module into sub-modules, using this\n// function requires the WUFFS_CONFIG__MODULE__BASE__PIXCONV sub-module, not\n// just WUFFS_CONFIG__MODULE__BASE__CORE.\nWUFFS_BASE__MAYBE_STATIC uint64_t //\nwuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(\n const wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n " + + " wuffs_base__slice_u8 src);\n\n#ifdef __cplusplus\n\ninline wuffs_base__status //\nwuffs_base__pixel_swizzler::prepare(wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_pixfmt,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n return wuffs_base__pixel_swizzler__prepare(this, dst_pixfmt, dst_palette,\n src_pixfmt, src_palette, blend);\n}\n\nuint64_t //\nwuffs_base__pixel_swizzler::swizzle_interleaved_from_slice(\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) const {\n return wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(\n this, dst, dst_palette, src);\n}\n\n#endif // __cplusplus\n" + "" const BaseIOPrivateH = "" + @@ -588,6 +588,8 @@ const BasePixConvSubmoduleC = "" + "n3 = src_len / 3;\n size_t len = (dst_len4 < src_len3) ? dst_len4 : src_len3;\n uint8_t* d = dst_ptr;\n const uint8_t* s = src_ptr;\n size_t n = len;\n\n // TODO: unroll.\n\n while (n >= 1) {\n wuffs_base__store_u32le__no_bounds_check(\n d + (0 * 4),\n 0xFF000000 | wuffs_base__load_u24le__no_bounds_check(s + (0 * 3)));\n\n s += 1 * 3;\n d += 1 * 4;\n n -= 1;\n }\n\n return len;\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__xxxx__y(uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n const uint8_t* src_ptr,\n size_t src_len) {\n size_t dst_len4 = dst_len / 4;\n size_t len = (dst_len4 < src_len) ? dst_len4 : src_len;\n uint8_t* d = dst_ptr;\n const uint8_t* s = src_ptr;\n size_t n = len;\n\n // TODO: unroll.\n\n while (n >= 1) {\n wuffs_base__store_u32le__no_bounds_check(\n d + (" + "0 * 4), 0xFF000000 | (0x010101 * (uint32_t)s[0]));\n\n s += 1 * 1;\n d += 1 * 4;\n n -= 1;\n }\n\n return len;\n}\n\n" + "" + + "// --------\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__transparent_black_src(\n uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n uint64_t num_pixels,\n uint32_t dst_pixfmt_bytes_per_pixel) {\n uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel;\n if (n > num_pixels) {\n n = num_pixels;\n }\n memset(dst_ptr, 0, ((size_t)(n * dst_pixfmt_bytes_per_pixel)));\n return n;\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__transparent_black_src_over(\n uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n uint64_t num_pixels,\n uint32_t dst_pixfmt_bytes_per_pixel) {\n uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel;\n if (n > num_pixels) {\n n = num_pixels;\n }\n return n;\n}\n\n" + + "" + "// --------\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__y(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__y;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n return wuffs_base__pixel_swizzler__xxx__y;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WU" + "FFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__xxxx__y;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n 1024) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_1_1;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n if (wuffs_base__pixel_swizzler__squash_align4_bgr_565_888(\n dst_palette, src_palette) != 25" + "6) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n 1024) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n 1024) {\n " + @@ -600,10 +602,11 @@ const BasePixConvSubmoduleC = "" + "\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgrx(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n " + " wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__bgrx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__xxx__xxxx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n return wuffs_base__pixel_swizzler__bgrw__bgrx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n return wuffs_base__pixel_swizzler__copy_4_4;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\n" + "" + - "// --------\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__status //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_pixfmt,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n if (!p) {\n return wuffs_base__make_status(wuffs_base__error__bad_receiver);\n }\n p->private_impl.func = NULL;\n p->private_impl.src_pixfmt_bytes_per_pixel = 0;\n\n wuffs_base__pixel_swizzler__func func = NULL;\n uint32_t src_pixfmt_bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(&src_pixfmt);\n if ((src_pixfmt_bits_per_pixel == 0) ||\n ((src_pixfmt_bits_per_pixel & 7) != 0)) {\n return wuffs_base__make_status(\n wuffs_base__error__unsupported_pixel_swizzler_option);\n }\n\n // TODO: support many more for" + - "mats.\n\n switch (src_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__Y:\n func = wuffs_base__pixel_swizzler__prepare__y(p, dst_pixfmt, dst_palette,\n src_palette, blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:\n func = wuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n func = wuffs_base__pixel_swizzler__prepare__bgr(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n func = wuffs_base__pixel_swizzler__prepare__bgra_nonpremul(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n func = wuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n\n case WUFFS_BASE" + - "__PIXEL_FORMAT__BGRX:\n func = wuffs_base__pixel_swizzler__prepare__bgrx(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n }\n\n p->private_impl.func = func;\n p->private_impl.src_pixfmt_bytes_per_pixel = src_pixfmt_bits_per_pixel / 8;\n return wuffs_base__make_status(\n func ? NULL : wuffs_base__error__unsupported_pixel_swizzler_option);\n}\n\nWUFFS_BASE__MAYBE_STATIC uint64_t //\nwuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(\n const wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n const uint8_t** ptr_iop_r,\n const uint8_t* io2_r) {\n if (p && p->private_impl.func) {\n const uint8_t* iop_r = *ptr_iop_r;\n uint64_t n = (*p->private_impl.func)(dst.ptr, dst.len, dst_palette.ptr,\n dst_palette.len, iop_r,\n (size_t)(io2_r - iop_r));\n *ptr_iop_r += n * p->private_impl.src_pixfmt_bytes_per_pixel;\n return n;\n }\n return 0;\n}\n\n" + - "WUFFS_BASE__MAYBE_STATIC uint64_t //\nwuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(\n const wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n if (p && p->private_impl.func) {\n return (*p->private_impl.func)(dst.ptr, dst.len, dst_palette.ptr,\n dst_palette.len, src.ptr, src.len);\n }\n return 0;\n}\n" + + "// --------\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__status //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_pixfmt,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n if (!p) {\n return wuffs_base__make_status(wuffs_base__error__bad_receiver);\n }\n p->private_impl.func = NULL;\n p->private_impl.transparent_black_func = NULL;\n p->private_impl.dst_pixfmt_bytes_per_pixel = 0;\n p->private_impl.src_pixfmt_bytes_per_pixel = 0;\n\n wuffs_base__pixel_swizzler__func func = NULL;\n wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func =\n NULL;\n\n uint32_t dst_pixfmt_bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(&dst_pixfmt);\n if ((dst_pixfmt_bits_per_pixel == " + + "0) ||\n ((dst_pixfmt_bits_per_pixel & 7) != 0)) {\n return wuffs_base__make_status(\n wuffs_base__error__unsupported_pixel_swizzler_option);\n }\n\n uint32_t src_pixfmt_bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(&src_pixfmt);\n if ((src_pixfmt_bits_per_pixel == 0) ||\n ((src_pixfmt_bits_per_pixel & 7) != 0)) {\n return wuffs_base__make_status(\n wuffs_base__error__unsupported_pixel_swizzler_option);\n }\n\n // TODO: support many more formats.\n\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n transparent_black_func =\n wuffs_base__pixel_swizzler__transparent_black_src;\n break;\n\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n transparent_black_func =\n wuffs_base__pixel_swizzler__transparent_black_src_over;\n break;\n }\n\n switch (src_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__Y:\n func = wuffs_base__pixel_swizzler__prepare__y(p, dst_pixfmt, dst_palette,\n src_palette" + + ", blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:\n func = wuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n func = wuffs_base__pixel_swizzler__prepare__bgr(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n func = wuffs_base__pixel_swizzler__prepare__bgra_nonpremul(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n func = wuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n func = wuffs_base__pixel_swizzler__prepare__bgrx(\n p, dst_pixfmt, dst_palette, src_palette, blend);\n break;\n }\n\n p->private_impl.func = func;\n p->private_impl.transparent_b" + + "lack_func = transparent_black_func;\n p->private_impl.dst_pixfmt_bytes_per_pixel = dst_pixfmt_bits_per_pixel / 8;\n p->private_impl.src_pixfmt_bytes_per_pixel = src_pixfmt_bits_per_pixel / 8;\n return wuffs_base__make_status(\n func ? NULL : wuffs_base__error__unsupported_pixel_swizzler_option);\n}\n\nWUFFS_BASE__MAYBE_STATIC uint64_t //\nwuffs_base__pixel_swizzler__swizzle_interleaved_from_reader(\n const wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n const uint8_t** ptr_iop_r,\n const uint8_t* io2_r) {\n if (p && p->private_impl.func) {\n const uint8_t* iop_r = *ptr_iop_r;\n uint64_t n = (*p->private_impl.func)(dst.ptr, dst.len, dst_palette.ptr,\n dst_palette.len, iop_r,\n (size_t)(io2_r - iop_r));\n *ptr_iop_r += n * p->private_impl.src_pixfmt_bytes_per_pixel;\n return n;\n }\n return 0;\n}\n\nWUFFS_BASE__MAYBE_STATIC uint64_t //\nwuffs_base__pixel_swizzler__swizzl" + + "e_interleaved_from_slice(\n const wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n if (p && p->private_impl.func) {\n return (*p->private_impl.func)(dst.ptr, dst.len, dst_palette.ptr,\n dst_palette.len, src.ptr, src.len);\n }\n return 0;\n}\n\nWUFFS_BASE__MAYBE_STATIC uint64_t //\nwuffs_base__pixel_swizzler__swizzle_interleaved_transparent_black(\n const wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n uint64_t num_pixels) {\n if (p && p->private_impl.transparent_black_func) {\n return (*p->private_impl.transparent_black_func)(\n dst.ptr, dst.len, dst_palette.ptr, dst_palette.len, num_pixels,\n p->private_impl.dst_pixfmt_bytes_per_pixel);\n }\n return 0;\n}\n" + "" const BaseUTF8SubmoduleC = "" + diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go index c63f0b32..8ae8a953 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -518,6 +518,8 @@ var Funcs = []string{ "dst: slice u8, dst_palette: slice u8, src: io_reader) u64", "pixel_swizzler.swizzle_interleaved_from_slice!(" + "dst: slice u8, dst_palette: slice u8, src: slice u8) u64", + "pixel_swizzler.swizzle_interleaved_transparent_black!(" + + "dst: slice u8, dst_palette: slice u8, num_pixels: u64) u64", } var Interfaces = []string{ diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index b9ab7ed3..729e27b3 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -4116,11 +4116,21 @@ typedef uint64_t (*wuffs_base__pixel_swizzler__func)(uint8_t* dst_ptr, const uint8_t* src_ptr, size_t src_len); +typedef uint64_t (*wuffs_base__pixel_swizzler__transparent_black_func)( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + uint64_t num_pixels, + uint32_t dst_pixfmt_bytes_per_pixel); + typedef struct wuffs_base__pixel_swizzler__struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. struct { wuffs_base__pixel_swizzler__func func; + wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func; + uint32_t dst_pixfmt_bytes_per_pixel; uint32_t src_pixfmt_bytes_per_pixel; } private_impl; @@ -15171,6 +15181,39 @@ wuffs_base__pixel_swizzler__xxxx__y(uint8_t* dst_ptr, // -------- +static uint64_t // +wuffs_base__pixel_swizzler__transparent_black_src( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + uint64_t num_pixels, + uint32_t dst_pixfmt_bytes_per_pixel) { + uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel; + if (n > num_pixels) { + n = num_pixels; + } + memset(dst_ptr, 0, ((size_t)(n * dst_pixfmt_bytes_per_pixel))); + return n; +} + +static uint64_t // +wuffs_base__pixel_swizzler__transparent_black_src_over( + uint8_t* dst_ptr, + size_t dst_len, + uint8_t* dst_palette_ptr, + size_t dst_palette_len, + uint64_t num_pixels, + uint32_t dst_pixfmt_bytes_per_pixel) { + uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel; + if (n > num_pixels) { + n = num_pixels; + } + return n; +} + +// -------- + static wuffs_base__pixel_swizzler__func // wuffs_base__pixel_swizzler__prepare__y(wuffs_base__pixel_swizzler* p, wuffs_base__pixel_format dst_pixfmt, @@ -15486,9 +15529,22 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, return wuffs_base__make_status(wuffs_base__error__bad_receiver); } p->private_impl.func = NULL; + p->private_impl.transparent_black_func = NULL; + p->private_impl.dst_pixfmt_bytes_per_pixel = 0; p->private_impl.src_pixfmt_bytes_per_pixel = 0; wuffs_base__pixel_swizzler__func func = NULL; + wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func = + NULL; + + uint32_t dst_pixfmt_bits_per_pixel = + wuffs_base__pixel_format__bits_per_pixel(&dst_pixfmt); + if ((dst_pixfmt_bits_per_pixel == 0) || + ((dst_pixfmt_bits_per_pixel & 7) != 0)) { + return wuffs_base__make_status( + wuffs_base__error__unsupported_pixel_swizzler_option); + } + uint32_t src_pixfmt_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&src_pixfmt); if ((src_pixfmt_bits_per_pixel == 0) || @@ -15499,6 +15555,18 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, // TODO: support many more formats. + switch (blend) { + case WUFFS_BASE__PIXEL_BLEND__SRC: + transparent_black_func = + wuffs_base__pixel_swizzler__transparent_black_src; + break; + + case WUFFS_BASE__PIXEL_BLEND__SRC_OVER: + transparent_black_func = + wuffs_base__pixel_swizzler__transparent_black_src_over; + break; + } + switch (src_pixfmt.repr) { case WUFFS_BASE__PIXEL_FORMAT__Y: func = wuffs_base__pixel_swizzler__prepare__y(p, dst_pixfmt, dst_palette, @@ -15532,6 +15600,8 @@ wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p, } p->private_impl.func = func; + p->private_impl.transparent_black_func = transparent_black_func; + p->private_impl.dst_pixfmt_bytes_per_pixel = dst_pixfmt_bits_per_pixel / 8; p->private_impl.src_pixfmt_bytes_per_pixel = src_pixfmt_bits_per_pixel / 8; return wuffs_base__make_status( func ? NULL : wuffs_base__error__unsupported_pixel_swizzler_option); @@ -15568,6 +15638,20 @@ wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice( return 0; } +WUFFS_BASE__MAYBE_STATIC uint64_t // +wuffs_base__pixel_swizzler__swizzle_interleaved_transparent_black( + const wuffs_base__pixel_swizzler* p, + wuffs_base__slice_u8 dst, + wuffs_base__slice_u8 dst_palette, + uint64_t num_pixels) { + if (p && p->private_impl.transparent_black_func) { + return (*p->private_impl.transparent_black_func)( + dst.ptr, dst.len, dst_palette.ptr, dst_palette.len, num_pixels, + p->private_impl.dst_pixfmt_bytes_per_pixel); + } + return 0; +} + #endif // !defined(WUFFS_CONFIG__MODULES) || // defined(WUFFS_CONFIG__MODULE__BASE) || // defined(WUFFS_CONFIG__MODULE__BASE__PIXCONV)