aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-12-28 01:19:57 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-12-28 02:07:42 +0100
commitd4b51f07b5b7a99cf2c7624b8fe3f4fb67db8cc5 (patch)
treef297e693adcb45a1f677a1b8bef9154e2cfaf477
parent720464327c1bc69297b21b70918cc93624be1dd0 (diff)
downloadfiv-d4b51f07b5b7a99cf2c7624b8fe3f4fb67db8cc5.tar.gz
fiv-d4b51f07b5b7a99cf2c7624b8fe3f4fb67db8cc5.tar.xz
fiv-d4b51f07b5b7a99cf2c7624b8fe3f4fb67db8cc5.zip
Avoid unused alpha channels when rescaling
-rw-r--r--fiv-io.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/fiv-io.c b/fiv-io.c
index eed6dfb..91c3a46 100644
--- a/fiv-io.c
+++ b/fiv-io.c
@@ -2785,6 +2785,7 @@ fiv_io_get_thumbnail_root(void)
static cairo_surface_t *
rescale_thumbnail(cairo_surface_t *thumbnail, double row_height)
{
+ cairo_format_t format = cairo_image_surface_get_format(thumbnail);
int width = cairo_image_surface_get_width(thumbnail);
int height = cairo_image_surface_get_height(thumbnail);
@@ -2800,13 +2801,13 @@ rescale_thumbnail(cairo_surface_t *thumbnail, double row_height)
if (scale_x == 1 && scale_y == 1)
return cairo_surface_reference(thumbnail);
- // TODO(p): Don't always include an alpha channel.
- cairo_format_t cairo_format = CAIRO_FORMAT_ARGB32;
-
int projected_width = round(scale_x * width);
int projected_height = round(scale_y * height);
cairo_surface_t *scaled = cairo_image_surface_create(
- cairo_format, projected_width, projected_height);
+ (format == CAIRO_FORMAT_RGB24 || format == CAIRO_FORMAT_RGB30)
+ ? CAIRO_FORMAT_RGB24
+ : CAIRO_FORMAT_ARGB32,
+ projected_width, projected_height);
cairo_t *cr = cairo_create(scaled);
cairo_scale(cr, scale_x, scale_y);