mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
Refactor VP8LColorCacheContains()
Return key/index if the query is found, and -1 otherwise. The benefit of this is to save a hashing computation. Change-Id: Iff056be330f5fb8204011259ac814f7677dd40fe
This commit is contained in:
parent
40872fb2e6
commit
1269dc7cfb
@ -598,9 +598,10 @@ static void AddSingleLiteralWithCostModel(const uint32_t* const argb,
|
|||||||
uint16_t* const dist_array) {
|
uint16_t* const dist_array) {
|
||||||
double cost_val = prev_cost;
|
double cost_val = prev_cost;
|
||||||
const uint32_t color = argb[0];
|
const uint32_t color = argb[0];
|
||||||
if (use_color_cache && VP8LColorCacheContains(hashers, color)) {
|
const int ix = use_color_cache ? VP8LColorCacheContains(hashers, color) : -1;
|
||||||
|
if (ix >= 0) {
|
||||||
|
// use_color_cache is true and hashers contains color
|
||||||
const double mul0 = 0.68;
|
const double mul0 = 0.68;
|
||||||
const int ix = VP8LColorCacheGetIndex(hashers, color);
|
|
||||||
cost_val += GetCacheCost(cost_model, ix) * mul0;
|
cost_val += GetCacheCost(cost_model, ix) * mul0;
|
||||||
} else {
|
} else {
|
||||||
const double mul1 = 0.82;
|
const double mul1 = 0.82;
|
||||||
@ -1410,9 +1411,11 @@ static int BackwardReferencesHashChainFollowChosenPath(
|
|||||||
i += len;
|
i += len;
|
||||||
} else {
|
} else {
|
||||||
PixOrCopy v;
|
PixOrCopy v;
|
||||||
if (use_color_cache && VP8LColorCacheContains(&hashers, argb[i])) {
|
const int idx =
|
||||||
|
use_color_cache ? VP8LColorCacheContains(&hashers, argb[i]) : -1;
|
||||||
|
if (idx >= 0) {
|
||||||
|
// use_color_cache is true and hashers contains argb[i]
|
||||||
// push pixel as a color cache index
|
// push pixel as a color cache index
|
||||||
const int idx = VP8LColorCacheGetIndex(&hashers, argb[i]);
|
|
||||||
v = PixOrCopyCreateCacheIdx(idx);
|
v = PixOrCopyCreateCacheIdx(idx);
|
||||||
} else {
|
} else {
|
||||||
if (use_color_cache) VP8LColorCacheInsert(&hashers, argb[i]);
|
if (use_color_cache) VP8LColorCacheInsert(&hashers, argb[i]);
|
||||||
@ -1601,8 +1604,9 @@ static int BackwardRefsWithLocalCache(const uint32_t* const argb,
|
|||||||
PixOrCopy* const v = c.cur_pos;
|
PixOrCopy* const v = c.cur_pos;
|
||||||
if (PixOrCopyIsLiteral(v)) {
|
if (PixOrCopyIsLiteral(v)) {
|
||||||
const uint32_t argb_literal = v->argb_or_distance;
|
const uint32_t argb_literal = v->argb_or_distance;
|
||||||
if (VP8LColorCacheContains(&hashers, argb_literal)) {
|
const int ix = VP8LColorCacheContains(&hashers, argb_literal);
|
||||||
const int ix = VP8LColorCacheGetIndex(&hashers, argb_literal);
|
if (ix >= 0) {
|
||||||
|
// hashers contains argb_literal
|
||||||
*v = PixOrCopyCreateCacheIdx(ix);
|
*v = PixOrCopyCreateCacheIdx(ix);
|
||||||
} else {
|
} else {
|
||||||
VP8LColorCacheInsert(&hashers, argb_literal);
|
VP8LColorCacheInsert(&hashers, argb_literal);
|
||||||
|
@ -53,10 +53,11 @@ static WEBP_INLINE int VP8LColorCacheGetIndex(const VP8LColorCache* const cc,
|
|||||||
return (kHashMul * argb) >> cc->hash_shift_;
|
return (kHashMul * argb) >> cc->hash_shift_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the key if cc contains argb, and -1 otherwise.
|
||||||
static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc,
|
static WEBP_INLINE int VP8LColorCacheContains(const VP8LColorCache* const cc,
|
||||||
uint32_t argb) {
|
uint32_t argb) {
|
||||||
const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
|
const uint32_t key = (kHashMul * argb) >> cc->hash_shift_;
|
||||||
return (cc->colors_[key] == argb);
|
return (cc->colors_[key] == argb) ? (int)key : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user