annotate libmpcodecs/vf_kerndeint.c @ 12324:fa573cfa912d

vocabulary
author rathann
date Tue, 27 Apr 2004 17:01:00 +0000
parents 1c268fb0503d
children 6ff3379a0862
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11869
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
1 /*
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
2 Original AVISynth Filter Copyright (C) 2003 Donald A. Graft
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
3 Adapted to MPlayer by Tobias Diedrich
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
4
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
7 the Free Software Foundation.
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
8
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
12 GNU General Public License for more details.
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
13
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
15 along with this program; if not, write to the Free Software
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
17 */
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
18
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
19 #include <stdio.h>
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
20 #include <stdlib.h>
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
21 #include <string.h>
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
22 #include <inttypes.h>
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
23 #include <math.h>
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
24
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
25 #include "../config.h"
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
26 #include "../mp_msg.h"
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
27
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
28 #ifdef HAVE_MALLOC_H
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
29 #include <malloc.h>
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
30 #endif
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
31
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
32 #include "img_format.h"
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
33 #include "mp_image.h"
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
34 #include "vf.h"
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
35 #include "../libvo/fastmemcpy.h"
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
36
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
37 //===========================================================================//
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
38
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
39 struct vf_priv_s {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
40 int frame;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
41 int map;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
42 int order;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
43 int thresh;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
44 int sharp;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
45 int twoway;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
46 };
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
47
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
48
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
49 /***************************************************************************/
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
50
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
51
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
52 static int config(struct vf_instance_s* vf,
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
53 int width, int height, int d_width, int d_height,
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
54 unsigned int flags, unsigned int outfmt){
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
55
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
56 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
57 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
58
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
59
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
60 static void uninit(struct vf_instance_s* vf)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
61 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
62 free(vf->priv);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
63 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
64
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
65 static inline int IsRGB(mp_image_t *mpi)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
66 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
67 return mpi->imgfmt == IMGFMT_RGB;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
68 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
69
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
70 static inline int IsYUY2(mp_image_t *mpi)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
71 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
72 return mpi->imgfmt == IMGFMT_YUY2;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
73 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
74
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
75 #define PLANAR_Y 0
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
76 #define PLANAR_U 1
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
77 #define PLANAR_V 2
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
78
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
79 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
80 int cw= mpi->w >> mpi->chroma_x_shift;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
81 int ch= mpi->h >> mpi->chroma_y_shift;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
82 int W = mpi->w, H = mpi->h;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
83 const unsigned char *prvp, *prvpp, *prvpn, *prvpnn, *prvppp, *prvp4p, *prvp4n;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
84 const unsigned char *srcp_saved;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
85 const unsigned char *srcp, *srcpp, *srcpn, *srcpnn, *srcppp, *srcp3p, *srcp3n, *srcp4p, *srcp4n;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
86 unsigned char *dstp, *dstp_saved;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
87 int src_pitch;
11879
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
88 int psrc_pitch;
11869
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
89 int dst_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
90 int x, y, z;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
91 int n = vf->priv->frame++;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
92 int val, hi, lo, w, h;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
93 double valf;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
94 unsigned int hint;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
95 int plane;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
96 int threshold = vf->priv->thresh;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
97 int order = vf->priv->order;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
98 int map = vf->priv->map;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
99 int sharp = vf->priv->sharp;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
100 int twoway = vf->priv->twoway;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
101
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
102 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
103 MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE,
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
104 mpi->w,mpi->h);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
105 mp_image_t *pmpi=vf_get_image(vf->next,mpi->imgfmt,
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
106 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
107 mpi->w,mpi->h);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
108 if(!dmpi) return 0;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
109
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
110 for (z=0; z<mpi->num_planes; z++) {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
111 if (z == 0) plane = PLANAR_Y;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
112 else if (z == 1) plane = PLANAR_U;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
113 else plane = PLANAR_V;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
114
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
115 h = plane == PLANAR_Y ? H : ch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
116 w = plane == PLANAR_Y ? W : cw;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
117
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
118 srcp = srcp_saved = mpi->planes[z];
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
119 src_pitch = mpi->stride[z];
11879
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
120 psrc_pitch = pmpi->stride[z];
11869
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
121 dstp = dstp_saved = dmpi->planes[z];
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
122 dst_pitch = dmpi->stride[z];
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
123 srcp = srcp_saved + (1-order) * src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
124 dstp = dstp_saved + (1-order) * dst_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
125
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
126 for (y=0; y<h; y+=2) {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
127 memcpy(dstp, srcp, w);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
128 srcp += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
129 dstp += 2*dst_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
130 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
131
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
132 // Copy through the lines that will be missed below.
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
133 memcpy(dstp_saved + order*dst_pitch, srcp_saved + (1-order)*src_pitch, w);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
134 memcpy(dstp_saved + (2+order)*dst_pitch, srcp_saved + (3-order)*src_pitch, w);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
135 memcpy(dstp_saved + (h-2+order)*dst_pitch, srcp_saved + (h-1-order)*src_pitch, w);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
136 memcpy(dstp_saved + (h-4+order)*dst_pitch, srcp_saved + (h-3-order)*src_pitch, w);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
137 /* For the other field choose adaptively between using the previous field
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
138 or the interpolant from the current field. */
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
139
11879
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
140 prvp = pmpi->planes[z] + 5*psrc_pitch - (1-order)*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
141 prvpp = prvp - psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
142 prvppp = prvp - 2*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
143 prvp4p = prvp - 4*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
144 prvpn = prvp + psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
145 prvpnn = prvp + 2*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
146 prvp4n = prvp + 4*psrc_pitch;
11869
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
147 srcp = srcp_saved + 5*src_pitch - (1-order)*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
148 srcpp = srcp - src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
149 srcppp = srcp - 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
150 srcp3p = srcp - 3*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
151 srcp4p = srcp - 4*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
152 srcpn = srcp + src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
153 srcpnn = srcp + 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
154 srcp3n = srcp + 3*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
155 srcp4n = srcp + 4*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
156 dstp = dstp_saved + 5*dst_pitch - (1-order)*dst_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
157 for (y = 5 - (1-order); y <= h - 5 - (1-order); y+=2)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
158 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
159 for (x = 0; x < w; x++)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
160 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
161 if ((threshold == 0) || (n == 0) ||
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
162 (abs((int)prvp[x] - (int)srcp[x]) > threshold) ||
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
163 (abs((int)prvpp[x] - (int)srcpp[x]) > threshold) ||
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
164 (abs((int)prvpn[x] - (int)srcpn[x]) > threshold))
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
165 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
166 if (map == 1)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
167 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
168 int g = x & ~3;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
169 if (IsRGB(mpi) == 1)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
170 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
171 dstp[g++] = 255;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
172 dstp[g++] = 255;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
173 dstp[g++] = 255;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
174 dstp[g] = 255;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
175 x = g;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
176 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
177 else if (IsYUY2(mpi) == 1)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
178 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
179 dstp[g++] = 235;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
180 dstp[g++] = 128;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
181 dstp[g++] = 235;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
182 dstp[g] = 128;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
183 x = g;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
184 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
185 else
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
186 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
187 if (plane == PLANAR_Y) dstp[x] = 235;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
188 else dstp[x] = 128;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
189 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
190 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
191 else
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
192 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
193 if (IsRGB(mpi))
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
194 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
195 hi = 255;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
196 lo = 0;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
197 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
198 else if (IsYUY2(mpi))
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
199 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
200 hi = (x & 1) ? 240 : 235;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
201 lo = 16;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
202 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
203 else
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
204 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
205 hi = (plane == PLANAR_Y) ? 235 : 240;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
206 lo = 16;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
207 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
208
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
209 if (sharp == 1)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
210 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
211 if (twoway == 1)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
212 valf = + 0.526*((int)srcpp[x] + (int)srcpn[x])
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
213 + 0.170*((int)srcp[x] + (int)prvp[x])
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
214 - 0.116*((int)srcppp[x] + (int)srcpnn[x] + (int)prvppp[x] + (int)prvpnn[x])
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
215 - 0.026*((int)srcp3p[x] + (int)srcp3n[x])
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
216 + 0.031*((int)srcp4p[x] + (int)srcp4n[x] + (int)prvp4p[x] + (int)prvp4n[x]);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
217 else
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
218 valf = + 0.526*((int)srcpp[x] + (int)srcpn[x])
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
219 + 0.170*((int)prvp[x])
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
220 - 0.116*((int)prvppp[x] + (int)prvpnn[x])
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
221 - 0.026*((int)srcp3p[x] + (int)srcp3n[x])
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
222 + 0.031*((int)prvp4p[x] + (int)prvp4p[x]);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
223 if (valf > hi) valf = hi;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
224 else if (valf < lo) valf = lo;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
225 dstp[x] = (int) valf;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
226 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
227 else
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
228 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
229 if (twoway == 1)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
230 val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)srcp[x] + (int)prvp[x]) -
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
231 (int)(srcppp[x]) - (int)(srcpnn[x]) -
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
232 (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
233 else
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
234 val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)prvp[x]) -
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
235 (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
236 if (val > hi) val = hi;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
237 else if (val < lo) val = lo;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
238 dstp[x] = (int) val;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
239 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
240 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
241 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
242 else
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
243 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
244 dstp[x] = srcp[x];
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
245 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
246 }
11879
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
247 prvp += 2*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
248 prvpp += 2*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
249 prvppp += 2*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
250 prvpn += 2*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
251 prvpnn += 2*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
252 prvp4p += 2*psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
253 prvp4n += 2*psrc_pitch;
11869
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
254 srcp += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
255 srcpp += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
256 srcppp += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
257 srcp3p += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
258 srcp4p += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
259 srcpn += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
260 srcpnn += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
261 srcp3n += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
262 srcp4n += 2*src_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
263 dstp += 2*dst_pitch;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
264 }
11879
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
265
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
266 srcp = mpi->planes[z];
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
267 dstp = pmpi->planes[z];
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
268 for (y=0; y<h; y++) {
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
269 memcpy(dstp, srcp, w);
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
270 srcp += src_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
271 dstp += psrc_pitch;
205d12acbb5f 10l fix by Jindrich Makovicka
ranma
parents: 11869
diff changeset
272 }
11869
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
273 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
274
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
275 return vf_next_put_image(vf,dmpi);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
276 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
277
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
278 //===========================================================================//
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
279
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
280 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
281 switch(fmt)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
282 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
283 case IMGFMT_YV12:
11991
1c268fb0503d A bit late, but here's the "more sane options ordering" patch.
ranma
parents: 11879
diff changeset
284 case IMGFMT_RGB:
1c268fb0503d A bit late, but here's the "more sane options ordering" patch.
ranma
parents: 11879
diff changeset
285 case IMGFMT_YUY2:
11869
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
286 return vf_next_query_format(vf, fmt);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
287 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
288 return 0;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
289 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
290
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
291 static int open(vf_instance_t *vf, char* args){
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
292 double LumSpac, LumTmp, ChromSpac, ChromTmp;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
293 double Param1, Param2, Param3;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
294
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
295 vf->config=config;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
296 vf->put_image=put_image;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
297 vf->query_format=query_format;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
298 vf->uninit=uninit;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
299 vf->priv=malloc(sizeof(struct vf_priv_s));
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
300 memset(vf->priv, 0, sizeof(struct vf_priv_s));
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
301
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
302 vf->priv->frame = 0;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
303
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
304 vf->priv->map = 0;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
305 vf->priv->order = 0;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
306 vf->priv->thresh = 10;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
307 vf->priv->sharp = 0;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
308 vf->priv->twoway = 0;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
309
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
310 if (args)
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
311 {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
312 sscanf(args, "%d:%d:%d:%d:%d",
11991
1c268fb0503d A bit late, but here's the "more sane options ordering" patch.
ranma
parents: 11879
diff changeset
313 &vf->priv->thresh, &vf->priv->map,
1c268fb0503d A bit late, but here's the "more sane options ordering" patch.
ranma
parents: 11879
diff changeset
314 &vf->priv->order, &vf->priv->sharp,
11869
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
315 &vf->priv->twoway);
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
316 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
317 if (vf->priv->order > 1) vf->priv->order = 1;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
318
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
319 return 1;
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
320 }
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
321
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
322 vf_info_t vf_info_kerndeint = {
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
323 "Kernel Deinterlacer",
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
324 "kerndeint",
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
325 "Donald Graft",
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
326 "",
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
327 open,
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
328 NULL
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
329 };
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
330
c10bd91a4eb2 kerndeint adaptive deinterlacer
ranma
parents:
diff changeset
331 //===========================================================================//