Merge branch 'fix_issue-656' of https://github.com/rygorous/stb into working
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parents 3b5ffbe, 6570d6a · Browse files · 1 file·+23 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+23 added−9 removed
- other:+23 added−9 removed
Provenance
- Commit
1737c34- Tree
24804e7- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent 1
3b5ffbe- Parent 2
6570d6a
1 file changed+23 added−9 removed
modified:stb_image.h+23 added-9 removed
6410 unmodified lines6411 6412 // on first frame, any non-written pixels get the background colour (non-transparent)6413 first_frame = 0; 6414 if (g->out == 0) {6415- if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header6416- g->out = (stbi_uc *) stbi__malloc(4 * g->w * g->h);6417- g->background = (stbi_uc *) stbi__malloc(4 * g->w * g->h); 6418- g->history = (stbi_uc *) stbi__malloc(g->w * g->h); 6419- if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");6415+ if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header6416+ if (!stbi__mad3sizes_valid(4, g->w, g->h, 0))6417+ return stbi__errpuc("too large", "GIF image is too large");6418+ pcount = g->w * g->h;6419+ g->out = (stbi_uc *) stbi__malloc(4 * pcount);6420+ g->background = (stbi_uc *) stbi__malloc(4 * pcount);6421+ g->history = (stbi_uc *) stbi__malloc(pcount);6422+ if (!g->out || !g->background || !g->history)6423+ return stbi__errpuc("outofmem", "Out of memory");6424 6425 // image is treated as "transparent" at the start - ie, nothing overwrites the current background; 6426 // background colour is only used for pixels that are not rendered first frame, after that "background"6427 // color refers to the color that was there the previous frame. 6424- memset( g->out, 0x00, 4 * g->w * g->h ); 6425- memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)6426- memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame6428+ memset(g->out, 0x00, 4 * pcount);6429+ memset(g->background, 0x00, 4 * pcount); // state of the background (starts transparent)6430+ memset(g->history, 0x00, pcount); // pixels that were affected previous frame6431 first_frame = 1; 6432 } else {6433 // second frame - how do we dispoase of the previous one?6434 dispose = (g->eflags & 0x1C) >> 2; 52 unmodified lines6487 g->max_y = g->start_y + h * g->line_size;6488 g->cur_x = g->start_x;6489 g->cur_y = g->start_y;6490 6491+ // if the width of the specified rectangle is 0, that means6492+ // we may not see *any* pixels or the image is malformed;6493+ // to make sure this is caught, move the current y down to6494+ // max_y (which is what out_gif_code checks).6495+ if (w == 0)6496+ g->cur_y = g->max_y;6497+6498 g->lflags = stbi__get8(s);6499 6500 if (g->lflags & 0x40) {6501 g->step = 8 * g->line_size; // first interlaced spacing11 unmodified lines6513 } else6514 return stbi__errpuc("missing color table", "Corrupt GIF"); 6515 6516 o = stbi__process_gif_raster(s, g);6506- if (o == NULL) return NULL;6517+ if (!o) return NULL;6518 6519 // if this was the first frame, 6520 pcount = g->w * g->h; 6521 if (first_frame && (g->bgindex > 0)) {131 unmodified lines6653 // moved conversion to after successful load so that the same6654 // can be done for multiple frames. 6655 if (req_comp && req_comp != 4)6656 u = stbi__convert_format(u, 4, req_comp, g.w, g.h);6657+ } else if (g.out) {6658+ // if there was an error and we allocated an image buffer, free it!6659+ STBI_FREE(g.out);6660 }6661 6662 // free buffers needed for multiple frame loading; 6663 STBI_FREE(g.history);881 unmodified lines