Load as much of a corrupted gif file as possible
This commit is contained in:
parent
14d1daf280
commit
8f34b7e95c
18
image.c
18
image.c
|
@ -60,7 +60,7 @@ void img_init(img_t *img, win_t *win) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_GIFLIB
|
#ifdef HAVE_GIFLIB
|
||||||
/* originally based on, but in it's current form merely inspired by Imlib2's
|
/* Originally based on, but in its current form merely inspired by Imlib2's
|
||||||
* src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
|
* src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
|
||||||
*/
|
*/
|
||||||
int img_load_gif(img_t *img, const fileinfo_t *file) {
|
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) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
|
if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
|
||||||
warn("could not open gif file: %s", file->name);
|
|
||||||
err = 1;
|
err = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +121,6 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
|
||||||
}
|
}
|
||||||
} else if (rec == IMAGE_DESC_RECORD_TYPE) {
|
} else if (rec == IMAGE_DESC_RECORD_TYPE) {
|
||||||
if (DGifGetImageDesc(gif) == GIF_ERROR) {
|
if (DGifGetImageDesc(gif) == GIF_ERROR) {
|
||||||
warn("could not open gif frame # %d: %s", img->multi.cnt, file->name);
|
|
||||||
err = 1;
|
err = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +179,6 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
if (!im) {
|
if (!im) {
|
||||||
warn("could not open gif frame # %d: %s", img->multi.cnt, file->name);
|
|
||||||
err = 1;
|
err = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -207,16 +204,17 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
|
||||||
|
|
||||||
DGifCloseFile(gif);
|
DGifCloseFile(gif);
|
||||||
|
|
||||||
if (!err && img->multi.cnt > 1) {
|
if (err && !file->loaded)
|
||||||
|
warn("corrupted gif file: %s", file->name);
|
||||||
|
|
||||||
|
if (img->multi.cnt > 1) {
|
||||||
imlib_context_set_image(img->im);
|
imlib_context_set_image(img->im);
|
||||||
imlib_free_image();
|
imlib_free_image();
|
||||||
img->im = img->multi.frames[0].im;
|
img->im = img->multi.frames[0].im;
|
||||||
img->multi.animate = GIF_AUTOPLAY;
|
img->multi.animate = GIF_AUTOPLAY;
|
||||||
} else {
|
} else if (img->multi.cnt == 1) {
|
||||||
for (i = 0; i < img->multi.cnt; i++) {
|
imlib_context_set_image(img->multi.frames[0].im);
|
||||||
imlib_context_set_image(img->multi.frames[i].im);
|
imlib_free_image();
|
||||||
imlib_free_image();
|
|
||||||
}
|
|
||||||
img->multi.cnt = 0;
|
img->multi.cnt = 0;
|
||||||
img->multi.animate = 0;
|
img->multi.animate = 0;
|
||||||
}
|
}
|
||||||
|
|
12
main.c
12
main.c
|
@ -99,6 +99,7 @@ void check_add_file(char *filename) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
files[fileidx].loaded = 0;
|
||||||
files[fileidx].name = s_strdup(filename);
|
files[fileidx].name = s_strdup(filename);
|
||||||
if (*filename == '/')
|
if (*filename == '/')
|
||||||
files[fileidx].path = files[fileidx].name;
|
files[fileidx].path = files[fileidx].name;
|
||||||
|
@ -198,18 +199,17 @@ void load_image(int new) {
|
||||||
new = filecnt - 1;
|
new = filecnt - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
files[new].loaded = 1;
|
||||||
fileidx = new;
|
fileidx = new;
|
||||||
if (!stat(files[new].path, &fstats))
|
if (!stat(files[new].path, &fstats))
|
||||||
filesize = fstats.st_size;
|
filesize = fstats.st_size;
|
||||||
else
|
else
|
||||||
filesize = 0;
|
filesize = 0;
|
||||||
|
|
||||||
if (img.multi.cnt) {
|
if (img.multi.cnt && img.multi.animate)
|
||||||
if (img.multi.animate)
|
set_timeout(animate, img.multi.frames[img.multi.sel].delay, 1);
|
||||||
set_timeout(animate, img.multi.frames[img.multi.sel].delay, 1);
|
else
|
||||||
else
|
reset_timeout(animate);
|
||||||
reset_timeout(animate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_title() {
|
void update_title() {
|
||||||
|
|
1
types.h
1
types.h
|
@ -29,6 +29,7 @@ typedef enum {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name; /* as given by user */
|
const char *name; /* as given by user */
|
||||||
const char *path; /* always absolute */
|
const char *path; /* always absolute */
|
||||||
|
unsigned char loaded;
|
||||||
} fileinfo_t;
|
} fileinfo_t;
|
||||||
|
|
||||||
/* timeouts in milliseconds: */
|
/* timeouts in milliseconds: */
|
||||||
|
|
Loading…
Reference in a new issue