aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--view.c27
1 files 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));