From caf350812deb4cb99b2ccd8eda01c4b7296d8a52 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Fri, 18 Oct 2013 13:33:09 +0200 Subject: fix scaling of wide images --- view.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/view.c b/view.c index f028c82..6982006 100644 --- a/view.c +++ b/view.c @@ -82,24 +82,21 @@ static void close_terminal() static gboolean view_pixbuf(GdkPixbuf *pixbuf) { + const gint max_width = window_width; + const gint max_height = window_height - char_height; gint width = gdk_pixbuf_get_width(pixbuf); - gint height = gdk_pixbuf_get_height(pixbuf); - - double scale = 1.0; - if (width > window_width) { - scale *= (double)window_width / width; - width = width * scale; - height = height * scale; - } - if (height > window_height || FALSE) { - scale *= (double)window_height / height; - width = width * scale; - height = height * scale; - } - + gint height = gdk_pixbuf_get_height(pixbuf); GdkPixbuf *scaled; - if (scale != 1.0) { + if (width > max_width || height > max_height) { + if (width > height) { + height = floor((height / (double)width) * max_width); + width = max_width; + } else { + width = floor((width / (double)height) * max_height); + height = max_height; + } + scaled = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR); } else { scaled = GDK_PIXBUF(g_object_ref(pixbuf)); -- cgit v1.2.3