From 6f86911df69bcfcd69d90feef43fef3450fc36e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 15 Nov 2021 08:20:05 +0100 Subject: [PATCH] Slightly optimize thumbnail loading Now it translates to just x86 bswap and ror. --- fastiv-io.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fastiv-io.c b/fastiv-io.c index f5b3b1a..64bbb3c 100644 --- a/fastiv-io.c +++ b/fastiv-io.c @@ -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; } }