Mercurial > mplayer.hg
changeset 10809:304c94c89359
simple logo remover
author | henry |
---|---|
date | Wed, 03 Sep 2003 22:44:28 +0000 |
parents | 9883dfced49c |
children | d0aaa6bf3def |
files | libmpcodecs/Makefile libmpcodecs/vf.c libmpcodecs/vf_delogo.c |
diffstat | 3 files changed, 250 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpcodecs/Makefile Wed Sep 03 22:30:30 2003 +0000 +++ b/libmpcodecs/Makefile Wed Sep 03 22:44:28 2003 +0000 @@ -14,7 +14,7 @@ VIDEO_SRCS_OPT=vd_realvid.c vd_ffmpeg.c vd_dshow.c vd_dmo.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_xanim.c vd_xvid.c vd_libdv.c vd_qtvideo.c vd_theora.c VIDEO_SRCS=dec_video.c vd.c $(VIDEO_SRCS_NAT) $(VIDEO_SRCS_LIB) $(VIDEO_SRCS_OPT) -VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c vf_ivtc.c vf_ilpack.c vf_dsize.c vf_decimate.c vf_softpulldown.c vf_tinterlace.c vf_pullup.c pullup.c vf_framestep.c vf_tile.c +VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c vf_ivtc.c vf_ilpack.c vf_dsize.c vf_decimate.c vf_softpulldown.c vf_tinterlace.c vf_pullup.c pullup.c vf_framestep.c vf_tile.c vf_delogo.c ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c ve_xvid.c ve_qtvideo.c ve_nuv.c NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c native/decode144.c native/decode288.c
--- a/libmpcodecs/vf.c Wed Sep 03 22:30:30 2003 +0000 +++ b/libmpcodecs/vf.c Wed Sep 03 22:44:28 2003 +0000 @@ -74,6 +74,7 @@ extern vf_info_t vf_info_pullup; extern vf_info_t vf_info_framestep; extern vf_info_t vf_info_tile; +extern vf_info_t vf_info_delogo; // list of available filters: static vf_info_t* filter_list[]={ @@ -137,6 +138,7 @@ &vf_info_pullup, &vf_info_framestep, &vf_info_tile, + &vf_info_delogo, NULL };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmpcodecs/vf_delogo.c Wed Sep 03 22:44:28 2003 +0000 @@ -0,0 +1,247 @@ +/* + Copyright (C) 2002 Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* A very simple tv station logo remover */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <inttypes.h> +#include <math.h> + +#include "../config.h" +#include "../mp_msg.h" +#include "../cpudetect.h" + +#ifdef HAVE_MALLOC_H +#include <malloc.h> +#endif + +#include "img_format.h" +#include "mp_image.h" +#include "vf.h" +#include "../libvo/fastmemcpy.h" + +//===========================================================================// + +struct vf_priv_s { + unsigned int outfmt; + int xoff, yoff, lw, lh, band, show; +}; + +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) + +static void delogo(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, + int logo_x, int logo_y, int logo_w, int logo_h, int band, int show) { + int y, x; + int interp, dist; + uint8_t *xdst, *xsrc; + + uint8_t *topleft, *botleft, *topright; + int xclipl, xclipr, yclipt, yclipb; + + xclipl = MAX(-logo_x, 0); + xclipr = MAX(logo_x+logo_w-width, 0); + yclipt = MAX(-logo_y, 0); + yclipb = MAX(logo_y+logo_h-height, 0); + + topleft = src+MAX(logo_y,0)*srcStride+MAX(logo_x,0); + topright = src+MAX(logo_y,0)*srcStride+MIN(logo_x+logo_w-1,width-1); + botleft = src+MIN(logo_y+logo_h-1,height-1)*srcStride+MAX(logo_x,0); + + for(y=0; y<height; y++) + { + for (x = 0, xdst = dst, xsrc = src; x < width; x++, xdst++, xsrc++) { + if (y >= logo_y && y < logo_y+logo_h && x >= logo_x && x < logo_x+logo_w) { + interp = ((topleft[srcStride*(y-logo_y-yclipt)] + + topleft[srcStride*(y-logo_y-1-yclipt)] + + topleft[srcStride*(y-logo_y+1-yclipt)])*(logo_w-(x-logo_x))/logo_w + + (topright[srcStride*(y-logo_y-yclipt)] + + topright[srcStride*(y-logo_y-1-yclipt)] + + topright[srcStride*(y-logo_y+1-yclipt)])*(x-logo_x)/logo_w + + (topleft[x-logo_x-xclipl] + + topleft[x-logo_x-1-xclipl] + + topleft[x-logo_x+1-xclipl])*(logo_h-(y-logo_y))/logo_h + + (botleft[x-logo_x-xclipl] + + botleft[x-logo_x-1-xclipl] + + botleft[x-logo_x+1-xclipl])*(y-logo_y)/logo_h + )/6; +/* interp = (topleft[srcStride*(y-logo_y)]*(logo_w-(x-logo_x))/logo_w + + topright[srcStride*(y-logo_y)]*(x-logo_x)/logo_w + + topleft[x-logo_x]*(logo_h-(y-logo_y))/logo_h + + botleft[x-logo_x]*(y-logo_y)/logo_h + )/2;*/ + if (y >= logo_y+band && y < logo_y+logo_h-band && x >= logo_x+band && x < logo_x+logo_w-band) { + *xdst = interp; + } else { + dist = 0; + if (x < logo_x+band) dist = MAX(dist, logo_x-x+band); + else if (x >= logo_x+logo_w-band) dist = MAX(dist, x-(logo_x+logo_w-1-band)); + if (y < logo_y+band) dist = MAX(dist, logo_y-y+band); + else if (y >= logo_y+logo_h-band) dist = MAX(dist, y-(logo_y+logo_h-1-band)); + *xdst = (*xsrc*dist + interp*(band-dist))/band; + if (show && dist == band) *xdst = 0; + } + } else { + *xdst = *xsrc; + } + } + + dst+= dstStride; + src+= srcStride; + } +} + +static int config(struct vf_instance_s* vf, + int width, int height, int d_width, int d_height, + unsigned int flags, unsigned int outfmt){ + + return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); +} + + +static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ + if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change + if(mpi->imgfmt!=vf->priv->outfmt) return; // colorspace differ + // ok, we can do pp in-place (or pp disabled): + vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, + mpi->type, mpi->flags, mpi->w, mpi->h); + mpi->planes[0]=vf->dmpi->planes[0]; + mpi->stride[0]=vf->dmpi->stride[0]; + mpi->width=vf->dmpi->width; + if(mpi->flags&MP_IMGFLAG_PLANAR){ + mpi->planes[1]=vf->dmpi->planes[1]; + mpi->planes[2]=vf->dmpi->planes[2]; + mpi->stride[1]=vf->dmpi->stride[1]; + mpi->stride[2]=vf->dmpi->stride[2]; + } + mpi->flags|=MP_IMGFLAG_DIRECT; +} + +static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ + mp_image_t *dmpi; + + if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ + // no DR, so get a new image! hope we'll get DR buffer: + vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt, + MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, + mpi->w,mpi->h); + } + dmpi= vf->dmpi; + + delogo(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, + vf->priv->xoff, vf->priv->yoff, vf->priv->lw, vf->priv->lh, vf->priv->band, vf->priv->show); + delogo(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, + vf->priv->xoff/2, vf->priv->yoff/2, vf->priv->lw/2, vf->priv->lh/2, vf->priv->band/2, vf->priv->show); + delogo(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, + vf->priv->xoff/2, vf->priv->yoff/2, vf->priv->lw/2, vf->priv->lh/2, vf->priv->band/2, vf->priv->show); + + vf_clone_mpi_attributes(dmpi, mpi); + + return vf_next_put_image(vf,dmpi); +} + +static void uninit(struct vf_instance_s* vf){ + if(!vf->priv) return; + + free(vf->priv); + vf->priv=NULL; +} + +//===========================================================================// + +static int query_format(struct vf_instance_s* vf, unsigned int fmt){ + switch(fmt) + { + case IMGFMT_YV12: + case IMGFMT_I420: + case IMGFMT_IYUV: + return vf_next_query_format(vf,vf->priv->outfmt); + } + return 0; +} + +static unsigned int fmt_list[]={ + IMGFMT_YV12, + IMGFMT_I420, + IMGFMT_IYUV, + 0 +}; + +static int open(vf_instance_t *vf, char* args){ + int res; + + vf->config=config; + vf->put_image=put_image; + vf->get_image=get_image; + vf->query_format=query_format; + vf->uninit=uninit; + vf->priv=malloc(sizeof(struct vf_priv_s)); + memset(vf->priv, 0, sizeof(struct vf_priv_s)); + + if (args) res = sscanf(args, "%d:%d:%d:%d:%d", + &vf->priv->xoff, &vf->priv->yoff, + &vf->priv->lw, &vf->priv->lh, + &vf->priv->band); + + if (res != 5) { + mp_msg(MSGT_VFILTER, MSGL_ERR, "deLogo: syntax is \"delogo=xoff:yoff:width:height:band\"\n"); + uninit(vf); + return 0; + } + + mp_msg(MSGT_VFILTER, MSGL_INFO, "deLogo: %d x %d, %d ; %d ; band = %d\n", + &vf->priv->lw, &vf->priv->lh, + &vf->priv->xoff, &vf->priv->yoff, + &vf->priv->band); + + vf->priv->show = 0; + + if (vf->priv->band < 0) { + vf->priv->band = 2; + vf->priv->show = 1; + } + + + vf->priv->lw += vf->priv->band*2; + vf->priv->lh += vf->priv->band*2; + vf->priv->xoff -= vf->priv->band; + vf->priv->yoff -= vf->priv->band; + + // check csp: + vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); + if(!vf->priv->outfmt) + { + uninit(vf); + return 0; // no csp match :( + } + + return 1; +} + +vf_info_t vf_info_delogo = { + "simple logo remover", + "delogo", + "Jindrich Makovicka", + "", + open, + NULL +}; + +//===========================================================================//