~ubuntu-branches/debian/wheezy/vlc/wheezy

« back to all changes in this revision

Viewing changes to extras/ffmpeg/libavcodec/vp3dsp.c

Tags: upstream-0.7.2.final
ImportĀ upstreamĀ versionĀ 0.7.2.final

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004 the ffmpeg project
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 */
 
18
 
 
19
/**
 
20
 * @file vp3dsp.c
 
21
 * Standard C DSP-oriented functions cribbed from the original VP3 
 
22
 * source code.
 
23
 */
 
24
 
 
25
#include "common.h"
 
26
#include "avcodec.h"
 
27
#include "dsputil.h"
 
28
#include "vp3data.h"
 
29
 
 
30
#define IdctAdjustBeforeShift 8
 
31
#define xC1S7 64277
 
32
#define xC2S6 60547
 
33
#define xC3S5 54491
 
34
#define xC4S4 46341
 
35
#define xC5S3 36410
 
36
#define xC6S2 25080
 
37
#define xC7S1 12785
 
38
 
 
39
void vp3_dsp_init_c(void)
 
40
{
 
41
    /* nop */
 
42
}
 
43
 
 
44
void vp3_idct_c(int16_t *input_data, int16_t *dequant_matrix,
 
45
    int coeff_count, int16_t *output_data)
 
46
{
 
47
    int32_t dequantized_data[64];
 
48
    int32_t *ip = dequantized_data;
 
49
    int16_t *op = output_data;
 
50
 
 
51
    int32_t A_, B_, C_, D_, _Ad, _Bd, _Cd, _Dd, E_, F_, G_, H_;
 
52
    int32_t _Ed, _Gd, _Add, _Bdd, _Fd, _Hd;
 
53
    int32_t t1, t2;
 
54
 
 
55
    int i, j;
 
56
 
 
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];
 
61
    }
 
62
 
 
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]);
 
69
            t1 >>= 16;
 
70
            t2 >>= 16;
 
71
            A_ = t1 + t2;
 
72
 
 
73
            t1 = (int32_t)(xC7S1 * ip[1]);
 
74
            t2 = (int32_t)(xC1S7 * ip[7]);
 
75
            t1 >>= 16;
 
76
            t2 >>= 16;
 
77
            B_ = t1 - t2;
 
78
 
 
79
            t1 = (int32_t)(xC3S5 * ip[3]);
 
80
            t2 = (int32_t)(xC5S3 * ip[5]);
 
81
            t1 >>= 16;
 
82
            t2 >>= 16;
 
83
            C_ = t1 + t2;
 
84
 
 
85
            t1 = (int32_t)(xC3S5 * ip[5]);
 
86
            t2 = (int32_t)(xC5S3 * ip[3]);
 
87
            t1 >>= 16;
 
88
            t2 >>= 16;
 
89
            D_ = t1 - t2;
 
90
 
 
91
 
 
92
            t1 = (int32_t)(xC4S4 * (A_ - C_));
 
93
            t1 >>= 16;
 
94
            _Ad = t1;
 
95
 
 
96
            t1 = (int32_t)(xC4S4 * (B_ - D_));
 
97
            t1 >>= 16;
 
98
            _Bd = t1;
 
99
 
 
100
 
 
101
            _Cd = A_ + C_;
 
102
            _Dd = B_ + D_;
 
103
 
 
104
            t1 = (int32_t)(xC4S4 * (ip[0] + ip[4]));
 
105
            t1 >>= 16;
 
106
            E_ = t1;
 
107
 
 
108
            t1 = (int32_t)(xC4S4 * (ip[0] - ip[4]));
 
109
            t1 >>= 16;
 
110
            F_ = t1;
 
111
 
 
112
            t1 = (int32_t)(xC2S6 * ip[2]);
 
113
            t2 = (int32_t)(xC6S2 * ip[6]);
 
114
            t1 >>= 16;
 
115
            t2 >>= 16;
 
116
            G_ = t1 + t2;
 
117
 
 
118
            t1 = (int32_t)(xC6S2 * ip[2]);
 
119
            t2 = (int32_t)(xC2S6 * ip[6]);
 
120
            t1 >>= 16;
 
121
            t2 >>= 16;
 
122
            H_ = t1 - t2;
 
123
 
 
124
 
 
125
            _Ed = E_ - G_;
 
126
            _Gd = E_ + G_;
 
127
 
 
128
            _Add = F_ + _Ad;
 
129
            _Bdd = _Bd - H_;
 
130
 
 
131
            _Fd = F_ - _Ad;
 
132
            _Hd = _Bd + H_;
 
133
 
 
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);
 
137
 
 
138
            ip[1] = (int16_t)((_Add + _Hd )  >> 0);
 
139
            ip[2] = (int16_t)((_Add - _Hd )  >> 0);
 
140
 
 
141
            ip[3] = (int16_t)((_Ed + _Dd )   >> 0);
 
142
            ip[4] = (int16_t)((_Ed - _Dd )   >> 0);
 
143
 
 
144
            ip[5] = (int16_t)((_Fd + _Bdd )  >> 0);
 
145
            ip[6] = (int16_t)((_Fd - _Bdd )  >> 0);
 
146
 
 
147
        }
 
148
 
 
149
        ip += 8;            /* next row */
 
150
    }
 
151
 
 
152
    ip = dequantized_data;
 
153
 
 
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] ) {
 
158
 
 
159
            t1 = (int32_t)(xC1S7 * ip[1*8]);
 
160
            t2 = (int32_t)(xC7S1 * ip[7*8]);
 
161
            t1 >>= 16;
 
162
            t2 >>= 16;
 
163
            A_ = t1 + t2;
 
164
 
 
165
            t1 = (int32_t)(xC7S1 * ip[1*8]);
 
166
            t2 = (int32_t)(xC1S7 * ip[7*8]);
 
167
            t1 >>= 16;
 
168
            t2 >>= 16;
 
169
            B_ = t1 - t2;
 
170
 
 
171
            t1 = (int32_t)(xC3S5 * ip[3*8]);
 
172
            t2 = (int32_t)(xC5S3 * ip[5*8]);
 
173
            t1 >>= 16;
 
174
            t2 >>= 16;
 
175
            C_ = t1 + t2;
 
176
 
 
177
            t1 = (int32_t)(xC3S5 * ip[5*8]);
 
178
            t2 = (int32_t)(xC5S3 * ip[3*8]);
 
179
            t1 >>= 16;
 
180
            t2 >>= 16;
 
181
            D_ = t1 - t2;
 
182
 
 
183
 
 
184
            t1 = (int32_t)(xC4S4 * (A_ - C_));
 
185
            t1 >>= 16;
 
186
            _Ad = t1;
 
187
 
 
188
            t1 = (int32_t)(xC4S4 * (B_ - D_));
 
189
            t1 >>= 16;
 
190
            _Bd = t1;
 
191
 
 
192
 
 
193
            _Cd = A_ + C_;
 
194
            _Dd = B_ + D_;
 
195
 
 
196
            t1 = (int32_t)(xC4S4 * (ip[0*8] + ip[4*8]));
 
197
            t1 >>= 16;
 
198
            E_ = t1;
 
199
 
 
200
            t1 = (int32_t)(xC4S4 * (ip[0*8] - ip[4*8]));
 
201
            t1 >>= 16;
 
202
            F_ = t1;
 
203
 
 
204
            t1 = (int32_t)(xC2S6 * ip[2*8]);
 
205
            t2 = (int32_t)(xC6S2 * ip[6*8]);
 
206
            t1 >>= 16;
 
207
            t2 >>= 16;
 
208
            G_ = t1 + t2;
 
209
 
 
210
            t1 = (int32_t)(xC6S2 * ip[2*8]);
 
211
            t2 = (int32_t)(xC2S6 * ip[6*8]);
 
212
            t1 >>= 16;
 
213
            t2 >>= 16;
 
214
            H_ = t1 - t2;
 
215
 
 
216
 
 
217
            _Ed = E_ - G_;
 
218
            _Gd = E_ + G_;
 
219
 
 
220
            _Add = F_ + _Ad;
 
221
            _Bdd = _Bd - H_;
 
222
 
 
223
            _Fd = F_ - _Ad;
 
224
            _Hd = _Bd + H_;
 
225
 
 
226
            _Gd += IdctAdjustBeforeShift;
 
227
            _Add += IdctAdjustBeforeShift;
 
228
            _Ed += IdctAdjustBeforeShift;
 
229
            _Fd += IdctAdjustBeforeShift;
 
230
 
 
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);
 
234
 
 
235
            op[1*8] = (int16_t)((_Add + _Hd )  >> 4);
 
236
            op[2*8] = (int16_t)((_Add - _Hd )  >> 4);
 
237
 
 
238
            op[3*8] = (int16_t)((_Ed + _Dd )   >> 4);
 
239
            op[4*8] = (int16_t)((_Ed - _Dd )   >> 4);
 
240
 
 
241
            op[5*8] = (int16_t)((_Fd + _Bdd )  >> 4);
 
242
            op[6*8] = (int16_t)((_Fd - _Bdd )  >> 4);
 
243
 
 
244
        } else {
 
245
 
 
246
            op[0*8] = 0;
 
247
            op[7*8] = 0;
 
248
            op[1*8] = 0;
 
249
            op[2*8] = 0;
 
250
            op[3*8] = 0;
 
251
            op[4*8] = 0;
 
252
            op[5*8] = 0;
 
253
            op[6*8] = 0;
 
254
        }
 
255
 
 
256
        ip++;            /* next column */
 
257
        op++;
 
258
    }
 
259
}