diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2021-04-04 12:11:23 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2021-04-04 15:48:05 +0100 |
commit | ad9ddb59c4f0607821e52919a5ffdd09a1090a4e (patch) | |
tree | 0ea69a936fd8f22b925efce06d0c41c5ea0b8d8a | |
parent | 19bbdfd0e2cea3d133d3de1d275496060d069376 (diff) | |
download | libnsgif-ad9ddb59c4f0607821e52919a5ffdd09a1090a4e.tar.gz libnsgif-ad9ddb59c4f0607821e52919a5ffdd09a1090a4e.tar.bz2 |
gif: Frame decoding: Rearrange for readability.
-rw-r--r-- | src/libnsgif.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/libnsgif.c b/src/libnsgif.c index 2db34df..050a961 100644 --- a/src/libnsgif.c +++ b/src/libnsgif.c @@ -656,7 +656,7 @@ gif__decode(gif_animation *gif, unsigned int transparency_index; const uint8_t *stack_base; const uint8_t *stack_pos; - uint32_t written = 0; + uint32_t available = 0; gif_result ret = GIF_OK; lzw_result res; @@ -687,23 +687,9 @@ gif__decode(gif_animation *gif, x = width; while (x > 0) { - if (written > 0) { - unsigned burst_bytes = written; - if (burst_bytes > x) { - burst_bytes = x; - } - x -= burst_bytes; - written -= burst_bytes; - while (burst_bytes-- > 0) { - register unsigned int colour; - colour = *stack_pos++; - if (colour != transparency_index) { - *frame_scanline = colour_table[colour]; - } - frame_scanline++; - } - } else { - res = lzw_decode(gif->lzw_ctx, &written); + unsigned row_available; + if (available == 0) { + res = lzw_decode(gif->lzw_ctx, &available); if (res != LZW_OK) { /* Unexpected end of frame, try to recover */ if (res == LZW_OK_EOD) { @@ -715,6 +701,18 @@ gif__decode(gif_animation *gif, } stack_pos = stack_base; } + + row_available = x < available ? x : available; + x -= row_available; + available -= row_available; + while (row_available-- > 0) { + register unsigned int colour; + colour = *stack_pos++; + if (colour != transparency_index) { + *frame_scanline = colour_table[colour]; + } + frame_scanline++; + } } } return ret; |