sa.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "readpng.c"
  4. #include "armath.c"
  5. void die() {
  6. printf("\
  7. usage: structuralascii <image>\n\
  8. - supported images are: png\n");
  9. exit(1);
  10. }
  11. int main(int argc, char **argv) {
  12. if (argc < 2)
  13. die();
  14. printf("structural ascii 0.1\n");
  15. printf(" file %s\n", argv[1]);
  16. FILE* img = fopen(argv[1], "r");
  17. if (img == NULL) {
  18. fprintf(stderr, " error while opening file for reading\n");
  19. return 1;
  20. }
  21. /* print stats about loaded image */
  22. readpng_version_info();
  23. long width;
  24. long height;
  25. int ret = readpng_init(img, &width, &height);
  26. if (ret) {
  27. fprintf(stderr, " error while initializing readpng\n");
  28. return 2;
  29. }
  30. printf("file width/height: %ldx%ld\n", width, height);
  31. long arw = width;
  32. long arh = height;
  33. simplifyfractionl(&arw, &arh);
  34. printf("file aspect ratio: %ld:%ld\n", arw, arh);
  35. unsigned char rbg;
  36. unsigned char gbg;
  37. unsigned char bbg;
  38. readpng_get_bgcolor(&rbg, &gbg, &bbg);
  39. printf("file background: %i, %i, %i\n", rbg, gbg, bbg);
  40. return 0;
  41. }