annotate libmpcodecs/vf_yadif.c @ 19779:5fb8e4ffb34b

keypad 7 returns to nearest dvdnav menu
author nicodvb
date Sun, 10 Sep 2006 10:39:10 +0000
parents d9a75b26da6c
children 1d5832b4b204
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
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
71 static void filter(struct vf_priv_s *p, uint8_t *dst[3], int dst_stride[3], int width, int height, int parity, int tff){
18657
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
72 int x, y, i;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
73
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
74 for(i=0; i<3; i++){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
75 int is_chroma= !!i;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
76 int w= width >>is_chroma;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
77 int h= height>>is_chroma;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
78 int refs= p->stride[i];
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
79
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
80 for(y=0; y<h; y++){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
81 if((y ^ parity) & 1){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
82 for(x=0; x<w; x++){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
83 uint8_t *prev= &p->ref[0][i][x + y*refs];
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
84 uint8_t *cur = &p->ref[1][i][x + y*refs];
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
85 uint8_t *next= &p->ref[2][i][x + y*refs];
18621
0001a9a9f1a9 cleanup
michael
parents: 18610
diff changeset
86 uint8_t *prev2= (tff ^ parity) ? prev : cur ;
0001a9a9f1a9 cleanup
michael
parents: 18610
diff changeset
87 uint8_t *next2= (tff ^ parity) ? cur : next;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
88
18623
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
89 int c= cur[-refs];
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
90 int d= (prev2[0] + next2[0])>>1;
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
91 int e= cur[+refs];
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
92 int temporal_diff0= ABS(prev2[0] - next2[0]);
18623
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
93 int temporal_diff1=( ABS(prev[-refs] - c) + ABS(prev[+refs] - e) )>>1;
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
94 int temporal_diff2=( ABS(next[-refs] - c) + ABS(next[+refs] - e) )>>1;
18610
e0df832235c6 simplify
michael
parents: 18608
diff changeset
95 int diff= MAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2);
18623
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
96 int spatial_pred= (c+e)>>1;
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
97 int spatial_score= ABS(cur[-refs-1] - cur[+refs-1]) + ABS(c-e)
18657
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
98 + ABS(cur[-refs+1] - cur[+refs+1]) - 1;
18621
0001a9a9f1a9 cleanup
michael
parents: 18610
diff changeset
99
18657
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
100 #define CHECK(j)\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
101 { int score= ABS(cur[-refs-1+j] - cur[+refs-1-j])\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
102 + ABS(cur[-refs +j] - cur[+refs -j])\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
103 + ABS(cur[-refs+1+j] - cur[+refs+1-j]);\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
104 if(score < spatial_score){\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
105 spatial_score= score;\
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
106 spatial_pred= (cur[-refs +j] + cur[+refs -j])>>1;\
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
107
18657
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
108 CHECK(-1) CHECK(-2) }} }}
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
109 CHECK( 1) CHECK( 2) }} }}
26f54fad099c better spatial interpolation
michael
parents: 18626
diff changeset
110
18626
2e2b8f34a69e make spatial interlacing check optional
michael
parents: 18625
diff changeset
111 if(p->mode<2){
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
112 int b= (prev2[-2*refs] + next2[-2*refs])>>1;
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
113 int f= (prev2[+2*refs] + next2[+2*refs])>>1;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
114 #if 0
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
115 int a= cur[-3*refs];
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
116 int g= cur[+3*refs];
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
117 int max= MAX3(d-e, d-c, MIN3(MAX(b-c,f-e),MAX(b-c,b-a),MAX(f-g,f-e)) );
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
118 int min= MIN3(d-e, d-c, MAX3(MIN(b-c,f-e),MIN(b-c,b-a),MIN(f-g,f-e)) );
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
119 #else
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
120 int max= MAX3(d-e, d-c, MIN(b-c, f-e));
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
121 int min= MIN3(d-e, d-c, MAX(b-c, f-e));
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
122 #endif
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
123
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
124 diff= MAX3(diff, min, -max);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
125 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
126
18623
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
127 if(d < spatial_pred) d= MIN(d + diff, spatial_pred);
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
128 else d= MAX(d - diff, spatial_pred);
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
129
18623
960cd1af26f2 cleanup
michael
parents: 18621
diff changeset
130 dst[i][x + y*dst_stride[i]]= d;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
131 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
132 }else{
18610
e0df832235c6 simplify
michael
parents: 18608
diff changeset
133 memcpy(&dst[i][y*dst_stride[i]], &p->ref[1][i][y*refs], w);
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
134 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
135 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
136 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
137 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
138
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
139 static int config(struct vf_instance_s* vf,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
140 int width, int height, int d_width, int d_height,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
141 unsigned int flags, unsigned int outfmt){
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
142 int i, j;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
143
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
144 for(i=0; i<3; i++){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
145 int is_chroma= !!i;
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
146 int w= ((width + 31) & (~31))>>is_chroma;
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
147 int h= ((height+6+ 31) & (~31))>>is_chroma;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
148
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
149 vf->priv->stride[i]= w;
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
150 for(j=0; j<3; j++)
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
151 vf->priv->ref[j][i]= malloc(w*h*sizeof(uint8_t))+3*w;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
152 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
153
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
154 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
155 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
156
18917
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
157 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
158 extern int correct_pts;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
159
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
160 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
161 int tff;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
162
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
163 if(vf->priv->parity < 0) {
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
164 if (mpi->fields & MP_IMGFIELD_ORDERED)
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
165 tff = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
166 else
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
167 tff = 1;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
168 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
169 else tff = (vf->priv->parity&1)^1;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
170
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
171 store_ref(vf->priv, mpi->planes, mpi->stride, mpi->w, mpi->h);
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
172
18917
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
173 vf->priv->buffered_mpi = mpi;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
174 vf->priv->buffered_tff = tff;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
175 vf->priv->buffered_i = 0;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
176 vf->priv->buffered_pts = pts;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
177
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
178 return continue_buffered_image(vf);
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
179 }
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
180
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
181 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
182 {
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
183 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
184 int tff = vf->priv->buffered_tff;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
185 double pts = vf->priv->buffered_pts;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
186 int i;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
187 int ret=0;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
188 mp_image_t *dmpi;
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
189
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
190 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
191
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
192 for(i = vf->priv->buffered_i; i<=(vf->priv->mode&1); i++){
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
193 dmpi=vf_get_image(vf->next,mpi->imgfmt,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
194 MP_IMGTYPE_TEMP,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
195 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
196 mpi->width,mpi->height);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
197 vf_clone_mpi_attributes(dmpi, mpi);
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
198 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
199 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
200 vf_queue_frame(vf, continue_buffered_image);
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
201 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
202 if (correct_pts)
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
203 break;
18626
2e2b8f34a69e make spatial interlacing check optional
michael
parents: 18625
diff changeset
204 if(i<(vf->priv->mode&1))
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
205 vf_next_control(vf, VFCTRL_FLIP_PAGE, NULL);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
206 }
18917
d9a75b26da6c Add a new video pts tracking mode, enabled by option -correct-pts.
uau
parents: 18657
diff changeset
207 vf->priv->buffered_i = 1;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
208 return ret;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
209 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
210
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
211 static void uninit(struct vf_instance_s* vf){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
212 int i;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
213 if(!vf->priv) return;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
214
18625
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
215 for(i=0; i<3*3; i++){
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
216 uint8_t **p= &vf->priv->ref[i%3][i/3];
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
217 if(*p) free(*p - 3*vf->priv->stride[i/3]);
dea3a68e2589 simplify
michael
parents: 18623
diff changeset
218 *p= NULL;
18608
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
219 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
220 free(vf->priv);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
221 vf->priv=NULL;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
222 }
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 int query_format(struct vf_instance_s* vf, unsigned int fmt){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
226 switch(fmt){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
227 case IMGFMT_YV12:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
228 case IMGFMT_I420:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
229 case IMGFMT_IYUV:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
230 case IMGFMT_Y800:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
231 case IMGFMT_Y8:
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
232 return vf_next_query_format(vf,fmt);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
233 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
234 return 0;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
235 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
236
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
237 static int open(vf_instance_t *vf, char* args){
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
238
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
239 vf->config=config;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
240 vf->put_image=put_image;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
241 vf->query_format=query_format;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
242 vf->uninit=uninit;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
243 vf->priv=malloc(sizeof(struct vf_priv_s));
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
244 memset(vf->priv, 0, sizeof(struct vf_priv_s));
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
245
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
246 vf->priv->mode=0;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
247 vf->priv->parity= -1;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
248
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
249 if (args) sscanf(args, "%d:%d", &vf->priv->mode, &vf->priv->parity);
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
250
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
251 return 1;
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
252 }
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
253
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
254 vf_info_t vf_info_yadif = {
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
255 "Yet Another DeInterlacing Filter",
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
256 "yadif",
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
257 "Michael Niedermayer",
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
258 "",
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
259 open,
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
260 NULL
a80c7de8a4ba yet another deinterlacing filter
michael
parents:
diff changeset
261 };