std/etc2: merge alphas and colors fields

This commit is contained in:
Nigel Tao
2025-06-10 16:20:52 +10:00
parent 9833880b78
commit 054fae77d3
2 changed files with 20 additions and 32 deletions

View File

@@ -9574,8 +9574,7 @@ struct wuffs_etc2__decoder__struct {
} private_impl;
struct {
uint64_t f_alphas[64];
uint64_t f_colors[64];
uint64_t f_colors[2][64];
uint8_t f_buffer[4096];
struct {
@@ -44830,7 +44829,7 @@ wuffs_etc2__decoder__from_src_to_colors(
*scratch |= ((uint64_t)(num_bits_0));
}
}
self->private_data.f_alphas[v_bi] = t_0;
self->private_data.f_colors[0u][v_bi] = t_0;
}
}
{
@@ -44860,7 +44859,7 @@ wuffs_etc2__decoder__from_src_to_colors(
*scratch |= ((uint64_t)(num_bits_1));
}
}
self->private_data.f_colors[v_bi] = t_1;
self->private_data.f_colors[1u][v_bi] = t_1;
}
v_bi += 1u;
}
@@ -44911,7 +44910,7 @@ wuffs_etc2__decoder__from_colors_to_buffer__choosy_default(
bool v_flip = false;
while (v_bi < self->private_impl.f_num_buffered_blocks) {
v_color = self->private_data.f_colors[v_bi];
v_color = self->private_data.f_colors[1u][v_bi];
v_diff = ((v_color & 8589934592u) != 0u);
v_tran = ( ! v_diff && (self->private_impl.f_pixfmt == 2197850248u));
if ( ! v_diff && (self->private_impl.f_pixfmt != 2197850248u)) {
@@ -45283,7 +45282,7 @@ wuffs_etc2__decoder__from_alphas_to_buffer(
uint32_t v_o = 0;
while (v_bi < self->private_impl.f_num_buffered_blocks) {
v_alpha = self->private_data.f_alphas[v_bi];
v_alpha = self->private_data.f_colors[0u][v_bi];
v_a0 = ((uint32_t)((v_alpha >> 56u)));
v_multiplier = ((uint32_t)(((v_alpha >> 52u) & 15u)));
v_which = ((uint32_t)(((v_alpha >> 48u) & 15u)));
@@ -45373,11 +45372,7 @@ wuffs_etc2__decoder__from_colors_to_buffer_unsigned(
v_nbb = wuffs_base__u32__min(self->private_impl.f_num_buffered_blocks, 32u);
while (v_bi < v_nbb) {
if (a_input == 0u) {
v_color = self->private_data.f_alphas[v_bi];
} else {
v_color = self->private_data.f_colors[v_bi];
}
v_color = self->private_data.f_colors[a_input][v_bi];
v_c0 = ((((uint32_t)((v_color >> 56u))) * 8u) + 4u);
v_multiplier = ((uint32_t)(((v_color >> 52u) & 15u)));
v_multiplier *= 8u;
@@ -45437,11 +45432,7 @@ wuffs_etc2__decoder__from_colors_to_buffer_signed(
v_nbb = wuffs_base__u32__min(self->private_impl.f_num_buffered_blocks, 32u);
while (v_bi < v_nbb) {
if (a_input == 0u) {
v_color = self->private_data.f_alphas[v_bi];
} else {
v_color = self->private_data.f_colors[v_bi];
}
v_color = self->private_data.f_colors[a_input][v_bi];
v_c0 = (((uint32_t)((v_color >> 56u))) * 8u);
if (v_c0 < 1024u) {
} else if (v_c0 == 1024u) {

View File

@@ -63,8 +63,13 @@ pub struct decoder? implements base.image_decoder(
swizzler : base.pixel_swizzler,
util : base.utility,
) + (
alphas : array[64] base.u64,
colors : array[64] base.u64,
// Usually, with 8 (instead of 16) bytes per block, colors[0] is unused
// and colors[1] holds color codes.
//
// For RGBA8, colors[0] and colors[1] hold alpha and color codes.
//
// For RG11U / RG11S, colors[0] and colors[1] hold red and green codes.
colors : array[2] array[64] base.u64,
// buffer holds 64 blocks. Each block is 4×4 pixels, 64 bytes.
buffer : array[4096] base.u8,
@@ -293,9 +298,9 @@ pri func decoder.from_src_to_colors?(src: base.io_reader) {
assert bi < 64 via "a < b: a < c; c <= b"(c: this.num_buffered_blocks)
if (this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL) or
(this.pixfmt == base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE) {
this.alphas[bi] = args.src.read_u64be?()
this.colors[0][bi] = args.src.read_u64be?()
}
this.colors[bi] = args.src.read_u64be?()
this.colors[1][bi] = args.src.read_u64be?()
bi += 1
}
}
@@ -317,7 +322,7 @@ pri func decoder.from_colors_to_buffer!(),
while bi < this.num_buffered_blocks {
assert bi < 64 via "a < b: a < c; c <= b"(c: this.num_buffered_blocks)
color = this.colors[bi]
color = this.colors[1][bi]
diff = (color & 0x2_0000_0000) <> 0
tran = (not diff) and (this.pixfmt == base.PIXEL_FORMAT__BGRA_BINARY)
@@ -782,7 +787,7 @@ pri func decoder.from_alphas_to_buffer!() {
while bi < this.num_buffered_blocks {
assert bi < 64 via "a < b: a < c; c <= b"(c: this.num_buffered_blocks)
alpha = this.alphas[bi]
alpha = this.colors[0][bi]
a0 = (alpha >> 56) as base.u32
multiplier = ((alpha >> 52) & 0x0F) as base.u32
@@ -848,11 +853,7 @@ pri func decoder.from_colors_to_buffer_unsigned!(input: base.u32[..= 1], dst_byt
nbb = this.num_buffered_blocks.min(no_more_than: 32)
while bi < nbb {
assert bi < 32 via "a < b: a < c; c <= b"(c: nbb)
if args.input == 0 {
color = this.alphas[bi]
} else {
color = this.colors[bi]
}
color = this.colors[args.input][bi]
c0 = (((color >> 56) as base.u32) * 8) + 4
multiplier = ((color >> 52) & 0x0F) as base.u32
@@ -914,11 +915,7 @@ pri func decoder.from_colors_to_buffer_signed!(input: base.u32[..= 1], dst_bytes
nbb = this.num_buffered_blocks.min(no_more_than: 32)
while bi < nbb {
assert bi < 32 via "a < b: a < c; c <= b"(c: nbb)
if args.input == 0 {
color = this.alphas[bi]
} else {
color = this.colors[bi]
}
color = this.colors[args.input][bi]
c0 = ((color >> 56) as base.u32) * 8
if c0 < (0x80 * 8) {