Improve 32x32 forward dct
The commit improves the 32x32 forward dct implementation: 1. change to use same constants and rounding as other forward dcts 2. select rounding to specifically minimize the roundtrip error, which improved average 19/block to .77/block using 100000 random input. Test showed a small but consistent gain on all test sets, about .15% Change-Id: If0afd6a71880a522f60c1c234be0462092c2eb53
This commit is contained in:
Родитель
9770d564f4
Коммит
66d94ac13c
|
@ -61,4 +61,11 @@ static INLINE int dct_const_round_shift(int input) {
|
|||
assert(INT16_MIN <= rv && rv <= INT16_MAX);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static INLINE int dct_32_round(int input) {
|
||||
int rv = (input + DCT_CONST_ROUNDING) >> DCT_CONST_BITS;
|
||||
assert(-131072 <= rv && rv <= 131071);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -744,412 +744,9 @@ void vp9_short_fht16x16_c(int16_t *input, int16_t *output,
|
|||
}
|
||||
}
|
||||
|
||||
#define TEST_INT_32x32_DCT 1
|
||||
|
||||
#if !TEST_INT_32x32_DCT
|
||||
|
||||
static void dct32_1d(double *input, double *output, int stride) {
|
||||
static const double C1 = 0.998795456205; // cos(pi * 1 / 64)
|
||||
static const double C2 = 0.995184726672; // cos(pi * 2 / 64)
|
||||
static const double C3 = 0.989176509965; // cos(pi * 3 / 64)
|
||||
static const double C4 = 0.980785280403; // cos(pi * 4 / 64)
|
||||
static const double C5 = 0.970031253195; // cos(pi * 5 / 64)
|
||||
static const double C6 = 0.956940335732; // cos(pi * 6 / 64)
|
||||
static const double C7 = 0.941544065183; // cos(pi * 7 / 64)
|
||||
static const double C8 = 0.923879532511; // cos(pi * 8 / 64)
|
||||
static const double C9 = 0.903989293123; // cos(pi * 9 / 64)
|
||||
static const double C10 = 0.881921264348; // cos(pi * 10 / 64)
|
||||
static const double C11 = 0.857728610000; // cos(pi * 11 / 64)
|
||||
static const double C12 = 0.831469612303; // cos(pi * 12 / 64)
|
||||
static const double C13 = 0.803207531481; // cos(pi * 13 / 64)
|
||||
static const double C14 = 0.773010453363; // cos(pi * 14 / 64)
|
||||
static const double C15 = 0.740951125355; // cos(pi * 15 / 64)
|
||||
static const double C16 = 0.707106781187; // cos(pi * 16 / 64)
|
||||
static const double C17 = 0.671558954847; // cos(pi * 17 / 64)
|
||||
static const double C18 = 0.634393284164; // cos(pi * 18 / 64)
|
||||
static const double C19 = 0.595699304492; // cos(pi * 19 / 64)
|
||||
static const double C20 = 0.555570233020; // cos(pi * 20 / 64)
|
||||
static const double C21 = 0.514102744193; // cos(pi * 21 / 64)
|
||||
static const double C22 = 0.471396736826; // cos(pi * 22 / 64)
|
||||
static const double C23 = 0.427555093430; // cos(pi * 23 / 64)
|
||||
static const double C24 = 0.382683432365; // cos(pi * 24 / 64)
|
||||
static const double C25 = 0.336889853392; // cos(pi * 25 / 64)
|
||||
static const double C26 = 0.290284677254; // cos(pi * 26 / 64)
|
||||
static const double C27 = 0.242980179903; // cos(pi * 27 / 64)
|
||||
static const double C28 = 0.195090322016; // cos(pi * 28 / 64)
|
||||
static const double C29 = 0.146730474455; // cos(pi * 29 / 64)
|
||||
static const double C30 = 0.098017140330; // cos(pi * 30 / 64)
|
||||
static const double C31 = 0.049067674327; // cos(pi * 31 / 64)
|
||||
|
||||
double step[32];
|
||||
|
||||
// Stage 1
|
||||
step[0] = input[stride*0] + input[stride*(32 - 1)];
|
||||
step[1] = input[stride*1] + input[stride*(32 - 2)];
|
||||
step[2] = input[stride*2] + input[stride*(32 - 3)];
|
||||
step[3] = input[stride*3] + input[stride*(32 - 4)];
|
||||
step[4] = input[stride*4] + input[stride*(32 - 5)];
|
||||
step[5] = input[stride*5] + input[stride*(32 - 6)];
|
||||
step[6] = input[stride*6] + input[stride*(32 - 7)];
|
||||
step[7] = input[stride*7] + input[stride*(32 - 8)];
|
||||
step[8] = input[stride*8] + input[stride*(32 - 9)];
|
||||
step[9] = input[stride*9] + input[stride*(32 - 10)];
|
||||
step[10] = input[stride*10] + input[stride*(32 - 11)];
|
||||
step[11] = input[stride*11] + input[stride*(32 - 12)];
|
||||
step[12] = input[stride*12] + input[stride*(32 - 13)];
|
||||
step[13] = input[stride*13] + input[stride*(32 - 14)];
|
||||
step[14] = input[stride*14] + input[stride*(32 - 15)];
|
||||
step[15] = input[stride*15] + input[stride*(32 - 16)];
|
||||
step[16] = -input[stride*16] + input[stride*(32 - 17)];
|
||||
step[17] = -input[stride*17] + input[stride*(32 - 18)];
|
||||
step[18] = -input[stride*18] + input[stride*(32 - 19)];
|
||||
step[19] = -input[stride*19] + input[stride*(32 - 20)];
|
||||
step[20] = -input[stride*20] + input[stride*(32 - 21)];
|
||||
step[21] = -input[stride*21] + input[stride*(32 - 22)];
|
||||
step[22] = -input[stride*22] + input[stride*(32 - 23)];
|
||||
step[23] = -input[stride*23] + input[stride*(32 - 24)];
|
||||
step[24] = -input[stride*24] + input[stride*(32 - 25)];
|
||||
step[25] = -input[stride*25] + input[stride*(32 - 26)];
|
||||
step[26] = -input[stride*26] + input[stride*(32 - 27)];
|
||||
step[27] = -input[stride*27] + input[stride*(32 - 28)];
|
||||
step[28] = -input[stride*28] + input[stride*(32 - 29)];
|
||||
step[29] = -input[stride*29] + input[stride*(32 - 30)];
|
||||
step[30] = -input[stride*30] + input[stride*(32 - 31)];
|
||||
step[31] = -input[stride*31] + input[stride*(32 - 32)];
|
||||
|
||||
// Stage 2
|
||||
output[stride*0] = step[0] + step[16 - 1];
|
||||
output[stride*1] = step[1] + step[16 - 2];
|
||||
output[stride*2] = step[2] + step[16 - 3];
|
||||
output[stride*3] = step[3] + step[16 - 4];
|
||||
output[stride*4] = step[4] + step[16 - 5];
|
||||
output[stride*5] = step[5] + step[16 - 6];
|
||||
output[stride*6] = step[6] + step[16 - 7];
|
||||
output[stride*7] = step[7] + step[16 - 8];
|
||||
output[stride*8] = -step[8] + step[16 - 9];
|
||||
output[stride*9] = -step[9] + step[16 - 10];
|
||||
output[stride*10] = -step[10] + step[16 - 11];
|
||||
output[stride*11] = -step[11] + step[16 - 12];
|
||||
output[stride*12] = -step[12] + step[16 - 13];
|
||||
output[stride*13] = -step[13] + step[16 - 14];
|
||||
output[stride*14] = -step[14] + step[16 - 15];
|
||||
output[stride*15] = -step[15] + step[16 - 16];
|
||||
|
||||
output[stride*16] = step[16];
|
||||
output[stride*17] = step[17];
|
||||
output[stride*18] = step[18];
|
||||
output[stride*19] = step[19];
|
||||
|
||||
output[stride*20] = (-step[20] + step[27])*C16;
|
||||
output[stride*21] = (-step[21] + step[26])*C16;
|
||||
output[stride*22] = (-step[22] + step[25])*C16;
|
||||
output[stride*23] = (-step[23] + step[24])*C16;
|
||||
|
||||
output[stride*24] = (step[24] + step[23])*C16;
|
||||
output[stride*25] = (step[25] + step[22])*C16;
|
||||
output[stride*26] = (step[26] + step[21])*C16;
|
||||
output[stride*27] = (step[27] + step[20])*C16;
|
||||
|
||||
output[stride*28] = step[28];
|
||||
output[stride*29] = step[29];
|
||||
output[stride*30] = step[30];
|
||||
output[stride*31] = step[31];
|
||||
|
||||
// Stage 3
|
||||
step[0] = output[stride*0] + output[stride*(8 - 1)];
|
||||
step[1] = output[stride*1] + output[stride*(8 - 2)];
|
||||
step[2] = output[stride*2] + output[stride*(8 - 3)];
|
||||
step[3] = output[stride*3] + output[stride*(8 - 4)];
|
||||
step[4] = -output[stride*4] + output[stride*(8 - 5)];
|
||||
step[5] = -output[stride*5] + output[stride*(8 - 6)];
|
||||
step[6] = -output[stride*6] + output[stride*(8 - 7)];
|
||||
step[7] = -output[stride*7] + output[stride*(8 - 8)];
|
||||
step[8] = output[stride*8];
|
||||
step[9] = output[stride*9];
|
||||
step[10] = (-output[stride*10] + output[stride*13])*C16;
|
||||
step[11] = (-output[stride*11] + output[stride*12])*C16;
|
||||
step[12] = (output[stride*12] + output[stride*11])*C16;
|
||||
step[13] = (output[stride*13] + output[stride*10])*C16;
|
||||
step[14] = output[stride*14];
|
||||
step[15] = output[stride*15];
|
||||
|
||||
step[16] = output[stride*16] + output[stride*23];
|
||||
step[17] = output[stride*17] + output[stride*22];
|
||||
step[18] = output[stride*18] + output[stride*21];
|
||||
step[19] = output[stride*19] + output[stride*20];
|
||||
step[20] = -output[stride*20] + output[stride*19];
|
||||
step[21] = -output[stride*21] + output[stride*18];
|
||||
step[22] = -output[stride*22] + output[stride*17];
|
||||
step[23] = -output[stride*23] + output[stride*16];
|
||||
step[24] = -output[stride*24] + output[stride*31];
|
||||
step[25] = -output[stride*25] + output[stride*30];
|
||||
step[26] = -output[stride*26] + output[stride*29];
|
||||
step[27] = -output[stride*27] + output[stride*28];
|
||||
step[28] = output[stride*28] + output[stride*27];
|
||||
step[29] = output[stride*29] + output[stride*26];
|
||||
step[30] = output[stride*30] + output[stride*25];
|
||||
step[31] = output[stride*31] + output[stride*24];
|
||||
|
||||
// Stage 4
|
||||
output[stride*0] = step[0] + step[3];
|
||||
output[stride*1] = step[1] + step[2];
|
||||
output[stride*2] = -step[2] + step[1];
|
||||
output[stride*3] = -step[3] + step[0];
|
||||
output[stride*4] = step[4];
|
||||
output[stride*5] = (-step[5] + step[6])*C16;
|
||||
output[stride*6] = (step[6] + step[5])*C16;
|
||||
output[stride*7] = step[7];
|
||||
output[stride*8] = step[8] + step[11];
|
||||
output[stride*9] = step[9] + step[10];
|
||||
output[stride*10] = -step[10] + step[9];
|
||||
output[stride*11] = -step[11] + step[8];
|
||||
output[stride*12] = -step[12] + step[15];
|
||||
output[stride*13] = -step[13] + step[14];
|
||||
output[stride*14] = step[14] + step[13];
|
||||
output[stride*15] = step[15] + step[12];
|
||||
|
||||
output[stride*16] = step[16];
|
||||
output[stride*17] = step[17];
|
||||
output[stride*18] = step[18]*-C8 + step[29]*C24;
|
||||
output[stride*19] = step[19]*-C8 + step[28]*C24;
|
||||
output[stride*20] = step[20]*-C24 + step[27]*-C8;
|
||||
output[stride*21] = step[21]*-C24 + step[26]*-C8;
|
||||
output[stride*22] = step[22];
|
||||
output[stride*23] = step[23];
|
||||
output[stride*24] = step[24];
|
||||
output[stride*25] = step[25];
|
||||
output[stride*26] = step[26]*C24 + step[21]*-C8;
|
||||
output[stride*27] = step[27]*C24 + step[20]*-C8;
|
||||
output[stride*28] = step[28]*C8 + step[19]*C24;
|
||||
output[stride*29] = step[29]*C8 + step[18]*C24;
|
||||
output[stride*30] = step[30];
|
||||
output[stride*31] = step[31];
|
||||
|
||||
// Stage 5
|
||||
step[0] = (output[stride*0] + output[stride*1]) * C16;
|
||||
step[1] = (-output[stride*1] + output[stride*0]) * C16;
|
||||
step[2] = output[stride*2]*C24 + output[stride*3] * C8;
|
||||
step[3] = output[stride*3]*C24 - output[stride*2] * C8;
|
||||
step[4] = output[stride*4] + output[stride*5];
|
||||
step[5] = -output[stride*5] + output[stride*4];
|
||||
step[6] = -output[stride*6] + output[stride*7];
|
||||
step[7] = output[stride*7] + output[stride*6];
|
||||
step[8] = output[stride*8];
|
||||
step[9] = output[stride*9]*-C8 + output[stride*14]*C24;
|
||||
step[10] = output[stride*10]*-C24 + output[stride*13]*-C8;
|
||||
step[11] = output[stride*11];
|
||||
step[12] = output[stride*12];
|
||||
step[13] = output[stride*13]*C24 + output[stride*10]*-C8;
|
||||
step[14] = output[stride*14]*C8 + output[stride*9]*C24;
|
||||
step[15] = output[stride*15];
|
||||
|
||||
step[16] = output[stride*16] + output[stride*19];
|
||||
step[17] = output[stride*17] + output[stride*18];
|
||||
step[18] = -output[stride*18] + output[stride*17];
|
||||
step[19] = -output[stride*19] + output[stride*16];
|
||||
step[20] = -output[stride*20] + output[stride*23];
|
||||
step[21] = -output[stride*21] + output[stride*22];
|
||||
step[22] = output[stride*22] + output[stride*21];
|
||||
step[23] = output[stride*23] + output[stride*20];
|
||||
step[24] = output[stride*24] + output[stride*27];
|
||||
step[25] = output[stride*25] + output[stride*26];
|
||||
step[26] = -output[stride*26] + output[stride*25];
|
||||
step[27] = -output[stride*27] + output[stride*24];
|
||||
step[28] = -output[stride*28] + output[stride*31];
|
||||
step[29] = -output[stride*29] + output[stride*30];
|
||||
step[30] = output[stride*30] + output[stride*29];
|
||||
step[31] = output[stride*31] + output[stride*28];
|
||||
|
||||
// Stage 6
|
||||
output[stride*0] = step[0];
|
||||
output[stride*1] = step[1];
|
||||
output[stride*2] = step[2];
|
||||
output[stride*3] = step[3];
|
||||
output[stride*4] = step[4]*C28 + step[7]*C4;
|
||||
output[stride*5] = step[5]*C12 + step[6]*C20;
|
||||
output[stride*6] = step[6]*C12 + step[5]*-C20;
|
||||
output[stride*7] = step[7]*C28 + step[4]*-C4;
|
||||
output[stride*8] = step[8] + step[9];
|
||||
output[stride*9] = -step[9] + step[8];
|
||||
output[stride*10] = -step[10] + step[11];
|
||||
output[stride*11] = step[11] + step[10];
|
||||
output[stride*12] = step[12] + step[13];
|
||||
output[stride*13] = -step[13] + step[12];
|
||||
output[stride*14] = -step[14] + step[15];
|
||||
output[stride*15] = step[15] + step[14];
|
||||
|
||||
output[stride*16] = step[16];
|
||||
output[stride*17] = step[17]*-C4 + step[30]*C28;
|
||||
output[stride*18] = step[18]*-C28 + step[29]*-C4;
|
||||
output[stride*19] = step[19];
|
||||
output[stride*20] = step[20];
|
||||
output[stride*21] = step[21]*-C20 + step[26]*C12;
|
||||
output[stride*22] = step[22]*-C12 + step[25]*-C20;
|
||||
output[stride*23] = step[23];
|
||||
output[stride*24] = step[24];
|
||||
output[stride*25] = step[25]*C12 + step[22]*-C20;
|
||||
output[stride*26] = step[26]*C20 + step[21]*C12;
|
||||
output[stride*27] = step[27];
|
||||
output[stride*28] = step[28];
|
||||
output[stride*29] = step[29]*C28 + step[18]*-C4;
|
||||
output[stride*30] = step[30]*C4 + step[17]*C28;
|
||||
output[stride*31] = step[31];
|
||||
|
||||
// Stage 7
|
||||
step[0] = output[stride*0];
|
||||
step[1] = output[stride*1];
|
||||
step[2] = output[stride*2];
|
||||
step[3] = output[stride*3];
|
||||
step[4] = output[stride*4];
|
||||
step[5] = output[stride*5];
|
||||
step[6] = output[stride*6];
|
||||
step[7] = output[stride*7];
|
||||
step[8] = output[stride*8]*C30 + output[stride*15]*C2;
|
||||
step[9] = output[stride*9]*C14 + output[stride*14]*C18;
|
||||
step[10] = output[stride*10]*C22 + output[stride*13]*C10;
|
||||
step[11] = output[stride*11]*C6 + output[stride*12]*C26;
|
||||
step[12] = output[stride*12]*C6 + output[stride*11]*-C26;
|
||||
step[13] = output[stride*13]*C22 + output[stride*10]*-C10;
|
||||
step[14] = output[stride*14]*C14 + output[stride*9]*-C18;
|
||||
step[15] = output[stride*15]*C30 + output[stride*8]*-C2;
|
||||
|
||||
step[16] = output[stride*16] + output[stride*17];
|
||||
step[17] = -output[stride*17] + output[stride*16];
|
||||
step[18] = -output[stride*18] + output[stride*19];
|
||||
step[19] = output[stride*19] + output[stride*18];
|
||||
step[20] = output[stride*20] + output[stride*21];
|
||||
step[21] = -output[stride*21] + output[stride*20];
|
||||
step[22] = -output[stride*22] + output[stride*23];
|
||||
step[23] = output[stride*23] + output[stride*22];
|
||||
step[24] = output[stride*24] + output[stride*25];
|
||||
step[25] = -output[stride*25] + output[stride*24];
|
||||
step[26] = -output[stride*26] + output[stride*27];
|
||||
step[27] = output[stride*27] + output[stride*26];
|
||||
step[28] = output[stride*28] + output[stride*29];
|
||||
step[29] = -output[stride*29] + output[stride*28];
|
||||
step[30] = -output[stride*30] + output[stride*31];
|
||||
step[31] = output[stride*31] + output[stride*30];
|
||||
|
||||
// Final stage --- outputs indices are bit-reversed.
|
||||
output[stride*0] = step[0];
|
||||
output[stride*16] = step[1];
|
||||
output[stride*8] = step[2];
|
||||
output[stride*24] = step[3];
|
||||
output[stride*4] = step[4];
|
||||
output[stride*20] = step[5];
|
||||
output[stride*12] = step[6];
|
||||
output[stride*28] = step[7];
|
||||
output[stride*2] = step[8];
|
||||
output[stride*18] = step[9];
|
||||
output[stride*10] = step[10];
|
||||
output[stride*26] = step[11];
|
||||
output[stride*6] = step[12];
|
||||
output[stride*22] = step[13];
|
||||
output[stride*14] = step[14];
|
||||
output[stride*30] = step[15];
|
||||
|
||||
output[stride*1] = step[16]*C31 + step[31]*C1;
|
||||
output[stride*17] = step[17]*C15 + step[30]*C17;
|
||||
output[stride*9] = step[18]*C23 + step[29]*C9;
|
||||
output[stride*25] = step[19]*C7 + step[28]*C25;
|
||||
output[stride*5] = step[20]*C27 + step[27]*C5;
|
||||
output[stride*21] = step[21]*C11 + step[26]*C21;
|
||||
output[stride*13] = step[22]*C19 + step[25]*C13;
|
||||
output[stride*29] = step[23]*C3 + step[24]*C29;
|
||||
output[stride*3] = step[24]*C3 + step[23]*-C29;
|
||||
output[stride*19] = step[25]*C19 + step[22]*-C13;
|
||||
output[stride*11] = step[26]*C11 + step[21]*-C21;
|
||||
output[stride*27] = step[27]*C27 + step[20]*-C5;
|
||||
output[stride*7] = step[28]*C7 + step[19]*-C25;
|
||||
output[stride*23] = step[29]*C23 + step[18]*-C9;
|
||||
output[stride*15] = step[30]*C15 + step[17]*-C17;
|
||||
output[stride*31] = step[31]*C31 + step[16]*-C1;
|
||||
}
|
||||
|
||||
void vp9_short_fdct32x32_c(int16_t *input, int16_t *out, int pitch) {
|
||||
vp9_clear_system_state(); // Make it simd safe : __asm emms;
|
||||
{
|
||||
int shortpitch = pitch >> 1;
|
||||
int i, j;
|
||||
double output[1024];
|
||||
// First transform columns
|
||||
for (i = 0; i < 32; i++) {
|
||||
double temp_in[32], temp_out[32];
|
||||
for (j = 0; j < 32; j++)
|
||||
temp_in[j] = input[j*shortpitch + i];
|
||||
dct32_1d(temp_in, temp_out, 1);
|
||||
for (j = 0; j < 32; j++)
|
||||
output[j*32 + i] = temp_out[j];
|
||||
}
|
||||
// Then transform rows
|
||||
for (i = 0; i < 32; ++i) {
|
||||
double temp_in[32], temp_out[32];
|
||||
for (j = 0; j < 32; ++j)
|
||||
temp_in[j] = output[j + i*32];
|
||||
dct32_1d(temp_in, temp_out, 1);
|
||||
for (j = 0; j < 32; ++j)
|
||||
output[j + i*32] = temp_out[j];
|
||||
}
|
||||
// Scale by some magic number
|
||||
for (i = 0; i < 1024; i++) {
|
||||
out[i] = (short)round(output[i]/4);
|
||||
}
|
||||
}
|
||||
|
||||
vp9_clear_system_state(); // Make it simd safe : __asm emms;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define RIGHT_SHIFT 13
|
||||
#define ROUNDING (1 << (RIGHT_SHIFT - 1))
|
||||
|
||||
static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
||||
static const int16_t C1 = 8182; // 2^13
|
||||
static const int16_t C2 = 8153;
|
||||
static const int16_t C3 = 8103;
|
||||
static const int16_t C4 = 8035;
|
||||
static const int16_t C5 = 7946;
|
||||
static const int16_t C6 = 7839;
|
||||
static const int16_t C7 = 7713;
|
||||
static const int16_t C8 = 7568;
|
||||
static const int16_t C9 = 7405;
|
||||
static const int16_t C10 = 7225;
|
||||
static const int16_t C11 = 7027;
|
||||
static const int16_t C12 = 6811;
|
||||
static const int16_t C13 = 6580;
|
||||
static const int16_t C14 = 6333;
|
||||
static const int16_t C15 = 6070;
|
||||
static const int16_t C16 = 5793;
|
||||
static const int16_t C17 = 5501;
|
||||
static const int16_t C18 = 5197;
|
||||
static const int16_t C19 = 4880;
|
||||
static const int16_t C20 = 4551;
|
||||
static const int16_t C21 = 4212;
|
||||
static const int16_t C22 = 3862;
|
||||
static const int16_t C23 = 3503;
|
||||
static const int16_t C24 = 3135;
|
||||
static const int16_t C25 = 2760;
|
||||
static const int16_t C26 = 2378;
|
||||
static const int16_t C27 = 1990;
|
||||
static const int16_t C28 = 1598;
|
||||
static const int16_t C29 = 1202;
|
||||
static const int16_t C30 = 803;
|
||||
static const int16_t C31 = 402;
|
||||
|
||||
static void dct32_1d(int *input, int *output) {
|
||||
int step[32];
|
||||
|
||||
int last_rounding = 0;
|
||||
int final_shift = RIGHT_SHIFT;
|
||||
int final_rounding = 0;
|
||||
|
||||
if (last_shift_bits > 0)
|
||||
last_rounding = 1 << (last_shift_bits - 1);
|
||||
|
||||
final_shift += last_shift_bits;
|
||||
if (final_shift > 0)
|
||||
final_rounding = 1 << (final_shift - 1);
|
||||
|
||||
// Stage 1
|
||||
step[0] = input[0] + input[(32 - 1)];
|
||||
step[1] = input[1] + input[(32 - 2)];
|
||||
|
@ -1207,15 +804,15 @@ static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
|||
output[18] = step[18];
|
||||
output[19] = step[19];
|
||||
|
||||
output[20] = ((-step[20] + step[27]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[21] = ((-step[21] + step[26]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[22] = ((-step[22] + step[25]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[23] = ((-step[23] + step[24]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[20] = dct_32_round((-step[20] + step[27]) * cospi_16_64);
|
||||
output[21] = dct_32_round((-step[21] + step[26]) * cospi_16_64);
|
||||
output[22] = dct_32_round((-step[22] + step[25]) * cospi_16_64);
|
||||
output[23] = dct_32_round((-step[23] + step[24]) * cospi_16_64);
|
||||
|
||||
output[24] = ((step[24] + step[23]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[25] = ((step[25] + step[22]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[26] = ((step[26] + step[21]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[27] = ((step[27] + step[20]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[24] = dct_32_round((step[24] + step[23]) * cospi_16_64);
|
||||
output[25] = dct_32_round((step[25] + step[22]) * cospi_16_64);
|
||||
output[26] = dct_32_round((step[26] + step[21]) * cospi_16_64);
|
||||
output[27] = dct_32_round((step[27] + step[20]) * cospi_16_64);
|
||||
|
||||
output[28] = step[28];
|
||||
output[29] = step[29];
|
||||
|
@ -1233,10 +830,10 @@ static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
|||
step[7] = -output[7] + output[(8 - 8)];
|
||||
step[8] = output[8];
|
||||
step[9] = output[9];
|
||||
step[10] = ((-output[10] + output[13]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[11] = ((-output[11] + output[12]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[12] = ((output[12] + output[11]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[13] = ((output[13] + output[10]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[10] = dct_32_round((-output[10] + output[13]) * cospi_16_64);
|
||||
step[11] = dct_32_round((-output[11] + output[12]) * cospi_16_64);
|
||||
step[12] = dct_32_round((output[12] + output[11]) * cospi_16_64);
|
||||
step[13] = dct_32_round((output[13] + output[10]) * cospi_16_64);
|
||||
step[14] = output[14];
|
||||
step[15] = output[15];
|
||||
|
||||
|
@ -1263,8 +860,8 @@ static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
|||
output[2] = -step[2] + step[1];
|
||||
output[3] = -step[3] + step[0];
|
||||
output[4] = step[4];
|
||||
output[5] = ((-step[5] + step[6]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[6] = ((step[6] + step[5]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[5] = dct_32_round((-step[5] + step[6]) * cospi_16_64);
|
||||
output[6] = dct_32_round((step[6] + step[5]) * cospi_16_64);
|
||||
output[7] = step[7];
|
||||
output[8] = step[8] + step[11];
|
||||
output[9] = step[9] + step[10];
|
||||
|
@ -1277,37 +874,37 @@ static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
|||
|
||||
output[16] = step[16];
|
||||
output[17] = step[17];
|
||||
output[18] = (step[18] * -C8 + step[29] * C24 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[19] = (step[19] * -C8 + step[28] * C24 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[20] = (step[20] * -C24 + step[27] * -C8 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[21] = (step[21] * -C24 + step[26] * -C8 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[18] = dct_32_round(step[18] * -cospi_8_64 + step[29] * cospi_24_64);
|
||||
output[19] = dct_32_round(step[19] * -cospi_8_64 + step[28] * cospi_24_64);
|
||||
output[20] = dct_32_round(step[20] * -cospi_24_64 + step[27] * -cospi_8_64);
|
||||
output[21] = dct_32_round(step[21] * -cospi_24_64 + step[26] * -cospi_8_64);
|
||||
output[22] = step[22];
|
||||
output[23] = step[23];
|
||||
output[24] = step[24];
|
||||
output[25] = step[25];
|
||||
output[26] = (step[26] * C24 + step[21] * -C8 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[27] = (step[27] * C24 + step[20] * -C8 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[28] = (step[28] * C8 + step[19] * C24 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[29] = (step[29] * C8 + step[18] * C24 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[26] = dct_32_round(step[26] * cospi_24_64 + step[21] * -cospi_8_64);
|
||||
output[27] = dct_32_round(step[27] * cospi_24_64 + step[20] * -cospi_8_64);
|
||||
output[28] = dct_32_round(step[28] * cospi_8_64 + step[19] * cospi_24_64);
|
||||
output[29] = dct_32_round(step[29] * cospi_8_64 + step[18] * cospi_24_64);
|
||||
output[30] = step[30];
|
||||
output[31] = step[31];
|
||||
|
||||
// Stage 5
|
||||
step[0] = ((output[0] + output[1]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[1] = ((-output[1] + output[0]) * C16 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[2] = (output[2] * C24 + output[3] * C8 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[3] = (output[3] * C24 - output[2] * C8 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[0] = dct_32_round((output[0] + output[1]) * cospi_16_64);
|
||||
step[1] = dct_32_round((-output[1] + output[0]) * cospi_16_64);
|
||||
step[2] = dct_32_round(output[2] * cospi_24_64 + output[3] * cospi_8_64);
|
||||
step[3] = dct_32_round(output[3] * cospi_24_64 - output[2] * cospi_8_64);
|
||||
step[4] = output[4] + output[5];
|
||||
step[5] = -output[5] + output[4];
|
||||
step[6] = -output[6] + output[7];
|
||||
step[7] = output[7] + output[6];
|
||||
step[8] = output[8];
|
||||
step[9] = (output[9] * -C8 + output[14] * C24 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[10] = (output[10] * -C24 + output[13] * -C8 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[9] = dct_32_round(output[9] * -cospi_8_64 + output[14] * cospi_24_64);
|
||||
step[10] = dct_32_round(output[10] * -cospi_24_64 + output[13] * -cospi_8_64);
|
||||
step[11] = output[11];
|
||||
step[12] = output[12];
|
||||
step[13] = (output[13] * C24 + output[10] * -C8 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[14] = (output[14] * C8 + output[9] * C24 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[13] = dct_32_round(output[13] * cospi_24_64 + output[10] * -cospi_8_64);
|
||||
step[14] = dct_32_round(output[14] * cospi_8_64 + output[9] * cospi_24_64);
|
||||
step[15] = output[15];
|
||||
|
||||
step[16] = output[16] + output[19];
|
||||
|
@ -1332,10 +929,10 @@ static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
|||
output[1] = step[1];
|
||||
output[2] = step[2];
|
||||
output[3] = step[3];
|
||||
output[4] = (step[4] * C28 + step[7] * C4 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[5] = (step[5] * C12 + step[6] * C20 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[6] = (step[6] * C12 + step[5] * -C20 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[7] = (step[7] * C28 + step[4] * -C4 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[4] = dct_32_round(step[4] * cospi_28_64 + step[7] * cospi_4_64);
|
||||
output[5] = dct_32_round(step[5] * cospi_12_64 + step[6] * cospi_20_64);
|
||||
output[6] = dct_32_round(step[6] * cospi_12_64 + step[5] * -cospi_20_64);
|
||||
output[7] = dct_32_round(step[7] * cospi_28_64 + step[4] * -cospi_4_64);
|
||||
output[8] = step[8] + step[9];
|
||||
output[9] = -step[9] + step[8];
|
||||
output[10] = -step[10] + step[11];
|
||||
|
@ -1346,20 +943,20 @@ static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
|||
output[15] = step[15] + step[14];
|
||||
|
||||
output[16] = step[16];
|
||||
output[17] = (step[17] * -C4 + step[30] * C28 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[18] = (step[18] * -C28 + step[29] * -C4 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[17] = dct_32_round(step[17] * -cospi_4_64 + step[30] * cospi_28_64);
|
||||
output[18] = dct_32_round(step[18] * -cospi_28_64 + step[29] * -cospi_4_64);
|
||||
output[19] = step[19];
|
||||
output[20] = step[20];
|
||||
output[21] = (step[21] * -C20 + step[26] * C12 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[22] = (step[22] * -C12 + step[25] * -C20 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[21] = dct_32_round(step[21] * -cospi_20_64 + step[26] * cospi_12_64);
|
||||
output[22] = dct_32_round(step[22] * -cospi_12_64 + step[25] * -cospi_20_64);
|
||||
output[23] = step[23];
|
||||
output[24] = step[24];
|
||||
output[25] = (step[25] * C12 + step[22] * -C20 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[26] = (step[26] * C20 + step[21] * C12 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[25] = dct_32_round(step[25] * cospi_12_64 + step[22] * -cospi_20_64);
|
||||
output[26] = dct_32_round(step[26] * cospi_20_64 + step[21] * cospi_12_64);
|
||||
output[27] = step[27];
|
||||
output[28] = step[28];
|
||||
output[29] = (step[29] * C28 + step[18] * -C4 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[30] = (step[30] * C4 + step[17] * C28 + ROUNDING) >> RIGHT_SHIFT;
|
||||
output[29] = dct_32_round(step[29] * cospi_28_64 + step[18] * -cospi_4_64);
|
||||
output[30] = dct_32_round(step[30] * cospi_4_64 + step[17] * cospi_28_64);
|
||||
output[31] = step[31];
|
||||
|
||||
// Stage 7
|
||||
|
@ -1371,14 +968,14 @@ static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
|||
step[5] = output[5];
|
||||
step[6] = output[6];
|
||||
step[7] = output[7];
|
||||
step[8] = (output[8] * C30 + output[15] * C2 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[9] = (output[9] * C14 + output[14] * C18 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[10] = (output[10] * C22 + output[13] * C10 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[11] = (output[11] * C6 + output[12] * C26 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[12] = (output[12] * C6 + output[11] * -C26 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[13] = (output[13] * C22 + output[10] * -C10 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[14] = (output[14] * C14 + output[9] * -C18 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[15] = (output[15] * C30 + output[8] * -C2 + ROUNDING) >> RIGHT_SHIFT;
|
||||
step[8] = dct_32_round(output[8] * cospi_30_64 + output[15] * cospi_2_64);
|
||||
step[9] = dct_32_round(output[9] * cospi_14_64 + output[14] * cospi_18_64);
|
||||
step[10] = dct_32_round(output[10] * cospi_22_64 + output[13] * cospi_10_64);
|
||||
step[11] = dct_32_round(output[11] * cospi_6_64 + output[12] * cospi_26_64);
|
||||
step[12] = dct_32_round(output[12] * cospi_6_64 + output[11] * -cospi_26_64);
|
||||
step[13] = dct_32_round(output[13] * cospi_22_64 + output[10] * -cospi_10_64);
|
||||
step[14] = dct_32_round(output[14] * cospi_14_64 + output[9] * -cospi_18_64);
|
||||
step[15] = dct_32_round(output[15] * cospi_30_64 + output[8] * -cospi_2_64);
|
||||
|
||||
step[16] = output[16] + output[17];
|
||||
step[17] = -output[17] + output[16];
|
||||
|
@ -1398,62 +995,40 @@ static void dct32_1d(int *input, int *output, int last_shift_bits) {
|
|||
step[31] = output[31] + output[30];
|
||||
|
||||
// Final stage --- outputs indices are bit-reversed.
|
||||
output[0] = (step[0] + last_rounding) >> last_shift_bits;
|
||||
output[16] = (step[1] + last_rounding) >> last_shift_bits;
|
||||
output[8] = (step[2] + last_rounding) >> last_shift_bits;
|
||||
output[24] = (step[3] + last_rounding) >> last_shift_bits;
|
||||
output[4] = (step[4] + last_rounding) >> last_shift_bits;
|
||||
output[20] = (step[5] + last_rounding) >> last_shift_bits;
|
||||
output[12] = (step[6] + last_rounding) >> last_shift_bits;
|
||||
output[28] = (step[7] + last_rounding) >> last_shift_bits;
|
||||
output[2] = (step[8] + last_rounding) >> last_shift_bits;
|
||||
output[18] = (step[9] + last_rounding) >> last_shift_bits;
|
||||
output[10] = (step[10] + last_rounding) >> last_shift_bits;
|
||||
output[26] = (step[11] + last_rounding) >> last_shift_bits;
|
||||
output[6] = (step[12] + last_rounding) >> last_shift_bits;
|
||||
output[22] = (step[13] + last_rounding) >> last_shift_bits;
|
||||
output[14] = (step[14] + last_rounding) >> last_shift_bits;
|
||||
output[30] = (step[15] + last_rounding) >> last_shift_bits;
|
||||
output[0] = step[0];
|
||||
output[16] = step[1];
|
||||
output[8] = step[2];
|
||||
output[24] = step[3];
|
||||
output[4] = step[4];
|
||||
output[20] = step[5];
|
||||
output[12] = step[6];
|
||||
output[28] = step[7];
|
||||
output[2] = step[8];
|
||||
output[18] = step[9];
|
||||
output[10] = step[10];
|
||||
output[26] = step[11];
|
||||
output[6] = step[12];
|
||||
output[22] = step[13];
|
||||
output[14] = step[14];
|
||||
output[30] = step[15];
|
||||
|
||||
output[1] = (step[16] * C31 + step[31] * C1 + final_rounding) >> final_shift;
|
||||
output[17] = (step[17] * C15 + step[30] * C17 + final_rounding)
|
||||
>> final_shift;
|
||||
output[9] = (step[18] * C23 + step[29] * C9 + final_rounding) >> final_shift;
|
||||
output[25] = (step[19] * C7 + step[28] * C25 + final_rounding) >> final_shift;
|
||||
output[5] = (step[20] * C27 + step[27] * C5 + final_rounding) >> final_shift;
|
||||
output[21] = (step[21] * C11 + step[26] * C21 + final_rounding)
|
||||
>> final_shift;
|
||||
output[13] = (step[22] * C19 + step[25] * C13 + final_rounding)
|
||||
>> final_shift;
|
||||
output[29] = (step[23] * C3 + step[24] * C29 + final_rounding) >> final_shift;
|
||||
output[3] = (step[24] * C3 + step[23] * -C29 + final_rounding) >> final_shift;
|
||||
output[19] = (step[25] * C19 + step[22] * -C13 + final_rounding)
|
||||
>> final_shift;
|
||||
output[11] = (step[26] * C11 + step[21] * -C21 + final_rounding)
|
||||
>> final_shift;
|
||||
output[27] = (step[27] * C27 + step[20] * -C5 + final_rounding)
|
||||
>> final_shift;
|
||||
output[7] = (step[28] * C7 + step[19] * -C25 + final_rounding) >> final_shift;
|
||||
output[23] = (step[29] * C23 + step[18] * -C9 + final_rounding)
|
||||
>> final_shift;
|
||||
output[15] = (step[30] * C15 + step[17] * -C17 + final_rounding)
|
||||
>> final_shift;
|
||||
output[31] = (step[31] * C31 + step[16] * -C1 + final_rounding)
|
||||
>> final_shift;
|
||||
|
||||
// Clamp to fit 16-bit.
|
||||
if (last_shift_bits > 0) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
if (output[i] < -32768)
|
||||
output[i] = -32768;
|
||||
else if (output[i] > 32767)
|
||||
output[i] = 32767;
|
||||
}
|
||||
output[1] = dct_32_round(step[16] * cospi_31_64 + step[31] * cospi_1_64);
|
||||
output[17] = dct_32_round(step[17] * cospi_15_64 + step[30] * cospi_17_64);
|
||||
output[9] = dct_32_round(step[18] * cospi_23_64 + step[29] * cospi_9_64);
|
||||
output[25] = dct_32_round(step[19] * cospi_7_64 + step[28] * cospi_25_64);
|
||||
output[5] = dct_32_round(step[20] * cospi_27_64 + step[27] * cospi_5_64);
|
||||
output[21] = dct_32_round(step[21] * cospi_11_64 + step[26] * cospi_21_64);
|
||||
output[13] = dct_32_round(step[22] * cospi_19_64 + step[25] * cospi_13_64);
|
||||
output[29] = dct_32_round(step[23] * cospi_3_64 + step[24] * cospi_29_64);
|
||||
output[3] = dct_32_round(step[24] * cospi_3_64 + step[23] * -cospi_29_64);
|
||||
output[19] = dct_32_round(step[25] * cospi_19_64 + step[22] * -cospi_13_64);
|
||||
output[11] = dct_32_round(step[26] * cospi_11_64 + step[21] * -cospi_21_64);
|
||||
output[27] = dct_32_round(step[27] * cospi_27_64 + step[20] * -cospi_5_64);
|
||||
output[7] = dct_32_round(step[28] * cospi_7_64 + step[19] * -cospi_25_64);
|
||||
output[23] = dct_32_round(step[29] * cospi_23_64 + step[18] * -cospi_9_64);
|
||||
output[15] = dct_32_round(step[30] * cospi_15_64 + step[17] * -cospi_17_64);
|
||||
output[31] = dct_32_round(step[31] * cospi_31_64 + step[16] * -cospi_1_64);
|
||||
}
|
||||
#undef RIGHT_SHIFT
|
||||
#undef ROUNDING
|
||||
|
||||
void vp9_short_fdct32x32_c(int16_t *input, int16_t *out, int pitch) {
|
||||
int shortpitch = pitch >> 1;
|
||||
|
@ -1463,10 +1038,10 @@ void vp9_short_fdct32x32_c(int16_t *input, int16_t *out, int pitch) {
|
|||
for (i = 0; i < 32; i++) {
|
||||
int temp_in[32], temp_out[32];
|
||||
for (j = 0; j < 32; j++)
|
||||
temp_in[j] = input[j * shortpitch + i];
|
||||
dct32_1d(temp_in, temp_out, 0);
|
||||
temp_in[j] = input[j * shortpitch + i] << 2;
|
||||
dct32_1d(temp_in, temp_out);
|
||||
for (j = 0; j < 32; j++)
|
||||
output[j * 32 + i] = temp_out[j];
|
||||
output[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2;
|
||||
}
|
||||
|
||||
// Then transform rows
|
||||
|
@ -1474,10 +1049,9 @@ void vp9_short_fdct32x32_c(int16_t *input, int16_t *out, int pitch) {
|
|||
int temp_in[32], temp_out[32];
|
||||
for (j = 0; j < 32; ++j)
|
||||
temp_in[j] = output[j + i * 32];
|
||||
dct32_1d(temp_in, temp_out, 2);
|
||||
dct32_1d(temp_in, temp_out);
|
||||
for (j = 0; j < 32; ++j)
|
||||
out[j + i * 32] = temp_out[j];
|
||||
out[j + i * 32] = (temp_out[j] + 1 + (temp_out[j] < 0)) >> 2;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче