changeset 21401:4a5045cd7c0c

Cleanup and fix rectangle size calculation, caused crashes with e.g. -vf rectangle=0:0:0:0
author reimar
date Fri, 01 Dec 2006 17:51:44 +0000
parents 6fe9c6a0c4b0
children 8c43ea1ea79a
files libmpcodecs/vf_rectangle.c
diffstat 1 files changed, 15 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vf_rectangle.c	Fri Dec 01 17:49:59 2006 +0000
+++ b/libmpcodecs/vf_rectangle.c	Fri Dec 01 17:51:44 2006 +0000
@@ -6,6 +6,7 @@
 #include "vf.h"
 
 #include "libvo/fastmemcpy.h"
+#include "libavutil/common.h"
 
 struct vf_priv_s {
     int x, y, w, h;
@@ -67,7 +68,7 @@
 put_image(struct vf_instance_s* vf, mp_image_t* mpi, double pts){
     mp_image_t* dmpi;
     unsigned int bpp = mpi->bpp / 8;
-    unsigned int x, y, w, h;
+    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);
@@ -87,30 +88,19 @@
 
     mp_msg(MSGT_VFILTER,MSGL_INFO, "rectangle: -vf rectangle=%d:%d:%d:%d \n", vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y);
 
-    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;
+    x = FFMIN(vf->priv->x, dmpi->width);
+    x = FFMAX(x, 0);
+
+    w = vf->priv->x + vf->priv->w - 1 - x;
+    w = FFMIN(w, dmpi->width - x);
+    w = FFMAX(w, 0);
+
+    y = FFMIN(vf->priv->y, dmpi->height);
+    y = FFMAX(y, 0);
+
+    h = vf->priv->y + vf->priv->h - 1 - y;
+    h = FFMIN(h, dmpi->height - y);
+    h = FFMAX(h, 0);
 
     if (0 <= vf->priv->y && vf->priv->y <= dmpi->height) {
 	unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp;