1 /* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 12 /**************************************************************************** 13 * Notes: 14 * 15 * This implementation makes use of 16 bit fixed point verio of two multiply 16 * constants: 17 * 1. sqrt(2) * cos (pi/8) 18 * 2. sqrt(2) * sin (pi/8) 19 * Becuase the first constant is bigger than 1, to maintain the same 16 bit 20 * fixed point precision as the second one, we use a trick of 21 * x * a = x + x*(a-1) 22 * so 23 * x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) *cos(pi/8)-1). 24 **************************************************************************/ 25 static const int cospi8sqrt2minus1 = 20091; 26 static const int sinpi8sqrt2 = 35468; 27 28 void vp8_short_idct4x4llm_c(short *input, unsigned char *pred_ptr, 29 int pred_stride, unsigned char *dst_ptr, 30 int dst_stride) 31 { 32 int i; 33 int r, c; 34 int a1, b1, c1, d1; 35 short output[16]; 36 short *ip = input; 37 short *op = output; 38 int temp1, temp2; 39 int shortpitch = 4; 40 41 for (i = 0; i < 4; i++) 42 { 43 a1 = ip[0] + ip[8]; 44 b1 = ip[0] - ip[8]; 45 46 temp1 = (ip[4] * sinpi8sqrt2) >> 16; 47 temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16); 48 c1 = temp1 - temp2; 49 50 temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16); 51 temp2 = (ip[12] * sinpi8sqrt2) >> 16; 52 d1 = temp1 + temp2; 53 54 op[shortpitch*0] = a1 + d1; 55 op[shortpitch*3] = a1 - d1; 56 57 op[shortpitch*1] = b1 + c1; 58 op[shortpitch*2] = b1 - c1; 59 60 ip++; 61 op++; 62 } 63 64 ip = output; 65 op = output; 66 67 for (i = 0; i < 4; i++) 68 { 69 a1 = ip[0] + ip[2]; 70 b1 = ip[0] - ip[2]; 71 72 temp1 = (ip[1] * sinpi8sqrt2) >> 16; 73 temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16); 74 c1 = temp1 - temp2; 75 76 temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16); 77 temp2 = (ip[3] * sinpi8sqrt2) >> 16; 78 d1 = temp1 + temp2; 79 80 81 op[0] = (a1 + d1 + 4) >> 3; 82 op[3] = (a1 - d1 + 4) >> 3; 83 84 op[1] = (b1 + c1 + 4) >> 3; 85 op[2] = (b1 - c1 + 4) >> 3; 86 87 ip += shortpitch; 88 op += shortpitch; 89 } 90 91 ip = output; 92 for (r = 0; r < 4; r++) 93 { 94 for (c = 0; c < 4; c++) 95 { 96 int a = ip[c] + pred_ptr[c] ; 97 98 if (a < 0) 99 a = 0; 100 101 if (a > 255) 102 a = 255; 103 104 dst_ptr[c] = (unsigned char) a ; 105 } 106 ip += 4; 107 dst_ptr += dst_stride; 108 pred_ptr += pred_stride; 109 } 110 } 111 112 void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr, 113 int pred_stride, unsigned char *dst_ptr, 114 int dst_stride) 115 { 116 int a1 = ((input_dc + 4) >> 3); 117 int r, c; 118 119 for (r = 0; r < 4; r++) 120 { 121 for (c = 0; c < 4; c++) 122 { 123 int a = a1 + pred_ptr[c] ; 124 125 if (a < 0) 126 a = 0; 127 128 if (a > 255) 129 a = 255; 130 131 dst_ptr[c] = (unsigned char) a ; 132 } 133 134 dst_ptr += dst_stride; 135 pred_ptr += pred_stride; 136 } 137 138 } 139 140 void vp8_short_inv_walsh4x4_c(short *input, short *mb_dqcoeff) 141 { 142 short output[16]; 143 int i; 144 int a1, b1, c1, d1; 145 int a2, b2, c2, d2; 146 short *ip = input; 147 short *op = output; 148 149 for (i = 0; i < 4; i++) 150 { 151 a1 = ip[0] + ip[12]; 152 b1 = ip[4] + ip[8]; 153 c1 = ip[4] - ip[8]; 154 d1 = ip[0] - ip[12]; 155 156 op[0] = a1 + b1; 157 op[4] = c1 + d1; 158 op[8] = a1 - b1; 159 op[12] = d1 - c1; 160 ip++; 161 op++; 162 } 163 164 ip = output; 165 op = output; 166 167 for (i = 0; i < 4; i++) 168 { 169 a1 = ip[0] + ip[3]; 170 b1 = ip[1] + ip[2]; 171 c1 = ip[1] - ip[2]; 172 d1 = ip[0] - ip[3]; 173 174 a2 = a1 + b1; 175 b2 = c1 + d1; 176 c2 = a1 - b1; 177 d2 = d1 - c1; 178 179 op[0] = (a2 + 3) >> 3; 180 op[1] = (b2 + 3) >> 3; 181 op[2] = (c2 + 3) >> 3; 182 op[3] = (d2 + 3) >> 3; 183 184 ip += 4; 185 op += 4; 186 } 187 188 for(i = 0; i < 16; i++) 189 { 190 mb_dqcoeff[i * 16] = output[i]; 191 } 192 } 193 194 void vp8_short_inv_walsh4x4_1_c(short *input, short *mb_dqcoeff) 195 { 196 int i; 197 int a1; 198 199 a1 = ((input[0] + 3) >> 3); 200 for(i = 0; i < 16; i++) 201 { 202 mb_dqcoeff[i * 16] = a1; 203 } 204 } 205