mirror of
https://github.com/webmproject/libwebp.git
synced 2025-04-11 19:36:47 +02:00
Merge "Fix return code of EncodeImageInternal()"
This commit is contained in:
commit
5f81391263
@ -679,9 +679,8 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw,
|
|||||||
|
|
||||||
VP8LBackwardRefsInit(&refs, refs_array[0].block_size_);
|
VP8LBackwardRefsInit(&refs, refs_array[0].block_size_);
|
||||||
if (histogram_image == NULL || histogram_symbols == NULL) {
|
if (histogram_image == NULL || histogram_symbols == NULL) {
|
||||||
VP8LFreeHistogramSet(histogram_image);
|
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||||
WebPSafeFree(histogram_symbols);
|
goto Error;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 'best_refs' is the reference to the best backward refs and points to one
|
// 'best_refs' is the reference to the best backward refs and points to one
|
||||||
@ -691,6 +690,7 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw,
|
|||||||
cache_bits, use_2d_locality,
|
cache_bits, use_2d_locality,
|
||||||
hash_chain, refs_array);
|
hash_chain, refs_array);
|
||||||
if (best_refs == NULL || !VP8LBackwardRefsCopy(best_refs, &refs)) {
|
if (best_refs == NULL || !VP8LBackwardRefsCopy(best_refs, &refs)) {
|
||||||
|
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
// Build histogram image and symbols from backward references.
|
// Build histogram image and symbols from backward references.
|
||||||
@ -698,6 +698,7 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw,
|
|||||||
quality, histogram_bits, cache_bits,
|
quality, histogram_bits, cache_bits,
|
||||||
histogram_image,
|
histogram_image,
|
||||||
histogram_symbols)) {
|
histogram_symbols)) {
|
||||||
|
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
// Create Huffman bit lengths and codes for each histogram image.
|
// Create Huffman bit lengths and codes for each histogram image.
|
||||||
@ -707,6 +708,7 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw,
|
|||||||
sizeof(*huffman_codes));
|
sizeof(*huffman_codes));
|
||||||
if (huffman_codes == NULL ||
|
if (huffman_codes == NULL ||
|
||||||
!GetHuffBitLengthsAndCodes(histogram_image, huffman_codes)) {
|
!GetHuffBitLengthsAndCodes(histogram_image, huffman_codes)) {
|
||||||
|
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||||
goto Error;
|
goto Error;
|
||||||
}
|
}
|
||||||
// Free combined histograms.
|
// Free combined histograms.
|
||||||
@ -729,7 +731,10 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw,
|
|||||||
sizeof(*histogram_argb));
|
sizeof(*histogram_argb));
|
||||||
int max_index = 0;
|
int max_index = 0;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
if (histogram_argb == NULL) goto Error;
|
if (histogram_argb == NULL) {
|
||||||
|
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto Error;
|
||||||
|
}
|
||||||
for (i = 0; i < histogram_image_xysize; ++i) {
|
for (i = 0; i < histogram_image_xysize; ++i) {
|
||||||
const int symbol_index = histogram_symbols[i] & 0xffff;
|
const int symbol_index = histogram_symbols[i] & 0xffff;
|
||||||
histogram_argb[i] = (symbol_index << 8);
|
histogram_argb[i] = (symbol_index << 8);
|
||||||
@ -755,7 +760,10 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw,
|
|||||||
int max_tokens = 0;
|
int max_tokens = 0;
|
||||||
huff_tree = (HuffmanTree*)WebPSafeMalloc(3ULL * CODE_LENGTH_CODES,
|
huff_tree = (HuffmanTree*)WebPSafeMalloc(3ULL * CODE_LENGTH_CODES,
|
||||||
sizeof(*huff_tree));
|
sizeof(*huff_tree));
|
||||||
if (huff_tree == NULL) goto Error;
|
if (huff_tree == NULL) {
|
||||||
|
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto Error;
|
||||||
|
}
|
||||||
// Find maximum number of symbols for the huffman tree-set.
|
// Find maximum number of symbols for the huffman tree-set.
|
||||||
for (i = 0; i < 5 * histogram_image_size; ++i) {
|
for (i = 0; i < 5 * histogram_image_size; ++i) {
|
||||||
HuffmanTreeCode* const codes = &huffman_codes[i];
|
HuffmanTreeCode* const codes = &huffman_codes[i];
|
||||||
@ -765,7 +773,10 @@ static WebPEncodingError EncodeImageInternal(VP8LBitWriter* const bw,
|
|||||||
}
|
}
|
||||||
tokens = (HuffmanTreeToken*)WebPSafeMalloc(max_tokens,
|
tokens = (HuffmanTreeToken*)WebPSafeMalloc(max_tokens,
|
||||||
sizeof(*tokens));
|
sizeof(*tokens));
|
||||||
if (tokens == NULL) goto Error;
|
if (tokens == NULL) {
|
||||||
|
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto Error;
|
||||||
|
}
|
||||||
for (i = 0; i < 5 * histogram_image_size; ++i) {
|
for (i = 0; i < 5 * histogram_image_size; ++i) {
|
||||||
HuffmanTreeCode* const codes = &huffman_codes[i];
|
HuffmanTreeCode* const codes = &huffman_codes[i];
|
||||||
StoreHuffmanCode(bw, huff_tree, tokens, codes);
|
StoreHuffmanCode(bw, huff_tree, tokens, codes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user