comparison src/video/SDL_stretch.c @ 894:1d1a823904d8

Don't crash if the stretch routines are used on hardware surfaces
author Sam Lantinga <slouken@libsdl.org>
date Sun, 16 May 2004 21:08:55 +0000
parents b8d311d90021
children 10b3fb28c86b
comparison
equal deleted inserted replaced
893:8762a202f121 894:1d1a823904d8
179 NOTE: This function is not safe to call from multiple threads! 179 NOTE: This function is not safe to call from multiple threads!
180 */ 180 */
181 int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, 181 int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect,
182 SDL_Surface *dst, SDL_Rect *dstrect) 182 SDL_Surface *dst, SDL_Rect *dstrect)
183 { 183 {
184 int src_locked;
185 int dst_locked;
184 int pos, inc; 186 int pos, inc;
185 int dst_width; 187 int dst_width;
186 int dst_maxrow; 188 int dst_maxrow;
187 int src_row, dst_row; 189 int src_row, dst_row;
188 Uint8 *srcp = NULL; 190 Uint8 *srcp = NULL;
227 full_dst.w = dst->w; 229 full_dst.w = dst->w;
228 full_dst.h = dst->h; 230 full_dst.h = dst->h;
229 dstrect = &full_dst; 231 dstrect = &full_dst;
230 } 232 }
231 233
234 /* Lock the destination if it's in hardware */
235 dst_locked = 0;
236 if ( SDL_MUSTLOCK(dst) ) {
237 if ( SDL_LockSurface(dst) < 0 ) {
238 SDL_SetError("Unable to lock destination surface");
239 return(-1);
240 }
241 dst_locked = 1;
242 }
243 /* Lock the source if it's in hardware */
244 src_locked = 0;
245 if ( SDL_MUSTLOCK(src) ) {
246 if ( SDL_LockSurface(src) < 0 ) {
247 if ( dst_locked ) {
248 SDL_UnlockSurface(dst);
249 }
250 SDL_SetError("Unable to lock source surface");
251 return(-1);
252 }
253 src_locked = 1;
254 }
255
232 /* Set up the data... */ 256 /* Set up the data... */
233 pos = 0x10000; 257 pos = 0x10000;
234 inc = (srcrect->h << 16) / dstrect->h; 258 inc = (srcrect->h << 16) / dstrect->h;
235 src_row = srcrect->y; 259 src_row = srcrect->y;
236 dst_row = dstrect->y; 260 dst_row = dstrect->y;
305 break; 329 break;
306 } 330 }
307 #endif 331 #endif
308 pos += inc; 332 pos += inc;
309 } 333 }
334
335 /* We need to unlock the surfaces if they're locked */
336 if ( dst_locked ) {
337 SDL_UnlockSurface(dst);
338 }
339 if ( src_locked ) {
340 SDL_UnlockSurface(src);
341 }
310 return(0); 342 return(0);
311 } 343 }
312 344