Mercurial > geeqie.yaz
annotate src/exiv2.cc @ 1439:2441a90c4bcf
compute histogram in idle time
author | nadvornik |
---|---|
date | Sun, 15 Mar 2009 11:34:09 +0000 |
parents | cd88fe4e5588 |
children | e37cde2857c1 |
rev | line source |
---|---|
475 | 1 /* |
2 * Geeqie | |
1284 | 3 * Copyright (C) 2008 - 2009 The Geeqie Team |
475 | 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> | |
1071 | 53 #include <exiv2/xmpsidecar.hpp> |
1070 | 54 #endif |
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" |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
64 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
65 #include "misc.h" |
184 | 66 } |
178 | 67 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
68 typedef struct _AltKey AltKey; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
69 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
70 struct _AltKey |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
71 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
72 const gchar *xmp_key; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
73 const gchar *exif_key; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
74 const gchar *iptc_key; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
75 }; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
76 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
77 /* this is a list of keys that should be converted, even with the older Exiv2 which does not support it directly */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
78 static const AltKey alt_keys[] = { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
79 {"Xmp.tiff.Orientation", "Exif.Image.Orientation", NULL}, |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
80 {"Xmp.dc.subject", NULL, "Iptc.Application2.Keywords"}, |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
81 {"Xmp.dc.description", NULL, "Iptc.Application2.Caption"}, |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
82 {NULL, NULL, NULL} |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
83 }; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
84 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
85 |
178 | 86 struct _ExifData |
87 { | |
185 | 88 Exiv2::ExifData::const_iterator exifIter; /* for exif_get_next_item */ |
89 Exiv2::IptcData::const_iterator iptcIter; /* for exif_get_next_item */ | |
200 | 90 #if EXIV2_TEST_VERSION(0,16,0) |
185 | 91 Exiv2::XmpData::const_iterator xmpIter; /* for exif_get_next_item */ |
200 | 92 #endif |
184 | 93 |
1069 | 94 virtual ~_ExifData() |
95 { | |
96 } | |
97 | |
1211 | 98 virtual void writeMetadata(gchar *path = NULL) |
184 | 99 { |
1069 | 100 g_critical("Unsupported method of writing metadata"); |
101 } | |
102 | |
103 virtual ExifData *original() | |
104 { | |
105 return NULL; | |
106 } | |
107 | |
108 virtual Exiv2::Image *image() = 0; | |
109 | |
110 virtual Exiv2::ExifData &exifData() = 0; | |
111 | |
112 virtual Exiv2::IptcData &iptcData() = 0; | |
200 | 113 |
114 #if EXIV2_TEST_VERSION(0,16,0) | |
1069 | 115 virtual Exiv2::XmpData &xmpData() = 0; |
116 #endif | |
117 | |
118 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length) = 0; | |
119 | |
120 virtual guchar *get_jpeg_color_profile(guint *data_len) = 0; | |
121 }; | |
122 | |
123 // This allows read-only access to the original metadata | |
124 struct _ExifDataOriginal : public _ExifData | |
125 { | |
126 protected: | |
127 Exiv2::Image::AutoPtr image_; | |
128 | |
129 /* the icc profile in jpeg is not technically exif - store it here */ | |
130 unsigned char *cp_data_; | |
131 guint cp_length_; | |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
132 gboolean valid_; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
133 |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
134 Exiv2::ExifData emptyExifData_; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
135 Exiv2::IptcData emptyIptcData_; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
136 #if EXIV2_TEST_VERSION(0,16,0) |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
137 Exiv2::XmpData emptyXmpData_; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
138 #endif |
1069 | 139 |
140 public: | |
1071 | 141 _ExifDataOriginal(Exiv2::Image::AutoPtr image) |
142 { | |
143 cp_data_ = NULL; | |
144 cp_length_ = 0; | |
145 image_ = image; | |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
146 valid_ = TRUE; |
1071 | 147 } |
1069 | 148 |
149 _ExifDataOriginal(gchar *path) | |
150 { | |
151 cp_data_ = NULL; | |
152 cp_length_ = 0; | |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
153 valid_ = TRUE; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
154 |
1069 | 155 gchar *pathl = path_from_utf8(path); |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
156 try |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
157 { |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
158 image_ = Exiv2::ImageFactory::open(pathl); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
159 // g_assert (image.get() != 0); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
160 image_->readMetadata(); |
1069 | 161 |
162 #if EXIV2_TEST_VERSION(0,16,0) | |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
163 if (image_->mimeType() == "application/rdf+xml") |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
164 { |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
165 //Exiv2 sidecar converts xmp to exif and iptc, we don't want it. |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
166 image_->clearExifData(); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
167 image_->clearIptcData(); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
168 } |
1069 | 169 #endif |
449 | 170 |
452
0a69a779395a
fixed color profile code for older versions of exiv2
nadvornik
parents:
449
diff
changeset
|
171 #if EXIV2_TEST_VERSION(0,14,0) |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
172 if (image_->mimeType() == "image/jpeg") |
1196 | 173 { |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
174 /* try to get jpeg color profile */ |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
175 Exiv2::BasicIo &io = image_->io(); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
176 gint open = io.isopen(); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
177 if (!open) io.open(); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
178 if (io.isopen()) |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
179 { |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
180 unsigned char *mapped = (unsigned char*)io.mmap(); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
181 if (mapped) exif_jpeg_parse_color(this, mapped, io.size()); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
182 io.munmap(); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
183 } |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
184 if (!open) io.close(); |
1196 | 185 } |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
186 #endif |
449 | 187 } |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
188 catch (Exiv2::AnyError& e) |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
189 { |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
190 valid_ = FALSE; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
191 } |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
192 g_free(pathl); |
184 | 193 } |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
194 |
1069 | 195 virtual ~_ExifDataOriginal() |
449 | 196 { |
1069 | 197 if (cp_data_) g_free(cp_data_); |
449 | 198 } |
199 | |
1069 | 200 virtual Exiv2::Image *image() |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
201 { |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
202 if (!valid_) return NULL; |
1069 | 203 return image_.get(); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
204 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
205 |
1069 | 206 virtual Exiv2::ExifData &exifData () |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
207 { |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
208 if (!valid_) return emptyExifData_; |
1069 | 209 return image_->exifData(); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
210 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
211 |
1069 | 212 virtual Exiv2::IptcData &iptcData () |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
213 { |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
214 if (!valid_) return emptyIptcData_; |
1069 | 215 return image_->iptcData(); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
216 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
217 |
200 | 218 #if EXIV2_TEST_VERSION(0,16,0) |
1069 | 219 virtual Exiv2::XmpData &xmpData () |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
220 { |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
221 if (!valid_) return emptyXmpData_; |
1069 | 222 return image_->xmpData(); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
223 } |
200 | 224 #endif |
184 | 225 |
1069 | 226 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length) |
227 { | |
228 if (cp_data_) g_free(cp_data_); | |
229 cp_data_ = cp_data; | |
230 cp_length_ = cp_length; | |
231 } | |
232 | |
233 virtual guchar *get_jpeg_color_profile(guint *data_len) | |
234 { | |
235 if (cp_data_) | |
236 { | |
237 if (data_len) *data_len = cp_length_; | |
238 return (unsigned char *) g_memdup(cp_data_, cp_length_); | |
239 } | |
240 return NULL; | |
241 } | |
178 | 242 }; |
243 | |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
244 extern "C" { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
245 static void _ExifDataProcessed_update_xmp(gpointer key, gpointer value, gpointer data); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
246 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
247 |
1069 | 248 // This allows read-write access to the metadata |
249 struct _ExifDataProcessed : public _ExifData | |
250 { | |
251 protected: | |
252 _ExifDataOriginal *imageData_; | |
253 _ExifDataOriginal *sidecarData_; | |
254 | |
255 Exiv2::ExifData exifData_; | |
256 Exiv2::IptcData iptcData_; | |
257 #if EXIV2_TEST_VERSION(0,16,0) | |
258 Exiv2::XmpData xmpData_; | |
259 #endif | |
260 | |
261 public: | |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
262 _ExifDataProcessed(gchar *path, gchar *sidecar_path, GHashTable *modified_xmp) |
1069 | 263 { |
264 imageData_ = new _ExifDataOriginal(path); | |
265 sidecarData_ = NULL; | |
266 #if EXIV2_TEST_VERSION(0,16,0) | |
1224 | 267 if (sidecar_path) |
1069 | 268 { |
269 sidecarData_ = new _ExifDataOriginal(sidecar_path); | |
270 xmpData_ = sidecarData_->xmpData(); | |
271 } | |
1224 | 272 else |
273 { | |
274 xmpData_ = imageData_->xmpData(); | |
275 } | |
276 | |
1069 | 277 #endif |
278 exifData_ = imageData_->exifData(); | |
279 iptcData_ = imageData_->iptcData(); | |
1070 | 280 #if EXIV2_TEST_VERSION(0,17,0) |
281 syncExifWithXmp(exifData_, xmpData_); | |
282 #endif | |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
283 if (modified_xmp) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
284 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
285 g_hash_table_foreach(modified_xmp, _ExifDataProcessed_update_xmp, this); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
286 } |
1069 | 287 } |
288 | |
289 virtual ~_ExifDataProcessed() | |
290 { | |
291 if (imageData_) delete imageData_; | |
292 if (sidecarData_) delete sidecarData_; | |
293 } | |
294 | |
295 virtual ExifData *original() | |
296 { | |
297 return imageData_; | |
298 } | |
299 | |
1211 | 300 virtual void writeMetadata(gchar *path = NULL) |
1069 | 301 { |
1211 | 302 if (!path) |
1069 | 303 { |
1211 | 304 #if EXIV2_TEST_VERSION(0,17,0) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
305 if (options->metadata.save_legacy_IPTC) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
306 copyXmpToIptc(xmpData_, iptcData_); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
307 else |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
308 iptcData_.clear(); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
309 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
310 copyXmpToExif(xmpData_, exifData_); |
1211 | 311 #endif |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
312 Exiv2::Image *image = imageData_->image(); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
313 |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
314 if (!image) Exiv2::Error(21); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
315 image->setExifData(exifData_); |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
316 image->setIptcData(iptcData_); |
1245 | 317 #if EXIV2_TEST_VERSION(0,16,0) |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
318 image->setXmpData(xmpData_); |
1245 | 319 #endif |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
320 image->writeMetadata(); |
1211 | 321 } |
1069 | 322 else |
323 { | |
1071 | 324 #if EXIV2_TEST_VERSION(0,17,0) |
1211 | 325 gchar *pathl = path_from_utf8(path);; |
1071 | 326 |
1211 | 327 Exiv2::Image::AutoPtr sidecar = Exiv2::ImageFactory::create(Exiv2::ImageType::xmp, pathl); |
1071 | 328 |
1211 | 329 g_free(pathl); |
330 | |
331 sidecar->setXmpData(xmpData_); | |
332 sidecar->writeMetadata(); | |
333 #else | |
334 throw Exiv2::Error(3, "xmp"); | |
1071 | 335 #endif |
1069 | 336 } |
337 } | |
338 | |
339 virtual Exiv2::Image *image() | |
340 { | |
341 return imageData_->image(); | |
342 } | |
343 | |
344 virtual Exiv2::ExifData &exifData () | |
345 { | |
346 return exifData_; | |
347 } | |
348 | |
349 virtual Exiv2::IptcData &iptcData () | |
350 { | |
351 return iptcData_; | |
352 } | |
353 | |
354 #if EXIV2_TEST_VERSION(0,16,0) | |
355 virtual Exiv2::XmpData &xmpData () | |
356 { | |
357 return xmpData_; | |
358 } | |
359 #endif | |
360 | |
361 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length) | |
362 { | |
363 imageData_->add_jpeg_color_profile(cp_data, cp_length); | |
364 } | |
365 | |
366 virtual guchar *get_jpeg_color_profile(guint *data_len) | |
367 { | |
368 return imageData_->get_jpeg_color_profile(data_len); | |
369 } | |
370 }; | |
371 | |
372 | |
373 | |
374 | |
184 | 375 extern "C" { |
178 | 376 |
1288 | 377 |
378 void exif_init(void) | |
379 { | |
380 #ifdef EXV_ENABLE_NLS | |
381 bind_textdomain_codeset (EXV_PACKAGE, "UTF-8"); | |
382 #endif | |
383 } | |
384 | |
385 | |
386 | |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
387 static void _ExifDataProcessed_update_xmp(gpointer key, gpointer value, gpointer data) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
388 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
389 exif_update_metadata((ExifData *)data, (gchar *)key, (GList *)value); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
390 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
391 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
392 ExifData *exif_read(gchar *path, gchar *sidecar_path, GHashTable *modified_xmp) |
178 | 393 { |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
496
diff
changeset
|
394 DEBUG_1("exif read %s, sidecar: %s", path, sidecar_path ? sidecar_path : "-"); |
178 | 395 try { |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
396 return new _ExifDataProcessed(path, sidecar_path, modified_xmp); |
178 | 397 } |
398 catch (Exiv2::AnyError& e) { | |
399 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
|
400 return NULL; |
178 | 401 } |
179
37004d5a584a
and first version that actually shows some exif data (see advanced view)
nadvornik
parents:
178
diff
changeset
|
402 |
178 | 403 } |
404 | |
1211 | 405 gboolean exif_write(ExifData *exif) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
406 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
407 try { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
408 exif->writeMetadata(); |
1211 | 409 return TRUE; |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
410 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
411 catch (Exiv2::AnyError& e) { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
412 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
1211 | 413 return FALSE; |
414 } | |
415 } | |
416 | |
417 gboolean exif_write_sidecar(ExifData *exif, gchar *path) | |
418 { | |
419 try { | |
420 exif->writeMetadata(path); | |
421 return TRUE; | |
422 } | |
423 catch (Exiv2::AnyError& e) { | |
424 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
425 return FALSE; | |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
426 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
427 |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
428 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
429 |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
430 |
178 | 431 void exif_free(ExifData *exif) |
432 { | |
1072 | 433 if (!exif) return; |
1069 | 434 g_assert(dynamic_cast<_ExifDataProcessed *>(exif)); // this should not be called on ExifDataOriginal |
182 | 435 delete exif; |
178 | 436 } |
437 | |
1069 | 438 ExifData *exif_get_original(ExifData *exif) |
439 { | |
440 return exif->original(); | |
441 } | |
442 | |
443 | |
184 | 444 ExifItem *exif_get_item(ExifData *exif, const gchar *key) |
178 | 445 { |
183 | 446 try { |
452
0a69a779395a
fixed color profile code for older versions of exiv2
nadvornik
parents:
449
diff
changeset
|
447 Exiv2::Metadatum *item = NULL; |
185 | 448 try { |
449 Exiv2::ExifKey ekey(key); | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
450 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
|
451 if (pos == exif->exifData().end()) return NULL; |
185 | 452 item = &*pos; |
453 } | |
454 catch (Exiv2::AnyError& e) { | |
455 try { | |
456 Exiv2::IptcKey ekey(key); | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
457 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
|
458 if (pos == exif->iptcData().end()) return NULL; |
185 | 459 item = &*pos; |
460 } | |
461 catch (Exiv2::AnyError& e) { | |
200 | 462 #if EXIV2_TEST_VERSION(0,16,0) |
185 | 463 Exiv2::XmpKey ekey(key); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
464 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
|
465 if (pos == exif->xmpData().end()) return NULL; |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
466 item = &*pos; |
200 | 467 #endif |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
468 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
469 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
470 return (ExifItem *)item; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
471 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
472 catch (Exiv2::AnyError& e) { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
473 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
474 return NULL; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
475 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
476 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
477 |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
478 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
|
479 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
480 try { |
452
0a69a779395a
fixed color profile code for older versions of exiv2
nadvornik
parents:
449
diff
changeset
|
481 Exiv2::Metadatum *item = NULL; |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
482 try { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
483 Exiv2::ExifKey ekey(key); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
484 exif->exifData().add(ekey, NULL); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
485 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
|
486 pos--; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
487 item = &*pos; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
488 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
489 catch (Exiv2::AnyError& e) { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
490 try { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
491 Exiv2::IptcKey ekey(key); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
492 exif->iptcData().add(ekey, NULL); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
493 Exiv2::IptcData::iterator pos = exif->iptcData().end(); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
494 pos--; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
495 item = &*pos; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
496 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
497 catch (Exiv2::AnyError& e) { |
200 | 498 #if EXIV2_TEST_VERSION(0,16,0) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
499 Exiv2::XmpKey ekey(key); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
500 exif->xmpData().add(ekey, NULL); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
501 Exiv2::XmpData::iterator pos = exif->xmpData().end(); |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
502 pos--; |
185 | 503 item = &*pos; |
200 | 504 #endif |
185 | 505 } |
506 } | |
184 | 507 return (ExifItem *)item; |
183 | 508 } |
509 catch (Exiv2::AnyError& e) { | |
184 | 510 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
511 return NULL; | |
512 } | |
513 } | |
514 | |
515 | |
516 ExifItem *exif_get_first_item(ExifData *exif) | |
517 { | |
518 try { | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
519 exif->exifIter = exif->exifData().begin(); |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
520 exif->iptcIter = exif->iptcData().begin(); |
200 | 521 #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
|
522 exif->xmpIter = exif->xmpData().begin(); |
200 | 523 #endif |
995 | 524 if (exif->exifIter != exif->exifData().end()) |
185 | 525 { |
526 const Exiv2::Metadatum *item = &*exif->exifIter; | |
527 exif->exifIter++; | |
528 return (ExifItem *)item; | |
529 } | |
995 | 530 if (exif->iptcIter != exif->iptcData().end()) |
185 | 531 { |
532 const Exiv2::Metadatum *item = &*exif->iptcIter; | |
533 exif->iptcIter++; | |
534 return (ExifItem *)item; | |
535 } | |
200 | 536 #if EXIV2_TEST_VERSION(0,16,0) |
995 | 537 if (exif->xmpIter != exif->xmpData().end()) |
185 | 538 { |
539 const Exiv2::Metadatum *item = &*exif->xmpIter; | |
540 exif->xmpIter++; | |
541 return (ExifItem *)item; | |
542 } | |
200 | 543 #endif |
185 | 544 return NULL; |
545 | |
184 | 546 } |
547 catch (Exiv2::AnyError& e) { | |
548 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
183 | 549 return NULL; |
550 } | |
178 | 551 } |
552 | |
553 ExifItem *exif_get_next_item(ExifData *exif) | |
554 { | |
184 | 555 try { |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
556 if (exif->exifIter != exif->exifData().end()) |
185 | 557 { |
558 const Exiv2::Metadatum *item = &*exif->exifIter; | |
559 exif->exifIter++; | |
560 return (ExifItem *)item; | |
561 } | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
562 if (exif->iptcIter != exif->iptcData().end()) |
185 | 563 { |
564 const Exiv2::Metadatum *item = &*exif->iptcIter; | |
565 exif->iptcIter++; | |
566 return (ExifItem *)item; | |
567 } | |
200 | 568 #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
|
569 if (exif->xmpIter != exif->xmpData().end()) |
185 | 570 { |
571 const Exiv2::Metadatum *item = &*exif->xmpIter; | |
572 exif->xmpIter++; | |
573 return (ExifItem *)item; | |
574 } | |
200 | 575 #endif |
185 | 576 return NULL; |
184 | 577 } |
578 catch (Exiv2::AnyError& e) { | |
579 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
580 return NULL; | |
581 } | |
178 | 582 } |
583 | |
185 | 584 char *exif_item_get_tag_name(ExifItem *item) |
178 | 585 { |
184 | 586 try { |
587 if (!item) return NULL; | |
185 | 588 return g_strdup(((Exiv2::Metadatum *)item)->key().c_str()); |
184 | 589 } |
590 catch (Exiv2::AnyError& e) { | |
591 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
592 return NULL; | |
593 } | |
178 | 594 } |
595 | |
596 guint exif_item_get_tag_id(ExifItem *item) | |
597 { | |
184 | 598 try { |
599 if (!item) return 0; | |
185 | 600 return ((Exiv2::Metadatum *)item)->tag(); |
184 | 601 } |
602 catch (Exiv2::AnyError& e) { | |
603 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
604 return 0; | |
605 } | |
178 | 606 } |
607 | |
608 guint exif_item_get_elements(ExifItem *item) | |
609 { | |
184 | 610 try { |
611 if (!item) return 0; | |
185 | 612 return ((Exiv2::Metadatum *)item)->count(); |
184 | 613 } |
614 catch (Exiv2::AnyError& e) { | |
615 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
185 | 616 return 0; |
184 | 617 } |
178 | 618 } |
619 | |
620 char *exif_item_get_data(ExifItem *item, guint *data_len) | |
621 { | |
414
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
622 try { |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
623 if (!item) return 0; |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
624 Exiv2::Metadatum *md = (Exiv2::Metadatum *)item; |
855 | 625 if (data_len) *data_len = md->size(); |
414
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
626 char *data = (char *)g_malloc(md->size()); |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
627 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
|
628 g_assert(res == md->size()); |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
629 return data; |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
630 } |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
631 catch (Exiv2::AnyError& e) { |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
632 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
633 return NULL; |
49c1cbe058ae
partially fixed reading embedded color profiles with exiv2
nadvornik
parents:
304
diff
changeset
|
634 } |
178 | 635 } |
636 | |
182 | 637 char *exif_item_get_description(ExifItem *item) |
178 | 638 { |
184 | 639 try { |
640 if (!item) return NULL; | |
1288 | 641 return utf8_validate_or_convert(((Exiv2::Metadatum *)item)->tagLabel().c_str()); |
184 | 642 } |
185 | 643 catch (std::exception& e) { |
644 // std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
184 | 645 return NULL; |
646 } | |
178 | 647 } |
648 | |
649 /* | |
650 invalidTypeId, unsignedByte, asciiString, unsignedShort, | |
651 unsignedLong, unsignedRational, signedByte, undefined, | |
652 signedShort, signedLong, signedRational, string, | |
653 date, time, comment, directory, | |
654 xmpText, xmpAlt, xmpBag, xmpSeq, | |
995 | 655 langAlt, lastTypeId |
178 | 656 */ |
657 | |
184 | 658 static guint format_id_trans_tbl [] = { |
659 EXIF_FORMAT_UNKNOWN, | |
660 EXIF_FORMAT_BYTE_UNSIGNED, | |
661 EXIF_FORMAT_STRING, | |
662 EXIF_FORMAT_SHORT_UNSIGNED, | |
663 EXIF_FORMAT_LONG_UNSIGNED, | |
664 EXIF_FORMAT_RATIONAL_UNSIGNED, | |
665 EXIF_FORMAT_BYTE, | |
666 EXIF_FORMAT_UNDEFINED, | |
667 EXIF_FORMAT_SHORT, | |
668 EXIF_FORMAT_LONG, | |
669 EXIF_FORMAT_RATIONAL, | |
670 EXIF_FORMAT_STRING, | |
671 EXIF_FORMAT_STRING, | |
672 EXIF_FORMAT_STRING, | |
673 EXIF_FORMAT_UNDEFINED, | |
674 EXIF_FORMAT_STRING, | |
675 EXIF_FORMAT_STRING, | |
676 EXIF_FORMAT_STRING, | |
677 EXIF_FORMAT_STRING | |
678 }; | |
679 | |
680 | |
178 | 681 |
682 guint exif_item_get_format_id(ExifItem *item) | |
683 { | |
184 | 684 try { |
685 if (!item) return EXIF_FORMAT_UNKNOWN; | |
185 | 686 guint id = ((Exiv2::Metadatum *)item)->typeId(); |
184 | 687 if (id >= (sizeof(format_id_trans_tbl) / sizeof(format_id_trans_tbl[0])) ) return EXIF_FORMAT_UNKNOWN; |
688 return format_id_trans_tbl[id]; | |
689 } | |
690 catch (Exiv2::AnyError& e) { | |
691 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
692 return EXIF_FORMAT_UNKNOWN; | |
693 } | |
178 | 694 } |
184 | 695 |
1422 | 696 const char *exif_item_get_format_name(ExifItem *item, gboolean brief) |
178 | 697 { |
184 | 698 try { |
699 if (!item) return NULL; | |
185 | 700 return ((Exiv2::Metadatum *)item)->typeName(); |
184 | 701 } |
702 catch (Exiv2::AnyError& e) { | |
703 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
704 return NULL; | |
705 } | |
178 | 706 } |
707 | |
708 | |
709 gchar *exif_item_get_data_as_text(ExifItem *item) | |
710 { | |
183 | 711 try { |
184 | 712 if (!item) return NULL; |
676 | 713 Exiv2::Metadatum *metadatum = (Exiv2::Metadatum *)item; |
677 | 714 #if EXIV2_TEST_VERSION(0,17,0) |
1288 | 715 return utf8_validate_or_convert(metadatum->print().c_str()); |
676 | 716 #else |
717 std::stringstream str; | |
718 Exiv2::Exifdatum *exifdatum; | |
719 Exiv2::Iptcdatum *iptcdatum; | |
686 | 720 #if EXIV2_TEST_VERSION(0,16,0) |
676 | 721 Exiv2::Xmpdatum *xmpdatum; |
686 | 722 #endif |
855 | 723 if ((exifdatum = dynamic_cast<Exiv2::Exifdatum *>(metadatum))) |
676 | 724 str << *exifdatum; |
725 else if ((iptcdatum = dynamic_cast<Exiv2::Iptcdatum *>(metadatum))) | |
726 str << *iptcdatum; | |
727 #if EXIV2_TEST_VERSION(0,16,0) | |
728 else if ((xmpdatum = dynamic_cast<Exiv2::Xmpdatum *>(metadatum))) | |
729 str << *xmpdatum; | |
730 #endif | |
731 | |
1288 | 732 return utf8_validate_or_convert(str.str().c_str()); |
676 | 733 #endif |
183 | 734 } |
735 catch (Exiv2::AnyError& e) { | |
736 return NULL; | |
737 } | |
178 | 738 } |
739 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
740 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
|
741 { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
742 try { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
743 if (!item) return NULL; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
744 Exiv2::Metadatum *em = (Exiv2::Metadatum *)item; |
200 | 745 #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
|
746 std::string str = em->toString(idx); |
200 | 747 #else |
748 std::string str = em->toString(); // FIXME | |
749 #endif | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
750 if (idx == 0 && str == "") str = em->toString(); |
995 | 751 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
|
752 { |
995 | 753 std::string::size_type pos = str.find_first_of(' '); |
754 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
|
755 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
756 |
1288 | 757 return utf8_validate_or_convert(str.c_str()); |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
758 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
759 catch (Exiv2::AnyError& e) { |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
760 return NULL; |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
761 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
762 } |
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
187
diff
changeset
|
763 |
178 | 764 |
765 gint exif_item_get_integer(ExifItem *item, gint *value) | |
766 { | |
184 | 767 try { |
768 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
|
769 *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
|
770 return 1; |
184 | 771 } |
772 catch (Exiv2::AnyError& e) { | |
773 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
774 return 0; | |
775 } | |
178 | 776 } |
777 | |
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
|
778 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, guint n) |
178 | 779 { |
184 | 780 try { |
781 if (!item) return NULL; | |
1052 | 782 if (n >= exif_item_get_elements(item)) return NULL; |
783 Exiv2::Rational v = ((Exiv2::Metadatum *)item)->toRational(n); | |
184 | 784 static ExifRational ret; |
785 ret.num = v.first; | |
786 ret.den = v.second; | |
485 | 787 if (sign) *sign = (((Exiv2::Metadatum *)item)->typeId() == Exiv2::signedRational); |
184 | 788 return &ret; |
789 } | |
790 catch (Exiv2::AnyError& e) { | |
791 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
792 return NULL; | |
793 } | |
178 | 794 } |
795 | |
1053
77ca9a5d42be
fixed charset of exiv2 strings in non-utf8 locales
nadvornik
parents:
1052
diff
changeset
|
796 gchar *exif_get_tag_description_by_key(const gchar *key) |
178 | 797 { |
184 | 798 try { |
799 Exiv2::ExifKey ekey(key); | |
1288 | 800 return utf8_validate_or_convert(Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ())); |
184 | 801 } |
802 catch (Exiv2::AnyError& e) { | |
803 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
804 return NULL; | |
805 } | |
178 | 806 } |
807 | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
808 static const AltKey *find_alt_key(const gchar *xmp_key) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
809 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
810 gint i = 0; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
811 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
812 while (alt_keys[i].xmp_key) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
813 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
814 if (strcmp(xmp_key, alt_keys[i].xmp_key) == 0) return &alt_keys[i]; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
815 i++; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
816 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
817 return NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
818 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
819 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
820 static gint exif_update_metadata_simple(ExifData *exif, const gchar *key, const GList *values) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
821 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
822 try { |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
823 const GList *work = values; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
824 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
825 try { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
826 Exiv2::ExifKey ekey(key); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
827 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
828 Exiv2::ExifData::iterator pos = exif->exifData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
829 while (pos != exif->exifData().end()) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
830 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
831 exif->exifData().erase(pos); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
832 pos = exif->exifData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
833 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
834 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
835 while (work) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
836 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
837 exif->exifData()[key] = (gchar *)work->data; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
838 work = work->next; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
839 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
840 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
841 catch (Exiv2::AnyError& e) { |
1245 | 842 #if EXIV2_TEST_VERSION(0,16,0) |
843 try | |
844 #endif | |
845 { | |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
846 Exiv2::IptcKey ekey(key); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
847 Exiv2::IptcData::iterator pos = exif->iptcData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
848 while (pos != exif->iptcData().end()) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
849 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
850 exif->iptcData().erase(pos); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
851 pos = exif->iptcData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
852 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
853 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
854 while (work) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
855 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
856 exif->iptcData()[key] = (gchar *)work->data; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
857 work = work->next; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
858 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
859 } |
1245 | 860 #if EXIV2_TEST_VERSION(0,16,0) |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
861 catch (Exiv2::AnyError& e) { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
862 Exiv2::XmpKey ekey(key); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
863 Exiv2::XmpData::iterator pos = exif->xmpData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
864 while (pos != exif->xmpData().end()) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
865 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
866 exif->xmpData().erase(pos); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
867 pos = exif->xmpData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
868 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
869 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
870 while (work) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
871 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
872 exif->xmpData()[key] = (gchar *)work->data; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
873 work = work->next; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
874 } |
1245 | 875 } |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
876 #endif |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
877 } |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
878 return 1; |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
879 } |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
880 catch (Exiv2::AnyError& e) { |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
881 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
882 return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
883 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
884 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
885 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
886 gint exif_update_metadata(ExifData *exif, const gchar *key, const GList *values) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
887 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
888 gint ret = exif_update_metadata_simple(exif, key, values); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
889 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
890 if ( |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
891 #if !EXIV2_TEST_VERSION(0,17,0) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
892 TRUE || /* no conversion support */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
893 #endif |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
894 !values || /* deleting item */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
895 !ret /* writing to the explicitely given xmp tag failed */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
896 ) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
897 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
898 /* deleted xmp metadatum can't be converted, we have to delete also the corresponding legacy tag */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
899 /* if we can't write xmp, update at least the legacy tag */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
900 const AltKey *alt_key = find_alt_key(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
901 if (alt_key && alt_key->iptc_key) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
902 ret = exif_update_metadata_simple(exif, alt_key->iptc_key, values); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
903 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
904 if (alt_key && alt_key->exif_key) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
905 ret = exif_update_metadata_simple(exif, alt_key->exif_key, values); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
906 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
907 return ret; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
908 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
909 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
910 |
1288 | 911 static GList *exif_add_value_to_glist(GList *list, Exiv2::Metadatum &item, MetadataFormat format, const Exiv2::ExifData *metadata) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
912 { |
1245 | 913 #if EXIV2_TEST_VERSION(0,16,0) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
914 Exiv2::TypeId id = item.typeId(); |
1288 | 915 if (format == METADATA_FORMATTED || |
916 id == Exiv2::asciiString || | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
917 id == Exiv2::undefined || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
918 id == Exiv2::string || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
919 id == Exiv2::date || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
920 id == Exiv2::time || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
921 id == Exiv2::xmpText || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
922 id == Exiv2::langAlt || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
923 id == Exiv2::comment |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
924 ) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
925 { |
1245 | 926 #endif |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
927 /* read as a single entry */ |
1288 | 928 std::string str; |
929 | |
930 if (format == METADATA_FORMATTED) | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
931 { |
1288 | 932 #if EXIV2_TEST_VERSION(0,17,0) |
933 str = item.print( | |
934 #if EXIV2_TEST_VERSION(0,18,0) | |
935 metadata | |
936 #endif | |
937 ); | |
938 #else | |
939 std::stringstream stream; | |
940 Exiv2::Exifdatum *exifdatum; | |
941 Exiv2::Iptcdatum *iptcdatum; | |
942 #if EXIV2_TEST_VERSION(0,16,0) | |
943 Exiv2::Xmpdatum *xmpdatum; | |
944 #endif | |
945 if ((exifdatum = dynamic_cast<Exiv2::Exifdatum *>(metadatum))) | |
946 stream << *exifdatum; | |
947 else if ((iptcdatum = dynamic_cast<Exiv2::Iptcdatum *>(metadatum))) | |
948 stream << *iptcdatum; | |
949 #if EXIV2_TEST_VERSION(0,16,0) | |
950 else if ((xmpdatum = dynamic_cast<Exiv2::Xmpdatum *>(metadatum))) | |
951 stream << *xmpdatum; | |
952 #endif | |
953 str = stream.str(); | |
954 #endif | |
955 if (str.length() > 1024) | |
956 { | |
957 /* truncate very long strings, they cause problems in gui */ | |
958 str.erase(1024); | |
959 str.append("..."); | |
960 } | |
961 } | |
962 else | |
963 { | |
964 str = item.toString(); | |
965 if (str.length() > 5 && str.substr(0, 5) == "lang=") | |
966 { | |
967 std::string::size_type pos = str.find_first_of(' '); | |
968 if (pos != std::string::npos) str = str.substr(pos+1); | |
969 } | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
970 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
971 list = g_list_append(list, utf8_validate_or_convert(str.c_str())); |
1245 | 972 #if EXIV2_TEST_VERSION(0,16,0) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
973 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
974 else |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
975 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
976 /* read as a list */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
977 gint i; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
978 for (i = 0; i < item.count(); i++) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
979 list = g_list_append(list, utf8_validate_or_convert(item.toString(i).c_str())); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
980 } |
1245 | 981 #endif |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
982 return list; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
983 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
984 |
1288 | 985 static GList *exif_get_metadata_simple(ExifData *exif, const gchar *key, MetadataFormat format) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
986 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
987 GList *list = NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
988 try { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
989 try { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
990 Exiv2::ExifKey ekey(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
991 Exiv2::ExifData::iterator pos = exif->exifData().findKey(ekey); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
992 if (pos != exif->exifData().end()) |
1288 | 993 list = exif_add_value_to_glist(list, *pos, format, &exif->exifData()); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
994 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
995 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
996 catch (Exiv2::AnyError& e) { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
997 try { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
998 Exiv2::IptcKey ekey(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
999 Exiv2::IptcData::iterator pos = exif->iptcData().begin(); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1000 while (pos != exif->iptcData().end()) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1001 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1002 if (pos->key() == key) |
1288 | 1003 list = exif_add_value_to_glist(list, *pos, format, NULL); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1004 ++pos; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1005 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1006 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1007 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1008 catch (Exiv2::AnyError& e) { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1009 #if EXIV2_TEST_VERSION(0,16,0) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1010 Exiv2::XmpKey ekey(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1011 Exiv2::XmpData::iterator pos = exif->xmpData().findKey(ekey); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1012 if (pos != exif->xmpData().end()) |
1288 | 1013 list = exif_add_value_to_glist(list, *pos, format, NULL); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1014 #endif |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1015 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1016 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1017 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1018 catch (Exiv2::AnyError& e) { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1019 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1020 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1021 return list; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1022 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1023 |
1288 | 1024 GList *exif_get_metadata(ExifData *exif, const gchar *key, MetadataFormat format) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1025 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1026 GList *list = NULL; |
1288 | 1027 |
1028 if (!key) return NULL; | |
1029 | |
1030 if (format == METADATA_FORMATTED) | |
1031 { | |
1032 gchar *text; | |
1033 gint key_valid; | |
1034 text = exif_get_formatted_by_key(exif, key, &key_valid); | |
1035 if (key_valid) return g_list_append(NULL, text); | |
1036 } | |
1037 | |
1038 list = exif_get_metadata_simple(exif, key, format); | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1039 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1040 /* the following code can be ifdefed out as soon as Exiv2 supports it */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1041 if (!list) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1042 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1043 const AltKey *alt_key = find_alt_key(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1044 if (alt_key && alt_key->iptc_key) |
1288 | 1045 list = exif_get_metadata_simple(exif, alt_key->iptc_key, format); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1046 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1047 #if !EXIV2_TEST_VERSION(0,17,0) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1048 /* with older Exiv2 versions exif is not synced */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1049 if (!list && alt_key && alt_key->exif_key) |
1288 | 1050 list = exif_get_metadata_simple(exif, alt_key->exif_key, format); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1051 #endif |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1052 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1053 return list; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1054 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1055 |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
1056 |
449 | 1057 void exif_add_jpeg_color_profile(ExifData *exif, unsigned char *cp_data, guint cp_length) |
1058 { | |
1069 | 1059 exif->add_jpeg_color_profile(cp_data, cp_length); |
449 | 1060 } |
1061 | |
1008 | 1062 guchar *exif_get_color_profile(ExifData *exif, guint *data_len) |
449 | 1063 { |
1069 | 1064 guchar *ret = exif->get_jpeg_color_profile(data_len); |
1065 if (ret) return ret; | |
1066 | |
449 | 1067 ExifItem *prof_item = exif_get_item(exif, "Exif.Image.InterColorProfile"); |
1068 if (prof_item && exif_item_get_format_id(prof_item) == EXIF_FORMAT_UNDEFINED) | |
1069 | 1069 ret = (guchar *)exif_item_get_data(prof_item, data_len); |
1070 return ret; | |
449 | 1071 } |
1072 | |
1008 | 1073 #if EXIV2_TEST_VERSION(0,17,90) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
1074 |
1060 | 1075 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height) |
1008 | 1076 { |
1077 if (!exif) return NULL; | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1078 |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
1079 if (!exif->image()) return NULL; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
1080 |
1069 | 1081 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
|
1082 /* given image pathname, first do simple (and fast) file extension test */ |
1060 | 1083 gboolean is_raw = filter_file_class(path, FORMAT_CLASS_RAWIMAGE); |
1084 | |
1085 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
|
1086 |
1008 | 1087 try { |
1088 | |
1069 | 1089 Exiv2::PreviewManager pm(*exif->image()); |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1090 |
1064 | 1091 Exiv2::PreviewPropertiesList list = pm.getPreviewProperties(); |
1008 | 1092 |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1093 if (!list.empty()) |
1008 | 1094 { |
1060 | 1095 Exiv2::PreviewPropertiesList::iterator pos; |
1096 Exiv2::PreviewPropertiesList::iterator last = --list.end(); | |
1097 | |
1098 if (requested_width == 0) | |
1099 { | |
1100 pos = last; // the largest | |
1101 } | |
1102 else | |
1103 { | |
1104 pos = list.begin(); | |
1105 while (pos != last) | |
1106 { | |
1107 if (pos->width_ >= (uint32_t)requested_width && | |
1108 pos->height_ >= (uint32_t)requested_height) break; | |
1109 ++pos; | |
1110 } | |
1111 | |
1112 // we are not interested in smaller thumbnails in normal image formats - we can use full image instead | |
1113 if (!is_raw) | |
1114 { | |
1115 if (pos->width_ < (uint32_t)requested_width || pos->height_ < (uint32_t)requested_height) return NULL; | |
1116 } | |
1117 } | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1118 |
1064 | 1119 Exiv2::PreviewImage image = pm.getPreviewImage(*pos); |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1120 |
1064 | 1121 Exiv2::DataBuf buf = image.copy(); |
1008 | 1122 std::pair<Exiv2::byte*, long> p = buf.release(); |
1123 | |
1124 *data_len = p.second; | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1125 return p.first; |
1008 | 1126 } |
1127 return NULL; | |
1128 } | |
1129 catch (Exiv2::AnyError& e) { | |
1130 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
1131 return NULL; | |
1132 } | |
1133 } | |
1134 | |
1135 void exif_free_preview(guchar *buf) | |
1136 { | |
1137 delete[] (Exiv2::byte*)buf; | |
1138 } | |
1139 #endif | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1140 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1141 } |
1008 | 1142 #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
|
1143 |
995 | 1144 /* 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
|
1145 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
|
1146 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1147 class RawFile { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1148 public: |
995 | 1149 |
1008 | 1150 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
|
1151 ~RawFile(); |
995 | 1152 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1153 const Exiv2::Value *find(uint16_t tag, uint16_t group); |
995 | 1154 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1155 unsigned long preview_offset(); |
995 | 1156 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1157 private: |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1158 int type; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1159 Exiv2::TiffComponent::AutoPtr rootDir; |
1008 | 1160 Exiv2::BasicIo &io_; |
1161 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
|
1162 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
|
1163 unsigned long offset; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1164 }; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1165 |
1008 | 1166 typedef struct _UnmapData UnmapData; |
1167 struct _UnmapData | |
1168 { | |
1169 guchar *ptr; | |
1170 guchar *map_data; | |
1171 size_t map_len; | |
1172 }; | |
1173 | |
1174 static GList *exif_unmap_list = 0; | |
1175 | |
1060 | 1176 extern "C" guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height) |
1008 | 1177 { |
1178 unsigned long offset; | |
1179 | |
1180 if (!exif) return NULL; | |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
1181 if (!exif->image()) return NULL; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
1182 |
1069 | 1183 const char* path = exif->image()->io().path().c_str(); |
1008 | 1184 |
1185 /* 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
|
1186 if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return NULL; |
1008 | 1187 |
1188 try { | |
1189 struct stat st; | |
1190 guchar *map_data; | |
1191 size_t map_len; | |
1192 UnmapData *ud; | |
1193 int fd; | |
1194 | |
1069 | 1195 RawFile rf(exif->image()->io()); |
1008 | 1196 offset = rf.preview_offset(); |
1197 DEBUG_1("%s: offset %lu", path, offset); | |
1198 | |
1199 fd = open(path, O_RDONLY); | |
1200 if (fd == -1) | |
1201 { | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1202 return NULL; |
1008 | 1203 } |
1204 | |
1205 if (fstat(fd, &st) == -1) | |
1206 { | |
1207 close(fd); | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1208 return NULL; |
1008 | 1209 } |
1210 map_len = st.st_size; | |
1211 map_data = (guchar *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0); | |
1212 close(fd); | |
1213 if (map_data == MAP_FAILED) | |
1214 { | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1215 return NULL; |
1008 | 1216 } |
1217 *data_len = map_len - offset; | |
1218 ud = g_new(UnmapData, 1); | |
1219 ud->ptr = map_data + offset; | |
1220 ud->map_data = map_data; | |
1221 ud->map_len = map_len; | |
1222 | |
1223 exif_unmap_list = g_list_prepend(exif_unmap_list, ud); | |
1224 return ud->ptr; | |
1225 | |
1226 } | |
1227 catch (Exiv2::AnyError& e) { | |
1228 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
1229 } | |
1230 return NULL; | |
1231 | |
1232 } | |
1233 | |
1234 void exif_free_preview(guchar *buf) | |
1235 { | |
1236 GList *work = exif_unmap_list; | |
1237 | |
1238 while (work) | |
1239 { | |
1240 UnmapData *ud = (UnmapData *)work->data; | |
1241 if (ud->ptr == buf) | |
1242 { | |
1243 munmap(ud->map_data, ud->map_len); | |
1244 exif_unmap_list = g_list_remove_link(exif_unmap_list, work); | |
1245 g_free(ud); | |
1246 return; | |
1247 } | |
1025 | 1248 work = work->next; |
1008 | 1249 } |
1250 g_assert_not_reached(); | |
1251 } | |
1252 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1253 using namespace Exiv2; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1254 |
1008 | 1255 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
|
1256 { |
1008 | 1257 /* |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1258 struct stat st; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1259 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
|
1260 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1261 throw Error(14); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1262 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1263 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
|
1264 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
|
1265 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
|
1266 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1267 throw Error(14); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1268 } |
1008 | 1269 */ |
1270 if (io.open() != 0) { | |
1271 throw Error(9, io.path(), strError()); | |
1272 } | |
1273 | |
1274 map_data = io.mmap(); | |
1275 map_len = io.size(); | |
1276 | |
1277 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1278 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
|
1279 |
200 | 1280 #if EXIV2_TEST_VERSION(0,16,0) |
201 | 1281 TiffHeaderBase *tiffHeader = NULL; |
200 | 1282 #else |
201 | 1283 TiffHeade2 *tiffHeader = NULL; |
200 | 1284 #endif |
201 | 1285 Cr2Header *cr2Header = NULL; |
1286 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1287 switch (type) { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1288 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
|
1289 tiffHeader = new TiffHeade2(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1290 break; |
201 | 1291 case Exiv2::ImageType::cr2: |
1292 cr2Header = new Cr2Header(); | |
1293 break; | |
200 | 1294 #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
|
1295 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
|
1296 tiffHeader = new OrfHeader(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1297 break; |
200 | 1298 #endif |
1299 #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
|
1300 case Exiv2::ImageType::raf: |
995 | 1301 if (map_len < 84 + 4) throw Error(14); |
1302 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
|
1303 return; |
200 | 1304 #endif |
191 | 1305 case Exiv2::ImageType::crw: |
1306 { | |
1307 // Parse the image, starting with a CIFF header component | |
1308 Exiv2::CiffHeader::AutoPtr parseTree(new Exiv2::CiffHeader); | |
1309 parseTree->read(map_data, map_len); | |
995 | 1310 CiffComponent *entry = parseTree->findComponent(0x2007, 0); |
191 | 1311 if (entry) offset = entry->pData() - map_data; |
1312 return; | |
1313 } | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1314 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1315 default: |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1316 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
|
1317 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1318 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1319 // 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
|
1320 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1321 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
|
1322 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1323 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
|
1324 if (0 == rootDir.get()) { |
995 | 1325 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
|
1326 } |
201 | 1327 |
1328 if (tiffHeader) | |
1329 { | |
1330 if (!tiffHeader->read(map_data, map_len)) throw Error(3, "TIFF"); | |
200 | 1331 #if EXIV2_TEST_VERSION(0,16,0) |
201 | 1332 rootDir->setStart(map_data + tiffHeader->offset()); |
200 | 1333 #else |
201 | 1334 rootDir->setStart(map_data + tiffHeader->ifdOffset()); |
200 | 1335 #endif |
201 | 1336 } |
1337 | |
1338 if (cr2Header) | |
1339 { | |
1340 rootDir->setStart(map_data + cr2Header->offset()); | |
1341 } | |
1342 | |
1343 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
|
1344 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1345 TiffReader reader(map_data, |
995 | 1346 map_len, |
1347 rootDir.get(), | |
1348 state); | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1349 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1350 rootDir->accept(reader); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1351 |
995 | 1352 if (tiffHeader) |
201 | 1353 delete tiffHeader; |
995 | 1354 if (cr2Header) |
201 | 1355 delete cr2Header; |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1356 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1357 |
609
b690cecbf5b8
Use function(void) instead of function() for declaring functions which
zas_
parents:
586
diff
changeset
|
1358 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
|
1359 { |
1008 | 1360 io_.munmap(); |
1361 io_.close(); | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1362 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1363 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1364 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
|
1365 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1366 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
|
1367 rootDir->accept(finder); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1368 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
|
1369 if (te) |
194 | 1370 { |
495 | 1371 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
|
1372 return te->pValue(); |
194 | 1373 } |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1374 else |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1375 return NULL; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1376 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1377 |
609
b690cecbf5b8
Use function(void) instead of function() for declaring functions which
zas_
parents:
586
diff
changeset
|
1378 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
|
1379 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1380 const Value *val; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1381 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
|
1382 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1383 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
|
1384 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1385 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
|
1386 if (val) return val->toLong(); |
995 | 1387 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1388 return 0; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1389 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1390 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1391 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
|
1392 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
|
1393 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1394 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
|
1395 if (val) return val->toLong(); |
995 | 1396 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1397 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
|
1398 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
|
1399 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1400 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
|
1401 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
|
1402 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1403 return 0; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1404 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1405 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1406 |
1008 | 1407 #endif |
178 | 1408 |
1409 | |
995 | 1410 #endif |
178 | 1411 /* HAVE_EXIV2 */ |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1053
diff
changeset
|
1412 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |