Fixed bug #189
authorSam Lantinga <slouken@libsdl.org>
Mon, 17 Apr 2006 05:38:33 +0000
changeset 1642f1211a4b7380
parent 1641 5cf11b00b900
child 1643 51038e80ae59
Fixed bug #189

Clip the overlay destination rectangle to the screen area on X11
src/video/x11/SDL_x11yuv.c
test/testoverlay2.c
     1.1 --- a/src/video/x11/SDL_x11yuv.c	Mon Apr 17 04:54:08 2006 +0000
     1.2 +++ b/src/video/x11/SDL_x11yuv.c	Mon Apr 17 05:38:33 2006 +0000
     1.3 @@ -357,20 +357,59 @@
     1.4  int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
     1.5  {
     1.6  	struct private_yuvhwdata *hwdata;
     1.7 +	int srcx, srcy, srcw, srch;
     1.8 +	int dstx, dsty, dstw, dsth;
     1.9  
    1.10  	hwdata = overlay->hwdata;
    1.11 +
    1.12 +	/* Clip the rectangle to the screen area */
    1.13 +	srcx = 0;
    1.14 +	srcy = 0;
    1.15 +	srcw = overlay->w;
    1.16 +	srch = overlay->h;
    1.17 +	dstx = dstrect->x;
    1.18 +	dsty = dstrect->y;
    1.19 +	dstw = dstrect->w;
    1.20 +	dsth = dstrect->h;
    1.21 +	if ( dstx < 0 ) {
    1.22 +		srcw += (dstx * overlay->w) / dstrect->w;
    1.23 +		dstw += dstx;
    1.24 +		srcx -= (dstx * overlay->w) / dstrect->w;
    1.25 +		dstx = 0;
    1.26 +	}
    1.27 +	if ( (dstx+dstw) > this->screen->w ) {
    1.28 +		int extra = (dstx+dstw - this->screen->w);
    1.29 +		srcw -= (extra * overlay->w) / dstrect->w;
    1.30 +		dstw -= extra;
    1.31 +	}
    1.32 +	if ( dsty < 0 ) {
    1.33 +		srch += (dsty * overlay->h) / dstrect->h;
    1.34 +		dsth += dsty;
    1.35 +		srcy -= (dsty * overlay->h) / dstrect->h;
    1.36 +		dsty = 0;
    1.37 +	}
    1.38 +	if ( (dsty+dsth) > this->screen->h ) {
    1.39 +		int extra = (dsty+dsth - this->screen->h);
    1.40 +		srch -= (extra * overlay->h) / dstrect->h;
    1.41 +		dsth -= extra;
    1.42 +	}
    1.43 +	if ( srcw <= 0 || srch <= 0 ||
    1.44 +	     srch <= 0 || dsth <= 0 ) {
    1.45 +		return;
    1.46 +	}
    1.47 +
    1.48  #ifndef NO_SHARED_MEMORY
    1.49  	if ( hwdata->yuv_use_mitshm ) {
    1.50  		SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
    1.51 -	              hwdata->image, 0, 0, overlay->w, overlay->h,
    1.52 -	              dstrect->x, dstrect->y, dstrect->w, dstrect->h, False);
    1.53 +	              hwdata->image,
    1.54 +		      srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth, False);
    1.55  	}
    1.56  	else
    1.57  #endif
    1.58  	{
    1.59  		SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
    1.60 -				     hwdata->image, 0, 0, overlay->w, overlay->h,
    1.61 -				     dstrect->x, dstrect->y, dstrect->w, dstrect->h);
    1.62 +				     hwdata->image,
    1.63 +		                     srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth);
    1.64  	}
    1.65  	XSync(GFX_Display, False);
    1.66  	return(0);
     2.1 --- a/test/testoverlay2.c	Mon Apr 17 04:54:08 2006 +0000
     2.2 +++ b/test/testoverlay2.c	Mon Apr 17 05:38:33 2006 +0000
     2.3 @@ -526,6 +526,10 @@
     2.4                           resized=1;
     2.5                       }
     2.6                       break;
     2.7 +                case SDL_MOUSEBUTTONDOWN:
     2.8 +                     overlayrect.x = event.button.x - overlayrect.w/2;
     2.9 +                     overlayrect.y = event.button.y - overlayrect.h/2;
    2.10 +                     break;
    2.11                  case SDL_KEYDOWN:
    2.12                       if (event.key.keysym.sym == SDLK_SPACE)
    2.13                       {