annotate libmpcodecs/pullup.c @ 32555:8a556b3aff79

Handle ':' on systems with DOS paths: it allows paths like C:foo.avi.
author cboesch
date Sun, 21 Nov 2010 19:46:37 +0000
parents 32725ca88fed
children 7af3e6f901fd
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: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
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: 29263
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: 29263
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: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
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: 29263
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: 29263
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: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
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: 29263
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: 29263
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: 29263
diff changeset
17 */
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
18
11412
ec3dac7d17a0 Warning fixes (approved by A'rpi).
rathann
parents: 10956
diff changeset
19 #include <stdio.h>
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
20 #include <stdlib.h>
11412
ec3dac7d17a0 Warning fixes (approved by A'rpi).
rathann
parents: 10956
diff changeset
21 #include <string.h>
26203
0d255d03016f #include config.h before all other headers.
diego
parents: 24350
diff changeset
22 #include "config.h"
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
23 #include "pullup.h"
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
24 #include "cpudetect.h"
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
25
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
26
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
27
28290
25337a2147e7 Lots and lots of #ifdef ARCH_... -> #if ARCH_...
reimar
parents: 27754
diff changeset
28 #if ARCH_X86
25337a2147e7 Lots and lots of #ifdef ARCH_... -> #if ARCH_...
reimar
parents: 27754
diff changeset
29 #if HAVE_MMX
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
30 static int diff_y_mmx(unsigned char *a, unsigned char *b, int s)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
31 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
32 int ret;
27754
08d18fe9da52 Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents: 26203
diff changeset
33 __asm__ volatile (
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
34 "movl $4, %%ecx \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
35 "pxor %%mm4, %%mm4 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
36 "pxor %%mm7, %%mm7 \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
37
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
38 "1: \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
39
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
40 "movq (%%"REG_S"), %%mm0 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
41 "movq (%%"REG_S"), %%mm2 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
42 "add %%"REG_a", %%"REG_S" \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
43 "movq (%%"REG_D"), %%mm1 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
44 "add %%"REG_a", %%"REG_D" \n\t"
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
45 "psubusb %%mm1, %%mm2 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
46 "psubusb %%mm0, %%mm1 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
47 "movq %%mm2, %%mm0 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
48 "movq %%mm1, %%mm3 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
49 "punpcklbw %%mm7, %%mm0 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
50 "punpcklbw %%mm7, %%mm1 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
51 "punpckhbw %%mm7, %%mm2 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
52 "punpckhbw %%mm7, %%mm3 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
53 "paddw %%mm0, %%mm4 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
54 "paddw %%mm1, %%mm4 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
55 "paddw %%mm2, %%mm4 \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
56 "paddw %%mm3, %%mm4 \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
57
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
58 "decl %%ecx \n\t"
10741
fec729835823 1000l, mmx code was not being used because of missing config.h, and
rfelker
parents: 10738
diff changeset
59 "jnz 1b \n\t"
fec729835823 1000l, mmx code was not being used because of missing config.h, and
rfelker
parents: 10738
diff changeset
60
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
61 "movq %%mm4, %%mm3 \n\t"
10741
fec729835823 1000l, mmx code was not being used because of missing config.h, and
rfelker
parents: 10738
diff changeset
62 "punpcklwd %%mm7, %%mm4 \n\t"
fec729835823 1000l, mmx code was not being used because of missing config.h, and
rfelker
parents: 10738
diff changeset
63 "punpckhwd %%mm7, %%mm3 \n\t"
fec729835823 1000l, mmx code was not being used because of missing config.h, and
rfelker
parents: 10738
diff changeset
64 "paddd %%mm4, %%mm3 \n\t"
fec729835823 1000l, mmx code was not being used because of missing config.h, and
rfelker
parents: 10738
diff changeset
65 "movd %%mm3, %%eax \n\t"
fec729835823 1000l, mmx code was not being used because of missing config.h, and
rfelker
parents: 10738
diff changeset
66 "psrlq $32, %%mm3 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
67 "movd %%mm3, %%edx \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
68 "addl %%edx, %%eax \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
69 "emms \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
70 : "=a" (ret)
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
71 : "S" (a), "D" (b), "a" (s)
14620
b9a05a395726 added ecx to clobber list
alex
parents: 14619
diff changeset
72 : "%ecx", "%edx"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
73 );
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
74 return ret;
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
75 }
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
76
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
77 static int licomb_y_mmx(unsigned char *a, unsigned char *b, int s)
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
78 {
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
79 int ret;
27754
08d18fe9da52 Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents: 26203
diff changeset
80 __asm__ volatile (
11624
03e8cbee7333 100l bug found by Zoli, wasted time and unfairly delocalized the metrics
rfelker
parents: 11412
diff changeset
81 "movl $4, %%ecx \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
82 "pxor %%mm6, %%mm6 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
83 "pxor %%mm7, %%mm7 \n\t"
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
84 "sub %%"REG_a", %%"REG_D" \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
85
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
86 "2: \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
87
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
88 "movq (%%"REG_D"), %%mm0 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
89 "movq (%%"REG_D"), %%mm1 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
90 "punpcklbw %%mm7, %%mm0 \n\t"
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
91 "movq (%%"REG_D",%%"REG_a"), %%mm2 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
92 "punpcklbw %%mm7, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
93 "punpcklbw %%mm7, %%mm2 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
94 "paddw %%mm0, %%mm0 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
95 "paddw %%mm2, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
96 "movq %%mm0, %%mm2 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
97 "psubusw %%mm1, %%mm0 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
98 "psubusw %%mm2, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
99 "paddw %%mm0, %%mm6 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
100 "paddw %%mm1, %%mm6 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
101
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
102 "movq (%%"REG_S"), %%mm0 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
103 "movq (%%"REG_D"), %%mm1 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
104 "punpckhbw %%mm7, %%mm0 \n\t"
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
105 "movq (%%"REG_D",%%"REG_a"), %%mm2 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
106 "punpckhbw %%mm7, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
107 "punpckhbw %%mm7, %%mm2 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
108 "paddw %%mm0, %%mm0 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
109 "paddw %%mm2, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
110 "movq %%mm0, %%mm2 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
111 "psubusw %%mm1, %%mm0 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
112 "psubusw %%mm2, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
113 "paddw %%mm0, %%mm6 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
114 "paddw %%mm1, %%mm6 \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
115
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
116 "movq (%%"REG_D",%%"REG_a"), %%mm0 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
117 "movq (%%"REG_S"), %%mm1 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
118 "punpcklbw %%mm7, %%mm0 \n\t"
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
119 "movq (%%"REG_S",%%"REG_a"), %%mm2 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
120 "punpcklbw %%mm7, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
121 "punpcklbw %%mm7, %%mm2 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
122 "paddw %%mm0, %%mm0 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
123 "paddw %%mm2, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
124 "movq %%mm0, %%mm2 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
125 "psubusw %%mm1, %%mm0 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
126 "psubusw %%mm2, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
127 "paddw %%mm0, %%mm6 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
128 "paddw %%mm1, %%mm6 \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
129
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
130 "movq (%%"REG_D",%%"REG_a"), %%mm0 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
131 "movq (%%"REG_S"), %%mm1 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
132 "punpckhbw %%mm7, %%mm0 \n\t"
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
133 "movq (%%"REG_S",%%"REG_a"), %%mm2 \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
134 "punpckhbw %%mm7, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
135 "punpckhbw %%mm7, %%mm2 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
136 "paddw %%mm0, %%mm0 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
137 "paddw %%mm2, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
138 "movq %%mm0, %%mm2 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
139 "psubusw %%mm1, %%mm0 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
140 "psubusw %%mm2, %%mm1 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
141 "paddw %%mm0, %%mm6 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
142 "paddw %%mm1, %%mm6 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
143
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
144 "add %%"REG_a", %%"REG_S" \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
145 "add %%"REG_a", %%"REG_D" \n\t"
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
146 "decl %%ecx \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
147 "jnz 2b \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
148
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
149 "movq %%mm6, %%mm5 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
150 "punpcklwd %%mm7, %%mm6 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
151 "punpckhwd %%mm7, %%mm5 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
152 "paddd %%mm6, %%mm5 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
153 "movd %%mm5, %%eax \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
154 "psrlq $32, %%mm5 \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
155 "movd %%mm5, %%edx \n\t"
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
156 "addl %%edx, %%eax \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
157
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
158 "emms \n\t"
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
159 : "=a" (ret)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
160 : "S" (a), "D" (b), "a" (s)
14620
b9a05a395726 added ecx to clobber list
alex
parents: 14619
diff changeset
161 : "%ecx", "%edx"
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
162 );
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
163 return ret;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
164 }
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
165
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
166 static int var_y_mmx(unsigned char *a, unsigned char *b, int s)
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
167 {
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
168 int ret;
27754
08d18fe9da52 Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents: 26203
diff changeset
169 __asm__ volatile (
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
170 "movl $3, %%ecx \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
171 "pxor %%mm4, %%mm4 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
172 "pxor %%mm7, %%mm7 \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
173
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
174 "1: \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
175
20961
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
176 "movq (%%"REG_S"), %%mm0 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
177 "movq (%%"REG_S"), %%mm2 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
178 "movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t"
a26421864b53 Fix AMD64 support, patch by Reimar Doffinger
gpoirier
parents: 18976
diff changeset
179 "add %%"REG_a", %%"REG_S" \n\t"
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
180 "psubusb %%mm1, %%mm2 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
181 "psubusb %%mm0, %%mm1 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
182 "movq %%mm2, %%mm0 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
183 "movq %%mm1, %%mm3 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
184 "punpcklbw %%mm7, %%mm0 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
185 "punpcklbw %%mm7, %%mm1 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
186 "punpckhbw %%mm7, %%mm2 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
187 "punpckhbw %%mm7, %%mm3 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
188 "paddw %%mm0, %%mm4 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
189 "paddw %%mm1, %%mm4 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
190 "paddw %%mm2, %%mm4 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
191 "paddw %%mm3, %%mm4 \n\t"
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
192
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
193 "decl %%ecx \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
194 "jnz 1b \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
195
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
196 "movq %%mm4, %%mm3 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
197 "punpcklwd %%mm7, %%mm4 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
198 "punpckhwd %%mm7, %%mm3 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
199 "paddd %%mm4, %%mm3 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
200 "movd %%mm3, %%eax \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
201 "psrlq $32, %%mm3 \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
202 "movd %%mm3, %%edx \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
203 "addl %%edx, %%eax \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
204 "emms \n\t"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
205 : "=a" (ret)
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
206 : "S" (a), "a" (s)
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
207 : "%ecx", "%edx"
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
208 );
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
209 return 4*ret;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
210 }
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
211 #endif
13720
821f464b4d90 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents: 13235
diff changeset
212 #endif
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
213
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
214 #define ABS(a) (((a)^((a)>>31))-((a)>>31))
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
215
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
216 static int diff_y(unsigned char *a, unsigned char *b, int s)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
217 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
218 int i, j, diff=0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
219 for (i=4; i; i--) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
220 for (j=0; j<8; j++) diff += ABS(a[j]-b[j]);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
221 a+=s; b+=s;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
222 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
223 return diff;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
224 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
225
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
226 static int licomb_y(unsigned char *a, unsigned char *b, int s)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
227 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
228 int i, j, diff=0;
11624
03e8cbee7333 100l bug found by Zoli, wasted time and unfairly delocalized the metrics
rfelker
parents: 11412
diff changeset
229 for (i=4; i; i--) {
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
230 for (j=0; j<8; j++)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
231 diff += ABS((a[j]<<1) - b[j-s] - b[j])
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
232 + ABS((b[j]<<1) - a[j] - a[j+s]);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
233 a+=s; b+=s;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
234 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
235 return diff;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
236 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
237
24319
033b9debbec4 warnig fix (blessed by Rich):
diego
parents: 24176
diff changeset
238 #if 0
11626
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
239 static int qpcomb_y(unsigned char *a, unsigned char *b, int s)
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
240 {
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
241 int i, j, diff=0;
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
242 for (i=4; i; i--) {
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
243 for (j=0; j<8; j++)
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
244 diff += ABS(a[j] - 3*b[j-s] + 3*a[j+s] - b[j]);
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
245 a+=s; b+=s;
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
246 }
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
247 return diff;
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
248 }
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
249
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
250 static int licomb_y_test(unsigned char *a, unsigned char *b, int s)
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
251 {
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
252 int c = licomb_y(a,b,s);
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
253 int m = licomb_y_mmx(a,b,s);
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
254 if (c != m) printf("%d != %d\n", c, m);
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
255 return m;
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
256 }
10843
60f58eadd666 10l, debug code broke compile with mmx disabled
rfelker
parents: 10747
diff changeset
257 #endif
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
258
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
259 static int var_y(unsigned char *a, unsigned char *b, int s)
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
260 {
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
261 int i, j, var=0;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
262 for (i=3; i; i--) {
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
263 for (j=0; j<8; j++) {
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
264 var += ABS(a[j]-a[j+s]);
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
265 }
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
266 a+=s; b+=s;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
267 }
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
268 return 4*var; /* match comb scaling */
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
269 }
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
270
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
271
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
272
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
273
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
274
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
275
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
276
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
277
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
278
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
279 static void alloc_buffer(struct pullup_context *c, struct pullup_buffer *b)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
280 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
281 int i;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
282 if (b->planes) return;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
283 b->planes = calloc(c->nplanes, sizeof(unsigned char *));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
284 for (i = 0; i < c->nplanes; i++) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
285 b->planes[i] = malloc(c->h[i]*c->stride[i]);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
286 /* Deal with idiotic 128=0 for chroma: */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
287 memset(b->planes[i], c->background[i], c->h[i]*c->stride[i]);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
288 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
289 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
290
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
291 struct pullup_buffer *pullup_lock_buffer(struct pullup_buffer *b, int parity)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
292 {
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
293 if (!b) return 0;
14619
f5e2fa7ec219 adding proper parenthesing
alex
parents: 13720
diff changeset
294 if ((parity+1) & 1) b->lock[0]++;
f5e2fa7ec219 adding proper parenthesing
alex
parents: 13720
diff changeset
295 if ((parity+1) & 2) b->lock[1]++;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
296 return b;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
297 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
298
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
299 void pullup_release_buffer(struct pullup_buffer *b, int parity)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
300 {
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
301 if (!b) return;
14619
f5e2fa7ec219 adding proper parenthesing
alex
parents: 13720
diff changeset
302 if ((parity+1) & 1) b->lock[0]--;
f5e2fa7ec219 adding proper parenthesing
alex
parents: 13720
diff changeset
303 if ((parity+1) & 2) b->lock[1]--;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
304 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
305
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
306 struct pullup_buffer *pullup_get_buffer(struct pullup_context *c, int parity)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
307 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
308 int i;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
309
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
310 /* Try first to get the sister buffer for the previous field */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
311 if (parity < 2 && c->last && parity != c->last->parity
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
312 && !c->last->buffer->lock[parity]) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
313 alloc_buffer(c, c->last->buffer);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
314 return pullup_lock_buffer(c->last->buffer, parity);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
315 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
316
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
317 /* Prefer a buffer with both fields open */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
318 for (i = 0; i < c->nbuffers; i++) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
319 if (c->buffers[i].lock[0]) continue;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
320 if (c->buffers[i].lock[1]) continue;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
321 alloc_buffer(c, &c->buffers[i]);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
322 return pullup_lock_buffer(&c->buffers[i], parity);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
323 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
324
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
325 if (parity == 2) return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
326
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
327 /* Search for any half-free buffer */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
328 for (i = 0; i < c->nbuffers; i++) {
14619
f5e2fa7ec219 adding proper parenthesing
alex
parents: 13720
diff changeset
329 if (((parity+1) & 1) && c->buffers[i].lock[0]) continue;
f5e2fa7ec219 adding proper parenthesing
alex
parents: 13720
diff changeset
330 if (((parity+1) & 2) && c->buffers[i].lock[1]) continue;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
331 alloc_buffer(c, &c->buffers[i]);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
332 return pullup_lock_buffer(&c->buffers[i], parity);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
333 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
334
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
335 return 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
336 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
337
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
338
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
339
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
340
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
341
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
342
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
343 static void compute_metric(struct pullup_context *c,
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
344 struct pullup_field *fa, int pa,
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
345 struct pullup_field *fb, int pb,
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
346 int (*func)(unsigned char *, unsigned char *, int), int *dest)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
347 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
348 unsigned char *a, *b;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
349 int x, y;
10956
fdcd0d571912 support for selecting which plane to use for metrics in the pullup
rfelker
parents: 10843
diff changeset
350 int mp = c->metric_plane;
fdcd0d571912 support for selecting which plane to use for metrics in the pullup
rfelker
parents: 10843
diff changeset
351 int xstep = c->bpp[mp];
fdcd0d571912 support for selecting which plane to use for metrics in the pullup
rfelker
parents: 10843
diff changeset
352 int ystep = c->stride[mp]<<3;
fdcd0d571912 support for selecting which plane to use for metrics in the pullup
rfelker
parents: 10843
diff changeset
353 int s = c->stride[mp]<<1; /* field stride */
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
354 int w = c->metric_w*xstep;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
355
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
356 if (!fa->buffer || !fb->buffer) return;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
357
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
358 /* Shortcut for duplicate fields (e.g. from RFF flag) */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
359 if (fa->buffer == fb->buffer && pa == pb) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
360 memset(dest, 0, c->metric_len * sizeof(int));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
361 return;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
362 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
363
10956
fdcd0d571912 support for selecting which plane to use for metrics in the pullup
rfelker
parents: 10843
diff changeset
364 a = fa->buffer->planes[mp] + pa * c->stride[mp] + c->metric_offset;
fdcd0d571912 support for selecting which plane to use for metrics in the pullup
rfelker
parents: 10843
diff changeset
365 b = fb->buffer->planes[mp] + pb * c->stride[mp] + c->metric_offset;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
366
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
367 for (y = c->metric_h; y; y--) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
368 for (x = 0; x < w; x += xstep) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
369 *dest++ = func(a + x, b + x, s);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
370 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
371 a += ystep; b += ystep;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
372 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
373 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
374
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
375
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
376
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
377
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
378
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
379 static void alloc_metrics(struct pullup_context *c, struct pullup_field *f)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
380 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
381 f->diffs = calloc(c->metric_len, sizeof(int));
11626
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
382 f->comb = calloc(c->metric_len, sizeof(int));
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
383 f->var = calloc(c->metric_len, sizeof(int));
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
384 /* add more metrics here as needed */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
385 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
386
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
387 static struct pullup_field *make_field_queue(struct pullup_context *c, int len)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
388 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
389 struct pullup_field *head, *f;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
390 f = head = calloc(1, sizeof(struct pullup_field));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
391 alloc_metrics(c, f);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
392 for (; len > 0; len--) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
393 f->next = calloc(1, sizeof(struct pullup_field));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
394 f->next->prev = f;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
395 f = f->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
396 alloc_metrics(c, f);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
397 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
398 f->next = head;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
399 head->prev = f;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
400 return head;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
401 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
402
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
403 static void check_field_queue(struct pullup_context *c)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
404 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
405 if (c->head->next == c->first) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
406 struct pullup_field *f = calloc(1, sizeof(struct pullup_field));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
407 alloc_metrics(c, f);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
408 f->prev = c->head;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
409 f->next = c->first;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
410 c->head->next = f;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
411 c->first->prev = f;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
412 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
413 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
414
11412
ec3dac7d17a0 Warning fixes (approved by A'rpi).
rathann
parents: 10956
diff changeset
415 void pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, int parity)
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
416 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
417 struct pullup_field *f;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
418
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
419 /* Grow the circular list if needed */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
420 check_field_queue(c);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
421
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
422 /* Cannot have two fields of same parity in a row; drop the new one */
11412
ec3dac7d17a0 Warning fixes (approved by A'rpi).
rathann
parents: 10956
diff changeset
423 if (c->last && c->last->parity == parity) return;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
424
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
425 f = c->head;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
426 f->parity = parity;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
427 f->buffer = pullup_lock_buffer(b, parity);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
428 f->flags = 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
429 f->breaks = 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
430 f->affinity = 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
431
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
432 compute_metric(c, f, parity, f->prev->prev, parity, c->diff, f->diffs);
11626
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
433 compute_metric(c, parity?f->prev:f, 0, parity?f:f->prev, 1, c->comb, f->comb);
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
434 compute_metric(c, f, parity, f, -1, c->var, f->var);
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
435
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
436 /* Advance the circular list */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
437 if (!c->first) c->first = c->head;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
438 c->last = c->head;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
439 c->head = c->head->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
440 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
441
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
442 void pullup_flush_fields(struct pullup_context *c)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
443 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
444 struct pullup_field *f;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
445
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
446 for (f = c->first; f && f != c->head; f = f->next) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
447 pullup_release_buffer(f->buffer, f->parity);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
448 f->buffer = 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
449 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
450 c->first = c->last = 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
451 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
452
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
453
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
454
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
455
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
456
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
457
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
458
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
459
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
460 #define F_HAVE_BREAKS 1
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
461 #define F_HAVE_AFFINITY 2
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
462
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
463
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
464 #define BREAK_LEFT 1
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
465 #define BREAK_RIGHT 2
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
466
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
467
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
468
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
469
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
470 static int queue_length(struct pullup_field *begin, struct pullup_field *end)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
471 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
472 int count = 1;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
473 struct pullup_field *f;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
474
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
475 if (!begin || !end) return 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
476 for (f = begin; f != end; f = f->next) count++;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
477 return count;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
478 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
479
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
480 static int find_first_break(struct pullup_field *f, int max)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
481 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
482 int i;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
483 for (i = 0; i < max; i++) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
484 if (f->breaks & BREAK_RIGHT || f->next->breaks & BREAK_LEFT)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
485 return i+1;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
486 f = f->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
487 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
488 return 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
489 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
490
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
491 static void compute_breaks(struct pullup_context *c, struct pullup_field *f0)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
492 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
493 int i;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
494 struct pullup_field *f1 = f0->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
495 struct pullup_field *f2 = f1->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
496 struct pullup_field *f3 = f2->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
497 int l, max_l=0, max_r=0;
13234
7056d7cfcd02 just some debugging junk i'd like to have in there for now :)
rfelker
parents: 12548
diff changeset
498 //struct pullup_field *ff;
7056d7cfcd02 just some debugging junk i'd like to have in there for now :)
rfelker
parents: 12548
diff changeset
499 //for (i=0, ff=c->first; ff != f0; i++, ff=ff->next);
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
500
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
501 if (f0->flags & F_HAVE_BREAKS) return;
13234
7056d7cfcd02 just some debugging junk i'd like to have in there for now :)
rfelker
parents: 12548
diff changeset
502 //printf("\n%d: ", i);
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
503 f0->flags |= F_HAVE_BREAKS;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
504
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
505 /* Special case when fields are 100% identical */
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
506 if (f0->buffer == f2->buffer && f1->buffer != f3->buffer) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
507 f2->breaks |= BREAK_RIGHT;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
508 return;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
509 }
12548
8584fdad0188 old changes in my local tree i forgot to commit - minor fixes
rfelker
parents: 11641
diff changeset
510 if (f0->buffer != f2->buffer && f1->buffer == f3->buffer) {
8584fdad0188 old changes in my local tree i forgot to commit - minor fixes
rfelker
parents: 11641
diff changeset
511 f1->breaks |= BREAK_LEFT;
8584fdad0188 old changes in my local tree i forgot to commit - minor fixes
rfelker
parents: 11641
diff changeset
512 return;
8584fdad0188 old changes in my local tree i forgot to commit - minor fixes
rfelker
parents: 11641
diff changeset
513 }
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
514
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
515 for (i = 0; i < c->metric_len; i++) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
516 l = f2->diffs[i] - f3->diffs[i];
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
517 if (l > max_l) max_l = l;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
518 if (-l > max_r) max_r = -l;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
519 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
520 /* Don't get tripped up when differences are mostly quant error */
13234
7056d7cfcd02 just some debugging junk i'd like to have in there for now :)
rfelker
parents: 12548
diff changeset
521 //printf("%d %d\n", max_l, max_r);
10738
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
522 if (max_l + max_r < 128) return;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
523 if (max_l > 4*max_r) f1->breaks |= BREAK_LEFT;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
524 if (max_r > 4*max_l) f2->breaks |= BREAK_RIGHT;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
525 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
526
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
527 static void compute_affinity(struct pullup_context *c, struct pullup_field *f)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
528 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
529 int i;
11641
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
530 int max_l=0, max_r=0, l;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
531 if (f->flags & F_HAVE_AFFINITY) return;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
532 f->flags |= F_HAVE_AFFINITY;
14951
12c44e82440a improve handling of soft-telecined input (faster, fewer mistakes)
rfelker
parents: 14620
diff changeset
533 if (f->buffer == f->next->next->buffer) {
12c44e82440a improve handling of soft-telecined input (faster, fewer mistakes)
rfelker
parents: 14620
diff changeset
534 f->affinity = 1;
12c44e82440a improve handling of soft-telecined input (faster, fewer mistakes)
rfelker
parents: 14620
diff changeset
535 f->next->affinity = 0;
12c44e82440a improve handling of soft-telecined input (faster, fewer mistakes)
rfelker
parents: 14620
diff changeset
536 f->next->next->affinity = -1;
12c44e82440a improve handling of soft-telecined input (faster, fewer mistakes)
rfelker
parents: 14620
diff changeset
537 f->next->flags |= F_HAVE_AFFINITY;
12c44e82440a improve handling of soft-telecined input (faster, fewer mistakes)
rfelker
parents: 14620
diff changeset
538 f->next->next->flags |= F_HAVE_AFFINITY;
12c44e82440a improve handling of soft-telecined input (faster, fewer mistakes)
rfelker
parents: 14620
diff changeset
539 return;
12c44e82440a improve handling of soft-telecined input (faster, fewer mistakes)
rfelker
parents: 14620
diff changeset
540 }
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
541 if (1) {
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
542 for (i = 0; i < c->metric_len; i++) {
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
543 int lv = f->prev->var[i];
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
544 int rv = f->next->var[i];
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
545 int v = f->var[i];
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
546 int lc = f->comb[i] - (v+lv) + ABS(v-lv);
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
547 int rc = f->next->comb[i] - (v+rv) + ABS(v-rv);
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
548 lc = lc>0 ? lc : 0;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
549 rc = rc>0 ? rc : 0;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
550 l = lc - rc;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
551 if (l > max_l) max_l = l;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
552 if (-l > max_r) max_r = -l;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
553 }
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
554 if (max_l + max_r < 64) return;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
555 if (max_r > 6*max_l) f->affinity = -1;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
556 else if (max_l > 6*max_r) f->affinity = 1;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
557 } else {
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
558 for (i = 0; i < c->metric_len; i++) {
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
559 l = f->comb[i] - f->next->comb[i];
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
560 if (l > max_l) max_l = l;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
561 if (-l > max_r) max_r = -l;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
562 }
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
563 if (max_l + max_r < 64) return;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
564 if (max_r > 2*max_l) f->affinity = -1;
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
565 else if (max_l > 2*max_r) f->affinity = 1;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
566 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
567 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
568
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
569 static void foo(struct pullup_context *c)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
570 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
571 struct pullup_field *f = c->first;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
572 int i, n = queue_length(f, c->last);
10730
67449e5936f3 fix 10l (computation based on uninitialized data which led to
rfelker
parents: 10664
diff changeset
573 for (i = 0; i < n-1; i++) {
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
574 if (i < n-3) compute_breaks(c, f);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
575 compute_affinity(c, f);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
576 f = f->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
577 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
578 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
579
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
580 static int decide_frame_length(struct pullup_context *c)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
581 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
582 struct pullup_field *f0 = c->first;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
583 struct pullup_field *f1 = f0->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
584 struct pullup_field *f2 = f1->next;
13235
bc7cb8cf36b2 strictness level -1 to 'almost' ignore breaks
rfelker
parents: 13234
diff changeset
585 int l;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
586
14973
08002417b7e4 don't buffer more future context that we need
rfelker
parents: 14969
diff changeset
587 if (queue_length(c->first, c->last) < 4) return 0;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
588 foo(c);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
589
10730
67449e5936f3 fix 10l (computation based on uninitialized data which led to
rfelker
parents: 10664
diff changeset
590 if (f0->affinity == -1) return 1;
67449e5936f3 fix 10l (computation based on uninitialized data which led to
rfelker
parents: 10664
diff changeset
591
13235
bc7cb8cf36b2 strictness level -1 to 'almost' ignore breaks
rfelker
parents: 13234
diff changeset
592 l = find_first_break(f0, 3);
bc7cb8cf36b2 strictness level -1 to 'almost' ignore breaks
rfelker
parents: 13234
diff changeset
593 if (l == 1 && c->strict_breaks < 0) l = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
594
13235
bc7cb8cf36b2 strictness level -1 to 'almost' ignore breaks
rfelker
parents: 13234
diff changeset
595 switch (l) {
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
596 case 1:
14969
e6ba8d3ba040 100l, meaning of strict_breaks was backwards...
rfelker
parents: 14951
diff changeset
597 if (c->strict_breaks < 1 && f0->affinity == 1 && f1->affinity == -1)
11641
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
598 return 2;
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
599 else return 1;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
600 case 2:
11641
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
601 /* FIXME: strictly speaking, f0->prev is no longer valid... :) */
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
602 if (c->strict_pairs
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
603 && (f0->prev->breaks & BREAK_RIGHT) && (f2->breaks & BREAK_LEFT)
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
604 && (f0->affinity != 1 || f1->affinity != -1) )
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
605 return 1;
10730
67449e5936f3 fix 10l (computation based on uninitialized data which led to
rfelker
parents: 10664
diff changeset
606 if (f1->affinity == 1) return 1;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
607 else return 2;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
608 case 3:
11641
b7c269232edd various updates:
rfelker
parents: 11631
diff changeset
609 if (f2->affinity == 1) return 2;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
610 else return 3;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
611 default:
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
612 /* 9 possibilities covered before switch */
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
613 if (f1->affinity == 1) return 1; /* covers 6 */
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
614 else if (f1->affinity == -1) return 2; /* covers 6 */
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
615 else if (f2->affinity == -1) { /* covers 2 */
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
616 if (f0->affinity == 1) return 3;
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
617 else return 1;
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
618 }
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
619 else return 2; /* the remaining 6 */
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
620 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
621 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
622
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
623
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
624 static void print_aff_and_breaks(struct pullup_context *c, struct pullup_field *f)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
625 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
626 int i;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
627 struct pullup_field *f0 = f;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
628 const char aff_l[] = "+..", aff_r[] = "..+";
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
629 printf("\naffinity: ");
14973
08002417b7e4 don't buffer more future context that we need
rfelker
parents: 14969
diff changeset
630 for (i = 0; i < 4; i++) {
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
631 printf("%c%d%c", aff_l[1+f->affinity], i, aff_r[1+f->affinity]);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
632 f = f->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
633 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
634 f = f0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
635 printf("\nbreaks: ");
14973
08002417b7e4 don't buffer more future context that we need
rfelker
parents: 14969
diff changeset
636 for (i=0; i<4; i++) {
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
637 printf("%c%d%c", f->breaks & BREAK_LEFT ? '|' : '.', i, f->breaks & BREAK_RIGHT ? '|' : '.');
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
638 f = f->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
639 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
640 printf("\n");
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
641 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
642
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
643
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
644
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
645
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
646
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
647 struct pullup_frame *pullup_get_frame(struct pullup_context *c)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
648 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
649 int i;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
650 struct pullup_frame *fr = c->frame;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
651 int n = decide_frame_length(c);
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
652 int aff = c->first->next->affinity;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
653
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
654 if (!n) return 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
655 if (fr->lock) return 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
656
10738
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
657 if (c->verbose) {
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
658 print_aff_and_breaks(c, c->first);
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
659 printf("duration: %d \n", n);
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
660 }
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
661
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
662 fr->lock++;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
663 fr->length = n;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
664 fr->parity = c->first->parity;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
665 fr->buffer = 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
666 for (i = 0; i < n; i++) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
667 /* We cheat and steal the buffer without release+relock */
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
668 fr->ifields[i] = c->first->buffer;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
669 c->first->buffer = 0;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
670 c->first = c->first->next;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
671 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
672
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
673 if (n == 1) {
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
674 fr->ofields[fr->parity] = fr->ifields[0];
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
675 fr->ofields[fr->parity^1] = 0;
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
676 } else if (n == 2) {
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
677 fr->ofields[fr->parity] = fr->ifields[0];
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
678 fr->ofields[fr->parity^1] = fr->ifields[1];
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
679 } else if (n == 3) {
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
680 if (aff == 0)
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
681 aff = (fr->ifields[0] == fr->ifields[1]) ? -1 : 1;
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
682 /* else if (c->verbose) printf("forced aff: %d \n", aff); */
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
683 fr->ofields[fr->parity] = fr->ifields[1+aff];
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
684 fr->ofields[fr->parity^1] = fr->ifields[1];
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
685 }
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
686 pullup_lock_buffer(fr->ofields[0], 0);
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
687 pullup_lock_buffer(fr->ofields[1], 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
688
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
689 if (fr->ofields[0] == fr->ofields[1]) {
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
690 fr->buffer = fr->ofields[0];
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
691 pullup_lock_buffer(fr->buffer, 2);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
692 return fr;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
693 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
694 return fr;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
695 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
696
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
697 static void copy_field(struct pullup_context *c, struct pullup_buffer *dest,
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
698 struct pullup_buffer *src, int parity)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
699 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
700 int i, j;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
701 unsigned char *d, *s;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
702 for (i = 0; i < c->nplanes; i++) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
703 s = src->planes[i] + parity*c->stride[i];
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
704 d = dest->planes[i] + parity*c->stride[i];
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
705 for (j = c->h[i]>>1; j; j--) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
706 memcpy(d, s, c->stride[i]);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
707 s += c->stride[i]<<1;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
708 d += c->stride[i]<<1;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
709 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
710 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
711 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
712
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
713 void pullup_pack_frame(struct pullup_context *c, struct pullup_frame *fr)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
714 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
715 int i;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
716 if (fr->buffer) return;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
717 if (fr->length < 2) return; /* FIXME: deal with this */
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
718 for (i = 0; i < 2; i++)
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
719 {
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
720 if (fr->ofields[i]->lock[i^1]) continue;
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
721 fr->buffer = fr->ofields[i];
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
722 pullup_lock_buffer(fr->buffer, 2);
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
723 copy_field(c, fr->buffer, fr->ofields[i^1], i^1);
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
724 return;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
725 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
726 fr->buffer = pullup_get_buffer(c, 2);
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
727 copy_field(c, fr->buffer, fr->ofields[0], 0);
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
728 copy_field(c, fr->buffer, fr->ofields[1], 1);
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
729 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
730
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
731 void pullup_release_frame(struct pullup_frame *fr)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
732 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
733 int i;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
734 for (i = 0; i < fr->length; i++)
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
735 pullup_release_buffer(fr->ifields[i], fr->parity ^ (i&1));
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
736 pullup_release_buffer(fr->ofields[0], 0);
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
737 pullup_release_buffer(fr->ofields[1], 1);
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
738 if (fr->buffer) pullup_release_buffer(fr->buffer, 2);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
739 fr->lock--;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
740 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
741
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
742
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
743
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
744
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
745
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
746
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 15721
diff changeset
747 struct pullup_context *pullup_alloc_context(void)
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
748 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
749 struct pullup_context *c;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
750
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
751 c = calloc(1, sizeof(struct pullup_context));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
752
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
753 return c;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
754 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
755
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
756 void pullup_preinit_context(struct pullup_context *c)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
757 {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
758 c->bpp = calloc(c->nplanes, sizeof(int));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
759 c->w = calloc(c->nplanes, sizeof(int));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
760 c->h = calloc(c->nplanes, sizeof(int));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
761 c->stride = calloc(c->nplanes, sizeof(int));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
762 c->background = calloc(c->nplanes, sizeof(int));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
763 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
764
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
765 void pullup_init_context(struct pullup_context *c)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
766 {
10956
fdcd0d571912 support for selecting which plane to use for metrics in the pullup
rfelker
parents: 10843
diff changeset
767 int mp = c->metric_plane;
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
768 if (c->nbuffers < 10) c->nbuffers = 10;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
769 c->buffers = calloc(c->nbuffers, sizeof (struct pullup_buffer));
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
770
15111
678f6aeb6754 silence gcc warning:
rathann
parents: 14973
diff changeset
771 c->metric_w = (c->w[mp] - ((c->junk_left + c->junk_right) << 3)) >> 3;
678f6aeb6754 silence gcc warning:
rathann
parents: 14973
diff changeset
772 c->metric_h = (c->h[mp] - ((c->junk_top + c->junk_bottom) << 1)) >> 3;
10956
fdcd0d571912 support for selecting which plane to use for metrics in the pullup
rfelker
parents: 10843
diff changeset
773 c->metric_offset = c->junk_left*c->bpp[mp] + (c->junk_top<<1)*c->stride[mp];
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
774 c->metric_len = c->metric_w * c->metric_h;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28290
diff changeset
775
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
776 c->head = make_field_queue(c, 8);
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
777
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
778 c->frame = calloc(1, sizeof (struct pullup_frame));
11628
6fc547235443 simplified frame decision logic and reduced the occurrance of length=1
rfelker
parents: 11627
diff changeset
779 c->frame->ifields = calloc(3, sizeof (struct pullup_buffer *));
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
780
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
781 switch(c->format) {
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
782 case PULLUP_FMT_Y:
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
783 c->diff = diff_y;
11626
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
784 c->comb = licomb_y;
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
785 c->var = var_y;
28290
25337a2147e7 Lots and lots of #ifdef ARCH_... -> #if ARCH_...
reimar
parents: 27754
diff changeset
786 #if ARCH_X86
25337a2147e7 Lots and lots of #ifdef ARCH_... -> #if ARCH_...
reimar
parents: 27754
diff changeset
787 #if HAVE_MMX
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
788 if (c->cpu & PULLUP_CPU_MMX) {
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
789 c->diff = diff_y_mmx;
11626
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
790 c->comb = licomb_y_mmx;
15721
eec6ace22741 small change to field-matching metrics which hopefully makes a big
rfelker
parents: 15111
diff changeset
791 c->var = var_y_mmx;
10747
cd4c523eaac4 more mmx and fix 100l sig11 in the previous mmx commit
rfelker
parents: 10741
diff changeset
792 }
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
793 #endif
13720
821f464b4d90 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents: 13235
diff changeset
794 #endif
12548
8584fdad0188 old changes in my local tree i forgot to commit - minor fixes
rfelker
parents: 11641
diff changeset
795 /* c->comb = qpcomb_y; */
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
796 break;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
797 #if 0
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
798 case PULLUP_FMT_YUY2:
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
799 c->diff = diff_yuy2;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
800 break;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
801 case PULLUP_FMT_RGB32:
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
802 c->diff = diff_rgb32;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
803 break;
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
804 #endif
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
805 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
806 }
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
807
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
808 void pullup_free_context(struct pullup_context *c)
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
809 {
10738
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
810 struct pullup_field *f;
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
811 free(c->buffers);
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
812 f = c->head;
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
813 do {
24350
eb7b1f3327aa Add a check for c->head being NULL in pullup_free_context().
gpoirier
parents: 24319
diff changeset
814 if (!f) break;
10738
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
815 free(f->diffs);
11626
168e540bad66 allow for different combing metrics to be selected (not useful yet)
rfelker
parents: 11625
diff changeset
816 free(f->comb);
10738
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
817 f = f->next;
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
818 free(f->prev);
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
819 } while (f != c->head);
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
820 free(c->frame);
b6b68224033d tweaks and cleanup
rfelker
parents: 10737
diff changeset
821 free(c);
10664
d47ca466c97b pullup -- third generation inverse telecine engine. the backend
rfelker
parents:
diff changeset
822 }