Merge "VP9: Eliminate up_available and left_available"
[aom.git] / vp8 / common / idctllm.c
blobf5403c5aaf789de0483d19da641e3ba14d5df8c0
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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 */
11 #include "./vp8_rtcd.h"
13 /****************************************************************************
14 * Notes:
16 * This implementation makes use of 16 bit fixed point verio of two multiply
17 * constants:
18 * 1. sqrt(2) * cos (pi/8)
19 * 2. sqrt(2) * sin (pi/8)
20 * Becuase the first constant is bigger than 1, to maintain the same 16 bit
21 * fixed point precision as the second one, we use a trick of
22 * x * a = x + x*(a-1)
23 * so
24 * x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) *cos(pi/8)-1).
25 **************************************************************************/
26 static const int cospi8sqrt2minus1 = 20091;
27 static const int sinpi8sqrt2 = 35468;
29 void vp8_short_idct4x4llm_c(short *input, unsigned char *pred_ptr,
30 int pred_stride, unsigned char *dst_ptr,
31 int dst_stride)
33 int i;
34 int r, c;
35 int a1, b1, c1, d1;
36 short output[16];
37 short *ip = input;
38 short *op = output;
39 int temp1, temp2;
40 int shortpitch = 4;
42 for (i = 0; i < 4; i++)
44 a1 = ip[0] + ip[8];
45 b1 = ip[0] - ip[8];
47 temp1 = (ip[4] * sinpi8sqrt2) >> 16;
48 temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16);
49 c1 = temp1 - temp2;
51 temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16);
52 temp2 = (ip[12] * sinpi8sqrt2) >> 16;
53 d1 = temp1 + temp2;
55 op[shortpitch*0] = a1 + d1;
56 op[shortpitch*3] = a1 - d1;
58 op[shortpitch*1] = b1 + c1;
59 op[shortpitch*2] = b1 - c1;
61 ip++;
62 op++;
65 ip = output;
66 op = output;
68 for (i = 0; i < 4; i++)
70 a1 = ip[0] + ip[2];
71 b1 = ip[0] - ip[2];
73 temp1 = (ip[1] * sinpi8sqrt2) >> 16;
74 temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16);
75 c1 = temp1 - temp2;
77 temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16);
78 temp2 = (ip[3] * sinpi8sqrt2) >> 16;
79 d1 = temp1 + temp2;
82 op[0] = (a1 + d1 + 4) >> 3;
83 op[3] = (a1 - d1 + 4) >> 3;
85 op[1] = (b1 + c1 + 4) >> 3;
86 op[2] = (b1 - c1 + 4) >> 3;
88 ip += shortpitch;
89 op += shortpitch;
92 ip = output;
93 for (r = 0; r < 4; r++)
95 for (c = 0; c < 4; c++)
97 int a = ip[c] + pred_ptr[c] ;
99 if (a < 0)
100 a = 0;
102 if (a > 255)
103 a = 255;
105 dst_ptr[c] = (unsigned char) a ;
107 ip += 4;
108 dst_ptr += dst_stride;
109 pred_ptr += pred_stride;
113 void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr,
114 int pred_stride, unsigned char *dst_ptr,
115 int dst_stride)
117 int a1 = ((input_dc + 4) >> 3);
118 int r, c;
120 for (r = 0; r < 4; r++)
122 for (c = 0; c < 4; c++)
124 int a = a1 + pred_ptr[c] ;
126 if (a < 0)
127 a = 0;
129 if (a > 255)
130 a = 255;
132 dst_ptr[c] = (unsigned char) a ;
135 dst_ptr += dst_stride;
136 pred_ptr += pred_stride;
141 void vp8_short_inv_walsh4x4_c(short *input, short *mb_dqcoeff)
143 short output[16];
144 int i;
145 int a1, b1, c1, d1;
146 int a2, b2, c2, d2;
147 short *ip = input;
148 short *op = output;
150 for (i = 0; i < 4; i++)
152 a1 = ip[0] + ip[12];
153 b1 = ip[4] + ip[8];
154 c1 = ip[4] - ip[8];
155 d1 = ip[0] - ip[12];
157 op[0] = a1 + b1;
158 op[4] = c1 + d1;
159 op[8] = a1 - b1;
160 op[12] = d1 - c1;
161 ip++;
162 op++;
165 ip = output;
166 op = output;
168 for (i = 0; i < 4; i++)
170 a1 = ip[0] + ip[3];
171 b1 = ip[1] + ip[2];
172 c1 = ip[1] - ip[2];
173 d1 = ip[0] - ip[3];
175 a2 = a1 + b1;
176 b2 = c1 + d1;
177 c2 = a1 - b1;
178 d2 = d1 - c1;
180 op[0] = (a2 + 3) >> 3;
181 op[1] = (b2 + 3) >> 3;
182 op[2] = (c2 + 3) >> 3;
183 op[3] = (d2 + 3) >> 3;
185 ip += 4;
186 op += 4;
189 for(i = 0; i < 16; i++)
191 mb_dqcoeff[i * 16] = output[i];
195 void vp8_short_inv_walsh4x4_1_c(short *input, short *mb_dqcoeff)
197 int i;
198 int a1;
200 a1 = ((input[0] + 3) >> 3);
201 for(i = 0; i < 16; i++)
203 mb_dqcoeff[i * 16] = a1;