Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ RECENT REVISION HISTORY:
Josh Tobin Neil Bickford Matthew Gregan github:poppolopoppo
Julian Raschke Gregory Mullen Christian Floisand github:darealshinji
Baldur Karlsson Kevin Schmidt JR Smith github:Michaelangel007
Brad Weinberger Matvey Cherevko github:mosra
Denis Genestier Brad Weinberger Matvey Cherevko github:mosra
Luca Sas Alexander Veselov Zack Middleton [reserved]
Ryan C. Gordon [reserved] [reserved]
DO NOT ADD YOUR NAME HERE
Expand Down Expand Up @@ -6967,54 +6967,70 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
stbi_uc *u = 0;
stbi_uc *out = 0;
stbi_uc *two_back = 0;
stbi__gif g;
stbi__gif *g = (stbi__gif *)stbi__malloc(sizeof(*g));
int stride;
int out_size = 0;
int delays_size = 0;
void* err;

if (!g) {
return stbi__errpuc("outofmem", "Out of memory");
}
STBI_NOTUSED(out_size);
STBI_NOTUSED(delays_size);

memset(&g, 0, sizeof(g));
memset(g, 0, sizeof(*g));
if (delays) {
*delays = 0;
}

do {
u = stbi__gif_load_next(s, &g, comp, req_comp, two_back);
u = stbi__gif_load_next(s, g, comp, req_comp, two_back);
if (u == (stbi_uc *) s) u = 0; // end of animated gif marker

if (u) {
*x = g.w;
*y = g.h;
*x = g->w;
*y = g->h;
++layers;
stride = g.w * g.h * 4;
stride = g->w * g->h * 4;

if (out) {
void *tmp = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride );
if (!tmp)
return stbi__load_gif_main_outofmem(&g, out, delays);
if (!tmp) {
err = stbi__load_gif_main_outofmem(g, out, delays);
STBI_FREE(g);
return err;
}
else {
out = (stbi_uc*) tmp;
out_size = layers * stride;
}

if (delays) {
int *new_delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers );
if (!new_delays)
return stbi__load_gif_main_outofmem(&g, out, delays);
if (!new_delays) {
err = stbi__load_gif_main_outofmem(g, out, delays);
STBI_FREE(g);
return err;
}
*delays = new_delays;
delays_size = layers * sizeof(int);
}
} else {
out = (stbi_uc*)stbi__malloc( layers * stride );
if (!out)
return stbi__load_gif_main_outofmem(&g, out, delays);
if (!out) {
err = stbi__load_gif_main_outofmem(g, out, delays);
STBI_FREE(g);
return err;
}
out_size = layers * stride;
if (delays) {
*delays = (int*) stbi__malloc( layers * sizeof(int) );
if (!*delays)
return stbi__load_gif_main_outofmem(&g, out, delays);
if (!*delays) {
err = stbi__load_gif_main_outofmem(g, out, delays);
STBI_FREE(g);
return err;
}
delays_size = layers * sizeof(int);
}
}
Expand All @@ -7024,21 +7040,22 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
}

if (delays) {
(*delays)[layers - 1U] = g.delay;
(*delays)[layers - 1U] = g->delay;
}
}
} while (u != 0);

// free temp buffer;
STBI_FREE(g.out);
STBI_FREE(g.history);
STBI_FREE(g.background);
STBI_FREE(g->out);
STBI_FREE(g->history);
STBI_FREE(g->background);

// do the final conversion after loading everything;
if (req_comp && req_comp != 4)
out = stbi__convert_format(out, 4, req_comp, layers * g.w, g.h);
out = stbi__convert_format(out, 4, req_comp, layers * g->w, g->h);

*z = layers;
STBI_FREE(g);
return out;
} else {
return stbi__errpuc("not GIF", "Image was not as a gif type.");
Expand Down