mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
factorize and unify GetAlpha() between the C and SSE2 version
patch by Christian Duvivier (cduvivier at google dot com) Change-Id: I47ac75010aa4036cf09f13d23043e654c4966a00
This commit is contained in:
parent
6d0e66c23e
commit
8dfc4c6f17
@ -24,13 +24,14 @@ static int ClipAlpha(int alpha) {
|
|||||||
return alpha < 0 ? 0 : alpha > 255 ? 255 : alpha;
|
return alpha < 0 ? 0 : alpha > 255 ? 255 : alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetAlpha(const int histo[MAX_COEFF_THRESH]) {
|
int VP8GetAlpha(const int histo[MAX_COEFF_THRESH + 1]) {
|
||||||
int num = 0, den = 0, val = 0;
|
int num = 0, den = 0, val = 0;
|
||||||
int k;
|
int k;
|
||||||
int alpha;
|
int alpha;
|
||||||
|
// note: changing this loop to avoid the numerous "k + 1" slows things down.
|
||||||
for (k = 0; k < MAX_COEFF_THRESH; ++k) {
|
for (k = 0; k < MAX_COEFF_THRESH; ++k) {
|
||||||
if (histo[k]) {
|
if (histo[k + 1]) {
|
||||||
val += histo[k];
|
val += histo[k + 1];
|
||||||
num += val * (k + 1);
|
num += val * (k + 1);
|
||||||
den += (k + 1) * (k + 1);
|
den += (k + 1) * (k + 1);
|
||||||
}
|
}
|
||||||
@ -42,20 +43,25 @@ static int GetAlpha(const int histo[MAX_COEFF_THRESH]) {
|
|||||||
|
|
||||||
static int CollectHistogram(const uint8_t* ref, const uint8_t* pred,
|
static int CollectHistogram(const uint8_t* ref, const uint8_t* pred,
|
||||||
int start_block, int end_block) {
|
int start_block, int end_block) {
|
||||||
int histo[MAX_COEFF_THRESH] = { 0 };
|
int histo[MAX_COEFF_THRESH + 1] = { 0 };
|
||||||
int16_t out[16];
|
int16_t out[16];
|
||||||
int j, k;
|
int j, k;
|
||||||
for (j = start_block; j < end_block; ++j) {
|
for (j = start_block; j < end_block; ++j) {
|
||||||
VP8FTransform(ref + VP8Scan[j], pred + VP8Scan[j], out);
|
VP8FTransform(ref + VP8Scan[j], pred + VP8Scan[j], out);
|
||||||
|
|
||||||
|
// Convert coefficients to bin (within out[]).
|
||||||
for (k = 0; k < 16; ++k) {
|
for (k = 0; k < 16; ++k) {
|
||||||
const int v = abs(out[k]) >> 2;
|
const int v = abs(out[k]) >> 2;
|
||||||
if (v) {
|
out[k] = (v > MAX_COEFF_THRESH) ? MAX_COEFF_THRESH : v;
|
||||||
const int bin = (v > MAX_COEFF_THRESH) ? MAX_COEFF_THRESH : v;
|
}
|
||||||
histo[bin - 1]++;
|
|
||||||
}
|
// Use bin to update histogram.
|
||||||
|
for (k = 0; k < 16; ++k) {
|
||||||
|
histo[out[k]]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GetAlpha(histo);
|
|
||||||
|
return VP8GetAlpha(histo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -61,21 +61,7 @@ static int CollectHistogramSSE2(const uint8_t* ref, const uint8_t* pred,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
return VP8GetAlpha(histo);
|
||||||
int num = 0, den = 0, val = 0;
|
|
||||||
int alpha;
|
|
||||||
for (k = 0; k < MAX_COEFF_THRESH; ++k) {
|
|
||||||
if (histo[k + 1]) {
|
|
||||||
val += histo[k + 1];
|
|
||||||
num += val * (k + 1);
|
|
||||||
den += (k + 1) * (k + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// we scale the value to a usable [0..255] range
|
|
||||||
alpha = den ? 10 * num / den - 5 : 0;
|
|
||||||
alpha = alpha < 0 ? 0 : alpha > 255 ? 255 : alpha;
|
|
||||||
return alpha;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -446,6 +446,8 @@ int VP8EncFinishLayer(VP8Encoder* const enc); // finalize coding
|
|||||||
void VP8EncDeleteLayer(VP8Encoder* enc); // reclaim memory
|
void VP8EncDeleteLayer(VP8Encoder* enc); // reclaim memory
|
||||||
|
|
||||||
// in dsp.c
|
// in dsp.c
|
||||||
|
int VP8GetAlpha(const int histo[MAX_COEFF_THRESH + 1]);
|
||||||
|
|
||||||
// Transforms
|
// Transforms
|
||||||
// VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
|
// VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
|
||||||
// will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
|
// will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
|
||||||
|
Loading…
Reference in New Issue
Block a user