src/video/SDL_yuv.c
changeset 1643 51038e80ae59
parent 1402 d910939febfa
child 1662 782fd950bd46
child 4076 9a7c62bbc8b3
     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)