31 #include "../../SDL_internal.h" 33 #if defined(__WIN32__) 34 #include "../../core/windows/SDL_windows.h" 65 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 77 #define GUARD_ROWS (2) 82 #define VALUE_LIMIT 0.001 110 int *dstwidth,
int *dstheight,
111 double *cangle,
double *sangle)
114 int angle90 = (int)(angle/90);
115 if(angle90 == angle/90) {
117 if(angle90 < 0) angle90 += 4;
122 *sangle = angle90 == 1 ? -1 : 1;
126 *cangle = angle90 == 0 ? 1 : -1;
130 double x,
y, cx, cy, sx, sy;
132 int dstwidthhalf, dstheighthalf;
136 radangle = angle * (M_PI / -180.0);
139 x = (double)(width / 2);
140 y = (double)(height / 2);
146 dstwidthhalf =
MAX((
int)
148 dstheighthalf =
MAX((
int)
150 *dstwidth = 2 * dstwidthhalf;
151 *dstheight = 2 * dstheighthalf;
158 int *sincx,
int *sincy,
int *signx,
int *signy)
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;
179 #define TRANSFORM_SURFACE_90(pixelType) \ 180 int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \ 181 Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \ 183 computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \ 184 if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \ 185 if (signy < 0) sp += (src->h-1)*src->pitch; \ 187 for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \ 188 if (sincx == sizeof(pixelType)) { \ 189 SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \ 190 sp += dst->w*sizeof(pixelType); \ 191 dp += dst->w*sizeof(pixelType); \ 193 for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \ 194 *(pixelType*)dp = *(pixelType*)sp; \ 211 #undef TRANSFORM_SURFACE_90 235 int x,
y,
t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
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);
250 gap = dst->
pitch - dst->
w * 4;
256 for (y = 0; y < dst->
h; y++) {
258 sdx = (ax + (isin * dy)) + xd;
259 sdy = (ay - (icos * dy)) + yd;
260 for (x = 0; x < dst->
w; x++) {
263 if (flipx) dx = sw - dx;
264 if (flipy) dy = sh - dy;
265 if ((
unsigned)dx < (unsigned)sw && (
unsigned)dy < (unsigned)sh) {
270 sp += (src->
pitch/4);
275 cswap = c00; c00=c01; c01=cswap;
276 cswap = c10; c10=c11; c11=cswap;
279 cswap = c00; c00=c10; c10=cswap;
280 cswap = c01; c01=c11; c11=cswap;
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;
307 for (y = 0; y < dst->
h; y++) {
309 sdx = (ax + (isin * dy)) + xd;
310 sdy = (ay - (icos * dy)) + yd;
311 for (x = 0; x < dst->
w; x++) {
314 if ((
unsigned)dx < (unsigned)src->
w && (
unsigned)dy < (unsigned)src->
h) {
315 if(flipx) dx = sw - dx;
316 if(flipy) dy = sh - dy;
349 int x,
y, dx, dy, xd, yd, sdx, sdy, ax, ay;
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);
361 gap = dst->
pitch - dst->
w;
369 for (y = 0; y < dst->
h; y++) {
371 sdx = (ax + (isin * dy)) + xd;
372 sdy = (ay - (icos * dy)) + yd;
373 for (x = 0; x < dst->
w; x++) {
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;
414 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)
418 int is32bit, angle90;
422 int colorKeyAvailable = 0;
423 double sangleinv, cangleinv;
435 colorKeyAvailable = 1;
448 if (rz_src ==
NULL) {
460 sangleinv = sangle*65536.0;
461 cangleinv = cangle*65536.0;
486 rz_dst->
h = dstheight;
488 if (colorKeyAvailable == 1){
505 angle90 = (int)(angle/90);
506 if (angle90 == angle/90) {
508 if (angle90 < 0) angle90 += 4;
523 _transformSurfaceRGBA(rz_src, rz_dst, centerx, centery, (
int) (sangleinv), (
int) (cangleinv), flipx, flipy, smooth);
544 transformSurfaceY(rz_src, rz_dst, centerx, centery, (
int)(sangleinv), (
int)(cangleinv), flipx, flipy);
552 Uint8 alphaMod, cr, cg, cb;
#define SDL_ConvertSurfaceFormat
#define SDL_UnlockSurface
GLdouble GLdouble GLdouble r
GLint GLint GLsizei width
GLint GLint GLint GLint GLint x
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
static void computeSourceIncrements90(SDL_Surface *src, int bpp, int angle, int flipx, int flipy, int *sincx, int *sincy, int *signx, int *signy)
A collection of pixels used in software blitting.
static void transformSurfaceRGBA90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
uint32_t Uint32
An unsigned 32-bit integer type.
GLint GLint GLsizei GLsizei height
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
#define SDL_GetSurfaceBlendMode
static SDL_BlendMode blendMode
GLint GLint GLint GLint GLint GLint y
#define SDL_SetSurfaceColorMod
uint8_t Uint8
An unsigned 8-bit integer type.
static void transformSurfaceY(SDL_Surface *src, SDL_Surface *dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
static void transformSurfaceY90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
#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)
#define TRANSFORM_SURFACE_90(pixelType)
#define SDL_CreateRGBSurface
#define SDL_GetSurfaceColorMod
#define SDL_SetSurfaceBlendMode
static Uint32 _colorkey(SDL_Surface *src)
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)
GLboolean GLboolean GLboolean b
void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle)
#define SDL_SetSurfaceAlphaMod
static void _transformSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)