Skip to content

Commit

Permalink
Parse GIF application extension block correctly (Issue #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
saitoha committed Mar 4, 2015
1 parent 7f73585 commit 2b66fd7
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions converters/stb_image.h
Expand Up @@ -4060,6 +4060,7 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
{
int i;
stbi_uc *old_out = 0;
stbi_uc buffer[256];

if (g->out == 0) {
if (!stbi__gif_header(s, g, comp,0)) return 0; // stbi__g_failure_reason set by stbi__gif_header
Expand Down Expand Up @@ -4149,27 +4150,20 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
break;
case 0xFF: // Application Extension
len = stbi__get8(s); // block size
if (len != 11) break;
if (stbi__get8(s) != 'N') break;
if (stbi__get8(s) != 'E') break;
if (stbi__get8(s) != 'T') break;
if (stbi__get8(s) != 'S') break;
if (stbi__get8(s) != 'C') break;
if (stbi__get8(s) != 'A') break;
if (stbi__get8(s) != 'P') break;
if (stbi__get8(s) != 'E') break;
if (stbi__get8(s) != '2') break;
if (stbi__get8(s) != '.') break;
if (stbi__get8(s) != '0') break;
if (stbi__get8(s) != 0x03) break;
// loop count
switch (stbi__get8(s)) {
case 0x00:
g->loop_count = 1;
break;
case 0x01:
g->loop_count = stbi__get16le(s);
break;
stbi__getn(s, buffer, len);
buffer[len] = 0;
if (len == 11 && strcmp((char *)buffer, "NETSCAPE2.0") == 0) {
if (stbi__get8(s) == 0x03) {
// loop count
switch (stbi__get8(s)) {
case 0x00:
g->loop_count = 1;
break;
case 0x01:
g->loop_count = stbi__get16le(s);
break;
}
}
}
break;
default:
Expand Down

0 comments on commit 2b66fd7

Please sign in to comment.