2 * Copyright (C) 2004 the ffmpeg project
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Standard C DSP-oriented functions cribbed from the original VP3
29 #define IdctAdjustBeforeShift 8
38 void vp3_dsp_init_c(void)
43 static void vp3_idct_c(int32_t *dequantized_data, int16_t *output_data)
45 int32_t *ip = dequantized_data;
46 int16_t *op = output_data;
48 int32_t A_, B_, C_, D_, _Ad, _Bd, _Cd, _Dd, E_, F_, G_, H_;
49 int32_t _Ed, _Gd, _Add, _Bdd, _Fd, _Hd;
54 /* Inverse DCT on the rows now */
55 for (i = 0; i < 8; i++) {
56 /* Check for non-zero values */
57 if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) {
58 t1 = (int32_t)(xC1S7 * ip[1]);
59 t2 = (int32_t)(xC7S1 * ip[7]);
64 t1 = (int32_t)(xC7S1 * ip[1]);
65 t2 = (int32_t)(xC1S7 * ip[7]);
70 t1 = (int32_t)(xC3S5 * ip[3]);
71 t2 = (int32_t)(xC5S3 * ip[5]);
76 t1 = (int32_t)(xC3S5 * ip[5]);
77 t2 = (int32_t)(xC5S3 * ip[3]);
83 t1 = (int32_t)(xC4S4 * (A_ - C_));
87 t1 = (int32_t)(xC4S4 * (B_ - D_));
95 t1 = (int32_t)(xC4S4 * (ip[0] + ip[4]));
99 t1 = (int32_t)(xC4S4 * (ip[0] - ip[4]));
103 t1 = (int32_t)(xC2S6 * ip[2]);
104 t2 = (int32_t)(xC6S2 * ip[6]);
109 t1 = (int32_t)(xC6S2 * ip[2]);
110 t2 = (int32_t)(xC2S6 * ip[6]);
125 /* Final sequence of operations over-write original inputs. */
126 ip[0] = (int16_t)((_Gd + _Cd ) >> 0);
127 ip[7] = (int16_t)((_Gd - _Cd ) >> 0);
129 ip[1] = (int16_t)((_Add + _Hd ) >> 0);
130 ip[2] = (int16_t)((_Add - _Hd ) >> 0);
132 ip[3] = (int16_t)((_Ed + _Dd ) >> 0);
133 ip[4] = (int16_t)((_Ed - _Dd ) >> 0);
135 ip[5] = (int16_t)((_Fd + _Bdd ) >> 0);
136 ip[6] = (int16_t)((_Fd - _Bdd ) >> 0);
140 ip += 8; /* next row */
143 ip = dequantized_data;
145 for ( i = 0; i < 8; i++) {
146 /* Check for non-zero values (bitwise or faster than ||) */
147 if ( ip[0 * 8] | ip[1 * 8] | ip[2 * 8] | ip[3 * 8] |
148 ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) {
150 t1 = (int32_t)(xC1S7 * ip[1*8]);
151 t2 = (int32_t)(xC7S1 * ip[7*8]);
156 t1 = (int32_t)(xC7S1 * ip[1*8]);
157 t2 = (int32_t)(xC1S7 * ip[7*8]);
162 t1 = (int32_t)(xC3S5 * ip[3*8]);
163 t2 = (int32_t)(xC5S3 * ip[5*8]);
168 t1 = (int32_t)(xC3S5 * ip[5*8]);
169 t2 = (int32_t)(xC5S3 * ip[3*8]);
175 t1 = (int32_t)(xC4S4 * (A_ - C_));
179 t1 = (int32_t)(xC4S4 * (B_ - D_));
187 t1 = (int32_t)(xC4S4 * (ip[0*8] + ip[4*8]));
191 t1 = (int32_t)(xC4S4 * (ip[0*8] - ip[4*8]));
195 t1 = (int32_t)(xC2S6 * ip[2*8]);
196 t2 = (int32_t)(xC6S2 * ip[6*8]);
201 t1 = (int32_t)(xC6S2 * ip[2*8]);
202 t2 = (int32_t)(xC2S6 * ip[6*8]);
217 _Gd += IdctAdjustBeforeShift;
218 _Add += IdctAdjustBeforeShift;
219 _Ed += IdctAdjustBeforeShift;
220 _Fd += IdctAdjustBeforeShift;
222 /* Final sequence of operations over-write original inputs. */
223 op[0*8] = (int16_t)((_Gd + _Cd ) >> 4);
224 op[7*8] = (int16_t)((_Gd - _Cd ) >> 4);
226 op[1*8] = (int16_t)((_Add + _Hd ) >> 4);
227 op[2*8] = (int16_t)((_Add - _Hd ) >> 4);
229 op[3*8] = (int16_t)((_Ed + _Dd ) >> 4);
230 op[4*8] = (int16_t)((_Ed - _Dd ) >> 4);
232 op[5*8] = (int16_t)((_Fd + _Bdd ) >> 4);
233 op[6*8] = (int16_t)((_Fd - _Bdd ) >> 4);
247 ip++; /* next column */
252 void vp3_idct_put_c(int16_t *input_data, int16_t *dequant_matrix,
253 int coeff_count, uint8_t *dest, int stride)
255 int32_t dequantized_data[64];
256 int16_t transformed_data[64];
260 /* de-zigzag and dequantize */
261 for (i = 0; i < coeff_count; i++) {
262 j = dezigzag_index[i];
263 dequantized_data[j] = dequant_matrix[i] * input_data[i];
266 vp3_idct_c(dequantized_data, transformed_data);
268 /* place in final output */
269 op = transformed_data;
270 for (i = 0; i < 8; i++) {
271 for (j = 0; j < 8; j++) {
277 *dest = (uint8_t)(*op + 128);
281 dest += (stride - 8);
285 void vp3_idct_add_c(int16_t *input_data, int16_t *dequant_matrix,
286 int coeff_count, uint8_t *dest, int stride)
288 int32_t dequantized_data[64];
289 int16_t transformed_data[64];
294 /* de-zigzag and dequantize */
295 for (i = 0; i < coeff_count; i++) {
296 j = dezigzag_index[i];
297 dequantized_data[j] = dequant_matrix[i] * input_data[i];
300 vp3_idct_c(dequantized_data, transformed_data);
302 /* place in final output */
303 op = transformed_data;
304 for (i = 0; i < 8; i++) {
305 for (j = 0; j < 8; j++) {
306 sample = *dest + *op;
309 else if (sample > 255)
312 *dest = (uint8_t)(sample & 0xFF);
316 dest += (stride - 8);