31 #include "../../SDL_internal.h"
33 #if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
35 #if defined(__WIN32__)
36 #include "../../core/windows/SDL_windows.h"
67 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
79 #define GUARD_ROWS (2)
109 int *dstwidth,
int *dstheight,
110 double *cangle,
double *sangle)
113 int angle90 = (int)(
angle/90);
114 if(angle90 ==
angle/90) {
116 if(angle90 < 0) angle90 += 4;
121 *sangle = angle90 == 1 ? -1 : 1;
125 *cangle = angle90 == 0 ? 1 : -1;
129 double x,
y, cx, cy, sx, sy;
131 int dstwidthhalf, dstheighthalf;
135 radangle =
angle * (M_PI / -180.0);
145 dstwidthhalf =
MAX((
int)
147 dstheighthalf =
MAX((
int)
149 *dstwidth = 2 * dstwidthhalf;
150 *dstheight = 2 * dstheighthalf;
157 int *sincx,
int *sincy,
int *signx,
int *signy)
159 int pitch = flipy ? -
src->pitch :
src->pitch;
164 case 0: *sincx =
bpp; *sincy = pitch -
src->w * *sincx; *signx = *signy = 1;
break;
165 case 1: *sincx = -pitch; *sincy =
bpp - *sincx *
src->h; *signx = 1; *signy = -1;
break;
166 case 2: *sincx = -
bpp; *sincy = -
src->w * *sincx - pitch; *signx = *signy = -1;
break;
167 case 3:
default: *sincx = pitch; *sincy = -*sincx *
src->h -
bpp; *signx = -1; *signy = 1;
break;
178 #define TRANSFORM_SURFACE_90(pixelType) \
179 int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \
180 Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \
182 computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \
183 if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \
184 if (signy < 0) sp += (src->h-1)*src->pitch; \
186 for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \
187 if (sincx == sizeof(pixelType)) { \
188 SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \
189 sp += dst->w*sizeof(pixelType); \
190 dp += dst->w*sizeof(pixelType); \
192 for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
193 *(pixelType*)dp = *(pixelType*)sp; \
210 #undef TRANSFORM_SURFACE_90
234 int x,
y,
t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
242 xd = ((
src->w -
dst->w) << 15);
243 yd = ((
src->h -
dst->h) << 15);
244 ax = (cx << 16) - (icos * cx);
245 ay = (cy << 16) - (isin * cx);
249 gap =
dst->pitch -
dst->w * 4;
255 for (
y = 0;
y <
dst->h;
y++) {
257 sdx = (ax + (isin * dy)) + xd;
258 sdy = (ay - (icos * dy)) + yd;
259 for (
x = 0;
x <
dst->w;
x++) {
262 if (flipx) dx = sw - dx;
263 if (flipy) dy = sh - dy;
264 if ((dx > -1) && (dy > -1) && (dx < (
src->w-1)) && (dy < (
src->h-1))) {
269 sp += (
src->pitch/4);
274 cswap = c00; c00=c01; c01=cswap;
275 cswap = c10; c10=c11; c11=cswap;
278 cswap = c00; c00=c10; c10=cswap;
279 cswap = c01; c01=c11; c11=cswap;
286 t1 = ((((c01.
r - c00.
r) * ex) >> 16) + c00.
r) & 0xff;
287 t2 = ((((c11.
r - c10.
r) * ex) >> 16) + c10.
r) & 0xff;
288 pc->
r = (((t2 -
t1) * ey) >> 16) +
t1;
289 t1 = ((((c01.
g - c00.
g) * ex) >> 16) + c00.
g) & 0xff;
290 t2 = ((((c11.
g - c10.
g) * ex) >> 16) + c10.
g) & 0xff;
291 pc->
g = (((t2 -
t1) * ey) >> 16) +
t1;
292 t1 = ((((c01.
b - c00.
b) * ex) >> 16) + c00.
b) & 0xff;
293 t2 = ((((c11.
b - c10.
b) * ex) >> 16) + c10.
b) & 0xff;
294 pc->
b = (((t2 -
t1) * ey) >> 16) +
t1;
295 t1 = ((((c01.
a - c00.
a) * ex) >> 16) + c00.
a) & 0xff;
296 t2 = ((((c11.
a - c10.
a) * ex) >> 16) + c10.
a) & 0xff;
297 pc->
a = (((t2 -
t1) * ey) >> 16) +
t1;
306 for (
y = 0;
y <
dst->h;
y++) {
308 sdx = (ax + (isin * dy)) + xd;
309 sdy = (ay - (icos * dy)) + yd;
310 for (
x = 0;
x <
dst->w;
x++) {
313 if ((
unsigned)dx < (unsigned)
src->w && (
unsigned)dy < (unsigned)
src->h) {
314 if(flipx) dx = sw - dx;
315 if(flipy) dy = sh - dy;
348 int x,
y, dx, dy, xd, yd, sdx, sdy, ax, ay;
355 xd = ((
src->w -
dst->w) << 15);
356 yd = ((
src->h -
dst->h) << 15);
357 ax = (cx << 16) - (icos * cx);
358 ay = (cy << 16) - (isin * cx);
360 gap =
dst->pitch -
dst->w;
368 for (
y = 0;
y <
dst->h;
y++) {
370 sdx = (ax + (isin * dy)) + xd;
371 sdy = (ay - (icos * dy)) + yd;
372 for (
x = 0;
x <
dst->w;
x++) {
375 if ((
unsigned)dx < (unsigned)
src->w && (
unsigned)dy < (unsigned)
src->h) {
376 if (flipx) dx = (
src->w-1)-dx;
377 if (flipy) dy = (
src->h-1)-dy;
417 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)
425 double sangleinv, cangleinv;
438 is8bit =
src->format->BitsPerPixel == 8 && colorKeyAvailable;
439 if (!(is8bit || (
src->format->BitsPerPixel == 32 &&
src->format->Amask)))
443 sangleinv = sangle*65536.0;
444 cangleinv = cangle*65536.0;
451 if (rz_dst !=
NULL) {
452 for (
i = 0;
i <
src->format->palette->ncolors;
i++) {
460 src->format->Rmask,
src->format->Gmask,
461 src->format->Bmask,
src->format->Amask);
469 rz_dst->
h = dstheight;
473 if (colorKeyAvailable ==
SDL_TRUE) {
503 angle90 = (int)(
angle/90);
504 if (angle90 ==
angle/90) {
506 if (angle90 < 0) angle90 += 4;
525 flipx, flipy, smooth);