[MPlayer-dev-eng] Patch: New filter that will set a constant luminance on a box

Erik Waling erikw at acc.umu.se
Sat Apr 3 14:11:35 CEST 2004


diff -rpuN MPlayer-1.0pre3/DOCS/man/en/mplayer.1 MPlayer-1.0pre3-work/DOCS/man/en/mplayer.1
--- MPlayer-1.0pre3/DOCS/man/en/mplayer.1	2003-12-09 07:23:36.000000000 +0100
+++ MPlayer-1.0pre3-work/DOCS/man/en/mplayer.1	2004-03-24 14:48:10.229222760 +0100
@@ -2462,6 +2462,21 @@ top left corner position (default: -1, u
 .RE
 .PD 1
 .TP
+.B lumbox[=w:h:x:y:l]
+Set a constant luminance on a box of the requested width and height at
+the specified coordinates. 
+Can be used for removing text on a dark color background.
+.PD 0
+.RSs
+.IPs w,h
+width and height (default: -1, maximum possible width)
+.IPs x,y
+top left corner position (default: -1, uppermost leftmost)
+.IPs l
+luminance (0-255, default: 0)
+.RE
+.PD 1
+.TP
 .B expand[=w:h:x:y:o]
 Expands (not scales) movie resolution to the given value and places the
 unscaled original at coordinates x, y.
diff -rpuN MPlayer-1.0pre3/libmpcodecs/Makefile MPlayer-1.0pre3-work/libmpcodecs/Makefile
--- MPlayer-1.0pre3/libmpcodecs/Makefile	2003-12-08 23:57:21.000000000 +0100
+++ MPlayer-1.0pre3-work/libmpcodecs/Makefile	2004-03-24 14:45:14.177986616 +0100
@@ -14,7 +14,7 @@ VIDEO_SRCS_NAT=vd_null.c vd_cinepak.c vd
 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_zrmjpeg.c vd_xanim.c vd_xvid.c vd_xvid4.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_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 vf_fil.c vf_hue.c vf_spp.c vf_yuvcsp.c vf_filmdint.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.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_lumbox.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 vf_fil.c vf_hue.c vf_spp.c vf_yuvcsp.c vf_filmdint.c
 ifeq ($(HAVE_FFPOSTPROCESS),yes)
 VFILTER_SRCS += vf_pp.c
 endif
diff -rpuN MPlayer-1.0pre3/libmpcodecs/vf.c MPlayer-1.0pre3-work/libmpcodecs/vf.c
--- MPlayer-1.0pre3/libmpcodecs/vf.c	2003-12-08 23:57:21.000000000 +0100
+++ MPlayer-1.0pre3-work/libmpcodecs/vf.c	2004-03-24 14:45:14.179986312 +0100
@@ -21,6 +21,7 @@
 
 extern vf_info_t vf_info_vo;
 extern vf_info_t vf_info_rectangle;
+extern vf_info_t vf_info_lumbox;
 #ifndef HAVE_NO_POSIX_SELECT
 extern vf_info_t vf_info_bmovl;
 #endif
@@ -86,6 +87,7 @@ extern vf_info_t vf_info_yuvcsp;
 // list of available filters:
 static vf_info_t* filter_list[]={
     &vf_info_rectangle,
+    &vf_info_lumbox,
 #ifndef HAVE_NO_POSIX_SELECT
     &vf_info_bmovl,
 #endif
diff -rpuN MPlayer-1.0pre3/libmpcodecs/vf_lumbox.c MPlayer-1.0pre3-work/libmpcodecs/vf_lumbox.c
--- MPlayer-1.0pre3/libmpcodecs/vf_lumbox.c	1970-01-01 01:00:00.000000000 +0100
+++ MPlayer-1.0pre3-work/libmpcodecs/vf_lumbox.c	2004-03-24 14:45:14.180986160 +0100
@@ -0,0 +1,165 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "mp_image.h"
+#include "../mp_msg.h"
+#include "vf.h"
+
+#include "../libvo/fastmemcpy.h"
+
+/* code originally from the rectangle filter written by Kim Minh Kaplan */
+
+struct vf_priv_s {
+    int x, y, w, h, lum;
+};
+
+static int
+config(struct vf_instance_s* vf,
+       int width, int height, int d_width, int d_height,
+       unsigned int flags, unsigned int outfmt)
+{
+    if (vf->priv->lum < 0)
+        vf->priv->lum = 0;
+    else if (vf->priv->lum > 0xff)
+        vf->priv->lum = 0xff;
+    if (vf->priv->w < 0 || width < vf->priv->w)
+	vf->priv->w = width;
+    if (vf->priv->h < 0 || height < vf->priv->h)
+	vf->priv->h = height;
+    if (vf->priv->x < 0)
+	vf->priv->x = (width - vf->priv->w) / 2;
+    if (vf->priv->y < 0)
+	vf->priv->y = (height - vf->priv->h) / 2;
+    if (vf->priv->w + vf->priv->x > width
+	|| vf->priv->h + vf->priv->y > height) {
+	mp_msg(MSGT_VFILTER,MSGL_WARN,"lumbox: bad position/width/height - rectangle area is out of the original!\n");
+	return 0;
+        
+    }
+    return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
+}
+
+static int
+control(struct vf_instance_s* vf, int request, void *data)
+{
+    const int *const tmp = data;
+    switch(request){
+    case VFCTRL_CHANGE_RECTANGLE:
+	switch (tmp[0]){
+	case 0:
+	    vf->priv->w += tmp[1];
+	    return 1;
+	    break;
+	case 1:
+	    vf->priv->h += tmp[1];
+	    return 1;
+	    break;
+	case 2:
+	    vf->priv->x += tmp[1];
+	    return 1;
+	    break;
+	case 3:
+	    vf->priv->y += tmp[1];
+	    return 1;
+	    break;
+        case 4:
+            vf->priv->lum += tmp[1];
+            return 1;
+            break;
+        default:
+	    mp_msg(MSGT_VFILTER,MSGL_FATAL,"Unknown param %d \n", tmp[0]);
+	    return 0;
+	}
+    }
+    return vf_next_control(vf, request, data);
+    return 0;
+}
+static int
+put_image(struct vf_instance_s* vf, mp_image_t* mpi){
+    mp_image_t* dmpi;
+    unsigned int bpp = mpi->bpp / 8;
+    unsigned int x, y, w, h;
+    dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP,
+			MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
+			mpi->w, mpi->h);
+
+    memcpy_pic(dmpi->planes[0],mpi->planes[0],mpi->w*bpp, mpi->h,
+	       dmpi->stride[0],mpi->stride[0]);    
+    if(mpi->flags&MP_IMGFLAG_PLANAR && mpi->flags&MP_IMGFLAG_YUV){
+	memcpy_pic(dmpi->planes[1],mpi->planes[1],
+		   mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift,
+	           dmpi->stride[1],mpi->stride[1]);
+	memcpy_pic(dmpi->planes[2],mpi->planes[2],
+		   mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift,
+	           dmpi->stride[2],mpi->stride[2]);
+    }
+
+    /* Change luminance on the box */
+
+    mp_msg(MSGT_VFILTER,MSGL_INFO, "lumbox: -vf lumbox=%d:%d:%d:%d:%d \n", vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y, vf->priv->lum);
+
+    if (vf->priv->x < 0)
+	x = 0;
+    else if (dmpi->width < vf->priv->x)
+	x = dmpi->width;
+    else
+	x = vf->priv->x;
+    if (vf->priv->x + vf->priv->w - 1 < 0)
+	w = vf->priv->x + vf->priv->w - 1 - x;
+    else if (dmpi->width < vf->priv->x + vf->priv->w - 1)
+	w = dmpi->width - x;
+    else
+	w = vf->priv->x + vf->priv->w - 1 - x;
+    if (vf->priv->y < 0)
+	y = 0;
+    else if (dmpi->height < vf->priv->y)
+	y = dmpi->height;
+    else
+	y = vf->priv->y;
+    if (vf->priv->y + vf->priv->h - 1 < 0)
+	h = vf->priv->y + vf->priv->h - 1 - y;
+    else if (dmpi->height < vf->priv->y + vf->priv->h - 1)
+	h = dmpi->height - y;
+    else
+	h = vf->priv->y + vf->priv->h - 1 - y;
+
+    if (0 <= vf->priv->y && vf->priv->y <= dmpi->height && 0 <= vf->priv->x  && vf->priv->x <= dmpi->width) {
+        unsigned int ycount = h;
+        unsigned int xcount;
+        unsigned char *p;
+        while(ycount--) {
+            p = dmpi->planes[0] + (y + ycount) * dmpi->stride[0] + x * bpp;
+            xcount = w * bpp;
+            while (xcount--)
+                p[xcount] = vf->priv->lum;
+        }
+    }
+
+    return vf_next_put_image(vf, dmpi);
+}
+
+static int
+open(vf_instance_t* vf, char* args) {
+    vf->config = config;
+    vf->control = control;
+    vf->put_image = put_image;
+    vf->priv = malloc(sizeof(struct vf_priv_s));
+    vf->priv->x = -1;
+    vf->priv->y = -1;
+    vf->priv->w = -1;
+    vf->priv->h = -1;
+    vf->priv->lum = -1;
+    if (args)
+	sscanf(args, "%d:%d:%d:%d:%d", 
+	       &vf->priv->w, &vf->priv->h, &vf->priv->x, &vf->priv->y, &vf->priv->lum);
+    return 1;
+}
+
+vf_info_t vf_info_lumbox = {
+    "set constant luminance on a box",
+    "lumbox",
+    "Erik Waling", 
+    "",
+    open,
+    NULL
+};





More information about the MPlayer-dev-eng mailing list