-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
62 lines (50 loc) · 1.59 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
52
53
54
55
56
57
58
59
60
61
62
#include <string.h>
#include "file.h"
#include "tag_type.h"
#include "ifd.h"
#include "cr2_header.h"
#include "tiff_header.h"
int main(int argc, char **argv)
{
if (argc <= 1) {
puts("Pass file path to CR2 file\n");
return 1;
}
const char *filename = argv[1];
FILE *cr = fopen(filename, "r");
if (cr == NULL) {
printf("Cannot open file %s\n", argv[1]);
return 1;
}
puts("Extra information");
printf("File: %s\n", filename);
size_t bytes = file_size(cr);
float mbytes = file_mb(bytes);
printf("File size: %.4f MB\n", mbytes);
struct tiff_header tiff_header;
tiff_header_parse(&tiff_header, cr);
tiff_header_dump(tiff_header, stdout);
if (!strncmp(tiff_header.endianness, HEADER_LITTLE_ENDIAN, BYTE_ORDER_CHARS)) {
puts("\nFile: is little endian format");
} else if (!strncmp(tiff_header.endianness, HEADER_BIG_ENDIAN, BYTE_ORDER_CHARS)) {
puts("\nFile is big endian format");
}
struct cr2_header cr2_header;
cr2_header_parse(&cr2_header, cr);
cr2_header_dump(cr2_header, stdout);
struct ifd ifds[N_IFDS];
ifds_parse(ifds, N_IFDS, tiff_header.offset_to_ifd, cr);
ifds_dump(ifds, N_IFDS, cr, stdout);
struct ifd exif;
ifd_parse(&exif, ifd_exif_value(ifds[0]), cr);
puts("\n\nEXIF");
ifd_dump(exif, cr, stdout);
struct ifd makernote;
ifd_parse(&makernote, ifd_maker_note(exif), cr);
puts("\nMAKERNOTE");
ifd_dump(makernote, cr, stdout);
ifd_entries_free(exif);
ifd_entries_free(makernote);
ifds_entries_free(ifds, N_IFDS);
fclose(cr);
}