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