pa07.c 696 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "bmp.h"
  4. /* ======== DO NOT MODIFY THIS FILE! ======== */
  5. int main(int argc, char **argv)
  6. {
  7. // Check arguments
  8. if (argc < 3) {
  9. printf("Usage: pa07 <source> <destination>\n");
  10. return EXIT_FAILURE;
  11. }
  12. // Load the input file
  13. BMP_Image *image = BMP_load(argv[1]);
  14. if (image == NULL) {
  15. printf("Input file invalid!\n");
  16. return EXIT_FAILURE;
  17. }
  18. // Invert the file
  19. BMP_invert(image);
  20. // Save the file
  21. if (!BMP_save(image, argv[2])) {
  22. printf("Output file invalid!\n");
  23. BMP_destroy(image);
  24. return EXIT_FAILURE;
  25. }
  26. // Destroy the BMP image
  27. BMP_destroy(image);
  28. return EXIT_SUCCESS;
  29. }