mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 00:47:28 +01:00
Rename some color_u32_argb_premul conversion funcs
This commit is contained in:
1 parent
c7e5ca1545
commit
f3b9704e4d
5 files changed
+110
-88
No files matched your search
@@ -2517,18 +2517,18 @@ wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(
|
||||
}
|
||||
|
||||
static inline wuffs_base__color_u32_argb_premul //
|
||||
wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(uint16_t c) {
|
||||
uint32_t b5 = 0x1F & (c >> 0);
|
||||
wuffs_base__color_u16_rgb_565__as__color_u32_argb_premul(uint16_t rgb_565) {
|
||||
uint32_t b5 = 0x1F & (rgb_565 >> 0);
|
||||
uint32_t b = (b5 << 3) | (b5 >> 2);
|
||||
uint32_t g6 = 0x3F & (c >> 5);
|
||||
uint32_t g6 = 0x3F & (rgb_565 >> 5);
|
||||
uint32_t g = (g6 << 2) | (g6 >> 4);
|
||||
uint32_t r5 = 0x1F & (c >> 11);
|
||||
uint32_t r5 = 0x1F & (rgb_565 >> 11);
|
||||
uint32_t r = (r5 << 3) | (r5 >> 2);
|
||||
return 0xFF000000 | (r << 16) | (g << 8) | (b << 0);
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__color_u32_argb_premul__as_gray(
|
||||
wuffs_base__color_u32_argb_premul__as__color_u8_gray(
|
||||
wuffs_base__color_u32_argb_premul c) {
|
||||
// Work in 16-bit color.
|
||||
uint32_t cr = 0x101 * (0xFF & (c >> 16));
|
||||
@@ -2545,10 +2545,11 @@ wuffs_base__color_u32_argb_premul__as_gray(
|
||||
return (uint8_t)(weighted_average >> 24);
|
||||
}
|
||||
|
||||
// wuffs_base__premul_u32_axxx converts from non-premultiplied alpha to
|
||||
// premultiplied alpha. The "axxx" means either "argb" or "abgr".
|
||||
static inline uint32_t //
|
||||
wuffs_base__premul_u32_axxx(uint32_t nonpremul) {
|
||||
// wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul converts
|
||||
// from non-premultiplied alpha to premultiplied alpha.
|
||||
static inline wuffs_base__color_u32_argb_premul //
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
uint32_t argb_nonpremul) {
|
||||
// Multiplying by 0x101 (twice, once for alpha and once for color) converts
|
||||
// from 8-bit to 16-bit color. Shifting right by 8 undoes that.
|
||||
//
|
||||
@@ -2558,36 +2559,37 @@ wuffs_base__premul_u32_axxx(uint32_t nonpremul) {
|
||||
//
|
||||
// - ((0x80 * 0x81 ) / 0xFF ) = 0x40 = 0x40
|
||||
// - ((0x8080 * 0x8181) / 0xFFFF) >> 8 = 0x4101 >> 8 = 0x41
|
||||
uint32_t a = 0xFF & (nonpremul >> 24);
|
||||
uint32_t a = 0xFF & (argb_nonpremul >> 24);
|
||||
uint32_t a16 = a * (0x101 * 0x101);
|
||||
|
||||
uint32_t r = 0xFF & (nonpremul >> 16);
|
||||
uint32_t r = 0xFF & (argb_nonpremul >> 16);
|
||||
r = ((r * a16) / 0xFFFF) >> 8;
|
||||
uint32_t g = 0xFF & (nonpremul >> 8);
|
||||
uint32_t g = 0xFF & (argb_nonpremul >> 8);
|
||||
g = ((g * a16) / 0xFFFF) >> 8;
|
||||
uint32_t b = 0xFF & (nonpremul >> 0);
|
||||
uint32_t b = 0xFF & (argb_nonpremul >> 0);
|
||||
b = ((b * a16) / 0xFFFF) >> 8;
|
||||
|
||||
return (a << 24) | (r << 16) | (g << 8) | (b << 0);
|
||||
}
|
||||
|
||||
// wuffs_base__nonpremul_u32_axxx converts from premultiplied alpha to
|
||||
// non-premultiplied alpha. The "axxx" means either "argb" or "abgr".
|
||||
// wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul converts
|
||||
// from premultiplied alpha to non-premultiplied alpha.
|
||||
static inline uint32_t //
|
||||
wuffs_base__nonpremul_u32_axxx(uint32_t premul) {
|
||||
uint32_t a = 0xFF & (premul >> 24);
|
||||
wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul(
|
||||
wuffs_base__color_u32_argb_premul c) {
|
||||
uint32_t a = 0xFF & (c >> 24);
|
||||
if (a == 0xFF) {
|
||||
return premul;
|
||||
return c;
|
||||
} else if (a == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint32_t a16 = a * 0x101;
|
||||
|
||||
uint32_t r = 0xFF & (premul >> 16);
|
||||
uint32_t r = 0xFF & (c >> 16);
|
||||
r = ((r * (0x101 * 0xFFFF)) / a16) >> 8;
|
||||
uint32_t g = 0xFF & (premul >> 8);
|
||||
uint32_t g = 0xFF & (c >> 8);
|
||||
g = ((g * (0x101 * 0xFFFF)) / a16) >> 8;
|
||||
uint32_t b = 0xFF & (premul >> 0);
|
||||
uint32_t b = 0xFF & (c >> 0);
|
||||
b = ((b * (0x101 * 0xFFFF)) / a16) >> 8;
|
||||
|
||||
return (a << 24) | (r << 16) | (g << 8) | (b << 0);
|
||||
@@ -8766,7 +8768,7 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL: {
|
||||
uint8_t* palette = pb->private_impl.planes[3].ptr;
|
||||
return wuffs_base__premul_u32_axxx(
|
||||
return wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__load_u32le__no_bounds_check(palette +
|
||||
(4 * ((size_t)row[x]))));
|
||||
}
|
||||
@@ -8778,7 +8780,7 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
return 0xFF000000 |
|
||||
wuffs_base__load_u24le__no_bounds_check(row + (3 * ((size_t)x)));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
return wuffs_base__premul_u32_axxx(
|
||||
return wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__load_u32le__no_bounds_check(row + (4 * ((size_t)x))));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRX:
|
||||
return 0xFF000000 |
|
||||
@@ -8789,8 +8791,10 @@ wuffs_base__pixel_buffer__color_u32_at(const wuffs_base__pixel_buffer* pb,
|
||||
0xFF000000 |
|
||||
wuffs_base__load_u24le__no_bounds_check(row + (3 * ((size_t)x))));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
return wuffs_base__swap_u32_argb_abgr(wuffs_base__premul_u32_axxx(
|
||||
wuffs_base__load_u32le__no_bounds_check(row + (4 * ((size_t)x)))));
|
||||
return wuffs_base__swap_u32_argb_abgr(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__load_u32le__no_bounds_check(row +
|
||||
(4 * ((size_t)x)))));
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
|
||||
return wuffs_base__swap_u32_argb_abgr(
|
||||
@@ -8840,7 +8844,8 @@ wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
wuffs_base__store_u8__no_bounds_check(
|
||||
row + ((size_t)x), wuffs_base__color_u32_argb_premul__as_gray(color));
|
||||
row + ((size_t)x),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u8_gray(color));
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:
|
||||
@@ -8860,7 +8865,9 @@ wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
wuffs_base__store_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)), wuffs_base__nonpremul_u32_axxx(color));
|
||||
row + (4 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul(
|
||||
color));
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
@@ -8869,8 +8876,9 @@ wuffs_base__pixel_buffer__set_color_u32_at(
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
|
||||
wuffs_base__store_u32le__no_bounds_check(
|
||||
row + (4 * ((size_t)x)), wuffs_base__nonpremul_u32_axxx(
|
||||
wuffs_base__swap_u32_argb_abgr(color)));
|
||||
row + (4 * ((size_t)x)),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u32_argb_nonpremul(
|
||||
wuffs_base__swap_u32_argb_abgr(color)));
|
||||
break;
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
|
||||
@@ -9031,7 +9039,7 @@ wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src(
|
||||
wuffs_base__store_u16le__no_bounds_check(
|
||||
d + (0 * 2),
|
||||
wuffs_base__color_u32_argb_premul__as__color_u16_rgb_565(
|
||||
wuffs_base__premul_u32_axxx(
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__load_u32le__no_bounds_check(s + (0 * 4)))));
|
||||
|
||||
s += 1 * 4;
|
||||
@@ -9218,8 +9226,9 @@ wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src(
|
||||
// TODO: unroll.
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = wuffs_base__premul_u32_axxx(
|
||||
wuffs_base__load_u32le__no_bounds_check(s + (0 * 4)));
|
||||
uint32_t s0 =
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(
|
||||
wuffs_base__load_u32le__no_bounds_check(s + (0 * 4)));
|
||||
wuffs_base__store_u24le__no_bounds_check(d + (0 * 3), s0);
|
||||
|
||||
s += 1 * 4;
|
||||
@@ -9324,8 +9333,9 @@ wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(
|
||||
|
||||
while (n >= 1) {
|
||||
uint32_t s0 = wuffs_base__load_u32le__no_bounds_check(s + (0 * 4));
|
||||
wuffs_base__store_u32le__no_bounds_check(d + (0 * 4),
|
||||
wuffs_base__premul_u32_axxx(s0));
|
||||
wuffs_base__store_u32le__no_bounds_check(
|
||||
d + (0 * 4),
|
||||
wuffs_base__color_u32_argb_nonpremul__as__color_u32_argb_premul(s0));
|
||||
|
||||
s += 1 * 4;
|
||||
d += 1 * 4;
|
||||
|
||||
Reference in new issue
Block a user