src/render/software/SDL_rotate.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 23 Jun 2015 01:44:44 -0400
changeset 9775 8bd9e4e20d99
parent 9763 c2ba8ab27c1a
permissions -rw-r--r--
Fixed compiler warning about shadowed local variables.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     1
/*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     2
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     3
SDL_rotate.c: rotates 32bit or 8bit surfaces
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     4
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     5
Shamelessly stolen from SDL_gfx by Andreas Schiffler. Original copyright follows:
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     6
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     7
Copyright (C) 2001-2011  Andreas Schiffler
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     8
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
     9
This software is provided 'as-is', without any express or implied
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    10
warranty. In no event will the authors be held liable for any damages
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    11
arising from the use of this software.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    12
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    13
Permission is granted to anyone to use this software for any purpose,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    14
including commercial applications, and to alter it and redistribute it
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    15
freely, subject to the following restrictions:
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    16
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    17
   1. The origin of this software must not be misrepresented; you must not
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    18
   claim that you wrote the original software. If you use this software
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    19
   in a product, an acknowledgment in the product documentation would be
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    20
   appreciated but is not required.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    21
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    22
   2. Altered source versions must be plainly marked as such, and must not be
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    23
   misrepresented as being the original software.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    24
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    25
   3. This notice may not be removed or altered from any source
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    26
   distribution.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    27
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    28
Andreas Schiffler -- aschiffler at ferzkopp dot net
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    29
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    30
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7859
diff changeset
    31
#include "../../SDL_internal.h"
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    32
7828
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
    33
#if defined(__WIN32__)
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7678
diff changeset
    34
#include "../../core/windows/SDL_windows.h"
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    35
#endif
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    36
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    37
#include <stdlib.h>
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    38
#include <string.h>
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    39
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    40
#include "SDL.h"
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    41
#include "SDL_rotate.h"
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    42
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    43
/* ---- Internally used structures */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    44
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    45
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    46
\brief A 32 bit RGBA pixel.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    47
*/
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    48
typedef struct tColorRGBA {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    49
    Uint8 r;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    50
    Uint8 g;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    51
    Uint8 b;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    52
    Uint8 a;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    53
} tColorRGBA;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    54
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    55
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    56
\brief A 8bit Y/palette pixel.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    57
*/
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    58
typedef struct tColorY {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    59
    Uint8 y;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    60
} tColorY;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    61
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    62
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    63
\brief Returns maximum of two numbers a and b.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    64
*/
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    65
#define MAX(a,b)    (((a) > (b)) ? (a) : (b))
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    66
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    67
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    68
\brief Number of guard rows added to destination surfaces.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    69
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    70
This is a simple but effective workaround for observed issues.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    71
These rows allocate extra memory and are then hidden from the surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    72
Rows are added to the end of destination surfaces when they are allocated.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    73
This catches any potential overflows which seem to happen with
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    74
just the right src image dimensions and scale/rotation and can lead
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    75
to a situation where the program can segfault.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    76
*/
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    77
#define GUARD_ROWS (2)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    78
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    79
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    80
\brief Lower limit of absolute zoom factor or rotation degrees.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    81
*/
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    82
#define VALUE_LIMIT 0.001
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    83
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    84
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    85
\brief Returns colorkey info for a surface
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    86
*/
7859
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
    87
static Uint32
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
    88
_colorkey(SDL_Surface *src)
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    89
{
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    90
    Uint32 key = 0;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    91
    SDL_GetColorKey(src, &key);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    92
    return key;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    93
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    94
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    95
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
    96
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    97
\brief Internal target surface sizing function for rotations with trig result return.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    98
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
    99
\param width The source surface width.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   100
\param height The source surface height.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   101
\param angle The angle to rotate in degrees.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   102
\param dstwidth The calculated width of the destination surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   103
\param dstheight The calculated height of the destination surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   104
\param cangle The sine of the angle
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   105
\param sangle The cosine of the angle
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   106
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   107
*/
7859
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   108
void
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   109
SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle,
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   110
                               int *dstwidth, int *dstheight,
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   111
                               double *cangle, double *sangle)
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   112
{
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   113
    double x, y, cx, cy, sx, sy;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   114
    double radangle;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   115
    int dstwidthhalf, dstheighthalf;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   116
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   117
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   118
    * Determine destination width and height by rotating a centered source box
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   119
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   120
    radangle = angle * (M_PI / 180.0);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   121
    *sangle = SDL_sin(radangle);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   122
    *cangle = SDL_cos(radangle);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   123
    x = (double)(width / 2);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   124
    y = (double)(height / 2);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   125
    cx = *cangle * x;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   126
    cy = *cangle * y;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   127
    sx = *sangle * x;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   128
    sy = *sangle * y;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   129
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   130
    dstwidthhalf = MAX((int)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   131
        SDL_ceil(MAX(MAX(MAX(SDL_fabs(cx + sy), SDL_fabs(cx - sy)), SDL_fabs(-cx + sy)), SDL_fabs(-cx - sy))), 1);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   132
    dstheighthalf = MAX((int)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   133
        SDL_ceil(MAX(MAX(MAX(SDL_fabs(sx + cy), SDL_fabs(sx - cy)), SDL_fabs(-sx + cy)), SDL_fabs(-sx - cy))), 1);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   134
    *dstwidth = 2 * dstwidthhalf;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   135
    *dstheight = 2 * dstheighthalf;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   136
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   137
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   138
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   139
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   140
\brief Internal 32 bit rotozoomer with optional anti-aliasing.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   141
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   142
Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   143
parameters by scanning the destination surface and applying optionally anti-aliasing
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   144
by bilinear interpolation.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   145
Assumes src and dst surfaces are of 32 bit depth.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   146
Assumes dst surface was allocated with the correct dimensions.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   147
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   148
\param src Source surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   149
\param dst Destination surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   150
\param cx Horizontal center coordinate.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   151
\param cy Vertical center coordinate.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   152
\param isin Integer version of sine of angle.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   153
\param icos Integer version of cosine of angle.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   154
\param flipx Flag indicating horizontal mirroring should be applied.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   155
\param flipy Flag indicating vertical mirroring should be applied.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   156
\param smooth Flag indicating anti-aliasing should be used.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   157
*/
7859
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   158
static void
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   159
_transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   160
{
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   161
    int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   162
    tColorRGBA c00, c01, c10, c11, cswap;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   163
    tColorRGBA *pc, *sp;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   164
    int gap;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   165
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   166
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   167
    * Variable setup
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   168
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   169
    xd = ((src->w - dst->w) << 15);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   170
    yd = ((src->h - dst->h) << 15);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   171
    ax = (cx << 16) - (icos * cx);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   172
    ay = (cy << 16) - (isin * cx);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   173
    sw = src->w - 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   174
    sh = src->h - 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   175
    pc = (tColorRGBA*) dst->pixels;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   176
    gap = dst->pitch - dst->w * 4;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   177
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   178
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   179
    * Switch between interpolating and non-interpolating code
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   180
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   181
    if (smooth) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   182
        for (y = 0; y < dst->h; y++) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   183
            dy = cy - y;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   184
            sdx = (ax + (isin * dy)) + xd;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   185
            sdy = (ay - (icos * dy)) + yd;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   186
            for (x = 0; x < dst->w; x++) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   187
                dx = (sdx >> 16);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   188
                dy = (sdy >> 16);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   189
                if (flipx) dx = sw - dx;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   190
                if (flipy) dy = sh - dy;
9762
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   191
                if ((unsigned)dx < (unsigned)sw && (unsigned)dy < (unsigned)sh) {
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   192
                    sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   193
                    c00 = *sp;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   194
                    sp += 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   195
                    c01 = *sp;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   196
                    sp += (src->pitch/4);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   197
                    c11 = *sp;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   198
                    sp -= 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   199
                    c10 = *sp;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   200
                    if (flipx) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   201
                        cswap = c00; c00=c01; c01=cswap;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   202
                        cswap = c10; c10=c11; c11=cswap;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   203
                    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   204
                    if (flipy) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   205
                        cswap = c00; c00=c10; c10=cswap;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   206
                        cswap = c01; c01=c11; c11=cswap;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   207
                    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   208
                    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   209
                    * Interpolate colors
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   210
                    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   211
                    ex = (sdx & 0xffff);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   212
                    ey = (sdy & 0xffff);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   213
                    t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   214
                    t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   215
                    pc->r = (((t2 - t1) * ey) >> 16) + t1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   216
                    t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   217
                    t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   218
                    pc->g = (((t2 - t1) * ey) >> 16) + t1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   219
                    t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   220
                    t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   221
                    pc->b = (((t2 - t1) * ey) >> 16) + t1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   222
                    t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   223
                    t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   224
                    pc->a = (((t2 - t1) * ey) >> 16) + t1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   225
                }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   226
                sdx += icos;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   227
                sdy += isin;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   228
                pc++;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   229
            }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   230
            pc = (tColorRGBA *) ((Uint8 *) pc + gap);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   231
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   232
    } else {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   233
        for (y = 0; y < dst->h; y++) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   234
            dy = cy - y;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   235
            sdx = (ax + (isin * dy)) + xd;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   236
            sdy = (ay - (icos * dy)) + yd;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   237
            for (x = 0; x < dst->w; x++) {
9762
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   238
                dx = (sdx >> 16);
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   239
                dy = (sdy >> 16);
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   240
                if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   241
                    if(flipx) dx = sw - dx;
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   242
                    if(flipy) dy = sh - dy;
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   243
                    *pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   244
                }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   245
                sdx += icos;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   246
                sdy += isin;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   247
                pc++;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   248
            }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   249
            pc = (tColorRGBA *) ((Uint8 *) pc + gap);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   250
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   251
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   252
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   253
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   254
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   255
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   256
\brief Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   257
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   258
Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   259
parameters by scanning the destination surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   260
Assumes src and dst surfaces are of 8 bit depth.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   261
Assumes dst surface was allocated with the correct dimensions.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   262
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   263
\param src Source surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   264
\param dst Destination surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   265
\param cx Horizontal center coordinate.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   266
\param cy Vertical center coordinate.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   267
\param isin Integer version of sine of angle.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   268
\param icos Integer version of cosine of angle.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   269
\param flipx Flag indicating horizontal mirroring should be applied.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   270
\param flipy Flag indicating vertical mirroring should be applied.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   271
*/
7859
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   272
static void
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   273
transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   274
{
6389
43a190ad60a7 Removed some unused variables that gcc 4.6.1 complains about.
Ryan C. Gordon <icculus@icculus.org>
parents: 6323
diff changeset
   275
    int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay;
9762
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   276
    tColorY *pc;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   277
    int gap;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   278
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   279
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   280
    * Variable setup
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   281
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   282
    xd = ((src->w - dst->w) << 15);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   283
    yd = ((src->h - dst->h) << 15);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   284
    ax = (cx << 16) - (icos * cx);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   285
    ay = (cy << 16) - (isin * cx);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   286
    pc = (tColorY*) dst->pixels;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   287
    gap = dst->pitch - dst->w;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   288
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   289
    * Clear surface to colorkey
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   290
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   291
    SDL_memset(pc, (int)(_colorkey(src) & 0xff), dst->pitch * dst->h);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   292
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   293
    * Iterate through destination surface
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   294
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   295
    for (y = 0; y < dst->h; y++) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   296
        dy = cy - y;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   297
        sdx = (ax + (isin * dy)) + xd;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   298
        sdy = (ay - (icos * dy)) + yd;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   299
        for (x = 0; x < dst->w; x++) {
9762
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   300
            dx = (sdx >> 16);
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   301
            dy = (sdy >> 16);
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   302
            if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   303
                if (flipx) dx = (src->w-1)-dx;
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   304
                if (flipy) dy = (src->h-1)-dy;
5c4a85c5b648 Fixed bug 1550 - SDL_RenderCopy/CopyEx in software should optionally render 8bit alpha
Sam Lantinga <slouken@libsdl.org>
parents: 8696
diff changeset
   305
                *pc = *((tColorY *)src->pixels + src->pitch * dy + dx);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   306
            }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   307
            sdx += icos;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   308
            sdy += isin;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   309
            pc++;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   310
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   311
        pc += gap;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   312
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   313
}
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   314
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   315
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   316
/* !
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   317
\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   318
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   319
Rotates a 32bit or 8bit 'src' surface to newly created 'dst' surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   320
'angle' is the rotation in degrees, 'centerx' and 'centery' the rotation center. If 'smooth' is set
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   321
then the destination 32bit surface is anti-aliased. If the surface is not 8bit
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   322
or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   323
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   324
\param src The surface to rotozoom.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   325
\param angle The angle to rotate in degrees.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   326
\param centerx The horizontal coordinate of the center of rotation
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   327
\param zoomy The vertical coordinate of the center of rotation
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   328
\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   329
\param flipx Set to 1 to flip the image horizontally
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   330
\param flipy Set to 1 to flip the image vertically
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   331
\param dstwidth The destination surface width
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   332
\param dstheight The destination surface height
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   333
\param cangle The angle cosine
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   334
\param sangle The angle sine
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   335
\return The new rotated surface.
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   336
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   337
*/
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   338
7859
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   339
SDL_Surface *
af63b63e7aac Prevent conflicts when linking both SDL2 and SDL2_gfx
Sam Lantinga <slouken@libsdl.org>
parents: 7828
diff changeset
   340
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)
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   341
{
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   342
    SDL_Surface *rz_src;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   343
    SDL_Surface *rz_dst;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   344
    int is32bit;
9763
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   345
    int i;
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   346
    Uint8 r,g,b;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   347
    Uint32 colorkey = 0;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   348
    int colorKeyAvailable = 0;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   349
    double sangleinv, cangleinv;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   350
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   351
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   352
    * Sanity check
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   353
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   354
    if (src == NULL)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   355
        return (NULL);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   356
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   357
    if (src->flags & SDL_TRUE/* SDL_SRCCOLORKEY */)
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   358
    {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   359
        colorkey = _colorkey(src);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   360
        SDL_GetRGB(colorkey, src->format, &r, &g, &b);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   361
        colorKeyAvailable = 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   362
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   363
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   364
    * Determine if source surface is 32bit or 8bit
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   365
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   366
    is32bit = (src->format->BitsPerPixel == 32);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   367
    if ((is32bit) || (src->format->BitsPerPixel == 8)) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   368
        /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   369
        * Use source surface 'as is'
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   370
        */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   371
        rz_src = src;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   372
    } else {
9763
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   373
        Uint32 format = SDL_MasksToPixelFormatEnum(32,
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   374
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   375
            0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   376
#else
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   377
            0xff000000,  0x00ff0000, 0x0000ff00, 0x000000ff
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   378
#endif
9763
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   379
        );
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   380
        rz_src = SDL_ConvertSurfaceFormat(src, format, src->flags);
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   381
        is32bit = 1;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   382
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   383
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   384
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   385
    /* Determine target size */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   386
    /* _rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, &dstwidth, &dstheight, &cangle, &sangle); */
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   387
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   388
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   389
    * Calculate target factors from sin/cos and zoom
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   390
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   391
    sangleinv = sangle*65536.0;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   392
    cangleinv = cangle*65536.0;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   393
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   394
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   395
    * Alloc space to completely contain the rotated surface
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   396
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   397
    rz_dst = NULL;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   398
    if (is32bit) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   399
        /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   400
        * Target surface is 32bit with source RGBA/ABGR ordering
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   401
        */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   402
        rz_dst =
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   403
            SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 32,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   404
            rz_src->format->Rmask, rz_src->format->Gmask,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   405
            rz_src->format->Bmask, rz_src->format->Amask);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   406
    } else {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   407
        /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   408
        * Target surface is 8bit
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   409
        */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   410
        rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   411
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   412
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   413
    /* Check target */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   414
    if (rz_dst == NULL)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   415
        return NULL;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   416
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   417
    /* Adjust for guard rows */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   418
    rz_dst->h = dstheight;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   419
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   420
    if (colorKeyAvailable == 1){
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   421
        colorkey = SDL_MapRGB(rz_dst->format, r, g, b);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   422
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   423
        SDL_FillRect(rz_dst, NULL, colorkey );
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   424
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   425
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   426
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   427
    * Lock source surface
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   428
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   429
    if (SDL_MUSTLOCK(rz_src)) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   430
        SDL_LockSurface(rz_src);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   431
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   432
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   433
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   434
    * Check which kind of surface we have
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   435
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   436
    if (is32bit) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   437
        /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   438
        * Call the 32bit transformation routine to do the rotation (using alpha)
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   439
        */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   440
        _transformSurfaceRGBA(rz_src, rz_dst, centerx, centery,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   441
            (int) (sangleinv), (int) (cangleinv),
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   442
            flipx, flipy,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   443
            smooth);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   444
        /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   445
        * Turn on source-alpha support
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   446
        */
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   447
        /* SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); */
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   448
        SDL_SetColorKey(rz_dst, /* SDL_SRCCOLORKEY */ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src));
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   449
    } else {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   450
        /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   451
        * Copy palette and colorkey info
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   452
        */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   453
        for (i = 0; i < rz_src->format->palette->ncolors; i++) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   454
            rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i];
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   455
        }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   456
        rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors;
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   457
        /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   458
        * Call the 8bit transformation routine to do the rotation
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   459
        */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   460
        transformSurfaceY(rz_src, rz_dst, centerx, centery,
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   461
            (int) (sangleinv), (int) (cangleinv),
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   462
            flipx, flipy);
7678
286c42d7c5ed OCD fixes: Adds a space after /* (glory to regular expressions!)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7677
diff changeset
   463
        SDL_SetColorKey(rz_dst, /* SDL_SRCCOLORKEY */ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src));
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   464
    }
9763
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   465
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   466
    /* copy alpha mod, color mod, and blend mode */
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   467
    {
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   468
      SDL_BlendMode blendMode;
9775
8bd9e4e20d99 Fixed compiler warning about shadowed local variables.
Ryan C. Gordon <icculus@icculus.org>
parents: 9763
diff changeset
   469
      Uint8 alphaMod, cr, cg, cb;
9763
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   470
      SDL_GetSurfaceAlphaMod(src, &alphaMod);
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   471
      SDL_GetSurfaceBlendMode(src, &blendMode);
9775
8bd9e4e20d99 Fixed compiler warning about shadowed local variables.
Ryan C. Gordon <icculus@icculus.org>
parents: 9763
diff changeset
   472
      SDL_GetSurfaceColorMod(src, &cr, &cg, &cb);
9763
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   473
      SDL_SetSurfaceAlphaMod(rz_dst, alphaMod);
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   474
      SDL_SetSurfaceBlendMode(rz_dst, blendMode);
9775
8bd9e4e20d99 Fixed compiler warning about shadowed local variables.
Ryan C. Gordon <icculus@icculus.org>
parents: 9763
diff changeset
   475
      SDL_SetSurfaceColorMod(rz_dst, cr, cg, cb);
9763
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   476
    }
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   477
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   478
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   479
    * Unlock source surface
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   480
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   481
    if (SDL_MUSTLOCK(rz_src)) {
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   482
        SDL_UnlockSurface(rz_src);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   483
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   484
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   485
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   486
    * Cleanup temp surface
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   487
    */
9763
c2ba8ab27c1a Fixed bug 2538 - SDL_SetTextureAlphaMod does not work with SDL_FlipMode or rotation in the software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9762
diff changeset
   488
    if (rz_src != src) {
6320
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   489
        SDL_FreeSurface(rz_src);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   490
    }
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   491
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   492
    /*
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   493
    * Return destination surface
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   494
    */
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   495
    return (rz_dst);
6077a1310907 RenderCopyEx,rotation and flipping for all hardware/software backends (#1308)
Gabriel Jacobo <gabomdq@gmail.com>
parents:
diff changeset
   496
}