src/render/software/SDL_rotate.c
changeset 12311 b19b09eb9e6d
parent 11511 833d4fbb3d76
child 12372 bced4041fcc0
equal deleted inserted replaced
12310:18f3294b230e 12311:b19b09eb9e6d
   148 }
   148 }
   149 
   149 
   150 /* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */
   150 /* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */
   151 static void
   151 static void
   152 computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy,
   152 computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy,
   153                           int *sincx, int *sincy, int *signx, int *signy)
   153                           int *sincx, int *sincy, int *signx, int *signy, SDL_Surface *dst)
   154 {
   154 {
   155     int pitch = flipy ? -src->pitch : src->pitch;
   155     int pitch = flipy ? -src->pitch : src->pitch;
   156     if (flipx) {
   156     if (flipx) {
   157         bpp = -bpp;
   157         bpp = -bpp;
   158     }
   158     }
   159     switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
   159     switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
   160     case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break;
   160     case 0: *sincx = bpp; *sincy = pitch - dst->w * *sincx; *signx = *signy = 1; break;
   161     case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break;
   161     case 1: *sincx = -pitch; *sincy = bpp - *sincx * dst->h; *signx = 1; *signy = -1; break;
   162     case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break;
   162     case 2: *sincx = -bpp; *sincy = -dst->w * *sincx - pitch; *signx = *signy = -1; break;
   163     case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break;
   163     case 3: default: *sincx = pitch; *sincy = -*sincx * dst->h - bpp; *signx = -1; *signy = 1; break;
   164     }
   164     }
   165     if (flipx) {
   165     if (flipx) {
   166         *signx = -*signx;
   166         *signx = -*signx;
   167     }
   167     }
   168     if (flipy) {
   168     if (flipy) {
   173 /* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */
   173 /* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */
   174 #define TRANSFORM_SURFACE_90(pixelType) \
   174 #define TRANSFORM_SURFACE_90(pixelType) \
   175     int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy;                      \
   175     int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy;                      \
   176     Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de;                                        \
   176     Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de;                                        \
   177                                                                                                             \
   177                                                                                                             \
   178     computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \
   178     computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy, dst); \
   179     if (signx < 0) sp += (src->w-1)*sizeof(pixelType);                                                      \
   179     if (signx < 0) sp += (dst->w-1)*sizeof(pixelType);                                                      \
   180     if (signy < 0) sp += (src->h-1)*src->pitch;                                                             \
   180     if (signy < 0) sp += (dst->h-1)*src->pitch;                                                             \
   181                                                                                                             \
       
   182     for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) {                                             \
   181     for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) {                                             \
   183         if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */               \
   182         if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */               \
   184             SDL_memcpy(dp, sp, dst->w*sizeof(pixelType));                                                   \
   183             SDL_memcpy(dp, sp, dst->w*sizeof(pixelType));                                                   \
   185             sp += dst->w*sizeof(pixelType);                                                                 \
   184             sp += dst->w*sizeof(pixelType);                                                                 \
   186             dp += dst->w*sizeof(pixelType);                                                                 \
   185             dp += dst->w*sizeof(pixelType);                                                                 \