2
* VC-1 and WMV3 decoder - DSP functions
3
* Copyright (c) 2006 Konstantin Shishkov
5
* This file is part of FFmpeg.
7
* FFmpeg 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.
12
* FFmpeg 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.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with FFmpeg; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
* VC-1 and WMV3 decoder
32
/** Apply overlap transform to horizontal edge
34
static void vc1_v_overlap_c(uint8_t* src, int stride)
40
for(i = 0; i < 8; i++) {
45
d1 = (a - d + 3 + rnd) >> 3;
46
d2 = (a - d + b - c + 4 - rnd) >> 3;
48
src[-2*stride] = a - d1;
49
src[-stride] = b - d2;
57
/** Apply overlap transform to vertical edge
59
static void vc1_h_overlap_c(uint8_t* src, int stride)
65
for(i = 0; i < 8; i++) {
70
d1 = (a - d + 3 + rnd) >> 3;
71
d2 = (a - d + b - c + 4 - rnd) >> 3;
83
/** Do inverse transform on 8x8 block
85
static void vc1_inv_trans_8x8_c(DCTELEM block[64])
88
register int t1,t2,t3,t4,t5,t6,t7,t8;
93
for(i = 0; i < 8; i++){
94
t1 = 12 * (src[0] + src[4]);
95
t2 = 12 * (src[0] - src[4]);
96
t3 = 16 * src[2] + 6 * src[6];
97
t4 = 6 * src[2] - 16 * src[6];
104
t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
105
t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
106
t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
107
t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
109
dst[0] = (t5 + t1 + 4) >> 3;
110
dst[1] = (t6 + t2 + 4) >> 3;
111
dst[2] = (t7 + t3 + 4) >> 3;
112
dst[3] = (t8 + t4 + 4) >> 3;
113
dst[4] = (t8 - t4 + 4) >> 3;
114
dst[5] = (t7 - t3 + 4) >> 3;
115
dst[6] = (t6 - t2 + 4) >> 3;
116
dst[7] = (t5 - t1 + 4) >> 3;
124
for(i = 0; i < 8; i++){
125
t1 = 12 * (src[ 0] + src[32]);
126
t2 = 12 * (src[ 0] - src[32]);
127
t3 = 16 * src[16] + 6 * src[48];
128
t4 = 6 * src[16] - 16 * src[48];
135
t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
136
t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
137
t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
138
t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
140
dst[ 0] = (t5 + t1 + 64) >> 7;
141
dst[ 8] = (t6 + t2 + 64) >> 7;
142
dst[16] = (t7 + t3 + 64) >> 7;
143
dst[24] = (t8 + t4 + 64) >> 7;
144
dst[32] = (t8 - t4 + 64 + 1) >> 7;
145
dst[40] = (t7 - t3 + 64 + 1) >> 7;
146
dst[48] = (t6 - t2 + 64 + 1) >> 7;
147
dst[56] = (t5 - t1 + 64 + 1) >> 7;
154
/** Do inverse transform on 8x4 part of block
156
static void vc1_inv_trans_8x4_c(DCTELEM block[64], int n)
159
register int t1,t2,t3,t4,t5,t6,t7,t8;
166
for(i = 0; i < 4; i++){
167
t1 = 12 * (src[0] + src[4]);
168
t2 = 12 * (src[0] - src[4]);
169
t3 = 16 * src[2] + 6 * src[6];
170
t4 = 6 * src[2] - 16 * src[6];
177
t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
178
t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
179
t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
180
t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
182
dst[0] = (t5 + t1 + 4) >> 3;
183
dst[1] = (t6 + t2 + 4) >> 3;
184
dst[2] = (t7 + t3 + 4) >> 3;
185
dst[3] = (t8 + t4 + 4) >> 3;
186
dst[4] = (t8 - t4 + 4) >> 3;
187
dst[5] = (t7 - t3 + 4) >> 3;
188
dst[6] = (t6 - t2 + 4) >> 3;
189
dst[7] = (t5 - t1 + 4) >> 3;
197
for(i = 0; i < 8; i++){
198
t1 = 17 * (src[ 0] + src[16]);
199
t2 = 17 * (src[ 0] - src[16]);
205
dst[ 0] = (t1 + t3 + t6 + 64) >> 7;
206
dst[ 8] = (t2 - t4 + t5 + 64) >> 7;
207
dst[16] = (t2 + t4 - t5 + 64) >> 7;
208
dst[24] = (t1 - t3 - t6 + 64) >> 7;
215
/** Do inverse transform on 4x8 parts of block
217
static void vc1_inv_trans_4x8_c(DCTELEM block[64], int n)
220
register int t1,t2,t3,t4,t5,t6,t7,t8;
227
for(i = 0; i < 8; i++){
228
t1 = 17 * (src[0] + src[2]);
229
t2 = 17 * (src[0] - src[2]);
235
dst[0] = (t1 + t3 + t6 + 4) >> 3;
236
dst[1] = (t2 - t4 + t5 + 4) >> 3;
237
dst[2] = (t2 + t4 - t5 + 4) >> 3;
238
dst[3] = (t1 - t3 - t6 + 4) >> 3;
246
for(i = 0; i < 4; i++){
247
t1 = 12 * (src[ 0] + src[32]);
248
t2 = 12 * (src[ 0] - src[32]);
249
t3 = 16 * src[16] + 6 * src[48];
250
t4 = 6 * src[16] - 16 * src[48];
257
t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
258
t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
259
t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
260
t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
262
dst[ 0] = (t5 + t1 + 64) >> 7;
263
dst[ 8] = (t6 + t2 + 64) >> 7;
264
dst[16] = (t7 + t3 + 64) >> 7;
265
dst[24] = (t8 + t4 + 64) >> 7;
266
dst[32] = (t8 - t4 + 64 + 1) >> 7;
267
dst[40] = (t7 - t3 + 64 + 1) >> 7;
268
dst[48] = (t6 - t2 + 64 + 1) >> 7;
269
dst[56] = (t5 - t1 + 64 + 1) >> 7;
276
/** Do inverse transform on 4x4 part of block
278
static void vc1_inv_trans_4x4_c(DCTELEM block[64], int n)
281
register int t1,t2,t3,t4,t5,t6;
285
off = (n&1) * 4 + (n&2) * 16;
288
for(i = 0; i < 4; i++){
289
t1 = 17 * (src[0] + src[2]);
290
t2 = 17 * (src[0] - src[2]);
296
dst[0] = (t1 + t3 + t6 + 4) >> 3;
297
dst[1] = (t2 - t4 + t5 + 4) >> 3;
298
dst[2] = (t2 + t4 - t5 + 4) >> 3;
299
dst[3] = (t1 - t3 - t6 + 4) >> 3;
307
for(i = 0; i < 4; i++){
308
t1 = 17 * (src[ 0] + src[16]);
309
t2 = 17 * (src[ 0] - src[16]);
315
dst[ 0] = (t1 + t3 + t6 + 64) >> 7;
316
dst[ 8] = (t2 - t4 + t5 + 64) >> 7;
317
dst[16] = (t2 + t4 - t5 + 64) >> 7;
318
dst[24] = (t1 - t3 - t6 + 64) >> 7;
325
/* motion compensation functions */
327
/** Filter used to interpolate fractional pel values
329
static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
335
return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
337
return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
339
return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
341
return 0; //should not occur
344
/** Function used to do motion compensation with bicubic interpolation
346
static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int mode, int rnd)
349
uint8_t tmp[8*11], *tptr;
356
for(j = 0; j < 11; j++) {
357
for(i = 0; i < 8; i++)
358
tptr[i] = av_clip_uint8(vc1_mspel_filter(src + i, 1, m, r));
366
for(j = 0; j < 8; j++) {
367
for(i = 0; i < 8; i++)
368
dst[i] = av_clip_uint8(vc1_mspel_filter(tptr + i, 8, m, r));
374
/* pixel functions - really are entry points to vc1_mspel_mc */
376
/* this one is defined in dsputil.c */
377
void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
379
static void ff_put_vc1_mspel_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
380
vc1_mspel_mc(dst, src, stride, 0x1, rnd);
383
static void ff_put_vc1_mspel_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
384
vc1_mspel_mc(dst, src, stride, 0x2, rnd);
387
static void ff_put_vc1_mspel_mc30_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
388
vc1_mspel_mc(dst, src, stride, 0x3, rnd);
391
static void ff_put_vc1_mspel_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
392
vc1_mspel_mc(dst, src, stride, 0x4, rnd);
395
static void ff_put_vc1_mspel_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
396
vc1_mspel_mc(dst, src, stride, 0x5, rnd);
399
static void ff_put_vc1_mspel_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
400
vc1_mspel_mc(dst, src, stride, 0x6, rnd);
403
static void ff_put_vc1_mspel_mc31_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
404
vc1_mspel_mc(dst, src, stride, 0x7, rnd);
407
static void ff_put_vc1_mspel_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
408
vc1_mspel_mc(dst, src, stride, 0x8, rnd);
411
static void ff_put_vc1_mspel_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
412
vc1_mspel_mc(dst, src, stride, 0x9, rnd);
415
static void ff_put_vc1_mspel_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
416
vc1_mspel_mc(dst, src, stride, 0xA, rnd);
419
static void ff_put_vc1_mspel_mc32_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
420
vc1_mspel_mc(dst, src, stride, 0xB, rnd);
423
static void ff_put_vc1_mspel_mc03_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
424
vc1_mspel_mc(dst, src, stride, 0xC, rnd);
427
static void ff_put_vc1_mspel_mc13_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
428
vc1_mspel_mc(dst, src, stride, 0xD, rnd);
431
static void ff_put_vc1_mspel_mc23_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
432
vc1_mspel_mc(dst, src, stride, 0xE, rnd);
435
static void ff_put_vc1_mspel_mc33_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
436
vc1_mspel_mc(dst, src, stride, 0xF, rnd);
439
void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) {
440
dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
441
dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
442
dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c;
443
dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
444
dsp->vc1_h_overlap = vc1_h_overlap_c;
445
dsp->vc1_v_overlap = vc1_v_overlap_c;
447
dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_c;
448
dsp->put_vc1_mspel_pixels_tab[ 1] = ff_put_vc1_mspel_mc10_c;
449
dsp->put_vc1_mspel_pixels_tab[ 2] = ff_put_vc1_mspel_mc20_c;
450
dsp->put_vc1_mspel_pixels_tab[ 3] = ff_put_vc1_mspel_mc30_c;
451
dsp->put_vc1_mspel_pixels_tab[ 4] = ff_put_vc1_mspel_mc01_c;
452
dsp->put_vc1_mspel_pixels_tab[ 5] = ff_put_vc1_mspel_mc11_c;
453
dsp->put_vc1_mspel_pixels_tab[ 6] = ff_put_vc1_mspel_mc21_c;
454
dsp->put_vc1_mspel_pixels_tab[ 7] = ff_put_vc1_mspel_mc31_c;
455
dsp->put_vc1_mspel_pixels_tab[ 8] = ff_put_vc1_mspel_mc02_c;
456
dsp->put_vc1_mspel_pixels_tab[ 9] = ff_put_vc1_mspel_mc12_c;
457
dsp->put_vc1_mspel_pixels_tab[10] = ff_put_vc1_mspel_mc22_c;
458
dsp->put_vc1_mspel_pixels_tab[11] = ff_put_vc1_mspel_mc32_c;
459
dsp->put_vc1_mspel_pixels_tab[12] = ff_put_vc1_mspel_mc03_c;
460
dsp->put_vc1_mspel_pixels_tab[13] = ff_put_vc1_mspel_mc13_c;
461
dsp->put_vc1_mspel_pixels_tab[14] = ff_put_vc1_mspel_mc23_c;
462
dsp->put_vc1_mspel_pixels_tab[15] = ff_put_vc1_mspel_mc33_c;