Slightly optimize thumbnail loading

Now it translates to just x86 bswap and ror.
This commit is contained in:
Přemysl Eric Janouch 2021-11-15 08:20:05 +01:00
parent 37adaac965
commit 6f86911df6
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 3 additions and 7 deletions

View File

@ -710,7 +710,7 @@ read_spng_thumbnail(
ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA ||
!spng_get_trns(ctx, &trns)) {
for (size_t i = size / sizeof *output; i--; ) {
uint8_t *unit = (uint8_t *) &data[i],
const uint8_t *unit = (const uint8_t *) &data[i],
a = unit[3],
b = unit[2] * a / 255,
g = unit[1] * a / 255,
@ -719,12 +719,8 @@ read_spng_thumbnail(
}
} else {
for (size_t i = size / sizeof *output; i--; ) {
uint8_t *unit = (uint8_t *) &data[i],
a = unit[3],
b = unit[2],
g = unit[1],
r = unit[0];
output[i] = a << 24 | r << 16 | g << 8 | b;
uint32_t x = g_ntohl(data[i]);
output[i] = x << 24 | x >> 8;
}
}