3526
|
1 /*
|
|
2 * VC-1 and WMV3 decoder - DSP functions
|
|
3 * Copyright (c) 2006 Konstantin Shishkov
|
|
4 *
|
|
5 * This library is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
7 * License as published by the Free Software Foundation; either
|
|
8 * version 2 of the License, or (at your option) any later version.
|
|
9 *
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * Lesser General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
16 * License along with this library; if not, write to the Free Software
|
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 *
|
|
19 */
|
|
20
|
|
21 /**
|
|
22 * @file vc1dsp.c
|
|
23 * VC-1 and WMV3 decoder
|
|
24 *
|
|
25 */
|
|
26
|
|
27 #include "dsputil.h"
|
|
28
|
|
29
|
|
30 /** Apply overlap transform to vertical edge
|
|
31 */
|
|
32 static void vc1_v_overlap_c(uint8_t* src, int stride, int rnd)
|
|
33 {
|
|
34 int i;
|
|
35 int a, b, c, d;
|
|
36 for(i = 0; i < 8; i++) {
|
|
37 a = src[-2*stride];
|
|
38 b = src[-stride];
|
|
39 c = src[0];
|
|
40 d = src[stride];
|
|
41
|
|
42 src[-2*stride] = clip_uint8((7*a + d + 4 - rnd) >> 3);
|
|
43 src[-stride] = clip_uint8((-a + 7*b + c + d + 3 + rnd) >> 3);
|
|
44 src[0] = clip_uint8((a + b + 7*c - d + 4 - rnd) >> 3);
|
|
45 src[stride] = clip_uint8((a + 7*d + 3 + rnd) >> 3);
|
|
46 src++;
|
|
47 }
|
|
48 }
|
|
49
|
|
50 /** Apply overlap transform to horizontal edge
|
|
51 */
|
|
52 static void vc1_h_overlap_c(uint8_t* src, int stride, int rnd)
|
|
53 {
|
|
54 int i;
|
|
55 int a, b, c, d;
|
|
56 for(i = 0; i < 8; i++) {
|
|
57 a = src[-2];
|
|
58 b = src[-1];
|
|
59 c = src[0];
|
|
60 d = src[1];
|
|
61
|
|
62 src[-2] = clip_uint8((7*a + d + 4 - rnd) >> 3);
|
|
63 src[-1] = clip_uint8((-a + 7*b + c + d + 3 + rnd) >> 3);
|
|
64 src[0] = clip_uint8((a + b + 7*c - d + 4 - rnd) >> 3);
|
|
65 src[1] = clip_uint8((a + 7*d + 3 + rnd) >> 3);
|
|
66 src += stride;
|
|
67 }
|
|
68 }
|
|
69
|
|
70
|
|
71 /** Do inverse transform on 8x8 block
|
|
72 */
|
|
73 static void vc1_inv_trans_8x8_c(DCTELEM block[64])
|
|
74 {
|
|
75 int i;
|
|
76 register int t1,t2,t3,t4,t5,t6,t7,t8;
|
|
77 DCTELEM *src, *dst;
|
|
78
|
|
79 src = block;
|
|
80 dst = block;
|
|
81 for(i = 0; i < 8; i++){
|
|
82 t1 = 12 * (src[0] + src[4]);
|
|
83 t2 = 12 * (src[0] - src[4]);
|
|
84 t3 = 16 * src[2] + 6 * src[6];
|
|
85 t4 = 6 * src[2] - 16 * src[6];
|
|
86
|
|
87 t5 = t1 + t3;
|
|
88 t6 = t2 + t4;
|
|
89 t7 = t2 - t4;
|
|
90 t8 = t1 - t3;
|
|
91
|
|
92 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
|
|
93 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
|
|
94 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
|
|
95 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
|
|
96
|
|
97 dst[0] = (t5 + t1 + 4) >> 3;
|
|
98 dst[1] = (t6 + t2 + 4) >> 3;
|
|
99 dst[2] = (t7 + t3 + 4) >> 3;
|
|
100 dst[3] = (t8 + t4 + 4) >> 3;
|
|
101 dst[4] = (t8 - t4 + 4) >> 3;
|
|
102 dst[5] = (t7 - t3 + 4) >> 3;
|
|
103 dst[6] = (t6 - t2 + 4) >> 3;
|
|
104 dst[7] = (t5 - t1 + 4) >> 3;
|
|
105
|
|
106 src += 8;
|
|
107 dst += 8;
|
|
108 }
|
|
109
|
|
110 src = block;
|
|
111 dst = block;
|
|
112 for(i = 0; i < 8; i++){
|
|
113 t1 = 12 * (src[ 0] + src[32]);
|
|
114 t2 = 12 * (src[ 0] - src[32]);
|
|
115 t3 = 16 * src[16] + 6 * src[48];
|
|
116 t4 = 6 * src[16] - 16 * src[48];
|
|
117
|
|
118 t5 = t1 + t3;
|
|
119 t6 = t2 + t4;
|
|
120 t7 = t2 - t4;
|
|
121 t8 = t1 - t3;
|
|
122
|
|
123 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
|
|
124 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
|
|
125 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
|
|
126 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
|
|
127
|
|
128 dst[ 0] = (t5 + t1 + 64) >> 7;
|
|
129 dst[ 8] = (t6 + t2 + 64) >> 7;
|
|
130 dst[16] = (t7 + t3 + 64) >> 7;
|
|
131 dst[24] = (t8 + t4 + 64) >> 7;
|
|
132 dst[32] = (t8 - t4 + 64 + 1) >> 7;
|
|
133 dst[40] = (t7 - t3 + 64 + 1) >> 7;
|
|
134 dst[48] = (t6 - t2 + 64 + 1) >> 7;
|
|
135 dst[56] = (t5 - t1 + 64 + 1) >> 7;
|
|
136
|
|
137 src++;
|
|
138 dst++;
|
|
139 }
|
|
140 }
|
|
141
|
|
142 /** Do inverse transform on 8x4 part of block
|
|
143 */
|
|
144 static void vc1_inv_trans_8x4_c(DCTELEM block[64], int n)
|
|
145 {
|
|
146 int i;
|
|
147 register int t1,t2,t3,t4,t5,t6,t7,t8;
|
|
148 DCTELEM *src, *dst;
|
|
149 int off;
|
|
150
|
|
151 off = n * 32;
|
|
152 src = block + off;
|
|
153 dst = block + off;
|
|
154 for(i = 0; i < 4; i++){
|
|
155 t1 = 12 * (src[0] + src[4]);
|
|
156 t2 = 12 * (src[0] - src[4]);
|
|
157 t3 = 16 * src[2] + 6 * src[6];
|
|
158 t4 = 6 * src[2] - 16 * src[6];
|
|
159
|
|
160 t5 = t1 + t3;
|
|
161 t6 = t2 + t4;
|
|
162 t7 = t2 - t4;
|
|
163 t8 = t1 - t3;
|
|
164
|
|
165 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
|
|
166 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
|
|
167 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
|
|
168 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
|
|
169
|
|
170 dst[0] = (t5 + t1 + 4) >> 3;
|
|
171 dst[1] = (t6 + t2 + 4) >> 3;
|
|
172 dst[2] = (t7 + t3 + 4) >> 3;
|
|
173 dst[3] = (t8 + t4 + 4) >> 3;
|
|
174 dst[4] = (t8 - t4 + 4) >> 3;
|
|
175 dst[5] = (t7 - t3 + 4) >> 3;
|
|
176 dst[6] = (t6 - t2 + 4) >> 3;
|
|
177 dst[7] = (t5 - t1 + 4) >> 3;
|
|
178
|
|
179 src += 8;
|
|
180 dst += 8;
|
|
181 }
|
|
182
|
|
183 src = block + off;
|
|
184 dst = block + off;
|
|
185 for(i = 0; i < 8; i++){
|
|
186 t1 = 17 * (src[ 0] + src[16]);
|
|
187 t2 = 17 * (src[ 0] - src[16]);
|
|
188 t3 = 22 * src[ 8];
|
|
189 t4 = 22 * src[24];
|
|
190 t5 = 10 * src[ 8];
|
|
191 t6 = 10 * src[24];
|
|
192
|
|
193 dst[ 0] = (t1 + t3 + t6 + 64) >> 7;
|
|
194 dst[ 8] = (t2 - t4 + t5 + 64) >> 7;
|
|
195 dst[16] = (t2 + t4 - t5 + 64) >> 7;
|
|
196 dst[24] = (t1 - t3 - t6 + 64) >> 7;
|
|
197
|
|
198 src ++;
|
|
199 dst ++;
|
|
200 }
|
|
201 }
|
|
202
|
|
203 /** Do inverse transform on 4x8 parts of block
|
|
204 */
|
|
205 static void vc1_inv_trans_4x8_c(DCTELEM block[64], int n)
|
|
206 {
|
|
207 int i;
|
|
208 register int t1,t2,t3,t4,t5,t6,t7,t8;
|
|
209 DCTELEM *src, *dst;
|
|
210 int off;
|
|
211
|
|
212 off = n * 4;
|
|
213 src = block + off;
|
|
214 dst = block + off;
|
|
215 for(i = 0; i < 8; i++){
|
|
216 t1 = 17 * (src[0] + src[2]);
|
|
217 t2 = 17 * (src[0] - src[2]);
|
|
218 t3 = 22 * src[1];
|
|
219 t4 = 22 * src[3];
|
|
220 t5 = 10 * src[1];
|
|
221 t6 = 10 * src[3];
|
|
222
|
|
223 dst[0] = (t1 + t3 + t6 + 4) >> 3;
|
|
224 dst[1] = (t2 - t4 + t5 + 4) >> 3;
|
|
225 dst[2] = (t2 + t4 - t5 + 4) >> 3;
|
|
226 dst[3] = (t1 - t3 - t6 + 4) >> 3;
|
|
227
|
|
228 src += 8;
|
|
229 dst += 8;
|
|
230 }
|
|
231
|
|
232 src = block + off;
|
|
233 dst = block + off;
|
|
234 for(i = 0; i < 4; i++){
|
|
235 t1 = 12 * (src[ 0] + src[32]);
|
|
236 t2 = 12 * (src[ 0] - src[32]);
|
|
237 t3 = 16 * src[16] + 6 * src[48];
|
|
238 t4 = 6 * src[16] - 16 * src[48];
|
|
239
|
|
240 t5 = t1 + t3;
|
|
241 t6 = t2 + t4;
|
|
242 t7 = t2 - t4;
|
|
243 t8 = t1 - t3;
|
|
244
|
|
245 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
|
|
246 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
|
|
247 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
|
|
248 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
|
|
249
|
|
250 dst[ 0] = (t5 + t1 + 64) >> 7;
|
|
251 dst[ 8] = (t6 + t2 + 64) >> 7;
|
|
252 dst[16] = (t7 + t3 + 64) >> 7;
|
|
253 dst[24] = (t8 + t4 + 64) >> 7;
|
|
254 dst[32] = (t8 - t4 + 64 + 1) >> 7;
|
|
255 dst[40] = (t7 - t3 + 64 + 1) >> 7;
|
|
256 dst[48] = (t6 - t2 + 64 + 1) >> 7;
|
|
257 dst[56] = (t5 - t1 + 64 + 1) >> 7;
|
|
258
|
|
259 src++;
|
|
260 dst++;
|
|
261 }
|
|
262 }
|
|
263
|
|
264 /** Do inverse transform on 4x4 part of block
|
|
265 */
|
|
266 static void vc1_inv_trans_4x4_c(DCTELEM block[64], int n)
|
|
267 {
|
|
268 int i;
|
|
269 register int t1,t2,t3,t4,t5,t6;
|
|
270 DCTELEM *src, *dst;
|
|
271 int off;
|
|
272
|
|
273 off = (n&1) * 4 + (n&2) * 16;
|
|
274 src = block + off;
|
|
275 dst = block + off;
|
|
276 for(i = 0; i < 4; i++){
|
|
277 t1 = 17 * (src[0] + src[2]);
|
|
278 t2 = 17 * (src[0] - src[2]);
|
|
279 t3 = 22 * src[1];
|
|
280 t4 = 22 * src[3];
|
|
281 t5 = 10 * src[1];
|
|
282 t6 = 10 * src[3];
|
|
283
|
|
284 dst[0] = (t1 + t3 + t6 + 4) >> 3;
|
|
285 dst[1] = (t2 - t4 + t5 + 4) >> 3;
|
|
286 dst[2] = (t2 + t4 - t5 + 4) >> 3;
|
|
287 dst[3] = (t1 - t3 - t6 + 4) >> 3;
|
|
288
|
|
289 src += 8;
|
|
290 dst += 8;
|
|
291 }
|
|
292
|
|
293 src = block + off;
|
|
294 dst = block + off;
|
|
295 for(i = 0; i < 4; i++){
|
|
296 t1 = 17 * (src[ 0] + src[16]);
|
|
297 t2 = 17 * (src[ 0] - src[16]);
|
|
298 t3 = 22 * src[ 8];
|
|
299 t4 = 22 * src[24];
|
|
300 t5 = 10 * src[ 8];
|
|
301 t6 = 10 * src[24];
|
|
302
|
|
303 dst[ 0] = (t1 + t3 + t6 + 64) >> 7;
|
|
304 dst[ 8] = (t2 - t4 + t5 + 64) >> 7;
|
|
305 dst[16] = (t2 + t4 - t5 + 64) >> 7;
|
|
306 dst[24] = (t1 - t3 - t6 + 64) >> 7;
|
|
307
|
|
308 src ++;
|
|
309 dst ++;
|
|
310 }
|
|
311 }
|
|
312
|
|
313 /* motion compensation functions */
|
|
314
|
|
315 /** Filter used to interpolate fractional pel values
|
|
316 */
|
3529
|
317 static always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
|
3526
|
318 {
|
|
319 switch(mode){
|
|
320 case 0: //no shift
|
|
321 return src[0];
|
|
322 case 1: // 1/4 shift
|
|
323 return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
|
|
324 case 2: // 1/2 shift
|
|
325 return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
|
|
326 case 3: // 3/4 shift
|
|
327 return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
|
|
328 }
|
|
329 return 0; //should not occur
|
|
330 }
|
|
331
|
|
332 /** Function used to do motion compensation with bicubic interpolation
|
|
333 */
|
|
334 static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int mode, int rnd)
|
|
335 {
|
|
336 int i, j;
|
|
337 uint8_t tmp[8*11], *tptr;
|
|
338 int m, r;
|
|
339
|
|
340 m = (mode & 3);
|
|
341 r = rnd;
|
|
342 src -= stride;
|
|
343 tptr = tmp;
|
|
344 for(j = 0; j < 11; j++) {
|
|
345 for(i = 0; i < 8; i++)
|
3529
|
346 tptr[i] = clip_uint8(vc1_mspel_filter(src + i, 1, m, r));
|
3526
|
347 src += stride;
|
|
348 tptr += 8;
|
|
349 }
|
|
350 r = 1 - rnd;
|
|
351 m = (mode >> 2) & 3;
|
|
352
|
|
353 tptr = tmp + 8;
|
|
354 for(j = 0; j < 8; j++) {
|
|
355 for(i = 0; i < 8; i++)
|
3529
|
356 dst[i] = clip_uint8(vc1_mspel_filter(tptr + i, 8, m, r));
|
3526
|
357 dst += stride;
|
|
358 tptr += 8;
|
|
359 }
|
|
360 }
|
|
361
|
|
362 /* pixel functions - really are entry points to vc1_mspel_mc */
|
|
363
|
|
364 /* this one is defined in dsputil.c */
|
|
365 void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
|
|
366
|
|
367 static void ff_put_vc1_mspel_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
368 vc1_mspel_mc(dst, src, stride, 0x1, rnd);
|
|
369 }
|
|
370
|
|
371 static void ff_put_vc1_mspel_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
372 vc1_mspel_mc(dst, src, stride, 0x2, rnd);
|
|
373 }
|
|
374
|
|
375 static void ff_put_vc1_mspel_mc30_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
376 vc1_mspel_mc(dst, src, stride, 0x3, rnd);
|
|
377 }
|
|
378
|
|
379 static void ff_put_vc1_mspel_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
380 vc1_mspel_mc(dst, src, stride, 0x4, rnd);
|
|
381 }
|
|
382
|
|
383 static void ff_put_vc1_mspel_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
384 vc1_mspel_mc(dst, src, stride, 0x5, rnd);
|
|
385 }
|
|
386
|
|
387 static void ff_put_vc1_mspel_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
388 vc1_mspel_mc(dst, src, stride, 0x6, rnd);
|
|
389 }
|
|
390
|
|
391 static void ff_put_vc1_mspel_mc31_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
392 vc1_mspel_mc(dst, src, stride, 0x7, rnd);
|
|
393 }
|
|
394
|
|
395 static void ff_put_vc1_mspel_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
396 vc1_mspel_mc(dst, src, stride, 0x8, rnd);
|
|
397 }
|
|
398
|
|
399 static void ff_put_vc1_mspel_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
400 vc1_mspel_mc(dst, src, stride, 0x9, rnd);
|
|
401 }
|
|
402
|
|
403 static void ff_put_vc1_mspel_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
404 vc1_mspel_mc(dst, src, stride, 0xA, rnd);
|
|
405 }
|
|
406
|
|
407 static void ff_put_vc1_mspel_mc32_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
408 vc1_mspel_mc(dst, src, stride, 0xB, rnd);
|
|
409 }
|
|
410
|
|
411 static void ff_put_vc1_mspel_mc03_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
412 vc1_mspel_mc(dst, src, stride, 0xC, rnd);
|
|
413 }
|
|
414
|
|
415 static void ff_put_vc1_mspel_mc13_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
416 vc1_mspel_mc(dst, src, stride, 0xD, rnd);
|
|
417 }
|
|
418
|
|
419 static void ff_put_vc1_mspel_mc23_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
420 vc1_mspel_mc(dst, src, stride, 0xE, rnd);
|
|
421 }
|
|
422
|
|
423 static void ff_put_vc1_mspel_mc33_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
|
|
424 vc1_mspel_mc(dst, src, stride, 0xF, rnd);
|
|
425 }
|
|
426
|
|
427 void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) {
|
|
428 dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
|
|
429 dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
|
|
430 dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c;
|
|
431 dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
|
|
432 dsp->vc1_h_overlap = vc1_h_overlap_c;
|
|
433 dsp->vc1_v_overlap = vc1_v_overlap_c;
|
|
434
|
|
435 dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_c;
|
|
436 dsp->put_vc1_mspel_pixels_tab[ 1] = ff_put_vc1_mspel_mc10_c;
|
|
437 dsp->put_vc1_mspel_pixels_tab[ 2] = ff_put_vc1_mspel_mc20_c;
|
|
438 dsp->put_vc1_mspel_pixels_tab[ 3] = ff_put_vc1_mspel_mc30_c;
|
|
439 dsp->put_vc1_mspel_pixels_tab[ 4] = ff_put_vc1_mspel_mc01_c;
|
|
440 dsp->put_vc1_mspel_pixels_tab[ 5] = ff_put_vc1_mspel_mc11_c;
|
|
441 dsp->put_vc1_mspel_pixels_tab[ 6] = ff_put_vc1_mspel_mc21_c;
|
|
442 dsp->put_vc1_mspel_pixels_tab[ 7] = ff_put_vc1_mspel_mc31_c;
|
|
443 dsp->put_vc1_mspel_pixels_tab[ 8] = ff_put_vc1_mspel_mc02_c;
|
|
444 dsp->put_vc1_mspel_pixels_tab[ 9] = ff_put_vc1_mspel_mc12_c;
|
|
445 dsp->put_vc1_mspel_pixels_tab[10] = ff_put_vc1_mspel_mc22_c;
|
|
446 dsp->put_vc1_mspel_pixels_tab[11] = ff_put_vc1_mspel_mc32_c;
|
|
447 dsp->put_vc1_mspel_pixels_tab[12] = ff_put_vc1_mspel_mc03_c;
|
|
448 dsp->put_vc1_mspel_pixels_tab[13] = ff_put_vc1_mspel_mc13_c;
|
|
449 dsp->put_vc1_mspel_pixels_tab[14] = ff_put_vc1_mspel_mc23_c;
|
|
450 dsp->put_vc1_mspel_pixels_tab[15] = ff_put_vc1_mspel_mc33_c;
|
|
451 }
|