From 605859cdd494b82fe206fe8d4737cda73cb6d467 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Sat, 10 Sep 2022 13:31:58 -0400 Subject: [PATCH] Fix loss of clarity with odd-sized centered image --- background-image.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/background-image.c b/background-image.c index c765bdf..fc2ca0d 100644 --- a/background-image.c +++ b/background-image.c @@ -100,9 +100,14 @@ void render_background_image(cairo_t *cairo, cairo_surface_t *image, break; } case BACKGROUND_MODE_CENTER: + /* + * Align the unscaled image to integer pixel boundaries + * in order to prevent loss of clarity (this only matters + * for odd-sized images). + */ cairo_set_source_surface(cairo, image, - (double)buffer_width / 2 - width / 2, - (double)buffer_height / 2 - height / 2); + (int)((double)buffer_width / 2 - width / 2), + (int)((double)buffer_height / 2 - height / 2)); break; case BACKGROUND_MODE_TILE: { cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);