diff --git a/src/enc/alpha.c b/src/enc/alpha.c index 97538da9..51a8cd10 100644 --- a/src/enc/alpha.c +++ b/src/enc/alpha.c @@ -84,8 +84,8 @@ static int EncodeLossless(const uint8_t* const data, int width, int height, config.quality = 10.f + 15.f * effort_level; if (config.quality > 100.f) config.quality = 100.f; - VP8LBitWriterInit(&tmp_bw, (width * height) >> 3); - ok = (VP8LEncodeStream(&config, &picture, &tmp_bw) == VP8_ENC_OK); + ok = VP8LBitWriterInit(&tmp_bw, (width * height) >> 3); + ok = ok && (VP8LEncodeStream(&config, &picture, &tmp_bw) == VP8_ENC_OK); WebPPictureFree(&picture); if (ok) { const uint8_t* const data = VP8LBitWriterFinish(&tmp_bw); diff --git a/src/enc/vp8l.c b/src/enc/vp8l.c index f40b5e3f..9778e5e8 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -1050,11 +1050,17 @@ int VP8LEncodeImage(const WebPConfig* const config, if (config == NULL || picture->argb == NULL) { err = VP8_ENC_ERROR_NULL_PARAMETER; - goto Error; + WebPEncodingSetError(picture, err); + return 0; } width = picture->width; height = picture->height; + if (!VP8LBitWriterInit(&bw, (width * height) >> 1)) { + err = VP8_ENC_ERROR_OUT_OF_MEMORY; + goto Error; + } + if (!WebPReportProgress(picture, 1, &percent)) { UserAbort: err = VP8_ENC_ERROR_USER_ABORT; @@ -1072,7 +1078,6 @@ int VP8LEncodeImage(const WebPConfig* const config, } // Write image size. - VP8LBitWriterInit(&bw, (width * height) >> 1); if (!WriteImageSize(picture, &bw)) { err = VP8_ENC_ERROR_OUT_OF_MEMORY; goto Error;