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 VALUE_LIMIT   0.001
 
#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
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:157
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
GLfloat angle
GLubyte GLubyte GLubyte GLubyte w
GLenum src
GLfloat GLfloat GLfloat GLfloat h

Definition at line 179 of file SDL_rotate.c.

Referenced by transformSurfaceRGBA90(), and transformSurfaceY90().

§ VALUE_LIMIT

#define VALUE_LIMIT   0.001

Definition at line 82 of file SDL_rotate.c.

Function Documentation

§ _colorkey()

static Uint32 _colorkey ( SDL_Surface src)
static

Definition at line 88 of file SDL_rotate.c.

References SDL_GetColorKey.

Referenced by SDLgfx_rotateSurface(), and transformSurfaceY().

89 {
90  Uint32 key = 0;
91  SDL_GetColorKey(src, &key);
92  return key;
93 }
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
#define SDL_GetColorKey

§ _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 233 of file SDL_rotate.c.

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

Referenced by SDLgfx_rotateSurface().

234 {
235  int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
236  tColorRGBA c00, c01, c10, c11, cswap;
237  tColorRGBA *pc, *sp;
238  int gap;
239 
240  /*
241  * Variable setup
242  */
243  xd = ((src->w - dst->w) << 15);
244  yd = ((src->h - dst->h) << 15);
245  ax = (cx << 16) - (icos * cx);
246  ay = (cy << 16) - (isin * cx);
247  sw = src->w - 1;
248  sh = src->h - 1;
249  pc = (tColorRGBA*) dst->pixels;
250  gap = dst->pitch - dst->w * 4;
251 
252  /*
253  * Switch between interpolating and non-interpolating code
254  */
255  if (smooth) {
256  for (y = 0; y < dst->h; y++) {
257  dy = cy - y;
258  sdx = (ax + (isin * dy)) + xd;
259  sdy = (ay - (icos * dy)) + yd;
260  for (x = 0; x < dst->w; x++) {
261  dx = (sdx >> 16);
262  dy = (sdy >> 16);
263  if (flipx) dx = sw - dx;
264  if (flipy) dy = sh - dy;
265  if ((unsigned)dx < (unsigned)sw && (unsigned)dy < (unsigned)sh) {
266  sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
267  c00 = *sp;
268  sp += 1;
269  c01 = *sp;
270  sp += (src->pitch/4);
271  c11 = *sp;
272  sp -= 1;
273  c10 = *sp;
274  if (flipx) {
275  cswap = c00; c00=c01; c01=cswap;
276  cswap = c10; c10=c11; c11=cswap;
277  }
278  if (flipy) {
279  cswap = c00; c00=c10; c10=cswap;
280  cswap = c01; c01=c11; c11=cswap;
281  }
282  /*
283  * Interpolate colors
284  */
285  ex = (sdx & 0xffff);
286  ey = (sdy & 0xffff);
287  t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
288  t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff;
289  pc->r = (((t2 - t1) * ey) >> 16) + t1;
290  t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff;
291  t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff;
292  pc->g = (((t2 - t1) * ey) >> 16) + t1;
293  t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff;
294  t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff;
295  pc->b = (((t2 - t1) * ey) >> 16) + t1;
296  t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff;
297  t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
298  pc->a = (((t2 - t1) * ey) >> 16) + t1;
299  }
300  sdx += icos;
301  sdy += isin;
302  pc++;
303  }
304  pc = (tColorRGBA *) ((Uint8 *) pc + gap);
305  }
306  } else {
307  for (y = 0; y < dst->h; y++) {
308  dy = cy - y;
309  sdx = (ax + (isin * dy)) + xd;
310  sdy = (ay - (icos * dy)) + yd;
311  for (x = 0; x < dst->w; x++) {
312  dx = (sdx >> 16);
313  dy = (sdy >> 16);
314  if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
315  if(flipx) dx = sw - dx;
316  if(flipy) dy = sh - dy;
317  *pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx);
318  }
319  sdx += icos;
320  sdy += isin;
321  pc++;
322  }
323  pc = (tColorRGBA *) ((Uint8 *) pc + gap);
324  }
325  }
326 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
Uint8 a
Definition: SDL_rotate.c:52
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1567
void * pixels
Definition: SDL_surface.h:75
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
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 157 of file SDL_rotate.c.

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

159 {
160  int pitch = flipy ? -src->pitch : src->pitch;
161  if (flipx) {
162  bpp = -bpp;
163  }
164  switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
165  case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break;
166  case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break;
167  case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break;
168  case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break;
169  }
170  if (flipx) {
171  *signx = -*signx;
172  }
173  if (flipy) {
174  *signy = -*signy;
175  }
176 }
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 414 of file SDL_rotate.c.

References _colorkey(), _transformSurfaceRGBA(), SDL_PixelFormat::Amask, SDL_PixelFormat::BitsPerPixel, blendMode, SDL_PixelFormat::Bmask, SDL_Palette::colors, SDL_Surface::flags, SDL_Surface::format, SDL_PixelFormat::Gmask, GUARD_ROWS, SDL_Surface::h, i, SDL_Palette::ncolors, NULL, SDL_PixelFormat::palette, SDL_PixelFormat::Rmask, SDL_ConvertSurfaceFormat, SDL_CreateRGBSurface, SDL_FillRect, SDL_FreeSurface, SDL_GetRGB, SDL_GetSurfaceAlphaMod, SDL_GetSurfaceBlendMode, SDL_GetSurfaceColorMod, SDL_LockSurface, SDL_MapRGB, SDL_MUSTLOCK, SDL_PIXELFORMAT_ARGB32, SDL_RLEACCEL, SDL_SetColorKey, SDL_SetSurfaceAlphaMod, SDL_SetSurfaceBlendMode, SDL_SetSurfaceColorMod, SDL_SWSURFACE, SDL_TRUE, SDL_UnlockSurface, transformSurfaceRGBA90(), transformSurfaceY(), and transformSurfaceY90().

Referenced by SW_RenderCopyEx().

415 {
416  SDL_Surface *rz_src;
417  SDL_Surface *rz_dst;
418  int is32bit, angle90;
419  int i;
420  Uint8 r = 0, g = 0, b = 0;
421  Uint32 colorkey = 0;
422  int colorKeyAvailable = 0;
423  double sangleinv, cangleinv;
424 
425  /*
426  * Sanity check
427  */
428  if (src == NULL)
429  return (NULL);
430 
431  if (src->flags & SDL_TRUE/* SDL_SRCCOLORKEY */)
432  {
433  colorkey = _colorkey(src);
434  SDL_GetRGB(colorkey, src->format, &r, &g, &b);
435  colorKeyAvailable = 1;
436  }
437  /*
438  * Determine if source surface is 32bit or 8bit
439  */
440  is32bit = (src->format->BitsPerPixel == 32);
441  if ((is32bit) || (src->format->BitsPerPixel == 8)) {
442  /*
443  * Use source surface 'as is'
444  */
445  rz_src = src;
446  } else {
448  if (rz_src == NULL) {
449  return NULL;
450  }
451  is32bit = 1;
452  }
453 
454  /* Determine target size */
455  /* _rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, &dstwidth, &dstheight, &cangle, &sangle); */
456 
457  /*
458  * Calculate target factors from sin/cos and zoom
459  */
460  sangleinv = sangle*65536.0;
461  cangleinv = cangle*65536.0;
462 
463  /*
464  * Alloc space to completely contain the rotated surface
465  */
466  if (is32bit) {
467  /*
468  * Target surface is 32bit with source RGBA/ABGR ordering
469  */
470  rz_dst =
471  SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 32,
472  rz_src->format->Rmask, rz_src->format->Gmask,
473  rz_src->format->Bmask, rz_src->format->Amask);
474  } else {
475  /*
476  * Target surface is 8bit
477  */
478  rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
479  }
480 
481  /* Check target */
482  if (rz_dst == NULL)
483  return NULL;
484 
485  /* Adjust for guard rows */
486  rz_dst->h = dstheight;
487 
488  if (colorKeyAvailable == 1){
489  colorkey = SDL_MapRGB(rz_dst->format, r, g, b);
490 
491  SDL_FillRect(rz_dst, NULL, colorkey );
492  }
493 
494  /*
495  * Lock source surface
496  */
497  if (SDL_MUSTLOCK(rz_src)) {
498  SDL_LockSurface(rz_src);
499  }
500 
501  /* check if the rotation is a multiple of 90 degrees so we can take a fast path and also somewhat reduce
502  * the off-by-one problem in _transformSurfaceRGBA that expresses itself when the rotation is near
503  * multiples of 90 degrees.
504  */
505  angle90 = (int)(angle/90);
506  if (angle90 == angle/90) {
507  angle90 %= 4;
508  if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
509  } else {
510  angle90 = -1;
511  }
512 
513  /*
514  * Check which kind of surface we have
515  */
516  if (is32bit) {
517  /*
518  * Call the 32bit transformation routine to do the rotation (using alpha)
519  */
520  if (angle90 >= 0) {
521  transformSurfaceRGBA90(rz_src, rz_dst, angle90, flipx, flipy);
522  } else {
523  _transformSurfaceRGBA(rz_src, rz_dst, centerx, centery, (int) (sangleinv), (int) (cangleinv), flipx, flipy, smooth);
524  }
525  /*
526  * Turn on source-alpha support
527  */
528  /* SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); */
529  SDL_SetColorKey(rz_dst, /* SDL_SRCCOLORKEY */ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src));
530  } else {
531  /*
532  * Copy palette and colorkey info
533  */
534  for (i = 0; i < rz_src->format->palette->ncolors; i++) {
535  rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
536  }
537  rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
538  /*
539  * Call the 8bit transformation routine to do the rotation
540  */
541  if(angle90 >= 0) {
542  transformSurfaceY90(rz_src, rz_dst, angle90, flipx, flipy);
543  } else {
544  transformSurfaceY(rz_src, rz_dst, centerx, centery, (int)(sangleinv), (int)(cangleinv), flipx, flipy);
545  }
546  SDL_SetColorKey(rz_dst, /* SDL_SRCCOLORKEY */ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src));
547  }
548 
549  /* copy alpha mod, color mod, and blend mode */
550  {
552  Uint8 alphaMod, cr, cg, cb;
553  SDL_GetSurfaceAlphaMod(src, &alphaMod);
554  SDL_GetSurfaceBlendMode(src, &blendMode);
555  SDL_GetSurfaceColorMod(src, &cr, &cg, &cb);
556  SDL_SetSurfaceAlphaMod(rz_dst, alphaMod);
557  SDL_SetSurfaceBlendMode(rz_dst, blendMode);
558  SDL_SetSurfaceColorMod(rz_dst, cr, cg, cb);
559  }
560 
561  /*
562  * Unlock source surface
563  */
564  if (SDL_MUSTLOCK(rz_src)) {
565  SDL_UnlockSurface(rz_src);
566  }
567 
568  /*
569  * Cleanup temp surface
570  */
571  if (rz_src != src) {
572  SDL_FreeSurface(rz_src);
573  }
574 
575  /*
576  * Return destination surface
577  */
578  return (rz_dst);
579 }
#define SDL_GetRGB
#define SDL_ConvertSurfaceFormat
#define SDL_UnlockSurface
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2072
#define SDL_SWSURFACE
Definition: SDL_surface.h:52
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:200
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:159
Uint32 flags
Definition: SDL_surface.h:71
#define SDL_GetSurfaceBlendMode
static SDL_BlendMode blendMode
Definition: testdraw2.c:34
GLboolean GLboolean g
#define SDL_FreeSurface
#define SDL_SetSurfaceColorMod
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:143
Uint8 BitsPerPixel
Definition: SDL_pixels.h:317
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:347
#define SDL_SetColorKey
static void transformSurfaceY90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
Definition: SDL_rotate.c:206
#define SDL_GetSurfaceAlphaMod
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:143
SDL_Color * colors
Definition: SDL_pixels.h:305
SDL_PixelFormat * format
Definition: SDL_surface.h:72
#define SDL_LockSurface
#define SDL_CreateRGBSurface
#define SDL_GetSurfaceColorMod
#define SDL_MUSTLOCK(S)
Definition: SDL_surface.h:61
#define SDL_SetSurfaceBlendMode
#define SDL_FillRect
#define SDL_MapRGB
GLfloat angle
static Uint32 _colorkey(SDL_Surface *src)
Definition: SDL_rotate.c:88
SDL_Palette * palette
Definition: SDL_pixels.h:316
GLenum src
GLboolean GLboolean GLboolean b
#define SDL_SetSurfaceAlphaMod
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
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:233

§ SDLgfx_rotozoomSurfaceSizeTrig()

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

Definition at line 109 of file SDL_rotate.c.

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

Referenced by SW_RenderCopyEx().

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

References TRANSFORM_SURFACE_90.

Referenced by SDLgfx_rotateSurface().

201 {
203 }
#define TRANSFORM_SURFACE_90(pixelType)
Definition: SDL_rotate.c:179

§ 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 347 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().

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

§ transformSurfaceY90()

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

Definition at line 206 of file SDL_rotate.c.

References TRANSFORM_SURFACE_90.

Referenced by SDLgfx_rotateSurface().

207 {
209 }
#define TRANSFORM_SURFACE_90(pixelType)
Definition: SDL_rotate.c:179