1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <string.h>
12 #include "vp9_rtcd.h"
13 #include "vpx_dsp_rtcd.h"
14
15 #include "vp9_idct.h"
16 #include "fwd_txfm.h"
17
fdct4(const tran_low_t * input,tran_low_t * output)18 static void fdct4(const tran_low_t *input, tran_low_t *output) {
19 tran_high_t step[4];
20 tran_high_t temp1, temp2;
21
22 step[0] = input[0] + input[3];
23 step[1] = input[1] + input[2];
24 step[2] = input[1] - input[2];
25 step[3] = input[0] - input[3];
26
27 temp1 = (step[0] + step[1]) * cospi_16_64;
28 temp2 = (step[0] - step[1]) * cospi_16_64;
29 output[0] = (tran_low_t)fdct_round_shift(temp1);
30 output[2] = (tran_low_t)fdct_round_shift(temp2);
31 temp1 = step[2] * cospi_24_64 + step[3] * cospi_8_64;
32 temp2 = -step[2] * cospi_8_64 + step[3] * cospi_24_64;
33 output[1] = (tran_low_t)fdct_round_shift(temp1);
34 output[3] = (tran_low_t)fdct_round_shift(temp2);
35 }
36
fdct8(const tran_low_t * input,tran_low_t * output)37 static void fdct8(const tran_low_t *input, tran_low_t *output) {
38 tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16
39 tran_high_t t0, t1, t2, t3; // needs32
40 tran_high_t x0, x1, x2, x3; // canbe16
41
42 // stage 1
43 s0 = input[0] + input[7];
44 s1 = input[1] + input[6];
45 s2 = input[2] + input[5];
46 s3 = input[3] + input[4];
47 s4 = input[3] - input[4];
48 s5 = input[2] - input[5];
49 s6 = input[1] - input[6];
50 s7 = input[0] - input[7];
51
52 // fdct4(step, step);
53 x0 = s0 + s3;
54 x1 = s1 + s2;
55 x2 = s1 - s2;
56 x3 = s0 - s3;
57 t0 = (x0 + x1) * cospi_16_64;
58 t1 = (x0 - x1) * cospi_16_64;
59 t2 = x2 * cospi_24_64 + x3 * cospi_8_64;
60 t3 = -x2 * cospi_8_64 + x3 * cospi_24_64;
61 output[0] = (tran_low_t)fdct_round_shift(t0);
62 output[2] = (tran_low_t)fdct_round_shift(t2);
63 output[4] = (tran_low_t)fdct_round_shift(t1);
64 output[6] = (tran_low_t)fdct_round_shift(t3);
65
66 // Stage 2
67 t0 = (s6 - s5) * cospi_16_64;
68 t1 = (s6 + s5) * cospi_16_64;
69 t2 = (tran_low_t)fdct_round_shift(t0);
70 t3 = (tran_low_t)fdct_round_shift(t1);
71
72 // Stage 3
73 x0 = s4 + t2;
74 x1 = s4 - t2;
75 x2 = s7 - t3;
76 x3 = s7 + t3;
77
78 // Stage 4
79 t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
80 t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
81 t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
82 t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
83 output[1] = (tran_low_t)fdct_round_shift(t0);
84 output[3] = (tran_low_t)fdct_round_shift(t2);
85 output[5] = (tran_low_t)fdct_round_shift(t1);
86 output[7] = (tran_low_t)fdct_round_shift(t3);
87 }
88
fdct16(const tran_low_t in[16],tran_low_t out[16])89 static void fdct16(const tran_low_t in[16], tran_low_t out[16]) {
90 tran_high_t step1[8]; // canbe16
91 tran_high_t step2[8]; // canbe16
92 tran_high_t step3[8]; // canbe16
93 tran_high_t input[8]; // canbe16
94 tran_high_t temp1, temp2; // needs32
95
96 // step 1
97 input[0] = in[0] + in[15];
98 input[1] = in[1] + in[14];
99 input[2] = in[2] + in[13];
100 input[3] = in[3] + in[12];
101 input[4] = in[4] + in[11];
102 input[5] = in[5] + in[10];
103 input[6] = in[6] + in[9];
104 input[7] = in[7] + in[8];
105
106 step1[0] = in[7] - in[8];
107 step1[1] = in[6] - in[9];
108 step1[2] = in[5] - in[10];
109 step1[3] = in[4] - in[11];
110 step1[4] = in[3] - in[12];
111 step1[5] = in[2] - in[13];
112 step1[6] = in[1] - in[14];
113 step1[7] = in[0] - in[15];
114
115 // fdct8(step, step);
116 {
117 tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16
118 tran_high_t t0, t1, t2, t3; // needs32
119 tran_high_t x0, x1, x2, x3; // canbe16
120
121 // stage 1
122 s0 = input[0] + input[7];
123 s1 = input[1] + input[6];
124 s2 = input[2] + input[5];
125 s3 = input[3] + input[4];
126 s4 = input[3] - input[4];
127 s5 = input[2] - input[5];
128 s6 = input[1] - input[6];
129 s7 = input[0] - input[7];
130
131 // fdct4(step, step);
132 x0 = s0 + s3;
133 x1 = s1 + s2;
134 x2 = s1 - s2;
135 x3 = s0 - s3;
136 t0 = (x0 + x1) * cospi_16_64;
137 t1 = (x0 - x1) * cospi_16_64;
138 t2 = x3 * cospi_8_64 + x2 * cospi_24_64;
139 t3 = x3 * cospi_24_64 - x2 * cospi_8_64;
140 out[0] = (tran_low_t)fdct_round_shift(t0);
141 out[4] = (tran_low_t)fdct_round_shift(t2);
142 out[8] = (tran_low_t)fdct_round_shift(t1);
143 out[12] = (tran_low_t)fdct_round_shift(t3);
144
145 // Stage 2
146 t0 = (s6 - s5) * cospi_16_64;
147 t1 = (s6 + s5) * cospi_16_64;
148 t2 = fdct_round_shift(t0);
149 t3 = fdct_round_shift(t1);
150
151 // Stage 3
152 x0 = s4 + t2;
153 x1 = s4 - t2;
154 x2 = s7 - t3;
155 x3 = s7 + t3;
156
157 // Stage 4
158 t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
159 t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
160 t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
161 t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
162 out[2] = (tran_low_t)fdct_round_shift(t0);
163 out[6] = (tran_low_t)fdct_round_shift(t2);
164 out[10] = (tran_low_t)fdct_round_shift(t1);
165 out[14] = (tran_low_t)fdct_round_shift(t3);
166 }
167
168 // step 2
169 temp1 = (step1[5] - step1[2]) * cospi_16_64;
170 temp2 = (step1[4] - step1[3]) * cospi_16_64;
171 step2[2] = fdct_round_shift(temp1);
172 step2[3] = fdct_round_shift(temp2);
173 temp1 = (step1[4] + step1[3]) * cospi_16_64;
174 temp2 = (step1[5] + step1[2]) * cospi_16_64;
175 step2[4] = fdct_round_shift(temp1);
176 step2[5] = fdct_round_shift(temp2);
177
178 // step 3
179 step3[0] = step1[0] + step2[3];
180 step3[1] = step1[1] + step2[2];
181 step3[2] = step1[1] - step2[2];
182 step3[3] = step1[0] - step2[3];
183 step3[4] = step1[7] - step2[4];
184 step3[5] = step1[6] - step2[5];
185 step3[6] = step1[6] + step2[5];
186 step3[7] = step1[7] + step2[4];
187
188 // step 4
189 temp1 = step3[1] * -cospi_8_64 + step3[6] * cospi_24_64;
190 temp2 = step3[2] * cospi_24_64 + step3[5] * cospi_8_64;
191 step2[1] = fdct_round_shift(temp1);
192 step2[2] = fdct_round_shift(temp2);
193 temp1 = step3[2] * cospi_8_64 - step3[5] * cospi_24_64;
194 temp2 = step3[1] * cospi_24_64 + step3[6] * cospi_8_64;
195 step2[5] = fdct_round_shift(temp1);
196 step2[6] = fdct_round_shift(temp2);
197
198 // step 5
199 step1[0] = step3[0] + step2[1];
200 step1[1] = step3[0] - step2[1];
201 step1[2] = step3[3] + step2[2];
202 step1[3] = step3[3] - step2[2];
203 step1[4] = step3[4] - step2[5];
204 step1[5] = step3[4] + step2[5];
205 step1[6] = step3[7] - step2[6];
206 step1[7] = step3[7] + step2[6];
207
208 // step 6
209 temp1 = step1[0] * cospi_30_64 + step1[7] * cospi_2_64;
210 temp2 = step1[1] * cospi_14_64 + step1[6] * cospi_18_64;
211 out[1] = (tran_low_t)fdct_round_shift(temp1);
212 out[9] = (tran_low_t)fdct_round_shift(temp2);
213
214 temp1 = step1[2] * cospi_22_64 + step1[5] * cospi_10_64;
215 temp2 = step1[3] * cospi_6_64 + step1[4] * cospi_26_64;
216 out[5] = (tran_low_t)fdct_round_shift(temp1);
217 out[13] = (tran_low_t)fdct_round_shift(temp2);
218
219 temp1 = step1[3] * -cospi_26_64 + step1[4] * cospi_6_64;
220 temp2 = step1[2] * -cospi_10_64 + step1[5] * cospi_22_64;
221 out[3] = (tran_low_t)fdct_round_shift(temp1);
222 out[11] = (tran_low_t)fdct_round_shift(temp2);
223
224 temp1 = step1[1] * -cospi_18_64 + step1[6] * cospi_14_64;
225 temp2 = step1[0] * -cospi_2_64 + step1[7] * cospi_30_64;
226 out[7] = (tran_low_t)fdct_round_shift(temp1);
227 out[15] = (tran_low_t)fdct_round_shift(temp2);
228 }
229
fadst4(const tran_low_t * input,tran_low_t * output)230 static void fadst4(const tran_low_t *input, tran_low_t *output) {
231 tran_high_t x0, x1, x2, x3;
232 tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
233
234 x0 = input[0];
235 x1 = input[1];
236 x2 = input[2];
237 x3 = input[3];
238
239 if (!(x0 | x1 | x2 | x3)) {
240 output[0] = output[1] = output[2] = output[3] = 0;
241 return;
242 }
243
244 s0 = sinpi_1_9 * x0;
245 s1 = sinpi_4_9 * x0;
246 s2 = sinpi_2_9 * x1;
247 s3 = sinpi_1_9 * x1;
248 s4 = sinpi_3_9 * x2;
249 s5 = sinpi_4_9 * x3;
250 s6 = sinpi_2_9 * x3;
251 s7 = x0 + x1 - x3;
252
253 x0 = s0 + s2 + s5;
254 x1 = sinpi_3_9 * s7;
255 x2 = s1 - s3 + s6;
256 x3 = s4;
257
258 s0 = x0 + x3;
259 s1 = x1;
260 s2 = x2 - x3;
261 s3 = x2 - x0 + x3;
262
263 // 1-D transform scaling factor is sqrt(2).
264 output[0] = (tran_low_t)fdct_round_shift(s0);
265 output[1] = (tran_low_t)fdct_round_shift(s1);
266 output[2] = (tran_low_t)fdct_round_shift(s2);
267 output[3] = (tran_low_t)fdct_round_shift(s3);
268 }
269
fadst8(const tran_low_t * input,tran_low_t * output)270 static void fadst8(const tran_low_t *input, tran_low_t *output) {
271 tran_high_t s0, s1, s2, s3, s4, s5, s6, s7;
272
273 tran_high_t x0 = input[7];
274 tran_high_t x1 = input[0];
275 tran_high_t x2 = input[5];
276 tran_high_t x3 = input[2];
277 tran_high_t x4 = input[3];
278 tran_high_t x5 = input[4];
279 tran_high_t x6 = input[1];
280 tran_high_t x7 = input[6];
281
282 // stage 1
283 s0 = cospi_2_64 * x0 + cospi_30_64 * x1;
284 s1 = cospi_30_64 * x0 - cospi_2_64 * x1;
285 s2 = cospi_10_64 * x2 + cospi_22_64 * x3;
286 s3 = cospi_22_64 * x2 - cospi_10_64 * x3;
287 s4 = cospi_18_64 * x4 + cospi_14_64 * x5;
288 s5 = cospi_14_64 * x4 - cospi_18_64 * x5;
289 s6 = cospi_26_64 * x6 + cospi_6_64 * x7;
290 s7 = cospi_6_64 * x6 - cospi_26_64 * x7;
291
292 x0 = fdct_round_shift(s0 + s4);
293 x1 = fdct_round_shift(s1 + s5);
294 x2 = fdct_round_shift(s2 + s6);
295 x3 = fdct_round_shift(s3 + s7);
296 x4 = fdct_round_shift(s0 - s4);
297 x5 = fdct_round_shift(s1 - s5);
298 x6 = fdct_round_shift(s2 - s6);
299 x7 = fdct_round_shift(s3 - s7);
300
301 // stage 2
302 s0 = x0;
303 s1 = x1;
304 s2 = x2;
305 s3 = x3;
306 s4 = cospi_8_64 * x4 + cospi_24_64 * x5;
307 s5 = cospi_24_64 * x4 - cospi_8_64 * x5;
308 s6 = -cospi_24_64 * x6 + cospi_8_64 * x7;
309 s7 = cospi_8_64 * x6 + cospi_24_64 * x7;
310
311 x0 = s0 + s2;
312 x1 = s1 + s3;
313 x2 = s0 - s2;
314 x3 = s1 - s3;
315 x4 = fdct_round_shift(s4 + s6);
316 x5 = fdct_round_shift(s5 + s7);
317 x6 = fdct_round_shift(s4 - s6);
318 x7 = fdct_round_shift(s5 - s7);
319
320 // stage 3
321 s2 = cospi_16_64 * (x2 + x3);
322 s3 = cospi_16_64 * (x2 - x3);
323 s6 = cospi_16_64 * (x6 + x7);
324 s7 = cospi_16_64 * (x6 - x7);
325
326 x2 = fdct_round_shift(s2);
327 x3 = fdct_round_shift(s3);
328 x6 = fdct_round_shift(s6);
329 x7 = fdct_round_shift(s7);
330
331 output[0] = (tran_low_t)x0;
332 output[1] = (tran_low_t)-x4;
333 output[2] = (tran_low_t)x6;
334 output[3] = (tran_low_t)-x2;
335 output[4] = (tran_low_t)x3;
336 output[5] = (tran_low_t)-x7;
337 output[6] = (tran_low_t)x5;
338 output[7] = (tran_low_t)-x1;
339 }
340
fadst16(const tran_low_t * input,tran_low_t * output)341 static void fadst16(const tran_low_t *input, tran_low_t *output) {
342 tran_high_t s0, s1, s2, s3, s4, s5, s6, s7, s8;
343 tran_high_t s9, s10, s11, s12, s13, s14, s15;
344
345 tran_high_t x0 = input[15];
346 tran_high_t x1 = input[0];
347 tran_high_t x2 = input[13];
348 tran_high_t x3 = input[2];
349 tran_high_t x4 = input[11];
350 tran_high_t x5 = input[4];
351 tran_high_t x6 = input[9];
352 tran_high_t x7 = input[6];
353 tran_high_t x8 = input[7];
354 tran_high_t x9 = input[8];
355 tran_high_t x10 = input[5];
356 tran_high_t x11 = input[10];
357 tran_high_t x12 = input[3];
358 tran_high_t x13 = input[12];
359 tran_high_t x14 = input[1];
360 tran_high_t x15 = input[14];
361
362 // stage 1
363 s0 = x0 * cospi_1_64 + x1 * cospi_31_64;
364 s1 = x0 * cospi_31_64 - x1 * cospi_1_64;
365 s2 = x2 * cospi_5_64 + x3 * cospi_27_64;
366 s3 = x2 * cospi_27_64 - x3 * cospi_5_64;
367 s4 = x4 * cospi_9_64 + x5 * cospi_23_64;
368 s5 = x4 * cospi_23_64 - x5 * cospi_9_64;
369 s6 = x6 * cospi_13_64 + x7 * cospi_19_64;
370 s7 = x6 * cospi_19_64 - x7 * cospi_13_64;
371 s8 = x8 * cospi_17_64 + x9 * cospi_15_64;
372 s9 = x8 * cospi_15_64 - x9 * cospi_17_64;
373 s10 = x10 * cospi_21_64 + x11 * cospi_11_64;
374 s11 = x10 * cospi_11_64 - x11 * cospi_21_64;
375 s12 = x12 * cospi_25_64 + x13 * cospi_7_64;
376 s13 = x12 * cospi_7_64 - x13 * cospi_25_64;
377 s14 = x14 * cospi_29_64 + x15 * cospi_3_64;
378 s15 = x14 * cospi_3_64 - x15 * cospi_29_64;
379
380 x0 = fdct_round_shift(s0 + s8);
381 x1 = fdct_round_shift(s1 + s9);
382 x2 = fdct_round_shift(s2 + s10);
383 x3 = fdct_round_shift(s3 + s11);
384 x4 = fdct_round_shift(s4 + s12);
385 x5 = fdct_round_shift(s5 + s13);
386 x6 = fdct_round_shift(s6 + s14);
387 x7 = fdct_round_shift(s7 + s15);
388 x8 = fdct_round_shift(s0 - s8);
389 x9 = fdct_round_shift(s1 - s9);
390 x10 = fdct_round_shift(s2 - s10);
391 x11 = fdct_round_shift(s3 - s11);
392 x12 = fdct_round_shift(s4 - s12);
393 x13 = fdct_round_shift(s5 - s13);
394 x14 = fdct_round_shift(s6 - s14);
395 x15 = fdct_round_shift(s7 - s15);
396
397 // stage 2
398 s0 = x0;
399 s1 = x1;
400 s2 = x2;
401 s3 = x3;
402 s4 = x4;
403 s5 = x5;
404 s6 = x6;
405 s7 = x7;
406 s8 = x8 * cospi_4_64 + x9 * cospi_28_64;
407 s9 = x8 * cospi_28_64 - x9 * cospi_4_64;
408 s10 = x10 * cospi_20_64 + x11 * cospi_12_64;
409 s11 = x10 * cospi_12_64 - x11 * cospi_20_64;
410 s12 = -x12 * cospi_28_64 + x13 * cospi_4_64;
411 s13 = x12 * cospi_4_64 + x13 * cospi_28_64;
412 s14 = -x14 * cospi_12_64 + x15 * cospi_20_64;
413 s15 = x14 * cospi_20_64 + x15 * cospi_12_64;
414
415 x0 = s0 + s4;
416 x1 = s1 + s5;
417 x2 = s2 + s6;
418 x3 = s3 + s7;
419 x4 = s0 - s4;
420 x5 = s1 - s5;
421 x6 = s2 - s6;
422 x7 = s3 - s7;
423 x8 = fdct_round_shift(s8 + s12);
424 x9 = fdct_round_shift(s9 + s13);
425 x10 = fdct_round_shift(s10 + s14);
426 x11 = fdct_round_shift(s11 + s15);
427 x12 = fdct_round_shift(s8 - s12);
428 x13 = fdct_round_shift(s9 - s13);
429 x14 = fdct_round_shift(s10 - s14);
430 x15 = fdct_round_shift(s11 - s15);
431
432 // stage 3
433 s0 = x0;
434 s1 = x1;
435 s2 = x2;
436 s3 = x3;
437 s4 = x4 * cospi_8_64 + x5 * cospi_24_64;
438 s5 = x4 * cospi_24_64 - x5 * cospi_8_64;
439 s6 = -x6 * cospi_24_64 + x7 * cospi_8_64;
440 s7 = x6 * cospi_8_64 + x7 * cospi_24_64;
441 s8 = x8;
442 s9 = x9;
443 s10 = x10;
444 s11 = x11;
445 s12 = x12 * cospi_8_64 + x13 * cospi_24_64;
446 s13 = x12 * cospi_24_64 - x13 * cospi_8_64;
447 s14 = -x14 * cospi_24_64 + x15 * cospi_8_64;
448 s15 = x14 * cospi_8_64 + x15 * cospi_24_64;
449
450 x0 = s0 + s2;
451 x1 = s1 + s3;
452 x2 = s0 - s2;
453 x3 = s1 - s3;
454 x4 = fdct_round_shift(s4 + s6);
455 x5 = fdct_round_shift(s5 + s7);
456 x6 = fdct_round_shift(s4 - s6);
457 x7 = fdct_round_shift(s5 - s7);
458 x8 = s8 + s10;
459 x9 = s9 + s11;
460 x10 = s8 - s10;
461 x11 = s9 - s11;
462 x12 = fdct_round_shift(s12 + s14);
463 x13 = fdct_round_shift(s13 + s15);
464 x14 = fdct_round_shift(s12 - s14);
465 x15 = fdct_round_shift(s13 - s15);
466
467 // stage 4
468 s2 = (-cospi_16_64) * (x2 + x3);
469 s3 = cospi_16_64 * (x2 - x3);
470 s6 = cospi_16_64 * (x6 + x7);
471 s7 = cospi_16_64 * (-x6 + x7);
472 s10 = cospi_16_64 * (x10 + x11);
473 s11 = cospi_16_64 * (-x10 + x11);
474 s14 = (-cospi_16_64) * (x14 + x15);
475 s15 = cospi_16_64 * (x14 - x15);
476
477 x2 = fdct_round_shift(s2);
478 x3 = fdct_round_shift(s3);
479 x6 = fdct_round_shift(s6);
480 x7 = fdct_round_shift(s7);
481 x10 = fdct_round_shift(s10);
482 x11 = fdct_round_shift(s11);
483 x14 = fdct_round_shift(s14);
484 x15 = fdct_round_shift(s15);
485
486 output[0] = (tran_low_t)x0;
487 output[1] = (tran_low_t)-x8;
488 output[2] = (tran_low_t)x12;
489 output[3] = (tran_low_t)-x4;
490 output[4] = (tran_low_t)x6;
491 output[5] = (tran_low_t)x14;
492 output[6] = (tran_low_t)x10;
493 output[7] = (tran_low_t)x2;
494 output[8] = (tran_low_t)x3;
495 output[9] = (tran_low_t)x11;
496 output[10] = (tran_low_t)x15;
497 output[11] = (tran_low_t)x7;
498 output[12] = (tran_low_t)x5;
499 output[13] = (tran_low_t)-x13;
500 output[14] = (tran_low_t)x9;
501 output[15] = (tran_low_t)-x1;
502 }
503
504 static const transform_2d FHT_4[] = {
505 { fdct4, fdct4 }, // DCT_DCT = 0
506 { fadst4, fdct4 }, // ADST_DCT = 1
507 { fdct4, fadst4 }, // DCT_ADST = 2
508 { fadst4, fadst4 } // ADST_ADST = 3
509 };
510
511 static const transform_2d FHT_8[] = {
512 { fdct8, fdct8 }, // DCT_DCT = 0
513 { fadst8, fdct8 }, // ADST_DCT = 1
514 { fdct8, fadst8 }, // DCT_ADST = 2
515 { fadst8, fadst8 } // ADST_ADST = 3
516 };
517
518 static const transform_2d FHT_16[] = {
519 { fdct16, fdct16 }, // DCT_DCT = 0
520 { fadst16, fdct16 }, // ADST_DCT = 1
521 { fdct16, fadst16 }, // DCT_ADST = 2
522 { fadst16, fadst16 } // ADST_ADST = 3
523 };
524
eb_vp9_fht4x4_c(const int16_t * input,tran_low_t * output,int stride,int tx_type)525 void eb_vp9_fht4x4_c(const int16_t *input, tran_low_t *output, int stride,
526 int tx_type) {
527 if (tx_type == DCT_DCT) {
528 eb_vp9_fdct4x4_c(input, output, stride);
529 } else {
530 tran_low_t out[4 * 4];
531 int i, j;
532 tran_low_t temp_in[4], temp_out[4];
533 const transform_2d ht = FHT_4[tx_type];
534
535 // Columns
536 for (i = 0; i < 4; ++i) {
537 for (j = 0; j < 4; ++j) temp_in[j] = input[j * stride + i] * 16;
538 if (i == 0 && temp_in[0]) temp_in[0] += 1;
539 ht.cols(temp_in, temp_out);
540 for (j = 0; j < 4; ++j) out[j * 4 + i] = temp_out[j];
541 }
542
543 // Rows
544 for (i = 0; i < 4; ++i) {
545 for (j = 0; j < 4; ++j) temp_in[j] = out[j + i * 4];
546 ht.rows(temp_in, temp_out);
547 for (j = 0; j < 4; ++j) output[j + i * 4] = (temp_out[j] + 1) >> 2;
548 }
549 }
550 }
551
vp9_fdct8x8_quant_c(const int16_t * input,int stride,tran_low_t * coeff_ptr,intptr_t n_coeffs,int skip_block,const int16_t * round_ptr,const int16_t * quant_ptr,tran_low_t * qcoeff_ptr,tran_low_t * dqcoeff_ptr,const int16_t * dequant_ptr,uint16_t * eob_ptr,const int16_t * scan,const int16_t * iscan)552 void vp9_fdct8x8_quant_c(const int16_t *input, int stride,
553 tran_low_t *coeff_ptr, intptr_t n_coeffs,
554 int skip_block, const int16_t *round_ptr,
555 const int16_t *quant_ptr, tran_low_t *qcoeff_ptr,
556 tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr,
557 uint16_t *eob_ptr, const int16_t *scan,
558 const int16_t *iscan) {
559 int eob = -1;
560
561 int i, j;
562 tran_low_t intermediate[64];
563
564 (void)iscan;
565
566 // Transform columns
567 {
568 tran_low_t *output = intermediate;
569 tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16
570 tran_high_t t0, t1, t2, t3; // needs32
571 tran_high_t x0, x1, x2, x3; // canbe16
572
573 int i;
574 for (i = 0; i < 8; i++) {
575 // stage 1
576 s0 = (input[0 * stride] + input[7 * stride]) * 4;
577 s1 = (input[1 * stride] + input[6 * stride]) * 4;
578 s2 = (input[2 * stride] + input[5 * stride]) * 4;
579 s3 = (input[3 * stride] + input[4 * stride]) * 4;
580 s4 = (input[3 * stride] - input[4 * stride]) * 4;
581 s5 = (input[2 * stride] - input[5 * stride]) * 4;
582 s6 = (input[1 * stride] - input[6 * stride]) * 4;
583 s7 = (input[0 * stride] - input[7 * stride]) * 4;
584
585 // fdct4(step, step);
586 x0 = s0 + s3;
587 x1 = s1 + s2;
588 x2 = s1 - s2;
589 x3 = s0 - s3;
590 t0 = (x0 + x1) * cospi_16_64;
591 t1 = (x0 - x1) * cospi_16_64;
592 t2 = x2 * cospi_24_64 + x3 * cospi_8_64;
593 t3 = -x2 * cospi_8_64 + x3 * cospi_24_64;
594 output[0 * 8] = (tran_low_t)fdct_round_shift(t0);
595 output[2 * 8] = (tran_low_t)fdct_round_shift(t2);
596 output[4 * 8] = (tran_low_t)fdct_round_shift(t1);
597 output[6 * 8] = (tran_low_t)fdct_round_shift(t3);
598
599 // Stage 2
600 t0 = (s6 - s5) * cospi_16_64;
601 t1 = (s6 + s5) * cospi_16_64;
602 t2 = fdct_round_shift(t0);
603 t3 = fdct_round_shift(t1);
604
605 // Stage 3
606 x0 = s4 + t2;
607 x1 = s4 - t2;
608 x2 = s7 - t3;
609 x3 = s7 + t3;
610
611 // Stage 4
612 t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
613 t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
614 t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
615 t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
616 output[1 * 8] = (tran_low_t)fdct_round_shift(t0);
617 output[3 * 8] = (tran_low_t)fdct_round_shift(t2);
618 output[5 * 8] = (tran_low_t)fdct_round_shift(t1);
619 output[7 * 8] = (tran_low_t)fdct_round_shift(t3);
620 input++;
621 output++;
622 }
623 }
624
625 // Rows
626 for (i = 0; i < 8; ++i) {
627 fdct8(&intermediate[i * 8], &coeff_ptr[i * 8]);
628 for (j = 0; j < 8; ++j) coeff_ptr[j + i * 8] /= 2;
629 }
630
631 memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
632 memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
633
634 if (!skip_block) {
635 // Quantization pass: All coefficients with index >= zero_flag are
636 // skippable. Note: zero_flag can be zero.
637 for (i = 0; i < n_coeffs; i++) {
638 const int rc = scan[i];
639 const int coeff = coeff_ptr[rc];
640 const int coeff_sign = (coeff >> 31);
641 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
642
643 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
644 tmp = (tmp * quant_ptr[rc != 0]) >> 16;
645
646 qcoeff_ptr[rc] = (int16_t)((tmp ^ coeff_sign) - coeff_sign);
647 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0];
648
649 if (tmp) eob = i;
650 }
651 }
652 *eob_ptr = (int16_t)eob + 1;
653 }
654
eb_vp9_fht8x8_c(const int16_t * input,tran_low_t * output,int stride,int tx_type)655 void eb_vp9_fht8x8_c(const int16_t *input, tran_low_t *output, int stride,
656 int tx_type) {
657 if (tx_type == DCT_DCT) {
658 eb_vp9_fdct8x8_c(input, output, stride);
659 } else {
660 tran_low_t out[64];
661 int i, j;
662 tran_low_t temp_in[8], temp_out[8];
663 const transform_2d ht = FHT_8[tx_type];
664
665 // Columns
666 for (i = 0; i < 8; ++i) {
667 for (j = 0; j < 8; ++j) temp_in[j] = input[j * stride + i] * 4;
668 ht.cols(temp_in, temp_out);
669 for (j = 0; j < 8; ++j) out[j * 8 + i] = temp_out[j];
670 }
671
672 // Rows
673 for (i = 0; i < 8; ++i) {
674 for (j = 0; j < 8; ++j) temp_in[j] = out[j + i * 8];
675 ht.rows(temp_in, temp_out);
676 for (j = 0; j < 8; ++j)
677 output[j + i * 8] = (temp_out[j] + (temp_out[j] < 0)) >> 1;
678 }
679 }
680 }
681
682 /* 4-point reversible, orthonormal Walsh-Hadamard in 3.5 adds, 0.5 shifts per
683 pixel. */
eb_vp9_fwht4x4_c(const int16_t * input,tran_low_t * output,int stride)684 void eb_vp9_fwht4x4_c(const int16_t *input, tran_low_t *output, int stride) {
685 int i;
686 tran_high_t a1, b1, c1, d1, e1;
687 const int16_t *ip_pass0 = input;
688 const tran_low_t *ip = NULL;
689 tran_low_t *op = output;
690
691 for (i = 0; i < 4; i++) {
692 a1 = ip_pass0[0 * stride];
693 b1 = ip_pass0[1 * stride];
694 c1 = ip_pass0[2 * stride];
695 d1 = ip_pass0[3 * stride];
696
697 a1 += b1;
698 d1 = d1 - c1;
699 e1 = (a1 - d1) >> 1;
700 b1 = e1 - b1;
701 c1 = e1 - c1;
702 a1 -= c1;
703 d1 += b1;
704 op[0] = (tran_low_t)a1;
705 op[4] = (tran_low_t)c1;
706 op[8] = (tran_low_t)d1;
707 op[12] = (tran_low_t)b1;
708
709 ip_pass0++;
710 op++;
711 }
712 ip = output;
713 op = output;
714
715 for (i = 0; i < 4; i++) {
716 a1 = ip[0];
717 b1 = ip[1];
718 c1 = ip[2];
719 d1 = ip[3];
720
721 a1 += b1;
722 d1 -= c1;
723 e1 = (a1 - d1) >> 1;
724 b1 = e1 - b1;
725 c1 = e1 - c1;
726 a1 -= c1;
727 d1 += b1;
728 op[0] = (tran_low_t)(a1 * UNIT_QUANT_FACTOR);
729 op[1] = (tran_low_t)(c1 * UNIT_QUANT_FACTOR);
730 op[2] = (tran_low_t)(d1 * UNIT_QUANT_FACTOR);
731 op[3] = (tran_low_t)(b1 * UNIT_QUANT_FACTOR);
732
733 ip += 4;
734 op += 4;
735 }
736 }
737
eb_vp9_fht16x16_c(const int16_t * input,tran_low_t * output,int stride,int tx_type)738 void eb_vp9_fht16x16_c(const int16_t *input, tran_low_t *output, int stride,
739 int tx_type) {
740 if (tx_type == DCT_DCT) {
741 eb_vp9_fdct16x16_c(input, output, stride);
742 } else {
743 tran_low_t out[256];
744 int i, j;
745 tran_low_t temp_in[16], temp_out[16];
746 const transform_2d ht = FHT_16[tx_type];
747
748 // Columns
749 for (i = 0; i < 16; ++i) {
750 for (j = 0; j < 16; ++j) temp_in[j] = input[j * stride + i] * 4;
751 ht.cols(temp_in, temp_out);
752 for (j = 0; j < 16; ++j)
753 out[j * 16 + i] = (temp_out[j] + 1 + (temp_out[j] < 0)) >> 2;
754 }
755
756 // Rows
757 for (i = 0; i < 16; ++i) {
758 for (j = 0; j < 16; ++j) temp_in[j] = out[j + i * 16];
759 ht.rows(temp_in, temp_out);
760 for (j = 0; j < 16; ++j) output[j + i * 16] = temp_out[j];
761 }
762 }
763 }
764
765 #if CONFIG_VP9_HIGHBITDEPTH
vp9_highbd_fht4x4_c(const int16_t * input,tran_low_t * output,int stride,int tx_type)766 void vp9_highbd_fht4x4_c(const int16_t *input, tran_low_t *output, int stride,
767 int tx_type) {
768 eb_vp9_fht4x4_c(input, output, stride, tx_type);
769 }
770
vp9_highbd_fht8x8_c(const int16_t * input,tran_low_t * output,int stride,int tx_type)771 void vp9_highbd_fht8x8_c(const int16_t *input, tran_low_t *output, int stride,
772 int tx_type) {
773 eb_vp9_fht8x8_c(input, output, stride, tx_type);
774 }
775
vp9_highbd_fwht4x4_c(const int16_t * input,tran_low_t * output,int stride)776 void vp9_highbd_fwht4x4_c(const int16_t *input, tran_low_t *output,
777 int stride) {
778 eb_vp9_fwht4x4_c(input, output, stride);
779 }
780
vp9_highbd_fht16x16_c(const int16_t * input,tran_low_t * output,int stride,int tx_type)781 void vp9_highbd_fht16x16_c(const int16_t *input, tran_low_t *output, int stride,
782 int tx_type) {
783 eb_vp9_fht16x16_c(input, output, stride, tx_type);
784 }
785 #endif // CONFIG_VP9_HIGHBITDEPTH
786