From 8a5725ccadcce726c052b5cf835b943126283178 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 1 Dec 2006 17:51:44 +0000 Subject: Cleanup and fix rectangle size calculation, caused crashes with e.g. -vf rectangle=0:0:0:0 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@21417 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/vf_rectangle.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/libmpcodecs/vf_rectangle.c b/libmpcodecs/vf_rectangle.c index 361734369c..54698e1b53 100644 --- a/libmpcodecs/vf_rectangle.c +++ b/libmpcodecs/vf_rectangle.c @@ -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 @@ static int 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 @@ put_image(struct vf_instance_s* vf, mp_image_t* mpi, double pts){ 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; -- cgit v1.2.3