aboutsummaryrefslogtreecommitdiff
path: root/fastiv-io.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-15 08:20:05 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-15 09:47:00 +0100
commit6f86911df69bcfcd69d90feef43fef3450fc36e5 (patch)
treea6101eefa024c743f763436cbeb5592fd2fb52e6 /fastiv-io.c
parent37adaac965d2dc7cbb28c1068c382521a30092b6 (diff)
downloadfiv-6f86911df69bcfcd69d90feef43fef3450fc36e5.tar.gz
fiv-6f86911df69bcfcd69d90feef43fef3450fc36e5.tar.xz
fiv-6f86911df69bcfcd69d90feef43fef3450fc36e5.zip
Slightly optimize thumbnail loading
Now it translates to just x86 bswap and ror.
Diffstat (limited to 'fastiv-io.c')
-rw-r--r--fastiv-io.c10
1 files 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;
}
}