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
30
#define IdctAdjustBeforeShift 8
39
void vp3_dsp_init_c(void)
44
void vp3_idct_c(int16_t *input_data, int16_t *dequant_matrix,
45
int coeff_count, int16_t *output_data)
47
int32_t dequantized_data[64];
48
int32_t *ip = dequantized_data;
49
int16_t *op = output_data;
51
int32_t A_, B_, C_, D_, _Ad, _Bd, _Cd, _Dd, E_, F_, G_, H_;
52
int32_t _Ed, _Gd, _Add, _Bdd, _Fd, _Hd;
57
/* de-zigzag and dequantize */
58
for (i = 0; i < coeff_count; i++) {
59
j = dezigzag_index[i];
60
dequantized_data[j] = dequant_matrix[i] * input_data[i];
63
/* Inverse DCT on the rows now */
64
for (i = 0; i < 8; i++) {
65
/* Check for non-zero values */
66
if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) {
67
t1 = (int32_t)(xC1S7 * ip[1]);
68
t2 = (int32_t)(xC7S1 * ip[7]);
73
t1 = (int32_t)(xC7S1 * ip[1]);
74
t2 = (int32_t)(xC1S7 * ip[7]);
79
t1 = (int32_t)(xC3S5 * ip[3]);
80
t2 = (int32_t)(xC5S3 * ip[5]);
85
t1 = (int32_t)(xC3S5 * ip[5]);
86
t2 = (int32_t)(xC5S3 * ip[3]);
92
t1 = (int32_t)(xC4S4 * (A_ - C_));
96
t1 = (int32_t)(xC4S4 * (B_ - D_));
104
t1 = (int32_t)(xC4S4 * (ip[0] + ip[4]));
108
t1 = (int32_t)(xC4S4 * (ip[0] - ip[4]));
112
t1 = (int32_t)(xC2S6 * ip[2]);
113
t2 = (int32_t)(xC6S2 * ip[6]);
118
t1 = (int32_t)(xC6S2 * ip[2]);
119
t2 = (int32_t)(xC2S6 * ip[6]);
134
/* Final sequence of operations over-write original inputs. */
135
ip[0] = (int16_t)((_Gd + _Cd ) >> 0);
136
ip[7] = (int16_t)((_Gd - _Cd ) >> 0);
138
ip[1] = (int16_t)((_Add + _Hd ) >> 0);
139
ip[2] = (int16_t)((_Add - _Hd ) >> 0);
141
ip[3] = (int16_t)((_Ed + _Dd ) >> 0);
142
ip[4] = (int16_t)((_Ed - _Dd ) >> 0);
144
ip[5] = (int16_t)((_Fd + _Bdd ) >> 0);
145
ip[6] = (int16_t)((_Fd - _Bdd ) >> 0);
149
ip += 8; /* next row */
152
ip = dequantized_data;
154
for ( i = 0; i < 8; i++) {
155
/* Check for non-zero values (bitwise or faster than ||) */
156
if ( ip[0 * 8] | ip[1 * 8] | ip[2 * 8] | ip[3 * 8] |
157
ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) {
159
t1 = (int32_t)(xC1S7 * ip[1*8]);
160
t2 = (int32_t)(xC7S1 * ip[7*8]);
165
t1 = (int32_t)(xC7S1 * ip[1*8]);
166
t2 = (int32_t)(xC1S7 * ip[7*8]);
171
t1 = (int32_t)(xC3S5 * ip[3*8]);
172
t2 = (int32_t)(xC5S3 * ip[5*8]);
177
t1 = (int32_t)(xC3S5 * ip[5*8]);
178
t2 = (int32_t)(xC5S3 * ip[3*8]);
184
t1 = (int32_t)(xC4S4 * (A_ - C_));
188
t1 = (int32_t)(xC4S4 * (B_ - D_));
196
t1 = (int32_t)(xC4S4 * (ip[0*8] + ip[4*8]));
200
t1 = (int32_t)(xC4S4 * (ip[0*8] - ip[4*8]));
204
t1 = (int32_t)(xC2S6 * ip[2*8]);
205
t2 = (int32_t)(xC6S2 * ip[6*8]);
210
t1 = (int32_t)(xC6S2 * ip[2*8]);
211
t2 = (int32_t)(xC2S6 * ip[6*8]);
226
_Gd += IdctAdjustBeforeShift;
227
_Add += IdctAdjustBeforeShift;
228
_Ed += IdctAdjustBeforeShift;
229
_Fd += IdctAdjustBeforeShift;
231
/* Final sequence of operations over-write original inputs. */
232
op[0*8] = (int16_t)((_Gd + _Cd ) >> 4);
233
op[7*8] = (int16_t)((_Gd - _Cd ) >> 4);
235
op[1*8] = (int16_t)((_Add + _Hd ) >> 4);
236
op[2*8] = (int16_t)((_Add - _Hd ) >> 4);
238
op[3*8] = (int16_t)((_Ed + _Dd ) >> 4);
239
op[4*8] = (int16_t)((_Ed - _Dd ) >> 4);
241
op[5*8] = (int16_t)((_Fd + _Bdd ) >> 4);
242
op[6*8] = (int16_t)((_Fd - _Bdd ) >> 4);
256
ip++; /* next column */