annotate src/format_raw.c @ 516:b7e99bfeadc9

Convert the minority of while() to while ().
author zas_
date Thu, 24 Apr 2008 15:49:57 +0000
parents 135570a8bd96
children 116346636d42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
1 /*
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
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
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 446
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
5 *
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
6 * Authors:
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
7 * Original version 2005 Lars Ellenberg, base on dcraw by David coffin.
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
8 *
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
9 * This software is released under the GNU General Public License (GNU GPL).
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
10 * Please read the included file COPYING for more information.
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
11 * This software comes with no warranty of any kind, use at your own risk!
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
12 */
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
13
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
14 #ifdef HAVE_CONFIG_H
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
15 # include "config.h"
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
16 #endif
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
17
177
0ca3b4c8ffae started exiv2 integration
nadvornik
parents: 138
diff changeset
18 #ifndef HAVE_EXIV2
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
19
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
20 #include <stdio.h>
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
21 #include <string.h>
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
22 #include <unistd.h>
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
23 #include <sys/types.h>
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
24 #include <sys/stat.h>
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
25 #include <sys/mman.h>
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
26
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
27 #include <glib.h>
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
28
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
29 #include "intl.h"
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
30
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 277
diff changeset
31 #include "main.h"
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
32 #include "format_raw.h"
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
33
507
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents: 506
diff changeset
34 #include "debug.h"
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
35 #include "format_canon.h"
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
36 #include "format_fuji.h"
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
37 #include "format_nikon.h"
57
a8c9992320f4 Fri Jun 10 20:57:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
38 #include "format_olympus.h"
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
39
53
00843150f7c8 Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents: 51
diff changeset
40
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
41 typedef struct _FormatRawEntry FormatRawEntry;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
42 struct _FormatRawEntry {
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
43 const gchar *extension;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
44 FormatRawMatchType magic_type;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
45 const guint magic_offset;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
46 const void *magic_pattern;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
47 const guint magic_length;
101
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
48 const FormatRawExifType exif_type;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
49 FormatRawExifParseFunc exif_func;
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
50 const gchar *description;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
51 FormatRawParseFunc func_parse;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
52 };
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
53
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
54 static FormatRawEntry format_raw_list[] = {
101
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
55 #if DEBUG_RAW_TIFF
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
56 FORMAT_RAW_DEBUG_TIFF,
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
57 #endif
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
58 FORMAT_RAW_CANON,
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
59 FORMAT_RAW_FUJI,
53
00843150f7c8 Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents: 51
diff changeset
60 FORMAT_RAW_NIKON,
101
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
61 FORMAT_RAW_OLYMPUS,
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
62 FORMAT_RAW_PENTAX,
277
9de0f88b2b91 Add support for some Samsung raw files (.pef).
zas_
parents: 227
diff changeset
63 FORMAT_RAW_SAMSUNG,
101
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
64 { 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
65 };
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
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
68 typedef struct _FormatExifEntry FormatExifEntry;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
69 struct _FormatExifEntry {
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
70 FormatExifMatchType header_type;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
71 const void *header_pattern;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
72 const guint header_length;
53
00843150f7c8 Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents: 51
diff changeset
73 const gchar *description;
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
74 FormatExifParseFunc func_parse;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
75 };
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 static FormatExifEntry format_exif_list[] = {
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
78 FORMAT_EXIF_CANON,
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
79 FORMAT_EXIF_FUJI,
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
80 FORMAT_EXIF_NIKON,
57
a8c9992320f4 Fri Jun 10 20:57:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
81 FORMAT_EXIF_OLYMPUS,
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
82 { 0, NULL, 0, NULL }
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
83 };
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
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
86 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
87 guint tag, ExifFormatType type,
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
88 guint *result_offset, guint *result_count)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
89 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
90 guint count;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
91 guint i;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
92
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
93 if (len < offset + 2) return 0;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
94 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
95
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
96 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
97 offset += 2;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
98 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
99
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
100 for (i = 0; i < count; i++)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
101 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
102 guint segment;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
103
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
104 segment = offset + i * 12;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
105 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
106 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
107 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
108 guint chunk_count;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
109 guint chunk_offset;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
110 guint chunk_length;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
111
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
112 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
113 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
114
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
115 if (chunk_length > 4)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
116 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
117 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
118 }
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
119 else
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
120 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
121 chunk_offset = segment + 8;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
122 }
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 if (chunk_offset + chunk_length <= len)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
125 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
126 *result_offset = chunk_offset;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
127 *result_count = chunk_count;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
128 }
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 return 0;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
131 }
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 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
135 }
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 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
138 guint tag, ExifFormatType type,
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
139 guint *result_offset, guint *result_count)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
140 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
141 ExifByteOrder bo;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
142 guint offset;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
143
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
144 if (len < 8) return FALSE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
145
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
146 if (memcmp(data, "II", 2) == 0)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
147 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
148 bo = EXIF_BYTE_ORDER_INTEL;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
149 }
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
150 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
151 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
152 bo = EXIF_BYTE_ORDER_MOTOROLA;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
153 }
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
154 else
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
155 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
156 return FALSE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
157 }
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 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
160 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
161 return FALSE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
162 }
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 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
165
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
166 while (offset != 0)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
167 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
168 guint ro = 0;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
169 guint rc = 0;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
170
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
171 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
172 if (ro != 0)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
173 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
174 *result_offset = ro;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
175 *result_count = rc;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
176 return TRUE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
177 }
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 return FALSE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
181 }
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 static FormatRawEntry *format_raw_find(unsigned char *data, const guint len)
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
184 {
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
185 gint n;
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
186 gint tiff;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
187 guint make_count = 0;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
188 guint make_offset = 0;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
189
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
190 tiff = (len > 8 &&
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
191 (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
192 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
193
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
194 n = 0;
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
195 while (format_raw_list[n].magic_pattern)
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
196 {
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
197 FormatRawEntry *entry = &format_raw_list[n];
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
198
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
199 switch (entry->magic_type)
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
200 {
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
201 case FORMAT_RAW_MATCH_MAGIC:
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
202 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
203 memcmp(data + entry->magic_offset,
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
204 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
205 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
206 return entry;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
207 }
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
208 break;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
209 case FORMAT_RAW_MATCH_TIFF_MAKE:
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
210 if (tiff &&
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
211 make_offset == 0 &&
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
212 !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
213 &make_offset, &make_count))
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
214 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
215 tiff = FALSE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
216 }
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
217 if (make_offset != 0 &&
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
218 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
219 memcmp(entry->magic_pattern,
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
220 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
221 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
222 return entry;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
223 }
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
224 break;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
225 default:
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
226 break;
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
227 }
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
228 n++;
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
229 }
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
230
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
231 return NULL;
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
232 }
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
233
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
234 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
235 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
236 guint *image_offset, guint *exif_offset)
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
237 {
46
905f8fa583a3 Thu May 26 22:14:53 2005 John Ellis <johne@verizon.net>
gqview
parents: 45
diff changeset
238 guint io = 0;
905f8fa583a3 Thu May 26 22:14:53 2005 John Ellis <johne@verizon.net>
gqview
parents: 45
diff changeset
239 guint eo = 0;
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
240 gint found;
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
241
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
242 if (!entry || !entry->func_parse) return FALSE;
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
243
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
244 DEBUG_1("RAW using file parser for %s", entry->description);
53
00843150f7c8 Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents: 51
diff changeset
245
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
246 found = entry->func_parse(data, len, &io, &eo);
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
247
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
248 if (!found ||
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
249 io >= len - 4 ||
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
250 eo >= len)
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
251 {
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
252 return FALSE;
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
253 }
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
254
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
255 if (image_offset) *image_offset = io;
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
256 if (exif_offset) *exif_offset = eo;
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
257
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
258 return TRUE;
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
259 }
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
260
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
261 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
262 guint *image_offset, guint *exif_offset)
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
263 {
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
264 FormatRawEntry *entry;
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
265
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
266 if (!data || len < 1) return FALSE;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
267
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
268 entry = format_raw_find(data, len);
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
269
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
270 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
271
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
272 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
273 }
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
274
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
275
101
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
276 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
277 FormatRawExifParseFunc *exif_parse_func)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
278 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
279 FormatRawEntry *entry;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
280
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
281 if (!data || len < 1) return FALSE;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
282
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
283 entry = format_raw_find(data, len);
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
284
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
285 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
286
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
287 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
288
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
289 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
290 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
291 *exif_parse_func = entry->exif_func;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
292 }
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 return entry->exif_type;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
295 }
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
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
298 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
299 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
300 guint *image_offset, guint *exif_offset)
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
301 {
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
302 FormatRawEntry *entry;
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
303 void *map_data = NULL;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
304 size_t map_len = 0;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
305 struct stat st;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
306 gint success;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
307
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
308 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
309
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
310 /* 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
311 if (path)
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
312 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
313 const gchar *ext;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
314 gint match = FALSE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
315 gint i;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
316
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
317 ext = strrchr(path, '.');
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
318 if (!ext) return FALSE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
319 ext++;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
320
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
321 i = 0;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
322 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
323 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
324 if (format_raw_list[i].extension &&
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
325 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
326 {
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
327 match = TRUE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
328 }
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
329 i++;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
330 }
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 if (!match) return FALSE;
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
333
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
334 DEBUG_1("RAW file parser extension match");
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
335 }
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
336
59
57f6da2510d9 Sun Jun 12 19:25:26 2005 John Ellis <johne@verizon.net>
gqview
parents: 57
diff changeset
337 /* FIXME:
57f6da2510d9 Sun Jun 12 19:25:26 2005 John Ellis <johne@verizon.net>
gqview
parents: 57
diff changeset
338 * 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
339 * the make field data may not always be within header_data + header_len
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
340 */
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
341 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
342
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
343 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
344
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
345 if (fstat(fd, &st) == -1)
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
346 {
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
347 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
348 return FALSE;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
349 }
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
350 map_len = st.st_size;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
351 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
352 if (map_data == MAP_FAILED)
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
353 {
47
aa4c0e1b54b0 Fri Jun 3 01:49:20 2005 John Ellis <johne@verizon.net>
gqview
parents: 46
diff changeset
354 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
355 return FALSE;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
356 }
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 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
359
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
360 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
361 {
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
362 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
363 }
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 if (success && image_offset)
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
366 {
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
367 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
368 {
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
369 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
370
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
371 *image_offset = 0;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
372 if (*exif_offset) *exif_offset = 0;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
373 success = FALSE;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
374 }
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 return success;
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
378 }
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
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
381 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
382 guint offset, guint size)
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
383 {
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
384 ExifItem *make;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
385 gint n;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
386
181
c01dd7c9c7dc unified tag names between exiv2 and internal rxif parser
nadvornik
parents: 177
diff changeset
387 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
388
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
389 n = 0;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
390 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
391 {
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
392 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
393 {
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
394 case FORMAT_EXIF_MATCH_MAKERNOTE:
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
395 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
396 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
397 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
398 {
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
399 return &format_exif_list[n];
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
400 }
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
401 break;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
402 case FORMAT_EXIF_MATCH_MAKE:
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
403 if (make &&
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
404 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
405 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
406 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
407 {
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
408 return &format_exif_list[n];
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
409 }
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
410 break;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
411 }
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
412 n++;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
413 }
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 return FALSE;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
416 }
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 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
419 guint size, ExifByteOrder bo)
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
420 {
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
421 FormatExifEntry *entry;
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
422
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
423 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
424
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
425 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
426
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 495
diff changeset
427 DEBUG_1("EXIF using makernote parser for %s", entry->description);
53
00843150f7c8 Tue Jun 7 03:47:03 2005 John Ellis <johne@verizon.net>
gqview
parents: 51
diff changeset
428
54
b58cac75ad12 Thu Jun 9 22:23:18 2005 John Ellis <johne@verizon.net>
gqview
parents: 53
diff changeset
429 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
430 }
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
431
101
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
432 /*
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 * 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
435 *-----------------------------------------------------------------------------
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 #if DEBUG_RAW_TIFF
51
276ea4c98d33 Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net>
gqview
parents: 47
diff changeset
438
101
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
439 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
440 ExifByteOrder bo, gint level);
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
441
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
442 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
443 ExifByteOrder bo, gint level)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
444 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
445 guint tag;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
446 guint type;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
447 guint count;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
448 guint segment;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
449 guint seg_len;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
450
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
451 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
452 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
453 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
454
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
455 seg_len = ExifFormatList[type].size * count;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
456 if (seg_len > 4)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
457 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
458 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
459 if (segment + seg_len > len) return;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
460 }
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
461 else
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
462 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
463 segment = offset + EXIF_TIFD_OFFSET_DATA;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
464 }
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 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
467 level, "", tag, tag, type,
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
468 (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
469 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
470
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
471 if (tag == 0x8769 || tag == 0x14a)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
472 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
473 gint i;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
474
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
475 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
476
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
477 for (i = 0; i < count; i++)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
478 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
479 guint subset;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
480
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
481 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
482 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
483 }
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
484 }
114
50fc73e08550 Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents: 101
diff changeset
485 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
486 {
50fc73e08550 Mon Nov 27 01:23:23 2006 John Ellis <johne@verizon.net>
gqview
parents: 101
diff changeset
487 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
488 }
101
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
489 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
490 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
491 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
492 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
493 }
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
494 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
495 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
496 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
497 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
498 }
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 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
502 ExifByteOrder bo, gint level)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
503 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
504 guint count;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
505 guint i;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
506
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
507 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
508
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
509 if (len < offset + 2) return FALSE;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
510
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
511 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
512 offset += 2;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
513 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
514
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
515 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
516
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
517 for (i = 0; i < count; i++)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
518 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
519 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
520 }
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 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
523
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
524 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
525 }
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 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
528 guint *image_offset, guint *exif_offset)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
529 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
530 ExifByteOrder bo;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
531 gint level;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
532 guint offset;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
533
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
534 if (len < 8) return FALSE;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
535
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
536 /* 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
537 if (memcmp(data, "II", 2) == 0)
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
538 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
539 bo = EXIF_BYTE_ORDER_INTEL;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
540 }
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
541 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
542 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
543 bo = EXIF_BYTE_ORDER_MOTOROLA;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
544 }
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
545 else
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
546 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
547 return FALSE;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
548 }
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 printf("*** debug parsing tiff\n");
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
551
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
552 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
553 level = 0;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
554 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
555 {
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
556 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
557 level++;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
558 }
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 printf("*** end\n");
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
561
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
562 /* 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
563 return FALSE;
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
564 }
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
565 #endif
847e4bc6b54c Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
gqview
parents: 59
diff changeset
566
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 281
diff changeset
567 #endif
177
0ca3b4c8ffae started exiv2 integration
nadvornik
parents: 138
diff changeset
568 /* not HAVE_EXIV2 */