aboutsummaryrefslogtreecommitdiff
path: root/fiv-io.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-12-20 04:29:19 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-12-20 04:40:35 +0100
commitada67f044a36f9b5368c8905bbb9aa6f1dacd0b6 (patch)
tree8c9e08ffe6921199d2b6a712ea4ac4450d4a551c /fiv-io.c
parent63955e881dcc958fa871731157a1230a8a41abc0 (diff)
downloadfiv-ada67f044a36f9b5368c8905bbb9aa6f1dacd0b6.tar.gz
fiv-ada67f044a36f9b5368c8905bbb9aa6f1dacd0b6.tar.xz
fiv-ada67f044a36f9b5368c8905bbb9aa6f1dacd0b6.zip
Optimize thumbnail rendering
Massive responsivity gains have been achieved here. Rescaling performance doesn't seem to be particularly affected.
Diffstat (limited to 'fiv-io.c')
-rw-r--r--fiv-io.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/fiv-io.c b/fiv-io.c
index 7b83a09..a78d9c9 100644
--- a/fiv-io.c
+++ b/fiv-io.c
@@ -2366,9 +2366,15 @@ read_spng_thumbnail(
}
struct spng_ihdr ihdr = {};
+ struct spng_trns trns = {};
spng_get_ihdr(ctx, &ihdr);
+ bool may_be_translucent = !spng_get_trns(ctx, &trns) ||
+ ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA ||
+ ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA;
+
cairo_surface_t *surface = cairo_image_surface_create(
- CAIRO_FORMAT_ARGB32, ihdr.width, ihdr.height);
+ may_be_translucent ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24,
+ ihdr.width, ihdr.height);
cairo_status_t surface_status = cairo_surface_status(surface);
if (surface_status != CAIRO_STATUS_SUCCESS) {
@@ -2396,10 +2402,7 @@ read_spng_thumbnail(
}
// pixman can be mildly abused to do this operation, but it won't be faster.
- struct spng_trns trns = {};
- if (ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA ||
- ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR_ALPHA ||
- !spng_get_trns(ctx, &trns)) {
+ if (may_be_translucent) {
for (size_t i = size / sizeof *data; i--; ) {
const uint8_t *unit = (const uint8_t *) &data[i];
uint32_t a = unit[3],