comparison src/video/SDL_yuv.c @ 1643:51038e80ae59

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.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 17 Apr 2006 06:47:23 +0000
parents d910939febfa
children 782fd950bd46 9a7c62bbc8b3
comparison
equal deleted inserted replaced
1642:f1211a4b7380 1643:51038e80ae59
73 overlay->hwfuncs->Unlock(current_video, overlay); 73 overlay->hwfuncs->Unlock(current_video, overlay);
74 } 74 }
75 75
76 int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect) 76 int SDL_DisplayYUVOverlay(SDL_Overlay *overlay, SDL_Rect *dstrect)
77 { 77 {
78 return overlay->hwfuncs->Display(current_video, overlay, dstrect); 78 SDL_Rect src, dst;
79 int srcx, srcy, srcw, srch;
80 int dstx, dsty, dstw, dsth;
81
82 /* Clip the rectangle to the screen area */
83 srcx = 0;
84 srcy = 0;
85 srcw = overlay->w;
86 srch = overlay->h;
87 dstx = dstrect->x;
88 dsty = dstrect->y;
89 dstw = dstrect->w;
90 dsth = dstrect->h;
91 if ( dstx < 0 ) {
92 srcw += (dstx * overlay->w) / dstrect->w;
93 dstw += dstx;
94 srcx -= (dstx * overlay->w) / dstrect->w;
95 dstx = 0;
96 }
97 if ( (dstx+dstw) > current_video->screen->w ) {
98 int extra = (dstx+dstw - current_video->screen->w);
99 srcw -= (extra * overlay->w) / dstrect->w;
100 dstw -= extra;
101 }
102 if ( dsty < 0 ) {
103 srch += (dsty * overlay->h) / dstrect->h;
104 dsth += dsty;
105 srcy -= (dsty * overlay->h) / dstrect->h;
106 dsty = 0;
107 }
108 if ( (dsty+dsth) > current_video->screen->h ) {
109 int extra = (dsty+dsth - current_video->screen->h);
110 srch -= (extra * overlay->h) / dstrect->h;
111 dsth -= extra;
112 }
113 if ( srcw <= 0 || srch <= 0 ||
114 srch <= 0 || dsth <= 0 ) {
115 return 0;
116 }
117 /* Ugh, I can't wait for SDL_Rect to be int values */
118 src.x = srcx;
119 src.y = srcy;
120 src.w = srcw;
121 src.h = srch;
122 dst.x = dstx;
123 dst.y = dsty;
124 dst.w = dstw;
125 dst.h = dsth;
126 return overlay->hwfuncs->Display(current_video, overlay, &src, &dst);
79 } 127 }
80 128
81 void SDL_FreeYUVOverlay(SDL_Overlay *overlay) 129 void SDL_FreeYUVOverlay(SDL_Overlay *overlay)
82 { 130 {
83 if ( overlay ) { 131 if ( overlay ) {