diff options
author | Javier S. Pedro <javier@javispedro.com> | 2013-10-18 13:33:09 +0200 |
---|---|---|
committer | Javier S. Pedro <javier@javispedro.com> | 2013-10-18 13:33:09 +0200 |
commit | caf350812deb4cb99b2ccd8eda01c4b7296d8a52 (patch) | |
tree | 4d1c79a6e92b96e1dfd17ff5fb2c6392b12e234a | |
parent | 22b9821bad3f2e9fb93f4190a2554f28cf13c868 (diff) | |
download | vteimg-caf350812deb4cb99b2ccd8eda01c4b7296d8a52.tar.gz vteimg-caf350812deb4cb99b2ccd8eda01c4b7296d8a52.zip |
fix scaling of wide images
-rw-r--r-- | view.c | 27 |
1 files changed, 12 insertions, 15 deletions
@@ -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)); |