Run clang-format on everything (#1332)

This commit is contained in:
Sylvie
2024-03-04 14:22:49 -05:00
committed by GitHub
parent b004648a13
commit e74073e480
66 changed files with 6091 additions and 4957 deletions

View File

@@ -15,8 +15,8 @@
#include <png.h>
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <string>
#include <vector>
struct Attributes {
@@ -70,8 +70,9 @@ static void generate_tile_attributes(Attributes *attributes) {
// Use an array to look up the number of colors in the palette; this is faster (and simpler)
// than doing a population count over the bits
static char const popcount[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3,
4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4};
static char const popcount[] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4,
};
attributes->nbColors = popcount[pal];
}
@@ -104,8 +105,7 @@ static void generate_tile_data(unsigned char tiledata[8][8], unsigned colorcount
}
}
static void
copy_tile_data(unsigned char destination[8][8], unsigned char const source[8][8]) {
static void copy_tile_data(unsigned char destination[8][8], unsigned char const source[8][8]) {
// Apply a random rotation to the copy
// coord ^ 7 = inverted coordinate; coord ^ 0 = regular coordinate
unsigned xmask = getRandomBits(1) * 7;
@@ -148,9 +148,14 @@ static uint8_t _5to8(uint8_t five) {
}
// Can't mark as `const`, as the array type is otherwise not compatible (augh)
static void write_image(char const *filename, uint16_t /* const */ palettes[/* 60 */][4],
unsigned char /* const */ (*tileData)[8][8], Attributes const *attributes,
uint8_t width, uint8_t height) {
static void write_image(
char const *filename,
uint16_t /* const */ palettes[/* 60 */][4],
unsigned char /* const */ (*tileData)[8][8],
Attributes const *attributes,
uint8_t width,
uint8_t height
) {
uint8_t const nbTiles = width * height;
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
png_infop pngInfo = png_create_info_struct(png);
@@ -167,9 +172,17 @@ static void write_image(char const *filename, uint16_t /* const */ palettes[/* 6
}
png_init_io(png, file);
png_set_IHDR(png, pngInfo, width * 8, height * 8, 8, PNG_COLOR_TYPE_RGB_ALPHA,
getRandomBits(1) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_IHDR(
png,
pngInfo,
width * 8,
height * 8,
8,
PNG_COLOR_TYPE_RGB_ALPHA,
getRandomBits(1) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT
);
// While it would be nice to write the image little by little, I really don't want to handle
// interlacing myself. (We're doing interlacing to test that RGBGFX correctly handles it.)

View File

@@ -111,10 +111,13 @@ class Png {
std::streamsize nbBytesRead = self->file.sgetn(reinterpret_cast<char *>(data), expectedLen);
if (nbBytesRead != expectedLen) {
fatal("Error reading input image (\"%s\"): file too short (expected at least %zd more "
"bytes after reading %zu)",
self->path.c_str(), length - nbBytesRead,
(size_t)self->file.pubseekoff(0, std::ios_base::cur));
fatal(
"Error reading input image (\"%s\"): file too short (expected at least %zd more "
"bytes after reading %zu)",
self->path.c_str(),
length - nbBytesRead,
(size_t)self->file.pubseekoff(0, std::ios_base::cur)
);
}
}
@@ -149,8 +152,9 @@ public:
fatal("Input file (\"%s\") is not a PNG image!", path.c_str());
}
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)this, handleError,
handleWarning);
png = png_create_read_struct(
PNG_LIBPNG_VER_STRING, (png_voidp)this, handleError, handleWarning
);
if (!png) {
fatal("Failed to allocate PNG structure: %s", strerror(errno));
}
@@ -174,8 +178,9 @@ public:
int bitDepth, interlaceType; //, compressionType, filterMethod;
png_get_IHDR(png, info, &width, &height, &bitDepth, &colorType, &interlaceType, nullptr,
nullptr);
png_get_IHDR(
png, info, &width, &height, &bitDepth, &colorType, &interlaceType, nullptr, nullptr
);
if (width % 8 != 0) {
fatal("Image width (%" PRIu32 " pixels) is not a multiple of 8!", width);
@@ -308,19 +313,36 @@ static char *execProg(char const *name, char * const *argv) {
fatal("Error waiting for %s: %s", name, strerror(errno));
} else if (info.si_code != CLD_EXITED) {
assert(info.si_code == CLD_KILLED || info.si_code == CLD_DUMPED);
fatal("%s was terminated by signal %s%s\n\tThe command was: [%s]", name, strsignal(info.si_status),
info.si_code == CLD_DUMPED ? " (core dumped)" : "", formatArgv());
fatal(
"%s was terminated by signal %s%s\n\tThe command was: [%s]",
name,
strsignal(info.si_status),
info.si_code == CLD_DUMPED ? " (core dumped)" : "",
formatArgv()
);
} else if (info.si_status != 0) {
fatal("%s returned with status %d\n\tThe command was: [%s]", name, info.si_status, formatArgv());
fatal(
"%s returned with status %d\n\tThe command was: [%s]",
name,
info.si_status,
formatArgv()
);
}
#else // defined(_MSC_VER) || defined(__MINGW32__)
auto winStrerror = [](DWORD errnum) {
LPTSTR buf;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_MAX_WIDTH_MASK,
nullptr, errnum, 0, (LPTSTR)&buf, 0, nullptr)
if (FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_MAX_WIDTH_MASK,
nullptr,
errnum,
0,
(LPTSTR)&buf,
0,
nullptr
)
== 0) {
fatal("Failed to get error message for error 0x%x", errnum);
}
@@ -341,28 +363,31 @@ static char *execProg(char const *name, char * const *argv) {
STARTUPINFOA startupInfo;
GetStartupInfoA(&startupInfo);
STARTUPINFOA childStartupInfo{sizeof(startupInfo),
nullptr,
nullptr,
nullptr,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
nullptr,
0,
0,
0};
STARTUPINFOA childStartupInfo{
sizeof(startupInfo),
nullptr,
nullptr,
nullptr,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
nullptr,
0,
0,
0,
};
PROCESS_INFORMATION child;
if (CreateProcessA(nullptr, cmdLine, nullptr, nullptr, true, 0, nullptr, nullptr,
&childStartupInfo, &child)
if (CreateProcessA(
nullptr, cmdLine, nullptr, nullptr, true, 0, nullptr, nullptr, &childStartupInfo, &child
)
== 0) {
return winStrerror(GetLastError());
}
@@ -395,8 +420,9 @@ int main(int argc, char *argv[]) {
char *args[] = {path, argv[1], file, nullptr};
if (auto ret = execProg("randtilegen", args); ret != nullptr) {
fatal("Failed to execute ./randtilegen (%s). Is it in the current working directory?",
ret);
fatal(
"Failed to execute ./randtilegen (%s). Is it in the current working directory?", ret
);
}
}
@@ -405,7 +431,8 @@ int main(int argc, char *argv[]) {
pal_opt[] = "-p", pal_file[] = "result.pal", attr_opt[] = "-a",
attr_file[] = "result.attrmap", in_file[] = "out0.png";
std::vector<char *> args(
{path, out_opt, out_file, pal_opt, pal_file, attr_opt, attr_file, in_file});
{path, out_opt, out_file, pal_opt, pal_file, attr_opt, attr_file, in_file}
);
// Also copy the trailing `nullptr`
std::copy_n(&argv[2], argc - 1, std::back_inserter(args));
@@ -422,8 +449,17 @@ int main(int argc, char *argv[]) {
attr_opt[] = "-a", attr_file[] = "result.attrmap", in_file[] = "result.png";
auto width_string = std::to_string(image0.getWidth() / 8);
std::vector<char *> args = {
path, reverse_opt, width_string.data(), out_opt, out_file, pal_opt,
pal_file, attr_opt, attr_file, in_file};
path,
reverse_opt,
width_string.data(),
out_opt,
out_file,
pal_opt,
pal_file,
attr_opt,
attr_file,
in_file,
};
// Also copy the trailing `nullptr`
std::copy_n(&argv[2], argc - 1, std::back_inserter(args));
@@ -456,10 +492,20 @@ int main(int argc, char *argv[]) {
};
if (cgbColor(px0) != cgbColor(px1)) {
error("Color mismatch at (%" PRIu32 ", %" PRIu32
"): (%u,%u,%u,%u) became (%u,%u,%u,%u) after round-tripping",
x, y, px0.red, px0.green, px0.blue, px0.alpha, px1.red, px1.green, px1.blue,
px1.alpha);
error(
"Color mismatch at (%" PRIu32 ", %" PRIu32
"): (%u,%u,%u,%u) became (%u,%u,%u,%u) after round-tripping",
x,
y,
px0.red,
px0.green,
px0.blue,
px0.alpha,
px1.red,
px1.green,
px1.blue,
px1.alpha
);
}
}
}