jpeg: use a precalculated cosine table, which is about twice as fast

This commit is contained in:
K. Lange 2018-12-18 19:33:21 +09:00
parent 299724e83e
commit fab3091cc1

View File

@ -210,13 +210,24 @@ static double norm_coeff[2] = {
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},
};
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 * cos((double)n * M_PI * ((double)x + 0.5) / 8.0);
double mm = am * cos((double)m * M_PI * ((double)y + 0.5) / 8.0);
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);
self->base[xy_to_lin(x, y)] += nn * mm * coeff;
}
}