Software scaling support. Not very fast, but it seems to work.
1.1 --- a/include/SDL_surface.h Mon Feb 14 00:45:16 2011 -0800
1.2 +++ b/include/SDL_surface.h Mon Feb 14 11:50:18 2011 -0600
1.3 @@ -464,6 +464,17 @@
1.4 SDL_Surface * dst,
1.5 const SDL_Rect * dstrect);
1.6
1.7 +/**
1.8 + * \brief Perform a fast, low quality, stretch blit between two surfaces of the
1.9 + * different pixel formats.
1.10 + *
1.11 + * \note This function calls SDL_SoftStretch or SDL_LowerBlit.
1.12 + */
1.13 +extern DECLSPEC int SDLCALL SDL_BlitScaled
1.14 + (SDL_Surface * src, const SDL_Rect * srcrect,
1.15 + SDL_Surface * dst, const SDL_Rect * dstrect);
1.16 +
1.17 +
1.18 /* Ends C function definitions when using C++ */
1.19 #ifdef __cplusplus
1.20 /* *INDENT-OFF* */
2.1 --- a/src/render/software/SDL_render_sw.c Mon Feb 14 00:45:16 2011 -0800
2.2 +++ b/src/render/software/SDL_render_sw.c Mon Feb 14 11:50:18 2011 -0600
2.3 @@ -364,7 +364,12 @@
2.4 if (!surface) {
2.5 return -1;
2.6 }
2.7 - return SDL_BlitSurface(src, srcrect, surface, &final_rect);
2.8 +
2.9 + if ( srcrect->w == final_rect.w && srcrect->h == final_rect.h ) {
2.10 + return SDL_BlitSurface(src, srcrect, surface, &final_rect);
2.11 + } else {
2.12 + return SDL_BlitScaled(src, srcrect, surface, &final_rect);
2.13 + }
2.14 }
2.15
2.16 static int
3.1 --- a/src/video/SDL_surface.c Mon Feb 14 00:45:16 2011 -0800
3.2 +++ b/src/video/SDL_surface.c Mon Feb 14 11:50:18 2011 -0600
3.3 @@ -640,6 +640,51 @@
3.4 }
3.5
3.6 /*
3.7 + * Scale and blit a surface
3.8 +*/
3.9 +int
3.10 +SDL_BlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
3.11 + SDL_Surface * dst, const SDL_Rect * dstrect)
3.12 +{
3.13 + /* Save off the original dst width, height */
3.14 + int dstW = dstrect->w;
3.15 + int dstH = dstrect->h;
3.16 + SDL_Rect final_dst = *dstrect;
3.17 + SDL_Rect final_src = *srcrect;
3.18 +
3.19 + /* Clip the dst surface to the dstrect */
3.20 + SDL_SetClipRect( dst, &final_dst );
3.21 +
3.22 + /* If the dest was clipped to a zero sized rect then exit */
3.23 + if ( dst->clip_rect.w <= 0 || dst->clip_rect.h <= 0 ) {
3.24 + return -1;
3.25 + }
3.26 +
3.27 + /* Did the dst width change? */
3.28 + if ( dstW != dst->clip_rect.w ) {
3.29 + /* scale the src width appropriately */
3.30 + final_src.w = final_src.w * dst->clip_rect.w / dstW;
3.31 + }
3.32 +
3.33 + /* Did the dst height change? */
3.34 + if ( dstH != dst->clip_rect.h ) {
3.35 + /* scale the src width appropriately */
3.36 + final_src.h = final_src.h * dst->clip_rect.h / dstH;
3.37 + }
3.38 +
3.39 + /* Clip the src surface to the srcrect */
3.40 + SDL_SetClipRect( src, &final_src );
3.41 +
3.42 + src->map->info.flags |= SDL_COPY_NEAREST;
3.43 +
3.44 + if ( src->format->format == dst->format->format && !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
3.45 + return SDL_SoftStretch( src, &final_src, dst, &final_dst );
3.46 + } else {
3.47 + return SDL_LowerBlit( src, &final_src, dst, &final_dst );
3.48 + }
3.49 +}
3.50 +
3.51 +/*
3.52 * Lock a surface to directly access the pixels
3.53 */
3.54 int