You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dither.c 1.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "config.h"
  2. #include "common.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <pipi.h>
  7. int main(int argc, char *argv[])
  8. {
  9. char *srcname = NULL, *dstname = NULL;
  10. pipi_image_t *img, *newimg;
  11. if(argc < 3)
  12. {
  13. fprintf(stderr, "%s: too few arguments\n", argv[0]);
  14. fprintf(stderr, "Usage: %s <src> <method> <dest>\n", argv[0]);
  15. fprintf(stderr, "Where <method> is one of:\n");
  16. fprintf(stderr, " 1 Floyd-Steinberg (raster)\n");
  17. fprintf(stderr, " 2 Floyd-Steinberg (serpentine)\n");
  18. fprintf(stderr, " 3 Ostromoukhov (raster)\n");
  19. fprintf(stderr, " 4 Ostromoukhov (serpentine)\n");
  20. fprintf(stderr, " 5 Direct binary search\n");
  21. return EXIT_FAILURE;
  22. }
  23. srcname = argv[1];
  24. dstname = argv[3];
  25. img = pipi_load(srcname);
  26. switch(atoi(argv[2]))
  27. {
  28. case 6:
  29. newimg = pipi_dbs(img); break;
  30. case 5:
  31. newimg = pipi_ostromoukhov(img, PIPI_SCAN_SERPENTINE); break;
  32. case 4:
  33. newimg = pipi_ostromoukhov(img, PIPI_SCAN_RASTER); break;
  34. case 3:
  35. newimg = pipi_floydsteinberg(img, PIPI_SCAN_SERPENTINE); break;
  36. case 2:
  37. newimg = pipi_floydsteinberg(img, PIPI_SCAN_RASTER); break;
  38. case 1:
  39. default:
  40. newimg = pipi_dither_ordered(img); break;
  41. }
  42. pipi_free(img);
  43. pipi_save(newimg, dstname);
  44. pipi_free(newimg);
  45. return 0;
  46. }