1 Commits
r110 ... master

Author SHA1 Message Date
b513956e70 Tweak default colors to not fail on transparent images 2025-02-19 11:46:48 -06:00

10
main.c
View File

@@ -37,7 +37,7 @@ unsigned int nearest_power_of_2(unsigned int n) {
struct options { struct options {
uint32_t r; uint32_t r;
int s; int s;
uint8_t c; uint16_t c;
int o; int o;
int l; int l;
int w; int w;
@@ -94,7 +94,7 @@ void printNoFrames() { printf("You need to specify at least one frame to use, go
int main(const int argc, char *argv[]) { int main(const int argc, char *argv[]) {
printf( printf(
"Knowledge Adventure Worlds Easy Avatar Tool, version 1.1\n" "Knowledge Adventure Worlds Easy Avatar Tool, version 1.1.1\n"
"Copyright (c) 2025 Brett \"bonkmaykr\" Bergstrom\n" "Copyright (c) 2025 Brett \"bonkmaykr\" Bergstrom\n"
"This program is free software under the MIT license.\n" "This program is free software under the MIT license.\n"
"\n" "\n"
@@ -113,7 +113,7 @@ int main(const int argc, char *argv[]) {
struct options opt; struct options opt;
opt.r = 0; opt.r = 0;
opt.s = 0; opt.s = 0;
opt.c = 255; opt.c = 0xDEAD;
opt.o = 0; opt.o = 0;
opt.l = 0; opt.l = 0;
opt.w = 0; opt.w = 0;
@@ -147,7 +147,7 @@ int main(const int argc, char *argv[]) {
} else if (strcmp(argv[i], "-c") == 0) { } else if (strcmp(argv[i], "-c") == 0) {
if (i == argc-1) { printf("No parameter for option: -c\n"); return 0; } if (i == argc-1) { printf("No parameter for option: -c\n"); return 0; }
const int c = trunc(atof(argv[i+1])); const int c = trunc(atof(argv[i+1]));
if (c < 1 || c > 256) { printf("Invalid number of colors: %s\n", argv[i+1]); return 0; } if (c < 1 || c > 256 - (!opt.o)) { printf("Invalid number of colors: %s\nThe maximum palette size is 255 for transparent MOVs and 256 for opaque ones.\n", argv[i+1]); return 0; }
opt.c = c - 1; opt.c = c - 1;
i++; i++;
} else if (strcmp(argv[i], "-d") == 0) { } else if (strcmp(argv[i], "-d") == 0) {
@@ -159,6 +159,7 @@ int main(const int argc, char *argv[]) {
i++; i++;
} }
if (numFrames == 0) { printNoFrames(); return 0; } if (numFrames == 0) { printNoFrames(); return 0; }
if (opt.c == 0xDEAD) { if (opt.o) opt.c = 254; else opt.c = 255; }
if (MagickReadImage(mw, frames[0]) == MagickFalse) { printf("ERROR trying to read %s\n", frames[0]); return 0;} if (MagickReadImage(mw, frames[0]) == MagickFalse) { printf("ERROR trying to read %s\n", frames[0]); return 0;}
MagickSetImageFormat(mw, "BMP3"); MagickSetImageFormat(mw, "BMP3");
@@ -365,6 +366,7 @@ int main(const int argc, char *argv[]) {
i++; i++;
} }
} }
remove("segments.txt");
printf("\n\n!!! DONE !!!\n"); printf("\n\n!!! DONE !!!\n");
if (opt.d) if (opt.d)