diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2021-11-03 20:45:07 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2021-11-03 20:48:49 +0000 |
commit | f19df341f8a3f3ec5a319fd4621b4a8f53699dcb (patch) | |
tree | 0cbda44e428cdb735da8d39d42a251dc6dfc8732 | |
parent | ec55ce31acd8aa8b2601db2a74e5b1725fa61da2 (diff) | |
download | libnsgif-f19df341f8a3f3ec5a319fd4621b4a8f53699dcb.tar.gz libnsgif-f19df341f8a3f3ec5a319fd4621b4a8f53699dcb.tar.bz2 |
GIF: Use image parsing frunction for frame initialisation.
-rw-r--r-- | src/libnsgif.c | 63 |
1 files changed, 4 insertions, 59 deletions
diff --git a/src/libnsgif.c b/src/libnsgif.c index fc826a8..366b4ef 100644 --- a/src/libnsgif.c +++ b/src/libnsgif.c @@ -980,7 +980,6 @@ static gif_result gif_initialise_frame( struct gif_frame *frame; uint8_t *gif_data, *gif_end; int gif_bytes; - uint32_t block_size; /* Get our buffer position etc. */ gif_data = (uint8_t *)(gif->gif_data + gif->buffer_position); @@ -1034,67 +1033,13 @@ static gif_result gif_initialise_frame( if (ret != GIF_OK) { return ret; } - gif_data = gif->gif_data + gif->buffer_position; - gif_bytes = (gif_end - gif_data); - /* Move our data onwards and remember we've got a bit of this frame */ - gif->frame_count_partial = frame_idx + 1; - - /* Ensure we have a correct code size */ - if (gif_bytes < 1) { - return GIF_INSUFFICIENT_FRAME_DATA; - } - if (gif_data[0] >= LZW_CODE_MAX) { - return GIF_DATA_ERROR; - } - - /* Move our pointer to the actual image data */ - gif_data++; - --gif_bytes; - - /* Repeatedly skip blocks until we get a zero block or run out of data - * These blocks of image data are processed later by gif_decode_frame() - */ - block_size = 0; - while (block_size != 1) { - if (gif_bytes < 1) return GIF_INSUFFICIENT_FRAME_DATA; - block_size = gif_data[0] + 1; - /* Check if the frame data runs off the end of the file */ - if ((int)(gif_bytes - block_size) < 0) { - /* Try to recover by signaling the end of the gif. - * Once we get garbage data, there is no logical way to - * determine where the next frame is. It's probably - * better to partially load the gif than not at all. - */ - if (gif_bytes >= 2) { - gif_data[0] = 0; - gif_data[1] = GIF_TRAILER; - gif_bytes = 1; - ++gif_data; - break; - } else { - return GIF_INSUFFICIENT_FRAME_DATA; - } - } else { - gif_bytes -= block_size; - gif_data += block_size; - } + ret = gif__parse_image_data(gif, &gif->frames[frame_idx], false); + if (ret != GIF_OK) { + return ret; } - /* Add the frame and set the display flag */ - gif->buffer_position = gif_data - gif->gif_data; - gif->frame_count = frame_idx + 1; - gif->frames[frame_idx].display = true; - - /* Check if we've finished */ - if (gif_bytes < 1) { - return GIF_INSUFFICIENT_FRAME_DATA; - } else { - if (gif_data[0] == GIF_TRAILER) { - return GIF_OK; - } - } - return GIF_WORKING; + return GIF_OK; } /** |