jpeg: further precomputations

This commit is contained in:
K. Lange 2018-12-20 18:54:13 +09:00
parent 38691a2f01
commit 245fa0a092

View File

@ -205,29 +205,26 @@ struct idct {
double base[64];
};
static double norm_coeff[2] = {
0.35355339059,
0.5,
};
/**
* norm_coeff[0] = 0.35355339059
* norm_coeff[1] = 0.5
*/
static double cosines[8][8] = {
{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0},
{0.9807852804032304, 0.8314696123025452, 0.5555702330196023, 0.19509032201612833, -0.1950903220161282, -0.555570233019602, -0.8314696123025453, -0.9807852804032304},
{0.9238795325112867, 0.38268343236508984, -0.3826834323650897, -0.9238795325112867, -0.9238795325112868, -0.38268343236509034, 0.38268343236509, 0.9238795325112865},
{0.8314696123025452, -0.1950903220161282, -0.9807852804032304, -0.5555702330196022, 0.5555702330196018, 0.9807852804032304, 0.19509032201612878, -0.8314696123025451},
{0.7071067811865476, -0.7071067811865475, -0.7071067811865477, 0.7071067811865474, 0.7071067811865477, -0.7071067811865467, -0.7071067811865471, 0.7071067811865466},
{0.5555702330196023, -0.9807852804032304, 0.1950903220161283, 0.8314696123025455, -0.8314696123025451, -0.19509032201612803, 0.9807852804032307, -0.5555702330196015},
{0.38268343236508984, -0.9238795325112868, 0.9238795325112865, -0.3826834323650899, -0.38268343236509056, 0.9238795325112867, -0.9238795325112864, 0.38268343236508956},
{0.19509032201612833, -0.5555702330196022, 0.8314696123025455, -0.9807852804032307, 0.9807852804032304, -0.831469612302545, 0.5555702330196015, -0.19509032201612858},
{ 0.35355339059,0.35355339059,0.35355339059,0.35355339059,0.35355339059,0.35355339059,0.35355339059,0.35355339059 },
{ 0.490392640202,0.415734806151,0.27778511651,0.0975451610081,-0.0975451610081,-0.27778511651,-0.415734806151,-0.490392640202 },
{ 0.461939766256,0.191341716183,-0.191341716183,-0.461939766256,-0.461939766256,-0.191341716183,0.191341716183,0.461939766256 },
{ 0.415734806151,-0.0975451610081,-0.490392640202,-0.27778511651,0.27778511651,0.490392640202,0.0975451610081,-0.415734806151 },
{ 0.353553390593,-0.353553390593,-0.353553390593,0.353553390593,0.353553390593,-0.353553390593,-0.353553390593,0.353553390593 },
{ 0.27778511651,-0.490392640202,0.0975451610081,0.415734806151,-0.415734806151,-0.0975451610081,0.490392640202,-0.27778511651 },
{ 0.191341716183,-0.461939766256,0.461939766256,-0.191341716183,-0.191341716183,0.461939766256,-0.461939766256,0.191341716183 },
{ 0.0975451610081,-0.27778511651,0.415734806151,-0.490392640202,0.490392640202,-0.415734806151,0.27778511651,-0.0975451610081 },
};
static void add_idc(struct idct * self, int n, int m, int coeff) {
double an = norm_coeff[!!n];
double am = norm_coeff[!!m];
for (int y = 0; y < 8; ++y) {
for (int x = 0; x < 8; ++x) {
double nn = an * cosines[n][x]; // cos((double)n * M_PI * ((double)x + 0.5) / 8.0);
double mm = am * cosines[m][y]; // cos((double)m * M_PI * ((double)y + 0.5) / 8.0);
double nn = cosines[n][x]; // norm_coeff[!!n] * cos((double)n * M_PI * ((double)x + 0.5) / 8.0);
double mm = cosines[m][y]; // norm_coeff[!!m] * cos((double)m * M_PI * ((double)y + 0.5) / 8.0);
self->base[xy_to_lin(x, y)] += nn * mm * coeff;
}
}