Skip to content

Commit

Permalink
Add more checks for animation
Browse files Browse the repository at this point in the history
  • Loading branch information
vrabaud committed Nov 7, 2023
1 parent 19e0bbf commit 085d25d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/webpanimio.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ WebPPicture frame;
return ERROR_INT("sizes of all pix are not the same", __func__, 1);

/* Set up the encoder */
WebPAnimEncoderOptionsInit(&enc_options);
if (!WebPAnimEncoderOptionsInit(&enc_options))
return ERROR_INT("cannot initialize WebP encoder", procName, 1);
enc = WebPAnimEncoderNew(w, h, &enc_options);

if (!WebPConfigInit(&config)) {
Expand All @@ -224,19 +225,19 @@ WebPPicture frame;
status = WebPPictureImportRGBA(&frame, data, 4 * wpl);
pixDestroy(&pix1);
pixDestroy(&pix2);
if (!status) {
if (!status)
return ERROR_INT("cannot import RGBA picture", procName, 1);
}

/* Add the frame data to the encoder, and clear its memory */
status = WebPAnimEncoderAdd(enc, &frame, duration * i, &config);
WebPPictureFree(&frame);
if (!status) {
if (!status)
return ERROR_INT("cannot add frame to animation", procName, 1);
}
}
WebPAnimEncoderAdd(enc, NULL, duration * i, NULL); /* add a blank frame */
WebPAnimEncoderAssemble(enc, &webp_data); /* encode the data */
if (!WebPAnimEncoderAdd(enc, NULL, duration * i, NULL)) /* add a blank frame */
return ERROR_INT("cannot add blank frame to animation", procName, 1);
if (!WebPAnimEncoderAssemble(enc, &webp_data)) /* encode the data */
return ERROR_INT("cannot assemble animation", procName, 1);
WebPAnimEncoderDelete(enc);

/* Set the loopcount if requested. Note that when you make a mux,
Expand All @@ -260,7 +261,8 @@ WebPPicture frame;
L_ERROR("failed to set loop count\n", __func__);
}
WebPDataClear(&webp_data);
WebPMuxAssemble(mux, &webp_data);
if (WebPMuxAssemble(mux, &webp_data) != WEBP_MUX_OK)
L_ERROR("failed to assemble in the WebP muxer\n", procName);
WebPMuxDelete(mux);
}
}
Expand Down

0 comments on commit 085d25d

Please sign in to comment.