mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
Remove a duplicated pixel hash implementation.
Change-Id: If0df61add2fdf404f9baf0820ca83faa50f2791c
This commit is contained in:
parent
274daf5415
commit
39eda6584f
@ -1362,7 +1362,7 @@ static int CalculateBestCacheSize(const uint32_t* argb, int quality,
|
||||
const uint32_t g = (pix >> 8) & 0xff;
|
||||
const uint32_t b = (pix >> 0) & 0xff;
|
||||
// The keys of the caches can be derived from the longest one.
|
||||
int key = HashPix(pix, 32 - cache_bits_max);
|
||||
int key = VP8LHashPix(pix, 32 - cache_bits_max);
|
||||
// Do not use the color cache for cache_bits = 0.
|
||||
++histos[0]->blue_[b];
|
||||
++histos[0]->literal_[g];
|
||||
@ -1391,7 +1391,7 @@ static int CalculateBestCacheSize(const uint32_t* argb, int quality,
|
||||
do {
|
||||
if (*argb != argb_prev) {
|
||||
// Efficiency: insert only if the color changes.
|
||||
int key = HashPix(*argb, 32 - cache_bits_max);
|
||||
int key = VP8LHashPix(*argb, 32 - cache_bits_max);
|
||||
for (i = cache_bits_max; i >= 1; --i, key >>= 1) {
|
||||
hashers[i].colors_[key] = *argb;
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
#ifndef WEBP_UTILS_COLOR_CACHE_H_
|
||||
#define WEBP_UTILS_COLOR_CACHE_H_
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "../webp/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -30,7 +32,7 @@ typedef struct {
|
||||
|
||||
static const uint64_t kHashMul = 0x1e35a7bdull;
|
||||
|
||||
static WEBP_INLINE int HashPix(uint32_t argb, int shift) {
|
||||
static WEBP_INLINE int VP8LHashPix(uint32_t argb, int shift) {
|
||||
return (int)(((argb * kHashMul) & 0xffffffffu) >> shift);
|
||||
}
|
||||
|
||||
@ -48,19 +50,19 @@ static WEBP_INLINE void VP8LColorCacheSet(const VP8LColorCache* const cc,
|
||||
|
||||
static WEBP_INLINE void VP8LColorCacheInsert(const VP8LColorCache* const cc,
|
||||
uint32_t argb) {
|
||||
const int key = HashPix(argb, cc->hash_shift_);
|
||||
const int key = VP8LHashPix(argb, cc->hash_shift_);
|
||||
cc->colors_[key] = argb;
|
||||
}
|
||||
|
||||
static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc,
|
||||
uint32_t argb) {
|
||||
return HashPix(argb, cc->hash_shift_);
|
||||
return VP8LHashPix(argb, cc->hash_shift_);
|
||||
}
|
||||
|
||||
// Return the key if cc contains argb, and -1 otherwise.
|
||||
static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc,
|
||||
uint32_t argb) {
|
||||
const int key = HashPix(argb, cc->hash_shift_);
|
||||
const int key = VP8LHashPix(argb, cc->hash_shift_);
|
||||
return (cc->colors_[key] == argb) ? key : -1;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "../webp/decode.h"
|
||||
#include "../webp/encode.h"
|
||||
#include "../webp/format_constants.h" // for MAX_PALETTE_SIZE
|
||||
#include "./color_cache_utils.h"
|
||||
#include "./utils.h"
|
||||
|
||||
// If PRINT_MEM_INFO is defined, extra info (like total memory used, number of
|
||||
@ -252,7 +253,6 @@ int WebPGetColorPalette(const WebPPicture* const pic, uint32_t* const palette) {
|
||||
int num_colors = 0;
|
||||
uint8_t in_use[COLOR_HASH_SIZE] = { 0 };
|
||||
uint32_t colors[COLOR_HASH_SIZE];
|
||||
static const uint64_t kHashMul = 0x1e35a7bdull;
|
||||
const uint32_t* argb = pic->argb;
|
||||
const int width = pic->width;
|
||||
const int height = pic->height;
|
||||
@ -267,7 +267,7 @@ int WebPGetColorPalette(const WebPPicture* const pic, uint32_t* const palette) {
|
||||
continue;
|
||||
}
|
||||
last_pix = argb[x];
|
||||
key = ((last_pix * kHashMul) & 0xffffffffu) >> COLOR_HASH_RIGHT_SHIFT;
|
||||
key = VP8LHashPix(last_pix, COLOR_HASH_RIGHT_SHIFT);
|
||||
while (1) {
|
||||
if (!in_use[key]) {
|
||||
colors[key] = last_pix;
|
||||
|
Loading…
Reference in New Issue
Block a user