~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/simple_idct.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-25 15:47:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080225154712-qvr11ekcea4c9ry8
Tags: 1.1.6-0.1ubuntu1
* Merge from debian-multimedia (LP: #120003), Ubuntu Changes:
 - For ffmpeg-related build-deps, remove cvs from package names.
 - Standards-Version 3.7.3
 - Maintainer Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
5
5
 *
6
 
 * This library is free software; you can redistribute it and/or
 
6
 * This file is part of FFmpeg.
 
7
 *
 
8
 * FFmpeg is free software; you can redistribute it and/or
7
9
 * modify it under the terms of the GNU Lesser General Public
8
10
 * License as published by the Free Software Foundation; either
9
 
 * version 2 of the License, or (at your option) any later version.
 
11
 * version 2.1 of the License, or (at your option) any later version.
10
12
 *
11
 
 * This library is distributed in the hope that it will be useful,
 
13
 * FFmpeg is distributed in the hope that it will be useful,
12
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
16
 * Lesser General Public License for more details.
15
17
 *
16
18
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this library; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 * License along with FFmpeg; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
21
 */
20
 
 
 
22
 
21
23
/**
22
24
 * @file simple_idct.c
23
25
 * simpleidct in C.
24
26
 */
25
 
 
 
27
 
26
28
/*
27
29
  based upon some outcommented c code from mpeg2dec (idct_mmx.c
28
 
  written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>) 
 
30
  written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
29
31
 */
30
32
#include "avcodec.h"
31
33
#include "dsputil.h"
75
77
 
76
78
static inline void idctRowCondDC (DCTELEM * row)
77
79
{
78
 
        int a0, a1, a2, a3, b0, b1, b2, b3;
79
 
#ifdef FAST_64BIT
 
80
        int a0, a1, a2, a3, b0, b1, b2, b3;
 
81
#ifdef HAVE_FAST_64BIT
80
82
        uint64_t temp;
81
83
#else
82
84
        uint32_t temp;
83
85
#endif
84
86
 
85
 
#ifdef FAST_64BIT
 
87
#ifdef HAVE_FAST_64BIT
86
88
#ifdef WORDS_BIGENDIAN
87
89
#define ROW0_MASK 0xffff000000000000LL
88
90
#else
89
91
#define ROW0_MASK 0xffffLL
90
92
#endif
91
93
        if(sizeof(DCTELEM)==2){
92
 
            if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) | 
 
94
            if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) |
93
95
                  ((uint64_t *)row)[1]) == 0) {
94
96
                temp = (row[0] << 3) & 0xffff;
95
97
                temp += temp << 16;
97
99
                ((uint64_t *)row)[0] = temp;
98
100
                ((uint64_t *)row)[1] = temp;
99
101
                return;
100
 
            }
 
102
            }
101
103
        }else{
102
104
            if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
103
105
                row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
108
110
        if(sizeof(DCTELEM)==2){
109
111
            if (!(((uint32_t*)row)[1] |
110
112
                  ((uint32_t*)row)[2] |
111
 
                  ((uint32_t*)row)[3] | 
 
113
                  ((uint32_t*)row)[3] |
112
114
                  row[1])) {
113
115
                temp = (row[0] << 3) & 0xffff;
114
116
                temp += temp << 16;
125
127
#endif
126
128
 
127
129
        a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));
128
 
        a1 = a0;
129
 
        a2 = a0;
130
 
        a3 = a0;
 
130
        a1 = a0;
 
131
        a2 = a0;
 
132
        a3 = a0;
131
133
 
132
134
        /* no need to optimize : gcc does it */
133
135
        a0 += W2 * row[2];
144
146
        MUL16(b3, W7, row[1]);
145
147
        MAC16(b3, -W5, row[3]);
146
148
 
147
 
#ifdef FAST_64BIT
 
149
#ifdef HAVE_FAST_64BIT
148
150
        temp = ((uint64_t*)row)[1];
149
151
#else
150
152
        temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3];
151
153
#endif
152
 
        if (temp != 0) {
 
154
        if (temp != 0) {
153
155
            a0 += W4*row[4] + W6*row[6];
154
156
            a1 += - W4*row[4] - W2*row[6];
155
157
            a2 += - W4*row[4] + W2*row[6];
157
159
 
158
160
            MAC16(b0, W5, row[5]);
159
161
            MAC16(b0, W7, row[7]);
160
 
            
 
162
 
161
163
            MAC16(b1, -W1, row[5]);
162
164
            MAC16(b1, -W5, row[7]);
163
 
            
 
165
 
164
166
            MAC16(b2, W7, row[5]);
165
167
            MAC16(b2, W3, row[7]);
166
 
            
 
168
 
167
169
            MAC16(b3, W3, row[5]);
168
170
            MAC16(b3, -W1, row[7]);
169
 
        }
 
171
        }
170
172
 
171
 
        row[0] = (a0 + b0) >> ROW_SHIFT;
172
 
        row[7] = (a0 - b0) >> ROW_SHIFT;
173
 
        row[1] = (a1 + b1) >> ROW_SHIFT;
174
 
        row[6] = (a1 - b1) >> ROW_SHIFT;
175
 
        row[2] = (a2 + b2) >> ROW_SHIFT;
176
 
        row[5] = (a2 - b2) >> ROW_SHIFT;
177
 
        row[3] = (a3 + b3) >> ROW_SHIFT;
178
 
        row[4] = (a3 - b3) >> ROW_SHIFT;
 
173
        row[0] = (a0 + b0) >> ROW_SHIFT;
 
174
        row[7] = (a0 - b0) >> ROW_SHIFT;
 
175
        row[1] = (a1 + b1) >> ROW_SHIFT;
 
176
        row[6] = (a1 - b1) >> ROW_SHIFT;
 
177
        row[2] = (a2 + b2) >> ROW_SHIFT;
 
178
        row[5] = (a2 - b2) >> ROW_SHIFT;
 
179
        row[3] = (a3 + b3) >> ROW_SHIFT;
 
180
        row[4] = (a3 - b3) >> ROW_SHIFT;
179
181
}
180
182
 
181
 
static inline void idctSparseColPut (uint8_t *dest, int line_size, 
 
183
static inline void idctSparseColPut (uint8_t *dest, int line_size,
182
184
                                     DCTELEM * col)
183
185
{
184
 
        int a0, a1, a2, a3, b0, b1, b2, b3;
185
 
        uint8_t *cm = cropTbl + MAX_NEG_CROP;
 
186
        int a0, a1, a2, a3, b0, b1, b2, b3;
 
187
        uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
186
188
 
187
189
        /* XXX: I did that only to give same values as previous code */
188
 
        a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
189
 
        a1 = a0;
190
 
        a2 = a0;
191
 
        a3 = a0;
 
190
        a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
 
191
        a1 = a0;
 
192
        a2 = a0;
 
193
        a3 = a0;
192
194
 
193
195
        a0 +=  + W2*col[8*2];
194
196
        a1 +=  + W6*col[8*2];
205
207
        MAC16(b2, - W1, col[8*3]);
206
208
        MAC16(b3, - W5, col[8*3]);
207
209
 
208
 
        if(col[8*4]){
 
210
        if(col[8*4]){
209
211
            a0 += + W4*col[8*4];
210
212
            a1 += - W4*col[8*4];
211
213
            a2 += - W4*col[8*4];
212
214
            a3 += + W4*col[8*4];
213
 
        }
 
215
        }
214
216
 
215
 
        if (col[8*5]) {
 
217
        if (col[8*5]) {
216
218
            MAC16(b0, + W5, col[8*5]);
217
219
            MAC16(b1, - W1, col[8*5]);
218
220
            MAC16(b2, + W7, col[8*5]);
219
221
            MAC16(b3, + W3, col[8*5]);
220
 
        }
 
222
        }
221
223
 
222
 
        if(col[8*6]){
 
224
        if(col[8*6]){
223
225
            a0 += + W6*col[8*6];
224
226
            a1 += - W2*col[8*6];
225
227
            a2 += + W2*col[8*6];
226
228
            a3 += - W6*col[8*6];
227
 
        }
 
229
        }
228
230
 
229
 
        if (col[8*7]) {
 
231
        if (col[8*7]) {
230
232
            MAC16(b0, + W7, col[8*7]);
231
233
            MAC16(b1, - W5, col[8*7]);
232
234
            MAC16(b2, + W3, col[8*7]);
233
235
            MAC16(b3, - W1, col[8*7]);
234
 
        }
 
236
        }
235
237
 
236
238
        dest[0] = cm[(a0 + b0) >> COL_SHIFT];
237
239
        dest += line_size;
250
252
        dest[0] = cm[(a0 - b0) >> COL_SHIFT];
251
253
}
252
254
 
253
 
static inline void idctSparseColAdd (uint8_t *dest, int line_size, 
 
255
static inline void idctSparseColAdd (uint8_t *dest, int line_size,
254
256
                                     DCTELEM * col)
255
257
{
256
 
        int a0, a1, a2, a3, b0, b1, b2, b3;
257
 
        uint8_t *cm = cropTbl + MAX_NEG_CROP;
 
258
        int a0, a1, a2, a3, b0, b1, b2, b3;
 
259
        uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
258
260
 
259
261
        /* XXX: I did that only to give same values as previous code */
260
 
        a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
261
 
        a1 = a0;
262
 
        a2 = a0;
263
 
        a3 = a0;
 
262
        a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
 
263
        a1 = a0;
 
264
        a2 = a0;
 
265
        a3 = a0;
264
266
 
265
267
        a0 +=  + W2*col[8*2];
266
268
        a1 +=  + W6*col[8*2];
277
279
        MAC16(b2, - W1, col[8*3]);
278
280
        MAC16(b3, - W5, col[8*3]);
279
281
 
280
 
        if(col[8*4]){
 
282
        if(col[8*4]){
281
283
            a0 += + W4*col[8*4];
282
284
            a1 += - W4*col[8*4];
283
285
            a2 += - W4*col[8*4];
284
286
            a3 += + W4*col[8*4];
285
 
        }
 
287
        }
286
288
 
287
 
        if (col[8*5]) {
 
289
        if (col[8*5]) {
288
290
            MAC16(b0, + W5, col[8*5]);
289
291
            MAC16(b1, - W1, col[8*5]);
290
292
            MAC16(b2, + W7, col[8*5]);
291
293
            MAC16(b3, + W3, col[8*5]);
292
 
        }
 
294
        }
293
295
 
294
 
        if(col[8*6]){
 
296
        if(col[8*6]){
295
297
            a0 += + W6*col[8*6];
296
298
            a1 += - W2*col[8*6];
297
299
            a2 += + W2*col[8*6];
298
300
            a3 += - W6*col[8*6];
299
 
        }
 
301
        }
300
302
 
301
 
        if (col[8*7]) {
 
303
        if (col[8*7]) {
302
304
            MAC16(b0, + W7, col[8*7]);
303
305
            MAC16(b1, - W5, col[8*7]);
304
306
            MAC16(b2, + W3, col[8*7]);
305
307
            MAC16(b3, - W1, col[8*7]);
306
 
        }
 
308
        }
307
309
 
308
310
        dest[0] = cm[dest[0] + ((a0 + b0) >> COL_SHIFT)];
309
311
        dest += line_size;
324
326
 
325
327
static inline void idctSparseCol (DCTELEM * col)
326
328
{
327
 
        int a0, a1, a2, a3, b0, b1, b2, b3;
 
329
        int a0, a1, a2, a3, b0, b1, b2, b3;
328
330
 
329
331
        /* XXX: I did that only to give same values as previous code */
330
 
        a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
331
 
        a1 = a0;
332
 
        a2 = a0;
333
 
        a3 = a0;
 
332
        a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
 
333
        a1 = a0;
 
334
        a2 = a0;
 
335
        a3 = a0;
334
336
 
335
337
        a0 +=  + W2*col[8*2];
336
338
        a1 +=  + W6*col[8*2];
347
349
        MAC16(b2, - W1, col[8*3]);
348
350
        MAC16(b3, - W5, col[8*3]);
349
351
 
350
 
        if(col[8*4]){
 
352
        if(col[8*4]){
351
353
            a0 += + W4*col[8*4];
352
354
            a1 += - W4*col[8*4];
353
355
            a2 += - W4*col[8*4];
354
356
            a3 += + W4*col[8*4];
355
 
        }
 
357
        }
356
358
 
357
 
        if (col[8*5]) {
 
359
        if (col[8*5]) {
358
360
            MAC16(b0, + W5, col[8*5]);
359
361
            MAC16(b1, - W1, col[8*5]);
360
362
            MAC16(b2, + W7, col[8*5]);
361
363
            MAC16(b3, + W3, col[8*5]);
362
 
        }
 
364
        }
363
365
 
364
 
        if(col[8*6]){
 
366
        if(col[8*6]){
365
367
            a0 += + W6*col[8*6];
366
368
            a1 += - W2*col[8*6];
367
369
            a2 += + W2*col[8*6];
368
370
            a3 += - W6*col[8*6];
369
 
        }
 
371
        }
370
372
 
371
 
        if (col[8*7]) {
 
373
        if (col[8*7]) {
372
374
            MAC16(b0, + W7, col[8*7]);
373
375
            MAC16(b1, - W5, col[8*7]);
374
376
            MAC16(b2, + W3, col[8*7]);
375
377
            MAC16(b3, - W1, col[8*7]);
376
 
        }
 
378
        }
377
379
 
378
380
        col[0 ] = ((a0 + b0) >> COL_SHIFT);
379
381
        col[8 ] = ((a1 + b1) >> COL_SHIFT);
390
392
    int i;
391
393
    for(i=0; i<8; i++)
392
394
        idctRowCondDC(block + i*8);
393
 
    
 
395
 
394
396
    for(i=0; i<8; i++)
395
397
        idctSparseColPut(dest + i, line_size, block + i);
396
398
}
400
402
    int i;
401
403
    for(i=0; i<8; i++)
402
404
        idctRowCondDC(block + i*8);
403
 
    
 
405
 
404
406
    for(i=0; i<8; i++)
405
407
        idctSparseColAdd(dest + i, line_size, block + i);
406
408
}
410
412
    int i;
411
413
    for(i=0; i<8; i++)
412
414
        idctRowCondDC(block + i*8);
413
 
    
 
415
 
414
416
    for(i=0; i<8; i++)
415
417
        idctSparseCol(block + i);
416
418
}
429
431
static inline void idct4col(uint8_t *dest, int line_size, const DCTELEM *col)
430
432
{
431
433
    int c0, c1, c2, c3, a0, a1, a2, a3;
432
 
    const uint8_t *cm = cropTbl + MAX_NEG_CROP;
 
434
    const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
433
435
 
434
436
    a0 = col[8*0];
435
437
    a1 = col[8*2];
467
469
{
468
470
    int i;
469
471
    DCTELEM *ptr;
470
 
    
 
472
 
471
473
    /* butterfly */
472
474
    ptr = block;
473
475
    for(i=0;i<4;i++) {
509
511
static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col)
510
512
{
511
513
    int c0, c1, c2, c3, a0, a1, a2, a3;
512
 
    const uint8_t *cm = cropTbl + MAX_NEG_CROP;
 
514
    const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
513
515
 
514
516
    a0 = col[8*0];
515
517
    a1 = col[8*1];
537
539
static inline void idct4row(DCTELEM *row)
538
540
{
539
541
    int c0, c1, c2, c3, a0, a1, a2, a3;
540
 
    //const uint8_t *cm = cropTbl + MAX_NEG_CROP;
 
542
    //const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
541
543
 
542
544
    a0 = row[0];
543
545
    a1 = row[1];