2012-04-10 17:23:38 -07:00
|
|
|
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
//
|
2013-06-06 23:05:58 -07:00
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
2012-04-10 17:23:38 -07:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Color Cache for WebP Lossless
|
|
|
|
//
|
2012-07-19 16:09:47 -07:00
|
|
|
// Authors: Jyrki Alakuijala (jyrki@google.com)
|
|
|
|
// Urvang Joshi (urvang@google.com)
|
2012-04-10 17:23:38 -07:00
|
|
|
|
|
|
|
#ifndef WEBP_UTILS_COLOR_CACHE_H_
|
|
|
|
#define WEBP_UTILS_COLOR_CACHE_H_
|
|
|
|
|
|
|
|
#include "../webp/types.h"
|
|
|
|
|
2013-11-25 14:43:12 -08:00
|
|
|
#ifdef __cplusplus
|
2012-04-10 17:23:38 -07:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Main color cache struct.
|
|
|
|
typedef struct {
|
|
|
|
uint32_t *colors_; // color entries
|
2014-09-24 09:38:52 +02:00
|
|
|
int hash_shift_; // Hash shift: 32 - hash_bits_.
|
|
|
|
int hash_bits_;
|
2012-04-10 17:23:38 -07:00
|
|
|
} VP8LColorCache;
|
|
|
|
|
|
|
|
static const uint32_t kHashMul = 0x1e35a7bd;
|
|
|
|
|
|
|
|
static WEBP_INLINE uint32_t VP8LColorCacheLookup(
|
|
|
|
const VP8LColorCache* const cc, uint32_t key) {
|
2015-07-02 14:56:37 +00:00
|
|
|
assert((key >> cc->hash_bits_) == 0u);
|
2012-04-10 17:23:38 -07:00
|
|
|
return cc->colors_[key];
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:56:37 +00:00
|
|
|
static WEBP_INLINE void VP8LColorCacheSet(const VP8LColorCache* const cc,
|
|
|
|
uint32_t key, uint32_t argb) {
|
|
|
|
assert((key >> cc->hash_bits_) == 0u);
|
|
|
|
cc->colors_[key] = argb;
|
|
|
|
}
|
|
|
|
|
2012-04-10 17:23:38 -07:00
|
|
|
static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc,
|
|
|
|
uint32_t argb) {
|
|
|
|
const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
|
|
|
|
cc->colors_[key] = argb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc,
|
|
|
|
uint32_t argb) {
|
|
|
|
return (kHashMul * argb) >> cc->hash_shift_;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc,
|
|
|
|
uint32_t argb) {
|
|
|
|
const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
|
2015-07-02 14:56:37 +00:00
|
|
|
return (cc->colors_[key] == argb);
|
2012-04-10 17:23:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Initializes the color cache with 'hash_bits' bits for the keys.
|
|
|
|
// Returns false in case of memory error.
|
|
|
|
int VP8LColorCacheInit(VP8LColorCache* const color_cache, int hash_bits);
|
|
|
|
|
2014-09-24 09:38:52 +02:00
|
|
|
void VP8LColorCacheCopy(const VP8LColorCache* const src,
|
|
|
|
VP8LColorCache* const dst);
|
|
|
|
|
2012-07-16 19:13:58 -07:00
|
|
|
// Delete the memory associated to color cache.
|
2012-04-12 11:31:17 +00:00
|
|
|
void VP8LColorCacheClear(VP8LColorCache* const color_cache);
|
|
|
|
|
2012-04-10 17:23:38 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-11-25 14:43:12 -08:00
|
|
|
#ifdef __cplusplus
|
2012-04-10 17:23:38 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // WEBP_UTILS_COLOR_CACHE_H_
|