mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 05:38:22 +01:00
remove one malloc() by making color_cache non dynamic
Change-Id: I7c71a056f79a79bfacfe64a263f1eb8476c05456
This commit is contained in:
parent
8130c4cc64
commit
7f0c178e46
@ -565,13 +565,14 @@ static int DecodeImageData(VP8LDecoder* const dec,
|
||||
int col = 0, row = 0;
|
||||
VP8LBitReader* const br = &dec->br_;
|
||||
VP8LMetadata* const hdr = &dec->hdr_;
|
||||
VP8LColorCache* const color_cache = hdr->color_cache_;
|
||||
HTreeGroup* htree_group = hdr->htree_groups_;
|
||||
uint32_t* src = data;
|
||||
uint32_t* last_cached = data;
|
||||
uint32_t* const src_end = data + width * height;
|
||||
const int len_code_limit = NUM_LITERAL_CODES + NUM_LENGTH_CODES;
|
||||
const int color_cache_limit = len_code_limit + hdr->color_cache_size_;
|
||||
VP8LColorCache* const color_cache =
|
||||
(hdr->color_cache_size_ > 0) ? &hdr->color_cache_ : NULL;
|
||||
const int mask = hdr->huffman_mask_;
|
||||
|
||||
assert(htree_group != NULL);
|
||||
@ -784,7 +785,7 @@ static void ClearMetadata(VP8LMetadata* const hdr) {
|
||||
|
||||
free(hdr->huffman_image_);
|
||||
DeleteHtreeGroups(hdr->htree_groups_, hdr->num_htree_groups_);
|
||||
VP8LColorCacheDelete(hdr->color_cache_);
|
||||
VP8LColorCacheClear(&hdr->color_cache_);
|
||||
InitMetadata(hdr);
|
||||
}
|
||||
|
||||
@ -875,13 +876,13 @@ static int DecodeImageStream(int xsize, int ysize,
|
||||
// Finish setting up the color-cache
|
||||
if (color_cache_bits > 0) {
|
||||
hdr->color_cache_size_ = 1 << color_cache_bits;
|
||||
hdr->color_cache_ = (VP8LColorCache*)malloc(sizeof(*hdr->color_cache_));
|
||||
if (hdr->color_cache_ == NULL ||
|
||||
!VP8LColorCacheInit(hdr->color_cache_, color_cache_bits)) {
|
||||
if (!VP8LColorCacheInit(&hdr->color_cache_, color_cache_bits)) {
|
||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||
ok = 0;
|
||||
goto End;
|
||||
}
|
||||
} else {
|
||||
hdr->color_cache_size_ = 0;
|
||||
}
|
||||
UpdateDecoder(dec, transform_xsize, transform_ysize);
|
||||
|
||||
|
@ -45,7 +45,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
int color_cache_size_;
|
||||
VP8LColorCache *color_cache_;
|
||||
VP8LColorCache color_cache_;
|
||||
|
||||
int huffman_mask_;
|
||||
int huffman_subsample_bits_;
|
||||
|
@ -35,14 +35,10 @@ int VP8LColorCacheInit(VP8LColorCache* const cc, int hash_bits) {
|
||||
void VP8LColorCacheClear(VP8LColorCache* const cc) {
|
||||
if (cc != NULL) {
|
||||
free(cc->colors_);
|
||||
cc->colors_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void VP8LColorCacheDelete(VP8LColorCache* const cc) {
|
||||
VP8LColorCacheClear(cc);
|
||||
free(cc);
|
||||
}
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -56,12 +56,9 @@ static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc,
|
||||
// Returns false in case of memory error.
|
||||
int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits);
|
||||
|
||||
// Delete the color cache.
|
||||
// Delete the memory associated to color cache.
|
||||
void VP8LColorCacheClear(VP8LColorCache* const color_cache);
|
||||
|
||||
// Delete the color_cache object.
|
||||
void VP8LColorCacheDelete(VP8LColorCache* const color_cache);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
|
Loading…
Reference in New Issue
Block a user