-
Notifications
You must be signed in to change notification settings - Fork 27
/
dct_double.cc
86 lines (73 loc) · 2.7 KB
/
dct_double.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dct_double.h"
#include <cmath>
namespace knusperli {
namespace {
// kDCTMatrix[8*u+x] = 0.5*alpha(u)*cos((2*x+1)*u*M_PI/16),
// where alpha(0) = 1/sqrt(2) and alpha(u) = 1 for u > 0.
static const double kDCTMatrix[64] = {
0.3535533906, 0.3535533906, 0.3535533906, 0.3535533906,
0.3535533906, 0.3535533906, 0.3535533906, 0.3535533906,
0.4903926402, 0.4157348062, 0.2777851165, 0.0975451610,
-0.0975451610, -0.2777851165, -0.4157348062, -0.4903926402,
0.4619397663, 0.1913417162, -0.1913417162, -0.4619397663,
-0.4619397663, -0.1913417162, 0.1913417162, 0.4619397663,
0.4157348062, -0.0975451610, -0.4903926402, -0.2777851165,
0.2777851165, 0.4903926402, 0.0975451610, -0.4157348062,
0.3535533906, -0.3535533906, -0.3535533906, 0.3535533906,
0.3535533906, -0.3535533906, -0.3535533906, 0.3535533906,
0.2777851165, -0.4903926402, 0.0975451610, 0.4157348062,
-0.4157348062, -0.0975451610, 0.4903926402, -0.2777851165,
0.1913417162, -0.4619397663, 0.4619397663, -0.1913417162,
-0.1913417162, 0.4619397663, -0.4619397663, 0.1913417162,
0.0975451610, -0.2777851165, 0.4157348062, -0.4903926402,
0.4903926402, -0.4157348062, 0.2777851165, -0.0975451610,
};
void DCT1d(const double* in, int stride, double* out) {
for (int x = 0; x < 8; ++x) {
out[x * stride] = 0.0;
for (int u = 0; u < 8; ++u) {
out[x * stride] += kDCTMatrix[8 * x + u] * in[u * stride];
}
}
}
void IDCT1d(const double* in, int stride, double* out) {
for (int x = 0; x < 8; ++x) {
out[x * stride] = 0.0;
for (int u = 0; u < 8; ++u) {
out[x * stride] += kDCTMatrix[8 * u + x] * in[u * stride];
}
}
}
typedef void (*Transform1d)(const double* in, int stride, double* out);
void TransformBlock(double block[64], Transform1d f) {
double tmp[64];
for (int x = 0; x < 8; ++x) {
f(&block[x], 8, &tmp[x]);
}
for (int y = 0; y < 8; ++y) {
f(&tmp[8 * y], 1, &block[8 * y]);
}
}
} // namespace
void ComputeBlockDCTDouble(double block[64]) {
TransformBlock(block, DCT1d);
}
void ComputeBlockIDCTDouble(double block[64]) {
TransformBlock(block, IDCT1d);
}
} // namespace knusperli