Statistics
| Branch: | Revision:

ffmpeg / libavcodec / vc1dsp.c @ 2912e87a

History | View | Annotate | Download (24.7 KB)

1
/*
2
 * VC-1 and WMV3 decoder - DSP functions
3
 * Copyright (c) 2006 Konstantin Shishkov
4
 *
5
 * This file is part of Libav.
6
 *
7
 * Libav is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * Libav is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with Libav; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

    
22
/**
23
* @file
24
 * VC-1 and WMV3 decoder
25
 *
26
 */
27

    
28
#include "vc1dsp.h"
29

    
30

    
31
/** Apply overlap transform to horizontal edge
32
*/
33
static void vc1_v_overlap_c(uint8_t* src, int stride)
34
{
35
    int i;
36
    int a, b, c, d;
37
    int d1, d2;
38
    int rnd = 1;
39
    for(i = 0; i < 8; i++) {
40
        a = src[-2*stride];
41
        b = src[-stride];
42
        c = src[0];
43
        d = src[stride];
44
        d1 = (a - d + 3 + rnd) >> 3;
45
        d2 = (a - d + b - c + 4 - rnd) >> 3;
46

    
47
        src[-2*stride] = a - d1;
48
        src[-stride] = av_clip_uint8(b - d2);
49
        src[0] = av_clip_uint8(c + d2);
50
        src[stride] = d + d1;
51
        src++;
52
        rnd = !rnd;
53
    }
54
}
55

    
56
/** Apply overlap transform to vertical edge
57
*/
58
static void vc1_h_overlap_c(uint8_t* src, int stride)
59
{
60
    int i;
61
    int a, b, c, d;
62
    int d1, d2;
63
    int rnd = 1;
64
    for(i = 0; i < 8; i++) {
65
        a = src[-2];
66
        b = src[-1];
67
        c = src[0];
68
        d = src[1];
69
        d1 = (a - d + 3 + rnd) >> 3;
70
        d2 = (a - d + b - c + 4 - rnd) >> 3;
71

    
72
        src[-2] = a - d1;
73
        src[-1] = av_clip_uint8(b - d2);
74
        src[0] = av_clip_uint8(c + d2);
75
        src[1] = d + d1;
76
        src += stride;
77
        rnd = !rnd;
78
    }
79
}
80

    
81
/**
82
 * VC-1 in-loop deblocking filter for one line
83
 * @param src source block type
84
 * @param stride block stride
85
 * @param pq block quantizer
86
 * @return whether other 3 pairs should be filtered or not
87
 * @see 8.6
88
 */
89
static av_always_inline int vc1_filter_line(uint8_t* src, int stride, int pq){
90
    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
91

    
92
    int a0 = (2*(src[-2*stride] - src[ 1*stride]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3;
93
    int a0_sign = a0 >> 31;        /* Store sign */
94
    a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */
95
    if(a0 < pq){
96
        int a1 = FFABS((2*(src[-4*stride] - src[-1*stride]) - 5*(src[-3*stride] - src[-2*stride]) + 4) >> 3);
97
        int a2 = FFABS((2*(src[ 0*stride] - src[ 3*stride]) - 5*(src[ 1*stride] - src[ 2*stride]) + 4) >> 3);
98
        if(a1 < a0 || a2 < a0){
99
            int clip = src[-1*stride] - src[ 0*stride];
100
            int clip_sign = clip >> 31;
101
            clip = ((clip ^ clip_sign) - clip_sign)>>1;
102
            if(clip){
103
                int a3 = FFMIN(a1, a2);
104
                int d = 5 * (a3 - a0);
105
                int d_sign = (d >> 31);
106
                d = ((d ^ d_sign) - d_sign) >> 3;
107
                d_sign ^= a0_sign;
108

    
109
                if( d_sign ^ clip_sign )
110
                    d = 0;
111
                else{
112
                    d = FFMIN(d, clip);
113
                    d = (d ^ d_sign) - d_sign;          /* Restore sign */
114
                    src[-1*stride] = cm[src[-1*stride] - d];
115
                    src[ 0*stride] = cm[src[ 0*stride] + d];
116
                }
117
                return 1;
118
            }
119
        }
120
    }
121
    return 0;
122
}
123

    
124
/**
125
 * VC-1 in-loop deblocking filter
126
 * @param src source block type
127
 * @param step distance between horizontally adjacent elements
128
 * @param stride distance between vertically adjacent elements
129
 * @param len edge length to filter (4 or 8 pixels)
130
 * @param pq block quantizer
131
 * @see 8.6
132
 */
133
static inline void vc1_loop_filter(uint8_t* src, int step, int stride, int len, int pq)
134
{
135
    int i;
136
    int filt3;
137

    
138
    for(i = 0; i < len; i += 4){
139
        filt3 = vc1_filter_line(src + 2*step, stride, pq);
140
        if(filt3){
141
            vc1_filter_line(src + 0*step, stride, pq);
142
            vc1_filter_line(src + 1*step, stride, pq);
143
            vc1_filter_line(src + 3*step, stride, pq);
144
        }
145
        src += step * 4;
146
    }
147
}
148

    
149
static void vc1_v_loop_filter4_c(uint8_t *src, int stride, int pq)
150
{
151
    vc1_loop_filter(src, 1, stride, 4, pq);
152
}
153

    
154
static void vc1_h_loop_filter4_c(uint8_t *src, int stride, int pq)
155
{
156
    vc1_loop_filter(src, stride, 1, 4, pq);
157
}
158

    
159
static void vc1_v_loop_filter8_c(uint8_t *src, int stride, int pq)
160
{
161
    vc1_loop_filter(src, 1, stride, 8, pq);
162
}
163

    
164
static void vc1_h_loop_filter8_c(uint8_t *src, int stride, int pq)
165
{
166
    vc1_loop_filter(src, stride, 1, 8, pq);
167
}
168

    
169
static void vc1_v_loop_filter16_c(uint8_t *src, int stride, int pq)
170
{
171
    vc1_loop_filter(src, 1, stride, 16, pq);
172
}
173

    
174
static void vc1_h_loop_filter16_c(uint8_t *src, int stride, int pq)
175
{
176
    vc1_loop_filter(src, stride, 1, 16, pq);
177
}
178

    
179
/** Do inverse transform on 8x8 block
180
*/
181
static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
182
{
183
    int i;
184
    int dc = block[0];
185
    const uint8_t *cm;
186
    dc = (3 * dc +  1) >> 1;
187
    dc = (3 * dc + 16) >> 5;
188
    cm = ff_cropTbl + MAX_NEG_CROP + dc;
189
    for(i = 0; i < 8; i++){
190
        dest[0] = cm[dest[0]];
191
        dest[1] = cm[dest[1]];
192
        dest[2] = cm[dest[2]];
193
        dest[3] = cm[dest[3]];
194
        dest[4] = cm[dest[4]];
195
        dest[5] = cm[dest[5]];
196
        dest[6] = cm[dest[6]];
197
        dest[7] = cm[dest[7]];
198
        dest += linesize;
199
    }
200
}
201

    
202
static av_always_inline void vc1_inv_trans_8x8_c(DCTELEM block[64], int shl, int sub)
203
{
204
    int i;
205
    register int t1,t2,t3,t4,t5,t6,t7,t8;
206
    DCTELEM *src, *dst, temp[64];
207

    
208
    src = block;
209
    dst = temp;
210
    for(i = 0; i < 8; i++){
211
        t1 = 12 * (src[ 0] + src[32]) + 4;
212
        t2 = 12 * (src[ 0] - src[32]) + 4;
213
        t3 = 16 * src[16] +  6 * src[48];
214
        t4 =  6 * src[16] - 16 * src[48];
215

    
216
        t5 = t1 + t3;
217
        t6 = t2 + t4;
218
        t7 = t2 - t4;
219
        t8 = t1 - t3;
220

    
221
        t1 = 16 * src[ 8] + 15 * src[24] +  9 * src[40] +  4 * src[56];
222
        t2 = 15 * src[ 8] -  4 * src[24] - 16 * src[40] -  9 * src[56];
223
        t3 =  9 * src[ 8] - 16 * src[24] +  4 * src[40] + 15 * src[56];
224
        t4 =  4 * src[ 8] -  9 * src[24] + 15 * src[40] - 16 * src[56];
225

    
226
        dst[0] = (t5 + t1) >> 3;
227
        dst[1] = (t6 + t2) >> 3;
228
        dst[2] = (t7 + t3) >> 3;
229
        dst[3] = (t8 + t4) >> 3;
230
        dst[4] = (t8 - t4) >> 3;
231
        dst[5] = (t7 - t3) >> 3;
232
        dst[6] = (t6 - t2) >> 3;
233
        dst[7] = (t5 - t1) >> 3;
234

    
235
        src += 1;
236
        dst += 8;
237
    }
238

    
239
    src = temp;
240
    dst = block;
241
    for(i = 0; i < 8; i++){
242
        t1 = 12 * (src[ 0] + src[32]) + 64;
243
        t2 = 12 * (src[ 0] - src[32]) + 64;
244
        t3 = 16 * src[16] +  6 * src[48];
245
        t4 =  6 * src[16] - 16 * src[48];
246

    
247
        t5 = t1 + t3;
248
        t6 = t2 + t4;
249
        t7 = t2 - t4;
250
        t8 = t1 - t3;
251

    
252
        t1 = 16 * src[ 8] + 15 * src[24] +  9 * src[40] +  4 * src[56];
253
        t2 = 15 * src[ 8] -  4 * src[24] - 16 * src[40] -  9 * src[56];
254
        t3 =  9 * src[ 8] - 16 * src[24] +  4 * src[40] + 15 * src[56];
255
        t4 =  4 * src[ 8] -  9 * src[24] + 15 * src[40] - 16 * src[56];
256

    
257
        dst[ 0] = (((t5 + t1    ) >> 7) - sub) << shl;
258
        dst[ 8] = (((t6 + t2    ) >> 7) - sub) << shl;
259
        dst[16] = (((t7 + t3    ) >> 7) - sub) << shl;
260
        dst[24] = (((t8 + t4    ) >> 7) - sub) << shl;
261
        dst[32] = (((t8 - t4 + 1) >> 7) - sub) << shl;
262
        dst[40] = (((t7 - t3 + 1) >> 7) - sub) << shl;
263
        dst[48] = (((t6 - t2 + 1) >> 7) - sub) << shl;
264
        dst[56] = (((t5 - t1 + 1) >> 7) - sub) << shl;
265

    
266
        src++;
267
        dst++;
268
    }
269
}
270

    
271
static void vc1_inv_trans_8x8_add_c(uint8_t *dest, int linesize, DCTELEM *block)
272
{
273
    vc1_inv_trans_8x8_c(block, 0, 0);
274
    ff_add_pixels_clamped_c(block, dest, linesize);
275
}
276

    
277
static void vc1_inv_trans_8x8_put_signed_c(uint8_t *dest, int linesize, DCTELEM *block)
278
{
279
    vc1_inv_trans_8x8_c(block, 0, 0);
280
    ff_put_signed_pixels_clamped_c(block, dest, linesize);
281
}
282

    
283
static void vc1_inv_trans_8x8_put_signed_rangered_c(uint8_t *dest, int linesize, DCTELEM *block)
284
{
285
    vc1_inv_trans_8x8_c(block, 1, 0);
286
    ff_put_signed_pixels_clamped_c(block, dest, linesize);
287
}
288

    
289
static void vc1_inv_trans_8x8_put_c(uint8_t *dest, int linesize, DCTELEM *block)
290
{
291
    vc1_inv_trans_8x8_c(block, 0, 0);
292
    ff_put_pixels_clamped_c(block, dest, linesize);
293
}
294

    
295
static void vc1_inv_trans_8x8_put_rangered_c(uint8_t *dest, int linesize, DCTELEM *block)
296
{
297
    vc1_inv_trans_8x8_c(block, 1, 64);
298
    ff_put_pixels_clamped_c(block, dest, linesize);
299
}
300

    
301
/** Do inverse transform on 8x4 part of block
302
*/
303
static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
304
{
305
    int i;
306
    int dc = block[0];
307
    const uint8_t *cm;
308
    dc = ( 3 * dc +  1) >> 1;
309
    dc = (17 * dc + 64) >> 7;
310
    cm = ff_cropTbl + MAX_NEG_CROP + dc;
311
    for(i = 0; i < 4; i++){
312
        dest[0] = cm[dest[0]];
313
        dest[1] = cm[dest[1]];
314
        dest[2] = cm[dest[2]];
315
        dest[3] = cm[dest[3]];
316
        dest[4] = cm[dest[4]];
317
        dest[5] = cm[dest[5]];
318
        dest[6] = cm[dest[6]];
319
        dest[7] = cm[dest[7]];
320
        dest += linesize;
321
    }
322
}
323

    
324
static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, DCTELEM *block)
325
{
326
    int i;
327
    register int t1,t2,t3,t4,t5,t6,t7,t8;
328
    DCTELEM *src, *dst;
329
    const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
330

    
331
    src = block;
332
    dst = block;
333
    for(i = 0; i < 4; i++){
334
        t1 = 12 * (src[0] + src[4]) + 4;
335
        t2 = 12 * (src[0] - src[4]) + 4;
336
        t3 = 16 * src[2] +  6 * src[6];
337
        t4 =  6 * src[2] - 16 * src[6];
338

    
339
        t5 = t1 + t3;
340
        t6 = t2 + t4;
341
        t7 = t2 - t4;
342
        t8 = t1 - t3;
343

    
344
        t1 = 16 * src[1] + 15 * src[3] +  9 * src[5] +  4 * src[7];
345
        t2 = 15 * src[1] -  4 * src[3] - 16 * src[5] -  9 * src[7];
346
        t3 =  9 * src[1] - 16 * src[3] +  4 * src[5] + 15 * src[7];
347
        t4 =  4 * src[1] -  9 * src[3] + 15 * src[5] - 16 * src[7];
348

    
349
        dst[0] = (t5 + t1) >> 3;
350
        dst[1] = (t6 + t2) >> 3;
351
        dst[2] = (t7 + t3) >> 3;
352
        dst[3] = (t8 + t4) >> 3;
353
        dst[4] = (t8 - t4) >> 3;
354
        dst[5] = (t7 - t3) >> 3;
355
        dst[6] = (t6 - t2) >> 3;
356
        dst[7] = (t5 - t1) >> 3;
357

    
358
        src += 8;
359
        dst += 8;
360
    }
361

    
362
    src = block;
363
    for(i = 0; i < 8; i++){
364
        t1 = 17 * (src[ 0] + src[16]) + 64;
365
        t2 = 17 * (src[ 0] - src[16]) + 64;
366
        t3 = 22 * src[ 8] + 10 * src[24];
367
        t4 = 22 * src[24] - 10 * src[ 8];
368

    
369
        dest[0*linesize] = cm[dest[0*linesize] + ((t1 + t3) >> 7)];
370
        dest[1*linesize] = cm[dest[1*linesize] + ((t2 - t4) >> 7)];
371
        dest[2*linesize] = cm[dest[2*linesize] + ((t2 + t4) >> 7)];
372
        dest[3*linesize] = cm[dest[3*linesize] + ((t1 - t3) >> 7)];
373

    
374
        src ++;
375
        dest++;
376
    }
377
}
378

    
379
/** Do inverse transform on 4x8 parts of block
380
*/
381
static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
382
{
383
    int i;
384
    int dc = block[0];
385
    const uint8_t *cm;
386
    dc = (17 * dc +  4) >> 3;
387
    dc = (12 * dc + 64) >> 7;
388
    cm = ff_cropTbl + MAX_NEG_CROP + dc;
389
    for(i = 0; i < 8; i++){
390
        dest[0] = cm[dest[0]];
391
        dest[1] = cm[dest[1]];
392
        dest[2] = cm[dest[2]];
393
        dest[3] = cm[dest[3]];
394
        dest += linesize;
395
    }
396
}
397

    
398
static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, DCTELEM *block)
399
{
400
    int i;
401
    register int t1,t2,t3,t4,t5,t6,t7,t8;
402
    DCTELEM *src, *dst;
403
    const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
404

    
405
    src = block;
406
    dst = block;
407
    for(i = 0; i < 8; i++){
408
        t1 = 17 * (src[0] + src[2]) + 4;
409
        t2 = 17 * (src[0] - src[2]) + 4;
410
        t3 = 22 * src[1] + 10 * src[3];
411
        t4 = 22 * src[3] - 10 * src[1];
412

    
413
        dst[0] = (t1 + t3) >> 3;
414
        dst[1] = (t2 - t4) >> 3;
415
        dst[2] = (t2 + t4) >> 3;
416
        dst[3] = (t1 - t3) >> 3;
417

    
418
        src += 8;
419
        dst += 8;
420
    }
421

    
422
    src = block;
423
    for(i = 0; i < 4; i++){
424
        t1 = 12 * (src[ 0] + src[32]) + 64;
425
        t2 = 12 * (src[ 0] - src[32]) + 64;
426
        t3 = 16 * src[16] +  6 * src[48];
427
        t4 =  6 * src[16] - 16 * src[48];
428

    
429
        t5 = t1 + t3;
430
        t6 = t2 + t4;
431
        t7 = t2 - t4;
432
        t8 = t1 - t3;
433

    
434
        t1 = 16 * src[ 8] + 15 * src[24] +  9 * src[40] +  4 * src[56];
435
        t2 = 15 * src[ 8] -  4 * src[24] - 16 * src[40] -  9 * src[56];
436
        t3 =  9 * src[ 8] - 16 * src[24] +  4 * src[40] + 15 * src[56];
437
        t4 =  4 * src[ 8] -  9 * src[24] + 15 * src[40] - 16 * src[56];
438

    
439
        dest[0*linesize] = cm[dest[0*linesize] + ((t5 + t1) >> 7)];
440
        dest[1*linesize] = cm[dest[1*linesize] + ((t6 + t2) >> 7)];
441
        dest[2*linesize] = cm[dest[2*linesize] + ((t7 + t3) >> 7)];
442
        dest[3*linesize] = cm[dest[3*linesize] + ((t8 + t4) >> 7)];
443
        dest[4*linesize] = cm[dest[4*linesize] + ((t8 - t4 + 1) >> 7)];
444
        dest[5*linesize] = cm[dest[5*linesize] + ((t7 - t3 + 1) >> 7)];
445
        dest[6*linesize] = cm[dest[6*linesize] + ((t6 - t2 + 1) >> 7)];
446
        dest[7*linesize] = cm[dest[7*linesize] + ((t5 - t1 + 1) >> 7)];
447

    
448
        src ++;
449
        dest++;
450
    }
451
}
452

    
453
/** Do inverse transform on 4x4 part of block
454
*/
455
static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
456
{
457
    int i;
458
    int dc = block[0];
459
    const uint8_t *cm;
460
    dc = (17 * dc +  4) >> 3;
461
    dc = (17 * dc + 64) >> 7;
462
    cm = ff_cropTbl + MAX_NEG_CROP + dc;
463
    for(i = 0; i < 4; i++){
464
        dest[0] = cm[dest[0]];
465
        dest[1] = cm[dest[1]];
466
        dest[2] = cm[dest[2]];
467
        dest[3] = cm[dest[3]];
468
        dest += linesize;
469
    }
470
}
471

    
472
static void vc1_inv_trans_4x4_c(uint8_t *dest, int linesize, DCTELEM *block)
473
{
474
    int i;
475
    register int t1,t2,t3,t4;
476
    DCTELEM *src, *dst;
477
    const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
478

    
479
    src = block;
480
    dst = block;
481
    for(i = 0; i < 4; i++){
482
        t1 = 17 * (src[0] + src[2]) + 4;
483
        t2 = 17 * (src[0] - src[2]) + 4;
484
        t3 = 22 * src[1] + 10 * src[3];
485
        t4 = 22 * src[3] - 10 * src[1];
486

    
487
        dst[0] = (t1 + t3) >> 3;
488
        dst[1] = (t2 - t4) >> 3;
489
        dst[2] = (t2 + t4) >> 3;
490
        dst[3] = (t1 - t3) >> 3;
491

    
492
        src += 8;
493
        dst += 8;
494
    }
495

    
496
    src = block;
497
    for(i = 0; i < 4; i++){
498
        t1 = 17 * (src[ 0] + src[16]) + 64;
499
        t2 = 17 * (src[ 0] - src[16]) + 64;
500
        t3 = 22 * src[ 8] + 10 * src[24];
501
        t4 = 22 * src[24] - 10 * src[ 8];
502

    
503
        dest[0*linesize] = cm[dest[0*linesize] + ((t1 + t3) >> 7)];
504
        dest[1*linesize] = cm[dest[1*linesize] + ((t2 - t4) >> 7)];
505
        dest[2*linesize] = cm[dest[2*linesize] + ((t2 + t4) >> 7)];
506
        dest[3*linesize] = cm[dest[3*linesize] + ((t1 - t3) >> 7)];
507

    
508
        src ++;
509
        dest++;
510
    }
511
}
512

    
513
/* motion compensation functions */
514
/** Filter in case of 2 filters */
515
#define VC1_MSPEL_FILTER_16B(DIR, TYPE)                                 \
516
static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, int stride, int mode) \
517
{                                                                       \
518
    switch(mode){                                                       \
519
    case 0: /* no shift - should not occur */                           \
520
        return 0;                                                       \
521
    case 1: /* 1/4 shift */                                             \
522
        return -4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2]; \
523
    case 2: /* 1/2 shift */                                             \
524
        return -src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2]; \
525
    case 3: /* 3/4 shift */                                             \
526
        return -3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2]; \
527
    }                                                                   \
528
    return 0; /* should not occur */                                    \
529
}
530

    
531
VC1_MSPEL_FILTER_16B(ver, uint8_t);
532
VC1_MSPEL_FILTER_16B(hor, int16_t);
533

    
534

    
535
/** Filter used to interpolate fractional pel values
536
 */
537
static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
538
{
539
    switch(mode){
540
    case 0: //no shift
541
        return src[0];
542
    case 1: // 1/4 shift
543
        return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
544
    case 2: // 1/2 shift
545
        return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
546
    case 3: // 3/4 shift
547
        return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
548
    }
549
    return 0; //should not occur
550
}
551

    
552
/** Function used to do motion compensation with bicubic interpolation
553
 */
554
#define VC1_MSPEL_MC(OP, OPNAME)\
555
static void OPNAME ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int hmode, int vmode, int rnd)\
556
{\
557
    int     i, j;\
558
\
559
    if (vmode) { /* Horizontal filter to apply */\
560
        int r;\
561
\
562
        if (hmode) { /* Vertical filter to apply, output to tmp */\
563
            static const int shift_value[] = { 0, 5, 1, 5 };\
564
            int              shift = (shift_value[hmode]+shift_value[vmode])>>1;\
565
            int16_t          tmp[11*8], *tptr = tmp;\
566
\
567
            r = (1<<(shift-1)) + rnd-1;\
568
\
569
            src -= 1;\
570
            for(j = 0; j < 8; j++) {\
571
                for(i = 0; i < 11; i++)\
572
                    tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode)+r)>>shift;\
573
                src += stride;\
574
                tptr += 11;\
575
            }\
576
\
577
            r = 64-rnd;\
578
            tptr = tmp+1;\
579
            for(j = 0; j < 8; j++) {\
580
                for(i = 0; i < 8; i++)\
581
                    OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode)+r)>>7);\
582
                dst += stride;\
583
                tptr += 11;\
584
            }\
585
\
586
            return;\
587
        }\
588
        else { /* No horizontal filter, output 8 lines to dst */\
589
            r = 1-rnd;\
590
\
591
            for(j = 0; j < 8; j++) {\
592
                for(i = 0; i < 8; i++)\
593
                    OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r));\
594
                src += stride;\
595
                dst += stride;\
596
            }\
597
            return;\
598
        }\
599
    }\
600
\
601
    /* Horizontal mode with no vertical mode */\
602
    for(j = 0; j < 8; j++) {\
603
        for(i = 0; i < 8; i++)\
604
            OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd));\
605
        dst += stride;\
606
        src += stride;\
607
    }\
608
}
609

    
610
#define op_put(a, b) a = av_clip_uint8(b)
611
#define op_avg(a, b) a = (a + av_clip_uint8(b) + 1) >> 1
612

    
613
VC1_MSPEL_MC(op_put, put_)
614
VC1_MSPEL_MC(op_avg, avg_)
615

    
616
/* pixel functions - really are entry points to vc1_mspel_mc */
617

    
618
#define PUT_VC1_MSPEL(a, b)\
619
static void put_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
620
     put_vc1_mspel_mc(dst, src, stride, a, b, rnd);                         \
621
}\
622
static void avg_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
623
     avg_vc1_mspel_mc(dst, src, stride, a, b, rnd);                         \
624
}
625

    
626
PUT_VC1_MSPEL(1, 0)
627
PUT_VC1_MSPEL(2, 0)
628
PUT_VC1_MSPEL(3, 0)
629

    
630
PUT_VC1_MSPEL(0, 1)
631
PUT_VC1_MSPEL(1, 1)
632
PUT_VC1_MSPEL(2, 1)
633
PUT_VC1_MSPEL(3, 1)
634

    
635
PUT_VC1_MSPEL(0, 2)
636
PUT_VC1_MSPEL(1, 2)
637
PUT_VC1_MSPEL(2, 2)
638
PUT_VC1_MSPEL(3, 2)
639

    
640
PUT_VC1_MSPEL(0, 3)
641
PUT_VC1_MSPEL(1, 3)
642
PUT_VC1_MSPEL(2, 3)
643
PUT_VC1_MSPEL(3, 3)
644

    
645
static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
646
    const int A=(8-x)*(8-y);
647
    const int B=(  x)*(8-y);
648
    const int C=(8-x)*(  y);
649
    const int D=(  x)*(  y);
650
    int i;
651

    
652
    assert(x<8 && y<8 && x>=0 && y>=0);
653

    
654
    for(i=0; i<h; i++)
655
    {
656
        dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
657
        dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
658
        dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
659
        dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
660
        dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
661
        dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
662
        dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
663
        dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
664
        dst+= stride;
665
        src+= stride;
666
    }
667
}
668

    
669
#define avg2(a,b) ((a+b+1)>>1)
670
static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){
671
    const int A=(8-x)*(8-y);
672
    const int B=(  x)*(8-y);
673
    const int C=(8-x)*(  y);
674
    const int D=(  x)*(  y);
675
    int i;
676

    
677
    assert(x<8 && y<8 && x>=0 && y>=0);
678

    
679
    for(i=0; i<h; i++)
680
    {
681
        dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
682
        dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
683
        dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
684
        dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
685
        dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
686
        dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
687
        dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
688
        dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
689
        dst+= stride;
690
        src+= stride;
691
    }
692
}
693

    
694
av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) {
695
    dsp->vc1_inv_trans_8x8_add = vc1_inv_trans_8x8_add_c;
696
    dsp->vc1_inv_trans_8x8_put_signed[0] = vc1_inv_trans_8x8_put_signed_c;
697
    dsp->vc1_inv_trans_8x8_put_signed[1] = vc1_inv_trans_8x8_put_signed_rangered_c;
698
    dsp->vc1_inv_trans_8x8_put[0] = vc1_inv_trans_8x8_put_c;
699
    dsp->vc1_inv_trans_8x8_put[1] = vc1_inv_trans_8x8_put_rangered_c;
700
    dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
701
    dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c;
702
    dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
703
    dsp->vc1_inv_trans_8x8_dc = vc1_inv_trans_8x8_dc_c;
704
    dsp->vc1_inv_trans_4x8_dc = vc1_inv_trans_4x8_dc_c;
705
    dsp->vc1_inv_trans_8x4_dc = vc1_inv_trans_8x4_dc_c;
706
    dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c;
707
    dsp->vc1_h_overlap = vc1_h_overlap_c;
708
    dsp->vc1_v_overlap = vc1_v_overlap_c;
709
    dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c;
710
    dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c;
711
    dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c;
712
    dsp->vc1_h_loop_filter8 = vc1_h_loop_filter8_c;
713
    dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_c;
714
    dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_c;
715

    
716
    dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_pixels8x8_c;
717
    dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_c;
718
    dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_c;
719
    dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_c;
720
    dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_c;
721
    dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_c;
722
    dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_c;
723
    dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_c;
724
    dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_c;
725
    dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_c;
726
    dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_c;
727
    dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_c;
728
    dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_c;
729
    dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_c;
730
    dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_c;
731
    dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_c;
732

    
733
    dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_pixels8x8_c;
734
    dsp->avg_vc1_mspel_pixels_tab[ 1] = avg_vc1_mspel_mc10_c;
735
    dsp->avg_vc1_mspel_pixels_tab[ 2] = avg_vc1_mspel_mc20_c;
736
    dsp->avg_vc1_mspel_pixels_tab[ 3] = avg_vc1_mspel_mc30_c;
737
    dsp->avg_vc1_mspel_pixels_tab[ 4] = avg_vc1_mspel_mc01_c;
738
    dsp->avg_vc1_mspel_pixels_tab[ 5] = avg_vc1_mspel_mc11_c;
739
    dsp->avg_vc1_mspel_pixels_tab[ 6] = avg_vc1_mspel_mc21_c;
740
    dsp->avg_vc1_mspel_pixels_tab[ 7] = avg_vc1_mspel_mc31_c;
741
    dsp->avg_vc1_mspel_pixels_tab[ 8] = avg_vc1_mspel_mc02_c;
742
    dsp->avg_vc1_mspel_pixels_tab[ 9] = avg_vc1_mspel_mc12_c;
743
    dsp->avg_vc1_mspel_pixels_tab[10] = avg_vc1_mspel_mc22_c;
744
    dsp->avg_vc1_mspel_pixels_tab[11] = avg_vc1_mspel_mc32_c;
745
    dsp->avg_vc1_mspel_pixels_tab[12] = avg_vc1_mspel_mc03_c;
746
    dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_c;
747
    dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_c;
748
    dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_c;
749

    
750
    dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
751
    dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
752

    
753
    if (HAVE_ALTIVEC)
754
        ff_vc1dsp_init_altivec(dsp);
755
    if (HAVE_MMX)
756
        ff_vc1dsp_init_mmx(dsp);
757
}