[Mplayer-cvslog] CVS: main/libmpcodecs vf_rectangle.c,1.1,1.2 dec_video.c,1.143,1.144 dec_video.h,1.7,1.8

Kim Minh Kaplan CVS kmkaplan at mplayerhq.hu
Sun Aug 4 04:21:53 CEST 2002


Update of /cvsroot/mplayer/main/libmpcodecs
In directory mail:/var/tmp.root/cvs-serv14018

Modified Files:
	vf_rectangle.c dec_video.c dec_video.h 
Log Message:
Add the control VFCTRL_CHANGE_RECTANGLE
print the rectangle boundaries.
vf_rectangle accepts stride.  Is this correct?


Index: vf_rectangle.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_rectangle.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- vf_rectangle.c	27 Jul 2002 11:40:15 -0000	1.1
+++ vf_rectangle.c	4 Aug 2002 02:21:50 -0000	1.2
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include "mp_image.h"
 #include "vf.h"
 
@@ -7,66 +8,130 @@
     int x, y, w, h;
 };
 
+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->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) {
+	fprintf(stderr, "rectangle: 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;
+	default:
+	    fprintf(stderr, "Unknown param %d \n", tmp[0]);
+	    return 0;
+	}
+    }
+    return vf_next_control(vf, request, data);
+    return 0;
+}
 static void
 put_image(struct vf_instance_s* vf, mp_image_t* mpi){
     mp_image_t* dmpi;
-    int x, y, w, h;
-    unsigned int bpp, count;
-    unsigned char *p1, *p2;
-    dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, 0, mpi->w, mpi->h);
+    unsigned int bpp;
+    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);
     bpp = dmpi->bpp / 8;
     memcpy(dmpi->planes[0], mpi->planes[0], dmpi->stride[0] * bpp * mpi->height);
     memcpy(dmpi->planes[1], mpi->planes[1], dmpi->stride[1] * mpi->chroma_height);
     memcpy(dmpi->planes[2], mpi->planes[2], dmpi->stride[2] * mpi->chroma_height);
 
     /* Draw the rectangle */
-    x = vf->priv->x;
-    if (x < 0)
+
+    fprintf(stderr, "rectangle: -vop crop=%d:%d:%d:%d \n", vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y);
+
+    if (vf->priv->x < 0)
 	x = 0;
-    y = vf->priv->y;
-    if (y < 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;
-    w = vf->priv->w;
-    if (w < 0)
-	w = dmpi->w - x;
-    h = vf->priv->h;
-    if (h < 0)
-	h = dmpi->h - y;
-    count = w * bpp;
-    p1 = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;
-    if (h == 1)
-	while (count--) {
-	    *p1 = 0xff - *p1;
-	    ++p1;
-	}
-    else {
-	p2 = p1 + (h - 1) * dmpi->stride[0];
-	while (count--) {
-	    *p1 = 0xff - *p1;
-	    ++p1;
-	    *p2 = 0xff - *p2;
-	    ++p2;
-	}
+    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) {
+	unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;
+	unsigned int count = w * bpp;
+	while (count--)
+	    p[count] = 0xff - p[count];
+    }
+    if (h != 1 && vf->priv->y + vf->priv->h - 1 <= mpi->height) {
+	unsigned char *p = dmpi->planes[0] + (vf->priv->y + vf->priv->h - 1) * dmpi->stride[0] + x * bpp;
+	unsigned int count = w * bpp;
+	while (count--)
+	    p[count] = 0xff - p[count];
     }
-    count = h;
-    p1 = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;
-    if (w == 1)
+    if (0 <= vf->priv->x  && vf->priv->x <= dmpi->width) {
+	unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;
+	unsigned int count = h;
 	while (count--) {
-	    int i = bpp;
+	    unsigned int i = bpp;
 	    while (i--)
-		p1[i] ^= 0xff;
-	    p1 += dmpi->stride[0];
+		p[i] = 0xff - p[i];
+	    p += dmpi->stride[0];
 	}
-    else {
-	p2 = p1 + (w - 1) * bpp;
+    }
+    if (w != 1 && vf->priv->x + vf->priv->w - 1 <= mpi->width) {
+	unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + (vf->priv->x + vf->priv->w - 1) * bpp;
+	unsigned int count = h;
 	while (count--) {
-	    int i = bpp;
-	    while (i--) {
-		p1[i] = 0xff - p1[i];
-		p2[i] = 0xff - p2[i];
-	    }
-	    p1 += dmpi->stride[0];
-	    p2 += dmpi->stride[0];
+	    unsigned int i = bpp;
+	    while (i--)
+		p[i] = 0xff - p[i];
+	    p += dmpi->stride[0];
 	}
     }
     vf_next_put_image(vf, dmpi);
@@ -74,6 +139,8 @@
 
 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;
@@ -83,8 +150,6 @@
     if (args)
 	sscanf(args, "%d:%d:%d:%d", 
 	       &vf->priv->w, &vf->priv->h, &vf->priv->x, &vf->priv->y);
-    printf("Crop: %d x %d, %d ; %d\n",
-	   vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y);
     return 1;
 }
 

Index: dec_video.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/dec_video.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -r1.143 -r1.144
--- dec_video.c	28 Jul 2002 21:30:09 -0000	1.143
+++ dec_video.c	4 Aug 2002 02:21:50 -0000	1.144
@@ -118,6 +118,21 @@
     return 0;
 }
 
+int set_rectangle(sh_video_t *sh_video,int param,int value)
+{
+    vf_instance_t* vf=sh_video->vfilter;
+    int data[] = {param, value};
+
+    mp_dbg(MSGT_DECVIDEO,MSGL_V,"set rectangle \n");
+    if (vf)
+    {
+        int ret = vf->control(vf, VFCTRL_CHANGE_RECTANGLE, data);
+	if (ret)
+	    return(1);
+    }
+    return 0;
+}
+
 void uninit_video(sh_video_t *sh_video){
     if(!sh_video->inited) return;
     mp_msg(MSGT_DECVIDEO,MSGL_V,"uninit video: %d  \n",sh_video->codec->driver);

Index: dec_video.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/dec_video.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- dec_video.h	6 Apr 2002 22:05:00 -0000	1.7
+++ dec_video.h	4 Aug 2002 02:21:50 -0000	1.8
@@ -12,5 +12,6 @@
 extern void set_video_quality(sh_video_t *sh_video,int quality);
 
 extern int set_video_colors(sh_video_t *sh_video,char *item,int value);
+extern int set_rectangle(sh_video_t *sh_video,int param,int value);
 
 extern int divx_quality;




More information about the MPlayer-cvslog mailing list