Skip to content

Commit

Permalink
[SF#895]Check image sizes and abort loading image if it's Mpx is abov…
Browse files Browse the repository at this point in the history
…e thumbnail_max.

This should be reflected in the Preferences on next strings change.
  • Loading branch information
LStranger committed Aug 23, 2014
1 parent 2aadebf commit 00120b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/base/fm-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ typedef enum
* @small_icon_size: size of small icons
* @pane_icon_size: size of side pane icons
* @thumbnail_size: size of thumbnail icons
* @thumbnail_max: show thumbnails for files smaller than 'thumb_max' KB
* @thumbnail_max: show thumbnails only for files not bigger than this, in KB or Kpix
* @auto_selection_delay: (since 1.2.0) delay for autoselection in single-click mode, in ms
* @drop_default_action: (since 1.2.0) default action on drop (see #FmDndDestDropAction)
* @single_click: single click to open file
Expand Down
2 changes: 1 addition & 1 deletion src/base/fm-thumbnail-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* fm-thumbnail-loader.c
*
* Copyright 2010 - 2013 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
* Copyright 2012 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
* Copyright 2012-2014 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
15 changes: 14 additions & 1 deletion src/gtk/fm-thumbnail.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* fm-thumbnail.c
*
* Copyright 2010 - 2012 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
* Copyright 2012 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
* Copyright 2012-2014 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -35,6 +35,7 @@
#include <config.h>
#endif
#include "fm-thumbnail.h"
#include "fm-config.h"

/* FIXME: this function prototype seems to be missing in header files of GdkPixbuf. Bug report to them. */
gboolean gdk_pixbuf_set_option(GdkPixbuf *pixbuf, const gchar *key, const gchar *value);
Expand Down Expand Up @@ -131,6 +132,18 @@ guint fm_thumbnail_request_get_size(FmThumbnailRequest* req)
}

static GObject* read_image_from_file(const char* filename) {
if (fm_config->thumbnail_max > 0)
{
int w = 1 , h = 1;

/* SF bug #895: image of big dimension can be still small due to
image compression and loading that image into memory can easily
overrun the available memory, so let limit image by Mpix as well */
gdk_pixbuf_get_file_info(filename, &w, &h);
/* g_debug("thumbnail generator: image size %dx%d", w, h); */
if (w * h > (fm_config->thumbnail_max << 10))
return NULL;
}
return (GObject*)gdk_pixbuf_new_from_file(filename, NULL);
}

Expand Down

0 comments on commit 00120b7

Please sign in to comment.