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