aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--image.c32
-rw-r--r--thumbs.c10
3 files changed, 26 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 6113957..6c26d3c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = 24
+VERSION = git-20171123
srcdir = .
VPATH = $(srcdir)
diff --git a/image.c b/image.c
index 75dc346..6803846 100644
--- a/image.c
+++ b/image.c
@@ -293,21 +293,35 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
}
#endif /* HAVE_GIFLIB */
-bool img_load(img_t *img, const fileinfo_t *file)
+Imlib_Image img_open(const fileinfo_t *file)
{
- const char *fmt;
struct stat st;
+ Imlib_Image im = NULL;
- if (access(file->path, R_OK) == -1 ||
- stat(file->path, &st) == -1 || !S_ISREG(st.st_mode) ||
- (img->im = imlib_load_image(file->path)) == NULL)
+ if (access(file->path, R_OK) == 0 &&
+ stat(file->path, &st) == 0 && S_ISREG(st.st_mode))
{
- if (file->flags & FF_WARN)
- error(0, 0, "%s: Error opening image", file->name);
- return false;
+ im = imlib_load_image(file->path);
+ if (im != NULL) {
+ imlib_context_set_image(im);
+ if (imlib_image_get_data_for_reading_only() == NULL) {
+ imlib_free_image();
+ im = NULL;
+ }
+ }
}
+ if (im == NULL && (file->flags & FF_WARN))
+ error(0, 0, "%s: Error opening image", file->name);
+ return im;
+}
+
+bool img_load(img_t *img, const fileinfo_t *file)
+{
+ const char *fmt;
+
+ if ((img->im = img_open(file)) == NULL)
+ return false;
- imlib_context_set_image(img->im);
imlib_image_set_changes_on_disk();
#if HAVE_LIBEXIF
diff --git a/thumbs.c b/thumbs.c
index a99c764..37be29f 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -32,6 +32,7 @@
#include <libexif/exif-data.h>
void exif_auto_orientate(const fileinfo_t*);
#endif
+Imlib_Image img_open(const fileinfo_t*);
static char *cache_dir;
@@ -237,7 +238,6 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
char *cfile;
thumb_t *t;
fileinfo_t *file;
- struct stat st;
Imlib_Image im = NULL;
if (n < 0 || n >= *tns->cnt)
@@ -331,14 +331,8 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
}
if (im == NULL) {
- if (access(file->path, R_OK) == -1 ||
- stat(file->path, &st) == -1 || !S_ISREG(st.st_mode) ||
- (im = imlib_load_image(file->path)) == NULL)
- {
- if (file->flags & FF_WARN)
- error(0, 0, "%s: Error opening image", file->name);
+ if ((im = img_open(file)) == NULL)
return false;
- }
}
imlib_context_set_image(im);