From c451350b6583fa20598993b2b659058d677ad647 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 17 Apr 2006 06:47:23 +0000 Subject: [PATCH] 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 | 50 ++++++++++++++++++++- src/video/SDL_yuv_sw.c | 65 ++++++++++++++------------- src/video/SDL_yuv_sw_c.h | 2 +- src/video/SDL_yuvfuncs.h | 2 +- src/video/bwindow/SDL_sysyuv.cc | 8 ++-- src/video/bwindow/SDL_sysyuv.h | 2 +- src/video/directfb/SDL_DirectFB_yuv.c | 2 +- src/video/directfb/SDL_DirectFB_yuv.h | 2 +- src/video/photon/SDL_ph_events.c | 32 ++++++++----- src/video/photon/SDL_phyuv.c | 24 +++++----- src/video/photon/SDL_phyuv_c.h | 2 +- src/video/ps2gs/SDL_gsyuv.c | 10 ++--- src/video/ps2gs/SDL_gsyuv_c.h | 2 +- src/video/windx5/SDL_dx5yuv.c | 26 +++++------ src/video/windx5/SDL_dx5yuv_c.h | 2 +- src/video/x11/SDL_x11yuv.c | 46 +++---------------- src/video/x11/SDL_x11yuv_c.h | 2 +- 17 files changed, 150 insertions(+), 129 deletions(-) diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c index 7c023598a..396b7c0f5 100644 --- a/src/video/SDL_yuv.c +++ b/src/video/SDL_yuv.c @@ -75,7 +75,55 @@ void SDL_UnlockYUVOverlay(SDL_Overlay *overlay) int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect) { - return overlay->hwfuncs->Display(current_video, overlay, dstrect); + SDL_Rect src, dst; + int srcx, srcy, srcw, srch; + int dstx, dsty, dstw, dsth; + + /* Clip the rectangle to the screen area */ + srcx = 0; + srcy = 0; + srcw = overlay->w; + srch = overlay->h; + dstx = dstrect->x; + dsty = dstrect->y; + dstw = dstrect->w; + dsth = dstrect->h; + if ( dstx < 0 ) { + srcw += (dstx * overlay->w) / dstrect->w; + dstw += dstx; + srcx -= (dstx * overlay->w) / dstrect->w; + dstx = 0; + } + if ( (dstx+dstw) > current_video->screen->w ) { + int extra = (dstx+dstw - current_video->screen->w); + srcw -= (extra * overlay->w) / dstrect->w; + dstw -= extra; + } + if ( dsty < 0 ) { + srch += (dsty * overlay->h) / dstrect->h; + dsth += dsty; + srcy -= (dsty * overlay->h) / dstrect->h; + dsty = 0; + } + if ( (dsty+dsth) > current_video->screen->h ) { + int extra = (dsty+dsth - current_video->screen->h); + srch -= (extra * overlay->h) / dstrect->h; + dsth -= extra; + } + if ( srcw <= 0 || srch <= 0 || + srch <= 0 || dsth <= 0 ) { + return 0; + } + /* Ugh, I can't wait for SDL_Rect to be int values */ + src.x = srcx; + src.y = srcy; + src.w = srcw; + src.h = srch; + dst.x = dstx; + dst.y = dsty; + dst.w = dstw; + dst.h = dsth; + return overlay->hwfuncs->Display(current_video, overlay, &src, &dst); } void SDL_FreeYUVOverlay(SDL_Overlay *overlay) diff --git a/src/video/SDL_yuv_sw.c b/src/video/SDL_yuv_sw.c index 8bb1cce71..625c2d997 100644 --- a/src/video/SDL_yuv_sw.c +++ b/src/video/SDL_yuv_sw.c @@ -1164,43 +1164,44 @@ void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay) return; } -int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) +int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) { struct private_yuvhwdata *swdata; - SDL_Surface *stretch; - SDL_Surface *display; + int stretch; int scale_2x; + SDL_Surface *display; Uint8 *lum, *Cr, *Cb; - Uint8 *dst; + Uint8 *dstp; int mod; swdata = overlay->hwdata; - scale_2x = 0; stretch = 0; - if ( (overlay->w != dstrect->w) || (overlay->h != dstrect->h) ) { - if ( (dstrect->w == 2*overlay->w) && - (dstrect->h == 2*overlay->h) ) { + scale_2x = 0; + if ( src->x || src->y || src->w < overlay->w || src->h < overlay->h ) { + stretch = 1; + } else if ( (src->w != dst->w) || (src->h != dst->h) ) { + if ( (dst->w == 2*src->w) && + (dst->h == 2*src->h) ) { scale_2x = 1; } else { - if ( ! swdata->stretch ) { - display = swdata->display; - swdata->stretch = SDL_CreateRGBSurface( - SDL_SWSURFACE, - overlay->w, overlay->h, - display->format->BitsPerPixel, - display->format->Rmask, - display->format->Gmask, - display->format->Bmask, 0); - if ( ! swdata->stretch ) { - return(-1); - } - } - stretch = swdata->stretch; + stretch = 1; } } - if ( stretch ) { - display = stretch; + if ( ! swdata->stretch ) { + display = swdata->display; + swdata->stretch = SDL_CreateRGBSurface( + SDL_SWSURFACE, + overlay->w, overlay->h, + display->format->BitsPerPixel, + display->format->Rmask, + display->format->Gmask, + display->format->Bmask, 0); + if ( ! swdata->stretch ) { + return(-1); + } + } + display = swdata->stretch; } else { display = swdata->display; } @@ -1240,31 +1241,31 @@ int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) } } if ( stretch ) { - dst = (Uint8 *)stretch->pixels; + dstp = (Uint8 *)swdata->stretch->pixels; } else { - dst = (Uint8 *)display->pixels - + dstrect->x * display->format->BytesPerPixel - + dstrect->y * display->pitch; + dstp = (Uint8 *)display->pixels + + dst->x * display->format->BytesPerPixel + + dst->y * display->pitch; } mod = (display->pitch / display->format->BytesPerPixel); if ( scale_2x ) { mod -= (overlay->w * 2); swdata->Display2X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, dst, overlay->h, overlay->w,mod); + lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); } else { mod -= overlay->w; swdata->Display1X(swdata->colortab, swdata->rgb_2_pix, - lum, Cr, Cb, dst, overlay->h, overlay->w,mod); + lum, Cr, Cb, dstp, overlay->h, overlay->w, mod); } if ( SDL_MUSTLOCK(display) ) { SDL_UnlockSurface(display); } if ( stretch ) { display = swdata->display; - SDL_SoftStretch(stretch, NULL, display, dstrect); + SDL_SoftStretch(swdata->stretch, src, display, dst); } - SDL_UpdateRects(display, 1, dstrect); + SDL_UpdateRects(display, 1, dst); return(0); } diff --git a/src/video/SDL_yuv_sw_c.h b/src/video/SDL_yuv_sw_c.h index 327acccd0..39df51d7f 100644 --- a/src/video/SDL_yuv_sw_c.h +++ b/src/video/SDL_yuv_sw_c.h @@ -32,6 +32,6 @@ extern int SDL_LockYUV_SW(_THIS, SDL_Overlay *overlay); extern void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay); -extern int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect); +extern int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst); extern void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay); diff --git a/src/video/SDL_yuvfuncs.h b/src/video/SDL_yuvfuncs.h index 173909f59..a48af3f0d 100644 --- a/src/video/SDL_yuvfuncs.h +++ b/src/video/SDL_yuvfuncs.h @@ -32,6 +32,6 @@ struct private_yuvhwfuncs { int (*Lock)(_THIS, SDL_Overlay *overlay); void (*Unlock)(_THIS, SDL_Overlay *overlay); - int (*Display)(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect); + int (*Display)(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst); void (*FreeHW)(_THIS, SDL_Overlay *overlay); }; diff --git a/src/video/bwindow/SDL_sysyuv.cc b/src/video/bwindow/SDL_sysyuv.cc index 537f89a90..557a120ed 100644 --- a/src/video/bwindow/SDL_sysyuv.cc +++ b/src/video/bwindow/SDL_sysyuv.cc @@ -263,7 +263,7 @@ void BE_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay) overlay->hwdata->locked = 0; } -int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect) +int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect *dst) { if ((overlay == NULL) || (overlay->hwdata==NULL) || (overlay->hwdata->bview==NULL) || (SDL_Win->View() == NULL)) @@ -277,11 +277,11 @@ int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect) if (SDL_Win->IsFullScreen()) { int left,top; SDL_Win->GetXYOffset(left,top); - bview->MoveTo(left+dstrect->x,top+dstrect->y); + bview->MoveTo(left+dst->x,top+dst->y); } else { - bview->MoveTo(dstrect->x,dstrect->y); + bview->MoveTo(dst->x,dst->y); } - bview->ResizeTo(dstrect->w,dstrect->h); + bview->ResizeTo(dst->w,dst->h); bview->Flush(); if (overlay->hwdata->first_display) { bview->Show(); diff --git a/src/video/bwindow/SDL_sysyuv.h b/src/video/bwindow/SDL_sysyuv.h index fa96f2ca2..64859f2fe 100644 --- a/src/video/bwindow/SDL_sysyuv.h +++ b/src/video/bwindow/SDL_sysyuv.h @@ -65,7 +65,7 @@ extern BBitmap * BE_GetOverlayBitmap(BRect bounds, color_space cs); extern SDL_Overlay* BE_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display); extern int BE_LockYUVOverlay(_THIS, SDL_Overlay* overlay); extern void BE_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay); -extern int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect); +extern int BE_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst); extern void BE_FreeYUVOverlay(_THIS, SDL_Overlay* overlay); }; diff --git a/src/video/directfb/SDL_DirectFB_yuv.c b/src/video/directfb/SDL_DirectFB_yuv.c index 9aa30758f..a116eecff 100644 --- a/src/video/directfb/SDL_DirectFB_yuv.c +++ b/src/video/directfb/SDL_DirectFB_yuv.c @@ -241,7 +241,7 @@ void DirectFB_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) surface->Unlock (surface); } -int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dst) +int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) { DFBResult ret; DFBDisplayLayerConfig conf; diff --git a/src/video/directfb/SDL_DirectFB_yuv.h b/src/video/directfb/SDL_DirectFB_yuv.h index dd2b974e7..23a42dc2b 100644 --- a/src/video/directfb/SDL_DirectFB_yuv.h +++ b/src/video/directfb/SDL_DirectFB_yuv.h @@ -32,7 +32,7 @@ extern int DirectFB_LockYUVOverlay(_THIS, SDL_Overlay *overlay); extern void DirectFB_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay); -extern int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect); +extern int DirectFB_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst); extern void DirectFB_FreeYUVOverlay(_THIS, SDL_Overlay *overlay); diff --git a/src/video/photon/SDL_ph_events.c b/src/video/photon/SDL_ph_events.c index 163dfc8a9..47405b743 100644 --- a/src/video/photon/SDL_ph_events.c +++ b/src/video/photon/SDL_ph_events.c @@ -245,15 +245,19 @@ static int ph_DispatchEvent(_THIS) int lockedstate=current_overlay->hwdata->locked; int chromastate=current_overlay->hwdata->ischromakey; int error; - SDL_Rect target; + SDL_Rect src, dst; current_overlay->hwdata->locked=1; - target.x=current_overlay->hwdata->CurrentViewPort.pos.x; - target.y=current_overlay->hwdata->CurrentViewPort.pos.y; - target.w=current_overlay->hwdata->CurrentViewPort.size.w; - target.h=current_overlay->hwdata->CurrentViewPort.size.h; + src.x = 0; + src.y = 0; + src.w = current_overlay->w; + src.y = current_overlay->h; + dst.x=current_overlay->hwdata->CurrentViewPort.pos.x; + dst.y=current_overlay->hwdata->CurrentViewPort.pos.y; + dst.w=current_overlay->hwdata->CurrentViewPort.size.w; + dst.h=current_overlay->hwdata->CurrentViewPort.size.h; current_overlay->hwdata->ischromakey=0; - error=ph_DisplayYUVOverlay(this, current_overlay, &target); + error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst); if (!error) { current_overlay->hwdata->ischromakey=chromastate; @@ -306,15 +310,19 @@ static int ph_DispatchEvent(_THIS) { int lockedstate=current_overlay->hwdata->locked; int error; - SDL_Rect target; + SDL_Rect src, dst; current_overlay->hwdata->locked=1; - target.x=current_overlay->hwdata->CurrentViewPort.pos.x; - target.y=current_overlay->hwdata->CurrentViewPort.pos.y; - target.w=current_overlay->hwdata->CurrentViewPort.size.w; - target.h=current_overlay->hwdata->CurrentViewPort.size.h; + src.x = 0; + src.y = 0; + src.w = current_overlay->w; + src.y = current_overlay->h; + dst.x=current_overlay->hwdata->CurrentViewPort.pos.x; + dst.y=current_overlay->hwdata->CurrentViewPort.pos.y; + dst.w=current_overlay->hwdata->CurrentViewPort.size.w; + dst.h=current_overlay->hwdata->CurrentViewPort.size.h; current_overlay->hwdata->forcedredraw=1; - error=ph_DisplayYUVOverlay(this, current_overlay, &target); + error=ph_DisplayYUVOverlay(this, current_overlay, &src, &dst); if (!error) { current_overlay->hwdata->forcedredraw=0; diff --git a/src/video/photon/SDL_phyuv.c b/src/video/photon/SDL_phyuv.c index 35a4bd4ec..62ec04147 100644 --- a/src/video/photon/SDL_phyuv.c +++ b/src/video/photon/SDL_phyuv.c @@ -334,7 +334,7 @@ void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay) overlay->hwdata->locked = 0; } -int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect) +int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst) { int rtncode; PhPoint_t pos; @@ -362,10 +362,10 @@ int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect) } /* If CurrentViewPort position/size has been changed, then move/resize the viewport */ - if ((overlay->hwdata->CurrentViewPort.pos.x != dstrect->x) || - (overlay->hwdata->CurrentViewPort.pos.y != dstrect->y) || - (overlay->hwdata->CurrentViewPort.size.w != dstrect->w) || - (overlay->hwdata->CurrentViewPort.size.h != dstrect->h) || + if ((overlay->hwdata->CurrentViewPort.pos.x != dst->x) || + (overlay->hwdata->CurrentViewPort.pos.y != dst->y) || + (overlay->hwdata->CurrentViewPort.size.w != dst->w) || + (overlay->hwdata->CurrentViewPort.size.h != dst->h) || (overlay->hwdata->scaler_on==0) || (winchanged==1) || (overlay->hwdata->forcedredraw==1)) { @@ -381,7 +381,7 @@ int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect) /* Draw the new rectangle of the chroma color at the viewport position */ PgSetFillColor(overlay->hwdata->chromakey); - PgDrawIRect(dstrect->x, dstrect->y, dstrect->x+dstrect->w-1, dstrect->y+dstrect->h-1, Pg_DRAW_FILL); + PgDrawIRect(dst->x, dst->y, dst->x+dst->w-1, dst->y+dst->h-1, Pg_DRAW_FILL); PgFlush(); } @@ -389,13 +389,13 @@ int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect) overlay->hwdata->scaler_on = 1; PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, PtWidgetRid(window), &windowextent); - overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dstrect->x; - overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dstrect->y; - overlay->hwdata->CurrentViewPort.size.w = dstrect->w; - overlay->hwdata->CurrentViewPort.size.h = dstrect->h; + overlay->hwdata->CurrentViewPort.pos.x = pos.x-windowextent.ul.x+dst->x; + overlay->hwdata->CurrentViewPort.pos.y = pos.y-windowextent.ul.y+dst->y; + overlay->hwdata->CurrentViewPort.size.w = dst->w; + overlay->hwdata->CurrentViewPort.size.h = dst->h; PhAreaToRect(&overlay->hwdata->CurrentViewPort, &overlay->hwdata->props.viewport); - overlay->hwdata->CurrentViewPort.pos.x = dstrect->x; - overlay->hwdata->CurrentViewPort.pos.y = dstrect->y; + overlay->hwdata->CurrentViewPort.pos.x = dst->x; + overlay->hwdata->CurrentViewPort.pos.y = dst->y; rtncode = PgConfigScalerChannel(overlay->hwdata->channel, &(overlay->hwdata->props)); diff --git a/src/video/photon/SDL_phyuv_c.h b/src/video/photon/SDL_phyuv_c.h index e889eee8f..a004a03e2 100644 --- a/src/video/photon/SDL_phyuv_c.h +++ b/src/video/photon/SDL_phyuv_c.h @@ -56,7 +56,7 @@ struct private_yuvhwdata extern SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface* display); extern int ph_LockYUVOverlay(_THIS, SDL_Overlay* overlay); extern void ph_UnlockYUVOverlay(_THIS, SDL_Overlay* overlay); -extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* dstrect); +extern int ph_DisplayYUVOverlay(_THIS, SDL_Overlay* overlay, SDL_Rect* src, SDL_Rect* dst); extern void ph_FreeYUVOverlay(_THIS, SDL_Overlay* overlay); #endif /* __SDL_PH_YUV_H__ */ diff --git a/src/video/ps2gs/SDL_gsyuv.c b/src/video/ps2gs/SDL_gsyuv.c index 0750fd2f1..0d33dde10 100644 --- a/src/video/ps2gs/SDL_gsyuv.c +++ b/src/video/ps2gs/SDL_gsyuv.c @@ -315,7 +315,7 @@ void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) return; } -int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) +int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) { struct private_yuvhwdata *hwdata; __u32 cmd; @@ -423,8 +423,8 @@ int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) /* Send the current image to the screen and scale it */ screen = this->screen; - x = (unsigned int)dstrect->x; - y = (unsigned int)dstrect->y; + x = (unsigned int)dst->x; + y = (unsigned int)dst->y; if ( screen->offset ) { x += (screen->offset % screen->pitch) / screen->format->BytesPerPixel; @@ -432,8 +432,8 @@ int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) } y += screen_image.y; *hwdata->stretch_x1y1 = (x * 16) + ((y * 16) << 16); - x += (unsigned int)dstrect->w; - y += (unsigned int)dstrect->h; + x += (unsigned int)dst->w; + y += (unsigned int)dst->h; *hwdata->stretch_x2y2 = (x * 16) + ((y * 16) << 16); return ioctl(console_fd, PS2IOC_SENDL, &hwdata->plist); } diff --git a/src/video/ps2gs/SDL_gsyuv_c.h b/src/video/ps2gs/SDL_gsyuv_c.h index 9adeb6318..970e05436 100644 --- a/src/video/ps2gs/SDL_gsyuv_c.h +++ b/src/video/ps2gs/SDL_gsyuv_c.h @@ -32,6 +32,6 @@ extern int GS_LockYUVOverlay(_THIS, SDL_Overlay *overlay); extern void GS_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay); -extern int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect); +extern int GS_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst); extern void GS_FreeYUVOverlay(_THIS, SDL_Overlay *overlay); diff --git a/src/video/windx5/SDL_dx5yuv.c b/src/video/windx5/SDL_dx5yuv.c index e250cd628..2457dacd8 100644 --- a/src/video/windx5/SDL_dx5yuv.c +++ b/src/video/windx5/SDL_dx5yuv.c @@ -247,30 +247,30 @@ void DX5_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) IDirectDrawSurface3_Unlock(surface, NULL); } -int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) +int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) { HRESULT result; LPDIRECTDRAWSURFACE3 surface; - RECT src, dst; + RECT srcrect, dstrect; surface = overlay->hwdata->surface; - src.top = 0; - src.bottom = overlay->h; - src.left = 0; - src.right = overlay->w; - dst.top = SDL_bounds.top+dstrect->y; - dst.left = SDL_bounds.left+dstrect->x; - dst.bottom = dst.top+dstrect->h; - dst.right = dst.left+dstrect->w; + srcrect.top = src->y; + srcrect.bottom = srcrect.top+src->h; + srcrect.left = src->x; + srcrect.right = srcrect.left+src->w; + dstrect.top = SDL_bounds.top+dst->y; + dstrect.left = SDL_bounds.left+dst->x; + dstrect.bottom = dstrect.top+dst->h; + dstrect.right = dstrect.left+dst->w; #ifdef USE_DIRECTX_OVERLAY - result = IDirectDrawSurface3_UpdateOverlay(surface, &src, - SDL_primary, &dst, DDOVER_SHOW, NULL); + result = IDirectDrawSurface3_UpdateOverlay(surface, &srcrect, + SDL_primary, &dstrect, DDOVER_SHOW, NULL); if ( result != DD_OK ) { SetDDerror("DirectDrawSurface3::UpdateOverlay", result); return(-1); } #else - result = IDirectDrawSurface3_Blt(SDL_primary, &dst, surface, &src, + result = IDirectDrawSurface3_Blt(SDL_primary, &dstrect, surface, &srcrect, DDBLT_WAIT, NULL); if ( result != DD_OK ) { SetDDerror("DirectDrawSurface3::Blt", result); diff --git a/src/video/windx5/SDL_dx5yuv_c.h b/src/video/windx5/SDL_dx5yuv_c.h index faf5507a4..c6afb68c1 100644 --- a/src/video/windx5/SDL_dx5yuv_c.h +++ b/src/video/windx5/SDL_dx5yuv_c.h @@ -33,6 +33,6 @@ extern int DX5_LockYUVOverlay(_THIS, SDL_Overlay *overlay); extern void DX5_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay); -extern int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect); +extern int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst); extern void DX5_FreeYUVOverlay(_THIS, SDL_Overlay *overlay); diff --git a/src/video/x11/SDL_x11yuv.c b/src/video/x11/SDL_x11yuv.c index 30953874b..63cf10b86 100644 --- a/src/video/x11/SDL_x11yuv.c +++ b/src/video/x11/SDL_x11yuv.c @@ -354,62 +354,26 @@ void X11_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) return; } -int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) +int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) { struct private_yuvhwdata *hwdata; - int srcx, srcy, srcw, srch; - int dstx, dsty, dstw, dsth; hwdata = overlay->hwdata; - /* Clip the rectangle to the screen area */ - srcx = 0; - srcy = 0; - srcw = overlay->w; - srch = overlay->h; - dstx = dstrect->x; - dsty = dstrect->y; - dstw = dstrect->w; - dsth = dstrect->h; - if ( dstx < 0 ) { - srcw += (dstx * overlay->w) / dstrect->w; - dstw += dstx; - srcx -= (dstx * overlay->w) / dstrect->w; - dstx = 0; - } - if ( (dstx+dstw) > this->screen->w ) { - int extra = (dstx+dstw - this->screen->w); - srcw -= (extra * overlay->w) / dstrect->w; - dstw -= extra; - } - if ( dsty < 0 ) { - srch += (dsty * overlay->h) / dstrect->h; - dsth += dsty; - srcy -= (dsty * overlay->h) / dstrect->h; - dsty = 0; - } - if ( (dsty+dsth) > this->screen->h ) { - int extra = (dsty+dsth - this->screen->h); - srch -= (extra * overlay->h) / dstrect->h; - dsth -= extra; - } - if ( srcw <= 0 || srch <= 0 || - srch <= 0 || dsth <= 0 ) { - return; - } - #ifndef NO_SHARED_MEMORY if ( hwdata->yuv_use_mitshm ) { SDL_NAME(XvShmPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC, hwdata->image, - srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth, False); + src->x, src->y, src->w, src->h, + dst->x, dst->y, dst->w, dst->h, False); } else #endif { SDL_NAME(XvPutImage)(GFX_Display, hwdata->port, SDL_Window, SDL_GC, hwdata->image, - srcx, srcy, srcw, srch, dstx, dsty, dstw, dsth); + src->x, src->y, src->w, src->h, + dst->x, dst->y, dst->w, dst->h); } XSync(GFX_Display, False); return(0); diff --git a/src/video/x11/SDL_x11yuv_c.h b/src/video/x11/SDL_x11yuv_c.h index 734644042..78f8750d9 100644 --- a/src/video/x11/SDL_x11yuv_c.h +++ b/src/video/x11/SDL_x11yuv_c.h @@ -34,7 +34,7 @@ extern int X11_LockYUVOverlay(_THIS, SDL_Overlay *overlay); extern void X11_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay); -extern int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect); +extern int X11_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst); extern void X11_FreeYUVOverlay(_THIS, SDL_Overlay *overlay);