mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 05:38:22 +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 =
|
||||
(int32_t*)WebPSafeMalloc(HASH_SIZE, sizeof(*hash_to_first_index));
|
||||
if (hash_to_first_index == NULL) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
percent_range = remaining_percent / 2;
|
||||
@ -1050,8 +1049,7 @@ int VP8LGetBackwardReferences(
|
||||
refs_best = GetBackwardReferencesLowEffort(
|
||||
width, height, argb, cache_bits_best, hash_chain, refs);
|
||||
if (refs_best == NULL) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
// Set it in first position.
|
||||
BackwardRefsSwap(refs_best, &refs[0]);
|
||||
@ -1059,8 +1057,7 @@ int VP8LGetBackwardReferences(
|
||||
if (!GetBackwardReferences(width, height, argb, quality, lz77_types_to_try,
|
||||
cache_bits_max, do_no_cache, hash_chain, refs,
|
||||
cache_bits_best)) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -689,7 +689,7 @@ static int PreLoopInitialize(VP8Encoder* const enc) {
|
||||
}
|
||||
if (!ok) {
|
||||
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;
|
||||
}
|
||||
|
@ -196,8 +196,7 @@ static int CoOccurrenceBuild(const WebPPicture* const pic,
|
||||
uint32_t palette_sorted[MAX_PALETTE_SIZE];
|
||||
lines = (uint32_t*)WebPSafeMalloc(2 * pic->width, sizeof(*lines));
|
||||
if (lines == NULL) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
line_top = &lines[0];
|
||||
line_current = &lines[pic->width];
|
||||
@ -255,8 +254,7 @@ static int PaletteSortModifiedZeng(
|
||||
cooccurrence =
|
||||
(uint32_t*)WebPSafeCalloc(num_colors * num_colors, sizeof(*cooccurrence));
|
||||
if (cooccurrence == NULL) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
if (!CoOccurrenceBuild(pic, palette_sorted, num_colors, cooccurrence)) {
|
||||
WebPSafeFree(cooccurrence);
|
||||
@ -1013,8 +1011,7 @@ static int StoreImageToBitMask(
|
||||
VP8LRefsCursorNext(&c);
|
||||
}
|
||||
if (bw->error_) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -1460,15 +1457,13 @@ static int WriteImage(const WebPPicture* const pic, VP8LBitWriter* const bw,
|
||||
|
||||
if (!WriteRiffHeader(pic, riff_size, vp8l_size) ||
|
||||
!pic->writer(webpll_data, webpll_size, pic)) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_WRITE);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_WRITE);
|
||||
}
|
||||
|
||||
if (pad) {
|
||||
const uint8_t pad_byte[1] = { 0 };
|
||||
if (!pic->writer(pad_byte, 1, pic)) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_WRITE);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_WRITE);
|
||||
}
|
||||
}
|
||||
*coded_size = CHUNK_HEADER_SIZE + riff_size;
|
||||
@ -1513,8 +1508,7 @@ static int AllocateTransformBuffer(VP8LEncoder* const enc, int width,
|
||||
ClearTransformBuffer(enc);
|
||||
mem = (uint32_t*)WebPSafeMalloc(mem_size, sizeof(*mem));
|
||||
if (mem == NULL) {
|
||||
WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
return 0;
|
||||
return WebPEncodingSetError(enc->pic_, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
enc->transform_mem_ = mem;
|
||||
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;
|
||||
|
||||
if (tmp_row == NULL) {
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (palette_size < APPLY_PALETTE_GREEDY_MAX) {
|
||||
@ -1977,9 +1970,8 @@ int VP8LEncodeStream(const WebPConfig* const config,
|
||||
int ok_main;
|
||||
|
||||
if (enc_main == NULL || !VP8LBitWriterInit(&bw_side, 0)) {
|
||||
WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
VP8LEncoderDelete(enc_main);
|
||||
return 0;
|
||||
return WebPEncodingSetError(picture, VP8_ENC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
// 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 (config == NULL || picture->argb == NULL) {
|
||||
WebPEncodingSetError(picture, VP8_ENC_ERROR_NULL_PARAMETER);
|
||||
return 0;
|
||||
return WebPEncodingSetError(picture, VP8_ENC_ERROR_NULL_PARAMETER);
|
||||
}
|
||||
|
||||
width = picture->width;
|
||||
|
@ -320,8 +320,7 @@ int WebPReportProgress(const WebPPicture* const pic,
|
||||
*percent_store = percent;
|
||||
if (pic->progress_hook && !pic->progress_hook(percent, pic)) {
|
||||
// user abort requested
|
||||
WebPEncodingSetError(pic, VP8_ENC_ERROR_USER_ABORT);
|
||||
return 0;
|
||||
return WebPEncodingSetError(pic, VP8_ENC_ERROR_USER_ABORT);
|
||||
}
|
||||
}
|
||||
return 1; // ok
|
||||
|
Loading…
Reference in New Issue
Block a user