libnsgif: Update to latest upstream. (#2706)

This commit is contained in:
Michael Drake 2022-03-04 08:05:36 +00:00 committed by GitHub
parent c0de1b6169
commit 5f7c12e474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 27 deletions

View File

@ -8,7 +8,7 @@ but within the libvips build system.
Run `./update.sh` to update this copy of libnsgif from the upstream repo. It Run `./update.sh` to update this copy of libnsgif from the upstream repo. It
will also patch libnsgif.c to prevent it modifying the input. will also patch libnsgif.c to prevent it modifying the input.
Last updated 7 Oct 2021. Last updated 3 Mar 2022.
# To do # To do

View File

@ -625,13 +625,15 @@ static void nsgif__restore_bg(
uint32_t offset_x = frame->info.rect.x0; uint32_t offset_x = frame->info.rect.x0;
uint32_t offset_y = frame->info.rect.y0; uint32_t offset_y = frame->info.rect.y0;
width -= gif__clip(offset_x, width, gif->info.width); if (frame->info.display == false ||
height -= gif__clip(offset_y, height, gif->info.height); frame->info.rect.x0 >= gif->info.width ||
frame->info.rect.y0 >= gif->info.height) {
if (frame->info.display == false || width == 0) {
return; return;
} }
width -= gif__clip(offset_x, width, gif->info.width);
height -= gif__clip(offset_y, height, gif->info.height);
if (frame->info.transparency) { if (frame->info.transparency) {
for (uint32_t y = 0; y < height; y++) { for (uint32_t y = 0; y < height; y++) {
uint32_t *scanline = bitmap + offset_x + uint32_t *scanline = bitmap + offset_x +
@ -1703,7 +1705,7 @@ nsgif_error nsgif_frame_decode(
uint32_t start_frame; uint32_t start_frame;
nsgif_error ret = NSGIF_OK; nsgif_error ret = NSGIF_OK;
if (frame > gif->info.frame_count) { if (frame >= gif->info.frame_count) {
return NSGIF_ERR_BAD_FRAME; return NSGIF_ERR_BAD_FRAME;
} }
@ -1742,7 +1744,7 @@ const nsgif_frame_info_t *nsgif_get_frame_info(
const nsgif_t *gif, const nsgif_t *gif,
uint32_t frame) uint32_t frame)
{ {
if (frame > gif->info.frame_count) { if (frame >= gif->info.frame_count) {
return NULL; return NULL;
} }
@ -1759,8 +1761,7 @@ const char *nsgif_strerror(nsgif_error err)
[NSGIF_ERR_BAD_FRAME] = "Requested frame does not exist", [NSGIF_ERR_BAD_FRAME] = "Requested frame does not exist",
[NSGIF_ERR_DATA_FRAME] = "Invalid frame data", [NSGIF_ERR_DATA_FRAME] = "Invalid frame data",
[NSGIF_ERR_FRAME_COUNT] = "Excessive number of frames", [NSGIF_ERR_FRAME_COUNT] = "Excessive number of frames",
[NSGIF_ERR_END_OF_DATA] = "Insufficient data for first frame", [NSGIF_ERR_END_OF_DATA] = "Unexpected end of GIF source data",
[NSGIF_ERR_END_OF_FRAME] = "End of data during frame",
[NSGIF_ERR_FRAME_DISPLAY] = "Frame can't be displayed", [NSGIF_ERR_FRAME_DISPLAY] = "Frame can't be displayed",
[NSGIF_ERR_ANIMATION_END] = "Animation complete", [NSGIF_ERR_ANIMATION_END] = "Animation complete",
}; };

View File

@ -82,15 +82,10 @@ typedef enum {
NSGIF_ERR_FRAME_COUNT, NSGIF_ERR_FRAME_COUNT,
/** /**
* GIF source data ended without one complete frame available. * Unexpected end of GIF source data.
*/ */
NSGIF_ERR_END_OF_DATA, NSGIF_ERR_END_OF_DATA,
/**
* GIF source data ended with incomplete frame.
*/
NSGIF_ERR_END_OF_FRAME,
/** /**
* The current frame cannot be displayed. * The current frame cannot be displayed.
*/ */
@ -215,6 +210,9 @@ void nsgif_destroy(nsgif_t *gif);
* *
* If an error occurs, all previously scanned frames are retained. * If an error occurs, all previously scanned frames are retained.
* *
* Note that an error returned from this function is purely informational.
* So long as at least one frame is available, you can display frames.
*
* \param[in] gif The \ref nsgif_t object. * \param[in] gif The \ref nsgif_t object.
* \param[in] size Number of bytes in data. * \param[in] size Number of bytes in data.
* \param[in] data Raw source GIF data. * \param[in] data Raw source GIF data.

View File

@ -207,21 +207,21 @@ static void decode(FILE* ppm, const char *name, nsgif_t *gif)
} }
frame_prev = frame_new; frame_prev = frame_new;
err = nsgif_frame_decode(gif, frame_new, &bitmap);
if (err != NSGIF_OK) {
warning("nsgif_decode_frame", err);
return;
}
if (nsgif_options.info == true) { if (nsgif_options.info == true) {
const nsgif_frame_info_t *f_info; const nsgif_frame_info_t *f_info;
f_info = nsgif_get_frame_info(gif, frame_new); f_info = nsgif_get_frame_info(gif, frame_new);
assert(f_info != NULL); if (f_info != NULL) {
print_gif_frame_info(f_info); print_gif_frame_info(f_info);
} }
}
if (ppm != NULL) { err = nsgif_frame_decode(gif, frame_new, &bitmap);
if (err != NSGIF_OK) {
warning("nsgif_decode_frame", err);
/* Continue decoding the rest of the frames. */
} else if (ppm != NULL) {
fprintf(ppm, "# frame %u:\n", frame_new); fprintf(ppm, "# frame %u:\n", frame_new);
image = (const uint8_t *) bitmap; image = (const uint8_t *) bitmap;
for (uint32_t y = 0; y != info->height; y++) { for (uint32_t y = 0; y != info->height; y++) {
@ -284,10 +284,9 @@ int main(int argc, char *argv[])
/* Scan the raw data */ /* Scan the raw data */
err = nsgif_data_scan(gif, size, data); err = nsgif_data_scan(gif, size, data);
if (err != NSGIF_OK) { if (err != NSGIF_OK) {
/* Not fatal; some GIFs are nasty. Can still try to decode
* any frames that were decoded successfully. */
warning("nsgif_data_scan", err); warning("nsgif_data_scan", err);
nsgif_destroy(gif);
free(data);
return EXIT_FAILURE;
} }
if (nsgif_options.loops == 0) { if (nsgif_options.loops == 0) {