src/video/SDL_surface.c
changeset 5296 48067bfc300c
parent 5288 d4381f3b0d1e
child 5375 16877f74123c
     1.1 --- a/src/video/SDL_surface.c	Mon Feb 14 00:45:16 2011 -0800
     1.2 +++ b/src/video/SDL_surface.c	Mon Feb 14 11:50:18 2011 -0600
     1.3 @@ -640,6 +640,51 @@
     1.4  }
     1.5  
     1.6  /*
     1.7 + * Scale and blit a surface 
     1.8 +*/
     1.9 +int
    1.10 +SDL_BlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
    1.11 +               SDL_Surface * dst, const SDL_Rect * dstrect)
    1.12 +{
    1.13 +    /* Save off the original dst width, height */
    1.14 +    int dstW = dstrect->w;
    1.15 +    int dstH = dstrect->h;
    1.16 +    SDL_Rect final_dst = *dstrect;
    1.17 +    SDL_Rect final_src = *srcrect;
    1.18 +
    1.19 +    /* Clip the dst surface to the dstrect */
    1.20 +    SDL_SetClipRect( dst, &final_dst );
    1.21 +
    1.22 +    /* If the dest was clipped to a zero sized rect then exit */
    1.23 +    if ( dst->clip_rect.w <= 0 || dst->clip_rect.h <= 0 ) {
    1.24 +        return -1;
    1.25 +    }
    1.26 +
    1.27 +    /* Did the dst width change? */
    1.28 +    if ( dstW != dst->clip_rect.w ) {
    1.29 +        /* scale the src width appropriately */
    1.30 +        final_src.w = final_src.w * dst->clip_rect.w / dstW;
    1.31 +    }
    1.32 +
    1.33 +    /* Did the dst height change? */
    1.34 +    if ( dstH != dst->clip_rect.h ) {
    1.35 +        /* scale the src width appropriately */
    1.36 +        final_src.h = final_src.h * dst->clip_rect.h / dstH;
    1.37 +    }
    1.38 +
    1.39 +    /* Clip the src surface to the srcrect */
    1.40 +    SDL_SetClipRect( src, &final_src );
    1.41 +
    1.42 +    src->map->info.flags |= SDL_COPY_NEAREST;
    1.43 +
    1.44 +    if ( src->format->format == dst->format->format && !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
    1.45 +        return SDL_SoftStretch( src, &final_src, dst, &final_dst );
    1.46 +    } else {
    1.47 +        return SDL_LowerBlit( src, &final_src, dst, &final_dst );
    1.48 +    }
    1.49 +}
    1.50 +
    1.51 +/*
    1.52   * Lock a surface to directly access the pixels
    1.53   */
    1.54  int