Krolyxon
Commit 8f34b7e

Branches

Refs →

nsxiv8f34b7e

Load as much of a corrupted gif file as possible

Author
Bert
Date
2011-09-06 11:55 +0200
Parent
14d1daf
Commit
8f34b7e95cc4de30b67eacb264688ca14acaaf60

+15 −16

3 files changed

  1. M image.c +8 −10
  2. M main.c +6 −6
  3. M types.h +1 −0
M image.c View
@@ -60,7 +60,7 @@ void img_init(img_t *img, win_t *win) {
6060 }
6161
6262 #ifdef HAVE_GIFLIB
63−/* originally based on, but in it's current form merely inspired by Imlib2's
63+/* Originally based on, but in its current form merely inspired by Imlib2's
6464 * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
6565 */
6666 int img_load_gif(img_t *img, const fileinfo_t *file) {
@@ -97,7 +97,6 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
9797
9898 do {
9999 if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
100− warn("could not open gif file: %s", file->name);
101100 err = 1;
102101 break;
103102 }
@@ -122,7 +121,6 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
122121 }
123122 } else if (rec == IMAGE_DESC_RECORD_TYPE) {
124123 if (DGifGetImageDesc(gif) == GIF_ERROR) {
125− warn("could not open gif frame # %d: %s", img->multi.cnt, file->name);
126124 err = 1;
127125 break;
128126 }
@@ -181,7 +179,6 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
181179 free(data);
182180
183181 if (!im) {
184− warn("could not open gif frame # %d: %s", img->multi.cnt, file->name);
185182 err = 1;
186183 break;
187184 }
@@ -207,16 +204,17 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
207204
208205 DGifCloseFile(gif);
209206
210− if (!err && img->multi.cnt > 1) {
207+ if (err && !file->loaded)
208+ warn("corrupted gif file: %s", file->name);
209+
210+ if (img->multi.cnt > 1) {
211211 imlib_context_set_image(img->im);
212212 imlib_free_image();
213213 img->im = img->multi.frames[0].im;
214214 img->multi.animate = GIF_AUTOPLAY;
215− } else {
216− for (i = 0; i < img->multi.cnt; i++) {
217− imlib_context_set_image(img->multi.frames[i].im);
218− imlib_free_image();
219− }
215+ } else if (img->multi.cnt == 1) {
216+ imlib_context_set_image(img->multi.frames[0].im);
217+ imlib_free_image();
220218 img->multi.cnt = 0;
221219 img->multi.animate = 0;
222220 }
M main.c View
@@ -99,6 +99,7 @@ void check_add_file(char *filename) {
9999 return;
100100 }
101101 }
102+ files[fileidx].loaded = 0;
102103 files[fileidx].name = s_strdup(filename);
103104 if (*filename == '/')
104105 files[fileidx].path = files[fileidx].name;
@@ -198,18 +199,17 @@ void load_image(int new) {
198199 new = filecnt - 1;
199200 }
200201
202+ files[new].loaded = 1;
201203 fileidx = new;
202204 if (!stat(files[new].path, &fstats))
203205 filesize = fstats.st_size;
204206 else
205207 filesize = 0;
206208
207− if (img.multi.cnt) {
208− if (img.multi.animate)
209− set_timeout(animate, img.multi.frames[img.multi.sel].delay, 1);
210− else
211− reset_timeout(animate);
212− }
209+ if (img.multi.cnt && img.multi.animate)
210+ set_timeout(animate, img.multi.frames[img.multi.sel].delay, 1);
211+ else
212+ reset_timeout(animate);
213213 }
214214
215215 void update_title() {
M types.h View
@@ -29,6 +29,7 @@ typedef enum {
2929 typedef struct {
3030 const char *name; /* as given by user */
3131 const char *path; /* always absolute */
32+ unsigned char loaded;
3233 } fileinfo_t;
3334
3435 /* timeouts in milliseconds: */