| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifndef WEBP_UTILS_COLOR_CACHE_UTILS_H_ |
| 16 |
#define WEBP_UTILS_COLOR_CACHE_UTILS_H_ |
| 17 |
|
| 18 |
#include <assert.h> |
| 19 |
|
| 20 |
#include "src/dsp/dsp.h" |
| 21 |
#include "src/webp/types.h" |
| 22 |
|
| 23 |
#ifdef __cplusplus |
| 24 |
extern "C" { |
| 25 |
#endif |
| 26 |
|
| 27 |
|
| 28 |
typedef struct { |
| 29 |
uint32_t* colors_; |
| 30 |
int hash_shift_; |
| 31 |
int hash_bits_; |
| 32 |
} VP8LColorCache; |
| 33 |
|
| 34 |
static const uint32_t kHashMul = 0x1e35a7bdu; |
| 35 |
|
| 36 |
static WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW WEBP_INLINE |
| 37 |
int VP8LHashPix(uint32_t argb, int shift) { |
| 38 |
return (int)((argb * kHashMul) >> shift); |
| 39 |
} |
| 40 |
|
| 41 |
static WEBP_INLINE uint32_t VP8LColorCacheLookup( |
| 42 |
const VP8LColorCache* const cc, uint32_t key) { |
| 43 |
assert((key >> cc->hash_bits_) == 0u); |
| 44 |
return cc->colors_[key]; |
| 45 |
} |
| 46 |
|
| 47 |
static WEBP_INLINE void VP8LColorCacheSet(const VP8LColorCache* const cc, |
| 48 |
uint32_t key, uint32_t argb) { |
| 49 |
assert((key >> cc->hash_bits_) == 0u); |
| 50 |
cc->colors_[key] = argb; |
| 51 |
} |
| 52 |
|
| 53 |
static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc, |
| 54 |
uint32_t argb) { |
| 55 |
const int key = VP8LHashPix(argb, cc->hash_shift_); |
| 56 |
cc->colors_[key] = argb; |
| 57 |
} |
| 58 |
|
| 59 |
static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc, |
| 60 |
uint32_t argb) { |
| 61 |
return VP8LHashPix(argb, cc->hash_shift_); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc, |
| 66 |
uint32_t argb) { |
| 67 |
const int key = VP8LHashPix(argb, cc->hash_shift_); |
| 68 |
return (cc->colors_[key] == argb) ? key : -1; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits); |
| 76 |
|
| 77 |
void VP8LColorCacheCopy(const VP8LColorCache* const src, |
| 78 |
VP8LColorCache* const dst); |
| 79 |
|
| 80 |
|
| 81 |
void VP8LColorCacheClear(VP8LColorCache* const color_cache); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
#ifdef __cplusplus |
| 86 |
} |
| 87 |
#endif |
| 88 |
|
| 89 |
#endif |