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: michael@0: /**************************************************************************** michael@0: * Notes: michael@0: * michael@0: * This implementation makes use of 16 bit fixed point verio of two multiply michael@0: * constants: michael@0: * 1. sqrt(2) * cos (pi/8) michael@0: * 2. sqrt(2) * sin (pi/8) michael@0: * Becuase the first constant is bigger than 1, to maintain the same 16 bit michael@0: * fixed point precision as the second one, we use a trick of michael@0: * x * a = x + x*(a-1) michael@0: * so michael@0: * x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) *cos(pi/8)-1). michael@0: **************************************************************************/ michael@0: static const int cospi8sqrt2minus1 = 20091; michael@0: static const int sinpi8sqrt2 = 35468; michael@0: michael@0: void vp8_short_idct4x4llm_c(short *input, unsigned char *pred_ptr, michael@0: int pred_stride, unsigned char *dst_ptr, michael@0: int dst_stride) michael@0: { michael@0: int i; michael@0: int r, c; michael@0: int a1, b1, c1, d1; michael@0: short output[16]; michael@0: short *ip = input; michael@0: short *op = output; michael@0: int temp1, temp2; michael@0: int shortpitch = 4; michael@0: michael@0: for (i = 0; i < 4; i++) michael@0: { michael@0: a1 = ip[0] + ip[8]; michael@0: b1 = ip[0] - ip[8]; michael@0: michael@0: temp1 = (ip[4] * sinpi8sqrt2) >> 16; michael@0: temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16); michael@0: c1 = temp1 - temp2; michael@0: michael@0: temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16); michael@0: temp2 = (ip[12] * sinpi8sqrt2) >> 16; michael@0: d1 = temp1 + temp2; michael@0: michael@0: op[shortpitch*0] = a1 + d1; michael@0: op[shortpitch*3] = a1 - d1; michael@0: michael@0: op[shortpitch*1] = b1 + c1; michael@0: op[shortpitch*2] = b1 - c1; michael@0: michael@0: ip++; michael@0: op++; michael@0: } michael@0: michael@0: ip = output; michael@0: op = output; michael@0: michael@0: for (i = 0; i < 4; i++) michael@0: { michael@0: a1 = ip[0] + ip[2]; michael@0: b1 = ip[0] - ip[2]; michael@0: michael@0: temp1 = (ip[1] * sinpi8sqrt2) >> 16; michael@0: temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16); michael@0: c1 = temp1 - temp2; michael@0: michael@0: temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16); michael@0: temp2 = (ip[3] * sinpi8sqrt2) >> 16; michael@0: d1 = temp1 + temp2; michael@0: michael@0: michael@0: op[0] = (a1 + d1 + 4) >> 3; michael@0: op[3] = (a1 - d1 + 4) >> 3; michael@0: michael@0: op[1] = (b1 + c1 + 4) >> 3; michael@0: op[2] = (b1 - c1 + 4) >> 3; michael@0: michael@0: ip += shortpitch; michael@0: op += shortpitch; michael@0: } michael@0: michael@0: ip = output; michael@0: for (r = 0; r < 4; r++) michael@0: { michael@0: for (c = 0; c < 4; c++) michael@0: { michael@0: int a = ip[c] + pred_ptr[c] ; michael@0: michael@0: if (a < 0) michael@0: a = 0; michael@0: michael@0: if (a > 255) michael@0: a = 255; michael@0: michael@0: dst_ptr[c] = (unsigned char) a ; michael@0: } michael@0: ip += 4; michael@0: dst_ptr += dst_stride; michael@0: pred_ptr += pred_stride; michael@0: } michael@0: } michael@0: michael@0: void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr, michael@0: int pred_stride, unsigned char *dst_ptr, michael@0: int dst_stride) michael@0: { michael@0: int a1 = ((input_dc + 4) >> 3); michael@0: int r, c; michael@0: michael@0: for (r = 0; r < 4; r++) michael@0: { michael@0: for (c = 0; c < 4; c++) michael@0: { michael@0: int a = a1 + pred_ptr[c] ; michael@0: michael@0: if (a < 0) michael@0: a = 0; michael@0: michael@0: if (a > 255) michael@0: a = 255; michael@0: michael@0: dst_ptr[c] = (unsigned char) a ; michael@0: } michael@0: michael@0: dst_ptr += dst_stride; michael@0: pred_ptr += pred_stride; michael@0: } michael@0: michael@0: } michael@0: michael@0: void vp8_short_inv_walsh4x4_c(short *input, short *mb_dqcoeff) michael@0: { michael@0: short output[16]; michael@0: int i; michael@0: int a1, b1, c1, d1; michael@0: int a2, b2, c2, d2; michael@0: short *ip = input; michael@0: short *op = output; michael@0: michael@0: for (i = 0; i < 4; i++) michael@0: { michael@0: a1 = ip[0] + ip[12]; michael@0: b1 = ip[4] + ip[8]; michael@0: c1 = ip[4] - ip[8]; michael@0: d1 = ip[0] - ip[12]; michael@0: michael@0: op[0] = a1 + b1; michael@0: op[4] = c1 + d1; michael@0: op[8] = a1 - b1; michael@0: op[12] = d1 - c1; michael@0: ip++; michael@0: op++; michael@0: } michael@0: michael@0: ip = output; michael@0: op = output; michael@0: michael@0: for (i = 0; i < 4; i++) michael@0: { michael@0: a1 = ip[0] + ip[3]; michael@0: b1 = ip[1] + ip[2]; michael@0: c1 = ip[1] - ip[2]; michael@0: d1 = ip[0] - ip[3]; michael@0: michael@0: a2 = a1 + b1; michael@0: b2 = c1 + d1; michael@0: c2 = a1 - b1; michael@0: d2 = d1 - c1; michael@0: michael@0: op[0] = (a2 + 3) >> 3; michael@0: op[1] = (b2 + 3) >> 3; michael@0: op[2] = (c2 + 3) >> 3; michael@0: op[3] = (d2 + 3) >> 3; michael@0: michael@0: ip += 4; michael@0: op += 4; michael@0: } michael@0: michael@0: for(i = 0; i < 16; i++) michael@0: { michael@0: mb_dqcoeff[i * 16] = output[i]; michael@0: } michael@0: } michael@0: michael@0: void vp8_short_inv_walsh4x4_1_c(short *input, short *mb_dqcoeff) michael@0: { michael@0: int i; michael@0: int a1; michael@0: michael@0: a1 = ((input[0] + 3) >> 3); michael@0: for(i = 0; i < 16; i++) michael@0: { michael@0: mb_dqcoeff[i * 16] = a1; michael@0: } michael@0: }