src/render/software/SDL_rotate.c
changeset 12372 bced4041fcc0
parent 12311 b19b09eb9e6d
equal deleted inserted replaced
12371:41b93d8303d6 12372:bced4041fcc0
    81 */
    81 */
    82 static Uint32
    82 static Uint32
    83 _colorkey(SDL_Surface *src)
    83 _colorkey(SDL_Surface *src)
    84 {
    84 {
    85     Uint32 key = 0;
    85     Uint32 key = 0;
    86     SDL_GetColorKey(src, &key);
    86     if (SDL_HasColorKey(src)) {
       
    87         SDL_GetColorKey(src, &key);
       
    88     }
    87     return key;
    89     return key;
    88 }
    90 }
    89 
    91 
    90 
    92 
    91 /* !
    93 /* !
   148 }
   150 }
   149 
   151 
   150 /* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */
   152 /* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */
   151 static void
   153 static void
   152 computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy,
   154 computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy,
   153                           int *sincx, int *sincy, int *signx, int *signy, SDL_Surface *dst)
   155                           int *sincx, int *sincy, int *signx, int *signy)
   154 {
   156 {
   155     int pitch = flipy ? -src->pitch : src->pitch;
   157     int pitch = flipy ? -src->pitch : src->pitch;
   156     if (flipx) {
   158     if (flipx) {
   157         bpp = -bpp;
   159         bpp = -bpp;
   158     }
   160     }
   159     switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
   161     switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
   160     case 0: *sincx = bpp; *sincy = pitch - dst->w * *sincx; *signx = *signy = 1; break;
   162     case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break;
   161     case 1: *sincx = -pitch; *sincy = bpp - *sincx * dst->h; *signx = 1; *signy = -1; break;
   163     case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break;
   162     case 2: *sincx = -bpp; *sincy = -dst->w * *sincx - pitch; *signx = *signy = -1; break;
   164     case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break;
   163     case 3: default: *sincx = pitch; *sincy = -*sincx * dst->h - bpp; *signx = -1; *signy = 1; break;
   165     case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break;
   164     }
   166     }
   165     if (flipx) {
   167     if (flipx) {
   166         *signx = -*signx;
   168         *signx = -*signx;
   167     }
   169     }
   168     if (flipy) {
   170     if (flipy) {
   173 /* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */
   175 /* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */
   174 #define TRANSFORM_SURFACE_90(pixelType) \
   176 #define TRANSFORM_SURFACE_90(pixelType) \
   175     int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy;                      \
   177     int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy;                      \
   176     Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de;                                        \
   178     Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de;                                        \
   177                                                                                                             \
   179                                                                                                             \
   178     computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy, dst); \
   180     computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \
   179     if (signx < 0) sp += (dst->w-1)*sizeof(pixelType);                                                      \
   181     if (signx < 0) sp += (src->w-1)*sizeof(pixelType);                                                      \
   180     if (signy < 0) sp += (dst->h-1)*src->pitch;                                                             \
   182     if (signy < 0) sp += (src->h-1)*src->pitch;                                                             \
       
   183                                                                                                             \
   181     for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) {                                             \
   184     for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) {                                             \
   182         if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */               \
   185         if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */               \
   183             SDL_memcpy(dp, sp, dst->w*sizeof(pixelType));                                                   \
   186             SDL_memcpy(dp, sp, dst->w*sizeof(pixelType));                                                   \
   184             sp += dst->w*sizeof(pixelType);                                                                 \
   187             sp += dst->w*sizeof(pixelType);                                                                 \
   185             dp += dst->w*sizeof(pixelType);                                                                 \
   188             dp += dst->w*sizeof(pixelType);                                                                 \
   421 
   424 
   422     /* Sanity check */
   425     /* Sanity check */
   423     if (src == NULL)
   426     if (src == NULL)
   424         return NULL;
   427         return NULL;
   425 
   428 
   426     if (SDL_GetColorKey(src, &colorkey) == 0) {
   429     if (SDL_HasColorKey(src)) {
   427         colorKeyAvailable = SDL_TRUE;
   430         if (SDL_GetColorKey(src, &colorkey) == 0) {
       
   431             colorKeyAvailable = SDL_TRUE;
       
   432         }
   428     }
   433     }
   429 
   434 
   430     /* This function requires a 32-bit surface or 8-bit surface with a colorkey */
   435     /* This function requires a 32-bit surface or 8-bit surface with a colorkey */
   431     is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable;
   436     is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable;
   432     if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))
   437     if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))