resize images to fit
This commit is contained in:
parent
adac097097
commit
8a83c62829
3 changed files with 52 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue