Mercurial > geeqie.yaz
annotate src/exiv2.cc @ 1070:abf48b53216b
simple synchronization XMP <-> Exif, IPTC
author | nadvornik |
---|---|
date | Sat, 18 Oct 2008 19:20:27 +0000 |
parents | aeae25d5d50d |
children | 01e743d275f2 |
rev | line source |
---|---|
475 | 1 /* |
2 * Geeqie | |
3 * Copyright (C) 2008 The Geeqie Team | |
4 * | |
5 * Author: Vladimir Nadvornik | |
6 * | |
7 * This software is released under the GNU General Public License (GNU GPL). | |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
10 */ | |
178 | 11 |
686 | 12 #include "config.h" |
178 | 13 |
14 #ifdef HAVE_EXIV2 | |
15 | |
16 #include <exiv2/image.hpp> | |
17 #include <exiv2/exif.hpp> | |
18 #include <iostream> | |
19 | |
200 | 20 // EXIV2_TEST_VERSION is defined in Exiv2 0.15 and newer. |
21 #ifndef EXIV2_TEST_VERSION | |
22 # define EXIV2_TEST_VERSION(major,minor,patch) \ | |
23 ( EXIV2_VERSION >= EXIV2_MAKE_VERSION(major,minor,patch) ) | |
24 #endif | |
25 | |
26 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
27 #include <sys/types.h> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
28 #include <sys/stat.h> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
29 #include <unistd.h> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
30 #include <fcntl.h> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
31 #include <sys/mman.h> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
32 |
1008 | 33 #if !EXIV2_TEST_VERSION(0,17,90) |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
34 #include <exiv2/tiffparser.hpp> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
35 #include <exiv2/tiffcomposite.hpp> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
36 #include <exiv2/tiffvisitor.hpp> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
37 #include <exiv2/tiffimage.hpp> |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
38 #include <exiv2/cr2image.hpp> |
191 | 39 #include <exiv2/crwimage.hpp> |
200 | 40 #if EXIV2_TEST_VERSION(0,16,0) |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
41 #include <exiv2/orfimage.hpp> |
200 | 42 #endif |
43 #if EXIV2_TEST_VERSION(0,13,0) | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
44 #include <exiv2/rafimage.hpp> |
200 | 45 #endif |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
46 #include <exiv2/futils.hpp> |
1008 | 47 #else |
48 #include <exiv2/preview.hpp> | |
49 #endif | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
50 |
1070 | 51 #if EXIV2_TEST_VERSION(0,17,0) |
52 #include <exiv2/convert.hpp> | |
53 #endif | |
54 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
55 |
178 | 56 extern "C" { |
995 | 57 #include <glib.h> |
507 | 58 |
281 | 59 #include "main.h" |
178 | 60 #include "exif.h" |
507 | 61 |
586 | 62 #include "filefilter.h" |
496
a1f13fab6686
fixed a bug in opening files with non-utf8 locales in exiv2.cc
nadvornik
parents:
495
diff
changeset
|
63 #include "ui_fileops.h" |
184 | 64 } |
178 | 65 |
66 struct _ExifData | |
67 { | |
185 | 68 Exiv2::ExifData::const_iterator exifIter; /* for exif_get_next_item */ |
69 Exiv2::IptcData::const_iterator iptcIter; /* for exif_get_next_item */ | |
200 | 70 #if EXIV2_TEST_VERSION(0,16,0) |
185 | 71 Exiv2::XmpData::const_iterator xmpIter; /* for exif_get_next_item */ |
200 | 72 #endif |
184 | 73 |
1069 | 74 virtual ~_ExifData() |
75 { | |
76 } | |
77 | |
78 virtual void writeMetadata() | |
184 | 79 { |
1069 | 80 g_critical("Unsupported method of writing metadata"); |
81 } | |
82 | |
83 virtual ExifData *original() | |
84 { | |
85 return NULL; | |
86 } | |
87 | |
88 virtual Exiv2::Image *image() = 0; | |
89 | |
90 virtual Exiv2::ExifData &exifData() = 0; | |
91 | |
92 virtual Exiv2::IptcData &iptcData() = 0; | |
200 | 93 |
94 #if EXIV2_TEST_VERSION(0,16,0) | |
1069 | 95 virtual Exiv2::XmpData &xmpData() = 0; |
96 #endif | |
97 | |
98 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length) = 0; | |
99 | |
100 virtual guchar *get_jpeg_color_profile(guint *data_len) = 0; | |
101 }; | |
102 | |
103 // This allows read-only access to the original metadata | |
104 struct _ExifDataOriginal : public _ExifData | |
105 { | |
106 protected: | |
107 Exiv2::Image::AutoPtr image_; | |
108 | |
109 /* the icc profile in jpeg is not technically exif - store it here */ | |
110 unsigned char *cp_data_; | |
111 guint cp_length_; | |
112 | |
113 public: | |
114 | |
115 _ExifDataOriginal(gchar *path) | |
116 { | |
117 cp_data_ = NULL; | |
118 cp_length_ = 0; | |
119 gchar *pathl = path_from_utf8(path); | |
120 image_ = Exiv2::ImageFactory::open(pathl); | |
121 g_free(pathl); | |
122 // g_assert (image.get() != 0); | |
123 image_->readMetadata(); | |
124 | |
125 #if EXIV2_TEST_VERSION(0,16,0) | |
126 if (image_->mimeType() == "application/rdf+xml") | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
127 { |
1069 | 128 //Exiv2 sidecar converts xmp to exif and iptc, we don't want it. |
129 image_->clearExifData(); | |
130 image_->clearIptcData(); | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
131 } |
1069 | 132 #endif |
449 | 133 |
452
0a69a779395a
fixed color profile code for older versions of exiv2
nadvornik
parents:
449
diff
changeset
|
134 #if EXIV2_TEST_VERSION(0,14,0) |
1069 | 135 if (image_->mimeType() == "image/jpeg") |
449 | 136 { |
137 /* try to get jpeg color profile */ | |
1069 | 138 Exiv2::BasicIo &io = image_->io(); |
449 | 139 gint open = io.isopen(); |
140 if (!open) io.open(); | |
141 unsigned char *mapped = (unsigned char*)io.mmap(); | |
142 if (mapped) exif_jpeg_parse_color(this, mapped, io.size()); | |
143 io.munmap(); | |
144 if (!open) io.close(); | |
145 } | |
995 | 146 #endif |
184 | 147 } |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
148 |
1069 | 149 virtual ~_ExifDataOriginal() |
449 | 150 { |
1069 | 151 if (cp_data_) g_free(cp_data_); |
449 | 152 } |
153 | |
1069 | 154 virtual Exiv2::Image *image() |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
155 { |
1069 | 156 return image_.get(); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
157 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
158 |
1069 | 159 virtual Exiv2::ExifData &exifData () |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
160 { |
1069 | 161 return image_->exifData(); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
162 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
163 |
1069 | 164 virtual Exiv2::IptcData &iptcData () |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
165 { |
1069 | 166 return image_->iptcData(); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
167 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
168 |
200 | 169 #if EXIV2_TEST_VERSION(0,16,0) |
1069 | 170 virtual Exiv2::XmpData &xmpData () |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
171 { |
1069 | 172 return image_->xmpData(); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
173 } |
200 | 174 #endif |
184 | 175 |
1069 | 176 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length) |
177 { | |
178 if (cp_data_) g_free(cp_data_); | |
179 cp_data_ = cp_data; | |
180 cp_length_ = cp_length; | |
181 } | |
182 | |
183 virtual guchar *get_jpeg_color_profile(guint *data_len) | |
184 { | |
185 if (cp_data_) | |
186 { | |
187 if (data_len) *data_len = cp_length_; | |
188 return (unsigned char *) g_memdup(cp_data_, cp_length_); | |
189 } | |
190 return NULL; | |
191 } | |
178 | 192 }; |
193 | |
1069 | 194 // This allows read-write access to the metadata |
195 struct _ExifDataProcessed : public _ExifData | |
196 { | |
197 protected: | |
198 _ExifDataOriginal *imageData_; | |
199 _ExifDataOriginal *sidecarData_; | |
200 | |
201 Exiv2::ExifData exifData_; | |
202 Exiv2::IptcData iptcData_; | |
203 #if EXIV2_TEST_VERSION(0,16,0) | |
204 Exiv2::XmpData xmpData_; | |
205 #endif | |
206 | |
207 public: | |
208 _ExifDataProcessed(gchar *path, gchar *sidecar_path) | |
209 { | |
210 imageData_ = new _ExifDataOriginal(path); | |
211 sidecarData_ = NULL; | |
212 #if EXIV2_TEST_VERSION(0,16,0) | |
213 xmpData_ = imageData_->xmpData(); | |
214 DEBUG_2("xmp count %li", xmpData_.count()); | |
215 if (sidecar_path && xmpData_.empty()) | |
216 { | |
217 sidecarData_ = new _ExifDataOriginal(sidecar_path); | |
218 xmpData_ = sidecarData_->xmpData(); | |
219 } | |
220 #endif | |
221 exifData_ = imageData_->exifData(); | |
222 iptcData_ = imageData_->iptcData(); | |
1070 | 223 #if EXIV2_TEST_VERSION(0,17,0) |
224 syncExifWithXmp(exifData_, xmpData_); | |
225 #endif | |
1069 | 226 } |
227 | |
228 virtual ~_ExifDataProcessed() | |
229 { | |
230 if (imageData_) delete imageData_; | |
231 if (sidecarData_) delete sidecarData_; | |
232 } | |
233 | |
234 virtual ExifData *original() | |
235 { | |
236 return imageData_; | |
237 } | |
238 | |
239 virtual void writeMetadata() | |
240 { | |
1070 | 241 #if EXIV2_TEST_VERSION(0,17,0) |
242 syncExifWithXmp(exifData_, xmpData_); | |
243 copyXmpToIptc(xmpData_, iptcData_); //FIXME it should be configurable | |
244 #endif | |
1069 | 245 if (sidecarData_) |
246 { | |
247 sidecarData_->image()->setXmpData(xmpData_); | |
248 //Exiv2 sidecar converts xmp to exif and iptc, we don't want it. | |
249 sidecarData_->image()->clearExifData(); | |
250 sidecarData_->image()->clearIptcData(); | |
251 sidecarData_->image()->writeMetadata(); | |
252 } | |
253 else | |
254 { | |
255 imageData_->image()->setExifData(exifData_); | |
256 imageData_->image()->setIptcData(iptcData_); | |
257 imageData_->image()->setXmpData(xmpData_); | |
258 imageData_->image()->writeMetadata(); | |
259 } | |
260 } | |
261 | |
262 virtual Exiv2::Image *image() | |
263 { | |
264 return imageData_->image(); | |
265 } | |
266 | |
267 virtual Exiv2::ExifData &exifData () | |
268 { | |
269 return exifData_; | |
270 } | |
271 | |
272 virtual Exiv2::IptcData &iptcData () | |
273 { | |
274 return iptcData_; | |
275 } | |
276 | |
277 #if EXIV2_TEST_VERSION(0,16,0) | |
278 virtual Exiv2::XmpData &xmpData () | |
279 { | |
280 return xmpData_; | |
281 } | |
282 #endif | |
283 | |
284 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length) | |
285 { | |
286 imageData_->add_jpeg_color_profile(cp_data, cp_length); | |
287 } | |
288 | |
289 virtual guchar *get_jpeg_color_profile(guint *data_len) | |
290 { | |
291 return imageData_->get_jpeg_color_profile(data_len); | |
292 } | |
293 }; | |
294 | |
295 | |
296 | |
297 | |
184 | 298 extern "C" { |
178 | 299 |
449 | 300 ExifData *exif_read(gchar *path, gchar *sidecar_path) |
178 | 301 { |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
496
diff
changeset
|
302 DEBUG_1("exif read %s, sidecar: %s", path, sidecar_path ? sidecar_path : "-"); |
178 | 303 try { |
1069 | 304 return new _ExifDataProcessed(path, sidecar_path); |
178 | 305 } |
306 catch (Exiv2::AnyError& e) { | |
307 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
308 return NULL; |
178 | 309 } |
179
37004d5a584a
and first version that actually shows some exif data (see advanced view)
nadvornik
parents:
178
diff
changeset
|
310 |
178 | 311 } |
312 | |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
313 int exif_write(ExifData *exif) |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
314 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
315 try { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
316 exif->writeMetadata(); |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
317 return 1; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
318 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
319 catch (Exiv2::AnyError& e) { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
320 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
321 return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
322 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
323 |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
324 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
325 |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
326 |
178 | 327 void exif_free(ExifData *exif) |
328 { | |
1069 | 329 g_assert(dynamic_cast<_ExifDataProcessed *>(exif)); // this should not be called on ExifDataOriginal |
182 | 330 delete exif; |
178 | 331 } |
332 | |
1069 | 333 ExifData *exif_get_original(ExifData *exif) |
334 { | |
335 return exif->original(); | |
336 } | |
337 | |
338 | |
184 | 339 ExifItem *exif_get_item(ExifData *exif, const gchar *key) |
178 | 340 { |
183 | 341 try { |
452
0a69a779395a
fixed color profile code for older versions of exiv2
nadvornik
parents:
449
diff
changeset
|
342 Exiv2::Metadatum *item = NULL; |
185 | 343 try { |
344 Exiv2::ExifKey ekey(key); | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
345 Exiv2::ExifData::iterator pos = exif->exifData().findKey(ekey); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
346 if (pos == exif->exifData().end()) return NULL; |
185 | 347 item = &*pos; |
348 } | |
349 catch (Exiv2::AnyError& e) { | |
350 try { | |
351 Exiv2::IptcKey ekey(key); | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
352 Exiv2::IptcData::iterator pos = exif->iptcData().findKey(ekey); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
353 if (pos == exif->iptcData().end()) return NULL; |
185 | 354 item = &*pos; |
355 } | |
356 catch (Exiv2::AnyError& e) { | |
200 | 357 #if EXIV2_TEST_VERSION(0,16,0) |
185 | 358 Exiv2::XmpKey ekey(key); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
359 Exiv2::XmpData::iterator pos = exif->xmpData().findKey(ekey); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
360 if (pos == exif->xmpData().end()) return NULL; |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
361 item = &*pos; |
200 | 362 #endif |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
363 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
364 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
365 return (ExifItem *)item; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
366 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
367 catch (Exiv2::AnyError& e) { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
368 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
369 return NULL; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
370 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
371 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
372 |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
373 ExifItem *exif_add_item(ExifData *exif, const gchar *key) |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
374 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
375 try { |
452
0a69a779395a
fixed color profile code for older versions of exiv2
nadvornik
parents:
449
diff
changeset
|
376 Exiv2::Metadatum *item = NULL; |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
377 try { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
378 Exiv2::ExifKey ekey(key); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
379 exif->exifData().add(ekey, NULL); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
380 Exiv2::ExifData::iterator pos = exif->exifData().end(); // a hack, there should be a better way to get the currently added item |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
381 pos--; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
382 item = &*pos; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
383 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
384 catch (Exiv2::AnyError& e) { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
385 try { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
386 Exiv2::IptcKey ekey(key); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
387 exif->iptcData().add(ekey, NULL); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
388 Exiv2::IptcData::iterator pos = exif->iptcData().end(); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
389 pos--; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
390 item = &*pos; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
391 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
392 catch (Exiv2::AnyError& e) { |
200 | 393 #if EXIV2_TEST_VERSION(0,16,0) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
394 Exiv2::XmpKey ekey(key); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
395 exif->xmpData().add(ekey, NULL); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
396 Exiv2::XmpData::iterator pos = exif->xmpData().end(); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
397 pos--; |
185 | 398 item = &*pos; |
200 | 399 #endif |
185 | 400 } |
401 } | |
184 | 402 return (ExifItem *)item; |
183 | 403 } |
404 catch (Exiv2::AnyError& e) { | |
184 | 405 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
406 return NULL; | |
407 } | |
408 } | |
409 | |
410 | |
411 ExifItem *exif_get_first_item(ExifData *exif) | |
412 { | |
413 try { | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
414 exif->exifIter = exif->exifData().begin(); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
415 exif->iptcIter = exif->iptcData().begin(); |
200 | 416 #if EXIV2_TEST_VERSION(0,16,0) |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
417 exif->xmpIter = exif->xmpData().begin(); |
200 | 418 #endif |
995 | 419 if (exif->exifIter != exif->exifData().end()) |
185 | 420 { |
421 const Exiv2::Metadatum *item = &*exif->exifIter; | |
422 exif->exifIter++; | |
423 return (ExifItem *)item; | |
424 } | |
995 | 425 if (exif->iptcIter != exif->iptcData().end()) |
185 | 426 { |
427 const Exiv2::Metadatum *item = &*exif->iptcIter; | |
428 exif->iptcIter++; | |
429 return (ExifItem *)item; | |
430 } | |
200 | 431 #if EXIV2_TEST_VERSION(0,16,0) |
995 | 432 if (exif->xmpIter != exif->xmpData().end()) |
185 | 433 { |
434 const Exiv2::Metadatum *item = &*exif->xmpIter; | |
435 exif->xmpIter++; | |
436 return (ExifItem *)item; | |
437 } | |
200 | 438 #endif |
185 | 439 return NULL; |
440 | |
184 | 441 } |
442 catch (Exiv2::AnyError& e) { | |
443 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
183 | 444 return NULL; |
445 } | |
178 | 446 } |
447 | |
448 ExifItem *exif_get_next_item(ExifData *exif) | |
449 { | |
184 | 450 try { |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
451 if (exif->exifIter != exif->exifData().end()) |
185 | 452 { |
453 const Exiv2::Metadatum *item = &*exif->exifIter; | |
454 exif->exifIter++; | |
455 return (ExifItem *)item; | |
456 } | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
457 if (exif->iptcIter != exif->iptcData().end()) |
185 | 458 { |
459 const Exiv2::Metadatum *item = &*exif->iptcIter; | |
460 exif->iptcIter++; | |
461 return (ExifItem *)item; | |
462 } | |
200 | 463 #if EXIV2_TEST_VERSION(0,16,0) |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
464 if (exif->xmpIter != exif->xmpData().end()) |
185 | 465 { |
466 const Exiv2::Metadatum *item = &*exif->xmpIter; | |
467 exif->xmpIter++; | |
468 return (ExifItem *)item; | |
469 } | |
200 | 470 #endif |
185 | 471 return NULL; |
184 | 472 } |
473 catch (Exiv2::AnyError& e) { | |
474 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
475 return NULL; | |
476 } | |
178 | 477 } |
478 | |
185 | 479 char *exif_item_get_tag_name(ExifItem *item) |
178 | 480 { |
184 | 481 try { |
482 if (!item) return NULL; | |
185 | 483 return g_strdup(((Exiv2::Metadatum *)item)->key().c_str()); |
184 | 484 } |
485 catch (Exiv2::AnyError& e) { | |
486 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
487 return NULL; | |
488 } | |
178 | 489 } |
490 | |
491 guint exif_item_get_tag_id(ExifItem *item) | |
492 { | |
184 | 493 try { |
494 if (!item) return 0; | |
185 | 495 return ((Exiv2::Metadatum *)item)->tag(); |
184 | 496 } |
497 catch (Exiv2::AnyError& e) { | |
498 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
499 return 0; | |
500 } | |
178 | 501 } |
502 | |
503 guint exif_item_get_elements(ExifItem *item) | |
504 { | |
184 | 505 try { |
506 if (!item) return 0; | |
185 | 507 return ((Exiv2::Metadatum *)item)->count(); |
184 | 508 } |
509 catch (Exiv2::AnyError& e) { | |
510 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
185 | 511 return 0; |
184 | 512 } |
178 | 513 } |
514 | |
515 char *exif_item_get_data(ExifItem *item, guint *data_len) | |
516 { | |
414
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
517 try { |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
518 if (!item) return 0; |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
519 Exiv2::Metadatum *md = (Exiv2::Metadatum *)item; |
855 | 520 if (data_len) *data_len = md->size(); |
414
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
521 char *data = (char *)g_malloc(md->size()); |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
522 long res = md->copy((Exiv2::byte *)data, Exiv2::littleEndian /* should not matter */); |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
523 g_assert(res == md->size()); |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
524 return data; |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
525 } |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
526 catch (Exiv2::AnyError& e) { |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
527 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
528 return NULL; |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
529 } |
178 | 530 } |
531 | |
182 | 532 char *exif_item_get_description(ExifItem *item) |
178 | 533 { |
184 | 534 try { |
535 if (!item) return NULL; | |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
536 return g_locale_to_utf8(((Exiv2::Metadatum *)item)->tagLabel().c_str(), -1, NULL, NULL, NULL); |
184 | 537 } |
185 | 538 catch (std::exception& e) { |
539 // std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
184 | 540 return NULL; |
541 } | |
178 | 542 } |
543 | |
544 /* | |
545 invalidTypeId, unsignedByte, asciiString, unsignedShort, | |
546 unsignedLong, unsignedRational, signedByte, undefined, | |
547 signedShort, signedLong, signedRational, string, | |
548 date, time, comment, directory, | |
549 xmpText, xmpAlt, xmpBag, xmpSeq, | |
995 | 550 langAlt, lastTypeId |
178 | 551 */ |
552 | |
184 | 553 static guint format_id_trans_tbl [] = { |
554 EXIF_FORMAT_UNKNOWN, | |
555 EXIF_FORMAT_BYTE_UNSIGNED, | |
556 EXIF_FORMAT_STRING, | |
557 EXIF_FORMAT_SHORT_UNSIGNED, | |
558 EXIF_FORMAT_LONG_UNSIGNED, | |
559 EXIF_FORMAT_RATIONAL_UNSIGNED, | |
560 EXIF_FORMAT_BYTE, | |
561 EXIF_FORMAT_UNDEFINED, | |
562 EXIF_FORMAT_SHORT, | |
563 EXIF_FORMAT_LONG, | |
564 EXIF_FORMAT_RATIONAL, | |
565 EXIF_FORMAT_STRING, | |
566 EXIF_FORMAT_STRING, | |
567 EXIF_FORMAT_STRING, | |
568 EXIF_FORMAT_UNDEFINED, | |
569 EXIF_FORMAT_STRING, | |
570 EXIF_FORMAT_STRING, | |
571 EXIF_FORMAT_STRING, | |
572 EXIF_FORMAT_STRING | |
573 }; | |
574 | |
575 | |
178 | 576 |
577 guint exif_item_get_format_id(ExifItem *item) | |
578 { | |
184 | 579 try { |
580 if (!item) return EXIF_FORMAT_UNKNOWN; | |
185 | 581 guint id = ((Exiv2::Metadatum *)item)->typeId(); |
184 | 582 if (id >= (sizeof(format_id_trans_tbl) / sizeof(format_id_trans_tbl[0])) ) return EXIF_FORMAT_UNKNOWN; |
583 return format_id_trans_tbl[id]; | |
584 } | |
585 catch (Exiv2::AnyError& e) { | |
586 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
587 return EXIF_FORMAT_UNKNOWN; | |
588 } | |
178 | 589 } |
184 | 590 |
178 | 591 const char *exif_item_get_format_name(ExifItem *item, gint brief) |
592 { | |
184 | 593 try { |
594 if (!item) return NULL; | |
185 | 595 return ((Exiv2::Metadatum *)item)->typeName(); |
184 | 596 } |
597 catch (Exiv2::AnyError& e) { | |
598 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
599 return NULL; | |
600 } | |
178 | 601 } |
602 | |
603 | |
604 gchar *exif_item_get_data_as_text(ExifItem *item) | |
605 { | |
183 | 606 try { |
184 | 607 if (!item) return NULL; |
676 | 608 Exiv2::Metadatum *metadatum = (Exiv2::Metadatum *)item; |
677 | 609 #if EXIV2_TEST_VERSION(0,17,0) |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
610 return g_locale_to_utf8(metadatum->print().c_str(), -1, NULL, NULL, NULL); |
676 | 611 #else |
612 std::stringstream str; | |
613 Exiv2::Exifdatum *exifdatum; | |
614 Exiv2::Iptcdatum *iptcdatum; | |
686 | 615 #if EXIV2_TEST_VERSION(0,16,0) |
676 | 616 Exiv2::Xmpdatum *xmpdatum; |
686 | 617 #endif |
855 | 618 if ((exifdatum = dynamic_cast<Exiv2::Exifdatum *>(metadatum))) |
676 | 619 str << *exifdatum; |
620 else if ((iptcdatum = dynamic_cast<Exiv2::Iptcdatum *>(metadatum))) | |
621 str << *iptcdatum; | |
622 #if EXIV2_TEST_VERSION(0,16,0) | |
623 else if ((xmpdatum = dynamic_cast<Exiv2::Xmpdatum *>(metadatum))) | |
624 str << *xmpdatum; | |
625 #endif | |
626 | |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
627 return g_locale_to_utf8(str.str().c_str(), -1, NULL, NULL, NULL); |
676 | 628 #endif |
183 | 629 } |
630 catch (Exiv2::AnyError& e) { | |
631 return NULL; | |
632 } | |
178 | 633 } |
634 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
635 gchar *exif_item_get_string(ExifItem *item, int idx) |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
636 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
637 try { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
638 if (!item) return NULL; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
639 Exiv2::Metadatum *em = (Exiv2::Metadatum *)item; |
200 | 640 #if EXIV2_TEST_VERSION(0,16,0) |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
641 std::string str = em->toString(idx); |
200 | 642 #else |
643 std::string str = em->toString(); // FIXME | |
644 #endif | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
645 if (idx == 0 && str == "") str = em->toString(); |
995 | 646 if (str.length() > 5 && str.substr(0, 5) == "lang=") |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
647 { |
995 | 648 std::string::size_type pos = str.find_first_of(' '); |
649 if (pos != std::string::npos) str = str.substr(pos+1); | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
650 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
651 |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
652 // return g_locale_to_utf8(str.c_str(), -1, NULL, NULL, NULL); // FIXME |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
653 return g_strdup(str.c_str()); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
654 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
655 catch (Exiv2::AnyError& e) { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
656 return NULL; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
657 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
658 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
659 |
178 | 660 |
661 gint exif_item_get_integer(ExifItem *item, gint *value) | |
662 { | |
184 | 663 try { |
664 if (!item) return 0; | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
665 *value = ((Exiv2::Metadatum *)item)->toLong(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
666 return 1; |
184 | 667 } |
668 catch (Exiv2::AnyError& e) { | |
669 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
670 return 0; | |
671 } | |
178 | 672 } |
673 | |
1058
b600689a677e
Fix up few signed vs unsigned warnings: exif_item_get_rational() last parameter is now of guint type.
zas_
parents:
1055
diff
changeset
|
674 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, guint n) |
178 | 675 { |
184 | 676 try { |
677 if (!item) return NULL; | |
1052 | 678 if (n >= exif_item_get_elements(item)) return NULL; |
679 Exiv2::Rational v = ((Exiv2::Metadatum *)item)->toRational(n); | |
184 | 680 static ExifRational ret; |
681 ret.num = v.first; | |
682 ret.den = v.second; | |
485 | 683 if (sign) *sign = (((Exiv2::Metadatum *)item)->typeId() == Exiv2::signedRational); |
184 | 684 return &ret; |
685 } | |
686 catch (Exiv2::AnyError& e) { | |
687 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
688 return NULL; | |
689 } | |
178 | 690 } |
691 | |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
692 gchar *exif_get_tag_description_by_key(const gchar *key) |
178 | 693 { |
184 | 694 try { |
695 Exiv2::ExifKey ekey(key); | |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
696 return g_locale_to_utf8(Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ()), -1, NULL, NULL, NULL); |
184 | 697 } |
698 catch (Exiv2::AnyError& e) { | |
699 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
700 return NULL; | |
701 } | |
178 | 702 } |
703 | |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
704 int exif_item_set_string(ExifItem *item, const char *str) |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
705 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
706 try { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
707 if (!item) return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
708 ((Exiv2::Metadatum *)item)->setValue(std::string(str)); |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
709 return 1; |
1008 | 710 } |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
711 catch (Exiv2::AnyError& e) { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
712 return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
713 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
714 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
715 |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
716 int exif_item_delete(ExifData *exif, ExifItem *item) |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
717 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
718 try { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
719 if (!item) return 0; |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
720 for (Exiv2::ExifData::iterator i = exif->exifData().begin(); i != exif->exifData().end(); ++i) { |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
721 if (((Exiv2::Metadatum *)item) == &*i) { |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
722 i = exif->exifData().erase(i); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
723 return 1; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
724 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
725 } |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
726 for (Exiv2::IptcData::iterator i = exif->iptcData().begin(); i != exif->iptcData().end(); ++i) { |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
727 if (((Exiv2::Metadatum *)item) == &*i) { |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
728 i = exif->iptcData().erase(i); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
729 return 1; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
730 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
731 } |
200 | 732 #if EXIV2_TEST_VERSION(0,16,0) |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
733 for (Exiv2::XmpData::iterator i = exif->xmpData().begin(); i != exif->xmpData().end(); ++i) { |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
734 if (((Exiv2::Metadatum *)item) == &*i) { |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
735 i = exif->xmpData().erase(i); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
736 return 1; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
737 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
738 } |
995 | 739 #endif |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
740 return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
741 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
742 catch (Exiv2::AnyError& e) { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
743 return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
744 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
745 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
746 |
449 | 747 void exif_add_jpeg_color_profile(ExifData *exif, unsigned char *cp_data, guint cp_length) |
748 { | |
1069 | 749 exif->add_jpeg_color_profile(cp_data, cp_length); |
449 | 750 } |
751 | |
1008 | 752 guchar *exif_get_color_profile(ExifData *exif, guint *data_len) |
449 | 753 { |
1069 | 754 guchar *ret = exif->get_jpeg_color_profile(data_len); |
755 if (ret) return ret; | |
756 | |
449 | 757 ExifItem *prof_item = exif_get_item(exif, "Exif.Image.InterColorProfile"); |
758 if (prof_item && exif_item_get_format_id(prof_item) == EXIF_FORMAT_UNDEFINED) | |
1069 | 759 ret = (guchar *)exif_item_get_data(prof_item, data_len); |
760 return ret; | |
449 | 761 } |
762 | |
1008 | 763 #if EXIV2_TEST_VERSION(0,17,90) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
764 |
1060 | 765 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height) |
1008 | 766 { |
767 if (!exif) return NULL; | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
768 |
1069 | 769 const char* path = exif->image()->io().path().c_str(); |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
770 /* given image pathname, first do simple (and fast) file extension test */ |
1060 | 771 gboolean is_raw = filter_file_class(path, FORMAT_CLASS_RAWIMAGE); |
772 | |
773 if (!is_raw && requested_width == 0) return NULL; | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
774 |
1008 | 775 try { |
776 | |
1069 | 777 Exiv2::PreviewManager pm(*exif->image()); |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
778 |
1064 | 779 Exiv2::PreviewPropertiesList list = pm.getPreviewProperties(); |
1008 | 780 |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
781 if (!list.empty()) |
1008 | 782 { |
1060 | 783 Exiv2::PreviewPropertiesList::iterator pos; |
784 Exiv2::PreviewPropertiesList::iterator last = --list.end(); | |
785 | |
786 if (requested_width == 0) | |
787 { | |
788 pos = last; // the largest | |
789 } | |
790 else | |
791 { | |
792 pos = list.begin(); | |
793 while (pos != last) | |
794 { | |
795 if (pos->width_ >= (uint32_t)requested_width && | |
796 pos->height_ >= (uint32_t)requested_height) break; | |
797 ++pos; | |
798 } | |
799 | |
800 // we are not interested in smaller thumbnails in normal image formats - we can use full image instead | |
801 if (!is_raw) | |
802 { | |
803 if (pos->width_ < (uint32_t)requested_width || pos->height_ < (uint32_t)requested_height) return NULL; | |
804 } | |
805 } | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
806 |
1064 | 807 Exiv2::PreviewImage image = pm.getPreviewImage(*pos); |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
808 |
1064 | 809 Exiv2::DataBuf buf = image.copy(); |
1008 | 810 std::pair<Exiv2::byte*, long> p = buf.release(); |
811 | |
812 *data_len = p.second; | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
813 return p.first; |
1008 | 814 } |
815 return NULL; | |
816 } | |
817 catch (Exiv2::AnyError& e) { | |
818 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
819 return NULL; | |
820 } | |
821 } | |
822 | |
823 void exif_free_preview(guchar *buf) | |
824 { | |
825 delete[] (Exiv2::byte*)buf; | |
826 } | |
827 #endif | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
828 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
829 } |
1008 | 830 #if !EXIV2_TEST_VERSION(0,17,90) |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
831 |
995 | 832 /* This is a dirty hack to support raw file preview, bassed on |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
833 tiffparse.cpp from Exiv2 examples */ |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
834 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
835 class RawFile { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
836 public: |
995 | 837 |
1008 | 838 RawFile(Exiv2::BasicIo &io); |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
839 ~RawFile(); |
995 | 840 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
841 const Exiv2::Value *find(uint16_t tag, uint16_t group); |
995 | 842 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
843 unsigned long preview_offset(); |
995 | 844 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
845 private: |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
846 int type; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
847 Exiv2::TiffComponent::AutoPtr rootDir; |
1008 | 848 Exiv2::BasicIo &io_; |
849 const Exiv2::byte *map_data; | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
850 size_t map_len; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
851 unsigned long offset; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
852 }; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
853 |
1008 | 854 typedef struct _UnmapData UnmapData; |
855 struct _UnmapData | |
856 { | |
857 guchar *ptr; | |
858 guchar *map_data; | |
859 size_t map_len; | |
860 }; | |
861 | |
862 static GList *exif_unmap_list = 0; | |
863 | |
1060 | 864 extern "C" guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height) |
1008 | 865 { |
866 unsigned long offset; | |
867 | |
868 if (!exif) return NULL; | |
1069 | 869 const char* path = exif->image()->io().path().c_str(); |
1008 | 870 |
871 /* given image pathname, first do simple (and fast) file extension test */ | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
872 if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return NULL; |
1008 | 873 |
874 try { | |
875 struct stat st; | |
876 guchar *map_data; | |
877 size_t map_len; | |
878 UnmapData *ud; | |
879 int fd; | |
880 | |
1069 | 881 RawFile rf(exif->image()->io()); |
1008 | 882 offset = rf.preview_offset(); |
883 DEBUG_1("%s: offset %lu", path, offset); | |
884 | |
885 fd = open(path, O_RDONLY); | |
886 if (fd == -1) | |
887 { | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
888 return NULL; |
1008 | 889 } |
890 | |
891 if (fstat(fd, &st) == -1) | |
892 { | |
893 close(fd); | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
894 return NULL; |
1008 | 895 } |
896 map_len = st.st_size; | |
897 map_data = (guchar *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0); | |
898 close(fd); | |
899 if (map_data == MAP_FAILED) | |
900 { | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
901 return NULL; |
1008 | 902 } |
903 *data_len = map_len - offset; | |
904 ud = g_new(UnmapData, 1); | |
905 ud->ptr = map_data + offset; | |
906 ud->map_data = map_data; | |
907 ud->map_len = map_len; | |
908 | |
909 exif_unmap_list = g_list_prepend(exif_unmap_list, ud); | |
910 return ud->ptr; | |
911 | |
912 } | |
913 catch (Exiv2::AnyError& e) { | |
914 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
915 } | |
916 return NULL; | |
917 | |
918 } | |
919 | |
920 void exif_free_preview(guchar *buf) | |
921 { | |
922 GList *work = exif_unmap_list; | |
923 | |
924 while (work) | |
925 { | |
926 UnmapData *ud = (UnmapData *)work->data; | |
927 if (ud->ptr == buf) | |
928 { | |
929 munmap(ud->map_data, ud->map_len); | |
930 exif_unmap_list = g_list_remove_link(exif_unmap_list, work); | |
931 g_free(ud); | |
932 return; | |
933 } | |
1025 | 934 work = work->next; |
1008 | 935 } |
936 g_assert_not_reached(); | |
937 } | |
938 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
939 using namespace Exiv2; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
940 |
1008 | 941 RawFile::RawFile(BasicIo &io) : io_(io), map_data(NULL), map_len(0), offset(0) |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
942 { |
1008 | 943 /* |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
944 struct stat st; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
945 if (fstat(fd, &st) == -1) |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
946 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
947 throw Error(14); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
948 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
949 map_len = st.st_size; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
950 map_data = (Exiv2::byte *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
951 if (map_data == MAP_FAILED) |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
952 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
953 throw Error(14); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
954 } |
1008 | 955 */ |
956 if (io.open() != 0) { | |
957 throw Error(9, io.path(), strError()); | |
958 } | |
959 | |
960 map_data = io.mmap(); | |
961 map_len = io.size(); | |
962 | |
963 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
964 type = Exiv2::ImageFactory::getType(map_data, map_len); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
965 |
200 | 966 #if EXIV2_TEST_VERSION(0,16,0) |
201 | 967 TiffHeaderBase *tiffHeader = NULL; |
200 | 968 #else |
201 | 969 TiffHeade2 *tiffHeader = NULL; |
200 | 970 #endif |
201 | 971 Cr2Header *cr2Header = NULL; |
972 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
973 switch (type) { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
974 case Exiv2::ImageType::tiff: |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
975 tiffHeader = new TiffHeade2(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
976 break; |
201 | 977 case Exiv2::ImageType::cr2: |
978 cr2Header = new Cr2Header(); | |
979 break; | |
200 | 980 #if EXIV2_TEST_VERSION(0,16,0) |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
981 case Exiv2::ImageType::orf: |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
982 tiffHeader = new OrfHeader(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
983 break; |
200 | 984 #endif |
985 #if EXIV2_TEST_VERSION(0,13,0) | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
986 case Exiv2::ImageType::raf: |
995 | 987 if (map_len < 84 + 4) throw Error(14); |
988 offset = getULong(map_data + 84, bigEndian); | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
989 return; |
200 | 990 #endif |
191 | 991 case Exiv2::ImageType::crw: |
992 { | |
993 // Parse the image, starting with a CIFF header component | |
994 Exiv2::CiffHeader::AutoPtr parseTree(new Exiv2::CiffHeader); | |
995 parseTree->read(map_data, map_len); | |
995 | 996 CiffComponent *entry = parseTree->findComponent(0x2007, 0); |
191 | 997 if (entry) offset = entry->pData() - map_data; |
998 return; | |
999 } | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1000 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1001 default: |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1002 throw Error(3, "RAW"); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1003 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1004 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1005 // process tiff-like formats |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1006 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1007 TiffCompFactoryFct createFct = TiffCreator::create; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1008 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1009 rootDir = createFct(Tag::root, Group::none); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1010 if (0 == rootDir.get()) { |
995 | 1011 throw Error(1, "No root element defined in TIFF structure"); |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1012 } |
201 | 1013 |
1014 if (tiffHeader) | |
1015 { | |
1016 if (!tiffHeader->read(map_data, map_len)) throw Error(3, "TIFF"); | |
200 | 1017 #if EXIV2_TEST_VERSION(0,16,0) |
201 | 1018 rootDir->setStart(map_data + tiffHeader->offset()); |
200 | 1019 #else |
201 | 1020 rootDir->setStart(map_data + tiffHeader->ifdOffset()); |
200 | 1021 #endif |
201 | 1022 } |
1023 | |
1024 if (cr2Header) | |
1025 { | |
1026 rootDir->setStart(map_data + cr2Header->offset()); | |
1027 } | |
1028 | |
1029 TiffRwState::AutoPtr state(new TiffRwState(tiffHeader ? tiffHeader->byteOrder() : littleEndian, 0, createFct)); | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1030 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1031 TiffReader reader(map_data, |
995 | 1032 map_len, |
1033 rootDir.get(), | |
1034 state); | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1035 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1036 rootDir->accept(reader); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1037 |
995 | 1038 if (tiffHeader) |
201 | 1039 delete tiffHeader; |
995 | 1040 if (cr2Header) |
201 | 1041 delete cr2Header; |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1042 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1043 |
609
b690cecbf5b8
Use function(void) instead of function() for declaring functions which
zas_
parents:
586
diff
changeset
|
1044 RawFile::~RawFile(void) |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1045 { |
1008 | 1046 io_.munmap(); |
1047 io_.close(); | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1048 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1049 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1050 const Value * RawFile::find(uint16_t tag, uint16_t group) |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1051 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1052 TiffFinder finder(tag, group); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1053 rootDir->accept(finder); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1054 TiffEntryBase* te = dynamic_cast<TiffEntryBase*>(finder.result()); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1055 if (te) |
194 | 1056 { |
495 | 1057 DEBUG_1("(tag: %04x %04x) ", tag, group); |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1058 return te->pValue(); |
194 | 1059 } |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1060 else |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1061 return NULL; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1062 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1063 |
609
b690cecbf5b8
Use function(void) instead of function() for declaring functions which
zas_
parents:
586
diff
changeset
|
1064 unsigned long RawFile::preview_offset(void) |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1065 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1066 const Value *val; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1067 if (offset) return offset; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1068 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1069 if (type == Exiv2::ImageType::cr2) |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1070 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1071 val = find(0x111, Group::ifd0); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1072 if (val) return val->toLong(); |
995 | 1073 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1074 return 0; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1075 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1076 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1077 val = find(0x201, Group::sub0_0); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1078 if (val) return val->toLong(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1079 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1080 val = find(0x201, Group::ifd0); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1081 if (val) return val->toLong(); |
995 | 1082 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1083 val = find(0x201, Group::ignr); // for PEF files, originally it was probably ifd2 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1084 if (val) return val->toLong(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1085 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1086 val = find(0x111, Group::sub0_1); // dng |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1087 if (val) return val->toLong(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1088 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1089 return 0; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1090 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1091 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1092 |
1008 | 1093 #endif |
178 | 1094 |
1095 | |
995 | 1096 #endif |
178 | 1097 /* HAVE_EXIV2 */ |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1053
diff
changeset
|
1098 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |