-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.c
51 lines (40 loc) · 1.07 KB
/
main.c
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
47
48
49
50
51
#include "definitions.h"
#include <magic.h>
#include <stdio.h>
#include <string.h>
static const char *mime_type(const char *filename)
{
const char *ret;
magic_t magic = magic_open(MAGIC_MIME_TYPE);
magic_load(magic, NULL);
ret = magic_file(magic, filename);
return ret;
}
static int print_data(intensity_data data)
{
if (data.error) {
fprintf(stderr, "Decoder library returned an error\n");
return 1;
}
printf("%f\t%f\t%f\t%f\n", data.nw, data.ne, data.sw, data.se);
return 0;
}
int main(int argc, char *argv[])
{
const char *file_mime;
intensity_data data;
if (argc != 2) {
fprintf(stderr, "Expected to be called with 2 arguments\n");
return 1;
}
file_mime = mime_type(argv[1]);
if (strcmp(file_mime, "image/png") == 0) {
data = png_intensities(argv[1]);
} else if (strcmp(file_mime, "image/jpeg") == 0) {
data = jpeg_intensities(argv[1]);
} else {
fprintf(stderr, "Unrecognized file type `%s'\n", file_mime);
return 1;
}
return print_data(data);
}