annotate libmpcodecs/vf_divtc.c @ 37195:ac6c37d85d65 default tip

configure: Fix initialization of variable def_local_aligned_32 It contiained the #define of HAVE_LOCAL_ALIGNED_16 instead of HAVE_LOCAL_ALIGNED_32.
author al
date Sun, 28 Sep 2014 18:38:41 +0000
parents b4ce15212bfc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29195
diff changeset
18
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
19 #include <stdio.h>
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
20 #include <stdlib.h>
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
21 #include <string.h>
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
22 #include <limits.h>
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
23 #include <math.h>
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
24
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16136
diff changeset
25 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16136
diff changeset
26 #include "mp_msg.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16136
diff changeset
27 #include "cpudetect.h"
21372
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 19372
diff changeset
28 #include "libavutil/common.h"
35705
b4ce15212bfc Replace obsolete x86_cpu.h #includes by the correct header.
diego
parents: 35175
diff changeset
29 #include "libavutil/x86/asm.h"
21507
fa99b3d31d13 Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents: 21372
diff changeset
30 #include "mpbswap.h"
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
31
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
32 #include "img_format.h"
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
33 #include "mp_image.h"
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
34 #include "vf.h"
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
35
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16136
diff changeset
36 #include "libvo/fastmemcpy.h"
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
37
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 24360
diff changeset
38 const vf_info_t vf_info_divtc;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
39
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
40 struct vf_priv_s
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
41 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
42 int deghost, pass, phase, window, fcount, bcount, frameno, misscount,
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
43 ocount, sum[5];
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
44 double threshold;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
45 FILE *file;
33443
02214457c955 Fix code incorrectly assuming "char" is signed.
reimar
parents: 32702
diff changeset
46 int8_t *bdata;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
47 unsigned int *csdata;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
48 int *history;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
49 };
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
50
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
51 /*
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
52 * diff_MMX and diff_C stolen from vf_decimate.c
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
53 */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
54
28907
ccbde3575f0a Check for HAVE_EBX_AVAILABLE before enabling MMX code that needs the EBX
reimar
parents: 28906
diff changeset
55 #if HAVE_MMX && HAVE_EBX_AVAILABLE
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
56 static int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
57 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
58 volatile short out[4];
27754
08d18fe9da52 Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents: 27667
diff changeset
59 __asm__ (
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
60 "movl $8, %%ecx \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
61 "pxor %%mm4, %%mm4 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
62 "pxor %%mm7, %%mm7 \n\t"
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
63
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
64 ASMALIGN(4)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
65 "1: \n\t"
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
66
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
67 "movq (%%"REG_S"), %%mm0 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
68 "movq (%%"REG_S"), %%mm2 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
69 "add %%"REG_a", %%"REG_S" \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
70 "movq (%%"REG_D"), %%mm1 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
71 "add %%"REG_b", %%"REG_D" \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
72 "psubusb %%mm1, %%mm2 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
73 "psubusb %%mm0, %%mm1 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
74 "movq %%mm2, %%mm0 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
75 "movq %%mm1, %%mm3 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
76 "punpcklbw %%mm7, %%mm0 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
77 "punpcklbw %%mm7, %%mm1 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
78 "punpckhbw %%mm7, %%mm2 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
79 "punpckhbw %%mm7, %%mm3 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
80 "paddw %%mm0, %%mm4 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
81 "paddw %%mm1, %%mm4 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
82 "paddw %%mm2, %%mm4 \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
83 "paddw %%mm3, %%mm4 \n\t"
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
84
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
85 "decl %%ecx \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
86 "jnz 1b \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
87 "movq %%mm4, (%%"REG_d") \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
88 "emms \n\t"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
89 :
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
90 : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
91 : "%ecx", "memory"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
92 );
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
93 return out[0]+out[1]+out[2]+out[3];
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
94 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
95 #endif
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
96
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
97 static int diff_C(unsigned char *old, unsigned char *new, int os, int ns)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
98 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
99 int x, y, d=0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
100
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
101 for(y=8; y; y--, new+=ns, old+=os)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
102 for(x=8; x; x--)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
103 d+=abs(new[x]-old[x]);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
104
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
105 return d;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
106 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
107
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
108 static int (*diff)(unsigned char *, unsigned char *, int, int);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
109
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
110 static int diff_plane(unsigned char *old, unsigned char *new,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
111 int w, int h, int os, int ns, int arg)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
112 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
113 int x, y, d, max=0, sum=0, n=0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
114
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
115 for(y=0; y<h-7; y+=8)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
116 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
117 for(x=0; x<w-7; x+=8)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
118 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
119 d=diff(old+x+y*os, new+x+y*ns, os, ns);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
120 if(d>max) max=d;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
121 sum+=d;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
122 n++;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
123 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
124 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
125
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
126 return (sum+n*max)/2;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
127 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
128
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
129 /*
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
130 static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
131 int w, int h, int s, int zs, int arg)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
132 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
133 unsigned int shift, sum;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
134 unsigned char *e;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
135
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
136 for(sum=0; h; h--, p+=s-w)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
137 for(e=p+w, shift=32; p<e;)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
138 sum^=(*p++)<<(shift=(shift-8)&31);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
139
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
140 return sum;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
141 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
142 */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
143
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
144 static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
145 int w, int h, int s, int zs, int arg)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
146 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
147 unsigned int shift;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
148 uint32_t sum, t;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
149 unsigned char *e, *e2;
29195
a49f45515e08 Replace glibc-specific __WORDSIZE preprocessor check with HAVE_FAST_64BIT.
diego
parents: 28907
diff changeset
150 #if HAVE_FAST_64BIT
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
151 typedef uint64_t wsum_t;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
152 #else
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
153 typedef uint32_t wsum_t;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
154 #endif
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
155 wsum_t wsum;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
156
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
157 for(sum=0; h; h--, p+=s-w)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
158 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
159 for(shift=0, e=p+w; (int)p&(sizeof(wsum_t)-1) && p<e;)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
160 sum^=*p++<<(shift=(shift-8)&31);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
161
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
162 for(wsum=0, e2=e-sizeof(wsum_t)+1; p<e2; p+=sizeof(wsum_t))
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
163 wsum^=*(wsum_t *)p;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
164
29195
a49f45515e08 Replace glibc-specific __WORDSIZE preprocessor check with HAVE_FAST_64BIT.
diego
parents: 28907
diff changeset
165 #if HAVE_FAST_64BIT
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
166 t=be2me_32((uint32_t)(wsum>>32^wsum));
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
167 #else
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
168 t=be2me_32(wsum);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
169 #endif
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
170
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
171 for(sum^=(t<<shift|t>>(32-shift)); p<e;)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
172 sum^=*p++<<(shift=(shift-8)&31);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
173 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
174
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
175 return sum;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
176 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
177
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
178 static int deghost_plane(unsigned char *d, unsigned char *s,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
179 int w, int h, int ds, int ss, int threshold)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
180 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
181 int t;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
182 unsigned char *e;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
183
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
184 for(; h; h--, s+=ss-w, d+=ds-w)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
185 for(e=d+w; d<e; d++, s++)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
186 if(abs(*d-*s)>=threshold)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
187 *d=(t=(*d<<1)-*s)<0?0:t>255?255:t;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
188
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
189 return 0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
190 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
191
23666
5c3c7efd9b75 Get rid of my_memcpy_pic code duplication in many filters.
reimar
parents: 21507
diff changeset
192 static int copyop(unsigned char *d, unsigned char *s, int bpl, int h, int dstride, int sstride, int dummy) {
5c3c7efd9b75 Get rid of my_memcpy_pic code duplication in many filters.
reimar
parents: 21507
diff changeset
193 memcpy_pic(d, s, bpl, h, dstride, sstride);
5c3c7efd9b75 Get rid of my_memcpy_pic code duplication in many filters.
reimar
parents: 21507
diff changeset
194 return 0;
5c3c7efd9b75 Get rid of my_memcpy_pic code duplication in many filters.
reimar
parents: 21507
diff changeset
195 }
5c3c7efd9b75 Get rid of my_memcpy_pic code duplication in many filters.
reimar
parents: 21507
diff changeset
196
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
197 static int imgop(int(*planeop)(unsigned char *, unsigned char *,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
198 int, int, int, int, int),
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
199 mp_image_t *dst, mp_image_t *src, int arg)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
200 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
201 if(dst->flags&MP_IMGFLAG_PLANAR)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
202 return planeop(dst->planes[0], src?src->planes[0]:0,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
203 dst->w, dst->h,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
204 dst->stride[0], src?src->stride[0]:0, arg)+
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
205 planeop(dst->planes[1], src?src->planes[1]:0,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
206 dst->chroma_width, dst->chroma_height,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
207 dst->stride[1], src?src->stride[1]:0, arg)+
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
208 planeop(dst->planes[2], src?src->planes[2]:0,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
209 dst->chroma_width, dst->chroma_height,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
210 dst->stride[2], src?src->stride[2]:0, arg);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
211
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
212 return planeop(dst->planes[0], src?src->planes[0]:0,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
213 dst->w*(dst->bpp/8), dst->h,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
214 dst->stride[0], src?src->stride[0]:0, arg);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
215 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
216
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
217 /*
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
218 * Find the phase in which the telecine pattern fits best to the
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
219 * given 5 frame slice of frame difference measurements.
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
220 *
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
221 * If phase1 and phase2 are not negative, only the two specified
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
222 * phases are tested.
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
223 */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
224
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
225 static int match(struct vf_priv_s *p, int *diffs,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
226 int phase1, int phase2, double *strength)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
227 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
228 static const int pattern1[]={ -4, 1, 1, 1, 1 },
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
229 pattern2[]={ -2, -3, 4, 4, -3 }, *pattern;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
230 int f, m, n, t[5];
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
231
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
232 pattern=p->deghost>0?pattern2:pattern1;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
233
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
234 for(f=0; f<5; f++)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
235 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
236 if(phase1<0 || phase2<0 || f==phase1 || f==phase2)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
237 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
238 for(n=t[f]=0; n<5; n++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
239 t[f]+=diffs[n]*pattern[(n-f+5)%5];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
240 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
241 else
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
242 t[f]=INT_MIN;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
243 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
244
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
245 /* find the best match */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
246 for(m=0, n=1; n<5; n++)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
247 if(t[n]>t[m]) m=n;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
248
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
249 if(strength)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
250 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
251 /* the second best match */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
252 for(f=m?0:1, n=f+1; n<5; n++)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
253 if(n!=m && t[n]>t[f]) f=n;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
254
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
255 *strength=(t[m]>0?(double)(t[m]-t[f])/t[m]:0.0);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
256 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
257
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
258 return m;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
259 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
260
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
261 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
262 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
263 mp_image_t *dmpi, *tmpi=0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
264 int n, m, f, newphase;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
265 struct vf_priv_s *p=vf->priv;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
266 unsigned int checksum;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
267 double d;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
268
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
269 dmpi=vf_get_image(vf->next, mpi->imgfmt,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
270 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
271 MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
272 mpi->width, mpi->height);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
273 vf_clone_mpi_attributes(dmpi, mpi);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
274
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
275 newphase=p->phase;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
276
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
277 switch(p->pass)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
278 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
279 case 1:
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
280 fprintf(p->file, "%08x %d\n",
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
281 (unsigned int)imgop((void *)checksum_plane, mpi, 0, 0),
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
282 p->frameno?imgop(diff_plane, dmpi, mpi, 0):0);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
283 break;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
284
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
285 case 2:
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
286 if(p->frameno/5>p->bcount)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
287 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
288 mp_msg(MSGT_VFILTER, MSGL_ERR,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
289 "\n%s: Log file ends prematurely! "
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
290 "Switching to one pass mode.\n", vf->info->name);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
291 p->pass=0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
292 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
293 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
294
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
295 checksum=(unsigned int)imgop((void *)checksum_plane, mpi, 0, 0);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
296
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
297 if(checksum!=p->csdata[p->frameno])
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
298 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
299 for(f=0; f<100; f++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
300 if(p->frameno+f<p->fcount && p->csdata[p->frameno+f]==checksum)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
301 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
302 else if(p->frameno-f>=0 && p->csdata[p->frameno-f]==checksum)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
303 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
304 f=-f;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
305 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
306 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
307
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
308 if(f<100)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
309 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
310 mp_msg(MSGT_VFILTER, MSGL_INFO,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
311 "\n%s: Mismatch with pass-1: %+d frame(s).\n",
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
312 vf->info->name, f);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
313
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
314 p->frameno+=f;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
315 p->misscount=0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
316 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
317 else if(p->misscount++>=30)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
318 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
319 mp_msg(MSGT_VFILTER, MSGL_ERR,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
320 "\n%s: Sync with pass-1 lost! "
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
321 "Switching to one pass mode.\n", vf->info->name);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
322 p->pass=0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
323 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
324 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
325 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
326
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
327 n=(p->frameno)/5;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
328 if(n>=p->bcount) n=p->bcount-1;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
329
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
330 newphase=p->bdata[n];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
331 break;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
332
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
333 default:
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
334 if(p->frameno)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
335 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
336 int *sump=p->sum+p->frameno%5,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
337 *histp=p->history+p->frameno%p->window;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
338
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
339 *sump-=*histp;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
340 *sump+=(*histp=imgop(diff_plane, dmpi, mpi, 0));
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
341 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
342
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
343 m=match(p, p->sum, -1, -1, &d);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
344
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
345 if(d>=p->threshold)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
346 newphase=m;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
347 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
348
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
349 n=p->ocount++%5;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
350
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
351 if(newphase!=p->phase && ((p->phase+4)%5<n)==((newphase+4)%5<n))
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
352 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
353 p->phase=newphase;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
354 mp_msg(MSGT_VFILTER, MSGL_STATUS,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
355 "\n%s: Telecine phase %d.\n", vf->info->name, p->phase);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
356 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
357
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
358 switch((p->frameno++-p->phase+10)%5)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
359 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
360 case 0:
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
361 imgop(copyop, dmpi, mpi, 0);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
362 return 0;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
363
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
364 case 4:
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
365 if(p->deghost>0)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
366 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
367 tmpi=vf_get_image(vf->next, mpi->imgfmt,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
368 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
369 MP_IMGFLAG_READABLE,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
370 mpi->width, mpi->height);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
371 vf_clone_mpi_attributes(tmpi, mpi);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
372
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
373 imgop(copyop, tmpi, mpi, 0);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
374 imgop(deghost_plane, tmpi, dmpi, p->deghost);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
375 imgop(copyop, dmpi, mpi, 0);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
376 return vf_next_put_image(vf, tmpi, MP_NOPTS_VALUE);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
377 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
378 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
379
23666
5c3c7efd9b75 Get rid of my_memcpy_pic code duplication in many filters.
reimar
parents: 21507
diff changeset
380 imgop(copyop, dmpi, mpi, 0);
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
381 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
382 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
383
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
384 static int analyze(struct vf_priv_s *p)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
385 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
386 int *buf=0, *bp, bufsize=0, n, b, f, i, j, m, s;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
387 unsigned int *cbuf=0, *cp;
33443
02214457c955 Fix code incorrectly assuming "char" is signed.
reimar
parents: 32702
diff changeset
388 int8_t *pbuf;
02214457c955 Fix code incorrectly assuming "char" is signed.
reimar
parents: 32702
diff changeset
389 int8_t lbuf[256];
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
390 int sum[5];
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
391 double d;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
392
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
393 /* read the file */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
394
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
395 n=15;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
396 while(fgets(lbuf, 256, p->file))
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
397 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
398 if(n>=bufsize-19)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
399 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
400 bufsize=bufsize?bufsize*2:30000;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
401 if((bp=realloc(buf, bufsize*sizeof *buf))) buf=bp;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
402 if((cp=realloc(cbuf, bufsize*sizeof *cbuf))) cbuf=cp;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
403
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
404 if(!bp || !cp)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
405 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
406 mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Not enough memory.\n",
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
407 vf_info_divtc.name);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
408 free(buf);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
409 free(cbuf);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
410 return 0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
411 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
412 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
413 sscanf(lbuf, "%x %d", cbuf+n, buf+n);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
414 n++;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
415 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
416
35175
4f7230f2e549 Fix check for empty log file (n contains a start offset of 15).
reimar
parents: 34198
diff changeset
417 if(n <= 15)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
418 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
419 mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Empty 2-pass log file.\n",
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
420 vf_info_divtc.name);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
421 free(buf);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
422 free(cbuf);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
423 return 0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
424 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
425
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
426 /* generate some dummy data past the beginning and end of the array */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
427
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
428 buf+=15, cbuf+=15;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
429 n-=15;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
430
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
431 memcpy(buf-15, buf, 15*sizeof *buf);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
432 memset(cbuf-15, 0, 15*sizeof *cbuf);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
433
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
434 while(n%5)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
435 buf[n]=buf[n-5], cbuf[n]=0, n++;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
436
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
437 memcpy(buf+n, buf+n-15, 15*sizeof *buf);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
438 memset(cbuf+n, 0, 15*sizeof *cbuf);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
439
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
440 p->csdata=cbuf;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
441 p->fcount=n;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
442
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
443 /* array with one slot for each slice of 5 frames */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
444
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
445 p->bdata=pbuf=malloc(p->bcount=b=(n/5));
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
446 memset(pbuf, 255, b);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
447
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
448 /* resolve the automatic mode */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
449
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
450 if(p->deghost<0)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
451 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
452 int deghost=-p->deghost;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
453 double s0=0.0, s1=0.0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
454
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
455 for(f=0; f<n; f+=5)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
456 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
457 p->deghost=0; match(p, buf+f, -1, -1, &d); s0+=d;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
458 p->deghost=1; match(p, buf+f, -1, -1, &d); s1+=d;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
459 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
460
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
461 p->deghost=s1>s0?deghost:0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
462
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
463 mp_msg(MSGT_VFILTER, MSGL_INFO,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
464 "%s: Deghosting %-3s (relative pattern strength %+.2fdB).\n",
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
465 vf_info_divtc.name,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
466 p->deghost?"ON":"OFF",
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
467 10.0*log10(s1/s0));
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
468 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
469
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
470 /* analyze the data */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
471
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
472 for(f=0; f<5; f++)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
473 for(sum[f]=0, n=-15; n<20; n+=5)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
474 sum[f]+=buf[n+f];
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
475
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
476 for(f=0; f<b; f++)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
477 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
478 m=match(p, sum, -1, -1, &d);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
479
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
480 if(d>=p->threshold)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
481 pbuf[f]=m;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
482
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
483 if(f<b-1)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
484 for(n=0; n<5; n++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
485 sum[n]=sum[n]-buf[5*(f-3)+n]+buf[5*(f+4)+n];
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
486 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
487
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
488 /* fill in the gaps */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
489
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
490 /* the beginning */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
491 for(f=0; f<b && pbuf[f]==-1; f++);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
492
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
493 if(f==b)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
494 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
495 free(buf-15);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
496 mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: No telecine pattern found!\n",
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
497 vf_info_divtc.name);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
498 return 0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
499 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
500
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
501 for(n=0; n<f; pbuf[n++]=pbuf[f]);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
502
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
503 /* the end */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
504 for(f=b-1; pbuf[f]==-1; f--);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
505 for(n=f+1; n<b; pbuf[n++]=pbuf[f]);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
506
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
507 /* the rest */
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
508 for(f=0;;)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
509 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
510 while(f<b && pbuf[f]!=-1) f++;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
511 if(f==b) break;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
512 for(n=f; pbuf[n]==-1; n++);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
513
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
514 if(pbuf[f-1]==pbuf[n])
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
515 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
516 /* just a gap */
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
517 while(f<n) pbuf[f++]=pbuf[n];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
518 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
519 else
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
520 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
521 /* phase change, reanalyze the original data in the gap with zero
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
522 threshold for only the two phases that appear at the ends */
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
523
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
524 for(i=0; i<5; i++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
525 for(sum[i]=0, j=5*f-15; j<5*f; j+=5)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
526 sum[i]+=buf[i+j];
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
527
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
528 for(i=f; i<n; i++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
529 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
530 pbuf[i]=match(p, sum, pbuf[f-1], pbuf[n], 0);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
531
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
532 for(j=0; j<5; j++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
533 sum[j]=sum[j]-buf[5*(i-3)+j]+buf[5*(i+4)+j];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
534 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
535
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
536 /* estimate the transition point by dividing the gap
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
537 in the same proportion as the number of matches of each kind */
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
538
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
539 for(i=f, m=f; i<n; i++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
540 if(pbuf[i]==pbuf[f-1]) m++;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
541
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
542 /* find the transition of the right direction nearest to the
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
543 estimated point */
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
544
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
545 if(m>f && m<n)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
546 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
547 for(j=m; j>f; j--)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
548 if(pbuf[j-1]==pbuf[f-1] && pbuf[j]==pbuf[n]) break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
549 for(s=m; s<n; s++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
550 if(pbuf[s-1]==pbuf[f-1] && pbuf[s]==pbuf[n]) break;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
551
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
552 m=(s-m<m-j)?s:j;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
553 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
554
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
555 /* and rewrite the data to allow only this one transition */
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
556
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
557 for(i=f; i<m; i++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
558 pbuf[i]=pbuf[f-1];
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
559
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
560 for(; i<n; i++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
561 pbuf[i]=pbuf[n];
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
562
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
563 f=n;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
564 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
565 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
566
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
567 free(buf-15);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
568
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
569 return 1;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
570 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
571
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
572 static int query_format(struct vf_instance *vf, unsigned int fmt)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
573 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
574 switch(fmt)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
575 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
576 case IMGFMT_444P: case IMGFMT_IYUV: case IMGFMT_RGB24:
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
577 case IMGFMT_422P: case IMGFMT_UYVY: case IMGFMT_BGR24:
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
578 case IMGFMT_411P: case IMGFMT_YUY2: case IMGFMT_IF09:
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
579 case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_YVU9:
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
580 case IMGFMT_IUYV: case IMGFMT_Y800: case IMGFMT_Y8:
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
581 return vf_next_query_format(vf,fmt);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
582 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
583
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
584 return 0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
585 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
586
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
587 static void uninit(struct vf_instance *vf)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
588 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
589 if(vf->priv)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
590 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
591 if(vf->priv->file) fclose(vf->priv->file);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
592 if(vf->priv->csdata) free(vf->priv->csdata-15);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
593 free(vf->priv->bdata);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
594 free(vf->priv->history);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
595 free(vf->priv);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
596 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
597 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
598
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30421
diff changeset
599 static int vf_open(vf_instance_t *vf, char *args)
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
600 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
601 struct vf_priv_s *p;
33447
4506f91c0a06 Add "const" to avoid compiler warning.
reimar
parents: 33443
diff changeset
602 const char *filename="framediff.log";
4506f91c0a06 Add "const" to avoid compiler warning.
reimar
parents: 33443
diff changeset
603 char *ap, *q, *a;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
604
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
605 if(args && !(args=strdup(args)))
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
606 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
607 nomem:
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
608 mp_msg(MSGT_VFILTER, MSGL_FATAL,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
609 "%s: Not enough memory.\n", vf->info->name);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
610 fail:
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
611 uninit(vf);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
612 free(args);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
613 return 0;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
614 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
615
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
616 vf->put_image=put_image;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
617 vf->uninit=uninit;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
618 vf->query_format=query_format;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
619 vf->default_reqs=VFCAP_ACCEPT_STRIDE;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
620 if(!(vf->priv=p=calloc(1, sizeof(struct vf_priv_s))))
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
621 goto nomem;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
622
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
623 p->phase=5;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
624 p->threshold=0.5;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
625 p->window=30;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
626
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
627 if((ap=args))
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
628 while(*ap)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
629 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
630 q=ap;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
631 if((ap=strchr(q, ':'))) *ap++=0; else ap=q+strlen(q);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
632 if((a=strchr(q, '='))) *a++=0; else a=q+strlen(q);
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
633
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
634 switch(*q)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
635 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
636 case 0: break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
637 case 'f': filename=a; break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
638 case 't': p->threshold=atof(a); break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
639 case 'w': p->window=5*(atoi(a)+4)/5; break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
640 case 'd': p->deghost=atoi(a); break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
641 case 'p':
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
642 if(q[1]=='h') p->phase=atoi(a);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
643 else p->pass=atoi(a);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
644 break;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
645
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
646 case 'h':
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
647 mp_msg(MSGT_VFILTER, MSGL_INFO,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
648 "\n%s options:\n\n"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
649 "pass=1|2 - Use 2-pass mode.\n"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
650 "file=filename - Set the 2-pass log file name "
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
651 "(default %s).\n"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
652 "threshold=value - Set the pattern recognition "
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
653 "sensitivity (default %g).\n"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
654 "deghost=value - Select deghosting threshold "
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
655 "(default %d).\n"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
656 "window=numframes - Set the statistics window "
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
657 "for 1-pass mode (default %d).\n"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
658 "phase=0|1|2|3|4 - Set the initial phase "
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
659 "for 1-pass mode (default %d).\n\n"
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
660 "The option names can be abbreviated to the shortest "
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
661 "unique prefix.\n\n",
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
662 vf->info->name, filename, p->threshold, p->deghost,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
663 p->window, p->phase%5);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
664 break;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
665
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
666 default:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
667 mp_msg(MSGT_VFILTER, MSGL_FATAL,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
668 "%s: Unknown argument %s.\n", vf->info->name, q);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
669 goto fail;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
670 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
671 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
672
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
673 switch(p->pass)
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
674 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
675 case 1:
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
676 if(!(p->file=fopen(filename, "w")))
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
677 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
678 mp_msg(MSGT_VFILTER, MSGL_FATAL,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
679 "%s: Can't create file %s.\n", vf->info->name, filename);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
680 goto fail;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
681 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
682
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
683 break;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
684
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
685 case 2:
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
686 if(!(p->file=fopen(filename, "r")))
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
687 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
688 mp_msg(MSGT_VFILTER, MSGL_FATAL,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
689 "%s: Can't open file %s.\n", vf->info->name, filename);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
690 goto fail;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
691 }
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
692
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
693 if(!analyze(p))
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
694 goto fail;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
695
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
696 fclose(p->file);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
697 p->file=0;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
698 break;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
699 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
700
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
701 if(p->window<5) p->window=5;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
702 if(!(p->history=calloc(sizeof *p->history, p->window)))
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
703 goto nomem;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
704
28906
6cc8cc259dc1 Use the same code as in vf_decimate to select diff_MMX
reimar
parents: 28905
diff changeset
705 diff = diff_C;
28907
ccbde3575f0a Check for HAVE_EBX_AVAILABLE before enabling MMX code that needs the EBX
reimar
parents: 28906
diff changeset
706 #if HAVE_MMX && HAVE_EBX_AVAILABLE
28906
6cc8cc259dc1 Use the same code as in vf_decimate to select diff_MMX
reimar
parents: 28905
diff changeset
707 if(gCpuCaps.hasMMX) diff = diff_MMX;
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
708 #endif
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
709
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
710 free(args);
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
711 return 1;
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
712 }
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
713
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 24360
diff changeset
714 const vf_info_t vf_info_divtc =
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
715 {
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
716 "inverse telecine for deinterlaced video",
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
717 "divtc",
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
718 "Ville Saari",
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
719 "",
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30421
diff changeset
720 vf_open,
12225
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
721 NULL
eb79a6192b2b New filter by Ville Saari (114263 at foo dot bar dot org)
rfelker
parents:
diff changeset
722 };