Mercurial > mplayer.hg
annotate libmpcodecs/vf_yadif.c @ 28987:d78fdafe0def
Fix build failure on x86_32 Mac OS X with PIC enabled
author | sdrik |
---|---|
date | Sat, 21 Mar 2009 12:16:32 +0000 |
parents | df67d03dde3b |
children | 963f578121c6 |
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 | |
28594
df67d03dde3b
Convert HAVE_MALLOC_H into a 0/1 definition, fixes the warning:
diego
parents:
28292
diff
changeset
|
32 #if HAVE_MALLOC_H |
18608 | 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" | |
27844
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
40 #include "libavutil/common.h" |
18608 | 41 |
42 //===========================================================================// | |
43 | |
44 struct vf_priv_s { | |
45 int mode; | |
46 int parity; | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
47 int buffered_i; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
48 int buffered_tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
49 double buffered_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
50 mp_image_t *buffered_mpi; |
18608 | 51 int stride[3]; |
18625 | 52 uint8_t *ref[4][3]; |
21060 | 53 int do_deinterlace; |
18608 | 54 }; |
55 | |
19830 | 56 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); |
57 | |
18608 | 58 static void store_ref(struct vf_priv_s *p, uint8_t *src[3], int src_stride[3], int width, int height){ |
59 int i; | |
60 | |
23458
973e53dc7df5
Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents:
23457
diff
changeset
|
61 memcpy (p->ref[3], p->ref[0], sizeof(uint8_t *)*3); |
18625 | 62 memmove(p->ref[0], p->ref[1], sizeof(uint8_t *)*3*3); |
18608 | 63 |
64 for(i=0; i<3; i++){ | |
65 int is_chroma= !!i; | |
66 | |
18625 | 67 memcpy_pic(p->ref[2][i], src[i], width>>is_chroma, height>>is_chroma, p->stride[i], src_stride[i]); |
18608 | 68 } |
69 } | |
70 | |
28292
d6001126678f
More #ifdef HAVE_MMX etc. missed by earlier search.
reimar
parents:
28174
diff
changeset
|
71 #if HAVE_MMX && defined(NAMED_ASM_ARGS) |
19830 | 72 |
73 #define LOAD4(mem,dst) \ | |
74 "movd "mem", "#dst" \n\t"\ | |
75 "punpcklbw %%mm7, "#dst" \n\t" | |
76 | |
77 #define PABS(tmp,dst) \ | |
78 "pxor "#tmp", "#tmp" \n\t"\ | |
79 "psubw "#dst", "#tmp" \n\t"\ | |
80 "pmaxsw "#tmp", "#dst" \n\t" | |
81 | |
82 #define CHECK(pj,mj) \ | |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
83 "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
|
84 "movq "#mj"(%[cur],%[prefs]), %%mm3 \n\t" /* cur[x+refs-1-j] */\ |
19830 | 85 "movq %%mm2, %%mm4 \n\t"\ |
86 "movq %%mm2, %%mm5 \n\t"\ | |
87 "pxor %%mm3, %%mm4 \n\t"\ | |
88 "pavgb %%mm3, %%mm5 \n\t"\ | |
89 "pand %[pb1], %%mm4 \n\t"\ | |
90 "psubusb %%mm4, %%mm5 \n\t"\ | |
91 "psrlq $8, %%mm5 \n\t"\ | |
92 "punpcklbw %%mm7, %%mm5 \n\t" /* (cur[x-refs+j] + cur[x+refs-j])>>1 */\ | |
93 "movq %%mm2, %%mm4 \n\t"\ | |
94 "psubusb %%mm3, %%mm2 \n\t"\ | |
95 "psubusb %%mm4, %%mm3 \n\t"\ | |
96 "pmaxub %%mm3, %%mm2 \n\t"\ | |
97 "movq %%mm2, %%mm3 \n\t"\ | |
98 "movq %%mm2, %%mm4 \n\t" /* ABS(cur[x-refs-1+j] - cur[x+refs-1-j]) */\ | |
99 "psrlq $8, %%mm3 \n\t" /* ABS(cur[x-refs +j] - cur[x+refs -j]) */\ | |
100 "psrlq $16, %%mm4 \n\t" /* ABS(cur[x-refs+1+j] - cur[x+refs+1-j]) */\ | |
101 "punpcklbw %%mm7, %%mm2 \n\t"\ | |
102 "punpcklbw %%mm7, %%mm3 \n\t"\ | |
103 "punpcklbw %%mm7, %%mm4 \n\t"\ | |
104 "paddw %%mm3, %%mm2 \n\t"\ | |
105 "paddw %%mm4, %%mm2 \n\t" /* score */ | |
106 | |
107 #define CHECK1 \ | |
108 "movq %%mm0, %%mm3 \n\t"\ | |
109 "pcmpgtw %%mm2, %%mm3 \n\t" /* if(score < spatial_score) */\ | |
110 "pminsw %%mm2, %%mm0 \n\t" /* spatial_score= score; */\ | |
111 "movq %%mm3, %%mm6 \n\t"\ | |
112 "pand %%mm3, %%mm5 \n\t"\ | |
113 "pandn %%mm1, %%mm3 \n\t"\ | |
114 "por %%mm5, %%mm3 \n\t"\ | |
115 "movq %%mm3, %%mm1 \n\t" /* spatial_pred= (cur[x-refs+j] + cur[x+refs-j])>>1; */ | |
116 | |
117 #define CHECK2 /* pretend not to have checked dir=2 if dir=1 was bad.\ | |
118 hurts both quality and speed, but matches the C version. */\ | |
119 "paddw %[pw1], %%mm6 \n\t"\ | |
120 "psllw $14, %%mm6 \n\t"\ | |
121 "paddsw %%mm6, %%mm2 \n\t"\ | |
122 "movq %%mm0, %%mm3 \n\t"\ | |
123 "pcmpgtw %%mm2, %%mm3 \n\t"\ | |
124 "pminsw %%mm2, %%mm0 \n\t"\ | |
125 "pand %%mm3, %%mm5 \n\t"\ | |
126 "pandn %%mm1, %%mm3 \n\t"\ | |
127 "por %%mm5, %%mm3 \n\t"\ | |
128 "movq %%mm3, %%mm1 \n\t" | |
129 | |
130 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){ | |
131 static const uint64_t pw_1 = 0x0001000100010001ULL; | |
132 static const uint64_t pb_1 = 0x0101010101010101ULL; | |
133 const int mode = p->mode; | |
134 uint64_t tmp0, tmp1, tmp2, tmp3; | |
135 int x; | |
136 | |
137 #define FILTER\ | |
138 for(x=0; x<w; x+=4){\ | |
27754
08d18fe9da52
Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents:
26727
diff
changeset
|
139 __asm__ volatile(\ |
19830 | 140 "pxor %%mm7, %%mm7 \n\t"\ |
141 LOAD4("(%[cur],%[mrefs])", %%mm0) /* c = cur[x-refs] */\ | |
142 LOAD4("(%[cur],%[prefs])", %%mm1) /* e = cur[x+refs] */\ | |
143 LOAD4("(%["prev2"])", %%mm2) /* prev2[x] */\ | |
144 LOAD4("(%["next2"])", %%mm3) /* next2[x] */\ | |
145 "movq %%mm3, %%mm4 \n\t"\ | |
146 "paddw %%mm2, %%mm3 \n\t"\ | |
147 "psraw $1, %%mm3 \n\t" /* d = (prev2[x] + next2[x])>>1 */\ | |
148 "movq %%mm0, %[tmp0] \n\t" /* c */\ | |
149 "movq %%mm3, %[tmp1] \n\t" /* d */\ | |
150 "movq %%mm1, %[tmp2] \n\t" /* e */\ | |
151 "psubw %%mm4, %%mm2 \n\t"\ | |
152 PABS( %%mm4, %%mm2) /* temporal_diff0 */\ | |
153 LOAD4("(%[prev],%[mrefs])", %%mm3) /* prev[x-refs] */\ | |
154 LOAD4("(%[prev],%[prefs])", %%mm4) /* prev[x+refs] */\ | |
155 "psubw %%mm0, %%mm3 \n\t"\ | |
156 "psubw %%mm1, %%mm4 \n\t"\ | |
157 PABS( %%mm5, %%mm3)\ | |
158 PABS( %%mm5, %%mm4)\ | |
159 "paddw %%mm4, %%mm3 \n\t" /* temporal_diff1 */\ | |
160 "psrlw $1, %%mm2 \n\t"\ | |
161 "psrlw $1, %%mm3 \n\t"\ | |
162 "pmaxsw %%mm3, %%mm2 \n\t"\ | |
163 LOAD4("(%[next],%[mrefs])", %%mm3) /* next[x-refs] */\ | |
164 LOAD4("(%[next],%[prefs])", %%mm4) /* next[x+refs] */\ | |
165 "psubw %%mm0, %%mm3 \n\t"\ | |
166 "psubw %%mm1, %%mm4 \n\t"\ | |
167 PABS( %%mm5, %%mm3)\ | |
168 PABS( %%mm5, %%mm4)\ | |
169 "paddw %%mm4, %%mm3 \n\t" /* temporal_diff2 */\ | |
170 "psrlw $1, %%mm3 \n\t"\ | |
171 "pmaxsw %%mm3, %%mm2 \n\t"\ | |
172 "movq %%mm2, %[tmp3] \n\t" /* diff */\ | |
173 \ | |
174 "paddw %%mm0, %%mm1 \n\t"\ | |
175 "paddw %%mm0, %%mm0 \n\t"\ | |
176 "psubw %%mm1, %%mm0 \n\t"\ | |
177 "psrlw $1, %%mm1 \n\t" /* spatial_pred */\ | |
178 PABS( %%mm2, %%mm0) /* ABS(c-e) */\ | |
179 \ | |
180 "movq -1(%[cur],%[mrefs]), %%mm2 \n\t" /* cur[x-refs-1] */\ | |
181 "movq -1(%[cur],%[prefs]), %%mm3 \n\t" /* cur[x+refs-1] */\ | |
182 "movq %%mm2, %%mm4 \n\t"\ | |
183 "psubusb %%mm3, %%mm2 \n\t"\ | |
184 "psubusb %%mm4, %%mm3 \n\t"\ | |
185 "pmaxub %%mm3, %%mm2 \n\t"\ | |
186 "pshufw $9,%%mm2, %%mm3 \n\t"\ | |
187 "punpcklbw %%mm7, %%mm2 \n\t" /* ABS(cur[x-refs-1] - cur[x+refs-1]) */\ | |
188 "punpcklbw %%mm7, %%mm3 \n\t" /* ABS(cur[x-refs+1] - cur[x+refs+1]) */\ | |
189 "paddw %%mm2, %%mm0 \n\t"\ | |
190 "paddw %%mm3, %%mm0 \n\t"\ | |
191 "psubw %[pw1], %%mm0 \n\t" /* spatial_score */\ | |
192 \ | |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
193 CHECK(-2,0)\ |
19830 | 194 CHECK1\ |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
195 CHECK(-3,1)\ |
19830 | 196 CHECK2\ |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
197 CHECK(0,-2)\ |
19830 | 198 CHECK1\ |
20010
5ae0a24fbed8
Compile fix for odd versions of binutils, namely the ones in Fedora.
gpoirier
parents:
19942
diff
changeset
|
199 CHECK(1,-3)\ |
19830 | 200 CHECK2\ |
201 \ | |
202 /* if(p->mode<2) ... */\ | |
203 "movq %[tmp3], %%mm6 \n\t" /* diff */\ | |
204 "cmp $2, %[mode] \n\t"\ | |
205 "jge 1f \n\t"\ | |
206 LOAD4("(%["prev2"],%[mrefs],2)", %%mm2) /* prev2[x-2*refs] */\ | |
207 LOAD4("(%["next2"],%[mrefs],2)", %%mm4) /* next2[x-2*refs] */\ | |
208 LOAD4("(%["prev2"],%[prefs],2)", %%mm3) /* prev2[x+2*refs] */\ | |
209 LOAD4("(%["next2"],%[prefs],2)", %%mm5) /* next2[x+2*refs] */\ | |
210 "paddw %%mm4, %%mm2 \n\t"\ | |
211 "paddw %%mm5, %%mm3 \n\t"\ | |
212 "psrlw $1, %%mm2 \n\t" /* b */\ | |
213 "psrlw $1, %%mm3 \n\t" /* f */\ | |
214 "movq %[tmp0], %%mm4 \n\t" /* c */\ | |
215 "movq %[tmp1], %%mm5 \n\t" /* d */\ | |
216 "movq %[tmp2], %%mm7 \n\t" /* e */\ | |
217 "psubw %%mm4, %%mm2 \n\t" /* b-c */\ | |
218 "psubw %%mm7, %%mm3 \n\t" /* f-e */\ | |
219 "movq %%mm5, %%mm0 \n\t"\ | |
220 "psubw %%mm4, %%mm5 \n\t" /* d-c */\ | |
221 "psubw %%mm7, %%mm0 \n\t" /* d-e */\ | |
222 "movq %%mm2, %%mm4 \n\t"\ | |
223 "pminsw %%mm3, %%mm2 \n\t"\ | |
224 "pmaxsw %%mm4, %%mm3 \n\t"\ | |
225 "pmaxsw %%mm5, %%mm2 \n\t"\ | |
226 "pminsw %%mm5, %%mm3 \n\t"\ | |
227 "pmaxsw %%mm0, %%mm2 \n\t" /* max */\ | |
228 "pminsw %%mm0, %%mm3 \n\t" /* min */\ | |
229 "pxor %%mm4, %%mm4 \n\t"\ | |
230 "pmaxsw %%mm3, %%mm6 \n\t"\ | |
231 "psubw %%mm2, %%mm4 \n\t" /* -max */\ | |
232 "pmaxsw %%mm4, %%mm6 \n\t" /* diff= MAX3(diff, min, -max); */\ | |
233 "1: \n\t"\ | |
234 \ | |
235 "movq %[tmp1], %%mm2 \n\t" /* d */\ | |
236 "movq %%mm2, %%mm3 \n\t"\ | |
237 "psubw %%mm6, %%mm2 \n\t" /* d-diff */\ | |
238 "paddw %%mm6, %%mm3 \n\t" /* d+diff */\ | |
239 "pmaxsw %%mm2, %%mm1 \n\t"\ | |
240 "pminsw %%mm3, %%mm1 \n\t" /* d = clip(spatial_pred, d-diff, d+diff); */\ | |
241 "packuswb %%mm1, %%mm1 \n\t"\ | |
242 \ | |
243 :[tmp0]"=m"(tmp0),\ | |
244 [tmp1]"=m"(tmp1),\ | |
245 [tmp2]"=m"(tmp2),\ | |
246 [tmp3]"=m"(tmp3)\ | |
247 :[prev] "r"(prev),\ | |
248 [cur] "r"(cur),\ | |
249 [next] "r"(next),\ | |
250 [prefs]"r"((long)refs),\ | |
251 [mrefs]"r"((long)-refs),\ | |
252 [pw1] "m"(pw_1),\ | |
253 [pb1] "m"(pb_1),\ | |
254 [mode] "g"(mode)\ | |
255 );\ | |
27754
08d18fe9da52
Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents:
26727
diff
changeset
|
256 __asm__ volatile("movd %%mm1, %0" :"=m"(*dst));\ |
19830 | 257 dst += 4;\ |
258 prev+= 4;\ | |
259 cur += 4;\ | |
260 next+= 4;\ | |
261 } | |
262 | |
263 if(parity){ | |
264 #define prev2 "prev" | |
265 #define next2 "cur" | |
266 FILTER | |
267 #undef prev2 | |
268 #undef next2 | |
269 }else{ | |
270 #define prev2 "cur" | |
271 #define next2 "next" | |
272 FILTER | |
273 #undef prev2 | |
274 #undef next2 | |
275 } | |
276 } | |
277 #undef LOAD4 | |
278 #undef PABS | |
279 #undef CHECK | |
280 #undef CHECK1 | |
281 #undef CHECK2 | |
282 #undef FILTER | |
283 | |
28292
d6001126678f
More #ifdef HAVE_MMX etc. missed by earlier search.
reimar
parents:
28174
diff
changeset
|
284 #endif /* HAVE_MMX && defined(NAMED_ASM_ARGS) */ |
19830 | 285 |
286 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 | 287 int x; |
288 uint8_t *prev2= parity ? prev : cur ; | |
289 uint8_t *next2= parity ? cur : next; | |
19829 | 290 for(x=0; x<w; x++){ |
291 int c= cur[-refs]; | |
292 int d= (prev2[0] + next2[0])>>1; | |
293 int e= cur[+refs]; | |
27844
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
294 int temporal_diff0= FFABS(prev2[0] - next2[0]); |
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
295 int temporal_diff1=( FFABS(prev[-refs] - c) + FFABS(prev[+refs] - e) )>>1; |
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
296 int temporal_diff2=( FFABS(next[-refs] - c) + FFABS(next[+refs] - e) )>>1; |
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
297 int diff= FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); |
19829 | 298 int spatial_pred= (c+e)>>1; |
27844
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
299 int spatial_score= FFABS(cur[-refs-1] - cur[+refs-1]) + FFABS(c-e) |
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
300 + FFABS(cur[-refs+1] - cur[+refs+1]) - 1; |
18621 | 301 |
18657 | 302 #define CHECK(j)\ |
27844
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
303 { int score= FFABS(cur[-refs-1+j] - cur[+refs-1-j])\ |
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
304 + FFABS(cur[-refs +j] - cur[+refs -j])\ |
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
305 + FFABS(cur[-refs+1+j] - cur[+refs+1-j]);\ |
18657 | 306 if(score < spatial_score){\ |
307 spatial_score= score;\ | |
308 spatial_pred= (cur[-refs +j] + cur[+refs -j])>>1;\ | |
18608 | 309 |
19829 | 310 CHECK(-1) CHECK(-2) }} }} |
311 CHECK( 1) CHECK( 2) }} }} | |
18657 | 312 |
19829 | 313 if(p->mode<2){ |
314 int b= (prev2[-2*refs] + next2[-2*refs])>>1; | |
315 int f= (prev2[+2*refs] + next2[+2*refs])>>1; | |
18608 | 316 #if 0 |
19829 | 317 int a= cur[-3*refs]; |
318 int g= cur[+3*refs]; | |
27844
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
319 int max= FFMAX3(d-e, d-c, FFMIN3(FFMAX(b-c,f-e),FFMAX(b-c,b-a),FFMAX(f-g,f-e)) ); |
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
320 int min= FFMIN3(d-e, d-c, FFMAX3(FFMIN(b-c,f-e),FFMIN(b-c,b-a),FFMIN(f-g,f-e)) ); |
18608 | 321 #else |
27844
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
322 int max= FFMAX3(d-e, d-c, FFMIN(b-c, f-e)); |
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
323 int min= FFMIN3(d-e, d-c, FFMAX(b-c, f-e)); |
18608 | 324 #endif |
325 | |
27844
ad60e4aee053
Use libavutil FFMIN etc. instead of defining our own variants.
reimar
parents:
27754
diff
changeset
|
326 diff= FFMAX3(diff, min, -max); |
19829 | 327 } |
18608 | 328 |
19829 | 329 if(spatial_pred > d + diff) |
330 spatial_pred = d + diff; | |
331 else if(spatial_pred < d - diff) | |
332 spatial_pred = d - diff; | |
19828 | 333 |
19829 | 334 dst[0] = spatial_pred; |
19828 | 335 |
19829 | 336 dst++; |
337 cur++; | |
338 prev++; | |
339 next++; | |
340 prev2++; | |
341 next2++; | |
342 } | |
19828 | 343 } |
18608 | 344 |
19828 | 345 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
|
346 int y, i; |
19828 | 347 |
348 for(i=0; i<3; i++){ | |
349 int is_chroma= !!i; | |
350 int w= width >>is_chroma; | |
351 int h= height>>is_chroma; | |
352 int refs= p->stride[i]; | |
353 | |
354 for(y=0; y<h; y++){ | |
355 if((y ^ parity) & 1){ | |
356 uint8_t *prev= &p->ref[0][i][y*refs]; | |
357 uint8_t *cur = &p->ref[1][i][y*refs]; | |
358 uint8_t *next= &p->ref[2][i][y*refs]; | |
359 uint8_t *dst2= &dst[i][y*dst_stride[i]]; | |
360 filter_line(p, dst2, prev, cur, next, w, refs, parity ^ tff); | |
18608 | 361 }else{ |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
23381
diff
changeset
|
362 fast_memcpy(&dst[i][y*dst_stride[i]], &p->ref[1][i][y*refs], w); |
18608 | 363 } |
364 } | |
365 } | |
28292
d6001126678f
More #ifdef HAVE_MMX etc. missed by earlier search.
reimar
parents:
28174
diff
changeset
|
366 #if HAVE_MMX && defined(NAMED_ASM_ARGS) |
27754
08d18fe9da52
Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents:
26727
diff
changeset
|
367 if(gCpuCaps.hasMMX2) __asm__ volatile("emms \n\t" : : : "memory"); |
19942
0983feab2dc2
Add forgotten emms which caused weird bugs like nan pts values.
reimar
parents:
19923
diff
changeset
|
368 #endif |
18608 | 369 } |
370 | |
371 static int config(struct vf_instance_s* vf, | |
372 int width, int height, int d_width, int d_height, | |
373 unsigned int flags, unsigned int outfmt){ | |
18625 | 374 int i, j; |
18608 | 375 |
376 for(i=0; i<3; i++){ | |
377 int is_chroma= !!i; | |
18625 | 378 int w= ((width + 31) & (~31))>>is_chroma; |
379 int h= ((height+6+ 31) & (~31))>>is_chroma; | |
18608 | 380 |
381 vf->priv->stride[i]= w; | |
18625 | 382 for(j=0; j<3; j++) |
383 vf->priv->ref[j][i]= malloc(w*h*sizeof(uint8_t))+3*w; | |
18608 | 384 } |
385 | |
386 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
387 } | |
388 | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
389 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
|
390 extern int correct_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
391 |
18608 | 392 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
|
393 int tff; |
18608 | 394 |
395 if(vf->priv->parity < 0) { | |
396 if (mpi->fields & MP_IMGFIELD_ORDERED) | |
397 tff = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST); | |
398 else | |
399 tff = 1; | |
400 } | |
401 else tff = (vf->priv->parity&1)^1; | |
402 | |
18625 | 403 store_ref(vf->priv, mpi->planes, mpi->stride, mpi->w, mpi->h); |
404 | |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
405 vf->priv->buffered_mpi = mpi; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
406 vf->priv->buffered_tff = tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
407 vf->priv->buffered_i = 0; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
408 vf->priv->buffered_pts = pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
409 |
22116 | 410 if(vf->priv->do_deinterlace == 0) |
411 return vf_next_put_image(vf, mpi, pts); | |
412 else if(vf->priv->do_deinterlace == 1){ | |
413 vf->priv->do_deinterlace= 2; | |
414 return 0; | |
415 }else | |
22117 | 416 return continue_buffered_image(vf); |
18917
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 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
419 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
|
420 { |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
421 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
|
422 int tff = vf->priv->buffered_tff; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
423 double pts = vf->priv->buffered_pts; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
424 int i; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
425 int ret=0; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
426 mp_image_t *dmpi; |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
427 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
428 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
|
429 |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
430 for(i = vf->priv->buffered_i; i<=(vf->priv->mode&1); i++){ |
18608 | 431 dmpi=vf_get_image(vf->next,mpi->imgfmt, |
432 MP_IMGTYPE_TEMP, | |
433 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
434 mpi->width,mpi->height); | |
435 vf_clone_mpi_attributes(dmpi, mpi); | |
18625 | 436 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
|
437 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
|
438 vf_queue_frame(vf, continue_buffered_image); |
18608 | 439 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
|
440 if (correct_pts) |
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
441 break; |
18626 | 442 if(i<(vf->priv->mode&1)) |
28174 | 443 vf_extra_flip(vf); |
18608 | 444 } |
18917
d9a75b26da6c
Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents:
18657
diff
changeset
|
445 vf->priv->buffered_i = 1; |
18608 | 446 return ret; |
447 } | |
448 | |
449 static void uninit(struct vf_instance_s* vf){ | |
450 int i; | |
451 if(!vf->priv) return; | |
452 | |
18625 | 453 for(i=0; i<3*3; i++){ |
454 uint8_t **p= &vf->priv->ref[i%3][i/3]; | |
455 if(*p) free(*p - 3*vf->priv->stride[i/3]); | |
456 *p= NULL; | |
18608 | 457 } |
458 free(vf->priv); | |
459 vf->priv=NULL; | |
460 } | |
461 | |
462 //===========================================================================// | |
463 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
464 switch(fmt){ | |
465 case IMGFMT_YV12: | |
466 case IMGFMT_I420: | |
467 case IMGFMT_IYUV: | |
468 case IMGFMT_Y800: | |
469 case IMGFMT_Y8: | |
470 return vf_next_query_format(vf,fmt); | |
471 } | |
472 return 0; | |
473 } | |
474 | |
21060 | 475 static int control(struct vf_instance_s* vf, int request, void* data){ |
476 switch (request){ | |
477 case VFCTRL_GET_DEINTERLACE: | |
478 *(int*)data = vf->priv->do_deinterlace; | |
479 return CONTROL_OK; | |
480 case VFCTRL_SET_DEINTERLACE: | |
22116 | 481 vf->priv->do_deinterlace = 2*!!*(int*)data; |
21060 | 482 return CONTROL_OK; |
483 } | |
484 return vf_next_control (vf, request, data); | |
485 } | |
486 | |
18608 | 487 static int open(vf_instance_t *vf, char* args){ |
488 | |
489 vf->config=config; | |
490 vf->put_image=put_image; | |
491 vf->query_format=query_format; | |
492 vf->uninit=uninit; | |
493 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
21060 | 494 vf->control=control; |
18608 | 495 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
496 | |
497 vf->priv->mode=0; | |
498 vf->priv->parity= -1; | |
21060 | 499 vf->priv->do_deinterlace=1; |
18608 | 500 |
501 if (args) sscanf(args, "%d:%d", &vf->priv->mode, &vf->priv->parity); | |
502 | |
19830 | 503 filter_line = filter_line_c; |
28292
d6001126678f
More #ifdef HAVE_MMX etc. missed by earlier search.
reimar
parents:
28174
diff
changeset
|
504 #if HAVE_MMX && defined(NAMED_ASM_ARGS) |
19830 | 505 if(gCpuCaps.hasMMX2) filter_line = filter_line_mmx2; |
506 #endif | |
507 | |
18608 | 508 return 1; |
509 } | |
510 | |
25221 | 511 const vf_info_t vf_info_yadif = { |
18608 | 512 "Yet Another DeInterlacing Filter", |
513 "yadif", | |
514 "Michael Niedermayer", | |
515 "", | |
516 open, | |
517 NULL | |
518 }; |