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 #include "./vp8_rtcd.h"
12
13 /****************************************************************************
14 * Notes:
15 *
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;
28
vp8_short_idct4x4llm_c(short * input,unsigned char * pred_ptr,int pred_stride,unsigned char * dst_ptr,int dst_stride)29 void vp8_short_idct4x4llm_c(short *input, unsigned char *pred_ptr,
30 int pred_stride, unsigned char *dst_ptr,
31 int dst_stride)
32 {
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;
41
42 for (i = 0; i < 4; i++)
43 {
44 a1 = ip[0] + ip[8];
45 b1 = ip[0] - ip[8];
46
47 temp1 = (ip[4] * sinpi8sqrt2) >> 16;
48 temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16);
49 c1 = temp1 - temp2;
50
51 temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16);
52 temp2 = (ip[12] * sinpi8sqrt2) >> 16;
53 d1 = temp1 + temp2;
54
55 op[shortpitch*0] = a1 + d1;
56 op[shortpitch*3] = a1 - d1;
57
58 op[shortpitch*1] = b1 + c1;
59 op[shortpitch*2] = b1 - c1;
60
61 ip++;
62 op++;
63 }
64
65 ip = output;
66 op = output;
67
68 for (i = 0; i < 4; i++)
69 {
70 a1 = ip[0] + ip[2];
71 b1 = ip[0] - ip[2];
72
73 temp1 = (ip[1] * sinpi8sqrt2) >> 16;
74 temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16);
75 c1 = temp1 - temp2;
76
77 temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16);
78 temp2 = (ip[3] * sinpi8sqrt2) >> 16;
79 d1 = temp1 + temp2;
80
81
82 op[0] = (a1 + d1 + 4) >> 3;
83 op[3] = (a1 - d1 + 4) >> 3;
84
85 op[1] = (b1 + c1 + 4) >> 3;
86 op[2] = (b1 - c1 + 4) >> 3;
87
88 ip += shortpitch;
89 op += shortpitch;
90 }
91
92 ip = output;
93 for (r = 0; r < 4; r++)
94 {
95 for (c = 0; c < 4; c++)
96 {
97 int a = ip[c] + pred_ptr[c] ;
98
99 if (a < 0)
100 a = 0;
101
102 if (a > 255)
103 a = 255;
104
105 dst_ptr[c] = (unsigned char) a ;
106 }
107 ip += 4;
108 dst_ptr += dst_stride;
109 pred_ptr += pred_stride;
110 }
111 }
112
vp8_dc_only_idct_add_c(short input_dc,unsigned char * pred_ptr,int pred_stride,unsigned char * dst_ptr,int dst_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)
116 {
117 int a1 = ((input_dc + 4) >> 3);
118 int r, c;
119
120 for (r = 0; r < 4; r++)
121 {
122 for (c = 0; c < 4; c++)
123 {
124 int a = a1 + pred_ptr[c] ;
125
126 if (a < 0)
127 a = 0;
128
129 if (a > 255)
130 a = 255;
131
132 dst_ptr[c] = (unsigned char) a ;
133 }
134
135 dst_ptr += dst_stride;
136 pred_ptr += pred_stride;
137 }
138
139 }
140
vp8_short_inv_walsh4x4_c(short * input,short * mb_dqcoeff)141 void vp8_short_inv_walsh4x4_c(short *input, short *mb_dqcoeff)
142 {
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;
149
150 for (i = 0; i < 4; i++)
151 {
152 a1 = ip[0] + ip[12];
153 b1 = ip[4] + ip[8];
154 c1 = ip[4] - ip[8];
155 d1 = ip[0] - ip[12];
156
157 op[0] = a1 + b1;
158 op[4] = c1 + d1;
159 op[8] = a1 - b1;
160 op[12] = d1 - c1;
161 ip++;
162 op++;
163 }
164
165 ip = output;
166 op = output;
167
168 for (i = 0; i < 4; i++)
169 {
170 a1 = ip[0] + ip[3];
171 b1 = ip[1] + ip[2];
172 c1 = ip[1] - ip[2];
173 d1 = ip[0] - ip[3];
174
175 a2 = a1 + b1;
176 b2 = c1 + d1;
177 c2 = a1 - b1;
178 d2 = d1 - c1;
179
180 op[0] = (a2 + 3) >> 3;
181 op[1] = (b2 + 3) >> 3;
182 op[2] = (c2 + 3) >> 3;
183 op[3] = (d2 + 3) >> 3;
184
185 ip += 4;
186 op += 4;
187 }
188
189 for(i = 0; i < 16; i++)
190 {
191 mb_dqcoeff[i * 16] = output[i];
192 }
193 }
194
vp8_short_inv_walsh4x4_1_c(short * input,short * mb_dqcoeff)195 void vp8_short_inv_walsh4x4_1_c(short *input, short *mb_dqcoeff)
196 {
197 int i;
198 int a1;
199
200 a1 = ((input[0] + 3) >> 3);
201 for(i = 0; i < 16; i++)
202 {
203 mb_dqcoeff[i * 16] = a1;
204 }
205 }
206