mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
enc/*: normalize WebPEncodingSetError() calls
return WebPEncodingSetError() directly where possible (it returns 0 / failure for convenience). Change-Id: I89a937778886c15ecbbe078af5b4c8c89ef0f9af
This commit is contained in:
parent
287fdefe95
commit
4339332038
@ -283,8 +283,7 @@ int VP8LHashChainFill(VP8LHashChain* const p, int quality,
|
|||||||
hash_to_first_index =
|
hash_to_first_index =
|
||||||
(int32_t*)WebPSafeMalloc(HASH_SIZE, sizeof(*hash_to_first_index));
|
(int32_t*)WebPSafeMalloc(HASH_SIZE, sizeof(*hash_to_first_index));
|
||||||
if (hash_to_first_index == NULL) {
|
if (hash_to_first_index == NULL) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
percent_range = remaining_percent / 2;
|
percent_range = remaining_percent / 2;
|
||||||
@ -1050,8 +1049,7 @@ int VP8LGetBackwardReferences(
|
|||||||
refs_best = GetBackwardReferencesLowEffort(
|
refs_best = GetBackwardReferencesLowEffort(
|
||||||
width, height, argb, cache_bits_best, hash_chain, refs);
|
width, height, argb, cache_bits_best, hash_chain, refs);
|
||||||
if (refs_best == NULL) {
|
if (refs_best == NULL) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
// Set it in first position.
|
// Set it in first position.
|
||||||
BackwardRefsSwap(refs_best, &refs[0]);
|
BackwardRefsSwap(refs_best, &refs[0]);
|
||||||
@ -1059,8 +1057,7 @@ int VP8LGetBackwardReferences(
|
|||||||
if (!GetBackwardReferences(width, height, argb, quality, lz77_types_to_try,
|
if (!GetBackwardReferences(width, height, argb, quality, lz77_types_to_try,
|
||||||
cache_bits_max, do_no_cache, hash_chain, refs,
|
cache_bits_max, do_no_cache, hash_chain, refs,
|
||||||
cache_bits_best)) {
|
cache_bits_best)) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -689,7 +689,7 @@ static int PreLoopInitialize(VP8Encoder* const enc) {
|
|||||||
}
|
}
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
VP8EncFreeBitWriters(enc); // malloc error occurred
|
VP8EncFreeBitWriters(enc); // malloc error occurred
|
||||||
WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
@ -196,8 +196,7 @@ static int CoOccurrenceBuild(const WebPPicture* const pic,
|
|||||||
uint32_t palette_sorted[MAX_PALETTE_SIZE];
|
uint32_t palette_sorted[MAX_PALETTE_SIZE];
|
||||||
lines = (uint32_t*)WebPSafeMalloc(2 * pic->width, sizeof(*lines));
|
lines = (uint32_t*)WebPSafeMalloc(2 * pic->width, sizeof(*lines));
|
||||||
if (lines == NULL) {
|
if (lines == NULL) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
line_top = &lines[0];
|
line_top = &lines[0];
|
||||||
line_current = &lines[pic->width];
|
line_current = &lines[pic->width];
|
||||||
@ -255,8 +254,7 @@ static int PaletteSortModifiedZeng(
|
|||||||
cooccurrence =
|
cooccurrence =
|
||||||
(uint32_t*)WebPSafeCalloc(num_colors * num_colors, sizeof(*cooccurrence));
|
(uint32_t*)WebPSafeCalloc(num_colors * num_colors, sizeof(*cooccurrence));
|
||||||
if (cooccurrence == NULL) {
|
if (cooccurrence == NULL) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
if (!CoOccurrenceBuild(pic, palette_sorted, num_colors, cooccurrence)) {
|
if (!CoOccurrenceBuild(pic, palette_sorted, num_colors, cooccurrence)) {
|
||||||
WebPSafeFree(cooccurrence);
|
WebPSafeFree(cooccurrence);
|
||||||
@ -1013,8 +1011,7 @@ static int StoreImageToBitMask(
|
|||||||
VP8LRefsCursorNext(&c);
|
VP8LRefsCursorNext(&c);
|
||||||
}
|
}
|
||||||
if (bw->error_) {
|
if (bw->error_) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1460,15 +1457,13 @@ static int WriteImage(const WebPPicture* const pic, VP8LBitWriter* const bw,
|
|||||||
|
|
||||||
if (!WriteRiffHeader(pic, riff_size, vp8l_size) ||
|
if (!WriteRiffHeader(pic, riff_size, vp8l_size) ||
|
||||||
!pic->writer(webpll_data, webpll_size, pic)) {
|
!pic->writer(webpll_data, webpll_size, pic)) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_WRITE);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_WRITE);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pad) {
|
if (pad) {
|
||||||
const uint8_t pad_byte[1] = { 0 };
|
const uint8_t pad_byte[1] = { 0 };
|
||||||
if (!pic->writer(pad_byte, 1, pic)) {
|
if (!pic->writer(pad_byte, 1, pic)) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_WRITE);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_WRITE);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*coded_size = CHUNK_HEADER_SIZE + riff_size;
|
*coded_size = CHUNK_HEADER_SIZE + riff_size;
|
||||||
@ -1513,8 +1508,7 @@ static int AllocateTransformBuffer(VP8LEncoder* const enc, int width,
|
|||||||
ClearTransformBuffer(enc);
|
ClearTransformBuffer(enc);
|
||||||
mem = (uint32_t*)WebPSafeMalloc(mem_size, sizeof(*mem));
|
mem = (uint32_t*)WebPSafeMalloc(mem_size, sizeof(*mem));
|
||||||
if (mem == NULL) {
|
if (mem == NULL) {
|
||||||
WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
enc->transform_mem_ = mem;
|
enc->transform_mem_ = mem;
|
||||||
enc->transform_mem_size_ = (size_t)mem_size;
|
enc->transform_mem_size_ = (size_t)mem_size;
|
||||||
@ -1622,8 +1616,7 @@ static int ApplyPalette(const uint32_t* src, uint32_t src_stride, uint32_t* dst,
|
|||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
if (tmp_row == NULL) {
|
if (tmp_row == NULL) {
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (palette_size < APPLY_PALETTE_GREEDY_MAX) {
|
if (palette_size < APPLY_PALETTE_GREEDY_MAX) {
|
||||||
@ -1977,9 +1970,8 @@ int VP8LEncodeStream(const WebPConfig* const config,
|
|||||||
int ok_main;
|
int ok_main;
|
||||||
|
|
||||||
if (enc_main == NULL || !VP8LBitWriterInit(&bw_side, 0)) {
|
if (enc_main == NULL || !VP8LBitWriterInit(&bw_side, 0)) {
|
||||||
WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
|
||||||
VP8LEncoderDelete(enc_main);
|
VP8LEncoderDelete(enc_main);
|
||||||
return 0;
|
return WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid "garbage value" error from Clang's static analysis tool.
|
// Avoid "garbage value" error from Clang's static analysis tool.
|
||||||
@ -2126,8 +2118,7 @@ int VP8LEncodeImage(const WebPConfig* const config,
|
|||||||
if (picture == NULL) return 0;
|
if (picture == NULL) return 0;
|
||||||
|
|
||||||
if (config == NULL || picture->argb == NULL) {
|
if (config == NULL || picture->argb == NULL) {
|
||||||
WebPEncodingSetError(picture, VP8_ENC_ERROR_NULL_PARAMETER);
|
return WebPEncodingSetError(picture, VP8_ENC_ERROR_NULL_PARAMETER);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
width = picture->width;
|
width = picture->width;
|
||||||
|
@ -320,8 +320,7 @@ int WebPReportProgress(const WebPPicture* const pic,
|
|||||||
*percent_store = percent;
|
*percent_store = percent;
|
||||||
if (pic->progress_hook && !pic->progress_hook(percent, pic)) {
|
if (pic->progress_hook && !pic->progress_hook(percent, pic)) {
|
||||||
// user abort requested
|
// user abort requested
|
||||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_USER_ABORT);
|
return WebPEncodingSetError(pic, VP8_ENC_ERROR_USER_ABORT);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1; // ok
|
return 1; // ok
|
||||||
|
Loading…
Reference in New Issue
Block a user