diff options
Diffstat (limited to 'src/plugins/exiv2_extractor.cc')
-rw-r--r-- | src/plugins/exiv2_extractor.cc | 692 |
1 files changed, 358 insertions, 334 deletions
diff --git a/src/plugins/exiv2_extractor.cc b/src/plugins/exiv2_extractor.cc index ef402a8..78f9bda 100644 --- a/src/plugins/exiv2_extractor.cc +++ b/src/plugins/exiv2_extractor.cc | |||
@@ -43,189 +43,194 @@ class ExtractorIO : public Exiv2::BasicIo | |||
43 | { | 43 | { |
44 | private: | 44 | private: |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Extract context we are using. | 47 | * Extract context we are using. |
48 | */ | 48 | */ |
49 | struct EXTRACTOR_ExtractContext *ec; | 49 | struct EXTRACTOR_ExtractContext *ec; |
50 | 50 | ||
51 | public: | 51 | public: |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Constructor. | 54 | * Constructor. |
55 | * | 55 | * |
56 | * @param s_ec extract context to wrap | 56 | * @param s_ec extract context to wrap |
57 | */ | 57 | */ |
58 | ExtractorIO (struct EXTRACTOR_ExtractContext *s_ec) | 58 | ExtractorIO (struct EXTRACTOR_ExtractContext *s_ec) |
59 | { | 59 | { |
60 | ec = s_ec; | 60 | ec = s_ec; |
61 | } | 61 | } |
62 | 62 | ||
63 | /** | ||
64 | * Destructor. | ||
65 | */ | ||
66 | virtual ~ExtractorIO () | ||
67 | { | ||
68 | /* nothing to do */ | ||
69 | } | ||
70 | 63 | ||
71 | /** | 64 | /** |
72 | * Open stream. | 65 | * Destructor. |
73 | * | 66 | */ |
74 | * @return 0 (always successful) | 67 | virtual ~ExtractorIO () |
75 | */ | 68 | { |
76 | virtual int open (); | 69 | /* nothing to do */ |
77 | 70 | } | |
78 | /** | 71 | |
79 | * Close stream. | 72 | |
80 | * | 73 | /** |
81 | * @return 0 (always successful) | 74 | * Open stream. |
82 | */ | 75 | * |
83 | virtual int close (); | 76 | * @return 0 (always successful) |
84 | 77 | */ | |
85 | /** | 78 | virtual int open (); |
86 | * Read up to 'rcount' bytes into a buffer | 79 | |
87 | * | 80 | /** |
88 | * @param rcount number of bytes to read | 81 | * Close stream. |
89 | * @return buffer with data read, empty buffer (!) on failure (!) | 82 | * |
90 | */ | 83 | * @return 0 (always successful) |
91 | virtual Exiv2::DataBuf read (long rcount); | 84 | */ |
92 | 85 | virtual int close (); | |
93 | /** | 86 | |
94 | * Read up to 'rcount' bytes into 'buf'. | 87 | /** |
95 | * | 88 | * Read up to 'rcount' bytes into a buffer |
96 | * @param buf buffer to fill | 89 | * |
97 | * @param rcount size of 'buf' | 90 | * @param rcount number of bytes to read |
98 | * @return number of bytes read successfully, 0 on failure (!) | 91 | * @return buffer with data read, empty buffer (!) on failure (!) |
99 | */ | 92 | */ |
100 | virtual long read (Exiv2::byte *buf, | 93 | virtual Exiv2::DataBuf read (long rcount); |
101 | long rcount); | 94 | |
102 | 95 | /** | |
103 | /** | 96 | * Read up to 'rcount' bytes into 'buf'. |
104 | * Read a single character. | 97 | * |
105 | * | 98 | * @param buf buffer to fill |
106 | * @return the character | 99 | * @param rcount size of 'buf' |
107 | * @throw exception on errors | 100 | * @return number of bytes read successfully, 0 on failure (!) |
108 | */ | 101 | */ |
109 | virtual int getb (); | 102 | virtual long read (Exiv2::byte *buf, |
110 | 103 | long rcount); | |
111 | /** | 104 | |
112 | * Write to stream. | 105 | /** |
113 | * | 106 | * Read a single character. |
114 | * @param data data to write | 107 | * |
115 | * @param wcount how many bytes to write | 108 | * @return the character |
116 | * @return -1 (always fails) | 109 | * @throw exception on errors |
117 | */ | 110 | */ |
118 | virtual long write (const Exiv2::byte *data, | 111 | virtual int getb (); |
119 | long wcount); | 112 | |
120 | 113 | /** | |
121 | /** | 114 | * Write to stream. |
122 | * Write to stream. | 115 | * |
123 | * | 116 | * @param data data to write |
124 | * @param src stream to copy | 117 | * @param wcount how many bytes to write |
125 | * @return -1 (always fails) | 118 | * @return -1 (always fails) |
126 | */ | 119 | */ |
127 | virtual long write (Exiv2::BasicIo &src); | 120 | virtual long write (const Exiv2::byte *data, |
128 | 121 | long wcount); | |
129 | /** | 122 | |
130 | * Write a single byte. | 123 | /** |
131 | * | 124 | * Write to stream. |
132 | * @param data byte to write | 125 | * |
133 | * @return -1 (always fails) | 126 | * @param src stream to copy |
134 | */ | 127 | * @return -1 (always fails) |
135 | virtual int putb (Exiv2::byte data); | 128 | */ |
136 | 129 | virtual long write (Exiv2::BasicIo &src); | |
137 | /** | 130 | |
138 | * Not supported. | 131 | /** |
139 | * | 132 | * Write a single byte. |
140 | * @throws error | 133 | * |
141 | */ | 134 | * @param data byte to write |
142 | virtual void transfer (Exiv2::BasicIo& src); | 135 | * @return -1 (always fails) |
143 | 136 | */ | |
144 | /** | 137 | virtual int putb (Exiv2::byte data); |
145 | * Seek to the given offset. | 138 | |
146 | * | 139 | /** |
147 | * @param offset desired offset | 140 | * Not supported. |
148 | * @parma pos offset is relative to where? | 141 | * |
149 | * @return -1 on failure, 0 on success | 142 | * @throws error |
150 | */ | 143 | */ |
151 | virtual int seek (long offset, | 144 | virtual void transfer (Exiv2::BasicIo& src); |
152 | Exiv2::BasicIo::Position pos); | 145 | |
153 | 146 | /** | |
154 | /** | 147 | * Seek to the given offset. |
155 | * Not supported. | 148 | * |
156 | * | 149 | * @param offset desired offset |
157 | * @throws error | 150 | * @parma pos offset is relative to where? |
158 | */ | 151 | * @return -1 on failure, 0 on success |
159 | virtual Exiv2::byte* mmap (bool isWritable); | 152 | */ |
160 | 153 | virtual int seek (long offset, | |
161 | /** | 154 | Exiv2::BasicIo::Position pos); |
162 | * Not supported. | 155 | |
163 | * | 156 | /** |
164 | * @return -1 (error) | 157 | * Not supported. |
165 | */ | 158 | * |
166 | virtual int munmap (); | 159 | * @throws error |
167 | 160 | */ | |
168 | /** | 161 | virtual Exiv2::byte*mmap (bool isWritable); |
169 | * Return our current offset in the file. | 162 | |
170 | * | 163 | /** |
171 | * @return -1 on error | 164 | * Not supported. |
172 | */ | 165 | * |
173 | virtual long int tell (void) const; | 166 | * @return -1 (error) |
174 | 167 | */ | |
175 | /** | 168 | virtual int munmap (); |
176 | * Return overall size of the file. | 169 | |
177 | * | 170 | /** |
178 | * @return -1 on error | 171 | * Return our current offset in the file. |
179 | */ | 172 | * |
180 | #if EXIV2_TEST_VERSION(0,26,0) | 173 | * @return -1 on error |
181 | virtual size_t size (void) const; | 174 | */ |
175 | virtual long int tell (void) const; | ||
176 | |||
177 | /** | ||
178 | * Return overall size of the file. | ||
179 | * | ||
180 | * @return -1 on error | ||
181 | */ | ||
182 | #if EXIV2_TEST_VERSION (0,26,0) | ||
183 | virtual size_t size (void) const; | ||
184 | |||
182 | #else | 185 | #else |
183 | virtual long int size (void) const; | 186 | virtual long int size (void) const; |
187 | |||
184 | #endif | 188 | #endif |
185 | 189 | ||
186 | /** | 190 | /** |
187 | * Check if file is open. | 191 | * Check if file is open. |
188 | * | 192 | * |
189 | * @return true (always). | 193 | * @return true (always). |
190 | */ | 194 | */ |
191 | virtual bool isopen () const; | 195 | virtual bool isopen () const; |
192 | 196 | ||
193 | /** | 197 | /** |
194 | * Check if this file source is in error mode. | 198 | * Check if this file source is in error mode. |
195 | * | 199 | * |
196 | * @return 0 (always all is fine). | 200 | * @return 0 (always all is fine). |
197 | */ | 201 | */ |
198 | virtual int error () const; | 202 | virtual int error () const; |
199 | 203 | ||
200 | /** | 204 | /** |
201 | * Check if current position of the file is at the end | 205 | * Check if current position of the file is at the end |
202 | * | 206 | * |
203 | * @return true if at EOF, false if not. | 207 | * @return true if at EOF, false if not. |
204 | */ | 208 | */ |
205 | virtual bool eof () const; | 209 | virtual bool eof () const; |
206 | 210 | ||
207 | /** | 211 | /** |
208 | * Not supported. | 212 | * Not supported. |
209 | * | 213 | * |
210 | * @throws error | 214 | * @throws error |
211 | */ | 215 | */ |
212 | virtual std::string path () const; | 216 | virtual std::string path () const; |
213 | 217 | ||
214 | #ifdef EXV_UNICODE_PATH | 218 | #ifdef EXV_UNICODE_PATH |
215 | /** | 219 | /** |
216 | * Not supported. | 220 | * Not supported. |
217 | * | 221 | * |
218 | * @throws error | 222 | * @throws error |
219 | */ | 223 | */ |
220 | virtual std::wstring wpath () const; | 224 | virtual std::wstring wpath () const; |
225 | |||
221 | #endif | 226 | #endif |
222 | 227 | ||
223 | /** | 228 | /** |
224 | * Not supported. | 229 | * Not supported. |
225 | * | 230 | * |
226 | * @throws error | 231 | * @throws error |
227 | */ | 232 | */ |
228 | virtual Exiv2::BasicIo::AutoPtr temporary () const; | 233 | virtual Exiv2::BasicIo::AutoPtr temporary () const; |
229 | 234 | ||
230 | }; | 235 | }; |
231 | 236 | ||
@@ -241,6 +246,7 @@ ExtractorIO::open () | |||
241 | return 0; | 246 | return 0; |
242 | } | 247 | } |
243 | 248 | ||
249 | |||
244 | /** | 250 | /** |
245 | * Close stream. | 251 | * Close stream. |
246 | * | 252 | * |
@@ -280,7 +286,7 @@ ExtractorIO::read (long rcount) | |||
280 | */ | 286 | */ |
281 | long | 287 | long |
282 | ExtractorIO::read (Exiv2::byte *buf, | 288 | ExtractorIO::read (Exiv2::byte *buf, |
283 | long rcount) | 289 | long rcount) |
284 | { | 290 | { |
285 | void *data; | 291 | void *data; |
286 | ssize_t ret; | 292 | ssize_t ret; |
@@ -288,14 +294,14 @@ ExtractorIO::read (Exiv2::byte *buf, | |||
288 | 294 | ||
289 | got = 0; | 295 | got = 0; |
290 | while (got < rcount) | 296 | while (got < rcount) |
291 | { | 297 | { |
292 | if (-1 == (ret = ec->read (ec->cls, &data, rcount - got))) | 298 | if (-1 == (ret = ec->read (ec->cls, &data, rcount - got))) |
293 | return got; | 299 | return got; |
294 | if (0 == ret) | 300 | if (0 == ret) |
295 | break; | 301 | break; |
296 | memcpy (&buf[got], data, ret); | 302 | memcpy (&buf[got], data, ret); |
297 | got += ret; | 303 | got += ret; |
298 | } | 304 | } |
299 | return got; | 305 | return got; |
300 | } | 306 | } |
301 | 307 | ||
@@ -313,7 +319,7 @@ ExtractorIO::getb () | |||
313 | const unsigned char *r; | 319 | const unsigned char *r; |
314 | 320 | ||
315 | if (1 != ec->read (ec->cls, &data, 1)) | 321 | if (1 != ec->read (ec->cls, &data, 1)) |
316 | #if EXIV2_TEST_VERSION(0,27,0) | 322 | #if EXIV2_TEST_VERSION (0,27,0) |
317 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); | 323 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); |
318 | #else | 324 | #else |
319 | throw Exiv2::BasicError<char> (42 /* error code */); | 325 | throw Exiv2::BasicError<char> (42 /* error code */); |
@@ -332,7 +338,7 @@ ExtractorIO::getb () | |||
332 | */ | 338 | */ |
333 | long | 339 | long |
334 | ExtractorIO::write (const Exiv2::byte *data, | 340 | ExtractorIO::write (const Exiv2::byte *data, |
335 | long wcount) | 341 | long wcount) |
336 | { | 342 | { |
337 | return -1; | 343 | return -1; |
338 | } | 344 | } |
@@ -372,8 +378,8 @@ ExtractorIO::putb (Exiv2::byte data) | |||
372 | void | 378 | void |
373 | ExtractorIO::transfer (Exiv2::BasicIo& src) | 379 | ExtractorIO::transfer (Exiv2::BasicIo& src) |
374 | { | 380 | { |
375 | #if EXIV2_TEST_VERSION(0,27,0) | 381 | #if EXIV2_TEST_VERSION (0,27,0) |
376 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); | 382 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); |
377 | #else | 383 | #else |
378 | throw Exiv2::BasicError<char> (42 /* error code */); | 384 | throw Exiv2::BasicError<char> (42 /* error code */); |
379 | #endif | 385 | #endif |
@@ -389,24 +395,24 @@ ExtractorIO::transfer (Exiv2::BasicIo& src) | |||
389 | */ | 395 | */ |
390 | int | 396 | int |
391 | ExtractorIO::seek (long offset, | 397 | ExtractorIO::seek (long offset, |
392 | Exiv2::BasicIo::Position pos) | 398 | Exiv2::BasicIo::Position pos) |
393 | { | 399 | { |
394 | int rel; | 400 | int rel; |
395 | 401 | ||
396 | switch (pos) | 402 | switch (pos) |
397 | { | 403 | { |
398 | case beg: // Exiv2::BasicIo::beg: | 404 | case beg: // Exiv2::BasicIo::beg: |
399 | rel = SEEK_SET; | 405 | rel = SEEK_SET; |
400 | break; | 406 | break; |
401 | case cur: | 407 | case cur: |
402 | rel = SEEK_CUR; | 408 | rel = SEEK_CUR; |
403 | break; | 409 | break; |
404 | case end: | 410 | case end: |
405 | rel = SEEK_END; | 411 | rel = SEEK_END; |
406 | break; | 412 | break; |
407 | default: | 413 | default: |
408 | abort (); | 414 | abort (); |
409 | } | 415 | } |
410 | if (-1 == ec->seek (ec->cls, offset, rel)) | 416 | if (-1 == ec->seek (ec->cls, offset, rel)) |
411 | return -1; | 417 | return -1; |
412 | return 0; | 418 | return 0; |
@@ -421,8 +427,8 @@ ExtractorIO::seek (long offset, | |||
421 | Exiv2::byte * | 427 | Exiv2::byte * |
422 | ExtractorIO::mmap (bool isWritable) | 428 | ExtractorIO::mmap (bool isWritable) |
423 | { | 429 | { |
424 | #if EXIV2_TEST_VERSION(0,27,0) | 430 | #if EXIV2_TEST_VERSION (0,27,0) |
425 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); | 431 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); |
426 | #else | 432 | #else |
427 | throw Exiv2::BasicError<char> (42 /* error code */); | 433 | throw Exiv2::BasicError<char> (42 /* error code */); |
428 | #endif | 434 | #endif |
@@ -458,7 +464,7 @@ ExtractorIO::tell (void) const | |||
458 | * | 464 | * |
459 | * @return -1 on error | 465 | * @return -1 on error |
460 | */ | 466 | */ |
461 | #if EXIV2_TEST_VERSION(0,26,0) | 467 | #if EXIV2_TEST_VERSION (0,26,0) |
462 | size_t | 468 | size_t |
463 | #else | 469 | #else |
464 | long int | 470 | long int |
@@ -513,8 +519,8 @@ ExtractorIO::eof () const | |||
513 | std::string | 519 | std::string |
514 | ExtractorIO::path () const | 520 | ExtractorIO::path () const |
515 | { | 521 | { |
516 | #if EXIV2_TEST_VERSION(0,27,0) | 522 | #if EXIV2_TEST_VERSION (0,27,0) |
517 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); | 523 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); |
518 | #else | 524 | #else |
519 | throw Exiv2::BasicError<char> (42 /* error code */); | 525 | throw Exiv2::BasicError<char> (42 /* error code */); |
520 | #endif | 526 | #endif |
@@ -530,12 +536,14 @@ ExtractorIO::path () const | |||
530 | std::wstring | 536 | std::wstring |
531 | ExtractorIO::wpath () const | 537 | ExtractorIO::wpath () const |
532 | { | 538 | { |
533 | #if EXIV2_TEST_VERSION(0,27,0) | 539 | #if EXIV2_TEST_VERSION (0,27,0) |
534 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); | 540 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); |
535 | #else | 541 | #else |
536 | throw Exiv2::BasicError<char> (42 /* error code */); | 542 | throw Exiv2::BasicError<char> (42 /* error code */); |
537 | #endif | 543 | #endif |
538 | } | 544 | } |
545 | |||
546 | |||
539 | #endif | 547 | #endif |
540 | 548 | ||
541 | 549 | ||
@@ -548,8 +556,8 @@ Exiv2::BasicIo::AutoPtr | |||
548 | ExtractorIO::temporary () const | 556 | ExtractorIO::temporary () const |
549 | { | 557 | { |
550 | fprintf (stderr, "throwing temporary error\n"); | 558 | fprintf (stderr, "throwing temporary error\n"); |
551 | #if EXIV2_TEST_VERSION(0,27,0) | 559 | #if EXIV2_TEST_VERSION (0,27,0) |
552 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); | 560 | throw Exiv2::BasicError<char> (Exiv2::kerDecodeLangAltQualifierFailed); |
553 | #else | 561 | #else |
554 | throw Exiv2::BasicError<char> (42 /* error code */); | 562 | throw Exiv2::BasicError<char> (42 /* error code */); |
555 | #endif | 563 | #endif |
@@ -563,7 +571,11 @@ ExtractorIO::temporary () const | |||
563 | * @param s 0-terminated UTF8 string value with the meta data | 571 | * @param s 0-terminated UTF8 string value with the meta data |
564 | * @param type libextractor type for the meta data | 572 | * @param type libextractor type for the meta data |
565 | */ | 573 | */ |
566 | #define ADD(s, type) do { if (0 != proc (proc_cls, "exiv2", type, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return 1; } while (0) | 574 | #define ADD(s, type) do { if (0 != proc (proc_cls, "exiv2", type, \ |
575 | EXTRACTOR_METAFORMAT_UTF8, \ | ||
576 | "text/plain", s, strlen (s) \ | ||
577 | + 1)) return 1; \ | ||
578 | } while (0) | ||
567 | 579 | ||
568 | 580 | ||
569 | /** | 581 | /** |
@@ -579,10 +591,10 @@ ExtractorIO::temporary () const | |||
579 | */ | 591 | */ |
580 | static int | 592 | static int |
581 | add_exiv2_tag (const Exiv2::ExifData& exifData, | 593 | add_exiv2_tag (const Exiv2::ExifData& exifData, |
582 | const std::string& key, | 594 | const std::string& key, |
583 | enum EXTRACTOR_MetaType type, | 595 | enum EXTRACTOR_MetaType type, |
584 | EXTRACTOR_MetaDataProcessor proc, | 596 | EXTRACTOR_MetaDataProcessor proc, |
585 | void *proc_cls) | 597 | void *proc_cls) |
586 | { | 598 | { |
587 | const char *str; | 599 | const char *str; |
588 | Exiv2::ExifKey ek (key); | 600 | Exiv2::ExifKey ek (key); |
@@ -590,8 +602,8 @@ add_exiv2_tag (const Exiv2::ExifData& exifData, | |||
590 | 602 | ||
591 | if (exifData.end () == md) | 603 | if (exifData.end () == md) |
592 | return 0; /* not found */ | 604 | return 0; /* not found */ |
593 | std::string ccstr = Exiv2::toString(*md); | 605 | std::string ccstr = Exiv2::toString (*md); |
594 | str = ccstr.c_str(); | 606 | str = ccstr.c_str (); |
595 | /* skip over whitespace */ | 607 | /* skip over whitespace */ |
596 | while ( (strlen (str) > 0) && isspace ((unsigned char) str[0])) | 608 | while ( (strlen (str) > 0) && isspace ((unsigned char) str[0])) |
597 | str++; | 609 | str++; |
@@ -615,28 +627,28 @@ add_exiv2_tag (const Exiv2::ExifData& exifData, | |||
615 | */ | 627 | */ |
616 | static int | 628 | static int |
617 | add_iptc_data (const Exiv2::IptcData& iptcData, | 629 | add_iptc_data (const Exiv2::IptcData& iptcData, |
618 | const std::string& key, | 630 | const std::string& key, |
619 | enum EXTRACTOR_MetaType type, | 631 | enum EXTRACTOR_MetaType type, |
620 | EXTRACTOR_MetaDataProcessor proc, | 632 | EXTRACTOR_MetaDataProcessor proc, |
621 | void *proc_cls) | 633 | void *proc_cls) |
622 | { | 634 | { |
623 | const char *str; | 635 | const char *str; |
624 | Exiv2::IptcKey ek (key); | 636 | Exiv2::IptcKey ek (key); |
625 | Exiv2::IptcData::const_iterator md = iptcData.findKey (ek); | 637 | Exiv2::IptcData::const_iterator md = iptcData.findKey (ek); |
626 | 638 | ||
627 | while (iptcData.end () != md) | 639 | while (iptcData.end () != md) |
628 | { | 640 | { |
629 | if (0 != strcmp (Exiv2::toString (md->key ()).c_str (), key.c_str ())) | 641 | if (0 != strcmp (Exiv2::toString (md->key ()).c_str (), key.c_str ())) |
630 | break; | 642 | break; |
631 | std::string ccstr = Exiv2::toString (*md); | 643 | std::string ccstr = Exiv2::toString (*md); |
632 | str = ccstr.c_str (); | 644 | str = ccstr.c_str (); |
633 | /* skip over whitespace */ | 645 | /* skip over whitespace */ |
634 | while ((strlen (str) > 0) && isspace ((unsigned char) str[0])) | 646 | while ((strlen (str) > 0) && isspace ((unsigned char) str[0])) |
635 | str++; | 647 | str++; |
636 | if (strlen (str) > 0) | 648 | if (strlen (str) > 0) |
637 | ADD (str, type); | 649 | ADD (str, type); |
638 | md++; | 650 | md++; |
639 | } | 651 | } |
640 | return 0; | 652 | return 0; |
641 | } | 653 | } |
642 | 654 | ||
@@ -654,26 +666,27 @@ add_iptc_data (const Exiv2::IptcData& iptcData, | |||
654 | */ | 666 | */ |
655 | static int | 667 | static int |
656 | add_xmp_data (const Exiv2::XmpData& xmpData, | 668 | add_xmp_data (const Exiv2::XmpData& xmpData, |
657 | const std::string& key, | 669 | const std::string& key, |
658 | enum EXTRACTOR_MetaType type, | 670 | enum EXTRACTOR_MetaType type, |
659 | EXTRACTOR_MetaDataProcessor proc, | 671 | EXTRACTOR_MetaDataProcessor proc, |
660 | void *proc_cls) | 672 | void *proc_cls) |
661 | { | 673 | { |
662 | const char * str; | 674 | const char *str; |
663 | Exiv2::XmpKey ek (key); | 675 | Exiv2::XmpKey ek (key); |
664 | Exiv2::XmpData::const_iterator md = xmpData.findKey (ek); | 676 | Exiv2::XmpData::const_iterator md = xmpData.findKey (ek); |
665 | 677 | ||
666 | while (xmpData.end () != md) | 678 | while (xmpData.end () != md) |
667 | { | 679 | { |
668 | if (0 != strcmp (Exiv2::toString (md->key ()).c_str (), key.c_str ())) | 680 | if (0 != strcmp (Exiv2::toString (md->key ()).c_str (), key.c_str ())) |
669 | break; | 681 | break; |
670 | std::string ccstr = Exiv2::toString (*md); | 682 | std::string ccstr = Exiv2::toString (*md); |
671 | str = ccstr.c_str (); | 683 | str = ccstr.c_str (); |
672 | while ( (strlen (str) > 0) && isspace ((unsigned char) str[0])) str++; | 684 | while ( (strlen (str) > 0) && isspace ((unsigned char) str[0])) |
673 | if (strlen (str) > 0) | 685 | str++; |
674 | ADD (str, type); | 686 | if (strlen (str) > 0) |
675 | md++; | 687 | ADD (str, type); |
676 | } | 688 | md++; |
689 | } | ||
677 | return 0; | 690 | return 0; |
678 | } | 691 | } |
679 | 692 | ||
@@ -685,7 +698,8 @@ add_xmp_data (const Exiv2::XmpData& xmpData, | |||
685 | * @param s key to lookup | 698 | * @param s key to lookup |
686 | * @param type libextractor type to use for the meta data found under the given key | 699 | * @param type libextractor type to use for the meta data found under the given key |
687 | */ | 700 | */ |
688 | #define ADDEXIV(s,t) do { if (0 != add_exiv2_tag (exifData, s, t, ec->proc, ec->cls)) return; } while (0) | 701 | #define ADDEXIV(s,t) do { if (0 != add_exiv2_tag (exifData, s, t, ec->proc, \ |
702 | ec->cls)) return; } while (0) | ||
689 | 703 | ||
690 | 704 | ||
691 | /** | 705 | /** |
@@ -695,7 +709,8 @@ add_xmp_data (const Exiv2::XmpData& xmpData, | |||
695 | * @param s key to lookup | 709 | * @param s key to lookup |
696 | * @param type libextractor type to use for the meta data found under the given key | 710 | * @param type libextractor type to use for the meta data found under the given key |
697 | */ | 711 | */ |
698 | #define ADDIPTC(s,t) do { if (0 != add_iptc_data (iptcData, s, t, ec->proc, ec->cls)) return; } while (0) | 712 | #define ADDIPTC(s,t) do { if (0 != add_iptc_data (iptcData, s, t, ec->proc, \ |
713 | ec->cls)) return; } while (0) | ||
699 | 714 | ||
700 | 715 | ||
701 | /** | 716 | /** |
@@ -705,7 +720,8 @@ add_xmp_data (const Exiv2::XmpData& xmpData, | |||
705 | * @param s key to lookup | 720 | * @param s key to lookup |
706 | * @param type libextractor type to use for the meta data found under the given key | 721 | * @param type libextractor type to use for the meta data found under the given key |
707 | */ | 722 | */ |
708 | #define ADDXMP(s,t) do { if (0 != add_xmp_data (xmpData, s, t, ec->proc, ec->cls)) return; } while (0) | 723 | #define ADDXMP(s,t) do { if (0 != add_xmp_data (xmpData, s, t, ec->proc, \ |
724 | ec->cls)) return; } while (0) | ||
709 | 725 | ||
710 | 726 | ||
711 | /** | 727 | /** |
@@ -717,97 +733,105 @@ extern "C" void | |||
717 | EXTRACTOR_exiv2_extract_method (struct EXTRACTOR_ExtractContext *ec) | 733 | EXTRACTOR_exiv2_extract_method (struct EXTRACTOR_ExtractContext *ec) |
718 | { | 734 | { |
719 | try | 735 | try |
720 | { | 736 | { |
721 | #if !EXIV2_TEST_VERSION(0,24,0) | 737 | #if ! EXIV2_TEST_VERSION (0,24,0) |
722 | Exiv2::LogMsg::setLevel (Exiv2::LogMsg::mute); | 738 | Exiv2::LogMsg::setLevel (Exiv2::LogMsg::mute); |
723 | #endif | 739 | #endif |
724 | std::auto_ptr<Exiv2::BasicIo> eio(new ExtractorIO (ec)); | 740 | std::auto_ptr<Exiv2::BasicIo> eio (new ExtractorIO (ec)); |
725 | Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open (eio); | 741 | Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open (eio); |
726 | if (0 == image.get ()) | 742 | if (0 == image.get ()) |
727 | return; | 743 | return; |
728 | image->readMetadata (); | 744 | image->readMetadata (); |
729 | Exiv2::ExifData &exifData = image->exifData (); | 745 | Exiv2::ExifData &exifData = image->exifData (); |
730 | if (! exifData.empty ()) | 746 | if (! exifData.empty ()) |
731 | { | ||
732 | ADDEXIV ("Exif.Image.Copyright", EXTRACTOR_METATYPE_COPYRIGHT); | ||
733 | ADDEXIV ("Exif.Photo.UserComment", EXTRACTOR_METATYPE_COMMENT); | ||
734 | ADDEXIV ("Exif.GPSInfo.GPSLatitudeRef", EXTRACTOR_METATYPE_GPS_LATITUDE_REF); | ||
735 | ADDEXIV ("Exif.GPSInfo.GPSLatitude", EXTRACTOR_METATYPE_GPS_LATITUDE); | ||
736 | ADDEXIV ("Exif.GPSInfo.GPSLongitudeRef", EXTRACTOR_METATYPE_GPS_LONGITUDE_REF); | ||
737 | ADDEXIV ("Exif.GPSInfo.GPSLongitude", EXTRACTOR_METATYPE_GPS_LONGITUDE); | ||
738 | ADDEXIV ("Exif.Image.Make", EXTRACTOR_METATYPE_CAMERA_MAKE); | ||
739 | ADDEXIV ("Exif.Image.Model", EXTRACTOR_METATYPE_CAMERA_MODEL); | ||
740 | ADDEXIV ("Exif.Image.Orientation", EXTRACTOR_METATYPE_ORIENTATION); | ||
741 | ADDEXIV ("Exif.Photo.DateTimeOriginal", EXTRACTOR_METATYPE_CREATION_DATE); | ||
742 | ADDEXIV ("Exif.Photo.ExposureBiasValue", EXTRACTOR_METATYPE_EXPOSURE_BIAS); | ||
743 | ADDEXIV ("Exif.Photo.Flash", EXTRACTOR_METATYPE_FLASH); | ||
744 | ADDEXIV ("Exif.CanonSi.FlashBias", EXTRACTOR_METATYPE_FLASH_BIAS); | ||
745 | ADDEXIV ("Exif.Panasonic.FlashBias", EXTRACTOR_METATYPE_FLASH_BIAS); | ||
746 | ADDEXIV ("Exif.Olympus.FlashBias", EXTRACTOR_METATYPE_FLASH_BIAS); | ||
747 | ADDEXIV ("Exif.Photo.FocalLength", EXTRACTOR_METATYPE_FOCAL_LENGTH); | ||
748 | ADDEXIV ("Exif.Photo.FocalLengthIn35mmFilm", EXTRACTOR_METATYPE_FOCAL_LENGTH_35MM); | ||
749 | ADDEXIV ("Exif.Photo.ISOSpeedRatings", EXTRACTOR_METATYPE_ISO_SPEED); | ||
750 | ADDEXIV ("Exif.CanonSi.ISOSpeed", EXTRACTOR_METATYPE_ISO_SPEED); | ||
751 | ADDEXIV ("Exif.Nikon1.ISOSpeed", EXTRACTOR_METATYPE_ISO_SPEED); | ||
752 | ADDEXIV ("Exif.Nikon2.ISOSpeed", EXTRACTOR_METATYPE_ISO_SPEED); | ||
753 | ADDEXIV ("Exif.Nikon3.ISOSpeed", EXTRACTOR_METATYPE_ISO_SPEED); | ||
754 | ADDEXIV ("Exif.Photo.ExposureProgram", EXTRACTOR_METATYPE_EXPOSURE_MODE); | ||
755 | ADDEXIV ("Exif.CanonCs.ExposureProgram", EXTRACTOR_METATYPE_EXPOSURE_MODE); | ||
756 | ADDEXIV ("Exif.Photo.MeteringMode", EXTRACTOR_METATYPE_METERING_MODE); | ||
757 | ADDEXIV ("Exif.CanonCs.Macro", EXTRACTOR_METATYPE_MACRO_MODE); | ||
758 | ADDEXIV ("Exif.Fujifilm.Macro", EXTRACTOR_METATYPE_MACRO_MODE); | ||
759 | ADDEXIV ("Exif.Olympus.Macro", EXTRACTOR_METATYPE_MACRO_MODE); | ||
760 | ADDEXIV ("Exif.Panasonic.Macro", EXTRACTOR_METATYPE_MACRO_MODE); | ||
761 | ADDEXIV ("Exif.CanonCs.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
762 | ADDEXIV ("Exif.Fujifilm.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
763 | ADDEXIV ("Exif.Sigma.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
764 | ADDEXIV ("Exif.Nikon1.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
765 | ADDEXIV ("Exif.Nikon2.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
766 | ADDEXIV ("Exif.Nikon3.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
767 | ADDEXIV ("Exif.Olympus.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
768 | ADDEXIV ("Exif.Panasonic.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
769 | ADDEXIV ("Exif.CanonSi.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
770 | ADDEXIV ("Exif.Fujifilm.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
771 | ADDEXIV ("Exif.Sigma.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
772 | ADDEXIV ("Exif.Nikon1.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
773 | ADDEXIV ("Exif.Nikon2.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
774 | ADDEXIV ("Exif.Nikon3.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
775 | ADDEXIV ("Exif.Olympus.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
776 | ADDEXIV ("Exif.Panasonic.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
777 | ADDEXIV ("Exif.Photo.FNumber", EXTRACTOR_METATYPE_APERTURE); | ||
778 | ADDEXIV ("Exif.Photo.ExposureTime", EXTRACTOR_METATYPE_EXPOSURE); | ||
779 | } | ||
780 | |||
781 | Exiv2::IptcData &iptcData = image->iptcData(); | ||
782 | if (! iptcData.empty()) | ||
783 | { | ||
784 | ADDIPTC ("Iptc.Application2.Keywords", EXTRACTOR_METATYPE_KEYWORDS); | ||
785 | ADDIPTC ("Iptc.Application2.City", EXTRACTOR_METATYPE_LOCATION_CITY); | ||
786 | ADDIPTC ("Iptc.Application2.SubLocation", EXTRACTOR_METATYPE_LOCATION_SUBLOCATION); | ||
787 | ADDIPTC ("Iptc.Application2.CountryName", EXTRACTOR_METATYPE_LOCATION_COUNTRY); | ||
788 | } | ||
789 | |||
790 | Exiv2::XmpData &xmpData = image->xmpData(); | ||
791 | if (! xmpData.empty()) | ||
792 | { | ||
793 | ADDXMP ("Xmp.photoshop.Country", EXTRACTOR_METATYPE_LOCATION_COUNTRY); | ||
794 | ADDXMP ("Xmp.photoshop.City", EXTRACTOR_METATYPE_LOCATION_CITY); | ||
795 | ADDXMP ("Xmp.xmp.Rating", EXTRACTOR_METATYPE_RATING); | ||
796 | ADDXMP ("Xmp.MicrosoftPhoto.Rating", EXTRACTOR_METATYPE_RATING); | ||
797 | ADDXMP ("Xmp.iptc.CountryCode", EXTRACTOR_METATYPE_LOCATION_COUNTRY_CODE); | ||
798 | ADDXMP ("Xmp.xmp.CreatorTool", EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); | ||
799 | ADDXMP ("Xmp.lr.hierarchicalSubject", EXTRACTOR_METATYPE_SUBJECT); | ||
800 | } | ||
801 | } | ||
802 | catch (const Exiv2::AnyError& e) | ||
803 | { | 747 | { |
804 | #if DEBUG | 748 | ADDEXIV ("Exif.Image.Copyright", EXTRACTOR_METATYPE_COPYRIGHT); |
805 | std::cerr << "Caught Exiv2 exception '" << e << "'\n"; | 749 | ADDEXIV ("Exif.Photo.UserComment", EXTRACTOR_METATYPE_COMMENT); |
806 | #endif | 750 | ADDEXIV ("Exif.GPSInfo.GPSLatitudeRef", |
751 | EXTRACTOR_METATYPE_GPS_LATITUDE_REF); | ||
752 | ADDEXIV ("Exif.GPSInfo.GPSLatitude", EXTRACTOR_METATYPE_GPS_LATITUDE); | ||
753 | ADDEXIV ("Exif.GPSInfo.GPSLongitudeRef", | ||
754 | EXTRACTOR_METATYPE_GPS_LONGITUDE_REF); | ||
755 | ADDEXIV ("Exif.GPSInfo.GPSLongitude", EXTRACTOR_METATYPE_GPS_LONGITUDE); | ||
756 | ADDEXIV ("Exif.Image.Make", EXTRACTOR_METATYPE_CAMERA_MAKE); | ||
757 | ADDEXIV ("Exif.Image.Model", EXTRACTOR_METATYPE_CAMERA_MODEL); | ||
758 | ADDEXIV ("Exif.Image.Orientation", EXTRACTOR_METATYPE_ORIENTATION); | ||
759 | ADDEXIV ("Exif.Photo.DateTimeOriginal", EXTRACTOR_METATYPE_CREATION_DATE); | ||
760 | ADDEXIV ("Exif.Photo.ExposureBiasValue", | ||
761 | EXTRACTOR_METATYPE_EXPOSURE_BIAS); | ||
762 | ADDEXIV ("Exif.Photo.Flash", EXTRACTOR_METATYPE_FLASH); | ||
763 | ADDEXIV ("Exif.CanonSi.FlashBias", EXTRACTOR_METATYPE_FLASH_BIAS); | ||
764 | ADDEXIV ("Exif.Panasonic.FlashBias", EXTRACTOR_METATYPE_FLASH_BIAS); | ||
765 | ADDEXIV ("Exif.Olympus.FlashBias", EXTRACTOR_METATYPE_FLASH_BIAS); | ||
766 | ADDEXIV ("Exif.Photo.FocalLength", EXTRACTOR_METATYPE_FOCAL_LENGTH); | ||
767 | ADDEXIV ("Exif.Photo.FocalLengthIn35mmFilm", | ||
768 | EXTRACTOR_METATYPE_FOCAL_LENGTH_35MM); | ||
769 | ADDEXIV ("Exif.Photo.ISOSpeedRatings", EXTRACTOR_METATYPE_ISO_SPEED); | ||
770 | ADDEXIV ("Exif.CanonSi.ISOSpeed", EXTRACTOR_METATYPE_ISO_SPEED); | ||
771 | ADDEXIV ("Exif.Nikon1.ISOSpeed", EXTRACTOR_METATYPE_ISO_SPEED); | ||
772 | ADDEXIV ("Exif.Nikon2.ISOSpeed", EXTRACTOR_METATYPE_ISO_SPEED); | ||
773 | ADDEXIV ("Exif.Nikon3.ISOSpeed", EXTRACTOR_METATYPE_ISO_SPEED); | ||
774 | ADDEXIV ("Exif.Photo.ExposureProgram", EXTRACTOR_METATYPE_EXPOSURE_MODE); | ||
775 | ADDEXIV ("Exif.CanonCs.ExposureProgram", | ||
776 | EXTRACTOR_METATYPE_EXPOSURE_MODE); | ||
777 | ADDEXIV ("Exif.Photo.MeteringMode", EXTRACTOR_METATYPE_METERING_MODE); | ||
778 | ADDEXIV ("Exif.CanonCs.Macro", EXTRACTOR_METATYPE_MACRO_MODE); | ||
779 | ADDEXIV ("Exif.Fujifilm.Macro", EXTRACTOR_METATYPE_MACRO_MODE); | ||
780 | ADDEXIV ("Exif.Olympus.Macro", EXTRACTOR_METATYPE_MACRO_MODE); | ||
781 | ADDEXIV ("Exif.Panasonic.Macro", EXTRACTOR_METATYPE_MACRO_MODE); | ||
782 | ADDEXIV ("Exif.CanonCs.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
783 | ADDEXIV ("Exif.Fujifilm.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
784 | ADDEXIV ("Exif.Sigma.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
785 | ADDEXIV ("Exif.Nikon1.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
786 | ADDEXIV ("Exif.Nikon2.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
787 | ADDEXIV ("Exif.Nikon3.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
788 | ADDEXIV ("Exif.Olympus.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
789 | ADDEXIV ("Exif.Panasonic.Quality", EXTRACTOR_METATYPE_IMAGE_QUALITY); | ||
790 | ADDEXIV ("Exif.CanonSi.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
791 | ADDEXIV ("Exif.Fujifilm.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
792 | ADDEXIV ("Exif.Sigma.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
793 | ADDEXIV ("Exif.Nikon1.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
794 | ADDEXIV ("Exif.Nikon2.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
795 | ADDEXIV ("Exif.Nikon3.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
796 | ADDEXIV ("Exif.Olympus.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
797 | ADDEXIV ("Exif.Panasonic.WhiteBalance", EXTRACTOR_METATYPE_WHITE_BALANCE); | ||
798 | ADDEXIV ("Exif.Photo.FNumber", EXTRACTOR_METATYPE_APERTURE); | ||
799 | ADDEXIV ("Exif.Photo.ExposureTime", EXTRACTOR_METATYPE_EXPOSURE); | ||
807 | } | 800 | } |
808 | catch (void *anything) | 801 | |
802 | Exiv2::IptcData &iptcData = image->iptcData (); | ||
803 | if (! iptcData.empty ()) | ||
804 | { | ||
805 | ADDIPTC ("Iptc.Application2.Keywords", EXTRACTOR_METATYPE_KEYWORDS); | ||
806 | ADDIPTC ("Iptc.Application2.City", EXTRACTOR_METATYPE_LOCATION_CITY); | ||
807 | ADDIPTC ("Iptc.Application2.SubLocation", | ||
808 | EXTRACTOR_METATYPE_LOCATION_SUBLOCATION); | ||
809 | ADDIPTC ("Iptc.Application2.CountryName", | ||
810 | EXTRACTOR_METATYPE_LOCATION_COUNTRY); | ||
811 | } | ||
812 | |||
813 | Exiv2::XmpData &xmpData = image->xmpData (); | ||
814 | if (! xmpData.empty ()) | ||
809 | { | 815 | { |
816 | ADDXMP ("Xmp.photoshop.Country", EXTRACTOR_METATYPE_LOCATION_COUNTRY); | ||
817 | ADDXMP ("Xmp.photoshop.City", EXTRACTOR_METATYPE_LOCATION_CITY); | ||
818 | ADDXMP ("Xmp.xmp.Rating", EXTRACTOR_METATYPE_RATING); | ||
819 | ADDXMP ("Xmp.MicrosoftPhoto.Rating", EXTRACTOR_METATYPE_RATING); | ||
820 | ADDXMP ("Xmp.iptc.CountryCode", EXTRACTOR_METATYPE_LOCATION_COUNTRY_CODE); | ||
821 | ADDXMP ("Xmp.xmp.CreatorTool", EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); | ||
822 | ADDXMP ("Xmp.lr.hierarchicalSubject", EXTRACTOR_METATYPE_SUBJECT); | ||
810 | } | 823 | } |
824 | } | ||
825 | catch (const Exiv2::AnyError& e) | ||
826 | { | ||
827 | #if DEBUG | ||
828 | std::cerr << "Caught Exiv2 exception '" << e << "'\n"; | ||
829 | #endif | ||
830 | } | ||
831 | catch (void *anything) | ||
832 | { | ||
833 | } | ||
811 | } | 834 | } |
812 | 835 | ||
836 | |||
813 | /* end of exiv2_extractor.cc */ | 837 | /* end of exiv2_extractor.cc */ |