Skip to content

Commit

Permalink
fix deinterlacing for small pictures
Browse files Browse the repository at this point in the history
fixes #12
  • Loading branch information
miniupnp committed Apr 16, 2019
1 parent 3bb9980 commit 37d939a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
Binary file added invalid_gif/issue_12.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 29 additions & 25 deletions ngiflib.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* decodeur GIF en C portable (pas de pb big/little endian)
* Thomas BERNARD. janvier 2004.
* (c) 2004-2017 Thomas Bernard. All rights reserved
* (c) 2004-2019 Thomas Bernard. All rights reserved
*/

/* Fonction de debug */
Expand Down Expand Up @@ -135,29 +135,31 @@ static void WritePixel(struct ngiflib_img * i, struct ngiflib_decode_context * c
break;
case 1: /* 1st pass : every eighth row starting from 0 */
context->curY += 8;
if(context->curY >= p->height) {
context->pass++;
context->curY = i->posY + 4;
}
break;
case 2: /* 2nd pass : every eighth row starting from 4 */
context->curY += 8;
if(context->curY >= p->height) {
context->pass++;
context->curY = i->posY + 2;
}
break;
case 3: /* 3rd pass : every fourth row starting from 2 */
context->curY += 4;
if(context->curY >= p->height) {
context->pass++;
context->curY = i->posY + 1;
}
break;
case 4: /* 4th pass : every odd row */
context->curY += 2;
break;
}
while(context->pass > 0 && context->pass < 4 &&
context->curY >= p->height) {
switch(++context->pass) {
case 2: /* 2nd pass : every eighth row starting from 4 */
context->curY = i->posY + 4;
break;
case 3: /* 3rd pass : every fourth row starting from 2 */
context->curY = i->posY + 2;
break;
case 4: /* 4th pass : every odd row */
context->curY = i->posY + 1;
break;
}
}
#ifndef NGIFLIB_INDEXED_ONLY
if(p->mode & NGIFLIB_MODE_INDEXED) {
#endif /* NGIFLIB_INDEXED_ONLY */
Expand Down Expand Up @@ -249,29 +251,31 @@ static void WritePixels(struct ngiflib_img * i, struct ngiflib_decode_context *
break;
case 1: /* 1st pass : every eighth row starting from 0 */
context->curY += 8;
if(context->curY >= p->height) {
context->pass++;
context->curY = i->posY + 4;
}
break;
case 2: /* 2nd pass : every eighth row starting from 4 */
context->curY += 8;
if(context->curY >= p->height) {
context->pass++;
context->curY = i->posY + 2;
}
break;
case 3: /* 3rd pass : every fourth row starting from 2 */
context->curY += 4;
if(context->curY >= p->height) {
context->pass++;
context->curY = i->posY + 1;
}
break;
case 4: /* 4th pass : every odd row */
context->curY += 2;
break;
}
while(context->pass > 0 && context->pass < 4 &&
context->curY >= p->height) {
switch(++context->pass) {
case 2: /* 2nd pass : every eighth row starting from 4 */
context->curY = i->posY + 4;
break;
case 3: /* 3rd pass : every fourth row starting from 2 */
context->curY = i->posY + 2;
break;
case 4: /* 4th pass : every odd row */
context->curY = i->posY + 1;
break;
}
}
#ifndef NGIFLIB_INDEXED_ONLY
if(p->mode & NGIFLIB_MODE_INDEXED) {
#endif /* NGIFLIB_INDEXED_ONLY */
Expand Down

0 comments on commit 37d939a

Please sign in to comment.