Mercurial > mplayer.hg
annotate libmpcodecs/vf_yadif.c @ 27611:07f04cb82a73
sync with xine
author | compn |
---|---|
date | Fri, 19 Sep 2008 19:55:25 +0000 |
parents | 82601a38e2a7 |
children | 08d18fe9da52 |
rev | line source |
---|---|
18608 | 1 /* |
26727 | 2 * Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at> |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
18608 | 20 |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 #include <inttypes.h> | |
25 #include <math.h> | |
26 | |
27 #include "config.h" | |
19830 | 28 #include "cpudetect.h" |
18608 | 29 |
30 #include "mp_msg.h" | |
31 | |
32 #ifdef HAVE_MALLOC_H | |
33 #include <malloc.h> | |
34 #endif | |
35 | |
36 #include "img_format.h" | |
37 #include "mp_image.h" | |
38 #include "vf.h" | |
39 #include "libvo/fastmemcpy.h" | |
40 | |
41 #define MIN(a,b) ((a) > (b) ? (b) : (a)) | |
42 #define MAX(a,b) ((a) < (b) ? (b) : (a)) | |
43 #define ABS(a) ((a) > 0 ? (a) : (-(a))) | |
44 | |
45 #define MIN3(a,b,c) MIN(MIN(a,b),c) | |
46 #define MAX3(a,b,c) MAX(MAX(a,b),c) | |
47 | |
48 //===========================================================================// | |
49 | |
50 struct vf_priv_s { | |
51 int mode; | |
52 int parity; | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
53 int buffered_i; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
54 int buffered_tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
55 double buffered_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
56 mp_image_t *buffered_mpi; |
18608 | 57 int stride[3]; |
18625 | 58 uint8_t *ref[4][3]; |
21060 | 59 int do_deinterlace; |
18608 | 60 }; |
61 | |
19830 | 62 static void (*filter_line)(struct vf_priv_s *p, uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int refs, int parity); |
63 | |
18608 | 64 static void store_ref(struct vf_priv_s *p, uint8_t *src[3], int src_stride[3], int width, int height){ |
65 int i; | |
66 | |
23458
973e53dc7df5
Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents:
23457
diff
changeset
|
67 memcpy (p->ref[3], p->ref[0], sizeof(uint8_t *)*3); |
18625 | 68 memmove(p->ref[0], p->ref[1], sizeof(uint8_t *)*3*3); |
18608 | 69 |
70 for(i=0; i<3; i++){ | |
71 int is_chroma= !!i; | |
72 | |
18625 | 73 memcpy_pic(p->ref[2][i], src[i], width>>is_chroma, height>>is_chroma, p->stride[i], src_stride[i]); |
18608 | 74 } |
75 } | |
76 | |
19888
2ce14efa8917
Replace preprocessor hacks to work around compilers not supporting named
diego
parents:
19830
diff
changeset
|
77 #if defined(HAVE_MMX) && defined(NAMED_ASM_ARGS) |
19830 | 78 |
79 #define LOAD4(mem,dst) \ | |
80 "movd "mem", "#dst" \n\t"\ | |
81 "punpcklbw %%mm7, "#dst" \n\t" | |
82 | |
83 #define PABS(tmp,dst) \ | |
84 "pxor "#tmp", "#tmp" \n\t"\ | |
85 "psubw "#dst", "#tmp" \n\t"\ | |
86 "pmaxsw "#tmp", "#dst" \n\t" | |
87 | |
88 #define CHECK(pj,mj) \ | |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
89 "movq "#pj"(%[cur],%[mrefs]), %%mm2 \n\t" /* cur[x-refs-1+j] */\ |
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
90 "movq "#mj"(%[cur],%[prefs]), %%mm3 \n\t" /* cur[x+refs-1-j] */\ |
19830 | 91 "movq %%mm2, %%mm4 \n\t"\ |
92 "movq %%mm2, %%mm5 \n\t"\ | |
93 "pxor %%mm3, %%mm4 \n\t"\ | |
94 "pavgb %%mm3, %%mm5 \n\t"\ | |
95 "pand %[pb1], %%mm4 \n\t"\ | |
96 "psubusb %%mm4, %%mm5 \n\t"\ | |
97 "psrlq $8, %%mm5 \n\t"\ | |
98 "punpcklbw %%mm7, %%mm5 \n\t" /* (cur[x-refs+j] + cur[x+refs-j])>>1 */\ | |
99 "movq %%mm2, %%mm4 \n\t"\ | |
100 "psubusb %%mm3, %%mm2 \n\t"\ | |
101 "psubusb %%mm4, %%mm3 \n\t"\ | |
102 "pmaxub %%mm3, %%mm2 \n\t"\ | |
103 "movq %%mm2, %%mm3 \n\t"\ | |
104 "movq %%mm2, %%mm4 \n\t" /* ABS(cur[x-refs-1+j] - cur[x+refs-1-j]) */\ | |
105 "psrlq $8, %%mm3 \n\t" /* ABS(cur[x-refs +j] - cur[x+refs -j]) */\ | |
106 "psrlq $16, %%mm4 \n\t" /* ABS(cur[x-refs+1+j] - cur[x+refs+1-j]) */\ | |
107 "punpcklbw %%mm7, %%mm2 \n\t"\ | |
108 "punpcklbw %%mm7, %%mm3 \n\t"\ | |
109 "punpcklbw %%mm7, %%mm4 \n\t"\ | |
110 "paddw %%mm3, %%mm2 \n\t"\ | |
111 "paddw %%mm4, %%mm2 \n\t" /* score */ | |
112 | |
113 #define CHECK1 \ | |
114 "movq %%mm0, %%mm3 \n\t"\ | |
115 "pcmpgtw %%mm2, %%mm3 \n\t" /* if(score < spatial_score) */\ | |
116 "pminsw %%mm2, %%mm0 \n\t" /* spatial_score= score; */\ | |
117 "movq %%mm3, %%mm6 \n\t"\ | |
118 "pand %%mm3, %%mm5 \n\t"\ | |
119 "pandn %%mm1, %%mm3 \n\t"\ | |
120 "por %%mm5, %%mm3 \n\t"\ | |
121 "movq %%mm3, %%mm1 \n\t" /* spatial_pred= (cur[x-refs+j] + cur[x+refs-j])>>1; */ | |
122 | |
123 #define CHECK2 /* pretend not to have checked dir=2 if dir=1 was bad.\ | |
124 hurts both quality and speed, but matches the C version. */\ | |
125 "paddw %[pw1], %%mm6 \n\t"\ | |
126 "psllw $14, %%mm6 \n\t"\ | |
127 "paddsw %%mm6, %%mm2 \n\t"\ | |
128 "movq %%mm0, %%mm3 \n\t"\ | |
129 "pcmpgtw %%mm2, %%mm3 \n\t"\ | |
130 "pminsw %%mm2, %%mm0 \n\t"\ | |
131 "pand %%mm3, %%mm5 \n\t"\ | |
132 "pandn %%mm1, %%mm3 \n\t"\ | |
133 "por %%mm5, %%mm3 \n\t"\ | |
134 "movq %%mm3, %%mm1 \n\t" | |
135 | |
136 static void filter_line_mmx2(struct vf_priv_s *p, uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int refs, int parity){ | |
137 static const uint64_t pw_1 = 0x0001000100010001ULL; | |
138 static const uint64_t pb_1 = 0x0101010101010101ULL; | |
139 const int mode = p->mode; | |
140 uint64_t tmp0, tmp1, tmp2, tmp3; | |
141 int x; | |
142 | |
143 #define FILTER\ | |
144 for(x=0; x<w; x+=4){\ | |
145 asm volatile(\ | |
146 "pxor %%mm7, %%mm7 \n\t"\ | |
147 LOAD4("(%[cur],%[mrefs])", %%mm0) /* c = cur[x-refs] */\ | |
148 LOAD4("(%[cur],%[prefs])", %%mm1) /* e = cur[x+refs] */\ | |
149 LOAD4("(%["prev2"])", %%mm2) /* prev2[x] */\ | |
150 LOAD4("(%["next2"])", %%mm3) /* next2[x] */\ | |
151 "movq %%mm3, %%mm4 \n\t"\ | |
152 "paddw %%mm2, %%mm3 \n\t"\ | |
153 "psraw $1, %%mm3 \n\t" /* d = (prev2[x] + next2[x])>>1 */\ | |
154 "movq %%mm0, %[tmp0] \n\t" /* c */\ | |
155 "movq %%mm3, %[tmp1] \n\t" /* d */\ | |
156 "movq %%mm1, %[tmp2] \n\t" /* e */\ | |
157 "psubw %%mm4, %%mm2 \n\t"\ | |
158 PABS( %%mm4, %%mm2) /* temporal_diff0 */\ | |
159 LOAD4("(%[prev],%[mrefs])", %%mm3) /* prev[x-refs] */\ | |
160 LOAD4("(%[prev],%[prefs])", %%mm4) /* prev[x+refs] */\ | |
161 "psubw %%mm0, %%mm3 \n\t"\ | |
162 "psubw %%mm1, %%mm4 \n\t"\ | |
163 PABS( %%mm5, %%mm3)\ | |
164 PABS( %%mm5, %%mm4)\ | |
165 "paddw %%mm4, %%mm3 \n\t" /* temporal_diff1 */\ | |
166 "psrlw $1, %%mm2 \n\t"\ | |
167 "psrlw $1, %%mm3 \n\t"\ | |
168 "pmaxsw %%mm3, %%mm2 \n\t"\ | |
169 LOAD4("(%[next],%[mrefs])", %%mm3) /* next[x-refs] */\ | |
170 LOAD4("(%[next],%[prefs])", %%mm4) /* next[x+refs] */\ | |
171 "psubw %%mm0, %%mm3 \n\t"\ | |
172 "psubw %%mm1, %%mm4 \n\t"\ | |
173 PABS( %%mm5, %%mm3)\ | |
174 PABS( %%mm5, %%mm4)\ | |
175 "paddw %%mm4, %%mm3 \n\t" /* temporal_diff2 */\ | |
176 "psrlw $1, %%mm3 \n\t"\ | |
177 "pmaxsw %%mm3, %%mm2 \n\t"\ | |
178 "movq %%mm2, %[tmp3] \n\t" /* diff */\ | |
179 \ | |
180 "paddw %%mm0, %%mm1 \n\t"\ | |
181 "paddw %%mm0, %%mm0 \n\t"\ | |
182 "psubw %%mm1, %%mm0 \n\t"\ | |
183 "psrlw $1, %%mm1 \n\t" /* spatial_pred */\ | |
184 PABS( %%mm2, %%mm0) /* ABS(c-e) */\ | |
185 \ | |
186 "movq -1(%[cur],%[mrefs]), %%mm2 \n\t" /* cur[x-refs-1] */\ | |
187 "movq -1(%[cur],%[prefs]), %%mm3 \n\t" /* cur[x+refs-1] */\ | |
188 "movq %%mm2, %%mm4 \n\t"\ | |
189 "psubusb %%mm3, %%mm2 \n\t"\ | |
190 "psubusb %%mm4, %%mm3 \n\t"\ | |
191 "pmaxub %%mm3, %%mm2 \n\t"\ | |
192 "pshufw $9,%%mm2, %%mm3 \n\t"\ | |
193 "punpcklbw %%mm7, %%mm2 \n\t" /* ABS(cur[x-refs-1] - cur[x+refs-1]) */\ | |
194 "punpcklbw %%mm7, %%mm3 \n\t" /* ABS(cur[x-refs+1] - cur[x+refs+1]) */\ | |
195 "paddw %%mm2, %%mm0 \n\t"\ | |
196 "paddw %%mm3, %%mm0 \n\t"\ | |
197 "psubw %[pw1], %%mm0 \n\t" /* spatial_score */\ | |
198 \ | |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
199 CHECK(-2,0)\ |
19830 | 200 CHECK1\ |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
201 CHECK(-3,1)\ |
19830 | 202 CHECK2\ |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
203 CHECK(0,-2)\ |
19830 | 204 CHECK1\ |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
205 CHECK(1,-3)\ |
19830 | 206 CHECK2\ |
207 \ | |
208 /* if(p->mode<2) ... */\ | |
209 "movq %[tmp3], %%mm6 \n\t" /* diff */\ | |
210 "cmp $2, %[mode] \n\t"\ | |
211 "jge 1f \n\t"\ | |
212 LOAD4("(%["prev2"],%[mrefs],2)", %%mm2) /* prev2[x-2*refs] */\ | |
213 LOAD4("(%["next2"],%[mrefs],2)", %%mm4) /* next2[x-2*refs] */\ | |
214 LOAD4("(%["prev2"],%[prefs],2)", %%mm3) /* prev2[x+2*refs] */\ | |
215 LOAD4("(%["next2"],%[prefs],2)", %%mm5) /* next2[x+2*refs] */\ | |
216 "paddw %%mm4, %%mm2 \n\t"\ | |
217 "paddw %%mm5, %%mm3 \n\t"\ | |
218 "psrlw $1, %%mm2 \n\t" /* b */\ | |
219 "psrlw $1, %%mm3 \n\t" /* f */\ | |
220 "movq %[tmp0], %%mm4 \n\t" /* c */\ | |
221 "movq %[tmp1], %%mm5 \n\t" /* d */\ | |
222 "movq %[tmp2], %%mm7 \n\t" /* e */\ | |
223 "psubw %%mm4, %%mm2 \n\t" /* b-c */\ | |
224 "psubw %%mm7, %%mm3 \n\t" /* f-e */\ | |
225 "movq %%mm5, %%mm0 \n\t"\ | |
226 "psubw %%mm4, %%mm5 \n\t" /* d-c */\ | |
227 "psubw %%mm7, %%mm0 \n\t" /* d-e */\ | |
228 "movq %%mm2, %%mm4 \n\t"\ | |
229 "pminsw %%mm3, %%mm2 \n\t"\ | |
230 "pmaxsw %%mm4, %%mm3 \n\t"\ | |
231 "pmaxsw %%mm5, %%mm2 \n\t"\ | |
232 "pminsw %%mm5, %%mm3 \n\t"\ | |
233 "pmaxsw %%mm0, %%mm2 \n\t" /* max */\ | |
234 "pminsw %%mm0, %%mm3 \n\t" /* min */\ | |
235 "pxor %%mm4, %%mm4 \n\t"\ | |
236 "pmaxsw %%mm3, %%mm6 \n\t"\ | |
237 "psubw %%mm2, %%mm4 \n\t" /* -max */\ | |
238 "pmaxsw %%mm4, %%mm6 \n\t" /* diff= MAX3(diff, min, -max); */\ | |
239 "1: \n\t"\ | |
240 \ | |
241 "movq %[tmp1], %%mm2 \n\t" /* d */\ | |
242 "movq %%mm2, %%mm3 \n\t"\ | |
243 "psubw %%mm6, %%mm2 \n\t" /* d-diff */\ | |
244 "paddw %%mm6, %%mm3 \n\t" /* d+diff */\ | |
245 "pmaxsw %%mm2, %%mm1 \n\t"\ | |
246 "pminsw %%mm3, %%mm1 \n\t" /* d = clip(spatial_pred, d-diff, d+diff); */\ | |
247 "packuswb %%mm1, %%mm1 \n\t"\ | |
248 \ | |
249 :[tmp0]"=m"(tmp0),\ | |
250 [tmp1]"=m"(tmp1),\ | |
251 [tmp2]"=m"(tmp2),\ | |
252 [tmp3]"=m"(tmp3)\ | |
253 :[prev] "r"(prev),\ | |
254 [cur] "r"(cur),\ | |
255 [next] "r"(next),\ | |
256 [prefs]"r"((long)refs),\ | |
257 [mrefs]"r"((long)-refs),\ | |
258 [pw1] "m"(pw_1),\ | |
259 [pb1] "m"(pb_1),\ | |
260 [mode] "g"(mode)\ | |
261 );\ | |
262 asm volatile("movd %%mm1, %0" :"=m"(*dst));\ | |
263 dst += 4;\ | |
264 prev+= 4;\ | |
265 cur += 4;\ | |
266 next+= 4;\ | |
267 } | |
268 | |
269 if(parity){ | |
270 #define prev2 "prev" | |
271 #define next2 "cur" | |
272 FILTER | |
273 #undef prev2 | |
274 #undef next2 | |
275 }else{ | |
276 #define prev2 "cur" | |
277 #define next2 "next" | |
278 FILTER | |
279 #undef prev2 | |
280 #undef next2 | |
281 } | |
282 } | |
283 #undef LOAD4 | |
284 #undef PABS | |
285 #undef CHECK | |
286 #undef CHECK1 | |
287 #undef CHECK2 | |
288 #undef FILTER | |
289 | |
19888
2ce14efa8917
Replace preprocessor hacks to work around compilers not supporting named
diego
parents:
19830
diff
changeset
|
290 #endif /* defined(HAVE_MMX) && defined(NAMED_ASM_ARGS) */ |
19830 | 291 |
292 static void filter_line_c(struct vf_priv_s *p, uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int refs, int parity){ | |
19828 | 293 int x; |
294 uint8_t *prev2= parity ? prev : cur ; | |
295 uint8_t *next2= parity ? cur : next; | |
19829 | 296 for(x=0; x<w; x++){ |
297 int c= cur[-refs]; | |
298 int d= (prev2[0] + next2[0])>>1; | |
299 int e= cur[+refs]; | |
300 int temporal_diff0= ABS(prev2[0] - next2[0]); | |
301 int temporal_diff1=( ABS(prev[-refs] - c) + ABS(prev[+refs] - e) )>>1; | |
302 int temporal_diff2=( ABS(next[-refs] - c) + ABS(next[+refs] - e) )>>1; | |
303 int diff= MAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); | |
304 int spatial_pred= (c+e)>>1; | |
305 int spatial_score= ABS(cur[-refs-1] - cur[+refs-1]) + ABS(c-e) | |
306 + ABS(cur[-refs+1] - cur[+refs+1]) - 1; | |
18621 | 307 |
18657 | 308 #define CHECK(j)\ |
309 { int score= ABS(cur[-refs-1+j] - cur[+refs-1-j])\ | |
310 + ABS(cur[-refs +j] - cur[+refs -j])\ | |
311 + ABS(cur[-refs+1+j] - cur[+refs+1-j]);\ | |
312 if(score < spatial_score){\ | |
313 spatial_score= score;\ | |
314 spatial_pred= (cur[-refs +j] + cur[+refs -j])>>1;\ | |
18608 | 315 |
19829 | 316 CHECK(-1) CHECK(-2) }} }} |
317 CHECK( 1) CHECK( 2) }} }} | |
18657 | 318 |
19829 | 319 if(p->mode<2){ |
320 int b= (prev2[-2*refs] + next2[-2*refs])>>1; | |
321 int f= (prev2[+2*refs] + next2[+2*refs])>>1; | |
18608 | 322 #if 0 |
19829 | 323 int a= cur[-3*refs]; |
324 int g= cur[+3*refs]; | |
325 int max= MAX3(d-e, d-c, MIN3(MAX(b-c,f-e),MAX(b-c,b-a),MAX(f-g,f-e)) ); | |
326 int min= MIN3(d-e, d-c, MAX3(MIN(b-c,f-e),MIN(b-c,b-a),MIN(f-g,f-e)) ); | |
18608 | 327 #else |
19829 | 328 int max= MAX3(d-e, d-c, MIN(b-c, f-e)); |
329 int min= MIN3(d-e, d-c, MAX(b-c, f-e)); | |
18608 | 330 #endif |
331 | |
19829 | 332 diff= MAX3(diff, min, -max); |
333 } | |
18608 | 334 |
19829 | 335 if(spatial_pred > d + diff) |
336 spatial_pred = d + diff; | |
337 else if(spatial_pred < d - diff) | |
338 spatial_pred = d - diff; | |
19828 | 339 |
19829 | 340 dst[0] = spatial_pred; |
19828 | 341 |
19829 | 342 dst++; |
343 cur++; | |
344 prev++; | |
345 next++; | |
346 prev2++; | |
347 next2++; | |
348 } | |
19828 | 349 } |
18608 | 350 |
19828 | 351 static void filter(struct vf_priv_s *p, uint8_t *dst[3], int dst_stride[3], int width, int height, int parity, int tff){ |
23381
300e9b7c499f
Remove some unused variables, patch by timwoj ieee org.
diego
parents:
22117
diff
changeset
|
352 int y, i; |
19828 | 353 |
354 for(i=0; i<3; i++){ | |
355 int is_chroma= !!i; | |
356 int w= width >>is_chroma; | |
357 int h= height>>is_chroma; | |
358 int refs= p->stride[i]; | |
359 | |
360 for(y=0; y<h; y++){ | |
361 if((y ^ parity) & 1){ | |
362 uint8_t *prev= &p->ref[0][i][y*refs]; | |
363 uint8_t *cur = &p->ref[1][i][y*refs]; | |
364 uint8_t *next= &p->ref[2][i][y*refs]; | |
365 uint8_t *dst2= &dst[i][y*dst_stride[i]]; | |
366 filter_line(p, dst2, prev, cur, next, w, refs, parity ^ tff); | |
18608 | 367 }else{ |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
23381
diff
changeset
|
368 fast_memcpy(&dst[i][y*dst_stride[i]], &p->ref[1][i][y*refs], w); |
18608 | 369 } |
370 } | |
371 } | |
19942
0983feab2dc2
Add forgotten emms which caused weird bugs like nan pts values.
reimar
parents:
19923
diff
changeset
|
372 #if defined(HAVE_MMX) && defined(NAMED_ASM_ARGS) |
0983feab2dc2
Add forgotten emms which caused weird bugs like nan pts values.
reimar
parents:
19923
diff
changeset
|
373 if(gCpuCaps.hasMMX2) asm volatile("emms \n\t" : : : "memory"); |
0983feab2dc2
Add forgotten emms which caused weird bugs like nan pts values.
reimar
parents:
19923
diff
changeset
|
374 #endif |
18608 | 375 } |
376 | |
377 static int config(struct vf_instance_s* vf, | |
378 int width, int height, int d_width, int d_height, | |
379 unsigned int flags, unsigned int outfmt){ | |
18625 | 380 int i, j; |
18608 | 381 |
382 for(i=0; i<3; i++){ | |
383 int is_chroma= !!i; | |
18625 | 384 int w= ((width + 31) & (~31))>>is_chroma; |
385 int h= ((height+6+ 31) & (~31))>>is_chroma; | |
18608 | 386 |
387 vf->priv->stride[i]= w; | |
18625 | 388 for(j=0; j<3; j++) |
389 vf->priv->ref[j][i]= malloc(w*h*sizeof(uint8_t))+3*w; | |
18608 | 390 } |
391 | |
392 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
393 } | |
394 | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
395 static int continue_buffered_image(struct vf_instance_s *vf); |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
396 extern int correct_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
397 |
18608 | 398 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
399 int tff; |
18608 | 400 |
401 if(vf->priv->parity < 0) { | |
402 if (mpi->fields & MP_IMGFIELD_ORDERED) | |
403 tff = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST); | |
404 else | |
405 tff = 1; | |
406 } | |
407 else tff = (vf->priv->parity&1)^1; | |
408 | |
18625 | 409 store_ref(vf->priv, mpi->planes, mpi->stride, mpi->w, mpi->h); |
410 | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
411 vf->priv->buffered_mpi = mpi; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
412 vf->priv->buffered_tff = tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
413 vf->priv->buffered_i = 0; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
414 vf->priv->buffered_pts = pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
415 |
22116 | 416 if(vf->priv->do_deinterlace == 0) |
417 return vf_next_put_image(vf, mpi, pts); | |
418 else if(vf->priv->do_deinterlace == 1){ | |
419 vf->priv->do_deinterlace= 2; | |
420 return 0; | |
421 }else | |
22117 | 422 return continue_buffered_image(vf); |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
423 } |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
424 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
425 static int continue_buffered_image(struct vf_instance_s *vf) |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
426 { |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
427 mp_image_t *mpi = vf->priv->buffered_mpi; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
428 int tff = vf->priv->buffered_tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
429 double pts = vf->priv->buffered_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
430 int i; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
431 int ret=0; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
432 mp_image_t *dmpi; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
433 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
434 pts += vf->priv->buffered_i * .02; // XXX not right |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
435 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
436 for(i = vf->priv->buffered_i; i<=(vf->priv->mode&1); i++){ |
18608 | 437 dmpi=vf_get_image(vf->next,mpi->imgfmt, |
438 MP_IMGTYPE_TEMP, | |
439 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
440 mpi->width,mpi->height); | |
441 vf_clone_mpi_attributes(dmpi, mpi); | |
18625 | 442 filter(vf->priv, dmpi->planes, dmpi->stride, mpi->w, mpi->h, i ^ tff ^ 1, tff); |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
443 if (correct_pts && i < (vf->priv->mode & 1)) |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
444 vf_queue_frame(vf, continue_buffered_image); |
18608 | 445 ret |= vf_next_put_image(vf, dmpi, pts /*FIXME*/); |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
446 if (correct_pts) |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
447 break; |
18626 | 448 if(i<(vf->priv->mode&1)) |
18608 | 449 vf_next_control(vf, VFCTRL_FLIP_PAGE, NULL); |
450 } | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
451 vf->priv->buffered_i = 1; |
18608 | 452 return ret; |
453 } | |
454 | |
455 static void uninit(struct vf_instance_s* vf){ | |
456 int i; | |
457 if(!vf->priv) return; | |
458 | |
18625 | 459 for(i=0; i<3*3; i++){ |
460 uint8_t **p= &vf->priv->ref[i%3][i/3]; | |
461 if(*p) free(*p - 3*vf->priv->stride[i/3]); | |
462 *p= NULL; | |
18608 | 463 } |
464 free(vf->priv); | |
465 vf->priv=NULL; | |
466 } | |
467 | |
468 //===========================================================================// | |
469 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
470 switch(fmt){ | |
471 case IMGFMT_YV12: | |
472 case IMGFMT_I420: | |
473 case IMGFMT_IYUV: | |
474 case IMGFMT_Y800: | |
475 case IMGFMT_Y8: | |
476 return vf_next_query_format(vf,fmt); | |
477 } | |
478 return 0; | |
479 } | |
480 | |
21060 | 481 static int control(struct vf_instance_s* vf, int request, void* data){ |
482 switch (request){ | |
483 case VFCTRL_GET_DEINTERLACE: | |
484 *(int*)data = vf->priv->do_deinterlace; | |
485 return CONTROL_OK; | |
486 case VFCTRL_SET_DEINTERLACE: | |
22116 | 487 vf->priv->do_deinterlace = 2*!!*(int*)data; |
21060 | 488 return CONTROL_OK; |
489 } | |
490 return vf_next_control (vf, request, data); | |
491 } | |
492 | |
18608 | 493 static int open(vf_instance_t *vf, char* args){ |
494 | |
495 vf->config=config; | |
496 vf->put_image=put_image; | |
497 vf->query_format=query_format; | |
498 vf->uninit=uninit; | |
499 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
21060 | 500 vf->control=control; |
18608 | 501 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
502 | |
503 vf->priv->mode=0; | |
504 vf->priv->parity= -1; | |
21060 | 505 vf->priv->do_deinterlace=1; |
18608 | 506 |
507 if (args) sscanf(args, "%d:%d", &vf->priv->mode, &vf->priv->parity); | |
508 | |
19830 | 509 filter_line = filter_line_c; |
19923
7dcd96645457
Fix compilation if HAVE_MMX is defined but NAMED_ASM_ARGS isn't
reimar
parents:
19888
diff
changeset
|
510 #if defined(HAVE_MMX) && defined(NAMED_ASM_ARGS) |
19830 | 511 if(gCpuCaps.hasMMX2) filter_line = filter_line_mmx2; |
512 #endif | |
513 | |
18608 | 514 return 1; |
515 } | |
516 | |
25221 | 517 const vf_info_t vf_info_yadif = { |
18608 | 518 "Yet Another DeInterlacing Filter", |
519 "yadif", | |
520 "Michael Niedermayer", | |
521 "", | |
522 open, | |
523 NULL | |
524 }; |