OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. |
| 2 // |
| 3 // This code is licensed under the same terms as WebM: |
| 4 // Software License Agreement: http://www.webmproject.org/license/software/ |
| 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
| 6 // ----------------------------------------------------------------------------- |
| 7 // |
| 8 // Color Cache for WebP Lossless |
| 9 // |
| 10 // Authors: Jyrki Alakuijala (jyrki@google.com) |
| 11 // Urvang Joshi (urvang@google.com) |
| 12 |
| 13 #ifndef WEBP_UTILS_COLOR_CACHE_H_ |
| 14 #define WEBP_UTILS_COLOR_CACHE_H_ |
| 15 |
| 16 #include "../webp/types.h" |
| 17 |
| 18 #if defined(__cplusplus) || defined(c_plusplus) |
| 19 extern "C" { |
| 20 #endif |
| 21 |
| 22 // Main color cache struct. |
| 23 typedef struct { |
| 24 uint32_t *colors_; // color entries |
| 25 int hash_shift_; // Hash shift: 32 - hash_bits. |
| 26 } VP8LColorCache; |
| 27 |
| 28 static const uint32_t kHashMul = 0x1e35a7bd; |
| 29 |
| 30 static WEBP_INLINE uint32_t VP8LColorCacheLookup( |
| 31 const VP8LColorCache* const cc, uint32_t key) { |
| 32 assert(key <= (~0U >> cc->hash_shift_)); |
| 33 return cc->colors_[key]; |
| 34 } |
| 35 |
| 36 static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc, |
| 37 uint32_t argb) { |
| 38 const uint32_t key = (kHashMul * argb) >> cc->hash_shift_; |
| 39 cc->colors_[key] = argb; |
| 40 } |
| 41 |
| 42 static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc, |
| 43 uint32_t argb) { |
| 44 return (kHashMul * argb) >> cc->hash_shift_; |
| 45 } |
| 46 |
| 47 static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc, |
| 48 uint32_t argb) { |
| 49 const uint32_t key = (kHashMul * argb) >> cc->hash_shift_; |
| 50 return cc->colors_[key] == argb; |
| 51 } |
| 52 |
| 53 //------------------------------------------------------------------------------ |
| 54 |
| 55 // Initializes the color cache with 'hash_bits' bits for the keys. |
| 56 // Returns false in case of memory error. |
| 57 int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits); |
| 58 |
| 59 // Delete the memory associated to color cache. |
| 60 void VP8LColorCacheClear(VP8LColorCache* const color_cache); |
| 61 |
| 62 //------------------------------------------------------------------------------ |
| 63 |
| 64 #if defined(__cplusplus) || defined(c_plusplus) |
| 65 } |
| 66 #endif |
| 67 |
| 68 #endif // WEBP_UTILS_COLOR_CACHE_H_ |
OLD | NEW |