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