annotate libmpcodecs/vf_detc.c @ 18816:be4e5d19a5b3

Typo: use ptmpstr instead of tmpstr to strip leading spaces + add comment Patch by Zuxy Meng ##zuxy P meng AH gmail P com## --Cette ligne, et les suivantes ci-dessous, seront ignores-- M cpudetect.c
author gpoirier
date Sun, 25 Jun 2006 17:37:58 +0000
parents 20aca9baf5d8
children 6a08d0dabca8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
1 #include <stdio.h>
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
2 #include <stdlib.h>
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
3 #include <string.h>
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
4
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9665
diff changeset
5 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9665
diff changeset
6 #include "mp_msg.h"
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
7
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
8 #include "img_format.h"
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
9 #include "mp_image.h"
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
10 #include "vf.h"
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
11
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9665
diff changeset
12 #include "libvo/fastmemcpy.h"
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
13
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
14 struct metrics {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
15 int even;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
16 int odd;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
17 int noise;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
18 int temp;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
19 };
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
20
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
21 struct vf_priv_s {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
22 int frame;
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
23 int drop, lastdrop;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
24 struct metrics pm;
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
25 int thres[5];
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
26 int inframes, outframes;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
27 int mode;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
28 int (*analyze)(struct vf_priv_s *, mp_image_t *, mp_image_t *);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
29 int needread;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
30 };
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
31
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
32 #define COMPE(a,b,e) (abs((a)-(b)) < (((a)+(b))>>(e)))
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
33 #define COMPARABLE(a,b) COMPE((a),(b),2)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
34 #define VERYCLOSE(a,b) COMPE((a),(b),3)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
35
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
36 #define OUTER_TC_NBHD(s) ( \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
37 COMPARABLE((s)[-1].m.even,(s)[-1].m.odd) && \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
38 COMPARABLE((s)[1].m.even,(s)[0].m.odd) && \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
39 COMPARABLE((s)[2].m.even,(s)[1].m.odd) && \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
40 COMPARABLE((s)[-1].m.noise,(s)[0].m.temp) && \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
41 COMPARABLE((s)[2].m.noise,(s)[2].m.temp) )
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
42
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
43 #define INNER_TC_NBHD(s,l,h) ( \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
44 COMPARABLE((s)[0].m.even,(l)) && \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
45 COMPARABLE((s)[2].m.odd,(l)) && ( \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
46 COMPARABLE((s)[0].m.noise,(h)) || \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
47 COMPARABLE((s)[1].m.noise,(h)) ) )
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
48
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
49 enum {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
50 TC_DROP,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
51 TC_PROG,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
52 TC_IL1,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
53 TC_IL2
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
54 };
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
55
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
56 static inline void *my_memcpy_pic(void * dst, void * src, int bytesPerLine, int height, int dstStride, int srcStride)
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
57 {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
58 int i;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
59 void *retval=dst;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
60
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
61 for(i=0; i<height; i++)
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
62 {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
63 memcpy(dst, src, bytesPerLine);
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
64 src+= srcStride;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
65 dst+= dstStride;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
66 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
67
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
68 return retval;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
69 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
70
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
71 static unsigned int hash_pic(unsigned char *img, int w, int h, int stride)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
72 {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
73 int step = w*h/1024;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
74 unsigned int hash=0;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
75 int x=0, y;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
76
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
77 step -= step % 3;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
78
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
79 for (y=0; y<h; y++) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
80 for (; x<w; x+=step) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
81 hash = hash ^ (hash<<4) ^ img[x];
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
82 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
83 x -= w;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
84 img += stride;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
85 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
86
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
87 return hash;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
88 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
89
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
90 static void block_diffs(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns)
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
91 {
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
92 int x, y, even=0, odd=0, noise, temp;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
93 unsigned char *oldp, *newp;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
94 m->noise = m->temp = 0;
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
95 for (x = 8; x; x--) {
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
96 oldp = old++;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
97 newp = new++;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
98 noise = temp = 0;
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
99 for (y = 4; y; y--) {
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
100 even += abs(newp[0]-oldp[0]);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
101 odd += abs(newp[ns]-oldp[os]);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
102 noise += newp[ns]-newp[0];
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
103 temp += oldp[os]-newp[0];
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
104 oldp += os<<1;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
105 newp += ns<<1;
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
106 }
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
107 m->noise += abs(noise);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
108 m->temp += abs(temp);
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
109 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
110 m->even = even;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
111 m->odd = odd;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
112 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
113
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
114 static void diff_planes(struct metrics *m, unsigned char *old, unsigned char *new, int w, int h, int os, int ns)
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
115 {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
116 int x, y, me=0, mo=0, mn=0, mt=0;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
117 struct metrics l;
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
118 for (y = 0; y < h-7; y += 8) {
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
119 for (x = 0; x < w-7; x += 8) {
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
120 block_diffs(&l, old+x+y*os, new+x+y*ns, os, ns);
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
121 if (l.even > me) me = l.even;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
122 if (l.odd > mo) mo = l.odd;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
123 if (l.noise > mn) mn = l.noise;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
124 if (l.temp > mt) mt = l.temp;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
125 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
126 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
127 m->even = me;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
128 m->odd = mo;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
129 m->noise = mn;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
130 m->temp = mt;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
131 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
132
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
133 static void diff_fields(struct metrics *metr, mp_image_t *old, mp_image_t *new)
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
134 {
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
135 struct metrics m, mu, mv;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
136 diff_planes(&m, old->planes[0], new->planes[0],
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
137 new->w, new->h, old->stride[0], new->stride[0]);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
138 if (new->flags & MP_IMGFLAG_PLANAR) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
139 diff_planes(&mu, old->planes[1], new->planes[1],
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
140 new->chroma_width, new->chroma_height,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
141 old->stride[1], new->stride[1]);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
142 diff_planes(&mv, old->planes[2], new->planes[2],
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
143 new->chroma_width, new->chroma_height,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
144 old->stride[2], new->stride[2]);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
145 if (mu.even > m.even) m.even = mu.even;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
146 if (mu.odd > m.odd) m.odd = mu.odd;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
147 if (mu.noise > m.noise) m.noise = mu.noise;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
148 if (mu.temp > m.temp) m.temp = mu.temp;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
149 if (mv.even > m.even) m.even = mv.even;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
150 if (mv.odd > m.odd) m.odd = mv.odd;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
151 if (mv.noise > m.noise) m.noise = mv.noise;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
152 if (mv.temp > m.temp) m.temp = mv.temp;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
153 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
154 *metr = m;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
155 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
156
9636
5a087f79270a compiler warning fix by Dominik Mierzejewski <dominik@rangers.eu.org>
alex
parents: 9593
diff changeset
157 static void status(int f, struct metrics *m)
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
158 {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
159 mp_msg(MSGT_VFILTER, MSGL_V, "frame %d: e=%d o=%d n=%d t=%d\n",
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
160 f, m->even, m->odd, m->noise, m->temp);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
161 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
162
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
163 static int analyze_fixed_pattern(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
164 {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
165 if (p->frame >= 0) p->frame = (p->frame+1)%5;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
166 mp_msg(MSGT_VFILTER, MSGL_V, "frame %d\n", p->frame);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
167 switch (p->frame) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
168 case -1: case 0: case 1: case 2:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
169 return TC_PROG;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
170 case 3:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
171 return TC_IL1;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
172 case 4:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
173 return TC_IL2;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
174 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
175 return 0;
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
176 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
177
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
178 static int analyze_aggressive(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old)
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
179 {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
180 int i;
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
181 struct metrics m, pm;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
182
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
183 if (p->frame >= 0) p->frame = (p->frame+1)%5;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
184
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
185 diff_fields(&m, old, new);
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
186
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
187 status(p->frame, &m);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
188
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
189 pm = p->pm;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
190 p->pm = m;
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
191
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
192 if (p->frame == 4) {
9665
8f030cabf1d9 try to break pattern at scene changes to prevent merging pictures that
rfelker
parents: 9660
diff changeset
193 /* We need to break at scene changes, but is this a valid test? */
8f030cabf1d9 try to break pattern at scene changes to prevent merging pictures that
rfelker
parents: 9660
diff changeset
194 if ((m.even > p->thres[2]) && (m.odd > p->thres[2]) && (m.temp > p->thres[3])
8f030cabf1d9 try to break pattern at scene changes to prevent merging pictures that
rfelker
parents: 9660
diff changeset
195 && (m.temp > 5*pm.temp) && (m.temp*2 > m.noise)) {
8f030cabf1d9 try to break pattern at scene changes to prevent merging pictures that
rfelker
parents: 9660
diff changeset
196 mp_msg(MSGT_VFILTER, MSGL_V, "scene change breaking telecine!\n");
8f030cabf1d9 try to break pattern at scene changes to prevent merging pictures that
rfelker
parents: 9660
diff changeset
197 p->frame = -1;
8f030cabf1d9 try to break pattern at scene changes to prevent merging pictures that
rfelker
parents: 9660
diff changeset
198 return TC_DROP;
8f030cabf1d9 try to break pattern at scene changes to prevent merging pictures that
rfelker
parents: 9660
diff changeset
199 }
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
200 /* Thres. is to compensate for quantization errors when noise is low */
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
201 if (m.noise - m.temp > -p->thres[4]) {
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
202 if (COMPARABLE(m.even, pm.odd)) {
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
203 //mp_msg(MSGT_VFILTER, MSGL_V, "confirmed field match!\n");
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
204 return TC_IL2;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
205 } else if ((m.even < p->thres[0]) && (m.odd < p->thres[0]) && VERYCLOSE(m.even, m.odd)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
206 && VERYCLOSE(m.noise,m.temp) && VERYCLOSE(m.noise,pm.noise)) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
207 mp_msg(MSGT_VFILTER, MSGL_V, "interlaced frame appears in duplicate!!!\n");
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
208 p->pm = pm; /* hack :) */
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
209 p->frame = 3;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
210 return TC_IL1;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
211 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
212 } else {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
213 mp_msg(MSGT_VFILTER, MSGL_V, "mismatched telecine fields!\n");
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
214 p->frame = -1;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
215 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
216 }
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
217
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
218 if (2*m.even*m.temp < m.odd*m.noise) {
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
219 mp_msg(MSGT_VFILTER, MSGL_V, "caught telecine sync!\n");
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
220 p->frame = 3;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
221 return TC_IL1;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
222 }
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
223
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
224 if (p->frame < 3) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
225 if (m.noise > p->thres[3]) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
226 if (m.noise > 2*m.temp) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
227 mp_msg(MSGT_VFILTER, MSGL_V, "merging fields out of sequence!\n");
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
228 return TC_IL2;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
229 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
230 if ((m.noise > 2*pm.noise) && (m.even > p->thres[2]) && (m.odd > p->thres[2])) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
231 mp_msg(MSGT_VFILTER, MSGL_V, "dropping horrible interlaced frame!\n");
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
232 return TC_DROP;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
233 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
234 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
235 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
236
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
237 switch (p->frame) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
238 case -1:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
239 if (4*m.noise > 5*m.temp) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
240 mp_msg(MSGT_VFILTER, MSGL_V, "merging fields out of sequence!\n");
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
241 return TC_IL2;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
242 }
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
243 case 0:
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
244 case 1:
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
245 case 2:
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
246 return TC_PROG;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
247 case 3:
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
248 if ((m.even > p->thres[1]) && (m.even > m.odd) && (m.temp > m.noise)) {
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
249 mp_msg(MSGT_VFILTER, MSGL_V, "lost telecine tracking!\n");
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
250 p->frame = -1;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
251 return TC_PROG;
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
252 }
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
253 return TC_IL1;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
254 case 4:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
255 return TC_IL2;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
256 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
257 return 0;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
258 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
259
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
260 static void copy_image(mp_image_t *dmpi, mp_image_t *mpi, int field)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
261 {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
262 switch (field) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
263 case 0:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
264 my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
265 dmpi->stride[0]*2, mpi->stride[0]*2);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
266 if (mpi->flags & MP_IMGFLAG_PLANAR) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
267 my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
268 mpi->chroma_width, mpi->chroma_height/2,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
269 dmpi->stride[1]*2, mpi->stride[1]*2);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
270 my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
271 mpi->chroma_width, mpi->chroma_height/2,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
272 dmpi->stride[2]*2, mpi->stride[2]*2);
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
273 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
274 break;
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
275 case 1:
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
276 my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
277 mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
278 dmpi->stride[0]*2, mpi->stride[0]*2);
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
279 if (mpi->flags & MP_IMGFLAG_PLANAR) {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
280 my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
281 mpi->planes[1]+mpi->stride[1],
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
282 mpi->chroma_width, mpi->chroma_height/2,
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
283 dmpi->stride[1]*2, mpi->stride[1]*2);
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
284 my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
285 mpi->planes[2]+mpi->stride[2],
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
286 mpi->chroma_width, mpi->chroma_height/2,
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
287 dmpi->stride[2]*2, mpi->stride[2]*2);
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
288 }
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
289 break;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
290 case 2:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
291 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
292 dmpi->stride[0], mpi->stride[0]);
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
293 if (mpi->flags & MP_IMGFLAG_PLANAR) {
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
294 memcpy_pic(dmpi->planes[1], mpi->planes[1],
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
295 mpi->chroma_width, mpi->chroma_height,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
296 dmpi->stride[1], mpi->stride[1]);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
297 memcpy_pic(dmpi->planes[2], mpi->planes[2],
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
298 mpi->chroma_width, mpi->chroma_height,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
299 dmpi->stride[2], mpi->stride[2]);
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
300 }
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
301 break;
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
302 }
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
303 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
304
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
305 static int do_put_image(struct vf_instance_s* vf, mp_image_t *dmpi)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
306 {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
307 struct vf_priv_s *p = vf->priv;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
308 int dropflag;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
309
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
310 switch (p->drop) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
311 case 0:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
312 dropflag = 0;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
313 break;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
314 case 1:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
315 dropflag = (++p->lastdrop >= 5);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
316 break;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
317 case 2:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
318 dropflag = (++p->lastdrop >= 5) && (4*p->inframes <= 5*p->outframes);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
319 break;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
320 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
321
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
322 if (dropflag) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
323 mp_msg(MSGT_VFILTER, MSGL_V, "drop! [%d/%d=%g]\n",
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
324 p->outframes, p->inframes, (float)p->outframes/p->inframes);
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
325 p->lastdrop = 0;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
326 return 0;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
327 }
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
328
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
329 p->outframes++;
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
330 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
331 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
332
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
333 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
334 {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
335 int ret=0;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
336 mp_image_t *dmpi;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
337 struct vf_priv_s *p = vf->priv;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
338
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
339 p->inframes++;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
340
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
341 if (p->needread) dmpi = vf_get_image(vf->next, mpi->imgfmt,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
342 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
343 MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
344 mpi->width, mpi->height);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
345 /* FIXME: is there a good way to get rid of static type? */
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
346 else dmpi = vf_get_image(vf->next, mpi->imgfmt,
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
347 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
348 MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
349
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
350 switch (p->analyze(p, mpi, dmpi)) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
351 case TC_DROP:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
352 /* Don't copy anything unless we'll need to read it. */
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
353 if (p->needread) copy_image(dmpi, mpi, 2);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
354 p->lastdrop = 0;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
355 break;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
356 case TC_PROG:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
357 /* Copy and display the whole frame. */
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
358 copy_image(dmpi, mpi, 2);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
359 ret = do_put_image(vf, dmpi);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
360 break;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
361 case TC_IL1:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
362 /* Only copy bottom field unless we need to read. */
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
363 if (p->needread) copy_image(dmpi, mpi, 2);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
364 else copy_image(dmpi, mpi, 1);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
365 p->lastdrop = 0;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
366 break;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
367 case TC_IL2:
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
368 /* Copy top field and show frame, then copy bottom if needed. */
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
369 copy_image(dmpi, mpi, 0);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
370 ret = do_put_image(vf, dmpi);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
371 if (p->needread) copy_image(dmpi, mpi, 1);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
372 break;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
373 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
374 return ret;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
375 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
376
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
377 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
378 {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
379 /* FIXME - figure out which other formats work */
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
380 switch (fmt) {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
381 case IMGFMT_YV12:
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
382 case IMGFMT_IYUV:
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
383 case IMGFMT_I420:
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
384 return vf_next_query_format(vf, fmt);
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
385 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
386 return 0;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
387 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
388
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
389 static int config(struct vf_instance_s* vf,
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
390 int width, int height, int d_width, int d_height,
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
391 unsigned int flags, unsigned int outfmt)
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
392 {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
393 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
394 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
395
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
396 static void uninit(struct vf_instance_s* vf)
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
397 {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
398 free(vf->priv);
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
399 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
400
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
401 static struct {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
402 char *name;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
403 int (*func)(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
404 int needread;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
405 } anal_funcs[] = {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
406 { "fixed", analyze_fixed_pattern, 0 },
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
407 { "aggressive", analyze_aggressive, 1 },
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
408 { NULL, NULL, 0 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
409 };
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
410
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
411 #define STARTVARS if (0)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
412 #define GETVAR(str, name, out, func) \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
413 else if (!strncmp((str), name "=", sizeof(name))) \
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
414 (out) = (func)((str) + sizeof(name))
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
415
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
416 static void parse_var(struct vf_priv_s *p, char *var)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
417 {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
418 STARTVARS;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
419 GETVAR(var, "dr", p->drop, atoi);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
420 GETVAR(var, "t0", p->thres[0], atoi);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
421 GETVAR(var, "t1", p->thres[1], atoi);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
422 GETVAR(var, "t2", p->thres[2], atoi);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
423 GETVAR(var, "t3", p->thres[3], atoi);
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
424 GETVAR(var, "t4", p->thres[4], atoi);
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
425 GETVAR(var, "fr", p->frame, atoi);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
426 GETVAR(var, "am", p->mode, atoi);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
427 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
428
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
429 static void parse_args(struct vf_priv_s *p, char *args)
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
430 {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
431 char *next, *orig;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
432 for (args=orig=strdup(args); args; args=next) {
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
433 next = strchr(args, ':');
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
434 if (next) *next++ = 0;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
435 parse_var(p, args);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
436 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
437 free(orig);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
438 }
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
439
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
440 static int open(vf_instance_t *vf, char* args)
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
441 {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
442 struct vf_priv_s *p;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
443 vf->config = config;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
444 vf->put_image = put_image;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
445 vf->query_format = query_format;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
446 vf->uninit = uninit;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
447 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
448 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
449 p->frame = -1;
9660
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
450 p->thres[0] = 440;
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
451 p->thres[1] = 720;
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
452 p->thres[2] = 2500;
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
453 p->thres[3] = 2500;
c2d23e02522b improvements to detc filter:
rfelker
parents: 9636
diff changeset
454 p->thres[4] = 800;
9554
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
455 p->drop = 0;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
456 p->mode = 1;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
457 if (args) parse_args(p, args);
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
458 p->analyze = anal_funcs[p->mode].func;
12eae4cb4e56 new version of the de-telecine filter, largely rewritten. should work
rfelker
parents: 9467
diff changeset
459 p->needread = anal_funcs[p->mode].needread;
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
460 return 1;
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
461 }
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
462
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
463 vf_info_t vf_info_detc = {
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
464 "de-telecine filter",
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
465 "detc",
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
466 "Rich Felker",
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
467 "",
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9554
diff changeset
468 open,
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9554
diff changeset
469 NULL
9467
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
470 };
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
471
9fae4150ec43 experimental de-telecine filter. not documented or configurable yet,
rfelker
parents:
diff changeset
472