-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDCT.cpp
More file actions
171 lines (148 loc) · 3.37 KB
/
Copy pathDCT.cpp
File metadata and controls
171 lines (148 loc) · 3.37 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <math.h>
#include "DCT.h"
#define PI 3.14159265358979323846
// calculo normal
void DCTn_1D(double *s)
{
// COMPLETAR
double S[8];
for (int u = 0; u < 8; u++) {
double Cu = (u == 0) ? sqrt(1.0 / 8.0) : sqrt(2.0 / 8.0);
S[u] = 0.0;
for (int x = 0; x < 8; x++) {
S[u] += s[x] * cos((PI / 8.0) * (x + 0.5) * u);
}
S[u] *= Cu;
}
for (int i = 0; i < 8; i++) {
s[i] = S[i];
}
}
void IDCTn_1D(double *s)
{
// COMPLETAR
double S[8];
for (int x = 0; x < 8; x++) {
S[x] = 0.0;
for (int u = 0; u < 8; u++) {
double Cu = (u == 0) ? sqrt(1.0 / 8.0) : sqrt(2.0 / 8.0);
S[x] += Cu * s[u] * cos((PI / 8.0) * (x + 0.5) * u);
}
}
for (int i = 0; i < 8; i++) {
s[i] = S[i];
}
}
// vetterli y ligtenberg
void DCTvl_1D(double *s)
{
// COMPLETAR
}
void IDCTvl_1D(double *s)
{
double f0,f1,f2,f3,f4,f5,f6,f7;
double g0,g1,g2,g3,g4,g5,g6,g7;
double h0,h1,h2,h3,h4,h5,h6,h7;
double i0,i1,i2,i3,i4,i5,i6,i7;
double C4=cos(4*PI/16.0);
double C6=cos(6*PI/16.0);
double Cm1=cos(-PI/16.0);
double Cm3=cos((-3*PI)/16.0);
double S6=sin(6*PI/16.0);
double Sm1=sin(-PI/16.0);
double Sm3=sin((-3*PI)/16.0);
f0=s[0];f1=s[4];f2=s[2];f3=s[6];
f4=s[1];f5=s[7];f6=s[3];f7=s[5];
g0=(f0*C4);
g1=(f1*C4);
g2=(C6*(f2+f3)-(S6+C6)*f3);
g3=((S6-C6)*f2+C6*(f2+f3));
g5=(Cm1*(f4+f5)-((Sm1+Cm1)*f5));
g4=-((Sm1-Cm1)*f4+(Cm1*(f4+f5)));
g7=(Cm3*(f7+f6)-(Sm3+Cm3)*f7);
g6=(Sm3-Cm3)*f6+Cm3*(f7+f6);
h0=g0+g1;
h1=g0-g1;
h2=g2;
h3=g3;
h4=g6+g4;
h5=(g5-g7)*C4;
h6=(g4-g6)*C4;
h7=g7+g5;
i0=h0+h3;
i1=h5+h1;
i2=h2+h6;
i3=h0-h3;
i4=h4;
i5=h1-h5;
i6=h6-h2;
i7=h7;
s[0]=(i7+i0)/2;
s[1]=(i1+i2)/2;
s[2]=(i1-i2)/2;
s[3]=(i3+i4)/2;
s[4]=(i3-i4)/2;
s[5]=(i5+i6)/2;
s[6]=(i5-i6)/2;
s[7]=(i0-i7)/2;
}
void DCT_2Dn(double **block)
{
int x,y;
double aux[8];
// primero por filas
for (x=0; x<8; x++)
DCTn_1D(block[x]);
// después por columnas
for (x=0; x<8; x++)
{
for (y=0; y<8; y++) aux[y]=block[y][x]; // leemos las columnas
DCTn_1D(aux);
for (y=0; y<8; y++) block[y][x]=aux[y]; // escribimos las columnas
}
}
void IDCT_2Dn(double **block)
{
int x,y;
double aux[8];
// primero por filas
for (x=0; x<8; x++)
IDCTn_1D(block[x]);
// después por columnas
for (x=0; x<8; x++)
{
for (y=0; y<8; y++) aux[y]=block[y][x]; // leemos las columnas
IDCTn_1D(aux);
for (y=0; y<8; y++) block[y][x]=aux[y]; // escribimos las columnas
}
}
void DCT_2Dvl(double **block)
{
int x,y;
double aux[8];
// primero por filas
for (x=0; x<8; x++)
DCTvl_1D(block[x]);
// después por columnas
for (x=0; x<8; x++)
{
for (y=0; y<8; y++) aux[y]=block[y][x]; // leemos las columnas
DCTvl_1D(aux);
for (y=0; y<8; y++) block[y][x]=aux[y]; // escribimos las columnas
}
}
void IDCT_2Dvl(double **block)
{
int x,y;
double aux[8];
// primero por filas
for (x=0; x<8; x++)
IDCTvl_1D(block[x]);
// después por columnas
for (x=0; x<8; x++)
{
for (y=0; y<8; y++) aux[y]=block[y][x]; // leemos las columnas
IDCTvl_1D(aux);
for (y=0; y<8; y++) block[y][x]=aux[y]; // escribimos las columnas
}
}