More general fix for bug #189
authorSam Lantinga <slouken@libsdl.org>
Mon, 17 Apr 2006 06:47:23 +0000
changeset 164351038e80ae59
parent 1642 f1211a4b7380
child 1644 8a858076f39d
More general fix for bug #189

The clipping is done at a higher level, and the low level functions are
passed clipped rectangles. Drivers which don't support source clipping
have not been changed, so the image will be squished instead of clipped,
but at least they will no longer crash when the destination rect was out
of bounds.
src/video/SDL_yuv.c
src/video/SDL_yuv_sw.c
src/video/SDL_yuv_sw_c.h
src/video/SDL_yuvfuncs.h
src/video/bwindow/SDL_sysyuv.cc
src/video/bwindow/SDL_sysyuv.h
src/video/directfb/SDL_DirectFB_yuv.c
src/video/directfb/SDL_DirectFB_yuv.h
src/video/photon/SDL_ph_events.c
src/video/photon/SDL_phyuv.c
src/video/photon/SDL_phyuv_c.h
src/video/ps2gs/SDL_gsyuv.c
src/video/ps2gs/SDL_gsyuv_c.h
src/video/windx5/SDL_dx5yuv.c
src/video/windx5/SDL_dx5yuv_c.h
src/video/x11/SDL_x11yuv.c
src/video/x11/SDL_x11yuv_c.h
     1.1 --- a/src/video/SDL_yuv.c	Mon Apr 17 05:38:33 2006 +0000
     1.2 +++ b/src/video/SDL_yuv.c	Mon Apr 17 06:47:23 2006 +0000
     1.3 @@ -75,7 +75,55 @@
     1.4  
     1.5  int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect)
     1.6  {
     1.7 -	return overlay->hwfuncs->Display(current_video, overlay, dstrect);
     1.8 +	SDL_Rect src, dst;
     1.9 +	int srcx, srcy, srcw, srch;
    1.10 +	int dstx, dsty, dstw, dsth;
    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) > current_video->screen->w ) {
    1.28 +		int extra = (dstx+dstw - current_video->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) > current_video->screen->h ) {
    1.39 +		int extra = (dsty+dsth - current_video->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 0;
    1.46 +	}
    1.47 +	/* Ugh, I can't wait for SDL_Rect to be int values */
    1.48 +	src.x = srcx;
    1.49 +	src.y = srcy;
    1.50 +	src.w = srcw;
    1.51 +	src.h = srch;
    1.52 +	dst.x = dstx;
    1.53 +	dst.y = dsty;
    1.54 +	dst.w = dstw;
    1.55 +	dst.h = dsth;
    1.56 +	return overlay->hwfuncs->Display(current_video, overlay, &src, &dst);
    1.57  }
    1.58  
    1.59  void SDL_FreeYUVOverlay(SDL_Overlay *overlay)
     2.1 --- a/src/video/SDL_yuv_sw.c	Mon Apr 17 05:38:33 2006 +0000
     2.2 +++ b/src/video/SDL_yuv_sw.c	Mon Apr 17 06:47:23 2006 +0000
     2.3 @@ -1164,43 +1164,44 @@
     2.4  	return;
     2.5  }
     2.6  
     2.7 -int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
     2.8 +int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
     2.9  {
    2.10  	struct private_yuvhwdata *swdata;
    2.11 -	SDL_Surface *stretch;
    2.12 +	int stretch;
    2.13 +	int scale_2x;
    2.14  	SDL_Surface *display;
    2.15 -	int scale_2x;
    2.16  	Uint8 *lum, *Cr, *Cb;
    2.17 -	Uint8 *dst;
    2.18 +	Uint8 *dstp;
    2.19  	int mod;
    2.20  
    2.21  	swdata = overlay->hwdata;
    2.22 +	stretch = 0;
    2.23  	scale_2x = 0;
    2.24 -	stretch = 0;
    2.25 -	if ( (overlay->w != dstrect->w) || (overlay->h != dstrect->h) ) {
    2.26 -		if ( (dstrect->w == 2*overlay->w) &&
    2.27 -		     (dstrect->h == 2*overlay->h) ) {
    2.28 +	if ( src->x || src->y || src->w < overlay->w || src->h < overlay->h ) {
    2.29 +		stretch = 1;
    2.30 +	} else if ( (src->w != dst->w) || (src->h != dst->h) ) {
    2.31 +		if ( (dst->w == 2*src->w) &&
    2.32 +		     (dst->h == 2*src->h) ) {
    2.33  			scale_2x = 1;
    2.34  		} else {
    2.35 -			if ( ! swdata->stretch ) {
    2.36 -				display = swdata->display;
    2.37 -				swdata->stretch = SDL_CreateRGBSurface(
    2.38 -					SDL_SWSURFACE,
    2.39 -					overlay->w, overlay->h,
    2.40 -					display->format->BitsPerPixel,
    2.41 -					display->format->Rmask,
    2.42 -					display->format->Gmask,
    2.43 -					display->format->Bmask, 0);
    2.44 -				if ( ! swdata->stretch ) {
    2.45 -					return(-1);
    2.46 -				}
    2.47 -			}
    2.48 -			stretch = swdata->stretch;
    2.49 +			stretch = 1;
    2.50  		}
    2.51  	}
    2.52 -
    2.53  	if ( stretch ) {
    2.54 -		display = stretch;
    2.55 +		if ( ! swdata->stretch ) {
    2.56 +			display = swdata->display;
    2.57 +			swdata->stretch = SDL_CreateRGBSurface(
    2.58 +				SDL_SWSURFACE,
    2.59 +				overlay->w, overlay->h,
    2.60 +				display->format->BitsPerPixel,
    2.61 +				display->format->Rmask,
    2.62 +				display->format->Gmask,
    2.63 +				display->format->Bmask, 0);
    2.64 +			if ( ! swdata->stretch ) {
    2.65 +				return(-1);
    2.66 +			}
    2.67 +		}
    2.68 +		display = swdata->stretch;
    2.69  	} else {
    2.70  		display = swdata->display;
    2.71  	}
    2.72 @@ -1240,31 +1241,31 @@
    2.73  		}
    2.74  	}
    2.75  	if ( stretch ) {
    2.76 -		dst = (Uint8 *)stretch->pixels;
    2.77 +		dstp = (Uint8 *)swdata->stretch->pixels;
    2.78  	} else {
    2.79 -		dst = (Uint8 *)display->pixels
    2.80 -			+ dstrect->x * display->format->BytesPerPixel
    2.81 -			+ dstrect->y * display->pitch;
    2.82 +		dstp = (Uint8 *)display->pixels
    2.83 +			+ dst->x * display->format->BytesPerPixel
    2.84 +			+ dst->y * display->pitch;
    2.85  	}
    2.86  	mod = (display->pitch / display->format->BytesPerPixel);
    2.87  
    2.88  	if ( scale_2x ) {
    2.89  		mod -= (overlay->w * 2);
    2.90  		swdata->Display2X(swdata->colortab, swdata->rgb_2_pix,
    2.91 -		                  lum, Cr, Cb, dst, overlay->h, overlay->w,mod);
    2.92 +		                  lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
    2.93  	} else {
    2.94  		mod -= overlay->w;
    2.95  		swdata->Display1X(swdata->colortab, swdata->rgb_2_pix,
    2.96 -		                  lum, Cr, Cb, dst, overlay->h, overlay->w,mod);
    2.97 +		                  lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
    2.98  	}
    2.99  	if ( SDL_MUSTLOCK(display) ) {
   2.100  		SDL_UnlockSurface(display);
   2.101  	}
   2.102  	if ( stretch ) {
   2.103  		display = swdata->display;
   2.104 -		SDL_SoftStretch(stretch, NULL, display, dstrect);
   2.105 +		SDL_SoftStretch(swdata->stretch, src, display, dst);
   2.106  	}
   2.107 -	SDL_UpdateRects(display, 1, dstrect);
   2.108 +	SDL_UpdateRects(display, 1, dst);
   2.109  
   2.110  	return(0);
   2.111  }
     3.1 --- a/src/video/SDL_yuv_sw_c.h	Mon Apr 17 05:38:33 2006 +0000
     3.2 +++ b/src/video/SDL_yuv_sw_c.h	Mon Apr 17 06:47:23 2006 +0000
     3.3 @@ -32,6 +32,6 @@
     3.4  
     3.5  extern void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay);
     3.6  
     3.7 -extern int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
     3.8 +extern int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
     3.9  
    3.10  extern void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay);
     4.1 --- a/src/video/SDL_yuvfuncs.h	Mon Apr 17 05:38:33 2006 +0000
     4.2 +++ b/src/video/SDL_yuvfuncs.h	Mon Apr 17 06:47:23 2006 +0000
     4.3 @@ -32,6 +32,6 @@
     4.4  struct private_yuvhwfuncs {
     4.5  	int (*Lock)(_THIS, SDL_Overlay *overlay);
     4.6  	void (*Unlock)(_THIS, SDL_Overlay *overlay);
     4.7 -	int (*Display)(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
     4.8 +	int (*Display)(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
     4.9  	void (*FreeHW)(_THIS, SDL_Overlay *overlay);
    4.10  };
     5.1 --- a/src/video/bwindow/SDL_sysyuv.cc	Mon Apr 17 05:38:33 2006 +0000
     5.2 +++ b/src/video/bwindow/SDL_sysyuv.cc	Mon Apr 17 06:47:23 2006 +0000
     5.3 @@ -263,7 +263,7 @@
     5.4      overlay->hwdata->locked = 0;
     5.5  }
     5.6  
     5.7 -int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect)
     5.8 +int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect *dst)
     5.9  {
    5.10      if ((overlay == NULL) || (overlay->hwdata==NULL)
    5.11          || (overlay->hwdata->bview==NULL) || (SDL_Win->View() == NULL))
    5.12 @@ -277,11 +277,11 @@
    5.13      if (SDL_Win->IsFullScreen()) {
    5.14      	int left,top;
    5.15      	SDL_Win->GetXYOffset(left,top);
    5.16 -	    bview->MoveTo(left+dstrect->x,top+dstrect->y);
    5.17 +	    bview->MoveTo(left+dst->x,top+dst->y);
    5.18      } else {
    5.19 -	    bview->MoveTo(dstrect->x,dstrect->y);
    5.20 +	    bview->MoveTo(dst->x,dst->y);
    5.21      }
    5.22 -    bview->ResizeTo(dstrect->w,dstrect->h);
    5.23 +    bview->ResizeTo(dst->w,dst->h);
    5.24      bview->Flush();
    5.25  	if (overlay->hwdata->first_display) {
    5.26  		bview->Show();
     6.1 --- a/src/video/bwindow/SDL_sysyuv.h	Mon Apr 17 05:38:33 2006 +0000
     6.2 +++ b/src/video/bwindow/SDL_sysyuv.h	Mon Apr 17 06:47:23 2006 +0000
     6.3 @@ -65,7 +65,7 @@
     6.4  extern SDL_Overlay* BE_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display);
     6.5  extern int BE_LockYUVOverlay(_THIS, SDL_Overlay* overlay);
     6.6  extern void BE_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay);
     6.7 -extern int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect);
     6.8 +extern int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst);
     6.9  extern void BE_FreeYUVOverlay(_THIS, SDL_Overlay* overlay);
    6.10  
    6.11  };
     7.1 --- a/src/video/directfb/SDL_DirectFB_yuv.c	Mon Apr 17 05:38:33 2006 +0000
     7.2 +++ b/src/video/directfb/SDL_DirectFB_yuv.c	Mon Apr 17 06:47:23 2006 +0000
     7.3 @@ -241,7 +241,7 @@
     7.4    surface->Unlock (surface);
     7.5  }
     7.6  
     7.7 -int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dst)
     7.8 +int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
     7.9  {
    7.10    DFBResult              ret;
    7.11    DFBDisplayLayerConfig  conf;
     8.1 --- a/src/video/directfb/SDL_DirectFB_yuv.h	Mon Apr 17 05:38:33 2006 +0000
     8.2 +++ b/src/video/directfb/SDL_DirectFB_yuv.h	Mon Apr 17 06:47:23 2006 +0000
     8.3 @@ -32,7 +32,7 @@
     8.4  
     8.5  extern void DirectFB_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
     8.6  
     8.7 -extern int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
     8.8 +extern int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
     8.9  
    8.10  extern void DirectFB_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);
    8.11  
     9.1 --- a/src/video/photon/SDL_ph_events.c	Mon Apr 17 05:38:33 2006 +0000
     9.2 +++ b/src/video/photon/SDL_ph_events.c	Mon Apr 17 06:47:23 2006 +0000
     9.3 @@ -245,15 +245,19 @@
     9.4                     int lockedstate=current_overlay->hwdata->locked;
     9.5                     int chromastate=current_overlay->hwdata->ischromakey;
     9.6                     int error;
     9.7 -                   SDL_Rect target;
     9.8 +                   SDL_Rect src, dst;
     9.9  
    9.10                     current_overlay->hwdata->locked=1;
    9.11 -                   target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
    9.12 -                   target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
    9.13 -                   target.w=current_overlay->hwdata->CurrentViewPort.size.w;
    9.14 -                   target.h=current_overlay->hwdata->CurrentViewPort.size.h;
    9.15 +                   src.x = 0;
    9.16 +                   src.y = 0;
    9.17 +                   src.w = current_overlay->w;
    9.18 +                   src.y = current_overlay->h;
    9.19 +                   dst.x=current_overlay->hwdata->CurrentViewPort.pos.x;
    9.20 +                   dst.y=current_overlay->hwdata->CurrentViewPort.pos.y;
    9.21 +                   dst.w=current_overlay->hwdata->CurrentViewPort.size.w;
    9.22 +                   dst.h=current_overlay->hwdata->CurrentViewPort.size.h;
    9.23                     current_overlay->hwdata->ischromakey=0;
    9.24 -                   error=ph_DisplayYUVOverlay(this, current_overlay, &target);
    9.25 +                   error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst);
    9.26                     if (!error)
    9.27                     {
    9.28                         current_overlay->hwdata->ischromakey=chromastate;
    9.29 @@ -306,15 +310,19 @@
    9.30                      {
    9.31                          int lockedstate=current_overlay->hwdata->locked;
    9.32                          int error;
    9.33 -                        SDL_Rect target;
    9.34 +                        SDL_Rect src, dst;
    9.35  
    9.36                          current_overlay->hwdata->locked=1;
    9.37 -                        target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
    9.38 -                        target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
    9.39 -                        target.w=current_overlay->hwdata->CurrentViewPort.size.w;
    9.40 -                        target.h=current_overlay->hwdata->CurrentViewPort.size.h;
    9.41 +                        src.x = 0;
    9.42 +                        src.y = 0;
    9.43 +                        src.w = current_overlay->w;
    9.44 +                        src.y = current_overlay->h;
    9.45 +                        dst.x=current_overlay->hwdata->CurrentViewPort.pos.x;
    9.46 +                        dst.y=current_overlay->hwdata->CurrentViewPort.pos.y;
    9.47 +                        dst.w=current_overlay->hwdata->CurrentViewPort.size.w;
    9.48 +                        dst.h=current_overlay->hwdata->CurrentViewPort.size.h;
    9.49                          current_overlay->hwdata->forcedredraw=1;
    9.50 -                        error=ph_DisplayYUVOverlay(this, current_overlay, &target);
    9.51 +                        error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst);
    9.52                          if (!error)
    9.53                          {
    9.54                              current_overlay->hwdata->forcedredraw=0;
    10.1 --- a/src/video/photon/SDL_phyuv.c	Mon Apr 17 05:38:33 2006 +0000
    10.2 +++ b/src/video/photon/SDL_phyuv.c	Mon Apr 17 06:47:23 2006 +0000
    10.3 @@ -334,7 +334,7 @@
    10.4      overlay->hwdata->locked = 0;
    10.5  }
    10.6  
    10.7 -int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect)
    10.8 +int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst)
    10.9  {
   10.10      int rtncode;
   10.11      PhPoint_t pos;
   10.12 @@ -362,10 +362,10 @@
   10.13      }
   10.14  
   10.15      /* If CurrentViewPort position/size has been changed, then move/resize the viewport */
   10.16 -    if ((overlay->hwdata->CurrentViewPort.pos.x != dstrect->x) ||
   10.17 -        (overlay->hwdata->CurrentViewPort.pos.y != dstrect->y) ||
   10.18 -        (overlay->hwdata->CurrentViewPort.size.w != dstrect->w) ||
   10.19 -        (overlay->hwdata->CurrentViewPort.size.h != dstrect->h) ||
   10.20 +    if ((overlay->hwdata->CurrentViewPort.pos.x != dst->x) ||
   10.21 +        (overlay->hwdata->CurrentViewPort.pos.y != dst->y) ||
   10.22 +        (overlay->hwdata->CurrentViewPort.size.w != dst->w) ||
   10.23 +        (overlay->hwdata->CurrentViewPort.size.h != dst->h) ||
   10.24          (overlay->hwdata->scaler_on==0) || (winchanged==1) ||
   10.25          (overlay->hwdata->forcedredraw==1))
   10.26      {
   10.27 @@ -381,7 +381,7 @@
   10.28  
   10.29              /* Draw the new rectangle of the chroma color at the viewport position */
   10.30              PgSetFillColor(overlay->hwdata->chromakey);
   10.31 -            PgDrawIRect(dstrect->x, dstrect->y, dstrect->x+dstrect->w-1, dstrect->y+dstrect->h-1, Pg_DRAW_FILL);
   10.32 +            PgDrawIRect(dst->x, dst->y, dst->x+dst->w-1, dst->y+dst->h-1, Pg_DRAW_FILL);
   10.33              PgFlush();
   10.34          }
   10.35  
   10.36 @@ -389,13 +389,13 @@
   10.37          overlay->hwdata->scaler_on = 1;
   10.38  
   10.39          PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, PtWidgetRid(window), &windowextent);
   10.40 -        overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dstrect->x;
   10.41 -        overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dstrect->y;
   10.42 -        overlay->hwdata->CurrentViewPort.size.w = dstrect->w;
   10.43 -        overlay->hwdata->CurrentViewPort.size.h = dstrect->h;
   10.44 +        overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dst->x;
   10.45 +        overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dst->y;
   10.46 +        overlay->hwdata->CurrentViewPort.size.w = dst->w;
   10.47 +        overlay->hwdata->CurrentViewPort.size.h = dst->h;
   10.48          PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport);
   10.49 -        overlay->hwdata->CurrentViewPort.pos.x = dstrect->x;
   10.50 -        overlay->hwdata->CurrentViewPort.pos.y = dstrect->y;
   10.51 +        overlay->hwdata->CurrentViewPort.pos.x = dst->x;
   10.52 +        overlay->hwdata->CurrentViewPort.pos.y = dst->y;
   10.53  
   10.54          rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props));
   10.55  
    11.1 --- a/src/video/photon/SDL_phyuv_c.h	Mon Apr 17 05:38:33 2006 +0000
    11.2 +++ b/src/video/photon/SDL_phyuv_c.h	Mon Apr 17 06:47:23 2006 +0000
    11.3 @@ -56,7 +56,7 @@
    11.4  extern SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display);
    11.5  extern int ph_LockYUVOverlay(_THIS, SDL_Overlay* overlay);
    11.6  extern void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay);
    11.7 -extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect);
    11.8 +extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst);
    11.9  extern void ph_FreeYUVOverlay(_THIS, SDL_Overlay* overlay);
   11.10  
   11.11  #endif /* __SDL_PH_YUV_H__ */
    12.1 --- a/src/video/ps2gs/SDL_gsyuv.c	Mon Apr 17 05:38:33 2006 +0000
    12.2 +++ b/src/video/ps2gs/SDL_gsyuv.c	Mon Apr 17 06:47:23 2006 +0000
    12.3 @@ -315,7 +315,7 @@
    12.4  	return;
    12.5  }
    12.6  
    12.7 -int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
    12.8 +int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
    12.9  {
   12.10  	struct private_yuvhwdata *hwdata;
   12.11  	__u32 cmd;
   12.12 @@ -423,8 +423,8 @@
   12.13  
   12.14  	/* Send the current image to the screen and scale it */
   12.15  	screen = this->screen;
   12.16 -	x = (unsigned int)dstrect->x;
   12.17 -	y = (unsigned int)dstrect->y;
   12.18 +	x = (unsigned int)dst->x;
   12.19 +	y = (unsigned int)dst->y;
   12.20  	if ( screen->offset ) {
   12.21  		x += (screen->offset % screen->pitch) /
   12.22  		     screen->format->BytesPerPixel;
   12.23 @@ -432,8 +432,8 @@
   12.24  	}
   12.25  	y += screen_image.y;
   12.26  	*hwdata->stretch_x1y1 = (x * 16) + ((y * 16) << 16);
   12.27 -	x += (unsigned int)dstrect->w;
   12.28 -	y += (unsigned int)dstrect->h;
   12.29 +	x += (unsigned int)dst->w;
   12.30 +	y += (unsigned int)dst->h;
   12.31  	*hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16);
   12.32  	return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist);
   12.33  }
    13.1 --- a/src/video/ps2gs/SDL_gsyuv_c.h	Mon Apr 17 05:38:33 2006 +0000
    13.2 +++ b/src/video/ps2gs/SDL_gsyuv_c.h	Mon Apr 17 06:47:23 2006 +0000
    13.3 @@ -32,6 +32,6 @@
    13.4  
    13.5  extern void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
    13.6  
    13.7 -extern int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
    13.8 +extern int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
    13.9  
   13.10  extern void GS_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);
    14.1 --- a/src/video/windx5/SDL_dx5yuv.c	Mon Apr 17 05:38:33 2006 +0000
    14.2 +++ b/src/video/windx5/SDL_dx5yuv.c	Mon Apr 17 06:47:23 2006 +0000
    14.3 @@ -247,30 +247,30 @@
    14.4  	IDirectDrawSurface3_Unlock(surface, NULL);
    14.5  }
    14.6  
    14.7 -int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
    14.8 +int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
    14.9  {
   14.10  	HRESULT result;
   14.11  	LPDIRECTDRAWSURFACE3 surface;
   14.12 -	RECT src, dst;
   14.13 +	RECT srcrect, dstrect;
   14.14  
   14.15  	surface = overlay->hwdata->surface;
   14.16 -	src.top = 0;
   14.17 -	src.bottom = overlay->h;
   14.18 -	src.left = 0;
   14.19 -	src.right = overlay->w;
   14.20 -	dst.top = SDL_bounds.top+dstrect->y;
   14.21 -	dst.left = SDL_bounds.left+dstrect->x;
   14.22 -	dst.bottom = dst.top+dstrect->h;
   14.23 -	dst.right = dst.left+dstrect->w;
   14.24 +	srcrect.top = src->y;
   14.25 +	srcrect.bottom = srcrect.top+src->h;
   14.26 +	srcrect.left = src->x;
   14.27 +	srcrect.right = srcrect.left+src->w;
   14.28 +	dstrect.top = SDL_bounds.top+dst->y;
   14.29 +	dstrect.left = SDL_bounds.left+dst->x;
   14.30 +	dstrect.bottom = dstrect.top+dst->h;
   14.31 +	dstrect.right = dstrect.left+dst->w;
   14.32  #ifdef USE_DIRECTX_OVERLAY
   14.33 -	result = IDirectDrawSurface3_UpdateOverlay(surface, &src,
   14.34 -				SDL_primary, &dst, DDOVER_SHOW, NULL);
   14.35 +	result = IDirectDrawSurface3_UpdateOverlay(surface, &srcrect,
   14.36 +				SDL_primary, &dstrect, DDOVER_SHOW, NULL);
   14.37  	if ( result != DD_OK ) {
   14.38  		SetDDerror("DirectDrawSurface3::UpdateOverlay", result);
   14.39  		return(-1);
   14.40  	}
   14.41  #else
   14.42 -	result = IDirectDrawSurface3_Blt(SDL_primary, &dst, surface, &src,
   14.43 +	result = IDirectDrawSurface3_Blt(SDL_primary, &dstrect, surface, &srcrect,
   14.44  							DDBLT_WAIT, NULL);
   14.45  	if ( result != DD_OK ) {
   14.46  		SetDDerror("DirectDrawSurface3::Blt", result);
    15.1 --- a/src/video/windx5/SDL_dx5yuv_c.h	Mon Apr 17 05:38:33 2006 +0000
    15.2 +++ b/src/video/windx5/SDL_dx5yuv_c.h	Mon Apr 17 06:47:23 2006 +0000
    15.3 @@ -33,6 +33,6 @@
    15.4  
    15.5  extern void DX5_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
    15.6  
    15.7 -extern int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
    15.8 +extern int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
    15.9  
   15.10  extern void DX5_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);
    16.1 --- a/src/video/x11/SDL_x11yuv.c	Mon Apr 17 05:38:33 2006 +0000
    16.2 +++ b/src/video/x11/SDL_x11yuv.c	Mon Apr 17 06:47:23 2006 +0000
    16.3 @@ -354,62 +354,26 @@
    16.4  	return;
    16.5  }
    16.6  
    16.7 -int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect)
    16.8 +int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
    16.9  {
   16.10  	struct private_yuvhwdata *hwdata;
   16.11 -	int srcx, srcy, srcw, srch;
   16.12 -	int dstx, dsty, dstw, dsth;
   16.13  
   16.14  	hwdata = overlay->hwdata;
   16.15  
   16.16 -	/* Clip the rectangle to the screen area */
   16.17 -	srcx = 0;
   16.18 -	srcy = 0;
   16.19 -	srcw = overlay->w;
   16.20 -	srch = overlay->h;
   16.21 -	dstx = dstrect->x;
   16.22 -	dsty = dstrect->y;
   16.23 -	dstw = dstrect->w;
   16.24 -	dsth = dstrect->h;
   16.25 -	if ( dstx < 0 ) {
   16.26 -		srcw += (dstx * overlay->w) / dstrect->w;
   16.27 -		dstw += dstx;
   16.28 -		srcx -= (dstx * overlay->w) / dstrect->w;
   16.29 -		dstx = 0;
   16.30 -	}
   16.31 -	if ( (dstx+dstw) > this->screen->w ) {
   16.32 -		int extra = (dstx+dstw - this->screen->w);
   16.33 -		srcw -= (extra * overlay->w) / dstrect->w;
   16.34 -		dstw -= extra;
   16.35 -	}
   16.36 -	if ( dsty < 0 ) {
   16.37 -		srch += (dsty * overlay->h) / dstrect->h;
   16.38 -		dsth += dsty;
   16.39 -		srcy -= (dsty * overlay->h) / dstrect->h;
   16.40 -		dsty = 0;
   16.41 -	}
   16.42 -	if ( (dsty+dsth) > this->screen->h ) {
   16.43 -		int extra = (dsty+dsth - this->screen->h);
   16.44 -		srch -= (extra * overlay->h) / dstrect->h;
   16.45 -		dsth -= extra;
   16.46 -	}
   16.47 -	if ( srcw <= 0 || srch <= 0 ||
   16.48 -	     srch <= 0 || dsth <= 0 ) {
   16.49 -		return;
   16.50 -	}
   16.51 -
   16.52  #ifndef NO_SHARED_MEMORY
   16.53  	if ( hwdata->yuv_use_mitshm ) {
   16.54  		SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
   16.55  	              hwdata->image,
   16.56 -		      srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth, False);
   16.57 +		      src->x, src->y, src->w, src->h,
   16.58 +		      dst->x, dst->y, dst->w, dst->h, False);
   16.59  	}
   16.60  	else
   16.61  #endif
   16.62  	{
   16.63  		SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC,
   16.64  				     hwdata->image,
   16.65 -		                     srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth);
   16.66 +		                     src->x, src->y, src->w, src->h,
   16.67 +		                     dst->x, dst->y, dst->w, dst->h);
   16.68  	}
   16.69  	XSync(GFX_Display, False);
   16.70  	return(0);
    17.1 --- a/src/video/x11/SDL_x11yuv_c.h	Mon Apr 17 05:38:33 2006 +0000
    17.2 +++ b/src/video/x11/SDL_x11yuv_c.h	Mon Apr 17 06:47:23 2006 +0000
    17.3 @@ -34,7 +34,7 @@
    17.4  
    17.5  extern void X11_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay);
    17.6  
    17.7 -extern int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect);
    17.8 +extern int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst);
    17.9  
   17.10  extern void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);
   17.11