Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Template for the Discrete Cosine Transform for 32 samples |
3 |
|
|
* Copyright (c) 2001, 2002 Fabrice Bellard |
4 |
|
|
* |
5 |
|
|
* This file is part of FFmpeg. |
6 |
|
|
* |
7 |
|
|
* FFmpeg is free software; you can redistribute it and/or |
8 |
|
|
* modify it under the terms of the GNU Lesser General Public |
9 |
|
|
* License as published by the Free Software Foundation; either |
10 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* FFmpeg is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
|
|
* Lesser General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU Lesser General Public |
18 |
|
|
* License along with FFmpeg; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "dct32.h" |
23 |
|
|
#include "mathops.h" |
24 |
|
|
#include "libavutil/internal.h" |
25 |
|
|
|
26 |
|
|
#ifdef CHECKED |
27 |
|
|
#define SUINT int |
28 |
|
|
#define SUINT32 int32_t |
29 |
|
|
#else |
30 |
|
|
#define SUINT unsigned |
31 |
|
|
#define SUINT32 uint32_t |
32 |
|
|
#endif |
33 |
|
|
|
34 |
|
|
#if DCT32_FLOAT |
35 |
|
|
# define dct32 ff_dct32_float |
36 |
|
|
# define FIXHR(x) ((float)(x)) |
37 |
|
|
# define MULH3(x, y, s) ((s)*(y)*(x)) |
38 |
|
|
# define INTFLOAT float |
39 |
|
|
# define SUINTFLOAT float |
40 |
|
|
#else |
41 |
|
|
# define dct32 ff_dct32_fixed |
42 |
|
|
# define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5)) |
43 |
|
|
# define MULH3(x, y, s) MULH((s)*(x), y) |
44 |
|
|
# define INTFLOAT int |
45 |
|
|
# define SUINTFLOAT SUINT |
46 |
|
|
#endif |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */ |
50 |
|
|
|
51 |
|
|
/* cos(i*pi/64) */ |
52 |
|
|
|
53 |
|
|
#define COS0_0 FIXHR(0.50060299823519630134/2) |
54 |
|
|
#define COS0_1 FIXHR(0.50547095989754365998/2) |
55 |
|
|
#define COS0_2 FIXHR(0.51544730992262454697/2) |
56 |
|
|
#define COS0_3 FIXHR(0.53104259108978417447/2) |
57 |
|
|
#define COS0_4 FIXHR(0.55310389603444452782/2) |
58 |
|
|
#define COS0_5 FIXHR(0.58293496820613387367/2) |
59 |
|
|
#define COS0_6 FIXHR(0.62250412303566481615/2) |
60 |
|
|
#define COS0_7 FIXHR(0.67480834145500574602/2) |
61 |
|
|
#define COS0_8 FIXHR(0.74453627100229844977/2) |
62 |
|
|
#define COS0_9 FIXHR(0.83934964541552703873/2) |
63 |
|
|
#define COS0_10 FIXHR(0.97256823786196069369/2) |
64 |
|
|
#define COS0_11 FIXHR(1.16943993343288495515/4) |
65 |
|
|
#define COS0_12 FIXHR(1.48416461631416627724/4) |
66 |
|
|
#define COS0_13 FIXHR(2.05778100995341155085/8) |
67 |
|
|
#define COS0_14 FIXHR(3.40760841846871878570/8) |
68 |
|
|
#define COS0_15 FIXHR(10.19000812354805681150/32) |
69 |
|
|
|
70 |
|
|
#define COS1_0 FIXHR(0.50241928618815570551/2) |
71 |
|
|
#define COS1_1 FIXHR(0.52249861493968888062/2) |
72 |
|
|
#define COS1_2 FIXHR(0.56694403481635770368/2) |
73 |
|
|
#define COS1_3 FIXHR(0.64682178335999012954/2) |
74 |
|
|
#define COS1_4 FIXHR(0.78815462345125022473/2) |
75 |
|
|
#define COS1_5 FIXHR(1.06067768599034747134/4) |
76 |
|
|
#define COS1_6 FIXHR(1.72244709823833392782/4) |
77 |
|
|
#define COS1_7 FIXHR(5.10114861868916385802/16) |
78 |
|
|
|
79 |
|
|
#define COS2_0 FIXHR(0.50979557910415916894/2) |
80 |
|
|
#define COS2_1 FIXHR(0.60134488693504528054/2) |
81 |
|
|
#define COS2_2 FIXHR(0.89997622313641570463/2) |
82 |
|
|
#define COS2_3 FIXHR(2.56291544774150617881/8) |
83 |
|
|
|
84 |
|
|
#define COS3_0 FIXHR(0.54119610014619698439/2) |
85 |
|
|
#define COS3_1 FIXHR(1.30656296487637652785/4) |
86 |
|
|
|
87 |
|
|
#define COS4_0 FIXHR(M_SQRT1_2/2) |
88 |
|
|
|
89 |
|
|
/* butterfly operator */ |
90 |
|
|
#define BF(a, b, c, s)\ |
91 |
|
|
{\ |
92 |
|
|
tmp0 = val##a + val##b;\ |
93 |
|
|
tmp1 = val##a - val##b;\ |
94 |
|
|
val##a = tmp0;\ |
95 |
|
|
val##b = MULH3(tmp1, c, 1<<(s));\ |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
#define BF0(a, b, c, s)\ |
99 |
|
|
{\ |
100 |
|
|
tmp0 = tab[a] + tab[b];\ |
101 |
|
|
tmp1 = tab[a] - tab[b];\ |
102 |
|
|
val##a = tmp0;\ |
103 |
|
|
val##b = MULH3(tmp1, c, 1<<(s));\ |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
#define BF1(a, b, c, d)\ |
107 |
|
|
{\ |
108 |
|
|
BF(a, b, COS4_0, 1);\ |
109 |
|
|
BF(c, d,-COS4_0, 1);\ |
110 |
|
|
val##c += val##d;\ |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
#define BF2(a, b, c, d)\ |
114 |
|
|
{\ |
115 |
|
|
BF(a, b, COS4_0, 1);\ |
116 |
|
|
BF(c, d,-COS4_0, 1);\ |
117 |
|
|
val##c += val##d;\ |
118 |
|
|
val##a += val##c;\ |
119 |
|
|
val##c += val##b;\ |
120 |
|
|
val##b += val##d;\ |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
#define ADD(a, b) val##a += val##b |
124 |
|
|
|
125 |
|
|
/* DCT32 without 1/sqrt(2) coef zero scaling. */ |
126 |
|
536604 |
void dct32(INTFLOAT *out, const INTFLOAT *tab_arg) |
127 |
|
|
{ |
128 |
|
536604 |
const SUINTFLOAT *tab = tab_arg; |
129 |
|
|
SUINTFLOAT tmp0, tmp1; |
130 |
|
|
|
131 |
|
|
SUINTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 , |
132 |
|
|
val8 , val9 , val10, val11, val12, val13, val14, val15, |
133 |
|
|
val16, val17, val18, val19, val20, val21, val22, val23, |
134 |
|
|
val24, val25, val26, val27, val28, val29, val30, val31; |
135 |
|
|
|
136 |
|
|
/* pass 1 */ |
137 |
|
536604 |
BF0( 0, 31, COS0_0 , 1); |
138 |
|
536604 |
BF0(15, 16, COS0_15, 5); |
139 |
|
|
/* pass 2 */ |
140 |
|
536604 |
BF( 0, 15, COS1_0 , 1); |
141 |
|
536604 |
BF(16, 31,-COS1_0 , 1); |
142 |
|
|
/* pass 1 */ |
143 |
|
536604 |
BF0( 7, 24, COS0_7 , 1); |
144 |
|
536604 |
BF0( 8, 23, COS0_8 , 1); |
145 |
|
|
/* pass 2 */ |
146 |
|
536604 |
BF( 7, 8, COS1_7 , 4); |
147 |
|
536604 |
BF(23, 24,-COS1_7 , 4); |
148 |
|
|
/* pass 3 */ |
149 |
|
536604 |
BF( 0, 7, COS2_0 , 1); |
150 |
|
536604 |
BF( 8, 15,-COS2_0 , 1); |
151 |
|
536604 |
BF(16, 23, COS2_0 , 1); |
152 |
|
536604 |
BF(24, 31,-COS2_0 , 1); |
153 |
|
|
/* pass 1 */ |
154 |
|
536604 |
BF0( 3, 28, COS0_3 , 1); |
155 |
|
536604 |
BF0(12, 19, COS0_12, 2); |
156 |
|
|
/* pass 2 */ |
157 |
|
536604 |
BF( 3, 12, COS1_3 , 1); |
158 |
|
536604 |
BF(19, 28,-COS1_3 , 1); |
159 |
|
|
/* pass 1 */ |
160 |
|
536604 |
BF0( 4, 27, COS0_4 , 1); |
161 |
|
536604 |
BF0(11, 20, COS0_11, 2); |
162 |
|
|
/* pass 2 */ |
163 |
|
536604 |
BF( 4, 11, COS1_4 , 1); |
164 |
|
536604 |
BF(20, 27,-COS1_4 , 1); |
165 |
|
|
/* pass 3 */ |
166 |
|
536604 |
BF( 3, 4, COS2_3 , 3); |
167 |
|
536604 |
BF(11, 12,-COS2_3 , 3); |
168 |
|
536604 |
BF(19, 20, COS2_3 , 3); |
169 |
|
536604 |
BF(27, 28,-COS2_3 , 3); |
170 |
|
|
/* pass 4 */ |
171 |
|
536604 |
BF( 0, 3, COS3_0 , 1); |
172 |
|
536604 |
BF( 4, 7,-COS3_0 , 1); |
173 |
|
536604 |
BF( 8, 11, COS3_0 , 1); |
174 |
|
536604 |
BF(12, 15,-COS3_0 , 1); |
175 |
|
536604 |
BF(16, 19, COS3_0 , 1); |
176 |
|
536604 |
BF(20, 23,-COS3_0 , 1); |
177 |
|
536604 |
BF(24, 27, COS3_0 , 1); |
178 |
|
536604 |
BF(28, 31,-COS3_0 , 1); |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
/* pass 1 */ |
183 |
|
536604 |
BF0( 1, 30, COS0_1 , 1); |
184 |
|
536604 |
BF0(14, 17, COS0_14, 3); |
185 |
|
|
/* pass 2 */ |
186 |
|
536604 |
BF( 1, 14, COS1_1 , 1); |
187 |
|
536604 |
BF(17, 30,-COS1_1 , 1); |
188 |
|
|
/* pass 1 */ |
189 |
|
536604 |
BF0( 6, 25, COS0_6 , 1); |
190 |
|
536604 |
BF0( 9, 22, COS0_9 , 1); |
191 |
|
|
/* pass 2 */ |
192 |
|
536604 |
BF( 6, 9, COS1_6 , 2); |
193 |
|
536604 |
BF(22, 25,-COS1_6 , 2); |
194 |
|
|
/* pass 3 */ |
195 |
|
536604 |
BF( 1, 6, COS2_1 , 1); |
196 |
|
536604 |
BF( 9, 14,-COS2_1 , 1); |
197 |
|
536604 |
BF(17, 22, COS2_1 , 1); |
198 |
|
536604 |
BF(25, 30,-COS2_1 , 1); |
199 |
|
|
|
200 |
|
|
/* pass 1 */ |
201 |
|
536604 |
BF0( 2, 29, COS0_2 , 1); |
202 |
|
536604 |
BF0(13, 18, COS0_13, 3); |
203 |
|
|
/* pass 2 */ |
204 |
|
536604 |
BF( 2, 13, COS1_2 , 1); |
205 |
|
536604 |
BF(18, 29,-COS1_2 , 1); |
206 |
|
|
/* pass 1 */ |
207 |
|
536604 |
BF0( 5, 26, COS0_5 , 1); |
208 |
|
536604 |
BF0(10, 21, COS0_10, 1); |
209 |
|
|
/* pass 2 */ |
210 |
|
536604 |
BF( 5, 10, COS1_5 , 2); |
211 |
|
536604 |
BF(21, 26,-COS1_5 , 2); |
212 |
|
|
/* pass 3 */ |
213 |
|
536604 |
BF( 2, 5, COS2_2 , 1); |
214 |
|
536604 |
BF(10, 13,-COS2_2 , 1); |
215 |
|
536604 |
BF(18, 21, COS2_2 , 1); |
216 |
|
536604 |
BF(26, 29,-COS2_2 , 1); |
217 |
|
|
/* pass 4 */ |
218 |
|
536604 |
BF( 1, 2, COS3_1 , 2); |
219 |
|
536604 |
BF( 5, 6,-COS3_1 , 2); |
220 |
|
536604 |
BF( 9, 10, COS3_1 , 2); |
221 |
|
536604 |
BF(13, 14,-COS3_1 , 2); |
222 |
|
536604 |
BF(17, 18, COS3_1 , 2); |
223 |
|
536604 |
BF(21, 22,-COS3_1 , 2); |
224 |
|
536604 |
BF(25, 26, COS3_1 , 2); |
225 |
|
536604 |
BF(29, 30,-COS3_1 , 2); |
226 |
|
|
|
227 |
|
|
/* pass 5 */ |
228 |
|
536604 |
BF1( 0, 1, 2, 3); |
229 |
|
536604 |
BF2( 4, 5, 6, 7); |
230 |
|
536604 |
BF1( 8, 9, 10, 11); |
231 |
|
536604 |
BF2(12, 13, 14, 15); |
232 |
|
536604 |
BF1(16, 17, 18, 19); |
233 |
|
536604 |
BF2(20, 21, 22, 23); |
234 |
|
536604 |
BF1(24, 25, 26, 27); |
235 |
|
536604 |
BF2(28, 29, 30, 31); |
236 |
|
|
|
237 |
|
|
/* pass 6 */ |
238 |
|
|
|
239 |
|
536604 |
ADD( 8, 12); |
240 |
|
536604 |
ADD(12, 10); |
241 |
|
536604 |
ADD(10, 14); |
242 |
|
536604 |
ADD(14, 9); |
243 |
|
536604 |
ADD( 9, 13); |
244 |
|
536604 |
ADD(13, 11); |
245 |
|
536604 |
ADD(11, 15); |
246 |
|
|
|
247 |
|
536604 |
out[ 0] = val0; |
248 |
|
536604 |
out[16] = val1; |
249 |
|
536604 |
out[ 8] = val2; |
250 |
|
536604 |
out[24] = val3; |
251 |
|
536604 |
out[ 4] = val4; |
252 |
|
536604 |
out[20] = val5; |
253 |
|
536604 |
out[12] = val6; |
254 |
|
536604 |
out[28] = val7; |
255 |
|
536604 |
out[ 2] = val8; |
256 |
|
536604 |
out[18] = val9; |
257 |
|
536604 |
out[10] = val10; |
258 |
|
536604 |
out[26] = val11; |
259 |
|
536604 |
out[ 6] = val12; |
260 |
|
536604 |
out[22] = val13; |
261 |
|
536604 |
out[14] = val14; |
262 |
|
536604 |
out[30] = val15; |
263 |
|
|
|
264 |
|
536604 |
ADD(24, 28); |
265 |
|
536604 |
ADD(28, 26); |
266 |
|
536604 |
ADD(26, 30); |
267 |
|
536604 |
ADD(30, 25); |
268 |
|
536604 |
ADD(25, 29); |
269 |
|
536604 |
ADD(29, 27); |
270 |
|
536604 |
ADD(27, 31); |
271 |
|
|
|
272 |
|
536604 |
out[ 1] = val16 + val24; |
273 |
|
536604 |
out[17] = val17 + val25; |
274 |
|
536604 |
out[ 9] = val18 + val26; |
275 |
|
536604 |
out[25] = val19 + val27; |
276 |
|
536604 |
out[ 5] = val20 + val28; |
277 |
|
536604 |
out[21] = val21 + val29; |
278 |
|
536604 |
out[13] = val22 + val30; |
279 |
|
536604 |
out[29] = val23 + val31; |
280 |
|
536604 |
out[ 3] = val24 + val20; |
281 |
|
536604 |
out[19] = val25 + val21; |
282 |
|
536604 |
out[11] = val26 + val22; |
283 |
|
536604 |
out[27] = val27 + val23; |
284 |
|
536604 |
out[ 7] = val28 + val18; |
285 |
|
536604 |
out[23] = val29 + val19; |
286 |
|
536604 |
out[15] = val30 + val17; |
287 |
|
536604 |
out[31] = val31; |
288 |
|
536604 |
} |
289 |
|
|
|