43
|
1 /*
|
|
2 * GQView
|
|
3 * (C) 2005 John Ellis
|
|
4 *
|
|
5 * Authors:
|
|
6 * Original version 2005 Lars Ellenberg, base on dcraw by David coffin.
|
|
7 *
|
|
8 * This software is released under the GNU General Public License (GNU GPL).
|
|
9 * Please read the included file COPYING for more information.
|
|
10 * This software comes with no warranty of any kind, use at your own risk!
|
|
11 */
|
|
12
|
|
13 #ifdef HAVE_CONFIG_H
|
|
14 # include "config.h"
|
|
15 #endif
|
|
16
|
|
17 #include <stdio.h>
|
|
18 #include <string.h>
|
|
19 #include <unistd.h>
|
|
20
|
|
21 #include <glib.h>
|
|
22
|
|
23 #include "intl.h"
|
|
24
|
|
25 #include "format_raw.h"
|
|
26
|
|
27 static gint format_raw_test_canon(int fd, const void *data, const guint len,
|
|
28 guint *image_offset, guint *exif_offset)
|
|
29 {
|
|
30 return FALSE;
|
|
31 }
|
|
32
|
|
33 static gint format_raw_test_fuji(int fd, const void *data, const guint len,
|
|
34 guint *image_offset, guint *exif_offset)
|
|
35 {
|
|
36 if (len < 128 ||
|
|
37 memcmp(data, "FUJIFILM", 8) != 0)
|
|
38 {
|
|
39 return FALSE;
|
|
40 }
|
|
41
|
|
42 *image_offset = GUINT32_FROM_BE(*(guint32*)(data + 84));
|
|
43 *exif_offset = *image_offset + 12;
|
|
44 printf("found a raw fuji file!\n");
|
|
45 return TRUE;
|
|
46 }
|
|
47
|
|
48 static gint format_raw_test_nikon(int fd, const void *data, const guint len,
|
|
49 guint *image_offset, guint *exif_offset)
|
|
50 {
|
|
51 return FALSE;
|
|
52 }
|
|
53
|
|
54
|
|
55 gint format_raw_img_exif_offsets(int fd, const void *data, const guint len,
|
|
56 guint *image_offset, guint *exif_offset)
|
|
57 {
|
|
58 guint32 io = 0;
|
|
59 guint32 eo = 0;
|
|
60 gint found;
|
|
61
|
|
62 if (fd < 0 && !data) return FALSE;
|
|
63 #if 0
|
|
64 if (len < 512) return FALSE;
|
|
65 #endif
|
|
66
|
|
67 found = format_raw_test_canon(fd, data, len, &io, &eo) ||
|
|
68 format_raw_test_fuji (fd, data, len, &io, &eo) ||
|
|
69 format_raw_test_nikon(fd, data, len, &io, &eo);
|
|
70
|
|
71 if (!found ||
|
|
72 io >= len - 4 ||
|
|
73 eo >= len ||
|
|
74 memcmp(data + io, "\xff\xd8\xff\xe1", 4) != 0) /* jpeg marker */
|
|
75 {
|
|
76 return FALSE;
|
|
77 }
|
|
78
|
|
79 if (image_offset) *image_offset = io;
|
|
80 if (exif_offset) *exif_offset = eo;
|
|
81
|
|
82 return TRUE;
|
|
83 }
|
|
84
|
|
85
|
|
86
|