| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include <assert.h> |
| 15 |
#include <stdlib.h> |
| 16 |
#include <string.h> |
| 17 |
#include "src/utils/color_cache_utils.h" |
| 18 |
#include "src/utils/utils.h" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits) { |
| 24 |
const int hash_size = 1 << hash_bits; |
| 25 |
assert(color_cache != NULL); |
| 26 |
assert(hash_bits > 0); |
| 27 |
color_cache->colors_ = (uint32_t*)WebPSafeCalloc( |
| 28 |
(uint64_t)hash_size, sizeof(*color_cache->colors_)); |
| 29 |
if (color_cache->colors_ == NULL) return 0; |
| 30 |
color_cache->hash_shift_ = 32 - hash_bits; |
| 31 |
color_cache->hash_bits_ = hash_bits; |
| 32 |
return 1; |
| 33 |
} |
| 34 |
|
| 35 |
void VP8LColorCacheClear(VP8LColorCache* const color_cache) { |
| 36 |
if (color_cache != NULL) { |
| 37 |
WebPSafeFree(color_cache->colors_); |
| 38 |
color_cache->colors_ = NULL; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
void VP8LColorCacheCopy(const VP8LColorCache* const src, |
| 43 |
VP8LColorCache* const dst) { |
| 44 |
assert(src != NULL); |
| 45 |
assert(dst != NULL); |
| 46 |
assert(src->hash_bits_ == dst->hash_bits_); |
| 47 |
memcpy(dst->colors_, src->colors_, |
| 48 |
((size_t)1u << dst->hash_bits_) * sizeof(*dst->colors_)); |
| 49 |
} |