resize images to fit
authorColin Leroy <colin@colino.net>
Fri, 11 Oct 2002 11:12:56 +0000 (11:12 +0000)
committerColin Leroy <colin@colino.net>
Fri, 11 Oct 2002 11:12:56 +0000 (11:12 +0000)
ChangeLog.claws
configure.in
src/imageview.c

index 9152834be5839304533b61dbca8b24b2da50e76c..aff40ebe0415b461e7d11a8ede1b67b2c50973cb 100644 (file)
@@ -1,3 +1,8 @@
+2002-10-11 [colin]     0.8.5claws12
+
+       * src/imageview.c
+               Resize images to fit
+
 2002-10-11 [paul]      0.8.5claws11
 
        * po/es.po
index 6b1c84bbdf7f3d85ff8194e93e0a9f78df1a44a0..e4eff82ec3f0fb8f32134f7fd33e352dde535afe 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws11
+EXTRA_VERSION=claws12
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index f1e0546b2c8db3b11b903f66e5f97f998c3f42ac..3a73de60ac27f77a57cd48f9e8aec68d2e053f51 100644 (file)
@@ -40,6 +40,8 @@
 #include "imageview.h"
 #include "utils.h"
 
+void get_resized_size (int w, int h, int aw, int ah, int *sw, int *sh);
+
 ImageView *imageview_create(void)
 {
        ImageView *imageview;
@@ -71,9 +73,14 @@ void imageview_show_image(ImageView *imageview, MimeInfo *mimeinfo,
                          const gchar *file)
 {
        GdkPixbuf *pixbuf;
+       GdkPixbuf *pixbuf_scaled;
        GdkPixmap *pixmap;
        GdkBitmap *mask;
-
+       int avail_height = imageview->scrolledwin->parent->allocation.height - 10;
+       int avail_width  = imageview->scrolledwin->parent->allocation.width - 10;
+       int sized_height = -1;
+       int sized_width  = -1;
+       
        imageview_clear(imageview);
 
        pixbuf = gdk_pixbuf_new_from_file(file);
@@ -85,8 +92,13 @@ void imageview_show_image(ImageView *imageview, MimeInfo *mimeinfo,
 
        if (imageview->messageview->mainwin)
                main_window_cursor_wait(imageview->messageview->mainwin);
-
-       gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &mask, 0);
+       
+       get_resized_size (gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), 
+                         avail_width, avail_height, &sized_width, &sized_height);
+       
+       pixbuf_scaled = gdk_pixbuf_scale_simple (pixbuf, sized_width, sized_height, 0);
+       
+       gdk_pixbuf_render_pixmap_and_mask(pixbuf_scaled, &pixmap, &mask, 0);
 
        if (!imageview->image) {
                imageview->image = gtk_pixmap_new(pixmap, mask);
@@ -110,6 +122,10 @@ void imageview_show_image(ImageView *imageview, MimeInfo *mimeinfo,
                          const gchar *file)
 {
        GdkImlibImage *im;
+       int avail_height = imageview->scrolledwin->parent->allocation.height - 10;
+       int avail_width  = imageview->scrolledwin->parent->allocation.width - 10;
+       int sized_height = -1;
+       int sized_width  = -1;
 
        imageview_clear(imageview);
 
@@ -123,7 +139,10 @@ void imageview_show_image(ImageView *imageview, MimeInfo *mimeinfo,
        if (imageview->messageview->mainwin)
                main_window_cursor_wait(imageview->messageview->mainwin);
 
-       gdk_imlib_render(im, im->rgb_width, im->rgb_height);
+       get_resized_size (im->rgb_width, im->rgb_height, 
+                         avail_width, avail_height, &sized_width, &sized_height);
+
+       gdk_imlib_render(im, sized_width, sized_height);
 
        if (!imageview->image) {
                imageview->image = gtk_pixmap_new(gdk_imlib_move_image(im),
@@ -170,3 +189,26 @@ void imageview_destroy(ImageView *imageview)
 {
        g_free(imageview);
 }
+
+void get_resized_size (int w, int h, int aw, int ah, int *sw, int *sh) {
+       
+       float wratio = 1.0;
+       float hratio = 1.0;
+       float ratio  = 1.0;
+
+       if (w > aw)
+               wratio = (float)((float)aw/(float)w);
+       if (h > ah)
+               hratio = (float)((float)ah/(float)h);
+       
+       ratio = (wratio > hratio) ? hratio : wratio;
+
+       *sw = (int)(w * ratio);
+       *sh = (int)(h * ratio);
+       
+       /* be paranoid */
+       if (*sw <= 0 || *sh <= 0) {
+               *sw = w;
+               *sh = h;
+       }
+}