-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDCT.cpp
More file actions
64 lines (59 loc) · 2.64 KB
/
DCT.cpp
File metadata and controls
64 lines (59 loc) · 2.64 KB
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
#include <cmath>
#include <iostream>
#define PI 3.14159265
//TODO: comment this
using namespace std;
/*
Previously computed matrixes for computing DCT fo 8*8 matrixes.
Matix C and transpose C. DCT8(A) can be computed as C*A*CT.
*/
float C[]{0.353553, 0.353553, 0.353553, 0.353553, 0.353553, 0.353553, 0.353553, 0.353553,
0.490393, 0.415735, 0.277785, 0.0975452, -0.0975452, -0.277785, -0.415735, -0.490393,
0.46194, 0.191342, -0.191342, -0.46194, -0.46194, -0.191342, 0.191342, 0.46194,
0.415735, -0.0975452, -0.490393, -0.277785, 0.277785, 0.490393, 0.0975452, -0.415735,
0.353553, -0.353553, -0.353553, 0.353553, 0.353553, -0.353553, -0.353553, 0.353553,
0.277785, -0.490393, 0.0975452, 0.415735, -0.415735, -0.0975452, 0.490393, -0.277785,
0.191342, -0.46194, 0.46194, -0.191342, -0.191342, 0.46194, -0.46194, 0.191342,
0.0975452, -0.277785, 0.415735, -0.490393, 0.490393, -0.415735, 0.277785, -0.0975451};
float CT[]{0.353553, 0.490393, 0.46194, 0.415735, 0.353553, 0.277785, 0.191342, 0.0975452,
0.353553, 0.415735, 0.191342, -0.0975452, -0.353553, -0.490393, -0.46194, -0.277785,
0.353553, 0.277785, -0.191342, -0.490393, -0.353553, 0.0975452, 0.46194, 0.415735,
0.353553, 0.0975452, -0.46194, -0.277785, 0.353553, 0.415735, -0.191342, -0.490393,
0.353553, -0.0975452, -0.46194, 0.277785, 0.353553, -0.415735, -0.191342, 0.490393,
0.353553, -0.277785, -0.191342, 0.490393, -0.353553, -0.0975452, 0.46194, -0.415735,
0.353553, -0.415735, 0.191342, 0.0975452, -0.353553, 0.490393, -0.46194, 0.277785,
0.353553, -0.490393, 0.46194, -0.415735, 0.353553, -0.277785, 0.191342, -0.0975451};
/***
Computing discrete cosine transform(DCT). Computes matrix 8*8.
input:
matrix — pointer to matrix. Matrix presenting as one dimensional array
output:
result of DCT. Matrix, represented as array
*/
float* DCT(float* matrix){
float *res = new float[64];
float *buf = new float[64];
float sum;
//Multiplicating C * matrix
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
sum = 0;
for(int k = 0; k < 8; k++){
sum+= C[i * 8 + k] * matrix[k * 8 + j];
}
buf[i * 8 + j] = sum;
}
}
//Multiplicating (C * matrix) * CT
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
sum = 0;
for(int k = 0; k < 8; k++){
sum+= buf[i * 8 + k] * CT[k * 8 + j];
}
res[i * 8 + j] = sum;
}
}
delete[] buf;
return res;
}