annotate libmpcodecs/vf_yadif.c @ 19829:4f4a58a3fba8

cosmetics (indentation)
author lorenm
date Thu, 14 Sep 2006 03:59:48 +0000
parents 1d5832b4b204
children a1a997376658
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
1 /*
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
2 Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
3
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
7 (at your option) any later version.
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
8
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
12 GNU General Public License for more details.
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
13
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
15 along with this program; if not, write to the Free Software
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
17 */
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
18
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
19 #include <stdio.h>
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
20 #include <stdlib.h>
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
21 #include <string.h>
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
22 #include <inttypes.h>
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
23 #include <math.h>
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
24
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
25 #include "config.h"
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
26
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
27 #include "mp_msg.h"
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
28
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
29 #ifdef HAVE_MALLOC_H
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
30 #include <malloc.h>
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
31 #endif
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
32
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
33 #include "img_format.h"
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
34 #include "mp_image.h"
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
35 #include "vf.h"
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
36 #include "libvo/fastmemcpy.h"
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
37
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
38 #define MIN(a,b) ((a) > (b) ? (b) : (a))
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
39 #define MAX(a,b) ((a) < (b) ? (b) : (a))
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
40 #define ABS(a) ((a) > 0 ? (a) : (-(a)))
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
41
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
42 #define MIN3(a,b,c) MIN(MIN(a,b),c)
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
43 #define MAX3(a,b,c) MAX(MAX(a,b),c)
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
44
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
45 //===========================================================================//
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
46
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
47 struct vf_priv_s {
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
48 int mode;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
49 int parity;
18917
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
50 int buffered_i;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
51 int buffered_tff;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
52 double buffered_pts;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
53 mp_image_t *buffered_mpi;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
54 int stride[3];
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
55 uint8_t *ref[4][3];
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
56 };
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
57
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
58 static void store_ref(struct vf_priv_s *p, uint8_t *src[3], int src_stride[3], int width, int height){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
59 int i;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
60
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
61 memcpy (p->ref[3], p->ref[0], sizeof(uint8_t *)*3);
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
62 memmove(p->ref[0], p->ref[1], sizeof(uint8_t *)*3*3);
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
63
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
64 for(i=0; i<3; i++){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
65 int is_chroma= !!i;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
66
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
67 memcpy_pic(p->ref[2][i], src[i], width>>is_chroma, height>>is_chroma, p->stride[i], src_stride[i]);
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
68 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
69 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
70
19828
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
71 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){
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
72 int x;
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
73 uint8_t *prev2= parity ? prev : cur ;
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
74 uint8_t *next2= parity ? cur : next;
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
75 for(x=0; x<w; x++){
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
76 int c= cur[-refs];
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
77 int d= (prev2[0] + next2[0])>>1;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
78 int e= cur[+refs];
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
79 int temporal_diff0= ABS(prev2[0] - next2[0]);
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
80 int temporal_diff1=( ABS(prev[-refs] - c) + ABS(prev[+refs] - e) )>>1;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
81 int temporal_diff2=( ABS(next[-refs] - c) + ABS(next[+refs] - e) )>>1;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
82 int diff= MAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2);
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
83 int spatial_pred= (c+e)>>1;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
84 int spatial_score= ABS(cur[-refs-1] - cur[+refs-1]) + ABS(c-e)
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
85 + ABS(cur[-refs+1] - cur[+refs+1]) - 1;
18621
0001a9a9f1a9 cleanup
michael
parents: 18610
diff changeset
86
18657
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
87 #define CHECK(j)\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
88 { int score= ABS(cur[-refs-1+j] - cur[+refs-1-j])\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
89 + ABS(cur[-refs +j] - cur[+refs -j])\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
90 + ABS(cur[-refs+1+j] - cur[+refs+1-j]);\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
91 if(score < spatial_score){\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
92 spatial_score= score;\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
93 spatial_pred= (cur[-refs +j] + cur[+refs -j])>>1;\
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
94
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
95 CHECK(-1) CHECK(-2) }} }}
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
96 CHECK( 1) CHECK( 2) }} }}
18657
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
97
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
98 if(p->mode<2){
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
99 int b= (prev2[-2*refs] + next2[-2*refs])>>1;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
100 int f= (prev2[+2*refs] + next2[+2*refs])>>1;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
101 #if 0
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
102 int a= cur[-3*refs];
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
103 int g= cur[+3*refs];
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
104 int max= MAX3(d-e, d-c, MIN3(MAX(b-c,f-e),MAX(b-c,b-a),MAX(f-g,f-e)) );
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
105 int min= MIN3(d-e, d-c, MAX3(MIN(b-c,f-e),MIN(b-c,b-a),MIN(f-g,f-e)) );
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
106 #else
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
107 int max= MAX3(d-e, d-c, MIN(b-c, f-e));
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
108 int min= MIN3(d-e, d-c, MAX(b-c, f-e));
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
109 #endif
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
110
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
111 diff= MAX3(diff, min, -max);
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
112 }
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
113
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
114 if(spatial_pred > d + diff)
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
115 spatial_pred = d + diff;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
116 else if(spatial_pred < d - diff)
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
117 spatial_pred = d - diff;
19828
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
118
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
119 dst[0] = spatial_pred;
19828
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
120
19829
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
121 dst++;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
122 cur++;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
123 prev++;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
124 next++;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
125 prev2++;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
126 next2++;
4f4a58a3fba8 cosmetics (indentation)
lorenm
parents: 19828
diff changeset
127 }
19828
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
128 }
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
129
19828
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
130 static void filter(struct vf_priv_s *p, uint8_t *dst[3], int dst_stride[3], int width, int height, int parity, int tff){
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
131 int x, y, i;
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
132
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
133 for(i=0; i<3; i++){
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
134 int is_chroma= !!i;
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
135 int w= width >>is_chroma;
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
136 int h= height>>is_chroma;
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
137 int refs= p->stride[i];
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
138
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
139 for(y=0; y<h; y++){
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
140 if((y ^ parity) & 1){
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
141 uint8_t *prev= &p->ref[0][i][y*refs];
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
142 uint8_t *cur = &p->ref[1][i][y*refs];
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
143 uint8_t *next= &p->ref[2][i][y*refs];
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
144 uint8_t *dst2= &dst[i][y*dst_stride[i]];
1d5832b4b204 cosmetics
lorenm
parents: 18917
diff changeset
145 filter_line(p, dst2, prev, cur, next, w, refs, parity ^ tff);
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
146 }else{
18610
e0df832235c6 simplify
michael
parents: 18608
diff changeset
147 memcpy(&dst[i][y*dst_stride[i]], &p->ref[1][i][y*refs], w);
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
148 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
149 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
150 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
151 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
152
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
153 static int config(struct vf_instance_s* vf,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
154 int width, int height, int d_width, int d_height,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
155 unsigned int flags, unsigned int outfmt){
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
156 int i, j;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
157
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
158 for(i=0; i<3; i++){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
159 int is_chroma= !!i;
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
160 int w= ((width + 31) & (~31))>>is_chroma;
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
161 int h= ((height+6+ 31) & (~31))>>is_chroma;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
162
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
163 vf->priv->stride[i]= w;
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
164 for(j=0; j<3; j++)
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
165 vf->priv->ref[j][i]= malloc(w*h*sizeof(uint8_t))+3*w;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
166 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
167
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
168 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
169 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
170
18917
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
171 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
172 extern int correct_pts;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
173
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
174 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
175 int tff;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
176
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
177 if(vf->priv->parity < 0) {
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
178 if (mpi->fields & MP_IMGFIELD_ORDERED)
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
179 tff = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
180 else
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
181 tff = 1;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
182 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
183 else tff = (vf->priv->parity&1)^1;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
184
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
185 store_ref(vf->priv, mpi->planes, mpi->stride, mpi->w, mpi->h);
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
186
18917
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
187 vf->priv->buffered_mpi = mpi;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
188 vf->priv->buffered_tff = tff;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
189 vf->priv->buffered_i = 0;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
190 vf->priv->buffered_pts = pts;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
191
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
192 return continue_buffered_image(vf);
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
193 }
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
194
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
195 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
196 {
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
197 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
198 int tff = vf->priv->buffered_tff;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
199 double pts = vf->priv->buffered_pts;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
200 int i;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
201 int ret=0;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
202 mp_image_t *dmpi;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
203
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
204 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
205
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
206 for(i = vf->priv->buffered_i; i<=(vf->priv->mode&1); i++){
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
207 dmpi=vf_get_image(vf->next,mpi->imgfmt,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
208 MP_IMGTYPE_TEMP,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
209 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
210 mpi->width,mpi->height);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
211 vf_clone_mpi_attributes(dmpi, mpi);
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
212 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
213 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
214 vf_queue_frame(vf, continue_buffered_image);
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
215 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
216 if (correct_pts)
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
217 break;
18626
2e2b8f34a69e make spatial interlacing check optional
michael
parents: 18625
diff changeset
218 if(i<(vf->priv->mode&1))
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
219 vf_next_control(vf, VFCTRL_FLIP_PAGE, NULL);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
220 }
18917
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
221 vf->priv->buffered_i = 1;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
222 return ret;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
223 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
224
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
225 static void uninit(struct vf_instance_s* vf){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
226 int i;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
227 if(!vf->priv) return;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
228
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
229 for(i=0; i<3*3; i++){
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
230 uint8_t **p= &vf->priv->ref[i%3][i/3];
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
231 if(*p) free(*p - 3*vf->priv->stride[i/3]);
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
232 *p= NULL;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
233 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
234 free(vf->priv);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
235 vf->priv=NULL;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
236 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
237
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
238 //===========================================================================//
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
239 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
240 switch(fmt){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
241 case IMGFMT_YV12:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
242 case IMGFMT_I420:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
243 case IMGFMT_IYUV:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
244 case IMGFMT_Y800:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
245 case IMGFMT_Y8:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
246 return vf_next_query_format(vf,fmt);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
247 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
248 return 0;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
249 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
250
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
251 static int open(vf_instance_t *vf, char* args){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
252
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
253 vf->config=config;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
254 vf->put_image=put_image;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
255 vf->query_format=query_format;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
256 vf->uninit=uninit;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
257 vf->priv=malloc(sizeof(struct vf_priv_s));
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
258 memset(vf->priv, 0, sizeof(struct vf_priv_s));
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
259
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
260 vf->priv->mode=0;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
261 vf->priv->parity= -1;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
262
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
263 if (args) sscanf(args, "%d:%d", &vf->priv->mode, &vf->priv->parity);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
264
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
265 return 1;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
266 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
267
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
268 vf_info_t vf_info_yadif = {
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
269 "Yet Another DeInterlacing Filter",
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
270 "yadif",
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
271 "Michael Niedermayer",
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
272 "",
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
273 open,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
274 NULL
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
275 };