michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "./vpx_config.h" michael@0: #include "./vp9_rtcd.h" michael@0: #include "vp9/common/vp9_systemdependent.h" michael@0: #include "vp9/common/vp9_blockd.h" michael@0: #include "vp9/common/vp9_common.h" michael@0: #include "vp9/common/vp9_idct.h" michael@0: michael@0: void vp9_iwht4x4_16_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: /* 4-point reversible, orthonormal inverse Walsh-Hadamard in 3.5 adds, michael@0: 0.5 shifts per pixel. */ michael@0: int i; michael@0: int16_t output[16]; michael@0: int a1, b1, c1, d1, e1; michael@0: const int16_t *ip = input; michael@0: int16_t *op = output; michael@0: michael@0: for (i = 0; i < 4; i++) { michael@0: a1 = ip[0] >> UNIT_QUANT_SHIFT; michael@0: c1 = ip[1] >> UNIT_QUANT_SHIFT; michael@0: d1 = ip[2] >> UNIT_QUANT_SHIFT; michael@0: b1 = ip[3] >> UNIT_QUANT_SHIFT; michael@0: a1 += c1; michael@0: d1 -= b1; michael@0: e1 = (a1 - d1) >> 1; michael@0: b1 = e1 - b1; michael@0: c1 = e1 - c1; michael@0: a1 -= b1; michael@0: d1 += c1; michael@0: op[0] = a1; michael@0: op[1] = b1; michael@0: op[2] = c1; michael@0: op[3] = d1; michael@0: ip += 4; michael@0: op += 4; michael@0: } michael@0: michael@0: ip = output; michael@0: for (i = 0; i < 4; i++) { michael@0: a1 = ip[4 * 0]; michael@0: c1 = ip[4 * 1]; michael@0: d1 = ip[4 * 2]; michael@0: b1 = ip[4 * 3]; michael@0: a1 += c1; michael@0: d1 -= b1; michael@0: e1 = (a1 - d1) >> 1; michael@0: b1 = e1 - b1; michael@0: c1 = e1 - c1; michael@0: a1 -= b1; michael@0: d1 += c1; michael@0: dest[stride * 0] = clip_pixel(dest[stride * 0] + a1); michael@0: dest[stride * 1] = clip_pixel(dest[stride * 1] + b1); michael@0: dest[stride * 2] = clip_pixel(dest[stride * 2] + c1); michael@0: dest[stride * 3] = clip_pixel(dest[stride * 3] + d1); michael@0: michael@0: ip++; michael@0: dest++; michael@0: } michael@0: } michael@0: michael@0: void vp9_iwht4x4_1_add_c(const int16_t *in, uint8_t *dest, int dest_stride) { michael@0: int i; michael@0: int a1, e1; michael@0: int16_t tmp[4]; michael@0: const int16_t *ip = in; michael@0: int16_t *op = tmp; michael@0: michael@0: a1 = ip[0] >> UNIT_QUANT_SHIFT; michael@0: e1 = a1 >> 1; michael@0: a1 -= e1; michael@0: op[0] = a1; michael@0: op[1] = op[2] = op[3] = e1; michael@0: michael@0: ip = tmp; michael@0: for (i = 0; i < 4; i++) { michael@0: e1 = ip[0] >> 1; michael@0: a1 = ip[0] - e1; michael@0: dest[dest_stride * 0] = clip_pixel(dest[dest_stride * 0] + a1); michael@0: dest[dest_stride * 1] = clip_pixel(dest[dest_stride * 1] + e1); michael@0: dest[dest_stride * 2] = clip_pixel(dest[dest_stride * 2] + e1); michael@0: dest[dest_stride * 3] = clip_pixel(dest[dest_stride * 3] + e1); michael@0: ip++; michael@0: dest++; michael@0: } michael@0: } michael@0: michael@0: static void idct4_1d(const int16_t *input, int16_t *output) { michael@0: int16_t step[4]; michael@0: int temp1, temp2; michael@0: // stage 1 michael@0: temp1 = (input[0] + input[2]) * cospi_16_64; michael@0: temp2 = (input[0] - input[2]) * cospi_16_64; michael@0: step[0] = dct_const_round_shift(temp1); michael@0: step[1] = dct_const_round_shift(temp2); michael@0: temp1 = input[1] * cospi_24_64 - input[3] * cospi_8_64; michael@0: temp2 = input[1] * cospi_8_64 + input[3] * cospi_24_64; michael@0: step[2] = dct_const_round_shift(temp1); michael@0: step[3] = dct_const_round_shift(temp2); michael@0: michael@0: // stage 2 michael@0: output[0] = step[0] + step[3]; michael@0: output[1] = step[1] + step[2]; michael@0: output[2] = step[1] - step[2]; michael@0: output[3] = step[0] - step[3]; michael@0: } michael@0: michael@0: void vp9_idct4x4_16_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int16_t out[4 * 4]; michael@0: int16_t *outptr = out; michael@0: int i, j; michael@0: int16_t temp_in[4], temp_out[4]; michael@0: michael@0: // Rows michael@0: for (i = 0; i < 4; ++i) { michael@0: idct4_1d(input, outptr); michael@0: input += 4; michael@0: outptr += 4; michael@0: } michael@0: michael@0: // Columns michael@0: for (i = 0; i < 4; ++i) { michael@0: for (j = 0; j < 4; ++j) michael@0: temp_in[j] = out[j * 4 + i]; michael@0: idct4_1d(temp_in, temp_out); michael@0: for (j = 0; j < 4; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 4) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct4x4_1_add_c(const int16_t *input, uint8_t *dest, int dest_stride) { michael@0: int i; michael@0: int a1; michael@0: int16_t out = dct_const_round_shift(input[0] * cospi_16_64); michael@0: out = dct_const_round_shift(out * cospi_16_64); michael@0: a1 = ROUND_POWER_OF_TWO(out, 4); michael@0: michael@0: for (i = 0; i < 4; i++) { michael@0: dest[0] = clip_pixel(dest[0] + a1); michael@0: dest[1] = clip_pixel(dest[1] + a1); michael@0: dest[2] = clip_pixel(dest[2] + a1); michael@0: dest[3] = clip_pixel(dest[3] + a1); michael@0: dest += dest_stride; michael@0: } michael@0: } michael@0: michael@0: static void idct8_1d(const int16_t *input, int16_t *output) { michael@0: int16_t step1[8], step2[8]; michael@0: int temp1, temp2; michael@0: // stage 1 michael@0: step1[0] = input[0]; michael@0: step1[2] = input[4]; michael@0: step1[1] = input[2]; michael@0: step1[3] = input[6]; michael@0: temp1 = input[1] * cospi_28_64 - input[7] * cospi_4_64; michael@0: temp2 = input[1] * cospi_4_64 + input[7] * cospi_28_64; michael@0: step1[4] = dct_const_round_shift(temp1); michael@0: step1[7] = dct_const_round_shift(temp2); michael@0: temp1 = input[5] * cospi_12_64 - input[3] * cospi_20_64; michael@0: temp2 = input[5] * cospi_20_64 + input[3] * cospi_12_64; michael@0: step1[5] = dct_const_round_shift(temp1); michael@0: step1[6] = dct_const_round_shift(temp2); michael@0: michael@0: // stage 2 & stage 3 - even half michael@0: idct4_1d(step1, step1); michael@0: michael@0: // stage 2 - odd half michael@0: step2[4] = step1[4] + step1[5]; michael@0: step2[5] = step1[4] - step1[5]; michael@0: step2[6] = -step1[6] + step1[7]; michael@0: step2[7] = step1[6] + step1[7]; michael@0: michael@0: // stage 3 -odd half michael@0: step1[4] = step2[4]; michael@0: temp1 = (step2[6] - step2[5]) * cospi_16_64; michael@0: temp2 = (step2[5] + step2[6]) * cospi_16_64; michael@0: step1[5] = dct_const_round_shift(temp1); michael@0: step1[6] = dct_const_round_shift(temp2); michael@0: step1[7] = step2[7]; michael@0: michael@0: // stage 4 michael@0: output[0] = step1[0] + step1[7]; michael@0: output[1] = step1[1] + step1[6]; michael@0: output[2] = step1[2] + step1[5]; michael@0: output[3] = step1[3] + step1[4]; michael@0: output[4] = step1[3] - step1[4]; michael@0: output[5] = step1[2] - step1[5]; michael@0: output[6] = step1[1] - step1[6]; michael@0: output[7] = step1[0] - step1[7]; michael@0: } michael@0: michael@0: void vp9_idct8x8_64_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int16_t out[8 * 8]; michael@0: int16_t *outptr = out; michael@0: int i, j; michael@0: int16_t temp_in[8], temp_out[8]; michael@0: michael@0: // First transform rows michael@0: for (i = 0; i < 8; ++i) { michael@0: idct8_1d(input, outptr); michael@0: input += 8; michael@0: outptr += 8; michael@0: } michael@0: michael@0: // Then transform columns michael@0: for (i = 0; i < 8; ++i) { michael@0: for (j = 0; j < 8; ++j) michael@0: temp_in[j] = out[j * 8 + i]; michael@0: idct8_1d(temp_in, temp_out); michael@0: for (j = 0; j < 8; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 5) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct8x8_1_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int i, j; michael@0: int a1; michael@0: int16_t out = dct_const_round_shift(input[0] * cospi_16_64); michael@0: out = dct_const_round_shift(out * cospi_16_64); michael@0: a1 = ROUND_POWER_OF_TWO(out, 5); michael@0: for (j = 0; j < 8; ++j) { michael@0: for (i = 0; i < 8; ++i) michael@0: dest[i] = clip_pixel(dest[i] + a1); michael@0: dest += stride; michael@0: } michael@0: } michael@0: michael@0: static void iadst4_1d(const int16_t *input, int16_t *output) { michael@0: int s0, s1, s2, s3, s4, s5, s6, s7; michael@0: michael@0: int x0 = input[0]; michael@0: int x1 = input[1]; michael@0: int x2 = input[2]; michael@0: int x3 = input[3]; michael@0: michael@0: if (!(x0 | x1 | x2 | x3)) { michael@0: output[0] = output[1] = output[2] = output[3] = 0; michael@0: return; michael@0: } michael@0: michael@0: s0 = sinpi_1_9 * x0; michael@0: s1 = sinpi_2_9 * x0; michael@0: s2 = sinpi_3_9 * x1; michael@0: s3 = sinpi_4_9 * x2; michael@0: s4 = sinpi_1_9 * x2; michael@0: s5 = sinpi_2_9 * x3; michael@0: s6 = sinpi_4_9 * x3; michael@0: s7 = x0 - x2 + x3; michael@0: michael@0: x0 = s0 + s3 + s5; michael@0: x1 = s1 - s4 - s6; michael@0: x2 = sinpi_3_9 * s7; michael@0: x3 = s2; michael@0: michael@0: s0 = x0 + x3; michael@0: s1 = x1 + x3; michael@0: s2 = x2; michael@0: s3 = x0 + x1 - x3; michael@0: michael@0: // 1-D transform scaling factor is sqrt(2). michael@0: // The overall dynamic range is 14b (input) + 14b (multiplication scaling) michael@0: // + 1b (addition) = 29b. michael@0: // Hence the output bit depth is 15b. michael@0: output[0] = dct_const_round_shift(s0); michael@0: output[1] = dct_const_round_shift(s1); michael@0: output[2] = dct_const_round_shift(s2); michael@0: output[3] = dct_const_round_shift(s3); michael@0: } michael@0: michael@0: void vp9_iht4x4_16_add_c(const int16_t *input, uint8_t *dest, int stride, michael@0: int tx_type) { michael@0: const transform_2d IHT_4[] = { michael@0: { idct4_1d, idct4_1d }, // DCT_DCT = 0 michael@0: { iadst4_1d, idct4_1d }, // ADST_DCT = 1 michael@0: { idct4_1d, iadst4_1d }, // DCT_ADST = 2 michael@0: { iadst4_1d, iadst4_1d } // ADST_ADST = 3 michael@0: }; michael@0: michael@0: int i, j; michael@0: int16_t out[4 * 4]; michael@0: int16_t *outptr = out; michael@0: int16_t temp_in[4], temp_out[4]; michael@0: michael@0: // inverse transform row vectors michael@0: for (i = 0; i < 4; ++i) { michael@0: IHT_4[tx_type].rows(input, outptr); michael@0: input += 4; michael@0: outptr += 4; michael@0: } michael@0: michael@0: // inverse transform column vectors michael@0: for (i = 0; i < 4; ++i) { michael@0: for (j = 0; j < 4; ++j) michael@0: temp_in[j] = out[j * 4 + i]; michael@0: IHT_4[tx_type].cols(temp_in, temp_out); michael@0: for (j = 0; j < 4; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 4) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: static void iadst8_1d(const int16_t *input, int16_t *output) { michael@0: int s0, s1, s2, s3, s4, s5, s6, s7; michael@0: michael@0: int x0 = input[7]; michael@0: int x1 = input[0]; michael@0: int x2 = input[5]; michael@0: int x3 = input[2]; michael@0: int x4 = input[3]; michael@0: int x5 = input[4]; michael@0: int x6 = input[1]; michael@0: int x7 = input[6]; michael@0: michael@0: if (!(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7)) { michael@0: output[0] = output[1] = output[2] = output[3] = output[4] michael@0: = output[5] = output[6] = output[7] = 0; michael@0: return; michael@0: } michael@0: michael@0: // stage 1 michael@0: s0 = cospi_2_64 * x0 + cospi_30_64 * x1; michael@0: s1 = cospi_30_64 * x0 - cospi_2_64 * x1; michael@0: s2 = cospi_10_64 * x2 + cospi_22_64 * x3; michael@0: s3 = cospi_22_64 * x2 - cospi_10_64 * x3; michael@0: s4 = cospi_18_64 * x4 + cospi_14_64 * x5; michael@0: s5 = cospi_14_64 * x4 - cospi_18_64 * x5; michael@0: s6 = cospi_26_64 * x6 + cospi_6_64 * x7; michael@0: s7 = cospi_6_64 * x6 - cospi_26_64 * x7; michael@0: michael@0: x0 = dct_const_round_shift(s0 + s4); michael@0: x1 = dct_const_round_shift(s1 + s5); michael@0: x2 = dct_const_round_shift(s2 + s6); michael@0: x3 = dct_const_round_shift(s3 + s7); michael@0: x4 = dct_const_round_shift(s0 - s4); michael@0: x5 = dct_const_round_shift(s1 - s5); michael@0: x6 = dct_const_round_shift(s2 - s6); michael@0: x7 = dct_const_round_shift(s3 - s7); michael@0: michael@0: // stage 2 michael@0: s0 = x0; michael@0: s1 = x1; michael@0: s2 = x2; michael@0: s3 = x3; michael@0: s4 = cospi_8_64 * x4 + cospi_24_64 * x5; michael@0: s5 = cospi_24_64 * x4 - cospi_8_64 * x5; michael@0: s6 = -cospi_24_64 * x6 + cospi_8_64 * x7; michael@0: s7 = cospi_8_64 * x6 + cospi_24_64 * x7; michael@0: michael@0: x0 = s0 + s2; michael@0: x1 = s1 + s3; michael@0: x2 = s0 - s2; michael@0: x3 = s1 - s3; michael@0: x4 = dct_const_round_shift(s4 + s6); michael@0: x5 = dct_const_round_shift(s5 + s7); michael@0: x6 = dct_const_round_shift(s4 - s6); michael@0: x7 = dct_const_round_shift(s5 - s7); michael@0: michael@0: // stage 3 michael@0: s2 = cospi_16_64 * (x2 + x3); michael@0: s3 = cospi_16_64 * (x2 - x3); michael@0: s6 = cospi_16_64 * (x6 + x7); michael@0: s7 = cospi_16_64 * (x6 - x7); michael@0: michael@0: x2 = dct_const_round_shift(s2); michael@0: x3 = dct_const_round_shift(s3); michael@0: x6 = dct_const_round_shift(s6); michael@0: x7 = dct_const_round_shift(s7); michael@0: michael@0: output[0] = x0; michael@0: output[1] = -x4; michael@0: output[2] = x6; michael@0: output[3] = -x2; michael@0: output[4] = x3; michael@0: output[5] = -x7; michael@0: output[6] = x5; michael@0: output[7] = -x1; michael@0: } michael@0: michael@0: static const transform_2d IHT_8[] = { michael@0: { idct8_1d, idct8_1d }, // DCT_DCT = 0 michael@0: { iadst8_1d, idct8_1d }, // ADST_DCT = 1 michael@0: { idct8_1d, iadst8_1d }, // DCT_ADST = 2 michael@0: { iadst8_1d, iadst8_1d } // ADST_ADST = 3 michael@0: }; michael@0: michael@0: void vp9_iht8x8_64_add_c(const int16_t *input, uint8_t *dest, int stride, michael@0: int tx_type) { michael@0: int i, j; michael@0: int16_t out[8 * 8]; michael@0: int16_t *outptr = out; michael@0: int16_t temp_in[8], temp_out[8]; michael@0: const transform_2d ht = IHT_8[tx_type]; michael@0: michael@0: // inverse transform row vectors michael@0: for (i = 0; i < 8; ++i) { michael@0: ht.rows(input, outptr); michael@0: input += 8; michael@0: outptr += 8; michael@0: } michael@0: michael@0: // inverse transform column vectors michael@0: for (i = 0; i < 8; ++i) { michael@0: for (j = 0; j < 8; ++j) michael@0: temp_in[j] = out[j * 8 + i]; michael@0: ht.cols(temp_in, temp_out); michael@0: for (j = 0; j < 8; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 5) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct8x8_10_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int16_t out[8 * 8] = { 0 }; michael@0: int16_t *outptr = out; michael@0: int i, j; michael@0: int16_t temp_in[8], temp_out[8]; michael@0: michael@0: // First transform rows michael@0: // only first 4 row has non-zero coefs michael@0: for (i = 0; i < 4; ++i) { michael@0: idct8_1d(input, outptr); michael@0: input += 8; michael@0: outptr += 8; michael@0: } michael@0: michael@0: // Then transform columns michael@0: for (i = 0; i < 8; ++i) { michael@0: for (j = 0; j < 8; ++j) michael@0: temp_in[j] = out[j * 8 + i]; michael@0: idct8_1d(temp_in, temp_out); michael@0: for (j = 0; j < 8; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 5) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: static void idct16_1d(const int16_t *input, int16_t *output) { michael@0: int16_t step1[16], step2[16]; michael@0: int temp1, temp2; michael@0: michael@0: // stage 1 michael@0: step1[0] = input[0/2]; michael@0: step1[1] = input[16/2]; michael@0: step1[2] = input[8/2]; michael@0: step1[3] = input[24/2]; michael@0: step1[4] = input[4/2]; michael@0: step1[5] = input[20/2]; michael@0: step1[6] = input[12/2]; michael@0: step1[7] = input[28/2]; michael@0: step1[8] = input[2/2]; michael@0: step1[9] = input[18/2]; michael@0: step1[10] = input[10/2]; michael@0: step1[11] = input[26/2]; michael@0: step1[12] = input[6/2]; michael@0: step1[13] = input[22/2]; michael@0: step1[14] = input[14/2]; michael@0: step1[15] = input[30/2]; michael@0: michael@0: // stage 2 michael@0: step2[0] = step1[0]; michael@0: step2[1] = step1[1]; michael@0: step2[2] = step1[2]; michael@0: step2[3] = step1[3]; michael@0: step2[4] = step1[4]; michael@0: step2[5] = step1[5]; michael@0: step2[6] = step1[6]; michael@0: step2[7] = step1[7]; michael@0: michael@0: temp1 = step1[8] * cospi_30_64 - step1[15] * cospi_2_64; michael@0: temp2 = step1[8] * cospi_2_64 + step1[15] * cospi_30_64; michael@0: step2[8] = dct_const_round_shift(temp1); michael@0: step2[15] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = step1[9] * cospi_14_64 - step1[14] * cospi_18_64; michael@0: temp2 = step1[9] * cospi_18_64 + step1[14] * cospi_14_64; michael@0: step2[9] = dct_const_round_shift(temp1); michael@0: step2[14] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = step1[10] * cospi_22_64 - step1[13] * cospi_10_64; michael@0: temp2 = step1[10] * cospi_10_64 + step1[13] * cospi_22_64; michael@0: step2[10] = dct_const_round_shift(temp1); michael@0: step2[13] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = step1[11] * cospi_6_64 - step1[12] * cospi_26_64; michael@0: temp2 = step1[11] * cospi_26_64 + step1[12] * cospi_6_64; michael@0: step2[11] = dct_const_round_shift(temp1); michael@0: step2[12] = dct_const_round_shift(temp2); michael@0: michael@0: // stage 3 michael@0: step1[0] = step2[0]; michael@0: step1[1] = step2[1]; michael@0: step1[2] = step2[2]; michael@0: step1[3] = step2[3]; michael@0: michael@0: temp1 = step2[4] * cospi_28_64 - step2[7] * cospi_4_64; michael@0: temp2 = step2[4] * cospi_4_64 + step2[7] * cospi_28_64; michael@0: step1[4] = dct_const_round_shift(temp1); michael@0: step1[7] = dct_const_round_shift(temp2); michael@0: temp1 = step2[5] * cospi_12_64 - step2[6] * cospi_20_64; michael@0: temp2 = step2[5] * cospi_20_64 + step2[6] * cospi_12_64; michael@0: step1[5] = dct_const_round_shift(temp1); michael@0: step1[6] = dct_const_round_shift(temp2); michael@0: michael@0: step1[8] = step2[8] + step2[9]; michael@0: step1[9] = step2[8] - step2[9]; michael@0: step1[10] = -step2[10] + step2[11]; michael@0: step1[11] = step2[10] + step2[11]; michael@0: step1[12] = step2[12] + step2[13]; michael@0: step1[13] = step2[12] - step2[13]; michael@0: step1[14] = -step2[14] + step2[15]; michael@0: step1[15] = step2[14] + step2[15]; michael@0: michael@0: // stage 4 michael@0: temp1 = (step1[0] + step1[1]) * cospi_16_64; michael@0: temp2 = (step1[0] - step1[1]) * cospi_16_64; michael@0: step2[0] = dct_const_round_shift(temp1); michael@0: step2[1] = dct_const_round_shift(temp2); michael@0: temp1 = step1[2] * cospi_24_64 - step1[3] * cospi_8_64; michael@0: temp2 = step1[2] * cospi_8_64 + step1[3] * cospi_24_64; michael@0: step2[2] = dct_const_round_shift(temp1); michael@0: step2[3] = dct_const_round_shift(temp2); michael@0: step2[4] = step1[4] + step1[5]; michael@0: step2[5] = step1[4] - step1[5]; michael@0: step2[6] = -step1[6] + step1[7]; michael@0: step2[7] = step1[6] + step1[7]; michael@0: michael@0: step2[8] = step1[8]; michael@0: step2[15] = step1[15]; michael@0: temp1 = -step1[9] * cospi_8_64 + step1[14] * cospi_24_64; michael@0: temp2 = step1[9] * cospi_24_64 + step1[14] * cospi_8_64; michael@0: step2[9] = dct_const_round_shift(temp1); michael@0: step2[14] = dct_const_round_shift(temp2); michael@0: temp1 = -step1[10] * cospi_24_64 - step1[13] * cospi_8_64; michael@0: temp2 = -step1[10] * cospi_8_64 + step1[13] * cospi_24_64; michael@0: step2[10] = dct_const_round_shift(temp1); michael@0: step2[13] = dct_const_round_shift(temp2); michael@0: step2[11] = step1[11]; michael@0: step2[12] = step1[12]; michael@0: michael@0: // stage 5 michael@0: step1[0] = step2[0] + step2[3]; michael@0: step1[1] = step2[1] + step2[2]; michael@0: step1[2] = step2[1] - step2[2]; michael@0: step1[3] = step2[0] - step2[3]; michael@0: step1[4] = step2[4]; michael@0: temp1 = (step2[6] - step2[5]) * cospi_16_64; michael@0: temp2 = (step2[5] + step2[6]) * cospi_16_64; michael@0: step1[5] = dct_const_round_shift(temp1); michael@0: step1[6] = dct_const_round_shift(temp2); michael@0: step1[7] = step2[7]; michael@0: michael@0: step1[8] = step2[8] + step2[11]; michael@0: step1[9] = step2[9] + step2[10]; michael@0: step1[10] = step2[9] - step2[10]; michael@0: step1[11] = step2[8] - step2[11]; michael@0: step1[12] = -step2[12] + step2[15]; michael@0: step1[13] = -step2[13] + step2[14]; michael@0: step1[14] = step2[13] + step2[14]; michael@0: step1[15] = step2[12] + step2[15]; michael@0: michael@0: // stage 6 michael@0: step2[0] = step1[0] + step1[7]; michael@0: step2[1] = step1[1] + step1[6]; michael@0: step2[2] = step1[2] + step1[5]; michael@0: step2[3] = step1[3] + step1[4]; michael@0: step2[4] = step1[3] - step1[4]; michael@0: step2[5] = step1[2] - step1[5]; michael@0: step2[6] = step1[1] - step1[6]; michael@0: step2[7] = step1[0] - step1[7]; michael@0: step2[8] = step1[8]; michael@0: step2[9] = step1[9]; michael@0: temp1 = (-step1[10] + step1[13]) * cospi_16_64; michael@0: temp2 = (step1[10] + step1[13]) * cospi_16_64; michael@0: step2[10] = dct_const_round_shift(temp1); michael@0: step2[13] = dct_const_round_shift(temp2); michael@0: temp1 = (-step1[11] + step1[12]) * cospi_16_64; michael@0: temp2 = (step1[11] + step1[12]) * cospi_16_64; michael@0: step2[11] = dct_const_round_shift(temp1); michael@0: step2[12] = dct_const_round_shift(temp2); michael@0: step2[14] = step1[14]; michael@0: step2[15] = step1[15]; michael@0: michael@0: // stage 7 michael@0: output[0] = step2[0] + step2[15]; michael@0: output[1] = step2[1] + step2[14]; michael@0: output[2] = step2[2] + step2[13]; michael@0: output[3] = step2[3] + step2[12]; michael@0: output[4] = step2[4] + step2[11]; michael@0: output[5] = step2[5] + step2[10]; michael@0: output[6] = step2[6] + step2[9]; michael@0: output[7] = step2[7] + step2[8]; michael@0: output[8] = step2[7] - step2[8]; michael@0: output[9] = step2[6] - step2[9]; michael@0: output[10] = step2[5] - step2[10]; michael@0: output[11] = step2[4] - step2[11]; michael@0: output[12] = step2[3] - step2[12]; michael@0: output[13] = step2[2] - step2[13]; michael@0: output[14] = step2[1] - step2[14]; michael@0: output[15] = step2[0] - step2[15]; michael@0: } michael@0: michael@0: void vp9_idct16x16_256_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int16_t out[16 * 16]; michael@0: int16_t *outptr = out; michael@0: int i, j; michael@0: int16_t temp_in[16], temp_out[16]; michael@0: michael@0: // First transform rows michael@0: for (i = 0; i < 16; ++i) { michael@0: idct16_1d(input, outptr); michael@0: input += 16; michael@0: outptr += 16; michael@0: } michael@0: michael@0: // Then transform columns michael@0: for (i = 0; i < 16; ++i) { michael@0: for (j = 0; j < 16; ++j) michael@0: temp_in[j] = out[j * 16 + i]; michael@0: idct16_1d(temp_in, temp_out); michael@0: for (j = 0; j < 16; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 6) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: static void iadst16_1d(const int16_t *input, int16_t *output) { michael@0: int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15; michael@0: michael@0: int x0 = input[15]; michael@0: int x1 = input[0]; michael@0: int x2 = input[13]; michael@0: int x3 = input[2]; michael@0: int x4 = input[11]; michael@0: int x5 = input[4]; michael@0: int x6 = input[9]; michael@0: int x7 = input[6]; michael@0: int x8 = input[7]; michael@0: int x9 = input[8]; michael@0: int x10 = input[5]; michael@0: int x11 = input[10]; michael@0: int x12 = input[3]; michael@0: int x13 = input[12]; michael@0: int x14 = input[1]; michael@0: int x15 = input[14]; michael@0: michael@0: if (!(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 michael@0: | x9 | x10 | x11 | x12 | x13 | x14 | x15)) { michael@0: output[0] = output[1] = output[2] = output[3] = output[4] michael@0: = output[5] = output[6] = output[7] = output[8] michael@0: = output[9] = output[10] = output[11] = output[12] michael@0: = output[13] = output[14] = output[15] = 0; michael@0: return; michael@0: } michael@0: michael@0: // stage 1 michael@0: s0 = x0 * cospi_1_64 + x1 * cospi_31_64; michael@0: s1 = x0 * cospi_31_64 - x1 * cospi_1_64; michael@0: s2 = x2 * cospi_5_64 + x3 * cospi_27_64; michael@0: s3 = x2 * cospi_27_64 - x3 * cospi_5_64; michael@0: s4 = x4 * cospi_9_64 + x5 * cospi_23_64; michael@0: s5 = x4 * cospi_23_64 - x5 * cospi_9_64; michael@0: s6 = x6 * cospi_13_64 + x7 * cospi_19_64; michael@0: s7 = x6 * cospi_19_64 - x7 * cospi_13_64; michael@0: s8 = x8 * cospi_17_64 + x9 * cospi_15_64; michael@0: s9 = x8 * cospi_15_64 - x9 * cospi_17_64; michael@0: s10 = x10 * cospi_21_64 + x11 * cospi_11_64; michael@0: s11 = x10 * cospi_11_64 - x11 * cospi_21_64; michael@0: s12 = x12 * cospi_25_64 + x13 * cospi_7_64; michael@0: s13 = x12 * cospi_7_64 - x13 * cospi_25_64; michael@0: s14 = x14 * cospi_29_64 + x15 * cospi_3_64; michael@0: s15 = x14 * cospi_3_64 - x15 * cospi_29_64; michael@0: michael@0: x0 = dct_const_round_shift(s0 + s8); michael@0: x1 = dct_const_round_shift(s1 + s9); michael@0: x2 = dct_const_round_shift(s2 + s10); michael@0: x3 = dct_const_round_shift(s3 + s11); michael@0: x4 = dct_const_round_shift(s4 + s12); michael@0: x5 = dct_const_round_shift(s5 + s13); michael@0: x6 = dct_const_round_shift(s6 + s14); michael@0: x7 = dct_const_round_shift(s7 + s15); michael@0: x8 = dct_const_round_shift(s0 - s8); michael@0: x9 = dct_const_round_shift(s1 - s9); michael@0: x10 = dct_const_round_shift(s2 - s10); michael@0: x11 = dct_const_round_shift(s3 - s11); michael@0: x12 = dct_const_round_shift(s4 - s12); michael@0: x13 = dct_const_round_shift(s5 - s13); michael@0: x14 = dct_const_round_shift(s6 - s14); michael@0: x15 = dct_const_round_shift(s7 - s15); michael@0: michael@0: // stage 2 michael@0: s0 = x0; michael@0: s1 = x1; michael@0: s2 = x2; michael@0: s3 = x3; michael@0: s4 = x4; michael@0: s5 = x5; michael@0: s6 = x6; michael@0: s7 = x7; michael@0: s8 = x8 * cospi_4_64 + x9 * cospi_28_64; michael@0: s9 = x8 * cospi_28_64 - x9 * cospi_4_64; michael@0: s10 = x10 * cospi_20_64 + x11 * cospi_12_64; michael@0: s11 = x10 * cospi_12_64 - x11 * cospi_20_64; michael@0: s12 = - x12 * cospi_28_64 + x13 * cospi_4_64; michael@0: s13 = x12 * cospi_4_64 + x13 * cospi_28_64; michael@0: s14 = - x14 * cospi_12_64 + x15 * cospi_20_64; michael@0: s15 = x14 * cospi_20_64 + x15 * cospi_12_64; michael@0: michael@0: x0 = s0 + s4; michael@0: x1 = s1 + s5; michael@0: x2 = s2 + s6; michael@0: x3 = s3 + s7; michael@0: x4 = s0 - s4; michael@0: x5 = s1 - s5; michael@0: x6 = s2 - s6; michael@0: x7 = s3 - s7; michael@0: x8 = dct_const_round_shift(s8 + s12); michael@0: x9 = dct_const_round_shift(s9 + s13); michael@0: x10 = dct_const_round_shift(s10 + s14); michael@0: x11 = dct_const_round_shift(s11 + s15); michael@0: x12 = dct_const_round_shift(s8 - s12); michael@0: x13 = dct_const_round_shift(s9 - s13); michael@0: x14 = dct_const_round_shift(s10 - s14); michael@0: x15 = dct_const_round_shift(s11 - s15); michael@0: michael@0: // stage 3 michael@0: s0 = x0; michael@0: s1 = x1; michael@0: s2 = x2; michael@0: s3 = x3; michael@0: s4 = x4 * cospi_8_64 + x5 * cospi_24_64; michael@0: s5 = x4 * cospi_24_64 - x5 * cospi_8_64; michael@0: s6 = - x6 * cospi_24_64 + x7 * cospi_8_64; michael@0: s7 = x6 * cospi_8_64 + x7 * cospi_24_64; michael@0: s8 = x8; michael@0: s9 = x9; michael@0: s10 = x10; michael@0: s11 = x11; michael@0: s12 = x12 * cospi_8_64 + x13 * cospi_24_64; michael@0: s13 = x12 * cospi_24_64 - x13 * cospi_8_64; michael@0: s14 = - x14 * cospi_24_64 + x15 * cospi_8_64; michael@0: s15 = x14 * cospi_8_64 + x15 * cospi_24_64; michael@0: michael@0: x0 = s0 + s2; michael@0: x1 = s1 + s3; michael@0: x2 = s0 - s2; michael@0: x3 = s1 - s3; michael@0: x4 = dct_const_round_shift(s4 + s6); michael@0: x5 = dct_const_round_shift(s5 + s7); michael@0: x6 = dct_const_round_shift(s4 - s6); michael@0: x7 = dct_const_round_shift(s5 - s7); michael@0: x8 = s8 + s10; michael@0: x9 = s9 + s11; michael@0: x10 = s8 - s10; michael@0: x11 = s9 - s11; michael@0: x12 = dct_const_round_shift(s12 + s14); michael@0: x13 = dct_const_round_shift(s13 + s15); michael@0: x14 = dct_const_round_shift(s12 - s14); michael@0: x15 = dct_const_round_shift(s13 - s15); michael@0: michael@0: // stage 4 michael@0: s2 = (- cospi_16_64) * (x2 + x3); michael@0: s3 = cospi_16_64 * (x2 - x3); michael@0: s6 = cospi_16_64 * (x6 + x7); michael@0: s7 = cospi_16_64 * (- x6 + x7); michael@0: s10 = cospi_16_64 * (x10 + x11); michael@0: s11 = cospi_16_64 * (- x10 + x11); michael@0: s14 = (- cospi_16_64) * (x14 + x15); michael@0: s15 = cospi_16_64 * (x14 - x15); michael@0: michael@0: x2 = dct_const_round_shift(s2); michael@0: x3 = dct_const_round_shift(s3); michael@0: x6 = dct_const_round_shift(s6); michael@0: x7 = dct_const_round_shift(s7); michael@0: x10 = dct_const_round_shift(s10); michael@0: x11 = dct_const_round_shift(s11); michael@0: x14 = dct_const_round_shift(s14); michael@0: x15 = dct_const_round_shift(s15); michael@0: michael@0: output[0] = x0; michael@0: output[1] = -x8; michael@0: output[2] = x12; michael@0: output[3] = -x4; michael@0: output[4] = x6; michael@0: output[5] = x14; michael@0: output[6] = x10; michael@0: output[7] = x2; michael@0: output[8] = x3; michael@0: output[9] = x11; michael@0: output[10] = x15; michael@0: output[11] = x7; michael@0: output[12] = x5; michael@0: output[13] = -x13; michael@0: output[14] = x9; michael@0: output[15] = -x1; michael@0: } michael@0: michael@0: static const transform_2d IHT_16[] = { michael@0: { idct16_1d, idct16_1d }, // DCT_DCT = 0 michael@0: { iadst16_1d, idct16_1d }, // ADST_DCT = 1 michael@0: { idct16_1d, iadst16_1d }, // DCT_ADST = 2 michael@0: { iadst16_1d, iadst16_1d } // ADST_ADST = 3 michael@0: }; michael@0: michael@0: void vp9_iht16x16_256_add_c(const int16_t *input, uint8_t *dest, int stride, michael@0: int tx_type) { michael@0: int i, j; michael@0: int16_t out[16 * 16]; michael@0: int16_t *outptr = out; michael@0: int16_t temp_in[16], temp_out[16]; michael@0: const transform_2d ht = IHT_16[tx_type]; michael@0: michael@0: // Rows michael@0: for (i = 0; i < 16; ++i) { michael@0: ht.rows(input, outptr); michael@0: input += 16; michael@0: outptr += 16; michael@0: } michael@0: michael@0: // Columns michael@0: for (i = 0; i < 16; ++i) { michael@0: for (j = 0; j < 16; ++j) michael@0: temp_in[j] = out[j * 16 + i]; michael@0: ht.cols(temp_in, temp_out); michael@0: for (j = 0; j < 16; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 6) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct16x16_10_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int16_t out[16 * 16] = { 0 }; michael@0: int16_t *outptr = out; michael@0: int i, j; michael@0: int16_t temp_in[16], temp_out[16]; michael@0: michael@0: // First transform rows. Since all non-zero dct coefficients are in michael@0: // upper-left 4x4 area, we only need to calculate first 4 rows here. michael@0: for (i = 0; i < 4; ++i) { michael@0: idct16_1d(input, outptr); michael@0: input += 16; michael@0: outptr += 16; michael@0: } michael@0: michael@0: // Then transform columns michael@0: for (i = 0; i < 16; ++i) { michael@0: for (j = 0; j < 16; ++j) michael@0: temp_in[j] = out[j*16 + i]; michael@0: idct16_1d(temp_in, temp_out); michael@0: for (j = 0; j < 16; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 6) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct16x16_1_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int i, j; michael@0: int a1; michael@0: int16_t out = dct_const_round_shift(input[0] * cospi_16_64); michael@0: out = dct_const_round_shift(out * cospi_16_64); michael@0: a1 = ROUND_POWER_OF_TWO(out, 6); michael@0: for (j = 0; j < 16; ++j) { michael@0: for (i = 0; i < 16; ++i) michael@0: dest[i] = clip_pixel(dest[i] + a1); michael@0: dest += stride; michael@0: } michael@0: } michael@0: michael@0: static void idct32_1d(const int16_t *input, int16_t *output) { michael@0: int16_t step1[32], step2[32]; michael@0: int temp1, temp2; michael@0: michael@0: // stage 1 michael@0: step1[0] = input[0]; michael@0: step1[1] = input[16]; michael@0: step1[2] = input[8]; michael@0: step1[3] = input[24]; michael@0: step1[4] = input[4]; michael@0: step1[5] = input[20]; michael@0: step1[6] = input[12]; michael@0: step1[7] = input[28]; michael@0: step1[8] = input[2]; michael@0: step1[9] = input[18]; michael@0: step1[10] = input[10]; michael@0: step1[11] = input[26]; michael@0: step1[12] = input[6]; michael@0: step1[13] = input[22]; michael@0: step1[14] = input[14]; michael@0: step1[15] = input[30]; michael@0: michael@0: temp1 = input[1] * cospi_31_64 - input[31] * cospi_1_64; michael@0: temp2 = input[1] * cospi_1_64 + input[31] * cospi_31_64; michael@0: step1[16] = dct_const_round_shift(temp1); michael@0: step1[31] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = input[17] * cospi_15_64 - input[15] * cospi_17_64; michael@0: temp2 = input[17] * cospi_17_64 + input[15] * cospi_15_64; michael@0: step1[17] = dct_const_round_shift(temp1); michael@0: step1[30] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = input[9] * cospi_23_64 - input[23] * cospi_9_64; michael@0: temp2 = input[9] * cospi_9_64 + input[23] * cospi_23_64; michael@0: step1[18] = dct_const_round_shift(temp1); michael@0: step1[29] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = input[25] * cospi_7_64 - input[7] * cospi_25_64; michael@0: temp2 = input[25] * cospi_25_64 + input[7] * cospi_7_64; michael@0: step1[19] = dct_const_round_shift(temp1); michael@0: step1[28] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = input[5] * cospi_27_64 - input[27] * cospi_5_64; michael@0: temp2 = input[5] * cospi_5_64 + input[27] * cospi_27_64; michael@0: step1[20] = dct_const_round_shift(temp1); michael@0: step1[27] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = input[21] * cospi_11_64 - input[11] * cospi_21_64; michael@0: temp2 = input[21] * cospi_21_64 + input[11] * cospi_11_64; michael@0: step1[21] = dct_const_round_shift(temp1); michael@0: step1[26] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = input[13] * cospi_19_64 - input[19] * cospi_13_64; michael@0: temp2 = input[13] * cospi_13_64 + input[19] * cospi_19_64; michael@0: step1[22] = dct_const_round_shift(temp1); michael@0: step1[25] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = input[29] * cospi_3_64 - input[3] * cospi_29_64; michael@0: temp2 = input[29] * cospi_29_64 + input[3] * cospi_3_64; michael@0: step1[23] = dct_const_round_shift(temp1); michael@0: step1[24] = dct_const_round_shift(temp2); michael@0: michael@0: // stage 2 michael@0: step2[0] = step1[0]; michael@0: step2[1] = step1[1]; michael@0: step2[2] = step1[2]; michael@0: step2[3] = step1[3]; michael@0: step2[4] = step1[4]; michael@0: step2[5] = step1[5]; michael@0: step2[6] = step1[6]; michael@0: step2[7] = step1[7]; michael@0: michael@0: temp1 = step1[8] * cospi_30_64 - step1[15] * cospi_2_64; michael@0: temp2 = step1[8] * cospi_2_64 + step1[15] * cospi_30_64; michael@0: step2[8] = dct_const_round_shift(temp1); michael@0: step2[15] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = step1[9] * cospi_14_64 - step1[14] * cospi_18_64; michael@0: temp2 = step1[9] * cospi_18_64 + step1[14] * cospi_14_64; michael@0: step2[9] = dct_const_round_shift(temp1); michael@0: step2[14] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = step1[10] * cospi_22_64 - step1[13] * cospi_10_64; michael@0: temp2 = step1[10] * cospi_10_64 + step1[13] * cospi_22_64; michael@0: step2[10] = dct_const_round_shift(temp1); michael@0: step2[13] = dct_const_round_shift(temp2); michael@0: michael@0: temp1 = step1[11] * cospi_6_64 - step1[12] * cospi_26_64; michael@0: temp2 = step1[11] * cospi_26_64 + step1[12] * cospi_6_64; michael@0: step2[11] = dct_const_round_shift(temp1); michael@0: step2[12] = dct_const_round_shift(temp2); michael@0: michael@0: step2[16] = step1[16] + step1[17]; michael@0: step2[17] = step1[16] - step1[17]; michael@0: step2[18] = -step1[18] + step1[19]; michael@0: step2[19] = step1[18] + step1[19]; michael@0: step2[20] = step1[20] + step1[21]; michael@0: step2[21] = step1[20] - step1[21]; michael@0: step2[22] = -step1[22] + step1[23]; michael@0: step2[23] = step1[22] + step1[23]; michael@0: step2[24] = step1[24] + step1[25]; michael@0: step2[25] = step1[24] - step1[25]; michael@0: step2[26] = -step1[26] + step1[27]; michael@0: step2[27] = step1[26] + step1[27]; michael@0: step2[28] = step1[28] + step1[29]; michael@0: step2[29] = step1[28] - step1[29]; michael@0: step2[30] = -step1[30] + step1[31]; michael@0: step2[31] = step1[30] + step1[31]; michael@0: michael@0: // stage 3 michael@0: step1[0] = step2[0]; michael@0: step1[1] = step2[1]; michael@0: step1[2] = step2[2]; michael@0: step1[3] = step2[3]; michael@0: michael@0: temp1 = step2[4] * cospi_28_64 - step2[7] * cospi_4_64; michael@0: temp2 = step2[4] * cospi_4_64 + step2[7] * cospi_28_64; michael@0: step1[4] = dct_const_round_shift(temp1); michael@0: step1[7] = dct_const_round_shift(temp2); michael@0: temp1 = step2[5] * cospi_12_64 - step2[6] * cospi_20_64; michael@0: temp2 = step2[5] * cospi_20_64 + step2[6] * cospi_12_64; michael@0: step1[5] = dct_const_round_shift(temp1); michael@0: step1[6] = dct_const_round_shift(temp2); michael@0: michael@0: step1[8] = step2[8] + step2[9]; michael@0: step1[9] = step2[8] - step2[9]; michael@0: step1[10] = -step2[10] + step2[11]; michael@0: step1[11] = step2[10] + step2[11]; michael@0: step1[12] = step2[12] + step2[13]; michael@0: step1[13] = step2[12] - step2[13]; michael@0: step1[14] = -step2[14] + step2[15]; michael@0: step1[15] = step2[14] + step2[15]; michael@0: michael@0: step1[16] = step2[16]; michael@0: step1[31] = step2[31]; michael@0: temp1 = -step2[17] * cospi_4_64 + step2[30] * cospi_28_64; michael@0: temp2 = step2[17] * cospi_28_64 + step2[30] * cospi_4_64; michael@0: step1[17] = dct_const_round_shift(temp1); michael@0: step1[30] = dct_const_round_shift(temp2); michael@0: temp1 = -step2[18] * cospi_28_64 - step2[29] * cospi_4_64; michael@0: temp2 = -step2[18] * cospi_4_64 + step2[29] * cospi_28_64; michael@0: step1[18] = dct_const_round_shift(temp1); michael@0: step1[29] = dct_const_round_shift(temp2); michael@0: step1[19] = step2[19]; michael@0: step1[20] = step2[20]; michael@0: temp1 = -step2[21] * cospi_20_64 + step2[26] * cospi_12_64; michael@0: temp2 = step2[21] * cospi_12_64 + step2[26] * cospi_20_64; michael@0: step1[21] = dct_const_round_shift(temp1); michael@0: step1[26] = dct_const_round_shift(temp2); michael@0: temp1 = -step2[22] * cospi_12_64 - step2[25] * cospi_20_64; michael@0: temp2 = -step2[22] * cospi_20_64 + step2[25] * cospi_12_64; michael@0: step1[22] = dct_const_round_shift(temp1); michael@0: step1[25] = dct_const_round_shift(temp2); michael@0: step1[23] = step2[23]; michael@0: step1[24] = step2[24]; michael@0: step1[27] = step2[27]; michael@0: step1[28] = step2[28]; michael@0: michael@0: // stage 4 michael@0: temp1 = (step1[0] + step1[1]) * cospi_16_64; michael@0: temp2 = (step1[0] - step1[1]) * cospi_16_64; michael@0: step2[0] = dct_const_round_shift(temp1); michael@0: step2[1] = dct_const_round_shift(temp2); michael@0: temp1 = step1[2] * cospi_24_64 - step1[3] * cospi_8_64; michael@0: temp2 = step1[2] * cospi_8_64 + step1[3] * cospi_24_64; michael@0: step2[2] = dct_const_round_shift(temp1); michael@0: step2[3] = dct_const_round_shift(temp2); michael@0: step2[4] = step1[4] + step1[5]; michael@0: step2[5] = step1[4] - step1[5]; michael@0: step2[6] = -step1[6] + step1[7]; michael@0: step2[7] = step1[6] + step1[7]; michael@0: michael@0: step2[8] = step1[8]; michael@0: step2[15] = step1[15]; michael@0: temp1 = -step1[9] * cospi_8_64 + step1[14] * cospi_24_64; michael@0: temp2 = step1[9] * cospi_24_64 + step1[14] * cospi_8_64; michael@0: step2[9] = dct_const_round_shift(temp1); michael@0: step2[14] = dct_const_round_shift(temp2); michael@0: temp1 = -step1[10] * cospi_24_64 - step1[13] * cospi_8_64; michael@0: temp2 = -step1[10] * cospi_8_64 + step1[13] * cospi_24_64; michael@0: step2[10] = dct_const_round_shift(temp1); michael@0: step2[13] = dct_const_round_shift(temp2); michael@0: step2[11] = step1[11]; michael@0: step2[12] = step1[12]; michael@0: michael@0: step2[16] = step1[16] + step1[19]; michael@0: step2[17] = step1[17] + step1[18]; michael@0: step2[18] = step1[17] - step1[18]; michael@0: step2[19] = step1[16] - step1[19]; michael@0: step2[20] = -step1[20] + step1[23]; michael@0: step2[21] = -step1[21] + step1[22]; michael@0: step2[22] = step1[21] + step1[22]; michael@0: step2[23] = step1[20] + step1[23]; michael@0: michael@0: step2[24] = step1[24] + step1[27]; michael@0: step2[25] = step1[25] + step1[26]; michael@0: step2[26] = step1[25] - step1[26]; michael@0: step2[27] = step1[24] - step1[27]; michael@0: step2[28] = -step1[28] + step1[31]; michael@0: step2[29] = -step1[29] + step1[30]; michael@0: step2[30] = step1[29] + step1[30]; michael@0: step2[31] = step1[28] + step1[31]; michael@0: michael@0: // stage 5 michael@0: step1[0] = step2[0] + step2[3]; michael@0: step1[1] = step2[1] + step2[2]; michael@0: step1[2] = step2[1] - step2[2]; michael@0: step1[3] = step2[0] - step2[3]; michael@0: step1[4] = step2[4]; michael@0: temp1 = (step2[6] - step2[5]) * cospi_16_64; michael@0: temp2 = (step2[5] + step2[6]) * cospi_16_64; michael@0: step1[5] = dct_const_round_shift(temp1); michael@0: step1[6] = dct_const_round_shift(temp2); michael@0: step1[7] = step2[7]; michael@0: michael@0: step1[8] = step2[8] + step2[11]; michael@0: step1[9] = step2[9] + step2[10]; michael@0: step1[10] = step2[9] - step2[10]; michael@0: step1[11] = step2[8] - step2[11]; michael@0: step1[12] = -step2[12] + step2[15]; michael@0: step1[13] = -step2[13] + step2[14]; michael@0: step1[14] = step2[13] + step2[14]; michael@0: step1[15] = step2[12] + step2[15]; michael@0: michael@0: step1[16] = step2[16]; michael@0: step1[17] = step2[17]; michael@0: temp1 = -step2[18] * cospi_8_64 + step2[29] * cospi_24_64; michael@0: temp2 = step2[18] * cospi_24_64 + step2[29] * cospi_8_64; michael@0: step1[18] = dct_const_round_shift(temp1); michael@0: step1[29] = dct_const_round_shift(temp2); michael@0: temp1 = -step2[19] * cospi_8_64 + step2[28] * cospi_24_64; michael@0: temp2 = step2[19] * cospi_24_64 + step2[28] * cospi_8_64; michael@0: step1[19] = dct_const_round_shift(temp1); michael@0: step1[28] = dct_const_round_shift(temp2); michael@0: temp1 = -step2[20] * cospi_24_64 - step2[27] * cospi_8_64; michael@0: temp2 = -step2[20] * cospi_8_64 + step2[27] * cospi_24_64; michael@0: step1[20] = dct_const_round_shift(temp1); michael@0: step1[27] = dct_const_round_shift(temp2); michael@0: temp1 = -step2[21] * cospi_24_64 - step2[26] * cospi_8_64; michael@0: temp2 = -step2[21] * cospi_8_64 + step2[26] * cospi_24_64; michael@0: step1[21] = dct_const_round_shift(temp1); michael@0: step1[26] = dct_const_round_shift(temp2); michael@0: step1[22] = step2[22]; michael@0: step1[23] = step2[23]; michael@0: step1[24] = step2[24]; michael@0: step1[25] = step2[25]; michael@0: step1[30] = step2[30]; michael@0: step1[31] = step2[31]; michael@0: michael@0: // stage 6 michael@0: step2[0] = step1[0] + step1[7]; michael@0: step2[1] = step1[1] + step1[6]; michael@0: step2[2] = step1[2] + step1[5]; michael@0: step2[3] = step1[3] + step1[4]; michael@0: step2[4] = step1[3] - step1[4]; michael@0: step2[5] = step1[2] - step1[5]; michael@0: step2[6] = step1[1] - step1[6]; michael@0: step2[7] = step1[0] - step1[7]; michael@0: step2[8] = step1[8]; michael@0: step2[9] = step1[9]; michael@0: temp1 = (-step1[10] + step1[13]) * cospi_16_64; michael@0: temp2 = (step1[10] + step1[13]) * cospi_16_64; michael@0: step2[10] = dct_const_round_shift(temp1); michael@0: step2[13] = dct_const_round_shift(temp2); michael@0: temp1 = (-step1[11] + step1[12]) * cospi_16_64; michael@0: temp2 = (step1[11] + step1[12]) * cospi_16_64; michael@0: step2[11] = dct_const_round_shift(temp1); michael@0: step2[12] = dct_const_round_shift(temp2); michael@0: step2[14] = step1[14]; michael@0: step2[15] = step1[15]; michael@0: michael@0: step2[16] = step1[16] + step1[23]; michael@0: step2[17] = step1[17] + step1[22]; michael@0: step2[18] = step1[18] + step1[21]; michael@0: step2[19] = step1[19] + step1[20]; michael@0: step2[20] = step1[19] - step1[20]; michael@0: step2[21] = step1[18] - step1[21]; michael@0: step2[22] = step1[17] - step1[22]; michael@0: step2[23] = step1[16] - step1[23]; michael@0: michael@0: step2[24] = -step1[24] + step1[31]; michael@0: step2[25] = -step1[25] + step1[30]; michael@0: step2[26] = -step1[26] + step1[29]; michael@0: step2[27] = -step1[27] + step1[28]; michael@0: step2[28] = step1[27] + step1[28]; michael@0: step2[29] = step1[26] + step1[29]; michael@0: step2[30] = step1[25] + step1[30]; michael@0: step2[31] = step1[24] + step1[31]; michael@0: michael@0: // stage 7 michael@0: step1[0] = step2[0] + step2[15]; michael@0: step1[1] = step2[1] + step2[14]; michael@0: step1[2] = step2[2] + step2[13]; michael@0: step1[3] = step2[3] + step2[12]; michael@0: step1[4] = step2[4] + step2[11]; michael@0: step1[5] = step2[5] + step2[10]; michael@0: step1[6] = step2[6] + step2[9]; michael@0: step1[7] = step2[7] + step2[8]; michael@0: step1[8] = step2[7] - step2[8]; michael@0: step1[9] = step2[6] - step2[9]; michael@0: step1[10] = step2[5] - step2[10]; michael@0: step1[11] = step2[4] - step2[11]; michael@0: step1[12] = step2[3] - step2[12]; michael@0: step1[13] = step2[2] - step2[13]; michael@0: step1[14] = step2[1] - step2[14]; michael@0: step1[15] = step2[0] - step2[15]; michael@0: michael@0: step1[16] = step2[16]; michael@0: step1[17] = step2[17]; michael@0: step1[18] = step2[18]; michael@0: step1[19] = step2[19]; michael@0: temp1 = (-step2[20] + step2[27]) * cospi_16_64; michael@0: temp2 = (step2[20] + step2[27]) * cospi_16_64; michael@0: step1[20] = dct_const_round_shift(temp1); michael@0: step1[27] = dct_const_round_shift(temp2); michael@0: temp1 = (-step2[21] + step2[26]) * cospi_16_64; michael@0: temp2 = (step2[21] + step2[26]) * cospi_16_64; michael@0: step1[21] = dct_const_round_shift(temp1); michael@0: step1[26] = dct_const_round_shift(temp2); michael@0: temp1 = (-step2[22] + step2[25]) * cospi_16_64; michael@0: temp2 = (step2[22] + step2[25]) * cospi_16_64; michael@0: step1[22] = dct_const_round_shift(temp1); michael@0: step1[25] = dct_const_round_shift(temp2); michael@0: temp1 = (-step2[23] + step2[24]) * cospi_16_64; michael@0: temp2 = (step2[23] + step2[24]) * cospi_16_64; michael@0: step1[23] = dct_const_round_shift(temp1); michael@0: step1[24] = dct_const_round_shift(temp2); michael@0: step1[28] = step2[28]; michael@0: step1[29] = step2[29]; michael@0: step1[30] = step2[30]; michael@0: step1[31] = step2[31]; michael@0: michael@0: // final stage michael@0: output[0] = step1[0] + step1[31]; michael@0: output[1] = step1[1] + step1[30]; michael@0: output[2] = step1[2] + step1[29]; michael@0: output[3] = step1[3] + step1[28]; michael@0: output[4] = step1[4] + step1[27]; michael@0: output[5] = step1[5] + step1[26]; michael@0: output[6] = step1[6] + step1[25]; michael@0: output[7] = step1[7] + step1[24]; michael@0: output[8] = step1[8] + step1[23]; michael@0: output[9] = step1[9] + step1[22]; michael@0: output[10] = step1[10] + step1[21]; michael@0: output[11] = step1[11] + step1[20]; michael@0: output[12] = step1[12] + step1[19]; michael@0: output[13] = step1[13] + step1[18]; michael@0: output[14] = step1[14] + step1[17]; michael@0: output[15] = step1[15] + step1[16]; michael@0: output[16] = step1[15] - step1[16]; michael@0: output[17] = step1[14] - step1[17]; michael@0: output[18] = step1[13] - step1[18]; michael@0: output[19] = step1[12] - step1[19]; michael@0: output[20] = step1[11] - step1[20]; michael@0: output[21] = step1[10] - step1[21]; michael@0: output[22] = step1[9] - step1[22]; michael@0: output[23] = step1[8] - step1[23]; michael@0: output[24] = step1[7] - step1[24]; michael@0: output[25] = step1[6] - step1[25]; michael@0: output[26] = step1[5] - step1[26]; michael@0: output[27] = step1[4] - step1[27]; michael@0: output[28] = step1[3] - step1[28]; michael@0: output[29] = step1[2] - step1[29]; michael@0: output[30] = step1[1] - step1[30]; michael@0: output[31] = step1[0] - step1[31]; michael@0: } michael@0: michael@0: void vp9_idct32x32_1024_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int16_t out[32 * 32]; michael@0: int16_t *outptr = out; michael@0: int i, j; michael@0: int16_t temp_in[32], temp_out[32]; michael@0: michael@0: // Rows michael@0: for (i = 0; i < 32; ++i) { michael@0: int16_t zero_coeff[16]; michael@0: for (j = 0; j < 16; ++j) michael@0: zero_coeff[j] = input[2 * j] | input[2 * j + 1]; michael@0: for (j = 0; j < 8; ++j) michael@0: zero_coeff[j] = zero_coeff[2 * j] | zero_coeff[2 * j + 1]; michael@0: for (j = 0; j < 4; ++j) michael@0: zero_coeff[j] = zero_coeff[2 * j] | zero_coeff[2 * j + 1]; michael@0: for (j = 0; j < 2; ++j) michael@0: zero_coeff[j] = zero_coeff[2 * j] | zero_coeff[2 * j + 1]; michael@0: michael@0: if (zero_coeff[0] | zero_coeff[1]) michael@0: idct32_1d(input, outptr); michael@0: else michael@0: vpx_memset(outptr, 0, sizeof(int16_t) * 32); michael@0: input += 32; michael@0: outptr += 32; michael@0: } michael@0: michael@0: // Columns michael@0: for (i = 0; i < 32; ++i) { michael@0: for (j = 0; j < 32; ++j) michael@0: temp_in[j] = out[j * 32 + i]; michael@0: idct32_1d(temp_in, temp_out); michael@0: for (j = 0; j < 32; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 6) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct32x32_34_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int16_t out[32 * 32] = {0}; michael@0: int16_t *outptr = out; michael@0: int i, j; michael@0: int16_t temp_in[32], temp_out[32]; michael@0: michael@0: // Rows michael@0: // only upper-left 8x8 has non-zero coeff michael@0: for (i = 0; i < 8; ++i) { michael@0: idct32_1d(input, outptr); michael@0: input += 32; michael@0: outptr += 32; michael@0: } michael@0: michael@0: // Columns michael@0: for (i = 0; i < 32; ++i) { michael@0: for (j = 0; j < 32; ++j) michael@0: temp_in[j] = out[j * 32 + i]; michael@0: idct32_1d(temp_in, temp_out); michael@0: for (j = 0; j < 32; ++j) michael@0: dest[j * stride + i] = clip_pixel(ROUND_POWER_OF_TWO(temp_out[j], 6) michael@0: + dest[j * stride + i]); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct32x32_1_add_c(const int16_t *input, uint8_t *dest, int stride) { michael@0: int i, j; michael@0: int a1; michael@0: michael@0: int16_t out = dct_const_round_shift(input[0] * cospi_16_64); michael@0: out = dct_const_round_shift(out * cospi_16_64); michael@0: a1 = ROUND_POWER_OF_TWO(out, 6); michael@0: michael@0: for (j = 0; j < 32; ++j) { michael@0: for (i = 0; i < 32; ++i) michael@0: dest[i] = clip_pixel(dest[i] + a1); michael@0: dest += stride; michael@0: } michael@0: } michael@0: michael@0: // idct michael@0: void vp9_idct4x4_add(const int16_t *input, uint8_t *dest, int stride, int eob) { michael@0: if (eob > 1) michael@0: vp9_idct4x4_16_add(input, dest, stride); michael@0: else michael@0: vp9_idct4x4_1_add(input, dest, stride); michael@0: } michael@0: michael@0: michael@0: void vp9_iwht4x4_add(const int16_t *input, uint8_t *dest, int stride, int eob) { michael@0: if (eob > 1) michael@0: vp9_iwht4x4_16_add(input, dest, stride); michael@0: else michael@0: vp9_iwht4x4_1_add(input, dest, stride); michael@0: } michael@0: michael@0: void vp9_idct8x8_add(const int16_t *input, uint8_t *dest, int stride, int eob) { michael@0: // If dc is 1, then input[0] is the reconstructed value, do not need michael@0: // dequantization. Also, when dc is 1, dc is counted in eobs, namely eobs >=1. michael@0: michael@0: // The calculation can be simplified if there are not many non-zero dct michael@0: // coefficients. Use eobs to decide what to do. michael@0: // TODO(yunqingwang): "eobs = 1" case is also handled in vp9_short_idct8x8_c. michael@0: // Combine that with code here. michael@0: if (eob) { michael@0: if (eob == 1) michael@0: // DC only DCT coefficient michael@0: vp9_idct8x8_1_add(input, dest, stride); michael@0: else if (eob <= 10) michael@0: vp9_idct8x8_10_add(input, dest, stride); michael@0: else michael@0: vp9_idct8x8_64_add(input, dest, stride); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct16x16_add(const int16_t *input, uint8_t *dest, int stride, michael@0: int eob) { michael@0: /* The calculation can be simplified if there are not many non-zero dct michael@0: * coefficients. Use eobs to separate different cases. */ michael@0: if (eob) { michael@0: if (eob == 1) michael@0: /* DC only DCT coefficient. */ michael@0: vp9_idct16x16_1_add(input, dest, stride); michael@0: else if (eob <= 10) michael@0: vp9_idct16x16_10_add(input, dest, stride); michael@0: else michael@0: vp9_idct16x16_256_add(input, dest, stride); michael@0: } michael@0: } michael@0: michael@0: void vp9_idct32x32_add(const int16_t *input, uint8_t *dest, int stride, michael@0: int eob) { michael@0: if (eob) { michael@0: if (eob == 1) michael@0: vp9_idct32x32_1_add(input, dest, stride); michael@0: else if (eob <= 34) michael@0: // non-zero coeff only in upper-left 8x8 michael@0: vp9_idct32x32_34_add(input, dest, stride); michael@0: else michael@0: vp9_idct32x32_1024_add(input, dest, stride); michael@0: } michael@0: } michael@0: michael@0: // iht michael@0: void vp9_iht4x4_add(TX_TYPE tx_type, const int16_t *input, uint8_t *dest, michael@0: int stride, int eob) { michael@0: if (tx_type == DCT_DCT) michael@0: vp9_idct4x4_add(input, dest, stride, eob); michael@0: else michael@0: vp9_iht4x4_16_add(input, dest, stride, tx_type); michael@0: } michael@0: michael@0: void vp9_iht8x8_add(TX_TYPE tx_type, const int16_t *input, uint8_t *dest, michael@0: int stride, int eob) { michael@0: if (tx_type == DCT_DCT) { michael@0: vp9_idct8x8_add(input, dest, stride, eob); michael@0: } else { michael@0: if (eob > 0) { michael@0: vp9_iht8x8_64_add(input, dest, stride, tx_type); michael@0: } michael@0: } michael@0: } michael@0: michael@0: void vp9_iht16x16_add(TX_TYPE tx_type, const int16_t *input, uint8_t *dest, michael@0: int stride, int eob) { michael@0: if (tx_type == DCT_DCT) { michael@0: vp9_idct16x16_add(input, dest, stride, eob); michael@0: } else { michael@0: if (eob > 0) { michael@0: vp9_iht16x16_256_add(input, dest, stride, tx_type); michael@0: } michael@0: } michael@0: }