mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-16 00:08:14 +00:00
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
@@ -46,7 +46,8 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
|
||||
/* !
|
||||
\brief A 32 bit RGBA pixel.
|
||||
*/
|
||||
typedef struct tColorRGBA {
|
||||
typedef struct tColorRGBA
|
||||
{
|
||||
Uint8 r;
|
||||
Uint8 g;
|
||||
Uint8 b;
|
||||
@@ -56,7 +57,8 @@ typedef struct tColorRGBA {
|
||||
/* !
|
||||
\brief A 8bit Y/palette pixel.
|
||||
*/
|
||||
typedef struct tColorY {
|
||||
typedef struct tColorY
|
||||
{
|
||||
Uint8 y;
|
||||
} tColorY;
|
||||
|
||||
@@ -75,8 +77,7 @@ to a situation where the program can segfault.
|
||||
/* !
|
||||
\brief Returns colorkey info for a surface
|
||||
*/
|
||||
static Uint32
|
||||
get_colorkey(SDL_Surface *src)
|
||||
static Uint32 get_colorkey(SDL_Surface *src)
|
||||
{
|
||||
Uint32 key = 0;
|
||||
if (SDL_HasColorKey(src)) {
|
||||
@@ -86,8 +87,8 @@ get_colorkey(SDL_Surface *src)
|
||||
}
|
||||
|
||||
/* rotate (sx, sy) by (angle, center) into (dx, dy) */
|
||||
static void
|
||||
rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint *center, double *dx, double *dy) {
|
||||
static void rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint *center, double *dx, double *dy)
|
||||
{
|
||||
sx -= center->x;
|
||||
sy -= center->y;
|
||||
|
||||
@@ -110,9 +111,8 @@ rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint
|
||||
\param sangle The cosine of the angle
|
||||
|
||||
*/
|
||||
void
|
||||
SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
|
||||
SDL_Rect *rect_dest, double *cangle, double *sangle)
|
||||
void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
|
||||
SDL_Rect *rect_dest, double *cangle, double *sangle)
|
||||
{
|
||||
int minx, maxx, miny, maxy;
|
||||
double radangle;
|
||||
@@ -128,16 +128,16 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
|
||||
/*
|
||||
* Determine destination width and height by rotating a source box, at pixel center
|
||||
*/
|
||||
rotate(0.5, 0.5, sinangle, cosangle, center, &x0, &y0);
|
||||
rotate(width - 0.5, 0.5, sinangle, cosangle, center, &x1, &y1);
|
||||
rotate(0.5, height - 0.5, sinangle, cosangle, center, &x2, &y2);
|
||||
rotate(0.5, 0.5, sinangle, cosangle, center, &x0, &y0);
|
||||
rotate(width - 0.5, 0.5, sinangle, cosangle, center, &x1, &y1);
|
||||
rotate(0.5, height - 0.5, sinangle, cosangle, center, &x2, &y2);
|
||||
rotate(width - 0.5, height - 0.5, sinangle, cosangle, center, &x3, &y3);
|
||||
|
||||
minx = (int)SDL_floor( SDL_min( SDL_min(x0, x1), SDL_min(x2, x3) ) );
|
||||
maxx = (int)SDL_ceil( SDL_max( SDL_max(x0, x1), SDL_max(x2, x3) ) );
|
||||
minx = (int)SDL_floor(SDL_min(SDL_min(x0, x1), SDL_min(x2, x3)));
|
||||
maxx = (int)SDL_ceil(SDL_max(SDL_max(x0, x1), SDL_max(x2, x3)));
|
||||
|
||||
miny = (int)SDL_floor( SDL_min( SDL_min(y0, y1), SDL_min(y2, y3) ) );
|
||||
maxy = (int)SDL_ceil( SDL_max( SDL_max(y0, y1), SDL_max(y2, y3) ) );
|
||||
miny = (int)SDL_floor(SDL_min(SDL_min(y0, y1), SDL_min(y2, y3)));
|
||||
maxy = (int)SDL_ceil(SDL_max(SDL_max(y0, y1), SDL_max(y2, y3)));
|
||||
|
||||
rect_dest->w = maxx - minx;
|
||||
rect_dest->h = maxy - miny;
|
||||
@@ -150,20 +150,20 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
|
||||
|
||||
{
|
||||
/* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
|
||||
int angle90 = (int)(angle/90);
|
||||
if (angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
|
||||
int angle90 = (int)(angle / 90);
|
||||
if (angle90 == angle / 90) { /* if the angle is a multiple of 90 degrees */
|
||||
angle90 %= 4;
|
||||
if (angle90 < 0) {
|
||||
angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
}
|
||||
|
||||
if (angle90 & 1) {
|
||||
rect_dest->w = height;
|
||||
rect_dest->w = height;
|
||||
rect_dest->h = width;
|
||||
*cangle = 0;
|
||||
*sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */
|
||||
} else {
|
||||
rect_dest->w = width;
|
||||
rect_dest->w = width;
|
||||
rect_dest->h = height;
|
||||
*cangle = angle90 == 0 ? 1 : -1;
|
||||
*sangle = 0;
|
||||
@@ -173,19 +173,37 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
|
||||
}
|
||||
|
||||
/* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */
|
||||
static void
|
||||
computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy,
|
||||
int *sincx, int *sincy, int *signx, int *signy)
|
||||
static void computeSourceIncrements90(SDL_Surface *src, int bpp, int angle, int flipx, int flipy,
|
||||
int *sincx, int *sincy, int *signx, int *signy)
|
||||
{
|
||||
int pitch = flipy ? -src->pitch : src->pitch;
|
||||
if (flipx) {
|
||||
bpp = -bpp;
|
||||
}
|
||||
switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break;
|
||||
case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break;
|
||||
case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break;
|
||||
case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break;
|
||||
case 0:
|
||||
*sincx = bpp;
|
||||
*sincy = pitch - src->w * *sincx;
|
||||
*signx = *signy = 1;
|
||||
break;
|
||||
case 1:
|
||||
*sincx = -pitch;
|
||||
*sincy = bpp - *sincx * src->h;
|
||||
*signx = 1;
|
||||
*signy = -1;
|
||||
break;
|
||||
case 2:
|
||||
*sincx = -bpp;
|
||||
*sincy = -src->w * *sincx - pitch;
|
||||
*signx = *signy = -1;
|
||||
break;
|
||||
case 3:
|
||||
default:
|
||||
*sincx = pitch;
|
||||
*sincy = -*sincx * src->h - bpp;
|
||||
*signx = -1;
|
||||
*signy = 1;
|
||||
break;
|
||||
}
|
||||
if (flipx) {
|
||||
*signx = -*signx;
|
||||
@@ -196,34 +214,34 @@ computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int
|
||||
}
|
||||
|
||||
/* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */
|
||||
#define TRANSFORM_SURFACE_90(pixelType) \
|
||||
int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \
|
||||
Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \
|
||||
#define TRANSFORM_SURFACE_90(pixelType) \
|
||||
int dy, dincy = dst->pitch - dst->w * sizeof(pixelType), sincx, sincy, signx, signy; \
|
||||
Uint8 *sp = (Uint8 *)src->pixels, *dp = (Uint8 *)dst->pixels, *de; \
|
||||
\
|
||||
computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \
|
||||
if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \
|
||||
if (signy < 0) sp += (src->h-1)*src->pitch; \
|
||||
if (signx < 0) \
|
||||
sp += (src->w - 1) * sizeof(pixelType); \
|
||||
if (signy < 0) \
|
||||
sp += (src->h - 1) * src->pitch; \
|
||||
\
|
||||
for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \
|
||||
if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use SDL_memcpy */ \
|
||||
SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \
|
||||
sp += dst->w*sizeof(pixelType); \
|
||||
dp += dst->w*sizeof(pixelType); \
|
||||
SDL_memcpy(dp, sp, dst->w * sizeof(pixelType)); \
|
||||
sp += dst->w * sizeof(pixelType); \
|
||||
dp += dst->w * sizeof(pixelType); \
|
||||
} else { \
|
||||
for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
|
||||
*(pixelType*)dp = *(pixelType*)sp; \
|
||||
for (de = dp + dst->w * sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
|
||||
*(pixelType *)dp = *(pixelType *)sp; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
static void
|
||||
transformSurfaceRGBA90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy)
|
||||
static void transformSurfaceRGBA90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
|
||||
{
|
||||
TRANSFORM_SURFACE_90(tColorRGBA);
|
||||
}
|
||||
|
||||
static void
|
||||
transformSurfaceY90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy)
|
||||
static void transformSurfaceY90(SDL_Surface *src, SDL_Surface *dst, int angle, int flipx, int flipy)
|
||||
{
|
||||
TRANSFORM_SURFACE_90(tColorY);
|
||||
}
|
||||
@@ -249,32 +267,31 @@ Assumes dst surface was allocated with the correct dimensions.
|
||||
\param dst_rect destination coordinates
|
||||
\param center true center.
|
||||
*/
|
||||
static void
|
||||
transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
||||
int flipx, int flipy, int smooth,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
static void transformSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst, int isin, int icos,
|
||||
int flipx, int flipy, int smooth,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
{
|
||||
int sw, sh;
|
||||
int cx, cy;
|
||||
tColorRGBA c00, c01, c10, c11, cswap;
|
||||
tColorRGBA *pc, *sp;
|
||||
int gap;
|
||||
const int fp_half = (1<<15);
|
||||
const int fp_half = (1 << 15);
|
||||
|
||||
/*
|
||||
* Variable setup
|
||||
*/
|
||||
* Variable setup
|
||||
*/
|
||||
sw = src->w - 1;
|
||||
sh = src->h - 1;
|
||||
pc = (tColorRGBA*) dst->pixels;
|
||||
pc = (tColorRGBA *)dst->pixels;
|
||||
gap = dst->pitch - dst->w * 4;
|
||||
cx = (int)(center->x * 65536.0);
|
||||
cy = (int)(center->y * 65536.0);
|
||||
|
||||
/*
|
||||
* Switch between interpolating and non-interpolating code
|
||||
*/
|
||||
* Switch between interpolating and non-interpolating code
|
||||
*/
|
||||
if (smooth) {
|
||||
int y;
|
||||
for (y = 0; y < dst->h; y++) {
|
||||
@@ -292,28 +309,36 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
||||
if (flipy) {
|
||||
dy = sh - dy;
|
||||
}
|
||||
if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
|
||||
if ((dx > -1) && (dy > -1) && (dx < (src->w - 1)) && (dy < (src->h - 1))) {
|
||||
int ex, ey;
|
||||
int t1, t2;
|
||||
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
|
||||
sp = (tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx;
|
||||
c00 = *sp;
|
||||
sp += 1;
|
||||
c01 = *sp;
|
||||
sp += (src->pitch/4);
|
||||
sp += (src->pitch / 4);
|
||||
c11 = *sp;
|
||||
sp -= 1;
|
||||
c10 = *sp;
|
||||
if (flipx) {
|
||||
cswap = c00; c00=c01; c01=cswap;
|
||||
cswap = c10; c10=c11; c11=cswap;
|
||||
cswap = c00;
|
||||
c00 = c01;
|
||||
c01 = cswap;
|
||||
cswap = c10;
|
||||
c10 = c11;
|
||||
c11 = cswap;
|
||||
}
|
||||
if (flipy) {
|
||||
cswap = c00; c00=c10; c10=cswap;
|
||||
cswap = c01; c01=c11; c11=cswap;
|
||||
cswap = c00;
|
||||
c00 = c10;
|
||||
c10 = cswap;
|
||||
cswap = c01;
|
||||
c01 = c11;
|
||||
c11 = cswap;
|
||||
}
|
||||
/*
|
||||
* Interpolate colors
|
||||
*/
|
||||
* Interpolate colors
|
||||
*/
|
||||
ex = (sdx & 0xffff);
|
||||
ey = (sdy & 0xffff);
|
||||
t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
|
||||
@@ -333,7 +358,7 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
||||
sdy += isin;
|
||||
pc++;
|
||||
}
|
||||
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
|
||||
pc = (tColorRGBA *)((Uint8 *)pc + gap);
|
||||
}
|
||||
} else {
|
||||
int y;
|
||||
@@ -359,7 +384,7 @@ transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
||||
sdy += isin;
|
||||
pc++;
|
||||
}
|
||||
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
|
||||
pc = (tColorRGBA *)((Uint8 *)pc + gap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -382,35 +407,34 @@ Assumes dst surface was allocated with the correct dimensions.
|
||||
\param dst_rect destination coordinates
|
||||
\param center true center.
|
||||
*/
|
||||
static void
|
||||
transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
static void transformSurfaceY(SDL_Surface *src, SDL_Surface *dst, int isin, int icos, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
{
|
||||
int sw, sh;
|
||||
int cx, cy;
|
||||
tColorY *pc;
|
||||
int gap;
|
||||
const int fp_half = (1<<15);
|
||||
const int fp_half = (1 << 15);
|
||||
int y;
|
||||
|
||||
/*
|
||||
* Variable setup
|
||||
*/
|
||||
* Variable setup
|
||||
*/
|
||||
sw = src->w - 1;
|
||||
sh = src->h - 1;
|
||||
pc = (tColorY*) dst->pixels;
|
||||
pc = (tColorY *)dst->pixels;
|
||||
gap = dst->pitch - dst->w;
|
||||
cx = (int)(center->x * 65536.0);
|
||||
cy = (int)(center->y * 65536.0);
|
||||
|
||||
/*
|
||||
* Clear surface to colorkey
|
||||
*/
|
||||
* Clear surface to colorkey
|
||||
*/
|
||||
SDL_memset(pc, (int)(get_colorkey(src) & 0xff), dst->pitch * dst->h);
|
||||
/*
|
||||
* Iterate through destination surface
|
||||
*/
|
||||
* Iterate through destination surface
|
||||
*/
|
||||
for (y = 0; y < dst->h; y++) {
|
||||
int x;
|
||||
double src_x = (rect_dest->x + 0 + 0.5 - center->x);
|
||||
@@ -437,7 +461,6 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* !
|
||||
\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
|
||||
|
||||
@@ -465,8 +488,8 @@ When using the NONE and MOD modes, color and alpha modulation must be applied be
|
||||
*/
|
||||
|
||||
SDL_Surface *
|
||||
SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center)
|
||||
SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center)
|
||||
{
|
||||
SDL_Surface *rz_dst;
|
||||
int is8bit, angle90;
|
||||
@@ -493,8 +516,8 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
||||
}
|
||||
|
||||
/* Calculate target factors from sine/cosine and zoom */
|
||||
sangleinv = sangle*65536.0;
|
||||
cangleinv = cangle*65536.0;
|
||||
sangleinv = sangle * 65536.0;
|
||||
cangleinv = cangle * 65536.0;
|
||||
|
||||
/* Alloc space to completely contain the rotated surface */
|
||||
rz_dst = NULL;
|
||||
@@ -556,8 +579,8 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
||||
* the off-by-one problem in transformSurfaceRGBA that expresses itself when the rotation is near
|
||||
* multiples of 90 degrees.
|
||||
*/
|
||||
angle90 = (int)(angle/90);
|
||||
if (angle90 == angle/90) {
|
||||
angle90 = (int)(angle / 90);
|
||||
if (angle90 == angle / 90) {
|
||||
angle90 %= 4;
|
||||
if (angle90 < 0) {
|
||||
angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
@@ -581,7 +604,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
|
||||
transformSurfaceRGBA90(src, rz_dst, angle90, flipx, flipy);
|
||||
} else {
|
||||
transformSurfaceRGBA(src, rz_dst, (int)sangleinv, (int)cangleinv,
|
||||
flipx, flipy, smooth, rect_dest, center);
|
||||
flipx, flipy, smooth, rect_dest, center);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user