mirror of
https://github.com/webmproject/libwebp.git
synced 2025-02-12 15:02:53 +01:00
* fix off-by-one zthresh calculation
* remove the sharpening for non luma-AC coeffs * adjust the bias a little bit to compensate for this Using the multiply-by-reciprocal doesn't always give the same result as the exact divide, given the QFIX fixed-point precision we use. -> removed few now-unneeded SSE2 instructions (and checked for bit-exactness using -noasm) Change-Id: Ib68057cbdd69c4e589af56a01a8e7085db762c24
This commit is contained in:
parent
ad9dec0c24
commit
d513bb62bc
@ -830,8 +830,6 @@ static int QuantizeBlockSSE2(int16_t in[16], int16_t out[16],
|
||||
const __m128i bias8 = _mm_loadu_si128((__m128i*)&mtx->bias_[8]);
|
||||
const __m128i q0 = _mm_loadu_si128((__m128i*)&mtx->q_[0]);
|
||||
const __m128i q8 = _mm_loadu_si128((__m128i*)&mtx->q_[8]);
|
||||
const __m128i zthresh0 = _mm_loadu_si128((__m128i*)&mtx->zthresh_[0]);
|
||||
const __m128i zthresh8 = _mm_loadu_si128((__m128i*)&mtx->zthresh_[8]);
|
||||
|
||||
// sign(in) = in >> 15 (0x0000 if positive, 0xffff if negative)
|
||||
const __m128i sign0 = _mm_srai_epi16(in0, 15);
|
||||
@ -894,17 +892,8 @@ static int QuantizeBlockSSE2(int16_t in[16], int16_t out[16],
|
||||
in0 = _mm_mullo_epi16(out0, q0);
|
||||
in8 = _mm_mullo_epi16(out8, q8);
|
||||
|
||||
// if (coeff <= mtx->zthresh_) {in=0; out=0;}
|
||||
{
|
||||
__m128i cmp0 = _mm_cmpgt_epi16(coeff0, zthresh0);
|
||||
__m128i cmp8 = _mm_cmpgt_epi16(coeff8, zthresh8);
|
||||
in0 = _mm_and_si128(in0, cmp0);
|
||||
in8 = _mm_and_si128(in8, cmp8);
|
||||
_mm_storeu_si128((__m128i*)&in[0], in0);
|
||||
_mm_storeu_si128((__m128i*)&in[8], in8);
|
||||
out0 = _mm_and_si128(out0, cmp0);
|
||||
out8 = _mm_and_si128(out8, cmp8);
|
||||
}
|
||||
_mm_storeu_si128((__m128i*)&in[0], in0);
|
||||
_mm_storeu_si128((__m128i*)&in[8], in8);
|
||||
|
||||
// zigzag the output before storing it.
|
||||
//
|
||||
|
@ -169,19 +169,13 @@ static const uint16_t kAcTable2[128] = {
|
||||
385, 393, 401, 409, 416, 424, 432, 440
|
||||
};
|
||||
|
||||
static const uint16_t kCoeffThresh[16] = {
|
||||
0, 10, 20, 30,
|
||||
10, 20, 30, 30,
|
||||
20, 30, 30, 30,
|
||||
30, 30, 30, 30
|
||||
};
|
||||
|
||||
static const uint8_t kBiasMatrices[3][2] = { // [luma-ac,luma-dc,chroma][dc,ac]
|
||||
{ 96, 110 }, { 96, 112 }, { 112, 120 }
|
||||
{ 96, 110 }, { 96, 108 }, { 110, 115 }
|
||||
};
|
||||
|
||||
// Sharpening by (slightly) raising the hi-frequency coeffs.
|
||||
// Hack-ish but helpful for mid-bitrate range. Use with care.
|
||||
#define SHARPEN_BITS 11 // number of descaling bits for sharpening bias
|
||||
static const uint8_t kFreqSharpening[16] = {
|
||||
0, 30, 60, 90,
|
||||
30, 60, 90, 90,
|
||||
@ -204,9 +198,15 @@ static int ExpandMatrix(VP8Matrix* const m, int type) {
|
||||
const int bias = kBiasMatrices[type][is_ac_coeff];
|
||||
m->iq_[i] = (1 << QFIX) / m->q_[i];
|
||||
m->bias_[i] = BIAS(bias);
|
||||
// TODO(skal): tune kCoeffThresh[]
|
||||
m->zthresh_[i] = ((256 /*+ kCoeffThresh[i]*/ - bias) * m->q_[i] + 127) >> 8;
|
||||
m->sharpen_[i] = (kFreqSharpening[i] * m->q_[i]) >> 11;
|
||||
// zthresh_ is the exact value such that QUANTDIV(coeff, iQ, B) is:
|
||||
// * zero if coeff <= zthresh
|
||||
// * non-zero if coeff > zthresh
|
||||
m->zthresh_[i] = ((1 << QFIX) - 1 - m->bias_[i]) / m->iq_[i];
|
||||
if (type == 0) { // we only use sharpening for AC luma coeffs
|
||||
m->sharpen_[i] = (kFreqSharpening[i] * m->q_[i]) >> SHARPEN_BITS;
|
||||
} else {
|
||||
m->sharpen_[i] = 0;
|
||||
}
|
||||
sum += m->q_[i];
|
||||
}
|
||||
return (sum + 8) >> 4;
|
||||
|
Loading…
x
Reference in New Issue
Block a user