diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Makefile.am | 15 | ||||
-rw-r--r-- | src/plugins/tiff_extractor.c (renamed from src/plugins/tiffextractor.c) | 107 |
2 files changed, 71 insertions, 51 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 91f8d6b..156a1b5 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am | |||
@@ -94,6 +94,7 @@ plugin_LTLIBRARIES = \ | |||
94 | $(rpm) \ | 94 | $(rpm) \ |
95 | libextractor_tar.la \ | 95 | libextractor_tar.la \ |
96 | $(thumbgtk) \ | 96 | $(thumbgtk) \ |
97 | libextractor_tiff.la \ | ||
97 | libextractor_wav.la \ | 98 | libextractor_wav.la \ |
98 | libextractor_zip.la | 99 | libextractor_zip.la |
99 | 100 | ||
@@ -283,6 +284,13 @@ libextractor_thumbnailgtk_la_LDFLAGS = \ | |||
283 | libextractor_thumbnailgtk_la_SOURCES = \ | 284 | libextractor_thumbnailgtk_la_SOURCES = \ |
284 | thumbnailgtk_extractor.c | 285 | thumbnailgtk_extractor.c |
285 | 286 | ||
287 | libextractor_tiff_la_SOURCES = \ | ||
288 | tiff_extractor.c | ||
289 | libextractor_tiff_la_LDFLAGS = \ | ||
290 | $(PLUGINFLAGS) | ||
291 | libextractor_tiff_la_LIBADD = \ | ||
292 | $(top_builddir)/src/common/libextractor_common.la | ||
293 | |||
286 | libextractor_wav_la_SOURCES = \ | 294 | libextractor_wav_la_SOURCES = \ |
287 | wav_extractor.c | 295 | wav_extractor.c |
288 | libextractor_wav_la_LDFLAGS = \ | 296 | libextractor_wav_la_LDFLAGS = \ |
@@ -315,7 +323,6 @@ OLD_LIBS = \ | |||
315 | libextractor_s3m.la \ | 323 | libextractor_s3m.la \ |
316 | libextractor_sid.la \ | 324 | libextractor_sid.la \ |
317 | libextractor_tar.la \ | 325 | libextractor_tar.la \ |
318 | libextractor_tiff.la \ | ||
319 | $(thumbqt) \ | 326 | $(thumbqt) \ |
320 | libextractor_xm.la \ | 327 | libextractor_xm.la \ |
321 | libextractor_zip.la | 328 | libextractor_zip.la |
@@ -342,12 +349,6 @@ libextractor_id3v24_la_LDFLAGS = \ | |||
342 | libextractor_id3v24_la_LIBADD = \ | 349 | libextractor_id3v24_la_LIBADD = \ |
343 | $(top_builddir)/src/common/libextractor_common.la | 350 | $(top_builddir)/src/common/libextractor_common.la |
344 | 351 | ||
345 | libextractor_tiff_la_SOURCES = \ | ||
346 | tiffextractor.c | ||
347 | libextractor_tiff_la_LDFLAGS = \ | ||
348 | $(PLUGINFLAGS) | ||
349 | libextractor_tiff_la_LIBADD = \ | ||
350 | $(top_builddir)/src/common/libextractor_common.la | ||
351 | 352 | ||
352 | libextractor_riff_la_SOURCES = \ | 353 | libextractor_riff_la_SOURCES = \ |
353 | riffextractor.c | 354 | riffextractor.c |
diff --git a/src/plugins/tiffextractor.c b/src/plugins/tiff_extractor.c index 420f08e..6f226a1 100644 --- a/src/plugins/tiffextractor.c +++ b/src/plugins/tiff_extractor.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libextractor. | 2 | This file is part of libextractor. |
3 | (C) 2004 Vidyut Samanta and Christian Grothoff | 3 | (C) 2004, 2009 Vidyut Samanta and Christian Grothoff |
4 | 4 | ||
5 | libextractor is free software; you can redistribute it and/or modify | 5 | libextractor is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -24,16 +24,19 @@ | |||
24 | 24 | ||
25 | #define DEBUG 0 | 25 | #define DEBUG 0 |
26 | 26 | ||
27 | static void | 27 | static int |
28 | addKeyword (struct EXTRACTOR_Keywords **list, | 28 | addKeyword (EXTRACTOR_MetaDataProcessor proc, |
29 | char *keyword, EXTRACTOR_KeywordType type) | 29 | void *proc_cls, |
30 | const char *keyword, | ||
31 | enum EXTRACTOR_MetaType type) | ||
30 | { | 32 | { |
31 | EXTRACTOR_KeywordList *next; | 33 | return proc (proc_cls, |
32 | next = malloc (sizeof (EXTRACTOR_KeywordList)); | 34 | "tiff", |
33 | next->next = *list; | 35 | type, |
34 | next->keyword = keyword; | 36 | EXTRACTOR_METAFORMAT_UTF8, |
35 | next->keywordType = type; | 37 | "text/plain", |
36 | *list = next; | 38 | keyword, |
39 | strlen(keyword)+1); | ||
37 | } | 40 | } |
38 | 41 | ||
39 | typedef struct | 42 | typedef struct |
@@ -88,28 +91,32 @@ static char *DIRECTORY_ENTRY_SPECS[] = { | |||
88 | #define TYPE_LONG 4 | 91 | #define TYPE_LONG 4 |
89 | #define TYPE_RATIONAL 5 | 92 | #define TYPE_RATIONAL 5 |
90 | 93 | ||
91 | static void | 94 | static int |
92 | addASCII (struct EXTRACTOR_Keywords **prev, | 95 | addASCII (EXTRACTOR_MetaDataProcessor proc, |
93 | char *data, | 96 | void *proc_cls, |
94 | size_t size, DIRECTORY_ENTRY * entry, EXTRACTOR_KeywordType type) | 97 | const char *data, |
98 | size_t size, DIRECTORY_ENTRY * entry, | ||
99 | enum EXTRACTOR_MetaType type) | ||
95 | { | 100 | { |
96 | if (entry->count > size) | 101 | if (entry->count > size) |
97 | return; /* invalid! */ | 102 | return 0; /* invalid! */ |
98 | if (entry->type != TYPE_ASCII) | 103 | if (entry->type != TYPE_ASCII) |
99 | return; /* huh? */ | 104 | return 0; /* huh? */ |
100 | if (entry->count + entry->value_or_offset > size) | 105 | if (entry->count + entry->value_or_offset > size) |
101 | return; | 106 | return 0; |
102 | if (data[entry->value_or_offset + entry->count - 1] != 0) | 107 | if (data[entry->value_or_offset + entry->count - 1] != 0) |
103 | return; | 108 | return 0; |
104 | addKeyword (prev, | 109 | return addKeyword (proc, proc_cls, |
105 | strdup (&data[entry->value_or_offset]), type); | 110 | &data[entry->value_or_offset], type); |
106 | } | 111 | } |
107 | 112 | ||
108 | 113 | ||
109 | struct EXTRACTOR_Keywords * | 114 | int |
110 | libextractor_tiff_extract (char *filename, | 115 | EXTRACTOR_tiff_extract (const char *data, |
111 | char *data, | 116 | size_t size, |
112 | size_t size, struct EXTRACTOR_Keywords *prev) | 117 | EXTRACTOR_MetaDataProcessor proc, |
118 | void *proc_cls, | ||
119 | const char *options) | ||
113 | { | 120 | { |
114 | TIFF_HEADER hdr; | 121 | TIFF_HEADER hdr; |
115 | int byteOrder; /* 0: do not convert; | 122 | int byteOrder; /* 0: do not convert; |
@@ -119,22 +126,23 @@ libextractor_tiff_extract (char *filename, | |||
119 | unsigned int width = -1; | 126 | unsigned int width = -1; |
120 | 127 | ||
121 | if (size < TIFF_HEADER_SIZE) | 128 | if (size < TIFF_HEADER_SIZE) |
122 | return prev; /* can not be tiff */ | 129 | return 0; /* can not be tiff */ |
123 | if ((data[0] == 0x49) && (data[1] == 0x49)) | 130 | if ((data[0] == 0x49) && (data[1] == 0x49)) |
124 | byteOrder = 0; | 131 | byteOrder = 0; |
125 | else if ((data[0] == 0x4D) && (data[1] == 0x4D)) | 132 | else if ((data[0] == 0x4D) && (data[1] == 0x4D)) |
126 | byteOrder = 1; | 133 | byteOrder = 1; |
127 | else | 134 | else |
128 | return prev; /* can not be tiff */ | 135 | return 0; /* can not be tiff */ |
129 | #if __BYTE_ORDER == __BIG_ENDIAN | 136 | #if __BYTE_ORDER == __BIG_ENDIAN |
130 | byteOrder = 1 - byteOrder; | 137 | byteOrder = 1 - byteOrder; |
131 | #endif | 138 | #endif |
132 | EXTRACTOR_common_cat_unpack (data, TIFF_HEADER_SPECS[byteOrder], TIFF_HEADER_FIELDS (&hdr)); | 139 | EXTRACTOR_common_cat_unpack (data, TIFF_HEADER_SPECS[byteOrder], TIFF_HEADER_FIELDS (&hdr)); |
133 | if (hdr.fourty_two != 42) | 140 | if (hdr.fourty_two != 42) |
134 | return prev; /* can not be tiff */ | 141 | return 0; /* can not be tiff */ |
135 | if (hdr.ifd_offset + 6 > size) | 142 | if (hdr.ifd_offset + 6 > size) |
136 | return prev; /* malformed tiff */ | 143 | return 0; /* malformed tiff */ |
137 | addKeyword (&prev, strdup ("image/tiff"), EXTRACTOR_MIMETYPE); | 144 | if (0 != addKeyword (proc, proc_cls, "image/tiff", EXTRACTOR_METATYPE_MIMETYPE)) |
145 | return 1; | ||
138 | current_ifd = hdr.ifd_offset; | 146 | current_ifd = hdr.ifd_offset; |
139 | while (current_ifd != 0) | 147 | while (current_ifd != 0) |
140 | { | 148 | { |
@@ -143,7 +151,7 @@ libextractor_tiff_extract (char *filename, | |||
143 | int i; | 151 | int i; |
144 | if ( (current_ifd + 6 > size) || | 152 | if ( (current_ifd + 6 > size) || |
145 | (current_ifd + 6 < current_ifd) ) | 153 | (current_ifd + 6 < current_ifd) ) |
146 | return prev; | 154 | return 0; |
147 | if (byteOrder == 0) | 155 | if (byteOrder == 0) |
148 | len = data[current_ifd + 1] << 8 | data[current_ifd]; | 156 | len = data[current_ifd + 1] << 8 | data[current_ifd]; |
149 | else | 157 | else |
@@ -153,7 +161,7 @@ libextractor_tiff_extract (char *filename, | |||
153 | #if DEBUG | 161 | #if DEBUG |
154 | printf ("WARNING: malformed tiff\n"); | 162 | printf ("WARNING: malformed tiff\n"); |
155 | #endif | 163 | #endif |
156 | return prev; | 164 | return 0; |
157 | } | 165 | } |
158 | for (i = 0; i < len; i++) | 166 | for (i = 0; i < len; i++) |
159 | { | 167 | { |
@@ -177,9 +185,10 @@ libextractor_tiff_extract (char *filename, | |||
177 | if (width != -1) | 185 | if (width != -1) |
178 | { | 186 | { |
179 | char tmp[128]; | 187 | char tmp[128]; |
180 | snprintf (tmp, 128, "%ux%u", | 188 | snprintf (tmp, |
189 | sizeof(tmp), "%ux%u", | ||
181 | width, length); | 190 | width, length); |
182 | addKeyword (&prev, strdup (tmp), EXTRACTOR_SIZE); | 191 | addKeyword (proc, proc_cls, strdup (tmp), EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); |
183 | } | 192 | } |
184 | break; | 193 | break; |
185 | case TAG_WIDTH: | 194 | case TAG_WIDTH: |
@@ -190,34 +199,44 @@ libextractor_tiff_extract (char *filename, | |||
190 | if (length != -1) | 199 | if (length != -1) |
191 | { | 200 | { |
192 | char tmp[128]; | 201 | char tmp[128]; |
193 | snprintf (tmp, 128, "%ux%u", | 202 | snprintf (tmp, |
203 | sizeof(tmp), | ||
204 | "%ux%u", | ||
194 | width, length); | 205 | width, length); |
195 | addKeyword (&prev, strdup (tmp), EXTRACTOR_SIZE); | 206 | addKeyword (proc, proc_cls, strdup (tmp), EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); |
196 | } | 207 | } |
197 | break; | 208 | break; |
198 | case TAG_SOFTWARE: | 209 | case TAG_SOFTWARE: |
199 | addASCII (&prev, data, size, &entry, EXTRACTOR_SOFTWARE); | 210 | if (0 != addASCII (proc, proc_cls, data, size, &entry, EXTRACTOR_METATYPE_SOFTWARE)) |
211 | return 1; | ||
200 | break; | 212 | break; |
201 | case TAG_ARTIST: | 213 | case TAG_ARTIST: |
202 | addASCII (&prev, data, size, &entry, EXTRACTOR_ARTIST); | 214 | if (0 != addASCII (proc, proc_cls, data, size, &entry, EXTRACTOR_METATYPE_ARTIST)) |
215 | return 1; | ||
203 | break; | 216 | break; |
204 | case TAG_DOCUMENT_NAME: | 217 | case TAG_DOCUMENT_NAME: |
205 | addASCII (&prev, data, size, &entry, EXTRACTOR_TITLE); | 218 | if (0 != addASCII (proc, proc_cls, data, size, &entry, EXTRACTOR_METATYPE_TITLE)) |
219 | return 1; | ||
206 | break; | 220 | break; |
207 | case TAG_COPYRIGHT: | 221 | case TAG_COPYRIGHT: |
208 | addASCII (&prev, data, size, &entry, EXTRACTOR_COPYRIGHT); | 222 | if (0 != addASCII (proc, proc_cls, data, size, &entry, EXTRACTOR_METATYPE_COPYRIGHT)) |
223 | return 1; | ||
209 | break; | 224 | break; |
210 | case TAG_DESCRIPTION: | 225 | case TAG_DESCRIPTION: |
211 | addASCII (&prev, data, size, &entry, EXTRACTOR_DESCRIPTION); | 226 | if (0 != addASCII (proc, proc_cls, data, size, &entry, EXTRACTOR_METATYPE_DESCRIPTION)) |
227 | return 1; | ||
212 | break; | 228 | break; |
213 | case TAG_HOST: | 229 | case TAG_HOST: |
214 | addASCII (&prev, data, size, &entry, EXTRACTOR_BUILDHOST); | 230 | if (0 != addASCII (proc, proc_cls, data, size, &entry, EXTRACTOR_METATYPE_BUILDHOST)) |
231 | return 1; | ||
215 | break; | 232 | break; |
216 | case TAG_SCANNER: | 233 | case TAG_SCANNER: |
217 | addASCII (&prev, data, size, &entry, EXTRACTOR_SOURCE); | 234 | if (0 != addASCII (proc, proc_cls, data, size, &entry, EXTRACTOR_METATYPE_SOURCE)) |
235 | return 1; | ||
218 | break; | 236 | break; |
219 | case TAG_DAYTIME: | 237 | case TAG_DAYTIME: |
220 | addASCII (&prev, data, size, &entry, EXTRACTOR_CREATION_DATE); | 238 | if (0 != addASCII (proc, proc_cls, data, size, &entry, EXTRACTOR_METATYPE_CREATION_DATE)) |
239 | return 1; | ||
221 | break; | 240 | break; |
222 | } | 241 | } |
223 | } | 242 | } |
@@ -232,5 +251,5 @@ libextractor_tiff_extract (char *filename, | |||
232 | data[off] << 24 | data[off + 1] << 16 | | 251 | data[off] << 24 | data[off + 1] << 16 | |
233 | data[off + 2] << 8 | data[off + 3]; | 252 | data[off + 2] << 8 | data[off + 3]; |
234 | } | 253 | } |
235 | return prev; | 254 | return 0; |
236 | } | 255 | } |