Mercurial > geeqie.yaz
annotate src/format_raw.c @ 183:3962c9d3d6fd
more exiv2 fixes
author | nadvornik |
---|---|
date | Thu, 14 Feb 2008 11:03:20 +0000 |
parents | c01dd7c9c7dc |
children | 41fc4bfc8b25 |
rev | line source |
---|---|
43 | 1 /* |
2 * GQView | |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
3 * (C) 2006 John Ellis |
43 | 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 | |
177 | 17 #ifndef HAVE_EXIV2 |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
18 |
43 | 19 #include <stdio.h> |
20 #include <string.h> | |
21 #include <unistd.h> | |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
22 #include <sys/types.h> |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
23 #include <sys/stat.h> |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
24 #include <sys/mman.h> |
43 | 25 |
26 #include <glib.h> | |
27 | |
28 #include "intl.h" | |
29 | |
138 | 30 #include "gqview.h" |
43 | 31 #include "format_raw.h" |
32 | |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
33 #include "format_canon.h" |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
34 #include "format_fuji.h" |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
35 #include "format_nikon.h" |
57
a8c9992320f4
Fri Jun 10 20:57:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
36 #include "format_olympus.h" |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
37 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
38 |
53
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
39 /* so that debugging is honored */ |
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
40 extern gint debug; |
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
41 |
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
42 |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
43 typedef struct _FormatRawEntry FormatRawEntry; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
44 struct _FormatRawEntry { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
45 const gchar *extension; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
46 FormatRawMatchType magic_type; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
47 const guint magic_offset; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
48 const void *magic_pattern; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
49 const guint magic_length; |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
50 const FormatRawExifType exif_type; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
51 FormatRawExifParseFunc exif_func; |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
52 const gchar *description; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
53 FormatRawParseFunc func_parse; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
54 }; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
55 |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
56 static FormatRawEntry format_raw_list[] = { |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
57 #if DEBUG_RAW_TIFF |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
58 FORMAT_RAW_DEBUG_TIFF, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
59 #endif |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
60 FORMAT_RAW_CANON, |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
61 FORMAT_RAW_FUJI, |
53
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
62 FORMAT_RAW_NIKON, |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
63 FORMAT_RAW_OLYMPUS, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
64 FORMAT_RAW_PENTAX, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
65 { NULL, 0, 0, NULL, 0, 0, NULL, NULL, NULL } |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
66 }; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
67 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
68 |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
69 typedef struct _FormatExifEntry FormatExifEntry; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
70 struct _FormatExifEntry { |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
71 FormatExifMatchType header_type; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
72 const void *header_pattern; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
73 const guint header_length; |
53
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
74 const gchar *description; |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
75 FormatExifParseFunc func_parse; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
76 }; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
77 |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
78 static FormatExifEntry format_exif_list[] = { |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
79 FORMAT_EXIF_CANON, |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
80 FORMAT_EXIF_FUJI, |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
81 FORMAT_EXIF_NIKON, |
57
a8c9992320f4
Fri Jun 10 20:57:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
82 FORMAT_EXIF_OLYMPUS, |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
83 { 0, NULL, 0, NULL } |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
84 }; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
85 |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
86 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
87 static guint tiff_table(unsigned char *data, const guint len, guint offset, ExifByteOrder bo, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
88 guint tag, ExifFormatType type, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
89 guint *result_offset, guint *result_count) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
90 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
91 guint count; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
92 guint i; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
93 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
94 if (len < offset + 2) return 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
95 if (type < 0 || type > EXIF_FORMAT_COUNT) return 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
96 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
97 count = exif_byte_get_int16(data + offset, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
98 offset += 2; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
99 if (len < offset + count * 12 + 4) return 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
100 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
101 for (i = 0; i < count; i++) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
102 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
103 guint segment; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
104 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
105 segment = offset + i * 12; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
106 if (exif_byte_get_int16(data + segment, bo) == tag && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
107 exif_byte_get_int16(data + segment + 2, bo) == type) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
108 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
109 guint chunk_count; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
110 guint chunk_offset; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
111 guint chunk_length; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
112 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
113 chunk_count = exif_byte_get_int32(data + segment + 4, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
114 chunk_length = ExifFormatList[type].size * chunk_count; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
115 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
116 if (chunk_length > 4) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
117 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
118 chunk_offset = exif_byte_get_int32(data + segment + 8, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
119 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
120 else |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
121 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
122 chunk_offset = segment + 8; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
123 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
124 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
125 if (chunk_offset + chunk_length <= len) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
126 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
127 *result_offset = chunk_offset; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
128 *result_count = chunk_count; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
129 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
130 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
131 return 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
132 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
133 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
134 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
135 return exif_byte_get_int32(data + offset + count * 12, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
136 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
137 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
138 static gint format_tiff_find_tag_data(unsigned char *data, const guint len, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
139 guint tag, ExifFormatType type, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
140 guint *result_offset, guint *result_count) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
141 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
142 ExifByteOrder bo; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
143 guint offset; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
144 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
145 if (len < 8) return FALSE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
146 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
147 if (memcmp(data, "II", 2) == 0) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
148 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
149 bo = EXIF_BYTE_ORDER_INTEL; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
150 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
151 else if (memcmp(data, "MM", 2) == 0) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
152 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
153 bo = EXIF_BYTE_ORDER_MOTOROLA; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
154 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
155 else |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
156 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
157 return FALSE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
158 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
159 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
160 if (exif_byte_get_int16(data + 2, bo) != 0x002A) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
161 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
162 return FALSE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
163 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
164 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
165 offset = exif_byte_get_int32(data + 4, bo); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
166 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
167 while (offset != 0) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
168 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
169 guint ro = 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
170 guint rc = 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
171 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
172 offset = tiff_table(data, len, offset, bo, tag, type, &ro, &rc); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
173 if (ro != 0) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
174 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
175 *result_offset = ro; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
176 *result_count = rc; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
177 return TRUE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
178 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
179 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
180 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
181 return FALSE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
182 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
183 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
184 static FormatRawEntry *format_raw_find(unsigned char *data, const guint len) |
43 | 185 { |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
186 gint n; |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
187 gint tiff; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
188 guint make_count = 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
189 guint make_offset = 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
190 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
191 tiff = (len > 8 && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
192 (memcmp(data, "II\x2a\x00", 4) == 0 || |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
193 memcmp(data, "MM\x00\x2a", 4) == 0)); |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
194 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
195 n = 0; |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
196 while (format_raw_list[n].magic_pattern) |
43 | 197 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
198 FormatRawEntry *entry = &format_raw_list[n]; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
199 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
200 switch (entry->magic_type) |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
201 { |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
202 case FORMAT_RAW_MATCH_MAGIC: |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
203 if (entry->magic_length + entry->magic_offset <= len && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
204 memcmp(data + entry->magic_offset, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
205 entry->magic_pattern, entry->magic_length) == 0) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
206 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
207 return entry; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
208 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
209 break; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
210 case FORMAT_RAW_MATCH_TIFF_MAKE: |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
211 if (tiff && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
212 make_offset == 0 && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
213 !format_tiff_find_tag_data(data, len, 0x10f, EXIF_FORMAT_STRING, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
214 &make_offset, &make_count)) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
215 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
216 tiff = FALSE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
217 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
218 if (make_offset != 0 && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
219 make_count >= entry->magic_offset + entry->magic_length && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
220 memcmp(entry->magic_pattern, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
221 data + make_offset + entry->magic_offset, entry->magic_length) == 0) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
222 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
223 return entry; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
224 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
225 break; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
226 default: |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
227 break; |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
228 } |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
229 n++; |
43 | 230 } |
231 | |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
232 return NULL; |
43 | 233 } |
234 | |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
235 static gint format_raw_parse(FormatRawEntry *entry, |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
236 unsigned char *data, const guint len, |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
237 guint *image_offset, guint *exif_offset) |
43 | 238 { |
46
905f8fa583a3
Thu May 26 22:14:53 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
239 guint io = 0; |
905f8fa583a3
Thu May 26 22:14:53 2005 John Ellis <johne@verizon.net>
gqview
parents:
45
diff
changeset
|
240 guint eo = 0; |
43 | 241 gint found; |
242 | |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
243 if (!entry || !entry->func_parse) return FALSE; |
43 | 244 |
53
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
245 if (debug) printf("RAW using file parser for %s\n", entry->description); |
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
246 |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
247 found = entry->func_parse(data, len, &io, &eo); |
43 | 248 |
249 if (!found || | |
250 io >= len - 4 || | |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
251 eo >= len) |
43 | 252 { |
253 return FALSE; | |
254 } | |
255 | |
256 if (image_offset) *image_offset = io; | |
257 if (exif_offset) *exif_offset = eo; | |
258 | |
259 return TRUE; | |
260 } | |
261 | |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
262 gint format_raw_img_exif_offsets(unsigned char *data, const guint len, |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
263 guint *image_offset, guint *exif_offset) |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
264 { |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
265 FormatRawEntry *entry; |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
266 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
267 if (!data || len < 1) return FALSE; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
268 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
269 entry = format_raw_find(data, len); |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
270 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
271 if (!entry || !entry->func_parse) return FALSE; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
272 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
273 return format_raw_parse(entry, data, len, image_offset, exif_offset); |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
274 } |
43 | 275 |
276 | |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
277 FormatRawExifType format_raw_exif_offset(unsigned char *data, const guint len, guint *exif_offset, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
278 FormatRawExifParseFunc *exif_parse_func) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
279 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
280 FormatRawEntry *entry; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
281 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
282 if (!data || len < 1) return FALSE; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
283 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
284 entry = format_raw_find(data, len); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
285 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
286 if (!entry || !entry->func_parse) return FALSE; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
287 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
288 if (!format_raw_parse(entry, data, len, NULL, exif_offset)) return FORMAT_RAW_EXIF_NONE; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
289 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
290 if (entry->exif_type == FORMAT_RAW_EXIF_PROPRIETARY && exif_parse_func) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
291 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
292 *exif_parse_func = entry->exif_func; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
293 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
294 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
295 return entry->exif_type; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
296 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
297 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
298 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
299 gint format_raw_img_exif_offsets_fd(int fd, const gchar *path, |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
300 unsigned char *header_data, const guint header_len, |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
301 guint *image_offset, guint *exif_offset) |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
302 { |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
303 FormatRawEntry *entry; |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
304 void *map_data = NULL; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
305 size_t map_len = 0; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
306 struct stat st; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
307 gint success; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
308 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
309 if (!header_data || fd < 0) return FALSE; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
310 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
311 /* given image pathname, first do simple (and fast) file extension test */ |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
312 if (path) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
313 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
314 const gchar *ext; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
315 gint match = FALSE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
316 gint i; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
317 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
318 ext = strrchr(path, '.'); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
319 if (!ext) return FALSE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
320 ext++; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
321 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
322 i = 0; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
323 while (!match && format_raw_list[i].magic_pattern) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
324 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
325 if (format_raw_list[i].extension && |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
326 strcasecmp(format_raw_list[i].extension, ext) == 0) |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
327 { |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
328 match = TRUE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
329 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
330 i++; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
331 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
332 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
333 if (!match) return FALSE; |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
334 |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
335 if (debug) printf("RAW file parser extension match\n"); |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
336 } |
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
337 |
59
57f6da2510d9
Sun Jun 12 19:25:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
57
diff
changeset
|
338 /* FIXME: |
57f6da2510d9
Sun Jun 12 19:25:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
57
diff
changeset
|
339 * when the target is a tiff file it should be mmaped prior to format_raw_find as |
57f6da2510d9
Sun Jun 12 19:25:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
57
diff
changeset
|
340 * the make field data may not always be within header_data + header_len |
57f6da2510d9
Sun Jun 12 19:25:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
57
diff
changeset
|
341 */ |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
342 entry = format_raw_find(header_data, header_len); |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
343 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
344 if (!entry || !entry->func_parse) return FALSE; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
345 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
346 if (fstat(fd, &st) == -1) |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
347 { |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
348 printf("Failed to stat file %d\n", fd); |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
349 return FALSE; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
350 } |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
351 map_len = st.st_size; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
352 map_data = mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0); |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
353 if (map_data == MAP_FAILED) |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
354 { |
47
aa4c0e1b54b0
Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents:
46
diff
changeset
|
355 printf("Failed to mmap file %d\n", fd); |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
356 return FALSE; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
357 } |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
358 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
359 success = format_raw_parse(entry, map_data, map_len, image_offset, exif_offset); |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
360 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
361 if (munmap(map_data, map_len) == -1) |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
362 { |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
363 printf("Failed to unmap file %d\n", fd); |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
364 } |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
365 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
366 if (success && image_offset) |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
367 { |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
368 if (lseek(fd, *image_offset, SEEK_SET) != *image_offset) |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
369 { |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
370 printf("Failed to seek to embedded image\n"); |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
371 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
372 *image_offset = 0; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
373 if (*exif_offset) *exif_offset = 0; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
374 success = FALSE; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
375 } |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
376 } |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
377 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
378 return success; |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
379 } |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
380 |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
381 |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
382 static FormatExifEntry *format_exif_makernote_find(ExifData *exif, unsigned char *tiff, |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
383 guint offset, guint size) |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
384 { |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
385 ExifItem *make; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
386 gint n; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
387 |
181
c01dd7c9c7dc
unified tag names between exiv2 and internal rxif parser
nadvornik
parents:
177
diff
changeset
|
388 make = exif_get_item(exif, "Exif.Image.Make"); |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
389 |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
390 n = 0; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
391 while (format_exif_list[n].header_pattern) |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
392 { |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
393 switch (format_exif_list[n].header_type) |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
394 { |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
395 case FORMAT_EXIF_MATCH_MAKERNOTE: |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
396 if (format_exif_list[n].header_length + offset < size && |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
397 memcmp(tiff + offset, format_exif_list[n].header_pattern, |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
398 format_exif_list[n].header_length) == 0) |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
399 { |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
400 return &format_exif_list[n]; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
401 } |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
402 break; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
403 case FORMAT_EXIF_MATCH_MAKE: |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
404 if (make && |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
405 make->data_len >= format_exif_list[n].header_length && |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
406 memcmp(make->data, format_exif_list[n].header_pattern, |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
407 format_exif_list[n].header_length) == 0) |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
408 { |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
409 return &format_exif_list[n]; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
410 } |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
411 break; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
412 } |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
413 n++; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
414 } |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
415 |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
416 return FALSE; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
417 } |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
418 |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
419 gint format_exif_makernote_parse(ExifData *exif, unsigned char *tiff, guint offset, |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
420 guint size, ExifByteOrder bo) |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
421 { |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
422 FormatExifEntry *entry; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
423 |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
424 entry = format_exif_makernote_find(exif, tiff, offset, size); |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
425 |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
426 if (!entry || !entry->func_parse) return FALSE; |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
427 |
53
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
428 if (debug) printf("EXIF using makernote parser for %s\n", entry->description); |
00843150f7c8
Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents:
51
diff
changeset
|
429 |
54
b58cac75ad12
Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents:
53
diff
changeset
|
430 return entry->func_parse(exif, tiff, offset, size, bo); |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
431 } |
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
432 |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
433 /* |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
434 *----------------------------------------------------------------------------- |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
435 * Basic TIFF debugger, prints all IFD entries within tiff file |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
436 *----------------------------------------------------------------------------- |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
437 */ |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
438 #if DEBUG_RAW_TIFF |
51
276ea4c98d33
Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents:
47
diff
changeset
|
439 |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
440 static guint format_debug_tiff_table(unsigned char *data, const guint len, guint offset, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
441 ExifByteOrder bo, gint level); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
442 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
443 static void format_debug_tiff_entry(unsigned char *data, const guint len, guint offset, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
444 ExifByteOrder bo, gint level) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
445 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
446 guint tag; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
447 guint type; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
448 guint count; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
449 guint segment; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
450 guint seg_len; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
451 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
452 tag = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_TAG, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
453 type = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_FORMAT, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
454 count = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_COUNT, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
455 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
456 seg_len = ExifFormatList[type].size * count; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
457 if (seg_len > 4) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
458 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
459 segment = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_DATA, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
460 if (segment + seg_len > len) return; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
461 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
462 else |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
463 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
464 segment = offset + EXIF_TIFD_OFFSET_DATA; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
465 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
466 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
467 printf("%*stag:0x%04X (%05d), type:%2d %9s, len:%6d [%02X %02X %02X %02X] @ offset:%d\n", |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
468 level, "", tag, tag, type, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
469 (type < EXIF_FORMAT_COUNT) ? ExifFormatList[type].short_name : "???", count, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
470 data[segment], data[segment + 1], data[segment + 2], data[segment + 3], segment); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
471 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
472 if (tag == 0x8769 || tag == 0x14a) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
473 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
474 gint i; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
475 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
476 printf("%*s~~~ found %s table\n", level, "", (tag == 0x14a) ? "subIFD" : "EXIF" ); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
477 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
478 for (i = 0; i < count; i++) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
479 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
480 guint subset; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
481 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
482 subset = exif_byte_get_int32(data + segment + i * 4, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
483 format_debug_tiff_table(data, len, subset, bo, level + 1); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
484 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
485 } |
114
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
101
diff
changeset
|
486 else if (tag == 0x8773 && type == EXIF_FORMAT_UNDEFINED) |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
101
diff
changeset
|
487 { |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
101
diff
changeset
|
488 printf("%*s~~~ found ICC color profile at offset %d, length %d\n", level, "", segment, seg_len); |
50fc73e08550
Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents:
101
diff
changeset
|
489 } |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
490 else if (tag == 0x201 && (type == EXIF_FORMAT_LONG_UNSIGNED || type == EXIF_FORMAT_LONG)) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
491 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
492 guint subset = exif_byte_get_int32(data + segment, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
493 printf("%*s~~~ found jpeg data at offset %d\n", level, "", subset); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
494 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
495 else if (tag == 0x202 && (type == EXIF_FORMAT_LONG_UNSIGNED || type == EXIF_FORMAT_LONG)) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
496 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
497 guint subset = exif_byte_get_int32(data + segment, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
498 printf("%*s~~~ found jpeg data length of %d\n", level, "", subset); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
499 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
500 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
501 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
502 static guint format_debug_tiff_table(unsigned char *data, const guint len, guint offset, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
503 ExifByteOrder bo, gint level) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
504 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
505 guint count; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
506 guint i; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
507 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
508 if (level > EXIF_TIFF_MAX_LEVELS) return 0; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
509 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
510 if (len < offset + 2) return FALSE; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
511 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
512 count = exif_byte_get_int16(data + offset, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
513 offset += 2; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
514 if (len < offset + count * EXIF_TIFD_SIZE + 4) return 0; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
515 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
516 printf("%*s== tiff table #%d has %d entries ==\n", level, "", level, count); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
517 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
518 for (i = 0; i < count; i++) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
519 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
520 format_debug_tiff_entry(data, len, offset + i * EXIF_TIFD_SIZE, bo, level); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
521 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
522 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
523 printf("%*s----------- end of #%d ------------\n", level, "", level); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
524 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
525 return exif_byte_get_int32(data + offset + count * EXIF_TIFD_SIZE, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
526 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
527 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
528 gint format_debug_tiff_raw(unsigned char *data, const guint len, |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
529 guint *image_offset, guint *exif_offset) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
530 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
531 ExifByteOrder bo; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
532 gint level; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
533 guint offset; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
534 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
535 if (len < 8) return FALSE; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
536 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
537 /* for debugging, we are more relaxed as to magic header */ |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
538 if (memcmp(data, "II", 2) == 0) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
539 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
540 bo = EXIF_BYTE_ORDER_INTEL; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
541 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
542 else if (memcmp(data, "MM", 2) == 0) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
543 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
544 bo = EXIF_BYTE_ORDER_MOTOROLA; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
545 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
546 else |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
547 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
548 return FALSE; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
549 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
550 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
551 printf("*** debug parsing tiff\n"); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
552 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
553 offset = exif_byte_get_int32(data + 4, bo); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
554 level = 0; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
555 while (offset && level < EXIF_TIFF_MAX_LEVELS) |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
556 { |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
557 offset = format_debug_tiff_table(data, len, offset, bo, 0); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
558 level++; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
559 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
560 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
561 printf("*** end\n"); |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
562 |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
563 /* we are debugging, not trying to return any data */ |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
564 return FALSE; |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
565 } |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
566 #endif |
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
567 |
177 | 568 #endif |
569 /* not HAVE_EXIV2 */ | |
101
847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents:
59
diff
changeset
|
570 |