blob: 47e1722033702fba0500c8a2c8083e9a0089ffb4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  | 
#include <errno.h>
#include <lisiblepng.h>
#include <lisiblestd/log.h>
#include <stdio.h>
#include <string.h>
#define LOG0(msg) fprintf(stderr, msg "\n")
#define LOGN(fmt, ...) fprintf(stderr, fmt "\n", __VA_ARGS__)
int main(int argc, char **argv) {
  lstd_log_init();
  if (argc != 2) {
    LOG0("Usage: lisiblepng <png filepath>");
    return 1;
  }
  const char *png_filepath = argv[1];
  FILE *png_file = fopen(png_filepath, "r");
  fseek(png_file, 0, SEEK_END);
  long file_size = ftell(png_file);
  LOGN("File size: %ld bytes", file_size);
  fseek(png_file, 0, SEEK_SET);
  if (!png_file) {
    const char *error_message = strerror(errno);
    LOGN("Couldn't open PNG file: %s", error_message);
    return 1;
  }
  LisPng *png = LisPng_decode(png_file);
  if (!png) {
    LOG0("Couldn't decode PNG");
    return 1;
  }
  LisPng_dump_ppm(png);
  LisPng_destroy(png);
  if (fclose(png_file) != 0) {
    const char *error_message = strerror(errno);
    LOGN("Couldn't close PNG file: %s", error_message);
    return 1;
  }
  return 0;
}
  |