media/libvpx/vp9/encoder/vp9_dct.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11 #include <assert.h>
michael@0 12 #include <math.h>
michael@0 13
michael@0 14 #include "./vpx_config.h"
michael@0 15 #include "./vp9_rtcd.h"
michael@0 16
michael@0 17 #include "vp9/common/vp9_blockd.h"
michael@0 18 #include "vp9/common/vp9_idct.h"
michael@0 19 #include "vp9/common/vp9_systemdependent.h"
michael@0 20
michael@0 21 #include "vp9/encoder/vp9_dct.h"
michael@0 22
michael@0 23 static INLINE int fdct_round_shift(int input) {
michael@0 24 int rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
michael@0 25 assert(INT16_MIN <= rv && rv <= INT16_MAX);
michael@0 26 return rv;
michael@0 27 }
michael@0 28
michael@0 29 static void fdct4(const int16_t *input, int16_t *output) {
michael@0 30 int16_t step[4];
michael@0 31 int temp1, temp2;
michael@0 32
michael@0 33 step[0] = input[0] + input[3];
michael@0 34 step[1] = input[1] + input[2];
michael@0 35 step[2] = input[1] - input[2];
michael@0 36 step[3] = input[0] - input[3];
michael@0 37
michael@0 38 temp1 = (step[0] + step[1]) * cospi_16_64;
michael@0 39 temp2 = (step[0] - step[1]) * cospi_16_64;
michael@0 40 output[0] = fdct_round_shift(temp1);
michael@0 41 output[2] = fdct_round_shift(temp2);
michael@0 42 temp1 = step[2] * cospi_24_64 + step[3] * cospi_8_64;
michael@0 43 temp2 = -step[2] * cospi_8_64 + step[3] * cospi_24_64;
michael@0 44 output[1] = fdct_round_shift(temp1);
michael@0 45 output[3] = fdct_round_shift(temp2);
michael@0 46 }
michael@0 47
michael@0 48 void vp9_fdct4x4_c(const int16_t *input, int16_t *output, int stride) {
michael@0 49 // The 2D transform is done with two passes which are actually pretty
michael@0 50 // similar. In the first one, we transform the columns and transpose
michael@0 51 // the results. In the second one, we transform the rows. To achieve that,
michael@0 52 // as the first pass results are transposed, we tranpose the columns (that
michael@0 53 // is the transposed rows) and transpose the results (so that it goes back
michael@0 54 // in normal/row positions).
michael@0 55 int pass;
michael@0 56 // We need an intermediate buffer between passes.
michael@0 57 int16_t intermediate[4 * 4];
michael@0 58 const int16_t *in = input;
michael@0 59 int16_t *out = intermediate;
michael@0 60 // Do the two transform/transpose passes
michael@0 61 for (pass = 0; pass < 2; ++pass) {
michael@0 62 /*canbe16*/ int input[4];
michael@0 63 /*canbe16*/ int step[4];
michael@0 64 /*needs32*/ int temp1, temp2;
michael@0 65 int i;
michael@0 66 for (i = 0; i < 4; ++i) {
michael@0 67 // Load inputs.
michael@0 68 if (0 == pass) {
michael@0 69 input[0] = in[0 * stride] * 16;
michael@0 70 input[1] = in[1 * stride] * 16;
michael@0 71 input[2] = in[2 * stride] * 16;
michael@0 72 input[3] = in[3 * stride] * 16;
michael@0 73 if (i == 0 && input[0]) {
michael@0 74 input[0] += 1;
michael@0 75 }
michael@0 76 } else {
michael@0 77 input[0] = in[0 * 4];
michael@0 78 input[1] = in[1 * 4];
michael@0 79 input[2] = in[2 * 4];
michael@0 80 input[3] = in[3 * 4];
michael@0 81 }
michael@0 82 // Transform.
michael@0 83 step[0] = input[0] + input[3];
michael@0 84 step[1] = input[1] + input[2];
michael@0 85 step[2] = input[1] - input[2];
michael@0 86 step[3] = input[0] - input[3];
michael@0 87 temp1 = (step[0] + step[1]) * cospi_16_64;
michael@0 88 temp2 = (step[0] - step[1]) * cospi_16_64;
michael@0 89 out[0] = fdct_round_shift(temp1);
michael@0 90 out[2] = fdct_round_shift(temp2);
michael@0 91 temp1 = step[2] * cospi_24_64 + step[3] * cospi_8_64;
michael@0 92 temp2 = -step[2] * cospi_8_64 + step[3] * cospi_24_64;
michael@0 93 out[1] = fdct_round_shift(temp1);
michael@0 94 out[3] = fdct_round_shift(temp2);
michael@0 95 // Do next column (which is a transposed row in second/horizontal pass)
michael@0 96 in++;
michael@0 97 out += 4;
michael@0 98 }
michael@0 99 // Setup in/out for next pass.
michael@0 100 in = intermediate;
michael@0 101 out = output;
michael@0 102 }
michael@0 103
michael@0 104 {
michael@0 105 int i, j;
michael@0 106 for (i = 0; i < 4; ++i) {
michael@0 107 for (j = 0; j < 4; ++j)
michael@0 108 output[j + i * 4] = (output[j + i * 4] + 1) >> 2;
michael@0 109 }
michael@0 110 }
michael@0 111 }
michael@0 112
michael@0 113 static void fadst4(const int16_t *input, int16_t *output) {
michael@0 114 int x0, x1, x2, x3;
michael@0 115 int s0, s1, s2, s3, s4, s5, s6, s7;
michael@0 116
michael@0 117 x0 = input[0];
michael@0 118 x1 = input[1];
michael@0 119 x2 = input[2];
michael@0 120 x3 = input[3];
michael@0 121
michael@0 122 if (!(x0 | x1 | x2 | x3)) {
michael@0 123 output[0] = output[1] = output[2] = output[3] = 0;
michael@0 124 return;
michael@0 125 }
michael@0 126
michael@0 127 s0 = sinpi_1_9 * x0;
michael@0 128 s1 = sinpi_4_9 * x0;
michael@0 129 s2 = sinpi_2_9 * x1;
michael@0 130 s3 = sinpi_1_9 * x1;
michael@0 131 s4 = sinpi_3_9 * x2;
michael@0 132 s5 = sinpi_4_9 * x3;
michael@0 133 s6 = sinpi_2_9 * x3;
michael@0 134 s7 = x0 + x1 - x3;
michael@0 135
michael@0 136 x0 = s0 + s2 + s5;
michael@0 137 x1 = sinpi_3_9 * s7;
michael@0 138 x2 = s1 - s3 + s6;
michael@0 139 x3 = s4;
michael@0 140
michael@0 141 s0 = x0 + x3;
michael@0 142 s1 = x1;
michael@0 143 s2 = x2 - x3;
michael@0 144 s3 = x2 - x0 + x3;
michael@0 145
michael@0 146 // 1-D transform scaling factor is sqrt(2).
michael@0 147 output[0] = fdct_round_shift(s0);
michael@0 148 output[1] = fdct_round_shift(s1);
michael@0 149 output[2] = fdct_round_shift(s2);
michael@0 150 output[3] = fdct_round_shift(s3);
michael@0 151 }
michael@0 152
michael@0 153 static const transform_2d FHT_4[] = {
michael@0 154 { fdct4, fdct4 }, // DCT_DCT = 0
michael@0 155 { fadst4, fdct4 }, // ADST_DCT = 1
michael@0 156 { fdct4, fadst4 }, // DCT_ADST = 2
michael@0 157 { fadst4, fadst4 } // ADST_ADST = 3
michael@0 158 };
michael@0 159
michael@0 160 void vp9_short_fht4x4_c(const int16_t *input, int16_t *output,
michael@0 161 int stride, int tx_type) {
michael@0 162 int16_t out[4 * 4];
michael@0 163 int16_t *outptr = &out[0];
michael@0 164 int i, j;
michael@0 165 int16_t temp_in[4], temp_out[4];
michael@0 166 const transform_2d ht = FHT_4[tx_type];
michael@0 167
michael@0 168 // Columns
michael@0 169 for (i = 0; i < 4; ++i) {
michael@0 170 for (j = 0; j < 4; ++j)
michael@0 171 temp_in[j] = input[j * stride + i] * 16;
michael@0 172 if (i == 0 && temp_in[0])
michael@0 173 temp_in[0] += 1;
michael@0 174 ht.cols(temp_in, temp_out);
michael@0 175 for (j = 0; j < 4; ++j)
michael@0 176 outptr[j * 4 + i] = temp_out[j];
michael@0 177 }
michael@0 178
michael@0 179 // Rows
michael@0 180 for (i = 0; i < 4; ++i) {
michael@0 181 for (j = 0; j < 4; ++j)
michael@0 182 temp_in[j] = out[j + i * 4];
michael@0 183 ht.rows(temp_in, temp_out);
michael@0 184 for (j = 0; j < 4; ++j)
michael@0 185 output[j + i * 4] = (temp_out[j] + 1) >> 2;
michael@0 186 }
michael@0 187 }
michael@0 188
michael@0 189 static void fdct8(const int16_t *input, int16_t *output) {
michael@0 190 /*canbe16*/ int s0, s1, s2, s3, s4, s5, s6, s7;
michael@0 191 /*needs32*/ int t0, t1, t2, t3;
michael@0 192 /*canbe16*/ int x0, x1, x2, x3;
michael@0 193
michael@0 194 // stage 1
michael@0 195 s0 = input[0] + input[7];
michael@0 196 s1 = input[1] + input[6];
michael@0 197 s2 = input[2] + input[5];
michael@0 198 s3 = input[3] + input[4];
michael@0 199 s4 = input[3] - input[4];
michael@0 200 s5 = input[2] - input[5];
michael@0 201 s6 = input[1] - input[6];
michael@0 202 s7 = input[0] - input[7];
michael@0 203
michael@0 204 // fdct4(step, step);
michael@0 205 x0 = s0 + s3;
michael@0 206 x1 = s1 + s2;
michael@0 207 x2 = s1 - s2;
michael@0 208 x3 = s0 - s3;
michael@0 209 t0 = (x0 + x1) * cospi_16_64;
michael@0 210 t1 = (x0 - x1) * cospi_16_64;
michael@0 211 t2 = x2 * cospi_24_64 + x3 * cospi_8_64;
michael@0 212 t3 = -x2 * cospi_8_64 + x3 * cospi_24_64;
michael@0 213 output[0] = fdct_round_shift(t0);
michael@0 214 output[2] = fdct_round_shift(t2);
michael@0 215 output[4] = fdct_round_shift(t1);
michael@0 216 output[6] = fdct_round_shift(t3);
michael@0 217
michael@0 218 // Stage 2
michael@0 219 t0 = (s6 - s5) * cospi_16_64;
michael@0 220 t1 = (s6 + s5) * cospi_16_64;
michael@0 221 t2 = fdct_round_shift(t0);
michael@0 222 t3 = fdct_round_shift(t1);
michael@0 223
michael@0 224 // Stage 3
michael@0 225 x0 = s4 + t2;
michael@0 226 x1 = s4 - t2;
michael@0 227 x2 = s7 - t3;
michael@0 228 x3 = s7 + t3;
michael@0 229
michael@0 230 // Stage 4
michael@0 231 t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
michael@0 232 t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
michael@0 233 t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
michael@0 234 t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
michael@0 235 output[1] = fdct_round_shift(t0);
michael@0 236 output[3] = fdct_round_shift(t2);
michael@0 237 output[5] = fdct_round_shift(t1);
michael@0 238 output[7] = fdct_round_shift(t3);
michael@0 239 }
michael@0 240
michael@0 241 void vp9_fdct8x8_c(const int16_t *input, int16_t *final_output, int stride) {
michael@0 242 int i, j;
michael@0 243 int16_t intermediate[64];
michael@0 244
michael@0 245 // Transform columns
michael@0 246 {
michael@0 247 int16_t *output = intermediate;
michael@0 248 /*canbe16*/ int s0, s1, s2, s3, s4, s5, s6, s7;
michael@0 249 /*needs32*/ int t0, t1, t2, t3;
michael@0 250 /*canbe16*/ int x0, x1, x2, x3;
michael@0 251
michael@0 252 int i;
michael@0 253 for (i = 0; i < 8; i++) {
michael@0 254 // stage 1
michael@0 255 s0 = (input[0 * stride] + input[7 * stride]) * 4;
michael@0 256 s1 = (input[1 * stride] + input[6 * stride]) * 4;
michael@0 257 s2 = (input[2 * stride] + input[5 * stride]) * 4;
michael@0 258 s3 = (input[3 * stride] + input[4 * stride]) * 4;
michael@0 259 s4 = (input[3 * stride] - input[4 * stride]) * 4;
michael@0 260 s5 = (input[2 * stride] - input[5 * stride]) * 4;
michael@0 261 s6 = (input[1 * stride] - input[6 * stride]) * 4;
michael@0 262 s7 = (input[0 * stride] - input[7 * stride]) * 4;
michael@0 263
michael@0 264 // fdct4(step, step);
michael@0 265 x0 = s0 + s3;
michael@0 266 x1 = s1 + s2;
michael@0 267 x2 = s1 - s2;
michael@0 268 x3 = s0 - s3;
michael@0 269 t0 = (x0 + x1) * cospi_16_64;
michael@0 270 t1 = (x0 - x1) * cospi_16_64;
michael@0 271 t2 = x2 * cospi_24_64 + x3 * cospi_8_64;
michael@0 272 t3 = -x2 * cospi_8_64 + x3 * cospi_24_64;
michael@0 273 output[0 * 8] = fdct_round_shift(t0);
michael@0 274 output[2 * 8] = fdct_round_shift(t2);
michael@0 275 output[4 * 8] = fdct_round_shift(t1);
michael@0 276 output[6 * 8] = fdct_round_shift(t3);
michael@0 277
michael@0 278 // Stage 2
michael@0 279 t0 = (s6 - s5) * cospi_16_64;
michael@0 280 t1 = (s6 + s5) * cospi_16_64;
michael@0 281 t2 = fdct_round_shift(t0);
michael@0 282 t3 = fdct_round_shift(t1);
michael@0 283
michael@0 284 // Stage 3
michael@0 285 x0 = s4 + t2;
michael@0 286 x1 = s4 - t2;
michael@0 287 x2 = s7 - t3;
michael@0 288 x3 = s7 + t3;
michael@0 289
michael@0 290 // Stage 4
michael@0 291 t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
michael@0 292 t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
michael@0 293 t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
michael@0 294 t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
michael@0 295 output[1 * 8] = fdct_round_shift(t0);
michael@0 296 output[3 * 8] = fdct_round_shift(t2);
michael@0 297 output[5 * 8] = fdct_round_shift(t1);
michael@0 298 output[7 * 8] = fdct_round_shift(t3);
michael@0 299 input++;
michael@0 300 output++;
michael@0 301 }
michael@0 302 }
michael@0 303
michael@0 304 // Rows
michael@0 305 for (i = 0; i < 8; ++i) {
michael@0 306 fdct8(&intermediate[i * 8], &final_output[i * 8]);
michael@0 307 for (j = 0; j < 8; ++j)
michael@0 308 final_output[j + i * 8] /= 2;
michael@0 309 }
michael@0 310 }
michael@0 311
michael@0 312 void vp9_fdct16x16_c(const int16_t *input, int16_t *output, int stride) {
michael@0 313 // The 2D transform is done with two passes which are actually pretty
michael@0 314 // similar. In the first one, we transform the columns and transpose
michael@0 315 // the results. In the second one, we transform the rows. To achieve that,
michael@0 316 // as the first pass results are transposed, we tranpose the columns (that
michael@0 317 // is the transposed rows) and transpose the results (so that it goes back
michael@0 318 // in normal/row positions).
michael@0 319 int pass;
michael@0 320 // We need an intermediate buffer between passes.
michael@0 321 int16_t intermediate[256];
michael@0 322 const int16_t *in = input;
michael@0 323 int16_t *out = intermediate;
michael@0 324 // Do the two transform/transpose passes
michael@0 325 for (pass = 0; pass < 2; ++pass) {
michael@0 326 /*canbe16*/ int step1[8];
michael@0 327 /*canbe16*/ int step2[8];
michael@0 328 /*canbe16*/ int step3[8];
michael@0 329 /*canbe16*/ int input[8];
michael@0 330 /*needs32*/ int temp1, temp2;
michael@0 331 int i;
michael@0 332 for (i = 0; i < 16; i++) {
michael@0 333 if (0 == pass) {
michael@0 334 // Calculate input for the first 8 results.
michael@0 335 input[0] = (in[0 * stride] + in[15 * stride]) * 4;
michael@0 336 input[1] = (in[1 * stride] + in[14 * stride]) * 4;
michael@0 337 input[2] = (in[2 * stride] + in[13 * stride]) * 4;
michael@0 338 input[3] = (in[3 * stride] + in[12 * stride]) * 4;
michael@0 339 input[4] = (in[4 * stride] + in[11 * stride]) * 4;
michael@0 340 input[5] = (in[5 * stride] + in[10 * stride]) * 4;
michael@0 341 input[6] = (in[6 * stride] + in[ 9 * stride]) * 4;
michael@0 342 input[7] = (in[7 * stride] + in[ 8 * stride]) * 4;
michael@0 343 // Calculate input for the next 8 results.
michael@0 344 step1[0] = (in[7 * stride] - in[ 8 * stride]) * 4;
michael@0 345 step1[1] = (in[6 * stride] - in[ 9 * stride]) * 4;
michael@0 346 step1[2] = (in[5 * stride] - in[10 * stride]) * 4;
michael@0 347 step1[3] = (in[4 * stride] - in[11 * stride]) * 4;
michael@0 348 step1[4] = (in[3 * stride] - in[12 * stride]) * 4;
michael@0 349 step1[5] = (in[2 * stride] - in[13 * stride]) * 4;
michael@0 350 step1[6] = (in[1 * stride] - in[14 * stride]) * 4;
michael@0 351 step1[7] = (in[0 * stride] - in[15 * stride]) * 4;
michael@0 352 } else {
michael@0 353 // Calculate input for the first 8 results.
michael@0 354 input[0] = ((in[0 * 16] + 1) >> 2) + ((in[15 * 16] + 1) >> 2);
michael@0 355 input[1] = ((in[1 * 16] + 1) >> 2) + ((in[14 * 16] + 1) >> 2);
michael@0 356 input[2] = ((in[2 * 16] + 1) >> 2) + ((in[13 * 16] + 1) >> 2);
michael@0 357 input[3] = ((in[3 * 16] + 1) >> 2) + ((in[12 * 16] + 1) >> 2);
michael@0 358 input[4] = ((in[4 * 16] + 1) >> 2) + ((in[11 * 16] + 1) >> 2);
michael@0 359 input[5] = ((in[5 * 16] + 1) >> 2) + ((in[10 * 16] + 1) >> 2);
michael@0 360 input[6] = ((in[6 * 16] + 1) >> 2) + ((in[ 9 * 16] + 1) >> 2);
michael@0 361 input[7] = ((in[7 * 16] + 1) >> 2) + ((in[ 8 * 16] + 1) >> 2);
michael@0 362 // Calculate input for the next 8 results.
michael@0 363 step1[0] = ((in[7 * 16] + 1) >> 2) - ((in[ 8 * 16] + 1) >> 2);
michael@0 364 step1[1] = ((in[6 * 16] + 1) >> 2) - ((in[ 9 * 16] + 1) >> 2);
michael@0 365 step1[2] = ((in[5 * 16] + 1) >> 2) - ((in[10 * 16] + 1) >> 2);
michael@0 366 step1[3] = ((in[4 * 16] + 1) >> 2) - ((in[11 * 16] + 1) >> 2);
michael@0 367 step1[4] = ((in[3 * 16] + 1) >> 2) - ((in[12 * 16] + 1) >> 2);
michael@0 368 step1[5] = ((in[2 * 16] + 1) >> 2) - ((in[13 * 16] + 1) >> 2);
michael@0 369 step1[6] = ((in[1 * 16] + 1) >> 2) - ((in[14 * 16] + 1) >> 2);
michael@0 370 step1[7] = ((in[0 * 16] + 1) >> 2) - ((in[15 * 16] + 1) >> 2);
michael@0 371 }
michael@0 372 // Work on the first eight values; fdct8(input, even_results);
michael@0 373 {
michael@0 374 /*canbe16*/ int s0, s1, s2, s3, s4, s5, s6, s7;
michael@0 375 /*needs32*/ int t0, t1, t2, t3;
michael@0 376 /*canbe16*/ int x0, x1, x2, x3;
michael@0 377
michael@0 378 // stage 1
michael@0 379 s0 = input[0] + input[7];
michael@0 380 s1 = input[1] + input[6];
michael@0 381 s2 = input[2] + input[5];
michael@0 382 s3 = input[3] + input[4];
michael@0 383 s4 = input[3] - input[4];
michael@0 384 s5 = input[2] - input[5];
michael@0 385 s6 = input[1] - input[6];
michael@0 386 s7 = input[0] - input[7];
michael@0 387
michael@0 388 // fdct4(step, step);
michael@0 389 x0 = s0 + s3;
michael@0 390 x1 = s1 + s2;
michael@0 391 x2 = s1 - s2;
michael@0 392 x3 = s0 - s3;
michael@0 393 t0 = (x0 + x1) * cospi_16_64;
michael@0 394 t1 = (x0 - x1) * cospi_16_64;
michael@0 395 t2 = x3 * cospi_8_64 + x2 * cospi_24_64;
michael@0 396 t3 = x3 * cospi_24_64 - x2 * cospi_8_64;
michael@0 397 out[0] = fdct_round_shift(t0);
michael@0 398 out[4] = fdct_round_shift(t2);
michael@0 399 out[8] = fdct_round_shift(t1);
michael@0 400 out[12] = fdct_round_shift(t3);
michael@0 401
michael@0 402 // Stage 2
michael@0 403 t0 = (s6 - s5) * cospi_16_64;
michael@0 404 t1 = (s6 + s5) * cospi_16_64;
michael@0 405 t2 = fdct_round_shift(t0);
michael@0 406 t3 = fdct_round_shift(t1);
michael@0 407
michael@0 408 // Stage 3
michael@0 409 x0 = s4 + t2;
michael@0 410 x1 = s4 - t2;
michael@0 411 x2 = s7 - t3;
michael@0 412 x3 = s7 + t3;
michael@0 413
michael@0 414 // Stage 4
michael@0 415 t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
michael@0 416 t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
michael@0 417 t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
michael@0 418 t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
michael@0 419 out[2] = fdct_round_shift(t0);
michael@0 420 out[6] = fdct_round_shift(t2);
michael@0 421 out[10] = fdct_round_shift(t1);
michael@0 422 out[14] = fdct_round_shift(t3);
michael@0 423 }
michael@0 424 // Work on the next eight values; step1 -> odd_results
michael@0 425 {
michael@0 426 // step 2
michael@0 427 temp1 = (step1[5] - step1[2]) * cospi_16_64;
michael@0 428 temp2 = (step1[4] - step1[3]) * cospi_16_64;
michael@0 429 step2[2] = fdct_round_shift(temp1);
michael@0 430 step2[3] = fdct_round_shift(temp2);
michael@0 431 temp1 = (step1[4] + step1[3]) * cospi_16_64;
michael@0 432 temp2 = (step1[5] + step1[2]) * cospi_16_64;
michael@0 433 step2[4] = fdct_round_shift(temp1);
michael@0 434 step2[5] = fdct_round_shift(temp2);
michael@0 435 // step 3
michael@0 436 step3[0] = step1[0] + step2[3];
michael@0 437 step3[1] = step1[1] + step2[2];
michael@0 438 step3[2] = step1[1] - step2[2];
michael@0 439 step3[3] = step1[0] - step2[3];
michael@0 440 step3[4] = step1[7] - step2[4];
michael@0 441 step3[5] = step1[6] - step2[5];
michael@0 442 step3[6] = step1[6] + step2[5];
michael@0 443 step3[7] = step1[7] + step2[4];
michael@0 444 // step 4
michael@0 445 temp1 = step3[1] * -cospi_8_64 + step3[6] * cospi_24_64;
michael@0 446 temp2 = step3[2] * -cospi_24_64 - step3[5] * cospi_8_64;
michael@0 447 step2[1] = fdct_round_shift(temp1);
michael@0 448 step2[2] = fdct_round_shift(temp2);
michael@0 449 temp1 = step3[2] * -cospi_8_64 + step3[5] * cospi_24_64;
michael@0 450 temp2 = step3[1] * cospi_24_64 + step3[6] * cospi_8_64;
michael@0 451 step2[5] = fdct_round_shift(temp1);
michael@0 452 step2[6] = fdct_round_shift(temp2);
michael@0 453 // step 5
michael@0 454 step1[0] = step3[0] + step2[1];
michael@0 455 step1[1] = step3[0] - step2[1];
michael@0 456 step1[2] = step3[3] - step2[2];
michael@0 457 step1[3] = step3[3] + step2[2];
michael@0 458 step1[4] = step3[4] + step2[5];
michael@0 459 step1[5] = step3[4] - step2[5];
michael@0 460 step1[6] = step3[7] - step2[6];
michael@0 461 step1[7] = step3[7] + step2[6];
michael@0 462 // step 6
michael@0 463 temp1 = step1[0] * cospi_30_64 + step1[7] * cospi_2_64;
michael@0 464 temp2 = step1[1] * cospi_14_64 + step1[6] * cospi_18_64;
michael@0 465 out[1] = fdct_round_shift(temp1);
michael@0 466 out[9] = fdct_round_shift(temp2);
michael@0 467 temp1 = step1[2] * cospi_22_64 + step1[5] * cospi_10_64;
michael@0 468 temp2 = step1[3] * cospi_6_64 + step1[4] * cospi_26_64;
michael@0 469 out[5] = fdct_round_shift(temp1);
michael@0 470 out[13] = fdct_round_shift(temp2);
michael@0 471 temp1 = step1[3] * -cospi_26_64 + step1[4] * cospi_6_64;
michael@0 472 temp2 = step1[2] * -cospi_10_64 + step1[5] * cospi_22_64;
michael@0 473 out[3] = fdct_round_shift(temp1);
michael@0 474 out[11] = fdct_round_shift(temp2);
michael@0 475 temp1 = step1[1] * -cospi_18_64 + step1[6] * cospi_14_64;
michael@0 476 temp2 = step1[0] * -cospi_2_64 + step1[7] * cospi_30_64;
michael@0 477 out[7] = fdct_round_shift(temp1);
michael@0 478 out[15] = fdct_round_shift(temp2);
michael@0 479 }
michael@0 480 // Do next column (which is a transposed row in second/horizontal pass)
michael@0 481 in++;
michael@0 482 out += 16;
michael@0 483 }
michael@0 484 // Setup in/out for next pass.
michael@0 485 in = intermediate;
michael@0 486 out = output;
michael@0 487 }
michael@0 488 }
michael@0 489
michael@0 490 static void fadst8(const int16_t *input, int16_t *output) {
michael@0 491 int s0, s1, s2, s3, s4, s5, s6, s7;
michael@0 492
michael@0 493 int x0 = input[7];
michael@0 494 int x1 = input[0];
michael@0 495 int x2 = input[5];
michael@0 496 int x3 = input[2];
michael@0 497 int x4 = input[3];
michael@0 498 int x5 = input[4];
michael@0 499 int x6 = input[1];
michael@0 500 int x7 = input[6];
michael@0 501
michael@0 502 // stage 1
michael@0 503 s0 = cospi_2_64 * x0 + cospi_30_64 * x1;
michael@0 504 s1 = cospi_30_64 * x0 - cospi_2_64 * x1;
michael@0 505 s2 = cospi_10_64 * x2 + cospi_22_64 * x3;
michael@0 506 s3 = cospi_22_64 * x2 - cospi_10_64 * x3;
michael@0 507 s4 = cospi_18_64 * x4 + cospi_14_64 * x5;
michael@0 508 s5 = cospi_14_64 * x4 - cospi_18_64 * x5;
michael@0 509 s6 = cospi_26_64 * x6 + cospi_6_64 * x7;
michael@0 510 s7 = cospi_6_64 * x6 - cospi_26_64 * x7;
michael@0 511
michael@0 512 x0 = fdct_round_shift(s0 + s4);
michael@0 513 x1 = fdct_round_shift(s1 + s5);
michael@0 514 x2 = fdct_round_shift(s2 + s6);
michael@0 515 x3 = fdct_round_shift(s3 + s7);
michael@0 516 x4 = fdct_round_shift(s0 - s4);
michael@0 517 x5 = fdct_round_shift(s1 - s5);
michael@0 518 x6 = fdct_round_shift(s2 - s6);
michael@0 519 x7 = fdct_round_shift(s3 - s7);
michael@0 520
michael@0 521 // stage 2
michael@0 522 s0 = x0;
michael@0 523 s1 = x1;
michael@0 524 s2 = x2;
michael@0 525 s3 = x3;
michael@0 526 s4 = cospi_8_64 * x4 + cospi_24_64 * x5;
michael@0 527 s5 = cospi_24_64 * x4 - cospi_8_64 * x5;
michael@0 528 s6 = - cospi_24_64 * x6 + cospi_8_64 * x7;
michael@0 529 s7 = cospi_8_64 * x6 + cospi_24_64 * x7;
michael@0 530
michael@0 531 x0 = s0 + s2;
michael@0 532 x1 = s1 + s3;
michael@0 533 x2 = s0 - s2;
michael@0 534 x3 = s1 - s3;
michael@0 535 x4 = fdct_round_shift(s4 + s6);
michael@0 536 x5 = fdct_round_shift(s5 + s7);
michael@0 537 x6 = fdct_round_shift(s4 - s6);
michael@0 538 x7 = fdct_round_shift(s5 - s7);
michael@0 539
michael@0 540 // stage 3
michael@0 541 s2 = cospi_16_64 * (x2 + x3);
michael@0 542 s3 = cospi_16_64 * (x2 - x3);
michael@0 543 s6 = cospi_16_64 * (x6 + x7);
michael@0 544 s7 = cospi_16_64 * (x6 - x7);
michael@0 545
michael@0 546 x2 = fdct_round_shift(s2);
michael@0 547 x3 = fdct_round_shift(s3);
michael@0 548 x6 = fdct_round_shift(s6);
michael@0 549 x7 = fdct_round_shift(s7);
michael@0 550
michael@0 551 output[0] = x0;
michael@0 552 output[1] = - x4;
michael@0 553 output[2] = x6;
michael@0 554 output[3] = - x2;
michael@0 555 output[4] = x3;
michael@0 556 output[5] = - x7;
michael@0 557 output[6] = x5;
michael@0 558 output[7] = - x1;
michael@0 559 }
michael@0 560
michael@0 561 static const transform_2d FHT_8[] = {
michael@0 562 { fdct8, fdct8 }, // DCT_DCT = 0
michael@0 563 { fadst8, fdct8 }, // ADST_DCT = 1
michael@0 564 { fdct8, fadst8 }, // DCT_ADST = 2
michael@0 565 { fadst8, fadst8 } // ADST_ADST = 3
michael@0 566 };
michael@0 567
michael@0 568 void vp9_short_fht8x8_c(const int16_t *input, int16_t *output,
michael@0 569 int stride, int tx_type) {
michael@0 570 int16_t out[64];
michael@0 571 int16_t *outptr = &out[0];
michael@0 572 int i, j;
michael@0 573 int16_t temp_in[8], temp_out[8];
michael@0 574 const transform_2d ht = FHT_8[tx_type];
michael@0 575
michael@0 576 // Columns
michael@0 577 for (i = 0; i < 8; ++i) {
michael@0 578 for (j = 0; j < 8; ++j)
michael@0 579 temp_in[j] = input[j * stride + i] * 4;
michael@0 580 ht.cols(temp_in, temp_out);
michael@0 581 for (j = 0; j < 8; ++j)
michael@0 582 outptr[j * 8 + i] = temp_out[j];
michael@0 583 }
michael@0 584
michael@0 585 // Rows
michael@0 586 for (i = 0; i < 8; ++i) {
michael@0 587 for (j = 0; j < 8; ++j)
michael@0 588 temp_in[j] = out[j + i * 8];
michael@0 589 ht.rows(temp_in, temp_out);
michael@0 590 for (j = 0; j < 8; ++j)
michael@0 591 output[j + i * 8] = (temp_out[j] + (temp_out[j] < 0)) >> 1;
michael@0 592 }
michael@0 593 }
michael@0 594
michael@0 595 /* 4-point reversible, orthonormal Walsh-Hadamard in 3.5 adds, 0.5 shifts per
michael@0 596 pixel. */
michael@0 597 void vp9_fwht4x4_c(const int16_t *input, int16_t *output, int stride) {
michael@0 598 int i;
michael@0 599 int a1, b1, c1, d1, e1;
michael@0 600 const int16_t *ip = input;
michael@0 601 int16_t *op = output;
michael@0 602
michael@0 603 for (i = 0; i < 4; i++) {
michael@0 604 a1 = ip[0 * stride];
michael@0 605 b1 = ip[1 * stride];
michael@0 606 c1 = ip[2 * stride];
michael@0 607 d1 = ip[3 * stride];
michael@0 608
michael@0 609 a1 += b1;
michael@0 610 d1 = d1 - c1;
michael@0 611 e1 = (a1 - d1) >> 1;
michael@0 612 b1 = e1 - b1;
michael@0 613 c1 = e1 - c1;
michael@0 614 a1 -= c1;
michael@0 615 d1 += b1;
michael@0 616 op[0] = a1;
michael@0 617 op[4] = c1;
michael@0 618 op[8] = d1;
michael@0 619 op[12] = b1;
michael@0 620
michael@0 621 ip++;
michael@0 622 op++;
michael@0 623 }
michael@0 624 ip = output;
michael@0 625 op = output;
michael@0 626
michael@0 627 for (i = 0; i < 4; i++) {
michael@0 628 a1 = ip[0];
michael@0 629 b1 = ip[1];
michael@0 630 c1 = ip[2];
michael@0 631 d1 = ip[3];
michael@0 632
michael@0 633 a1 += b1;
michael@0 634 d1 -= c1;
michael@0 635 e1 = (a1 - d1) >> 1;
michael@0 636 b1 = e1 - b1;
michael@0 637 c1 = e1 - c1;
michael@0 638 a1 -= c1;
michael@0 639 d1 += b1;
michael@0 640 op[0] = a1 * UNIT_QUANT_FACTOR;
michael@0 641 op[1] = c1 * UNIT_QUANT_FACTOR;
michael@0 642 op[2] = d1 * UNIT_QUANT_FACTOR;
michael@0 643 op[3] = b1 * UNIT_QUANT_FACTOR;
michael@0 644
michael@0 645 ip += 4;
michael@0 646 op += 4;
michael@0 647 }
michael@0 648 }
michael@0 649
michael@0 650 // Rewrote to use same algorithm as others.
michael@0 651 static void fdct16(const int16_t in[16], int16_t out[16]) {
michael@0 652 /*canbe16*/ int step1[8];
michael@0 653 /*canbe16*/ int step2[8];
michael@0 654 /*canbe16*/ int step3[8];
michael@0 655 /*canbe16*/ int input[8];
michael@0 656 /*needs32*/ int temp1, temp2;
michael@0 657
michael@0 658 // step 1
michael@0 659 input[0] = in[0] + in[15];
michael@0 660 input[1] = in[1] + in[14];
michael@0 661 input[2] = in[2] + in[13];
michael@0 662 input[3] = in[3] + in[12];
michael@0 663 input[4] = in[4] + in[11];
michael@0 664 input[5] = in[5] + in[10];
michael@0 665 input[6] = in[6] + in[ 9];
michael@0 666 input[7] = in[7] + in[ 8];
michael@0 667
michael@0 668 step1[0] = in[7] - in[ 8];
michael@0 669 step1[1] = in[6] - in[ 9];
michael@0 670 step1[2] = in[5] - in[10];
michael@0 671 step1[3] = in[4] - in[11];
michael@0 672 step1[4] = in[3] - in[12];
michael@0 673 step1[5] = in[2] - in[13];
michael@0 674 step1[6] = in[1] - in[14];
michael@0 675 step1[7] = in[0] - in[15];
michael@0 676
michael@0 677 // fdct8(step, step);
michael@0 678 {
michael@0 679 /*canbe16*/ int s0, s1, s2, s3, s4, s5, s6, s7;
michael@0 680 /*needs32*/ int t0, t1, t2, t3;
michael@0 681 /*canbe16*/ int x0, x1, x2, x3;
michael@0 682
michael@0 683 // stage 1
michael@0 684 s0 = input[0] + input[7];
michael@0 685 s1 = input[1] + input[6];
michael@0 686 s2 = input[2] + input[5];
michael@0 687 s3 = input[3] + input[4];
michael@0 688 s4 = input[3] - input[4];
michael@0 689 s5 = input[2] - input[5];
michael@0 690 s6 = input[1] - input[6];
michael@0 691 s7 = input[0] - input[7];
michael@0 692
michael@0 693 // fdct4(step, step);
michael@0 694 x0 = s0 + s3;
michael@0 695 x1 = s1 + s2;
michael@0 696 x2 = s1 - s2;
michael@0 697 x3 = s0 - s3;
michael@0 698 t0 = (x0 + x1) * cospi_16_64;
michael@0 699 t1 = (x0 - x1) * cospi_16_64;
michael@0 700 t2 = x3 * cospi_8_64 + x2 * cospi_24_64;
michael@0 701 t3 = x3 * cospi_24_64 - x2 * cospi_8_64;
michael@0 702 out[0] = fdct_round_shift(t0);
michael@0 703 out[4] = fdct_round_shift(t2);
michael@0 704 out[8] = fdct_round_shift(t1);
michael@0 705 out[12] = fdct_round_shift(t3);
michael@0 706
michael@0 707 // Stage 2
michael@0 708 t0 = (s6 - s5) * cospi_16_64;
michael@0 709 t1 = (s6 + s5) * cospi_16_64;
michael@0 710 t2 = fdct_round_shift(t0);
michael@0 711 t3 = fdct_round_shift(t1);
michael@0 712
michael@0 713 // Stage 3
michael@0 714 x0 = s4 + t2;
michael@0 715 x1 = s4 - t2;
michael@0 716 x2 = s7 - t3;
michael@0 717 x3 = s7 + t3;
michael@0 718
michael@0 719 // Stage 4
michael@0 720 t0 = x0 * cospi_28_64 + x3 * cospi_4_64;
michael@0 721 t1 = x1 * cospi_12_64 + x2 * cospi_20_64;
michael@0 722 t2 = x2 * cospi_12_64 + x1 * -cospi_20_64;
michael@0 723 t3 = x3 * cospi_28_64 + x0 * -cospi_4_64;
michael@0 724 out[2] = fdct_round_shift(t0);
michael@0 725 out[6] = fdct_round_shift(t2);
michael@0 726 out[10] = fdct_round_shift(t1);
michael@0 727 out[14] = fdct_round_shift(t3);
michael@0 728 }
michael@0 729
michael@0 730 // step 2
michael@0 731 temp1 = (step1[5] - step1[2]) * cospi_16_64;
michael@0 732 temp2 = (step1[4] - step1[3]) * cospi_16_64;
michael@0 733 step2[2] = fdct_round_shift(temp1);
michael@0 734 step2[3] = fdct_round_shift(temp2);
michael@0 735 temp1 = (step1[4] + step1[3]) * cospi_16_64;
michael@0 736 temp2 = (step1[5] + step1[2]) * cospi_16_64;
michael@0 737 step2[4] = fdct_round_shift(temp1);
michael@0 738 step2[5] = fdct_round_shift(temp2);
michael@0 739
michael@0 740 // step 3
michael@0 741 step3[0] = step1[0] + step2[3];
michael@0 742 step3[1] = step1[1] + step2[2];
michael@0 743 step3[2] = step1[1] - step2[2];
michael@0 744 step3[3] = step1[0] - step2[3];
michael@0 745 step3[4] = step1[7] - step2[4];
michael@0 746 step3[5] = step1[6] - step2[5];
michael@0 747 step3[6] = step1[6] + step2[5];
michael@0 748 step3[7] = step1[7] + step2[4];
michael@0 749
michael@0 750 // step 4
michael@0 751 temp1 = step3[1] * -cospi_8_64 + step3[6] * cospi_24_64;
michael@0 752 temp2 = step3[2] * -cospi_24_64 - step3[5] * cospi_8_64;
michael@0 753 step2[1] = fdct_round_shift(temp1);
michael@0 754 step2[2] = fdct_round_shift(temp2);
michael@0 755 temp1 = step3[2] * -cospi_8_64 + step3[5] * cospi_24_64;
michael@0 756 temp2 = step3[1] * cospi_24_64 + step3[6] * cospi_8_64;
michael@0 757 step2[5] = fdct_round_shift(temp1);
michael@0 758 step2[6] = fdct_round_shift(temp2);
michael@0 759
michael@0 760 // step 5
michael@0 761 step1[0] = step3[0] + step2[1];
michael@0 762 step1[1] = step3[0] - step2[1];
michael@0 763 step1[2] = step3[3] - step2[2];
michael@0 764 step1[3] = step3[3] + step2[2];
michael@0 765 step1[4] = step3[4] + step2[5];
michael@0 766 step1[5] = step3[4] - step2[5];
michael@0 767 step1[6] = step3[7] - step2[6];
michael@0 768 step1[7] = step3[7] + step2[6];
michael@0 769
michael@0 770 // step 6
michael@0 771 temp1 = step1[0] * cospi_30_64 + step1[7] * cospi_2_64;
michael@0 772 temp2 = step1[1] * cospi_14_64 + step1[6] * cospi_18_64;
michael@0 773 out[1] = fdct_round_shift(temp1);
michael@0 774 out[9] = fdct_round_shift(temp2);
michael@0 775
michael@0 776 temp1 = step1[2] * cospi_22_64 + step1[5] * cospi_10_64;
michael@0 777 temp2 = step1[3] * cospi_6_64 + step1[4] * cospi_26_64;
michael@0 778 out[5] = fdct_round_shift(temp1);
michael@0 779 out[13] = fdct_round_shift(temp2);
michael@0 780
michael@0 781 temp1 = step1[3] * -cospi_26_64 + step1[4] * cospi_6_64;
michael@0 782 temp2 = step1[2] * -cospi_10_64 + step1[5] * cospi_22_64;
michael@0 783 out[3] = fdct_round_shift(temp1);
michael@0 784 out[11] = fdct_round_shift(temp2);
michael@0 785
michael@0 786 temp1 = step1[1] * -cospi_18_64 + step1[6] * cospi_14_64;
michael@0 787 temp2 = step1[0] * -cospi_2_64 + step1[7] * cospi_30_64;
michael@0 788 out[7] = fdct_round_shift(temp1);
michael@0 789 out[15] = fdct_round_shift(temp2);
michael@0 790 }
michael@0 791
michael@0 792 static void fadst16(const int16_t *input, int16_t *output) {
michael@0 793 int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15;
michael@0 794
michael@0 795 int x0 = input[15];
michael@0 796 int x1 = input[0];
michael@0 797 int x2 = input[13];
michael@0 798 int x3 = input[2];
michael@0 799 int x4 = input[11];
michael@0 800 int x5 = input[4];
michael@0 801 int x6 = input[9];
michael@0 802 int x7 = input[6];
michael@0 803 int x8 = input[7];
michael@0 804 int x9 = input[8];
michael@0 805 int x10 = input[5];
michael@0 806 int x11 = input[10];
michael@0 807 int x12 = input[3];
michael@0 808 int x13 = input[12];
michael@0 809 int x14 = input[1];
michael@0 810 int x15 = input[14];
michael@0 811
michael@0 812 // stage 1
michael@0 813 s0 = x0 * cospi_1_64 + x1 * cospi_31_64;
michael@0 814 s1 = x0 * cospi_31_64 - x1 * cospi_1_64;
michael@0 815 s2 = x2 * cospi_5_64 + x3 * cospi_27_64;
michael@0 816 s3 = x2 * cospi_27_64 - x3 * cospi_5_64;
michael@0 817 s4 = x4 * cospi_9_64 + x5 * cospi_23_64;
michael@0 818 s5 = x4 * cospi_23_64 - x5 * cospi_9_64;
michael@0 819 s6 = x6 * cospi_13_64 + x7 * cospi_19_64;
michael@0 820 s7 = x6 * cospi_19_64 - x7 * cospi_13_64;
michael@0 821 s8 = x8 * cospi_17_64 + x9 * cospi_15_64;
michael@0 822 s9 = x8 * cospi_15_64 - x9 * cospi_17_64;
michael@0 823 s10 = x10 * cospi_21_64 + x11 * cospi_11_64;
michael@0 824 s11 = x10 * cospi_11_64 - x11 * cospi_21_64;
michael@0 825 s12 = x12 * cospi_25_64 + x13 * cospi_7_64;
michael@0 826 s13 = x12 * cospi_7_64 - x13 * cospi_25_64;
michael@0 827 s14 = x14 * cospi_29_64 + x15 * cospi_3_64;
michael@0 828 s15 = x14 * cospi_3_64 - x15 * cospi_29_64;
michael@0 829
michael@0 830 x0 = fdct_round_shift(s0 + s8);
michael@0 831 x1 = fdct_round_shift(s1 + s9);
michael@0 832 x2 = fdct_round_shift(s2 + s10);
michael@0 833 x3 = fdct_round_shift(s3 + s11);
michael@0 834 x4 = fdct_round_shift(s4 + s12);
michael@0 835 x5 = fdct_round_shift(s5 + s13);
michael@0 836 x6 = fdct_round_shift(s6 + s14);
michael@0 837 x7 = fdct_round_shift(s7 + s15);
michael@0 838 x8 = fdct_round_shift(s0 - s8);
michael@0 839 x9 = fdct_round_shift(s1 - s9);
michael@0 840 x10 = fdct_round_shift(s2 - s10);
michael@0 841 x11 = fdct_round_shift(s3 - s11);
michael@0 842 x12 = fdct_round_shift(s4 - s12);
michael@0 843 x13 = fdct_round_shift(s5 - s13);
michael@0 844 x14 = fdct_round_shift(s6 - s14);
michael@0 845 x15 = fdct_round_shift(s7 - s15);
michael@0 846
michael@0 847 // stage 2
michael@0 848 s0 = x0;
michael@0 849 s1 = x1;
michael@0 850 s2 = x2;
michael@0 851 s3 = x3;
michael@0 852 s4 = x4;
michael@0 853 s5 = x5;
michael@0 854 s6 = x6;
michael@0 855 s7 = x7;
michael@0 856 s8 = x8 * cospi_4_64 + x9 * cospi_28_64;
michael@0 857 s9 = x8 * cospi_28_64 - x9 * cospi_4_64;
michael@0 858 s10 = x10 * cospi_20_64 + x11 * cospi_12_64;
michael@0 859 s11 = x10 * cospi_12_64 - x11 * cospi_20_64;
michael@0 860 s12 = - x12 * cospi_28_64 + x13 * cospi_4_64;
michael@0 861 s13 = x12 * cospi_4_64 + x13 * cospi_28_64;
michael@0 862 s14 = - x14 * cospi_12_64 + x15 * cospi_20_64;
michael@0 863 s15 = x14 * cospi_20_64 + x15 * cospi_12_64;
michael@0 864
michael@0 865 x0 = s0 + s4;
michael@0 866 x1 = s1 + s5;
michael@0 867 x2 = s2 + s6;
michael@0 868 x3 = s3 + s7;
michael@0 869 x4 = s0 - s4;
michael@0 870 x5 = s1 - s5;
michael@0 871 x6 = s2 - s6;
michael@0 872 x7 = s3 - s7;
michael@0 873 x8 = fdct_round_shift(s8 + s12);
michael@0 874 x9 = fdct_round_shift(s9 + s13);
michael@0 875 x10 = fdct_round_shift(s10 + s14);
michael@0 876 x11 = fdct_round_shift(s11 + s15);
michael@0 877 x12 = fdct_round_shift(s8 - s12);
michael@0 878 x13 = fdct_round_shift(s9 - s13);
michael@0 879 x14 = fdct_round_shift(s10 - s14);
michael@0 880 x15 = fdct_round_shift(s11 - s15);
michael@0 881
michael@0 882 // stage 3
michael@0 883 s0 = x0;
michael@0 884 s1 = x1;
michael@0 885 s2 = x2;
michael@0 886 s3 = x3;
michael@0 887 s4 = x4 * cospi_8_64 + x5 * cospi_24_64;
michael@0 888 s5 = x4 * cospi_24_64 - x5 * cospi_8_64;
michael@0 889 s6 = - x6 * cospi_24_64 + x7 * cospi_8_64;
michael@0 890 s7 = x6 * cospi_8_64 + x7 * cospi_24_64;
michael@0 891 s8 = x8;
michael@0 892 s9 = x9;
michael@0 893 s10 = x10;
michael@0 894 s11 = x11;
michael@0 895 s12 = x12 * cospi_8_64 + x13 * cospi_24_64;
michael@0 896 s13 = x12 * cospi_24_64 - x13 * cospi_8_64;
michael@0 897 s14 = - x14 * cospi_24_64 + x15 * cospi_8_64;
michael@0 898 s15 = x14 * cospi_8_64 + x15 * cospi_24_64;
michael@0 899
michael@0 900 x0 = s0 + s2;
michael@0 901 x1 = s1 + s3;
michael@0 902 x2 = s0 - s2;
michael@0 903 x3 = s1 - s3;
michael@0 904 x4 = fdct_round_shift(s4 + s6);
michael@0 905 x5 = fdct_round_shift(s5 + s7);
michael@0 906 x6 = fdct_round_shift(s4 - s6);
michael@0 907 x7 = fdct_round_shift(s5 - s7);
michael@0 908 x8 = s8 + s10;
michael@0 909 x9 = s9 + s11;
michael@0 910 x10 = s8 - s10;
michael@0 911 x11 = s9 - s11;
michael@0 912 x12 = fdct_round_shift(s12 + s14);
michael@0 913 x13 = fdct_round_shift(s13 + s15);
michael@0 914 x14 = fdct_round_shift(s12 - s14);
michael@0 915 x15 = fdct_round_shift(s13 - s15);
michael@0 916
michael@0 917 // stage 4
michael@0 918 s2 = (- cospi_16_64) * (x2 + x3);
michael@0 919 s3 = cospi_16_64 * (x2 - x3);
michael@0 920 s6 = cospi_16_64 * (x6 + x7);
michael@0 921 s7 = cospi_16_64 * (- x6 + x7);
michael@0 922 s10 = cospi_16_64 * (x10 + x11);
michael@0 923 s11 = cospi_16_64 * (- x10 + x11);
michael@0 924 s14 = (- cospi_16_64) * (x14 + x15);
michael@0 925 s15 = cospi_16_64 * (x14 - x15);
michael@0 926
michael@0 927 x2 = fdct_round_shift(s2);
michael@0 928 x3 = fdct_round_shift(s3);
michael@0 929 x6 = fdct_round_shift(s6);
michael@0 930 x7 = fdct_round_shift(s7);
michael@0 931 x10 = fdct_round_shift(s10);
michael@0 932 x11 = fdct_round_shift(s11);
michael@0 933 x14 = fdct_round_shift(s14);
michael@0 934 x15 = fdct_round_shift(s15);
michael@0 935
michael@0 936 output[0] = x0;
michael@0 937 output[1] = - x8;
michael@0 938 output[2] = x12;
michael@0 939 output[3] = - x4;
michael@0 940 output[4] = x6;
michael@0 941 output[5] = x14;
michael@0 942 output[6] = x10;
michael@0 943 output[7] = x2;
michael@0 944 output[8] = x3;
michael@0 945 output[9] = x11;
michael@0 946 output[10] = x15;
michael@0 947 output[11] = x7;
michael@0 948 output[12] = x5;
michael@0 949 output[13] = - x13;
michael@0 950 output[14] = x9;
michael@0 951 output[15] = - x1;
michael@0 952 }
michael@0 953
michael@0 954 static const transform_2d FHT_16[] = {
michael@0 955 { fdct16, fdct16 }, // DCT_DCT = 0
michael@0 956 { fadst16, fdct16 }, // ADST_DCT = 1
michael@0 957 { fdct16, fadst16 }, // DCT_ADST = 2
michael@0 958 { fadst16, fadst16 } // ADST_ADST = 3
michael@0 959 };
michael@0 960
michael@0 961 void vp9_short_fht16x16_c(const int16_t *input, int16_t *output,
michael@0 962 int stride, int tx_type) {
michael@0 963 int16_t out[256];
michael@0 964 int16_t *outptr = &out[0];
michael@0 965 int i, j;
michael@0 966 int16_t temp_in[16], temp_out[16];
michael@0 967 const transform_2d ht = FHT_16[tx_type];
michael@0 968
michael@0 969 // Columns
michael@0 970 for (i = 0; i < 16; ++i) {
michael@0 971 for (j = 0; j < 16; ++j)
michael@0 972 temp_in[j] = input[j * stride + i] * 4;
michael@0 973 ht.cols(temp_in, temp_out);
michael@0 974 for (j = 0; j < 16; ++j)
michael@0 975 outptr[j * 16 + i] = (temp_out[j] + 1 + (temp_out[j] < 0)) >> 2;
michael@0 976 // outptr[j * 16 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2;
michael@0 977 }
michael@0 978
michael@0 979 // Rows
michael@0 980 for (i = 0; i < 16; ++i) {
michael@0 981 for (j = 0; j < 16; ++j)
michael@0 982 temp_in[j] = out[j + i * 16];
michael@0 983 ht.rows(temp_in, temp_out);
michael@0 984 for (j = 0; j < 16; ++j)
michael@0 985 output[j + i * 16] = temp_out[j];
michael@0 986 }
michael@0 987 }
michael@0 988
michael@0 989 static INLINE int dct_32_round(int input) {
michael@0 990 int rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
michael@0 991 assert(-131072 <= rv && rv <= 131071);
michael@0 992 return rv;
michael@0 993 }
michael@0 994
michael@0 995 static INLINE int half_round_shift(int input) {
michael@0 996 int rv = (input + 1 + (input < 0)) >> 2;
michael@0 997 return rv;
michael@0 998 }
michael@0 999
michael@0 1000 static void dct32_1d(const int *input, int *output, int round) {
michael@0 1001 int step[32];
michael@0 1002 // Stage 1
michael@0 1003 step[0] = input[0] + input[(32 - 1)];
michael@0 1004 step[1] = input[1] + input[(32 - 2)];
michael@0 1005 step[2] = input[2] + input[(32 - 3)];
michael@0 1006 step[3] = input[3] + input[(32 - 4)];
michael@0 1007 step[4] = input[4] + input[(32 - 5)];
michael@0 1008 step[5] = input[5] + input[(32 - 6)];
michael@0 1009 step[6] = input[6] + input[(32 - 7)];
michael@0 1010 step[7] = input[7] + input[(32 - 8)];
michael@0 1011 step[8] = input[8] + input[(32 - 9)];
michael@0 1012 step[9] = input[9] + input[(32 - 10)];
michael@0 1013 step[10] = input[10] + input[(32 - 11)];
michael@0 1014 step[11] = input[11] + input[(32 - 12)];
michael@0 1015 step[12] = input[12] + input[(32 - 13)];
michael@0 1016 step[13] = input[13] + input[(32 - 14)];
michael@0 1017 step[14] = input[14] + input[(32 - 15)];
michael@0 1018 step[15] = input[15] + input[(32 - 16)];
michael@0 1019 step[16] = -input[16] + input[(32 - 17)];
michael@0 1020 step[17] = -input[17] + input[(32 - 18)];
michael@0 1021 step[18] = -input[18] + input[(32 - 19)];
michael@0 1022 step[19] = -input[19] + input[(32 - 20)];
michael@0 1023 step[20] = -input[20] + input[(32 - 21)];
michael@0 1024 step[21] = -input[21] + input[(32 - 22)];
michael@0 1025 step[22] = -input[22] + input[(32 - 23)];
michael@0 1026 step[23] = -input[23] + input[(32 - 24)];
michael@0 1027 step[24] = -input[24] + input[(32 - 25)];
michael@0 1028 step[25] = -input[25] + input[(32 - 26)];
michael@0 1029 step[26] = -input[26] + input[(32 - 27)];
michael@0 1030 step[27] = -input[27] + input[(32 - 28)];
michael@0 1031 step[28] = -input[28] + input[(32 - 29)];
michael@0 1032 step[29] = -input[29] + input[(32 - 30)];
michael@0 1033 step[30] = -input[30] + input[(32 - 31)];
michael@0 1034 step[31] = -input[31] + input[(32 - 32)];
michael@0 1035
michael@0 1036 // Stage 2
michael@0 1037 output[0] = step[0] + step[16 - 1];
michael@0 1038 output[1] = step[1] + step[16 - 2];
michael@0 1039 output[2] = step[2] + step[16 - 3];
michael@0 1040 output[3] = step[3] + step[16 - 4];
michael@0 1041 output[4] = step[4] + step[16 - 5];
michael@0 1042 output[5] = step[5] + step[16 - 6];
michael@0 1043 output[6] = step[6] + step[16 - 7];
michael@0 1044 output[7] = step[7] + step[16 - 8];
michael@0 1045 output[8] = -step[8] + step[16 - 9];
michael@0 1046 output[9] = -step[9] + step[16 - 10];
michael@0 1047 output[10] = -step[10] + step[16 - 11];
michael@0 1048 output[11] = -step[11] + step[16 - 12];
michael@0 1049 output[12] = -step[12] + step[16 - 13];
michael@0 1050 output[13] = -step[13] + step[16 - 14];
michael@0 1051 output[14] = -step[14] + step[16 - 15];
michael@0 1052 output[15] = -step[15] + step[16 - 16];
michael@0 1053
michael@0 1054 output[16] = step[16];
michael@0 1055 output[17] = step[17];
michael@0 1056 output[18] = step[18];
michael@0 1057 output[19] = step[19];
michael@0 1058
michael@0 1059 output[20] = dct_32_round((-step[20] + step[27]) * cospi_16_64);
michael@0 1060 output[21] = dct_32_round((-step[21] + step[26]) * cospi_16_64);
michael@0 1061 output[22] = dct_32_round((-step[22] + step[25]) * cospi_16_64);
michael@0 1062 output[23] = dct_32_round((-step[23] + step[24]) * cospi_16_64);
michael@0 1063
michael@0 1064 output[24] = dct_32_round((step[24] + step[23]) * cospi_16_64);
michael@0 1065 output[25] = dct_32_round((step[25] + step[22]) * cospi_16_64);
michael@0 1066 output[26] = dct_32_round((step[26] + step[21]) * cospi_16_64);
michael@0 1067 output[27] = dct_32_round((step[27] + step[20]) * cospi_16_64);
michael@0 1068
michael@0 1069 output[28] = step[28];
michael@0 1070 output[29] = step[29];
michael@0 1071 output[30] = step[30];
michael@0 1072 output[31] = step[31];
michael@0 1073
michael@0 1074 // dump the magnitude by 4, hence the intermediate values are within
michael@0 1075 // the range of 16 bits.
michael@0 1076 if (round) {
michael@0 1077 output[0] = half_round_shift(output[0]);
michael@0 1078 output[1] = half_round_shift(output[1]);
michael@0 1079 output[2] = half_round_shift(output[2]);
michael@0 1080 output[3] = half_round_shift(output[3]);
michael@0 1081 output[4] = half_round_shift(output[4]);
michael@0 1082 output[5] = half_round_shift(output[5]);
michael@0 1083 output[6] = half_round_shift(output[6]);
michael@0 1084 output[7] = half_round_shift(output[7]);
michael@0 1085 output[8] = half_round_shift(output[8]);
michael@0 1086 output[9] = half_round_shift(output[9]);
michael@0 1087 output[10] = half_round_shift(output[10]);
michael@0 1088 output[11] = half_round_shift(output[11]);
michael@0 1089 output[12] = half_round_shift(output[12]);
michael@0 1090 output[13] = half_round_shift(output[13]);
michael@0 1091 output[14] = half_round_shift(output[14]);
michael@0 1092 output[15] = half_round_shift(output[15]);
michael@0 1093
michael@0 1094 output[16] = half_round_shift(output[16]);
michael@0 1095 output[17] = half_round_shift(output[17]);
michael@0 1096 output[18] = half_round_shift(output[18]);
michael@0 1097 output[19] = half_round_shift(output[19]);
michael@0 1098 output[20] = half_round_shift(output[20]);
michael@0 1099 output[21] = half_round_shift(output[21]);
michael@0 1100 output[22] = half_round_shift(output[22]);
michael@0 1101 output[23] = half_round_shift(output[23]);
michael@0 1102 output[24] = half_round_shift(output[24]);
michael@0 1103 output[25] = half_round_shift(output[25]);
michael@0 1104 output[26] = half_round_shift(output[26]);
michael@0 1105 output[27] = half_round_shift(output[27]);
michael@0 1106 output[28] = half_round_shift(output[28]);
michael@0 1107 output[29] = half_round_shift(output[29]);
michael@0 1108 output[30] = half_round_shift(output[30]);
michael@0 1109 output[31] = half_round_shift(output[31]);
michael@0 1110 }
michael@0 1111
michael@0 1112 // Stage 3
michael@0 1113 step[0] = output[0] + output[(8 - 1)];
michael@0 1114 step[1] = output[1] + output[(8 - 2)];
michael@0 1115 step[2] = output[2] + output[(8 - 3)];
michael@0 1116 step[3] = output[3] + output[(8 - 4)];
michael@0 1117 step[4] = -output[4] + output[(8 - 5)];
michael@0 1118 step[5] = -output[5] + output[(8 - 6)];
michael@0 1119 step[6] = -output[6] + output[(8 - 7)];
michael@0 1120 step[7] = -output[7] + output[(8 - 8)];
michael@0 1121 step[8] = output[8];
michael@0 1122 step[9] = output[9];
michael@0 1123 step[10] = dct_32_round((-output[10] + output[13]) * cospi_16_64);
michael@0 1124 step[11] = dct_32_round((-output[11] + output[12]) * cospi_16_64);
michael@0 1125 step[12] = dct_32_round((output[12] + output[11]) * cospi_16_64);
michael@0 1126 step[13] = dct_32_round((output[13] + output[10]) * cospi_16_64);
michael@0 1127 step[14] = output[14];
michael@0 1128 step[15] = output[15];
michael@0 1129
michael@0 1130 step[16] = output[16] + output[23];
michael@0 1131 step[17] = output[17] + output[22];
michael@0 1132 step[18] = output[18] + output[21];
michael@0 1133 step[19] = output[19] + output[20];
michael@0 1134 step[20] = -output[20] + output[19];
michael@0 1135 step[21] = -output[21] + output[18];
michael@0 1136 step[22] = -output[22] + output[17];
michael@0 1137 step[23] = -output[23] + output[16];
michael@0 1138 step[24] = -output[24] + output[31];
michael@0 1139 step[25] = -output[25] + output[30];
michael@0 1140 step[26] = -output[26] + output[29];
michael@0 1141 step[27] = -output[27] + output[28];
michael@0 1142 step[28] = output[28] + output[27];
michael@0 1143 step[29] = output[29] + output[26];
michael@0 1144 step[30] = output[30] + output[25];
michael@0 1145 step[31] = output[31] + output[24];
michael@0 1146
michael@0 1147 // Stage 4
michael@0 1148 output[0] = step[0] + step[3];
michael@0 1149 output[1] = step[1] + step[2];
michael@0 1150 output[2] = -step[2] + step[1];
michael@0 1151 output[3] = -step[3] + step[0];
michael@0 1152 output[4] = step[4];
michael@0 1153 output[5] = dct_32_round((-step[5] + step[6]) * cospi_16_64);
michael@0 1154 output[6] = dct_32_round((step[6] + step[5]) * cospi_16_64);
michael@0 1155 output[7] = step[7];
michael@0 1156 output[8] = step[8] + step[11];
michael@0 1157 output[9] = step[9] + step[10];
michael@0 1158 output[10] = -step[10] + step[9];
michael@0 1159 output[11] = -step[11] + step[8];
michael@0 1160 output[12] = -step[12] + step[15];
michael@0 1161 output[13] = -step[13] + step[14];
michael@0 1162 output[14] = step[14] + step[13];
michael@0 1163 output[15] = step[15] + step[12];
michael@0 1164
michael@0 1165 output[16] = step[16];
michael@0 1166 output[17] = step[17];
michael@0 1167 output[18] = dct_32_round(step[18] * -cospi_8_64 + step[29] * cospi_24_64);
michael@0 1168 output[19] = dct_32_round(step[19] * -cospi_8_64 + step[28] * cospi_24_64);
michael@0 1169 output[20] = dct_32_round(step[20] * -cospi_24_64 + step[27] * -cospi_8_64);
michael@0 1170 output[21] = dct_32_round(step[21] * -cospi_24_64 + step[26] * -cospi_8_64);
michael@0 1171 output[22] = step[22];
michael@0 1172 output[23] = step[23];
michael@0 1173 output[24] = step[24];
michael@0 1174 output[25] = step[25];
michael@0 1175 output[26] = dct_32_round(step[26] * cospi_24_64 + step[21] * -cospi_8_64);
michael@0 1176 output[27] = dct_32_round(step[27] * cospi_24_64 + step[20] * -cospi_8_64);
michael@0 1177 output[28] = dct_32_round(step[28] * cospi_8_64 + step[19] * cospi_24_64);
michael@0 1178 output[29] = dct_32_round(step[29] * cospi_8_64 + step[18] * cospi_24_64);
michael@0 1179 output[30] = step[30];
michael@0 1180 output[31] = step[31];
michael@0 1181
michael@0 1182 // Stage 5
michael@0 1183 step[0] = dct_32_round((output[0] + output[1]) * cospi_16_64);
michael@0 1184 step[1] = dct_32_round((-output[1] + output[0]) * cospi_16_64);
michael@0 1185 step[2] = dct_32_round(output[2] * cospi_24_64 + output[3] * cospi_8_64);
michael@0 1186 step[3] = dct_32_round(output[3] * cospi_24_64 - output[2] * cospi_8_64);
michael@0 1187 step[4] = output[4] + output[5];
michael@0 1188 step[5] = -output[5] + output[4];
michael@0 1189 step[6] = -output[6] + output[7];
michael@0 1190 step[7] = output[7] + output[6];
michael@0 1191 step[8] = output[8];
michael@0 1192 step[9] = dct_32_round(output[9] * -cospi_8_64 + output[14] * cospi_24_64);
michael@0 1193 step[10] = dct_32_round(output[10] * -cospi_24_64 + output[13] * -cospi_8_64);
michael@0 1194 step[11] = output[11];
michael@0 1195 step[12] = output[12];
michael@0 1196 step[13] = dct_32_round(output[13] * cospi_24_64 + output[10] * -cospi_8_64);
michael@0 1197 step[14] = dct_32_round(output[14] * cospi_8_64 + output[9] * cospi_24_64);
michael@0 1198 step[15] = output[15];
michael@0 1199
michael@0 1200 step[16] = output[16] + output[19];
michael@0 1201 step[17] = output[17] + output[18];
michael@0 1202 step[18] = -output[18] + output[17];
michael@0 1203 step[19] = -output[19] + output[16];
michael@0 1204 step[20] = -output[20] + output[23];
michael@0 1205 step[21] = -output[21] + output[22];
michael@0 1206 step[22] = output[22] + output[21];
michael@0 1207 step[23] = output[23] + output[20];
michael@0 1208 step[24] = output[24] + output[27];
michael@0 1209 step[25] = output[25] + output[26];
michael@0 1210 step[26] = -output[26] + output[25];
michael@0 1211 step[27] = -output[27] + output[24];
michael@0 1212 step[28] = -output[28] + output[31];
michael@0 1213 step[29] = -output[29] + output[30];
michael@0 1214 step[30] = output[30] + output[29];
michael@0 1215 step[31] = output[31] + output[28];
michael@0 1216
michael@0 1217 // Stage 6
michael@0 1218 output[0] = step[0];
michael@0 1219 output[1] = step[1];
michael@0 1220 output[2] = step[2];
michael@0 1221 output[3] = step[3];
michael@0 1222 output[4] = dct_32_round(step[4] * cospi_28_64 + step[7] * cospi_4_64);
michael@0 1223 output[5] = dct_32_round(step[5] * cospi_12_64 + step[6] * cospi_20_64);
michael@0 1224 output[6] = dct_32_round(step[6] * cospi_12_64 + step[5] * -cospi_20_64);
michael@0 1225 output[7] = dct_32_round(step[7] * cospi_28_64 + step[4] * -cospi_4_64);
michael@0 1226 output[8] = step[8] + step[9];
michael@0 1227 output[9] = -step[9] + step[8];
michael@0 1228 output[10] = -step[10] + step[11];
michael@0 1229 output[11] = step[11] + step[10];
michael@0 1230 output[12] = step[12] + step[13];
michael@0 1231 output[13] = -step[13] + step[12];
michael@0 1232 output[14] = -step[14] + step[15];
michael@0 1233 output[15] = step[15] + step[14];
michael@0 1234
michael@0 1235 output[16] = step[16];
michael@0 1236 output[17] = dct_32_round(step[17] * -cospi_4_64 + step[30] * cospi_28_64);
michael@0 1237 output[18] = dct_32_round(step[18] * -cospi_28_64 + step[29] * -cospi_4_64);
michael@0 1238 output[19] = step[19];
michael@0 1239 output[20] = step[20];
michael@0 1240 output[21] = dct_32_round(step[21] * -cospi_20_64 + step[26] * cospi_12_64);
michael@0 1241 output[22] = dct_32_round(step[22] * -cospi_12_64 + step[25] * -cospi_20_64);
michael@0 1242 output[23] = step[23];
michael@0 1243 output[24] = step[24];
michael@0 1244 output[25] = dct_32_round(step[25] * cospi_12_64 + step[22] * -cospi_20_64);
michael@0 1245 output[26] = dct_32_round(step[26] * cospi_20_64 + step[21] * cospi_12_64);
michael@0 1246 output[27] = step[27];
michael@0 1247 output[28] = step[28];
michael@0 1248 output[29] = dct_32_round(step[29] * cospi_28_64 + step[18] * -cospi_4_64);
michael@0 1249 output[30] = dct_32_round(step[30] * cospi_4_64 + step[17] * cospi_28_64);
michael@0 1250 output[31] = step[31];
michael@0 1251
michael@0 1252 // Stage 7
michael@0 1253 step[0] = output[0];
michael@0 1254 step[1] = output[1];
michael@0 1255 step[2] = output[2];
michael@0 1256 step[3] = output[3];
michael@0 1257 step[4] = output[4];
michael@0 1258 step[5] = output[5];
michael@0 1259 step[6] = output[6];
michael@0 1260 step[7] = output[7];
michael@0 1261 step[8] = dct_32_round(output[8] * cospi_30_64 + output[15] * cospi_2_64);
michael@0 1262 step[9] = dct_32_round(output[9] * cospi_14_64 + output[14] * cospi_18_64);
michael@0 1263 step[10] = dct_32_round(output[10] * cospi_22_64 + output[13] * cospi_10_64);
michael@0 1264 step[11] = dct_32_round(output[11] * cospi_6_64 + output[12] * cospi_26_64);
michael@0 1265 step[12] = dct_32_round(output[12] * cospi_6_64 + output[11] * -cospi_26_64);
michael@0 1266 step[13] = dct_32_round(output[13] * cospi_22_64 + output[10] * -cospi_10_64);
michael@0 1267 step[14] = dct_32_round(output[14] * cospi_14_64 + output[9] * -cospi_18_64);
michael@0 1268 step[15] = dct_32_round(output[15] * cospi_30_64 + output[8] * -cospi_2_64);
michael@0 1269
michael@0 1270 step[16] = output[16] + output[17];
michael@0 1271 step[17] = -output[17] + output[16];
michael@0 1272 step[18] = -output[18] + output[19];
michael@0 1273 step[19] = output[19] + output[18];
michael@0 1274 step[20] = output[20] + output[21];
michael@0 1275 step[21] = -output[21] + output[20];
michael@0 1276 step[22] = -output[22] + output[23];
michael@0 1277 step[23] = output[23] + output[22];
michael@0 1278 step[24] = output[24] + output[25];
michael@0 1279 step[25] = -output[25] + output[24];
michael@0 1280 step[26] = -output[26] + output[27];
michael@0 1281 step[27] = output[27] + output[26];
michael@0 1282 step[28] = output[28] + output[29];
michael@0 1283 step[29] = -output[29] + output[28];
michael@0 1284 step[30] = -output[30] + output[31];
michael@0 1285 step[31] = output[31] + output[30];
michael@0 1286
michael@0 1287 // Final stage --- outputs indices are bit-reversed.
michael@0 1288 output[0] = step[0];
michael@0 1289 output[16] = step[1];
michael@0 1290 output[8] = step[2];
michael@0 1291 output[24] = step[3];
michael@0 1292 output[4] = step[4];
michael@0 1293 output[20] = step[5];
michael@0 1294 output[12] = step[6];
michael@0 1295 output[28] = step[7];
michael@0 1296 output[2] = step[8];
michael@0 1297 output[18] = step[9];
michael@0 1298 output[10] = step[10];
michael@0 1299 output[26] = step[11];
michael@0 1300 output[6] = step[12];
michael@0 1301 output[22] = step[13];
michael@0 1302 output[14] = step[14];
michael@0 1303 output[30] = step[15];
michael@0 1304
michael@0 1305 output[1] = dct_32_round(step[16] * cospi_31_64 + step[31] * cospi_1_64);
michael@0 1306 output[17] = dct_32_round(step[17] * cospi_15_64 + step[30] * cospi_17_64);
michael@0 1307 output[9] = dct_32_round(step[18] * cospi_23_64 + step[29] * cospi_9_64);
michael@0 1308 output[25] = dct_32_round(step[19] * cospi_7_64 + step[28] * cospi_25_64);
michael@0 1309 output[5] = dct_32_round(step[20] * cospi_27_64 + step[27] * cospi_5_64);
michael@0 1310 output[21] = dct_32_round(step[21] * cospi_11_64 + step[26] * cospi_21_64);
michael@0 1311 output[13] = dct_32_round(step[22] * cospi_19_64 + step[25] * cospi_13_64);
michael@0 1312 output[29] = dct_32_round(step[23] * cospi_3_64 + step[24] * cospi_29_64);
michael@0 1313 output[3] = dct_32_round(step[24] * cospi_3_64 + step[23] * -cospi_29_64);
michael@0 1314 output[19] = dct_32_round(step[25] * cospi_19_64 + step[22] * -cospi_13_64);
michael@0 1315 output[11] = dct_32_round(step[26] * cospi_11_64 + step[21] * -cospi_21_64);
michael@0 1316 output[27] = dct_32_round(step[27] * cospi_27_64 + step[20] * -cospi_5_64);
michael@0 1317 output[7] = dct_32_round(step[28] * cospi_7_64 + step[19] * -cospi_25_64);
michael@0 1318 output[23] = dct_32_round(step[29] * cospi_23_64 + step[18] * -cospi_9_64);
michael@0 1319 output[15] = dct_32_round(step[30] * cospi_15_64 + step[17] * -cospi_17_64);
michael@0 1320 output[31] = dct_32_round(step[31] * cospi_31_64 + step[16] * -cospi_1_64);
michael@0 1321 }
michael@0 1322
michael@0 1323 void vp9_fdct32x32_c(const int16_t *input, int16_t *out, int stride) {
michael@0 1324 int i, j;
michael@0 1325 int output[32 * 32];
michael@0 1326
michael@0 1327 // Columns
michael@0 1328 for (i = 0; i < 32; ++i) {
michael@0 1329 int temp_in[32], temp_out[32];
michael@0 1330 for (j = 0; j < 32; ++j)
michael@0 1331 temp_in[j] = input[j * stride + i] * 4;
michael@0 1332 dct32_1d(temp_in, temp_out, 0);
michael@0 1333 for (j = 0; j < 32; ++j)
michael@0 1334 output[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2;
michael@0 1335 }
michael@0 1336
michael@0 1337 // Rows
michael@0 1338 for (i = 0; i < 32; ++i) {
michael@0 1339 int temp_in[32], temp_out[32];
michael@0 1340 for (j = 0; j < 32; ++j)
michael@0 1341 temp_in[j] = output[j + i * 32];
michael@0 1342 dct32_1d(temp_in, temp_out, 0);
michael@0 1343 for (j = 0; j < 32; ++j)
michael@0 1344 out[j + i * 32] = (temp_out[j] + 1 + (temp_out[j] < 0)) >> 2;
michael@0 1345 }
michael@0 1346 }
michael@0 1347
michael@0 1348 // Note that although we use dct_32_round in dct32_1d computation flow,
michael@0 1349 // this 2d fdct32x32 for rate-distortion optimization loop is operating
michael@0 1350 // within 16 bits precision.
michael@0 1351 void vp9_fdct32x32_rd_c(const int16_t *input, int16_t *out, int stride) {
michael@0 1352 int i, j;
michael@0 1353 int output[32 * 32];
michael@0 1354
michael@0 1355 // Columns
michael@0 1356 for (i = 0; i < 32; ++i) {
michael@0 1357 int temp_in[32], temp_out[32];
michael@0 1358 for (j = 0; j < 32; ++j)
michael@0 1359 temp_in[j] = input[j * stride + i] * 4;
michael@0 1360 dct32_1d(temp_in, temp_out, 0);
michael@0 1361 for (j = 0; j < 32; ++j)
michael@0 1362 // TODO(cd): see quality impact of only doing
michael@0 1363 // output[j * 32 + i] = (temp_out[j] + 1) >> 2;
michael@0 1364 // PS: also change code in vp9/encoder/x86/vp9_dct_sse2.c
michael@0 1365 output[j * 32 + i] = (temp_out[j] + 1 + (temp_out[j] > 0)) >> 2;
michael@0 1366 }
michael@0 1367
michael@0 1368 // Rows
michael@0 1369 for (i = 0; i < 32; ++i) {
michael@0 1370 int temp_in[32], temp_out[32];
michael@0 1371 for (j = 0; j < 32; ++j)
michael@0 1372 temp_in[j] = output[j + i * 32];
michael@0 1373 dct32_1d(temp_in, temp_out, 1);
michael@0 1374 for (j = 0; j < 32; ++j)
michael@0 1375 out[j + i * 32] = temp_out[j];
michael@0 1376 }
michael@0 1377 }
michael@0 1378
michael@0 1379 void vp9_fht4x4(TX_TYPE tx_type, const int16_t *input, int16_t *output,
michael@0 1380 int stride) {
michael@0 1381 if (tx_type == DCT_DCT)
michael@0 1382 vp9_fdct4x4(input, output, stride);
michael@0 1383 else
michael@0 1384 vp9_short_fht4x4(input, output, stride, tx_type);
michael@0 1385 }
michael@0 1386
michael@0 1387 void vp9_fht8x8(TX_TYPE tx_type, const int16_t *input, int16_t *output,
michael@0 1388 int stride) {
michael@0 1389 if (tx_type == DCT_DCT)
michael@0 1390 vp9_fdct8x8(input, output, stride);
michael@0 1391 else
michael@0 1392 vp9_short_fht8x8(input, output, stride, tx_type);
michael@0 1393 }
michael@0 1394
michael@0 1395 void vp9_fht16x16(TX_TYPE tx_type, const int16_t *input, int16_t *output,
michael@0 1396 int stride) {
michael@0 1397 if (tx_type == DCT_DCT)
michael@0 1398 vp9_fdct16x16(input, output, stride);
michael@0 1399 else
michael@0 1400 vp9_short_fht16x16(input, output, stride, tx_type);
michael@0 1401 }

mercurial