comparison src/format_raw.c @ 51:276ea4c98d33

Sat Jun 4 22:24:00 2005 John Ellis <johne@verizon.net> * exif.[ch]: Use glib provided data types and byte order functions for consistency with rest of application. Made several more functions available in the header. Use MakerNote parsing from format_raw.c. * format_canon.[ch]: Changes to match exif.h and format_raw.h. * format_fuji.[ch]: Add support for Fuji EXIF MakerNote. * format_nikon.[ch]: New files, add support for Nikon EXIF MakerNote. * format_raw.[ch]: Add EXIF MakerNote parser functions to gather all camera formats here (similar to existing raw format list). * src/Makefile.am: Add format_nikon.[ch]. ##### Note: GQview CVS on sourceforge is not always up to date, please use ##### ##### an offical release when making enhancements and translation updates. #####
author gqview
date Sun, 05 Jun 2005 02:48:54 +0000
parents aa4c0e1b54b0
children 00843150f7c8
comparison
equal deleted inserted replaced
50:3b83fb81afc4 51:276ea4c98d33
28 28
29 #include "format_raw.h" 29 #include "format_raw.h"
30 30
31 #include "format_canon.h" 31 #include "format_canon.h"
32 #include "format_fuji.h" 32 #include "format_fuji.h"
33 33 #include "format_nikon.h"
34 34
35 typedef struct _FormatEntry FormatEntry; 35
36 struct _FormatEntry { 36 typedef struct _FormatRawEntry FormatRawEntry;
37 struct _FormatRawEntry {
37 const void *header_pattern; 38 const void *header_pattern;
38 const guint header_length; 39 const guint header_length;
39 const gchar *description; 40 const gchar *description;
40 FormatRawParseFunc func_parse; 41 FormatRawParseFunc func_parse;
41 }; 42 };
42 43
43 44 static FormatRawEntry format_raw_list[] = {
44 static FormatEntry format_list[] = {
45 FORMAT_RAW_CANON, 45 FORMAT_RAW_CANON,
46 FORMAT_RAW_FUJI, 46 FORMAT_RAW_FUJI,
47 { NULL, 0, NULL, NULL } 47 { NULL, 0, NULL, NULL }
48 }; 48 };
49 49
50 50
51 static FormatEntry *format_raw_find(const void *data, const guint len) 51 typedef struct _FormatExifEntry FormatExifEntry;
52 struct _FormatExifEntry {
53 FormatExifMatchType header_type;
54 const void *header_pattern;
55 const guint header_length;
56 FormatExifParseFunc func_parse;
57 };
58
59 static FormatExifEntry format_exif_list[] = {
60 FORMAT_EXIF_CANON,
61 FORMAT_EXIF_FUJI,
62 FORMAT_EXIF_NIKON,
63 { 0, NULL, 0, NULL }
64 };
65
66
67 static FormatRawEntry *format_raw_find(const void *data, const guint len)
52 { 68 {
53 gint n; 69 gint n;
54 70
55 n = 0; 71 n = 0;
56 while (format_list[n].header_pattern) 72 while (format_raw_list[n].header_pattern)
57 { 73 {
58 if (format_list[n].header_length <= len && 74 if (format_raw_list[n].header_length <= len &&
59 memcmp(data, format_list[n].header_pattern, format_list[n].header_length) == 0) 75 memcmp(data, format_raw_list[n].header_pattern, format_raw_list[n].header_length) == 0)
60 { 76 {
61 return &format_list[n]; 77 return &format_raw_list[n];
62 } 78 }
63 n++; 79 n++;
64 } 80 }
65 81
66 return NULL; 82 return NULL;
67 } 83 }
68 84
69 static gint format_raw_parse(FormatEntry *entry, 85 static gint format_raw_parse(FormatRawEntry *entry,
70 const void *data, const guint len, 86 const void *data, const guint len,
71 guint *image_offset, guint *exif_offset) 87 guint *image_offset, guint *exif_offset)
72 { 88 {
73 guint io = 0; 89 guint io = 0;
74 guint eo = 0; 90 guint eo = 0;
92 } 108 }
93 109
94 gint format_raw_img_exif_offsets(const void *data, const guint len, 110 gint format_raw_img_exif_offsets(const void *data, const guint len,
95 guint *image_offset, guint *exif_offset) 111 guint *image_offset, guint *exif_offset)
96 { 112 {
97 FormatEntry *entry; 113 FormatRawEntry *entry;
98 114
99 if (!data || len < 1) return FALSE; 115 if (!data || len < 1) return FALSE;
100 116
101 entry = format_raw_find(data, len); 117 entry = format_raw_find(data, len);
102 118
107 123
108 124
109 gint format_raw_img_exif_offsets_fd(int fd, const void *header_data, const guint header_len, 125 gint format_raw_img_exif_offsets_fd(int fd, const void *header_data, const guint header_len,
110 guint *image_offset, guint *exif_offset) 126 guint *image_offset, guint *exif_offset)
111 { 127 {
112 FormatEntry *entry; 128 FormatRawEntry *entry;
113 void *map_data = NULL; 129 void *map_data = NULL;
114 size_t map_len = 0; 130 size_t map_len = 0;
115 struct stat st; 131 struct stat st;
116 gint success; 132 gint success;
117 133
155 171
156 return success; 172 return success;
157 } 173 }
158 174
159 175
176 static FormatExifEntry *format_exif_makernote_find(ExifData *exif, unsigned char *tiff,
177 guint offset, guint size)
178 {
179 ExifItem *make;
180 gint n;
181
182 make = exif_get_item(exif, "Make");
183
184 n = 0;
185 while (format_exif_list[n].header_pattern)
186 {
187 switch (format_exif_list[n].header_type)
188 {
189 case FORMAT_EXIF_MATCH_MAKERNOTE:
190 if (format_exif_list[n].header_length + offset < size &&
191 memcmp(tiff + offset, format_exif_list[n].header_pattern,
192 format_exif_list[n].header_length) == 0)
193 {
194 return &format_exif_list[n];
195 }
196 break;
197 case FORMAT_EXIF_MATCH_MAKE:
198 if (make &&
199 make->data_len >= format_exif_list[n].header_length &&
200 memcmp(make->data, format_exif_list[n].header_pattern,
201 format_exif_list[n].header_length) == 0)
202 {
203 return &format_exif_list[n];
204 }
205 break;
206 }
207 n++;
208 }
209
210 return FALSE;
211 }
212
213 gint format_exif_makernote_parse(ExifData *exif, unsigned char *tiff, guint offset,
214 guint size, ExifByteOrder byte_order)
215 {
216 FormatExifEntry *entry;
217
218 entry = format_exif_makernote_find(exif, tiff, offset, size);
219
220 if (!entry || !entry->func_parse) return FALSE;
221
222 return entry->func_parse(exif, tiff, offset, size, byte_order);
223 }
224
225