comparison src/video/SDL_yuv_sw.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 5f52867ba65c
children 8a858076f39d
comparison
equal deleted inserted replaced
1642:f1211a4b7380 1643:51038e80ae59
1162 void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay) 1162 void SDL_UnlockYUV_SW(_THIS, SDL_Overlay *overlay)
1163 { 1163 {
1164 return; 1164 return;
1165 } 1165 }
1166 1166
1167 int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) 1167 int SDL_DisplayYUV_SW(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst)
1168 { 1168 {
1169 struct private_yuvhwdata *swdata; 1169 struct private_yuvhwdata *swdata;
1170 SDL_Surface *stretch; 1170 int stretch;
1171 int scale_2x;
1171 SDL_Surface *display; 1172 SDL_Surface *display;
1172 int scale_2x;
1173 Uint8 *lum, *Cr, *Cb; 1173 Uint8 *lum, *Cr, *Cb;
1174 Uint8 *dst; 1174 Uint8 *dstp;
1175 int mod; 1175 int mod;
1176 1176
1177 swdata = overlay->hwdata; 1177 swdata = overlay->hwdata;
1178 stretch = 0;
1178 scale_2x = 0; 1179 scale_2x = 0;
1179 stretch = 0; 1180 if ( src->x || src->y || src->w < overlay->w || src->h < overlay->h ) {
1180 if ( (overlay->w != dstrect->w) || (overlay->h != dstrect->h) ) { 1181 stretch = 1;
1181 if ( (dstrect->w == 2*overlay->w) && 1182 } else if ( (src->w != dst->w) || (src->h != dst->h) ) {
1182 (dstrect->h == 2*overlay->h) ) { 1183 if ( (dst->w == 2*src->w) &&
1184 (dst->h == 2*src->h) ) {
1183 scale_2x = 1; 1185 scale_2x = 1;
1184 } else { 1186 } else {
1187 stretch = 1;
1188 }
1189 }
1190 if ( stretch ) {
1191 if ( ! swdata->stretch ) {
1192 display = swdata->display;
1193 swdata->stretch = SDL_CreateRGBSurface(
1194 SDL_SWSURFACE,
1195 overlay->w, overlay->h,
1196 display->format->BitsPerPixel,
1197 display->format->Rmask,
1198 display->format->Gmask,
1199 display->format->Bmask, 0);
1185 if ( ! swdata->stretch ) { 1200 if ( ! swdata->stretch ) {
1186 display = swdata->display; 1201 return(-1);
1187 swdata->stretch = SDL_CreateRGBSurface(
1188 SDL_SWSURFACE,
1189 overlay->w, overlay->h,
1190 display->format->BitsPerPixel,
1191 display->format->Rmask,
1192 display->format->Gmask,
1193 display->format->Bmask, 0);
1194 if ( ! swdata->stretch ) {
1195 return(-1);
1196 }
1197 } 1202 }
1198 stretch = swdata->stretch; 1203 }
1199 } 1204 display = swdata->stretch;
1200 }
1201
1202 if ( stretch ) {
1203 display = stretch;
1204 } else { 1205 } else {
1205 display = swdata->display; 1206 display = swdata->display;
1206 } 1207 }
1207 switch (overlay->format) { 1208 switch (overlay->format) {
1208 case SDL_YV12_OVERLAY: 1209 case SDL_YV12_OVERLAY:
1238 if ( SDL_LockSurface(display) < 0 ) { 1239 if ( SDL_LockSurface(display) < 0 ) {
1239 return(-1); 1240 return(-1);
1240 } 1241 }
1241 } 1242 }
1242 if ( stretch ) { 1243 if ( stretch ) {
1243 dst = (Uint8 *)stretch->pixels; 1244 dstp = (Uint8 *)swdata->stretch->pixels;
1244 } else { 1245 } else {
1245 dst = (Uint8 *)display->pixels 1246 dstp = (Uint8 *)display->pixels
1246 + dstrect->x * display->format->BytesPerPixel 1247 + dst->x * display->format->BytesPerPixel
1247 + dstrect->y * display->pitch; 1248 + dst->y * display->pitch;
1248 } 1249 }
1249 mod = (display->pitch / display->format->BytesPerPixel); 1250 mod = (display->pitch / display->format->BytesPerPixel);
1250 1251
1251 if ( scale_2x ) { 1252 if ( scale_2x ) {
1252 mod -= (overlay->w * 2); 1253 mod -= (overlay->w * 2);
1253 swdata->Display2X(swdata->colortab, swdata->rgb_2_pix, 1254 swdata->Display2X(swdata->colortab, swdata->rgb_2_pix,
1254 lum, Cr, Cb, dst, overlay->h, overlay->w,mod); 1255 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
1255 } else { 1256 } else {
1256 mod -= overlay->w; 1257 mod -= overlay->w;
1257 swdata->Display1X(swdata->colortab, swdata->rgb_2_pix, 1258 swdata->Display1X(swdata->colortab, swdata->rgb_2_pix,
1258 lum, Cr, Cb, dst, overlay->h, overlay->w,mod); 1259 lum, Cr, Cb, dstp, overlay->h, overlay->w, mod);
1259 } 1260 }
1260 if ( SDL_MUSTLOCK(display) ) { 1261 if ( SDL_MUSTLOCK(display) ) {
1261 SDL_UnlockSurface(display); 1262 SDL_UnlockSurface(display);
1262 } 1263 }
1263 if ( stretch ) { 1264 if ( stretch ) {
1264 display = swdata->display; 1265 display = swdata->display;
1265 SDL_SoftStretch(stretch, NULL, display, dstrect); 1266 SDL_SoftStretch(swdata->stretch, src, display, dst);
1266 } 1267 }
1267 SDL_UpdateRects(display, 1, dstrect); 1268 SDL_UpdateRects(display, 1, dst);
1268 1269
1269 return(0); 1270 return(0);
1270 } 1271 }
1271 1272
1272 void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay) 1273 void SDL_FreeYUV_SW(_THIS, SDL_Overlay *overlay)