annotate libmpcodecs/vf_kerndeint.c @ 27056:ad1444d3ff26

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