1 /*
2 * This file is part of MPlayer.
3 *
4 * MPlayer 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 * MPlayer 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 along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <limits.h>
23
24 #include "config.h"
26
30
32
36
37 #define fixed_mode(p) ((p)<=BOTTOM_FIRST)
38
40 {
43 unsigned char *
buf[3];
44 };
45
46 /*
47 * Copy fields from either current or buffered previous frame to the
48 * output and store the current frame unmodified to the buffer.
49 */
50
52 int w, int h, int ts, int fs,
53 unsigned char **bufp,
enum mode mode)
54 {
56 int top;
57
58 if(!*bufp)
59 {
61 if(!(*bufp=malloc(h*w))) return;
62 }
63
64 for(end=to+h*ts, buf=*bufp, top=1; to<
end; from+=fs, to+=ts, buf+=w, top^=1)
65 {
68 }
69 }
70
71 /*
72 * This macro interpolates the value of both fields at a point halfway
73 * between lines and takes the squared difference. In field resolution
74 * the point is a quarter pixel below a line in one field and a quarter
75 * pixel above a line in other.
76 *
77 * (the result is actually multiplied by 25)
78 */
79
80 #define diff(a, as, b, bs) (t=((*a-b[bs])<<2)+a[as<<1]-b[-bs], t*t)
81
82 /*
83 * Find which field combination has the smallest average squared difference
84 * between the fields.
85 */
86
88 int w,
int h,
int os,
int ns,
enum mode mode,
89 int verbose, int fields)
90 {
91 double bdiff, pdiff, tdiff,
scale;
92 int bdif, tdif, pdif;
94 unsigned char *
end, *rend;
95
102
104 bdiff=pdiff=tdiff=65536.0;
105 else
106 {
107 bdiff=pdiff=tdiff=0.0;
108
109 for(end=new+(h-2)*ns, new+=ns, old+=os, top=0;
110 new<
end;
new+=ns-w, old+=os-w, top^=1)
111 {
112 pdif=tdif=bdif=0;
113
114 switch(mode)
115 {
117 if(top)
118 for(rend=new+w; new<rend; new++, old++)
119 pdif+=
diff(
new, ns,
new, ns),
120 tdif+=
diff(
new, ns, old, os);
121 else
122 for(rend=new+w; new<rend; new++, old++)
123 pdif+=
diff(
new, ns,
new, ns),
124 tdif+=
diff(old, os,
new, ns);
125 break;
126
128 if(top)
129 for(rend=new+w; new<rend; new++, old++)
130 pdif+=
diff(
new, ns,
new, ns),
131 bdif+=
diff(old, os,
new, ns);
132 else
133 for(rend=new+w; new<rend; new++, old++)
134 pdif+=
diff(
new, ns,
new, ns),
135 bdif+=
diff(
new, ns, old, os);
136 break;
137
139 if(top)
140 for(rend=new+w; new<rend; new++, old++)
141 tdif+=
diff(
new, ns, old, os),
142 bdif+=
diff(old, os,
new, ns);
143 else
144 for(rend=new+w; new<rend; new++, old++)
145 bdif+=
diff(
new, ns, old, os),
146 tdif+=
diff(old, os,
new, ns);
147 break;
148
149 default: /* FULL_ANALYZE */
150 if(top)
151 for(rend=new+w; new<rend; new++, old++)
152 pdif+=
diff(
new, ns,
new, ns),
153 tdif+=
diff(
new, ns, old, os),
154 bdif+=
diff(old, os,
new, ns);
155 else
156 for(rend=new+w; new<rend; new++, old++)
157 pdif+=
diff(
new, ns,
new, ns),
158 bdif+=
diff(
new, ns, old, os),
159 tdif+=
diff(old, os,
new, ns);
160 }
161
162 pdiff+=(double)pdif;
163 tdiff+=(double)tdif;
164 bdiff+=(double)bdif;
165 }
166
167 scale=1.0/(w*(h-3))/25.0;
171
173 bdiff=65536.0;
175 tdiff=65536.0;
177 pdiff=65536.0;
178
179 if(bdiff<pdiff && bdiff<tdiff)
181 else if(tdiff<pdiff && tdiff<bdiff)
183 else
185 }
186
188 {
194 }
195
197 }
198
200 {
202 int w;
204
208 return 0;
209
213
214 mode=vf->priv->mode;
215
216 if(!vf->priv->buf[0])
218 else
220 w, dmpi->
h, w, mpi->
stride[0], mode,
221 vf->priv->verbose, mpi->
fields);
222
226 &vf->priv->buf[0], mode);
227
229 {
233 &vf->priv->buf[1], mode);
237 &vf->priv->buf[2], mode);
238 }
239
241 }
242
243 static void uninit(
struct vf_instance *vf)
244 {
245 if (!vf->priv)
246 return;
247 free(vf->priv->buf[0]);
248 free(vf->priv->buf[1]);
249 free(vf->priv->buf[2]);
250 free(vf->priv);
251 }
252
254 {
258
260 {
262 return 0;
263 }
264
267
268 while(args && *args)
269 {
270 switch(*args)
271 {
282 case ':': break;
283
284 default:
286 return 0; /* bad args */
287 }
288
289 if( (args=strchr(args, ':')) ) args++;
290 }
291
292 return 1;
293 }
294
296 {
297 "phase shift fields",
298 "phase",
299 "Ville Saari",
300 "",
302 NULL
303 };