|
diff --git a/main.c b/main.c
|
| ... |
| 54 |
if (strcasecmp(format, "png") == 0) return PNG; |
54 |
if (strcasecmp(format, "png") == 0) return PNG; |
| 55 |
if (strcasecmp(format, "bmp") == 0) return BMP; |
55 |
if (strcasecmp(format, "bmp") == 0) return BMP; |
| 56 |
if (strcasecmp(format, "tga") == 0) return TGA; |
56 |
if (strcasecmp(format, "tga") == 0) return TGA; |
| 57 |
if (strcasecmp(format, "jpg") == 0 || strcasecmp(format, "jpeg") == 0) return JPG; |
57 |
if (strcasecmp(format, "jpg") == 0) return JPG; |
| 58 |
return PNG; |
58 |
return PNG; |
| 59 |
} |
59 |
} |
| 60 |
|
60 |
|
| 61 |
bool is_valid_format(const char *format) { |
61 |
bool is_valid_format(const char *format) { |
| 62 |
const char *valid_formats[] = {"png", "bmp", "tga", "jpg", "jpeg", NULL}; |
62 |
const char *valid_formats[] = {"png", "bmp", "tga", "jpg", NULL}; |
| 63 |
for (const char **f = valid_formats; *f != NULL; f++) { |
63 |
for (const char **f = valid_formats; *f != NULL; f++) { |
| 64 |
if (strcasecmp(format, *f) == 0) { |
64 |
if (strcasecmp(format, *f) == 0) { |
| 65 |
return true; |
65 |
return true; |
| ... |
| 304 |
} |
304 |
} |
| 305 |
break; |
305 |
break; |
| 306 |
case JPG: |
306 |
case JPG: |
| 307 |
if (verbose) printf("Processing as JPEG format\n"); |
307 |
if (verbose) printf("Processing as JPG format\n"); |
| 308 |
if (stbi_write_jpg(output_filename, width, height, 4, decoded_image, 100) == 0) { |
308 |
if (stbi_write_jpg(output_filename, width, height, 4, decoded_image, 100) == 0) { |
| 309 |
printf("Failed to write %s file\n", output_filename); |
309 |
printf("Failed to write %s file\n", output_filename); |
| 310 |
} else { |
310 |
} else { |
| ... |
| 425 |
printf(" -h, --help Display this help message\n"); |
425 |
printf(" -h, --help Display this help message\n"); |
| 426 |
printf(" -v, --verbose Enable verbose output\n"); |
426 |
printf(" -v, --verbose Enable verbose output\n"); |
| 427 |
printf(" -f, --format=FORMAT Set output format (default: png)\n"); |
427 |
printf(" -f, --format=FORMAT Set output format (default: png)\n"); |
| 428 |
printf(" Options: png, bmp, tga, jpg, jpeg\n"); |
428 |
printf(" Options: png, bmp, tga, jpg\n"); |
| 429 |
} |
429 |
} |
| 430 |
|
430 |
|
| 431 |
int main(int argc, char *argv[]) { |
431 |
int main(int argc, char *argv[]) { |
| ... |
| 455 |
break; |
455 |
break; |
| 456 |
case 'f': |
456 |
case 'f': |
| 457 |
if (!is_valid_format(optarg)) { |
457 |
if (!is_valid_format(optarg)) { |
| 458 |
fprintf(stderr, "Error: Invalid format '%s'. Valid formats are: png, bmp, tga, jpg, jpeg\n", optarg); |
458 |
fprintf(stderr, "Error: Invalid format '%s'. Valid formats are: png, bmp, tga, jpg\n", optarg); |
| 459 |
return 1; |
459 |
return 1; |
| 460 |
} |
460 |
} |
| 461 |
format = optarg; |
461 |
format = optarg; |
| ... |