Implement -c #none (#1301)

Also adds a test case for round-tripping `-r` with `-c #none`.
This commit is contained in:
Evie
2024-03-03 18:45:33 -05:00
committed by GitHub
parent 930a5c3e44
commit 6b67c82b94
12 changed files with 95 additions and 38 deletions

View File

@@ -0,0 +1,4 @@
error: Unexpected character, expected ',', ';', or end of argument
In inline palette spec: #000,#none#fff
^
Conversion aborted after 1 error

View File

@@ -0,0 +1 @@
-c #000,#none#fff

Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

Binary file not shown.

View File

@@ -281,6 +281,21 @@ public:
};
static char *execProg(char const *name, char * const *argv) {
auto formatArgv = [&argv] {
// This is `static` so that the returned `buf.c_str()` will live long enough
// for `fatal()` to use it below.
static std::string buf;
buf.clear();
for (char * const *arg = argv; *arg != nullptr; ++arg) {
buf.push_back('"');
buf.append(*arg);
buf.append("\", ");
}
buf.resize(buf.length() - 2);
return buf.c_str();
};
#if !defined(_MSC_VER) && !defined(__MINGW32__)
pid_t pid;
int err = posix_spawn(&pid, argv[0], nullptr, nullptr, argv, nullptr);
@@ -293,10 +308,10 @@ 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", name, strsignal(info.si_status),
info.si_code == CLD_DUMPED ? " (core 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());
} else if (info.si_status != 0) {
fatal("%s returned with status %d", name, info.si_status);
fatal("%s returned with status %d\n\tThe command was: [%s]", name, info.si_status, formatArgv());
}
#else // defined(_MSC_VER) || defined(__MINGW32__)
@@ -362,7 +377,7 @@ static char *execProg(char const *name, char * const *argv) {
CloseHandle(child.hThread);
if (status != 0) {
fatal("%s returned with status %ld", name, status);
fatal("%s returned with status %ld\n\tThe command was: [%s]", name, status, formatArgv());
}
#endif

View File

@@ -39,8 +39,15 @@ for f in *.bin; do
done
done
# Test round-tripping '-r' with '-c #none'
reverse_cmd="$RGBGFX -c#none,#fff,#000 -o none_round_trip.2bpp -r 1 out.png"
reconvert_cmd="$RGBGFX -c#none,#fff,#000 -o result.2bpp out.png"
compare_cmd="cmp none_round_trip.2bpp result.2bpp"
new_test "$reverse_cmd && $reconvert_cmd && $compare_cmd"
test || fail $?
# Remove temporaries (also ignored by Git) created by the above tests
rm -f out*.png result.png
rm -f out*.png result.png result.2bpp
for f in *.png; do
flags="$([[ -e "${f%.png}.flags" ]] && echo "@${f%.png}.flags")"