Mercurial > mplayer.hg
annotate libmpcodecs/vf_delogo.c @ 28264:7b7e005eaed1
Only check for YASM support on x86 systems.
author | diego |
---|---|
date | Sun, 11 Jan 2009 13:33:44 +0000 |
parents | 82601a38e2a7 |
children | df67d03dde3b |
rev | line source |
---|---|
10809 | 1 /* |
26727 | 2 * Copyright (C) 2002 Jindrich Makovicka <makovick@gmail.com> |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
10809 | 20 |
21 /* A very simple tv station logo remover */ | |
22 | |
23 #include <stdio.h> | |
24 #include <stdlib.h> | |
25 #include <string.h> | |
26 #include <inttypes.h> | |
27 #include <math.h> | |
28 | |
17012 | 29 #include "config.h" |
30 #include "mp_msg.h" | |
31 #include "cpudetect.h" | |
10809 | 32 |
33 #ifdef HAVE_MALLOC_H | |
34 #include <malloc.h> | |
35 #endif | |
36 | |
37 #include "img_format.h" | |
38 #include "mp_image.h" | |
39 #include "vf.h" | |
17012 | 40 #include "libvo/fastmemcpy.h" |
10809 | 41 |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
42 #include "m_option.h" |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
43 #include "m_struct.h" |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
44 |
10809 | 45 //===========================================================================// |
46 | |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
47 static struct vf_priv_s { |
10809 | 48 unsigned int outfmt; |
49 int xoff, yoff, lw, lh, band, show; | |
22027 | 50 } const vf_priv_dflt = { |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
51 0, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
52 0, 0, 0, 0, 0, 0 |
10809 | 53 }; |
54 | |
55 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) | |
56 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) | |
57 | |
58 static void delogo(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, | |
10811 | 59 int logo_x, int logo_y, int logo_w, int logo_h, int band, int show, int direct) { |
10809 | 60 int y, x; |
61 int interp, dist; | |
62 uint8_t *xdst, *xsrc; | |
63 | |
64 uint8_t *topleft, *botleft, *topright; | |
65 int xclipl, xclipr, yclipt, yclipb; | |
10811 | 66 int logo_x1, logo_x2, logo_y1, logo_y2; |
10809 | 67 |
68 xclipl = MAX(-logo_x, 0); | |
69 xclipr = MAX(logo_x+logo_w-width, 0); | |
70 yclipt = MAX(-logo_y, 0); | |
71 yclipb = MAX(logo_y+logo_h-height, 0); | |
72 | |
10811 | 73 logo_x1 = logo_x + xclipl; |
74 logo_x2 = logo_x + logo_w - xclipr; | |
75 logo_y1 = logo_y + yclipt; | |
76 logo_y2 = logo_y + logo_h - yclipb; | |
10809 | 77 |
10811 | 78 topleft = src+logo_y1*srcStride+logo_x1; |
11029 | 79 topright = src+logo_y1*srcStride+logo_x2-1; |
10811 | 80 botleft = src+(logo_y2-1)*srcStride+logo_x1; |
81 | |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
82 if (!direct) memcpy_pic(dst, src, width, height, dstStride, srcStride); |
10811 | 83 |
84 dst += (logo_y1+1)*dstStride; | |
85 src += (logo_y1+1)*srcStride; | |
86 | |
87 for(y = logo_y1+1; y < logo_y2-1; y++) | |
10809 | 88 { |
10811 | 89 for (x = logo_x1+1, xdst = dst+logo_x1+1, xsrc = src+logo_x1+1; x < logo_x2-1; x++, xdst++, xsrc++) { |
90 interp = ((topleft[srcStride*(y-logo_y-yclipt)] | |
91 + topleft[srcStride*(y-logo_y-1-yclipt)] | |
92 + topleft[srcStride*(y-logo_y+1-yclipt)])*(logo_w-(x-logo_x))/logo_w | |
93 + (topright[srcStride*(y-logo_y-yclipt)] | |
94 + topright[srcStride*(y-logo_y-1-yclipt)] | |
95 + topright[srcStride*(y-logo_y+1-yclipt)])*(x-logo_x)/logo_w | |
96 + (topleft[x-logo_x-xclipl] | |
97 + topleft[x-logo_x-1-xclipl] | |
98 + topleft[x-logo_x+1-xclipl])*(logo_h-(y-logo_y))/logo_h | |
99 + (botleft[x-logo_x-xclipl] | |
100 + botleft[x-logo_x-1-xclipl] | |
101 + botleft[x-logo_x+1-xclipl])*(y-logo_y)/logo_h | |
102 )/6; | |
10809 | 103 /* interp = (topleft[srcStride*(y-logo_y)]*(logo_w-(x-logo_x))/logo_w |
104 + topright[srcStride*(y-logo_y)]*(x-logo_x)/logo_w | |
105 + topleft[x-logo_x]*(logo_h-(y-logo_y))/logo_h | |
106 + botleft[x-logo_x]*(y-logo_y)/logo_h | |
107 )/2;*/ | |
10811 | 108 if (y >= logo_y+band && y < logo_y+logo_h-band && x >= logo_x+band && x < logo_x+logo_w-band) { |
10809 | 109 *xdst = interp; |
110 } else { | |
10811 | 111 dist = 0; |
112 if (x < logo_x+band) dist = MAX(dist, logo_x-x+band); | |
113 else if (x >= logo_x+logo_w-band) dist = MAX(dist, x-(logo_x+logo_w-1-band)); | |
114 if (y < logo_y+band) dist = MAX(dist, logo_y-y+band); | |
115 else if (y >= logo_y+logo_h-band) dist = MAX(dist, y-(logo_y+logo_h-1-band)); | |
116 *xdst = (*xsrc*dist + interp*(band-dist))/band; | |
117 if (show && (dist == band-1)) *xdst = 0; | |
10809 | 118 } |
119 } | |
120 | |
121 dst+= dstStride; | |
122 src+= srcStride; | |
123 } | |
124 } | |
125 | |
126 static int config(struct vf_instance_s* vf, | |
127 int width, int height, int d_width, int d_height, | |
128 unsigned int flags, unsigned int outfmt){ | |
129 | |
130 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
131 } | |
132 | |
133 | |
134 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
135 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
136 if(mpi->imgfmt!=vf->priv->outfmt) return; // colorspace differ | |
137 // ok, we can do pp in-place (or pp disabled): | |
138 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
139 mpi->type, mpi->flags, mpi->w, mpi->h); | |
140 mpi->planes[0]=vf->dmpi->planes[0]; | |
141 mpi->stride[0]=vf->dmpi->stride[0]; | |
142 mpi->width=vf->dmpi->width; | |
143 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
144 mpi->planes[1]=vf->dmpi->planes[1]; | |
145 mpi->planes[2]=vf->dmpi->planes[2]; | |
146 mpi->stride[1]=vf->dmpi->stride[1]; | |
147 mpi->stride[2]=vf->dmpi->stride[2]; | |
148 } | |
149 mpi->flags|=MP_IMGFLAG_DIRECT; | |
150 } | |
151 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17367
diff
changeset
|
152 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
10809 | 153 mp_image_t *dmpi; |
154 | |
155 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
156 // no DR, so get a new image! hope we'll get DR buffer: | |
157 vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt, | |
158 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
159 mpi->w,mpi->h); | |
160 } | |
161 dmpi= vf->dmpi; | |
162 | |
163 delogo(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, | |
10811 | 164 vf->priv->xoff, vf->priv->yoff, vf->priv->lw, vf->priv->lh, vf->priv->band, vf->priv->show, |
165 mpi->flags&MP_IMGFLAG_DIRECT); | |
10809 | 166 delogo(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, |
10811 | 167 vf->priv->xoff/2, vf->priv->yoff/2, vf->priv->lw/2, vf->priv->lh/2, vf->priv->band/2, vf->priv->show, |
168 mpi->flags&MP_IMGFLAG_DIRECT); | |
10809 | 169 delogo(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, |
10811 | 170 vf->priv->xoff/2, vf->priv->yoff/2, vf->priv->lw/2, vf->priv->lh/2, vf->priv->band/2, vf->priv->show, |
171 mpi->flags&MP_IMGFLAG_DIRECT); | |
10809 | 172 |
173 vf_clone_mpi_attributes(dmpi, mpi); | |
174 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17367
diff
changeset
|
175 return vf_next_put_image(vf,dmpi, pts); |
10809 | 176 } |
177 | |
178 static void uninit(struct vf_instance_s* vf){ | |
179 if(!vf->priv) return; | |
180 | |
181 free(vf->priv); | |
182 vf->priv=NULL; | |
183 } | |
184 | |
185 //===========================================================================// | |
186 | |
187 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
188 switch(fmt) | |
189 { | |
190 case IMGFMT_YV12: | |
191 case IMGFMT_I420: | |
192 case IMGFMT_IYUV: | |
193 return vf_next_query_format(vf,vf->priv->outfmt); | |
194 } | |
195 return 0; | |
196 } | |
197 | |
198 static unsigned int fmt_list[]={ | |
199 IMGFMT_YV12, | |
200 IMGFMT_I420, | |
201 IMGFMT_IYUV, | |
202 0 | |
203 }; | |
204 | |
205 static int open(vf_instance_t *vf, char* args){ | |
206 int res; | |
207 | |
208 vf->config=config; | |
209 vf->put_image=put_image; | |
210 vf->get_image=get_image; | |
211 vf->query_format=query_format; | |
212 vf->uninit=uninit; | |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
213 if (!vf->priv) |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
214 { |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
215 vf->priv=malloc(sizeof(struct vf_priv_s)); |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
216 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
217 } |
10809 | 218 |
219 if (args) res = sscanf(args, "%d:%d:%d:%d:%d", | |
220 &vf->priv->xoff, &vf->priv->yoff, | |
221 &vf->priv->lw, &vf->priv->lh, | |
222 &vf->priv->band); | |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
223 if (args && (res != 5)) { |
10809 | 224 uninit(vf); |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
225 return 0; // bad syntax |
10809 | 226 } |
227 | |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
228 mp_msg(MSGT_VFILTER, MSGL_V, "delogo: %d x %d, %d x %d, band = %d\n", |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
229 vf->priv->xoff, vf->priv->yoff, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
230 vf->priv->lw, vf->priv->lh, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
231 vf->priv->band); |
10809 | 232 |
233 vf->priv->show = 0; | |
234 | |
235 if (vf->priv->band < 0) { | |
10811 | 236 vf->priv->band = 4; |
10809 | 237 vf->priv->show = 1; |
238 } | |
239 | |
240 | |
241 vf->priv->lw += vf->priv->band*2; | |
242 vf->priv->lh += vf->priv->band*2; | |
243 vf->priv->xoff -= vf->priv->band; | |
244 vf->priv->yoff -= vf->priv->band; | |
245 | |
246 // check csp: | |
247 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); | |
248 if(!vf->priv->outfmt) | |
249 { | |
250 uninit(vf); | |
251 return 0; // no csp match :( | |
252 } | |
253 | |
254 return 1; | |
255 } | |
256 | |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
257 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f) |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
258 static m_option_t vf_opts_fields[] = { |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
259 { "x", ST_OFF(xoff), CONF_TYPE_INT, 0, 0, 0, NULL }, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
260 { "y", ST_OFF(yoff), CONF_TYPE_INT, 0, 0, 0, NULL }, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
261 { "w", ST_OFF(lw), CONF_TYPE_INT, 0, 0, 0, NULL }, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
262 { "h", ST_OFF(lh), CONF_TYPE_INT, 0, 0, 0, NULL }, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
263 { "t", ST_OFF(band), CONF_TYPE_INT, 0, 0, 0, NULL }, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
264 { "band", ST_OFF(band), CONF_TYPE_INT, 0, 0, 0, NULL }, // alias |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
265 { NULL, NULL, 0, 0, 0, 0, NULL } |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
266 }; |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
267 |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
268 static m_struct_t vf_opts = { |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
269 "delogo", |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
270 sizeof(struct vf_priv_s), |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
271 &vf_priv_dflt, |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
272 vf_opts_fields |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
273 }; |
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
274 |
25221 | 275 const vf_info_t vf_info_delogo = { |
10809 | 276 "simple logo remover", |
277 "delogo", | |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
278 "Jindrich Makovicka, Alex Beregszaszi", |
10809 | 279 "", |
280 open, | |
10816
e9dc9b0b16fa
added new config system support and fixed some bugs (altought sanity checks are needed in delogo as it segfaults easily with w/h out of range)
alex
parents:
10811
diff
changeset
|
281 &vf_opts |
10809 | 282 }; |
283 | |
284 //===========================================================================// |