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:
Sam Lantinga
2022-11-30 12:51:59 -08:00
committed by GitHub
parent 14b902faca
commit 5750bcb174
781 changed files with 51659 additions and 55763 deletions

View File

@@ -13,10 +13,8 @@
#include <SDL3/SDL_test_font.h>
#include "testyuv_cvt.h"
/* 422 (YUY2, etc) formats are the largest */
#define MAX_YUV_SURFACE_SIZE(W, H, P) (H*4*(W+P+1)/2)
#define MAX_YUV_SURFACE_SIZE(W, H, P) (H * 4 * (W + P + 1) / 2)
/* Return true if the YUV format is packed pixels */
static SDL_bool is_packed_yuv_format(Uint32 format)
@@ -32,12 +30,12 @@ static SDL_Surface *generate_test_pattern(int pattern_size)
if (pattern) {
int i, x, y;
Uint8 *p, c;
const int thickness = 2; /* Important so 2x2 blocks of color are the same, to avoid Cr/Cb interpolation over pixels */
const int thickness = 2; /* Important so 2x2 blocks of color are the same, to avoid Cr/Cb interpolation over pixels */
/* R, G, B in alternating horizontal bands */
for (y = 0; y < pattern->h; y += thickness) {
for (i = 0; i < thickness; ++i) {
p = (Uint8 *)pattern->pixels + (y + i) * pattern->pitch + ((y/thickness) % 3);
p = (Uint8 *)pattern->pixels + (y + i) * pattern->pitch + ((y / thickness) % 3);
for (x = 0; x < pattern->w; ++x) {
*p = 0xFF;
p += 3;
@@ -47,9 +45,9 @@ static SDL_Surface *generate_test_pattern(int pattern_size)
/* Black and white in alternating vertical bands */
c = 0xFF;
for (x = 1*thickness; x < pattern->w; x += 2*thickness) {
for (x = 1 * thickness; x < pattern->w; x += 2 * thickness) {
for (i = 0; i < thickness; ++i) {
p = (Uint8 *)pattern->pixels + (x + i)*3;
p = (Uint8 *)pattern->pixels + (x + i) * 3;
for (y = 0; y < pattern->h; ++y) {
SDL_memset(p, c, 3);
p += pattern->pitch;
@@ -123,7 +121,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
Uint8 *yuv2 = (Uint8 *)SDL_malloc(yuv_len);
int yuv1_pitch, yuv2_pitch;
int result = -1;
if (pattern == NULL || yuv1 == NULL || yuv2 == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't allocate test surfaces");
goto done;
@@ -200,7 +198,6 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
}
}
result = 0;
done:
@@ -210,10 +207,10 @@ done:
return result;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct {
struct
{
SDL_bool enable_intrinsics;
int pattern_size;
int extra_pitch;
@@ -309,10 +306,10 @@ main(int argc, char **argv)
/* Run automated tests */
if (should_run_automated_tests) {
for (i = 0; i < SDL_arraysize(automated_test_params); ++i) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Running automated test, pattern size %d, extra pitch %d, intrinsics %s\n",
automated_test_params[i].pattern_size,
automated_test_params[i].extra_pitch,
automated_test_params[i].enable_intrinsics ? "enabled" : "disabled");
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Running automated test, pattern size %d, extra pitch %d, intrinsics %s\n",
automated_test_params[i].pattern_size,
automated_test_params[i].extra_pitch,
automated_test_params[i].enable_intrinsics ? "enabled" : "disabled");
if (run_automated_tests(automated_test_params[i].pattern_size, automated_test_params[i].extra_pitch) < 0) {
return 2;
}
@@ -333,8 +330,8 @@ main(int argc, char **argv)
raw_yuv = SDL_calloc(1, MAX_YUV_SURFACE_SIZE(original->w, original->h, 0));
ConvertRGBtoYUV(yuv_format, original->pixels, original->pitch, raw_yuv, original->w, original->h,
SDL_GetYUVConversionModeForResolution(original->w, original->h),
0, 100);
SDL_GetYUVConversionModeForResolution(original->w, original->h),
0, 100);
pitch = CalculateYUVPitch(yuv_format, original->w);
converted = SDL_CreateRGBSurfaceWithFormat(original->w, original->h, rgb_format);
@@ -344,11 +341,11 @@ main(int argc, char **argv)
}
then = SDL_GetTicks();
for ( i = 0; i < iterations; ++i ) {
for (i = 0; i < iterations; ++i) {
SDL_ConvertPixels(original->w, original->h, yuv_format, raw_yuv, pitch, rgb_format, converted->pixels, converted->pitch);
}
now = SDL_GetTicks();
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%" SDL_PRIu32 " iterations in %" SDL_PRIu32 " ms, %.2fms each\n", iterations, (now - then), (float) (now - then) / iterations);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%" SDL_PRIu32 " iterations in %" SDL_PRIu32 " ms, %.2fms each\n", iterations, (now - then), (float)(now - then) / iterations);
window = SDL_CreateWindow("YUV test",
SDL_WINDOWPOS_UNDEFINED,
@@ -374,7 +371,7 @@ main(int argc, char **argv)
return 5;
}
SDL_UpdateTexture(output[2], NULL, raw_yuv, pitch);
yuv_name = SDL_GetPixelFormatName(yuv_format);
if (SDL_strncmp(yuv_name, "SDL_PIXELFORMAT_", 16) == 0) {
yuv_name += 16;
@@ -395,8 +392,9 @@ main(int argc, char **argv)
break;
}
{ int done = 0;
while ( !done ) {
{
int done = 0;
while (!done) {
SDL_Event event;
while (SDL_PollEvent(&event) > 0) {
if (event.type == SDL_QUIT) {
@@ -412,7 +410,7 @@ main(int argc, char **argv)
}
}
if (event.type == SDL_MOUSEBUTTONDOWN) {
if (event.button.x < (original->w/2)) {
if (event.button.x < (original->w / 2)) {
--current;
} else {
++current;