mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Add swizzle_interleaved_transparent_black
This commit is contained in:
1 parent
fa17982be0
commit
0ccdece50a
5 files changed
+181
-8
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user