aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/tiff_extractor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/tiff_extractor.c')
-rw-r--r--src/plugins/tiff_extractor.c123
1 files changed, 62 insertions, 61 deletions
diff --git a/src/plugins/tiff_extractor.c b/src/plugins/tiff_extractor.c
index 82ba94f..163bd80 100644
--- a/src/plugins/tiff_extractor.c
+++ b/src/plugins/tiff_extractor.c
@@ -36,8 +36,8 @@
36 */ 36 */
37static void 37static void
38error_cb (const char *module, 38error_cb (const char *module,
39 const char *fmt, 39 const char *fmt,
40 va_list ap) 40 va_list ap)
41{ 41{
42 /* do nothing */ 42 /* do nothing */
43} 43}
@@ -53,13 +53,13 @@ error_cb (const char *module,
53 */ 53 */
54static tsize_t 54static tsize_t
55read_cb (thandle_t ctx, 55read_cb (thandle_t ctx,
56 tdata_t data, 56 tdata_t data,
57 tsize_t size) 57 tsize_t size)
58{ 58{
59 struct EXTRACTOR_ExtractContext *ec = ctx; 59 struct EXTRACTOR_ExtractContext *ec = ctx;
60 void *ptr; 60 void *ptr;
61 ssize_t ret; 61 ssize_t ret;
62 62
63 ret = ec->read (ec->cls, &ptr, size); 63 ret = ec->read (ec->cls, &ptr, size);
64 if (ret > 0) 64 if (ret > 0)
65 memcpy (data, ptr, ret); 65 memcpy (data, ptr, ret);
@@ -77,8 +77,8 @@ read_cb (thandle_t ctx,
77 */ 77 */
78static tsize_t 78static tsize_t
79write_cb (thandle_t ctx, 79write_cb (thandle_t ctx,
80 tdata_t data, 80 tdata_t data,
81 tsize_t size) 81 tsize_t size)
82{ 82{
83 return -1; 83 return -1;
84} 84}
@@ -94,8 +94,8 @@ write_cb (thandle_t ctx,
94 */ 94 */
95static toff_t 95static toff_t
96seek_cb (thandle_t ctx, 96seek_cb (thandle_t ctx,
97 toff_t offset, 97 toff_t offset,
98 int whence) 98 int whence)
99{ 99{
100 struct EXTRACTOR_ExtractContext *ec = ctx; 100 struct EXTRACTOR_ExtractContext *ec = ctx;
101 101
@@ -168,77 +168,78 @@ static struct Matches tmap[] = {
168 168
169 169
170/** 170/**
171 * Main entry method for the 'image/tiff' extraction plugin. 171 * Main entry method for the 'image/tiff' extraction plugin.
172 * 172 *
173 * @param ec extraction context provided to the plugin 173 * @param ec extraction context provided to the plugin
174 */ 174 */
175void 175void
176EXTRACTOR_tiff_extract_method (struct EXTRACTOR_ExtractContext *ec) 176EXTRACTOR_tiff_extract_method (struct EXTRACTOR_ExtractContext *ec)
177{ 177{
178 TIFF *tiff; 178 TIFF *tiff;
179 unsigned int i; 179 unsigned int i;
180 char *meta; 180 char *meta;
181 char format[128]; 181 char format[128];
182 uint32_t width; 182 uint32_t width;
183 uint32_t height; 183 uint32_t height;
184 184
185 TIFFSetErrorHandler (&error_cb); 185 TIFFSetErrorHandler (&error_cb);
186 TIFFSetWarningHandler (&error_cb); 186 TIFFSetWarningHandler (&error_cb);
187 tiff = TIFFClientOpen ("<no filename>", 187 tiff = TIFFClientOpen ("<no filename>",
188 "rm", /* read-only, no mmap */ 188 "rm", /* read-only, no mmap */
189 ec, 189 ec,
190 &read_cb, 190 &read_cb,
191 &write_cb, 191 &write_cb,
192 &seek_cb, 192 &seek_cb,
193 &close_cb, 193 &close_cb,
194 &size_cb, 194 &size_cb,
195 NULL, NULL); 195 NULL, NULL);
196 if (NULL == tiff) 196 if (NULL == tiff)
197 return; 197 return;
198 for (i = 0; 0 != tmap[i].tag; i++) 198 for (i = 0; 0 != tmap[i].tag; i++)
199 if ( (1 == 199 if ( (1 ==
200 TIFFGetField (tiff, tmap[i].tag, &meta)) && 200 TIFFGetField (tiff, tmap[i].tag, &meta)) &&
201 (0 != 201 (0 !=
202 ec->proc (ec->cls, 202 ec->proc (ec->cls,
203 "tiff", 203 "tiff",
204 tmap[i].type, 204 tmap[i].type,
205 EXTRACTOR_METAFORMAT_UTF8, 205 EXTRACTOR_METAFORMAT_UTF8,
206 "text/plain", 206 "text/plain",
207 meta, 207 meta,
208 strlen (meta) + 1)) ) 208 strlen (meta) + 1)) )
209 goto CLEANUP; 209 goto CLEANUP;
210 if ( (1 == 210 if ( (1 ==
211 TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width)) && 211 TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width)) &&
212 (1 == 212 (1 ==
213 TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height)) ) 213 TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height)) )
214 { 214 {
215 snprintf (format, 215 snprintf (format,
216 sizeof (format), 216 sizeof (format),
217 "%ux%u", 217 "%ux%u",
218 (unsigned int) width, 218 (unsigned int) width,
219 (unsigned int) height); 219 (unsigned int) height);
220 if (0 != 220 if (0 !=
221 ec->proc (ec->cls, 221 ec->proc (ec->cls,
222 "tiff", 222 "tiff",
223 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, 223 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
224 EXTRACTOR_METAFORMAT_UTF8, 224 EXTRACTOR_METAFORMAT_UTF8,
225 "text/plain", 225 "text/plain",
226 format, 226 format,
227 strlen (format) + 1)) 227 strlen (format) + 1))
228 goto CLEANUP; 228 goto CLEANUP;
229 if (0 != 229 if (0 !=
230 ec->proc (ec->cls, 230 ec->proc (ec->cls,
231 "tiff", 231 "tiff",
232 EXTRACTOR_METATYPE_MIMETYPE, 232 EXTRACTOR_METATYPE_MIMETYPE,
233 EXTRACTOR_METAFORMAT_UTF8, 233 EXTRACTOR_METAFORMAT_UTF8,
234 "text/plain", 234 "text/plain",
235 "image/tiff", 235 "image/tiff",
236 strlen ("image/tiff") + 1)) 236 strlen ("image/tiff") + 1))
237 goto CLEANUP; 237 goto CLEANUP;
238 } 238 }
239 239
240 CLEANUP: 240CLEANUP:
241 TIFFClose (tiff); 241 TIFFClose (tiff);
242} 242}
243 243
244
244/* end of tiff_extractor.c */ 245/* end of tiff_extractor.c */