SDL  2.0
SDL_rotate.c File Reference
#include "../../SDL_internal.h"
#include <stdlib.h>
#include <string.h>
#include "SDL.h"
#include "SDL_rotate.h"
+ Include dependency graph for SDL_rotate.c:

Go to the source code of this file.

Data Structures

struct  tColorRGBA
 
struct  tColorY
 

Macros

#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
 
#define GUARD_ROWS   (2)
 
#define TRANSFORM_SURFACE_90(pixelType)
 

Functions

static Uint32 _colorkey (SDL_Surface *src)
 
void SDLgfx_rotozoomSurfaceSizeTrig (int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle)
 
static void computeSourceIncrements90 (SDL_Surface *src, int bpp, int angle, int flipx, int flipy, int *sincx, int *sincy, int *signx, int *signy)
 
static void transformSurfaceRGBA90 (SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
 
static void transformSurfaceY90 (SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
 
static void _transformSurfaceRGBA (SDL_Surface *src, SDL_Surface *dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
 
static void transformSurfaceY (SDL_Surface *src, SDL_Surface *dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
 
SDL_SurfaceSDLgfx_rotateSurface (SDL_Surface *src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle)
 

Macro Definition Documentation

◆ GUARD_ROWS

#define GUARD_ROWS   (2)

Definition at line 77 of file SDL_rotate.c.

Referenced by SDLgfx_rotateSurface().

◆ MAX

#define MAX (   a,
  b 
)    (((a) > (b)) ? (a) : (b))

Definition at line 65 of file SDL_rotate.c.

Referenced by SDLgfx_rotozoomSurfaceSizeTrig().

◆ TRANSFORM_SURFACE_90

#define TRANSFORM_SURFACE_90 (   pixelType)
Value:
int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \
Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \
computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \
if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \
if (signy < 0) sp += (src->h-1)*src->pitch; \
\
for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \
if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */ \
SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \
sp += dst->w*sizeof(pixelType); \
dp += dst->w*sizeof(pixelType); \
} else { \
for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
*(pixelType*)dp = *(pixelType*)sp; \
} \
} \
}
GLenum GLenum dst
GLfloat GLfloat GLfloat GLfloat h
static void computeSourceIncrements90(SDL_Surface *src, int bpp, int angle, int flipx, int flipy, int *sincx, int *sincy, int *signx, int *signy)
Definition: SDL_rotate.c:154
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
GLenum src
uint8_t Uint8
Definition: SDL_stdinc.h:179
GLubyte GLubyte GLubyte GLubyte w
GLfloat angle

Definition at line 176 of file SDL_rotate.c.

Referenced by transformSurfaceRGBA90(), and transformSurfaceY90().

Function Documentation

◆ _colorkey()

static Uint32 _colorkey ( SDL_Surface src)
static

Definition at line 83 of file SDL_rotate.c.

References SDL_GetColorKey, and SDL_HasColorKey.

Referenced by transformSurfaceY().

84 {
85  Uint32 key = 0;
86  if (SDL_HasColorKey(src)) {
87  SDL_GetColorKey(src, &key);
88  }
89  return key;
90 }
#define SDL_HasColorKey
GLuint64 key
Definition: gl2ext.h:2192
#define SDL_GetColorKey
uint32_t Uint32
Definition: SDL_stdinc.h:203

◆ _transformSurfaceRGBA()

static void _transformSurfaceRGBA ( SDL_Surface src,
SDL_Surface dst,
int  cx,
int  cy,
int  isin,
int  icos,
int  flipx,
int  flipy,
int  smooth 
)
static

Definition at line 230 of file SDL_rotate.c.

References tColorRGBA::a, tColorRGBA::b, tColorRGBA::g, SDL_Surface::h, if, SDL_Surface::pitch, SDL_Surface::pixels, tColorRGBA::r, and SDL_Surface::w.

Referenced by SDLgfx_rotateSurface().

231 {
232  int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
233  tColorRGBA c00, c01, c10, c11, cswap;
234  tColorRGBA *pc, *sp;
235  int gap;
236 
237  /*
238  * Variable setup
239  */
240  xd = ((src->w - dst->w) << 15);
241  yd = ((src->h - dst->h) << 15);
242  ax = (cx << 16) - (icos * cx);
243  ay = (cy << 16) - (isin * cx);
244  sw = src->w - 1;
245  sh = src->h - 1;
246  pc = (tColorRGBA*) dst->pixels;
247  gap = dst->pitch - dst->w * 4;
248 
249  /*
250  * Switch between interpolating and non-interpolating code
251  */
252  if (smooth) {
253  for (y = 0; y < dst->h; y++) {
254  dy = cy - y;
255  sdx = (ax + (isin * dy)) + xd;
256  sdy = (ay - (icos * dy)) + yd;
257  for (x = 0; x < dst->w; x++) {
258  dx = (sdx >> 16);
259  dy = (sdy >> 16);
260  if (flipx) dx = sw - dx;
261  if (flipy) dy = sh - dy;
262  if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
263  sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
264  c00 = *sp;
265  sp += 1;
266  c01 = *sp;
267  sp += (src->pitch/4);
268  c11 = *sp;
269  sp -= 1;
270  c10 = *sp;
271  if (flipx) {
272  cswap = c00; c00=c01; c01=cswap;
273  cswap = c10; c10=c11; c11=cswap;
274  }
275  if (flipy) {
276  cswap = c00; c00=c10; c10=cswap;
277  cswap = c01; c01=c11; c11=cswap;
278  }
279  /*
280  * Interpolate colors
281  */
282  ex = (sdx & 0xffff);
283  ey = (sdy & 0xffff);
284  t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
285  t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff;
286  pc->r = (((t2 - t1) * ey) >> 16) + t1;
287  t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff;
288  t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff;
289  pc->g = (((t2 - t1) * ey) >> 16) + t1;
290  t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff;
291  t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff;
292  pc->b = (((t2 - t1) * ey) >> 16) + t1;
293  t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff;
294  t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
295  pc->a = (((t2 - t1) * ey) >> 16) + t1;
296  }
297  sdx += icos;
298  sdy += isin;
299  pc++;
300  }
301  pc = (tColorRGBA *) ((Uint8 *) pc + gap);
302  }
303  } else {
304  for (y = 0; y < dst->h; y++) {
305  dy = cy - y;
306  sdx = (ax + (isin * dy)) + xd;
307  sdy = (ay - (icos * dy)) + yd;
308  for (x = 0; x < dst->w; x++) {
309  dx = (sdx >> 16);
310  dy = (sdy >> 16);
311  if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
312  if(flipx) dx = sw - dx;
313  if(flipy) dy = sh - dy;
314  *pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx);
315  }
316  sdx += icos;
317  sdy += isin;
318  pc++;
319  }
320  pc = (tColorRGBA *) ((Uint8 *) pc + gap);
321  }
322  }
323 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
Uint8 a
Definition: SDL_rotate.c:52
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
Definition: SDL_stdinc.h:179
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
Uint8 r
Definition: SDL_rotate.c:49
Uint8 b
Definition: SDL_rotate.c:51
Uint8 g
Definition: SDL_rotate.c:50

◆ computeSourceIncrements90()

static void computeSourceIncrements90 ( SDL_Surface src,
int  bpp,
int  angle,
int  flipx,
int  flipy,
int *  sincx,
int *  sincy,
int *  signx,
int *  signy 
)
static

Definition at line 154 of file SDL_rotate.c.

References bpp, SDL_Surface::h, SDL_Surface::pitch, and SDL_Surface::w.

156 {
157  int pitch = flipy ? -src->pitch : src->pitch;
158  if (flipx) {
159  bpp = -bpp;
160  }
161  switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
162  case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break;
163  case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break;
164  case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break;
165  case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break;
166  }
167  if (flipx) {
168  *signx = -*signx;
169  }
170  if (flipy) {
171  *signy = -*signy;
172  }
173 }
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
GLfloat angle

◆ SDLgfx_rotateSurface()

SDL_Surface* SDLgfx_rotateSurface ( SDL_Surface src,
double  angle,
int  centerx,
int  centery,
int  smooth,
int  flipx,
int  flipy,
int  dstwidth,
int  dstheight,
double  cangle,
double  sangle 
)

Definition at line 415 of file SDL_rotate.c.

References _transformSurfaceRGBA(), SDL_PixelFormat::Amask, SDL_PixelFormat::BitsPerPixel, SDL_PixelFormat::Bmask, SDL_Palette::colors, SDL_Surface::format, SDL_PixelFormat::Gmask, GUARD_ROWS, SDL_Surface::h, i, SDL_Palette::ncolors, NULL, SDL_PixelFormat::palette, SDL_PixelFormat::Rmask, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, SDL_BLENDMODE_NONE, SDL_CreateRGBSurface, SDL_FALSE, SDL_FillRect, SDL_GetColorKey, SDL_GetSurfaceBlendMode, SDL_HasColorKey, SDL_LockSurface, SDL_MapRGBA, SDL_MUSTLOCK, SDL_SetColorKey, SDL_SetSurfaceBlendMode, SDL_TRUE, SDL_UnlockSurface, transformSurfaceRGBA90(), transformSurfaceY(), and transformSurfaceY90().

Referenced by SW_RenderCopyEx().

416 {
417  SDL_Surface *rz_dst;
418  int is8bit, angle90;
419  int i;
420  SDL_BlendMode blendmode;
421  Uint32 colorkey = 0;
422  int colorKeyAvailable = SDL_FALSE;
423  double sangleinv, cangleinv;
424 
425  /* Sanity check */
426  if (src == NULL)
427  return NULL;
428 
429  if (SDL_HasColorKey(src)) {
430  if (SDL_GetColorKey(src, &colorkey) == 0) {
431  colorKeyAvailable = SDL_TRUE;
432  }
433  }
434 
435  /* This function requires a 32-bit surface or 8-bit surface with a colorkey */
436  is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable;
437  if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))
438  return NULL;
439 
440  /* Calculate target factors from sin/cos and zoom */
441  sangleinv = sangle*65536.0;
442  cangleinv = cangle*65536.0;
443 
444  /* Alloc space to completely contain the rotated surface */
445  rz_dst = NULL;
446  if (is8bit) {
447  /* Target surface is 8 bit */
448  rz_dst = SDL_CreateRGBSurface(0, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
449  if (rz_dst != NULL) {
450  for (i = 0; i < src->format->palette->ncolors; i++) {
451  rz_dst->format->palette->colors[i] = src->format->palette->colors[i];
452  }
453  rz_dst->format->palette->ncolors = src->format->palette->ncolors;
454  }
455  } else {
456  /* Target surface is 32 bit with source RGBA ordering */
457  rz_dst = SDL_CreateRGBSurface(0, dstwidth, dstheight + GUARD_ROWS, 32,
458  src->format->Rmask, src->format->Gmask,
459  src->format->Bmask, src->format->Amask);
460  }
461 
462  /* Check target */
463  if (rz_dst == NULL)
464  return NULL;
465 
466  /* Adjust for guard rows */
467  rz_dst->h = dstheight;
468 
469  SDL_GetSurfaceBlendMode(src, &blendmode);
470 
471  if (colorKeyAvailable == SDL_TRUE) {
472  /* If available, the colorkey will be used to discard the pixels that are outside of the rotated area. */
473  SDL_SetColorKey(rz_dst, SDL_TRUE, colorkey);
474  SDL_FillRect(rz_dst, NULL, colorkey);
475  } else if (blendmode == SDL_BLENDMODE_NONE) {
476  blendmode = SDL_BLENDMODE_BLEND;
477  } else if (blendmode == SDL_BLENDMODE_MOD) {
478  /* Without a colorkey, the target texture has to be white for the MOD blend mode so
479  * that the pixels outside the rotated area don't affect the destination surface.
480  */
481  colorkey = SDL_MapRGBA(rz_dst->format, 255, 255, 255, 0);
482  SDL_FillRect(rz_dst, NULL, colorkey);
483  /* Setting a white colorkey for the destination surface makes the final blit discard
484  * all pixels outside of the rotated area. This doesn't interfere with anything because
485  * white pixels are already a no-op and the MOD blend mode does not interact with alpha.
486  */
487  SDL_SetColorKey(rz_dst, SDL_TRUE, colorkey);
488  }
489 
490  SDL_SetSurfaceBlendMode(rz_dst, blendmode);
491 
492  /* Lock source surface */
493  if (SDL_MUSTLOCK(src)) {
494  SDL_LockSurface(src);
495  }
496 
497  /* check if the rotation is a multiple of 90 degrees so we can take a fast path and also somewhat reduce
498  * the off-by-one problem in _transformSurfaceRGBA that expresses itself when the rotation is near
499  * multiples of 90 degrees.
500  */
501  angle90 = (int)(angle/90);
502  if (angle90 == angle/90) {
503  angle90 %= 4;
504  if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
505  } else {
506  angle90 = -1;
507  }
508 
509  if (is8bit) {
510  /* Call the 8-bit transformation routine to do the rotation */
511  if(angle90 >= 0) {
512  transformSurfaceY90(src, rz_dst, angle90, flipx, flipy);
513  } else {
514  transformSurfaceY(src, rz_dst, centerx, centery, (int)sangleinv, (int)cangleinv,
515  flipx, flipy);
516  }
517  } else {
518  /* Call the 32-bit transformation routine to do the rotation */
519  if (angle90 >= 0) {
520  transformSurfaceRGBA90(src, rz_dst, angle90, flipx, flipy);
521  } else {
522  _transformSurfaceRGBA(src, rz_dst, centerx, centery, (int)sangleinv, (int)cangleinv,
523  flipx, flipy, smooth);
524  }
525  }
526 
527  /* Unlock source surface */
528  if (SDL_MUSTLOCK(src)) {
529  SDL_UnlockSurface(src);
530  }
531 
532  /* Return rotated surface */
533  return rz_dst;
534 }
#define SDL_HasColorKey
#define SDL_UnlockSurface
#define SDL_MapRGBA
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:40
#define GUARD_ROWS
Definition: SDL_rotate.c:77
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
static void transformSurfaceRGBA90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
Definition: SDL_rotate.c:197
#define SDL_GetSurfaceBlendMode
#define SDL_GetColorKey
Uint8 BitsPerPixel
Definition: SDL_pixels.h:319
static void transformSurfaceY(SDL_Surface *src, SDL_Surface *dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
Definition: SDL_rotate.c:344
#define SDL_SetColorKey
static void transformSurfaceY90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
Definition: SDL_rotate.c:203
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:164
SDL_Color * colors
Definition: SDL_pixels.h:307
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_LockSurface
#define SDL_CreateRGBSurface
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
#define SDL_SetSurfaceBlendMode
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define SDL_FillRect
GLfloat angle
SDL_Palette * palette
Definition: SDL_pixels.h:318
static void _transformSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
Definition: SDL_rotate.c:230

◆ SDLgfx_rotozoomSurfaceSizeTrig()

void SDLgfx_rotozoomSurfaceSizeTrig ( int  width,
int  height,
double  angle,
int *  dstwidth,
int *  dstheight,
double *  cangle,
double *  sangle 
)

Definition at line 106 of file SDL_rotate.c.

References MAX, SDL_ceil, SDL_cos, SDL_fabs, and SDL_sin.

Referenced by SW_RenderCopyEx().

109 {
110  /* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
111  int angle90 = (int)(angle/90);
112  if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
113  angle90 %= 4;
114  if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
115  if(angle90 & 1) {
116  *dstwidth = height;
117  *dstheight = width;
118  *cangle = 0;
119  *sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */
120  } else {
121  *dstwidth = width;
122  *dstheight = height;
123  *cangle = angle90 == 0 ? 1 : -1;
124  *sangle = 0;
125  }
126  } else {
127  double x, y, cx, cy, sx, sy;
128  double radangle;
129  int dstwidthhalf, dstheighthalf;
130  /*
131  * Determine destination width and height by rotating a centered source box
132  */
133  radangle = angle * (M_PI / -180.0); /* reverse the angle because our rotations are clockwise */
134  *sangle = SDL_sin(radangle);
135  *cangle = SDL_cos(radangle);
136  x = (double)(width / 2);
137  y = (double)(height / 2);
138  cx = *cangle * x;
139  cy = *cangle * y;
140  sx = *sangle * x;
141  sy = *sangle * y;
142 
143  dstwidthhalf = MAX((int)
144  SDL_ceil(MAX(MAX(MAX(SDL_fabs(cx + sy), SDL_fabs(cx - sy)), SDL_fabs(-cx + sy)), SDL_fabs(-cx - sy))), 1);
145  dstheighthalf = MAX((int)
146  SDL_ceil(MAX(MAX(MAX(SDL_fabs(sx + cy), SDL_fabs(sx - cy)), SDL_fabs(-sx + cy)), SDL_fabs(-sx - cy))), 1);
147  *dstwidth = 2 * dstwidthhalf;
148  *dstheight = 2 * dstheighthalf;
149  }
150 }
#define SDL_ceil
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
#define SDL_fabs
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
#define SDL_cos
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
GLfloat angle
#define MAX(a, b)
Definition: SDL_rotate.c:65
#define SDL_sin

◆ transformSurfaceRGBA90()

static void transformSurfaceRGBA90 ( SDL_Surface src,
SDL_Surface dst,
int  angle,
int  flipx,
int  flipy 
)
static

Definition at line 197 of file SDL_rotate.c.

References TRANSFORM_SURFACE_90.

Referenced by SDLgfx_rotateSurface().

198 {
200 }
#define TRANSFORM_SURFACE_90(pixelType)
Definition: SDL_rotate.c:176

◆ transformSurfaceY()

static void transformSurfaceY ( SDL_Surface src,
SDL_Surface dst,
int  cx,
int  cy,
int  isin,
int  icos,
int  flipx,
int  flipy 
)
static

Definition at line 344 of file SDL_rotate.c.

References _colorkey(), SDL_Surface::h, SDL_Surface::pitch, SDL_Surface::pixels, SDL_memset, and SDL_Surface::w.

Referenced by SDLgfx_rotateSurface().

345 {
346  int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay;
347  tColorY *pc;
348  int gap;
349 
350  /*
351  * Variable setup
352  */
353  xd = ((src->w - dst->w) << 15);
354  yd = ((src->h - dst->h) << 15);
355  ax = (cx << 16) - (icos * cx);
356  ay = (cy << 16) - (isin * cx);
357  pc = (tColorY*) dst->pixels;
358  gap = dst->pitch - dst->w;
359  /*
360  * Clear surface to colorkey
361  */
362  SDL_memset(pc, (int)(_colorkey(src) & 0xff), dst->pitch * dst->h);
363  /*
364  * Iterate through destination surface
365  */
366  for (y = 0; y < dst->h; y++) {
367  dy = cy - y;
368  sdx = (ax + (isin * dy)) + xd;
369  sdy = (ay - (icos * dy)) + yd;
370  for (x = 0; x < dst->w; x++) {
371  dx = (sdx >> 16);
372  dy = (sdy >> 16);
373  if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
374  if (flipx) dx = (src->w-1)-dx;
375  if (flipy) dy = (src->h-1)-dy;
376  *pc = *((tColorY *)src->pixels + src->pitch * dy + dx);
377  }
378  sdx += icos;
379  sdy += isin;
380  pc++;
381  }
382  pc += gap;
383  }
384 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
void * pixels
Definition: SDL_surface.h:75
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
static Uint32 _colorkey(SDL_Surface *src)
Definition: SDL_rotate.c:83
#define SDL_memset

◆ transformSurfaceY90()

static void transformSurfaceY90 ( SDL_Surface src,
SDL_Surface dst,
int  angle,
int  flipx,
int  flipy 
)
static

Definition at line 203 of file SDL_rotate.c.

References TRANSFORM_SURFACE_90.

Referenced by SDLgfx_rotateSurface().

204 {
206 }
#define TRANSFORM_SURFACE_90(pixelType)
Definition: SDL_rotate.c:176