Mercurial > geeqie.yaz
annotate src/exiv2.cc @ 1443:f879e7d94c6d
gint -> gboolean.
author | zas_ |
---|---|
date | Sun, 15 Mar 2009 13:33:56 +0000 |
parents | e37cde2857c1 |
children | 8178ef34d257 |
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); | |
1442 | 800 return utf8_validate_or_convert(ekey.tagLabel().c_str()); |
184 | 801 } |
802 catch (Exiv2::AnyError& e) { | |
1442 | 803 try { |
804 Exiv2::IptcKey ikey(key); | |
805 return utf8_validate_or_convert(ikey.tagLabel().c_str()); | |
806 } | |
807 catch (Exiv2::AnyError& e) { | |
808 try { | |
809 #if EXIV2_TEST_VERSION(0,16,0) | |
810 Exiv2::XmpKey xkey(key); | |
811 return utf8_validate_or_convert(xkey.tagLabel().c_str()); | |
812 #endif | |
813 } | |
814 catch (Exiv2::AnyError& e) { | |
815 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
816 return NULL; | |
817 } | |
818 } | |
184 | 819 } |
1442 | 820 return NULL; |
178 | 821 } |
822 | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
823 static const AltKey *find_alt_key(const gchar *xmp_key) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
824 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
825 gint i = 0; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
826 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
827 while (alt_keys[i].xmp_key) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
828 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
829 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
|
830 i++; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
831 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
832 return NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
833 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
834 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
835 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
|
836 { |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
837 try { |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
838 const GList *work = values; |
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 try { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
841 Exiv2::ExifKey ekey(key); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
842 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
843 Exiv2::ExifData::iterator pos = exif->exifData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
844 while (pos != exif->exifData().end()) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
845 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
846 exif->exifData().erase(pos); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
847 pos = exif->exifData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
848 } |
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 while (work) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
851 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
852 exif->exifData()[key] = (gchar *)work->data; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
853 work = work->next; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
854 } |
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 catch (Exiv2::AnyError& e) { |
1245 | 857 #if EXIV2_TEST_VERSION(0,16,0) |
858 try | |
859 #endif | |
860 { | |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
861 Exiv2::IptcKey ekey(key); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
862 Exiv2::IptcData::iterator pos = exif->iptcData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
863 while (pos != exif->iptcData().end()) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
864 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
865 exif->iptcData().erase(pos); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
866 pos = exif->iptcData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
867 } |
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 while (work) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
870 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
871 exif->iptcData()[key] = (gchar *)work->data; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
872 work = work->next; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
873 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
874 } |
1245 | 875 #if EXIV2_TEST_VERSION(0,16,0) |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
876 catch (Exiv2::AnyError& e) { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
877 Exiv2::XmpKey ekey(key); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
878 Exiv2::XmpData::iterator pos = exif->xmpData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
879 while (pos != exif->xmpData().end()) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
880 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
881 exif->xmpData().erase(pos); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
882 pos = exif->xmpData().findKey(ekey); |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
883 } |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
884 |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
885 while (work) |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
886 { |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
887 exif->xmpData()[key] = (gchar *)work->data; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
888 work = work->next; |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
889 } |
1245 | 890 } |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
891 #endif |
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
892 } |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
893 return 1; |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
894 } |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
895 catch (Exiv2::AnyError& e) { |
1203
43bfcbb62cd6
prepared infrastructure for delayed metadata writting - refreshing
nadvornik
parents:
1196
diff
changeset
|
896 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
897 return 0; |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
898 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
899 } |
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
900 |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
901 gint exif_update_metadata(ExifData *exif, const gchar *key, const GList *values) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
902 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
903 gint ret = exif_update_metadata_simple(exif, key, values); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
904 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
905 if ( |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
906 #if !EXIV2_TEST_VERSION(0,17,0) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
907 TRUE || /* no conversion support */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
908 #endif |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
909 !values || /* deleting item */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
910 !ret /* writing to the explicitely given xmp tag failed */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
911 ) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
912 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
913 /* 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
|
914 /* if we can't write xmp, update at least the legacy tag */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
915 const AltKey *alt_key = find_alt_key(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
916 if (alt_key && alt_key->iptc_key) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
917 ret = exif_update_metadata_simple(exif, alt_key->iptc_key, values); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
918 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
919 if (alt_key && alt_key->exif_key) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
920 ret = exif_update_metadata_simple(exif, alt_key->exif_key, values); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
921 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
922 return ret; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
923 } |
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 |
1288 | 926 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
|
927 { |
1245 | 928 #if EXIV2_TEST_VERSION(0,16,0) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
929 Exiv2::TypeId id = item.typeId(); |
1288 | 930 if (format == METADATA_FORMATTED || |
931 id == Exiv2::asciiString || | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
932 id == Exiv2::undefined || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
933 id == Exiv2::string || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
934 id == Exiv2::date || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
935 id == Exiv2::time || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
936 id == Exiv2::xmpText || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
937 id == Exiv2::langAlt || |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
938 id == Exiv2::comment |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
939 ) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
940 { |
1245 | 941 #endif |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
942 /* read as a single entry */ |
1288 | 943 std::string str; |
944 | |
945 if (format == METADATA_FORMATTED) | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
946 { |
1288 | 947 #if EXIV2_TEST_VERSION(0,17,0) |
948 str = item.print( | |
949 #if EXIV2_TEST_VERSION(0,18,0) | |
950 metadata | |
951 #endif | |
952 ); | |
953 #else | |
954 std::stringstream stream; | |
955 Exiv2::Exifdatum *exifdatum; | |
956 Exiv2::Iptcdatum *iptcdatum; | |
957 #if EXIV2_TEST_VERSION(0,16,0) | |
958 Exiv2::Xmpdatum *xmpdatum; | |
959 #endif | |
960 if ((exifdatum = dynamic_cast<Exiv2::Exifdatum *>(metadatum))) | |
961 stream << *exifdatum; | |
962 else if ((iptcdatum = dynamic_cast<Exiv2::Iptcdatum *>(metadatum))) | |
963 stream << *iptcdatum; | |
964 #if EXIV2_TEST_VERSION(0,16,0) | |
965 else if ((xmpdatum = dynamic_cast<Exiv2::Xmpdatum *>(metadatum))) | |
966 stream << *xmpdatum; | |
967 #endif | |
968 str = stream.str(); | |
969 #endif | |
970 if (str.length() > 1024) | |
971 { | |
972 /* truncate very long strings, they cause problems in gui */ | |
973 str.erase(1024); | |
974 str.append("..."); | |
975 } | |
976 } | |
977 else | |
978 { | |
979 str = item.toString(); | |
980 if (str.length() > 5 && str.substr(0, 5) == "lang=") | |
981 { | |
982 std::string::size_type pos = str.find_first_of(' '); | |
983 if (pos != std::string::npos) str = str.substr(pos+1); | |
984 } | |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
985 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
986 list = g_list_append(list, utf8_validate_or_convert(str.c_str())); |
1245 | 987 #if EXIV2_TEST_VERSION(0,16,0) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
988 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
989 else |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
990 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
991 /* read as a list */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
992 gint i; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
993 for (i = 0; i < item.count(); i++) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
994 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
|
995 } |
1245 | 996 #endif |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
997 return list; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
998 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
999 |
1288 | 1000 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
|
1001 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1002 GList *list = NULL; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1003 try { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1004 try { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1005 Exiv2::ExifKey ekey(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1006 Exiv2::ExifData::iterator pos = exif->exifData().findKey(ekey); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1007 if (pos != exif->exifData().end()) |
1288 | 1008 list = exif_add_value_to_glist(list, *pos, format, &exif->exifData()); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1009 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1010 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1011 catch (Exiv2::AnyError& e) { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1012 try { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1013 Exiv2::IptcKey ekey(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1014 Exiv2::IptcData::iterator pos = exif->iptcData().begin(); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1015 while (pos != exif->iptcData().end()) |
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 if (pos->key() == key) |
1288 | 1018 list = exif_add_value_to_glist(list, *pos, format, NULL); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1019 ++pos; |
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 |
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 catch (Exiv2::AnyError& e) { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1024 #if EXIV2_TEST_VERSION(0,16,0) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1025 Exiv2::XmpKey ekey(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1026 Exiv2::XmpData::iterator pos = exif->xmpData().findKey(ekey); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1027 if (pos != exif->xmpData().end()) |
1288 | 1028 list = exif_add_value_to_glist(list, *pos, format, NULL); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1029 #endif |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1030 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1031 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1032 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1033 catch (Exiv2::AnyError& e) { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1034 std::cout << "Caught Exiv2 exception '" << e << "'\n"; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1035 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1036 return list; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1037 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1038 |
1288 | 1039 GList *exif_get_metadata(ExifData *exif, const gchar *key, MetadataFormat format) |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1040 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1041 GList *list = NULL; |
1288 | 1042 |
1043 if (!key) return NULL; | |
1044 | |
1045 if (format == METADATA_FORMATTED) | |
1046 { | |
1047 gchar *text; | |
1048 gint key_valid; | |
1049 text = exif_get_formatted_by_key(exif, key, &key_valid); | |
1050 if (key_valid) return g_list_append(NULL, text); | |
1051 } | |
1052 | |
1053 list = exif_get_metadata_simple(exif, key, format); | |
1238
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 /* 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
|
1056 if (!list) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1057 { |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1058 const AltKey *alt_key = find_alt_key(key); |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1059 if (alt_key && alt_key->iptc_key) |
1288 | 1060 list = exif_get_metadata_simple(exif, alt_key->iptc_key, format); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1061 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1062 #if !EXIV2_TEST_VERSION(0,17,0) |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1063 /* with older Exiv2 versions exif is not synced */ |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1064 if (!list && alt_key && alt_key->exif_key) |
1288 | 1065 list = exif_get_metadata_simple(exif, alt_key->exif_key, format); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1066 #endif |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1067 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1068 return list; |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1069 } |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1224
diff
changeset
|
1070 |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
1071 |
449 | 1072 void exif_add_jpeg_color_profile(ExifData *exif, unsigned char *cp_data, guint cp_length) |
1073 { | |
1069 | 1074 exif->add_jpeg_color_profile(cp_data, cp_length); |
449 | 1075 } |
1076 | |
1008 | 1077 guchar *exif_get_color_profile(ExifData *exif, guint *data_len) |
449 | 1078 { |
1069 | 1079 guchar *ret = exif->get_jpeg_color_profile(data_len); |
1080 if (ret) return ret; | |
1081 | |
449 | 1082 ExifItem *prof_item = exif_get_item(exif, "Exif.Image.InterColorProfile"); |
1083 if (prof_item && exif_item_get_format_id(prof_item) == EXIF_FORMAT_UNDEFINED) | |
1069 | 1084 ret = (guchar *)exif_item_get_data(prof_item, data_len); |
1085 return ret; | |
449 | 1086 } |
1087 | |
1008 | 1088 #if EXIV2_TEST_VERSION(0,17,90) |
187
9eafc4957f1a
write support in Exiv2 wrapper; for now only string values
nadvornik
parents:
186
diff
changeset
|
1089 |
1060 | 1090 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height) |
1008 | 1091 { |
1092 if (!exif) return NULL; | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1093 |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
1094 if (!exif->image()) return NULL; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
1095 |
1069 | 1096 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
|
1097 /* given image pathname, first do simple (and fast) file extension test */ |
1060 | 1098 gboolean is_raw = filter_file_class(path, FORMAT_CLASS_RAWIMAGE); |
1099 | |
1100 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
|
1101 |
1008 | 1102 try { |
1103 | |
1069 | 1104 Exiv2::PreviewManager pm(*exif->image()); |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1105 |
1064 | 1106 Exiv2::PreviewPropertiesList list = pm.getPreviewProperties(); |
1008 | 1107 |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1108 if (!list.empty()) |
1008 | 1109 { |
1060 | 1110 Exiv2::PreviewPropertiesList::iterator pos; |
1111 Exiv2::PreviewPropertiesList::iterator last = --list.end(); | |
1112 | |
1113 if (requested_width == 0) | |
1114 { | |
1115 pos = last; // the largest | |
1116 } | |
1117 else | |
1118 { | |
1119 pos = list.begin(); | |
1120 while (pos != last) | |
1121 { | |
1122 if (pos->width_ >= (uint32_t)requested_width && | |
1123 pos->height_ >= (uint32_t)requested_height) break; | |
1124 ++pos; | |
1125 } | |
1126 | |
1127 // we are not interested in smaller thumbnails in normal image formats - we can use full image instead | |
1128 if (!is_raw) | |
1129 { | |
1130 if (pos->width_ < (uint32_t)requested_width || pos->height_ < (uint32_t)requested_height) return NULL; | |
1131 } | |
1132 } | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1133 |
1064 | 1134 Exiv2::PreviewImage image = pm.getPreviewImage(*pos); |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1135 |
1064 | 1136 Exiv2::DataBuf buf = image.copy(); |
1008 | 1137 std::pair<Exiv2::byte*, long> p = buf.release(); |
1138 | |
1139 *data_len = p.second; | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1140 return p.first; |
1008 | 1141 } |
1142 return NULL; | |
1143 } | |
1144 catch (Exiv2::AnyError& e) { | |
1145 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
1146 return NULL; | |
1147 } | |
1148 } | |
1149 | |
1150 void exif_free_preview(guchar *buf) | |
1151 { | |
1152 delete[] (Exiv2::byte*)buf; | |
1153 } | |
1154 #endif | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1155 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1156 } |
1008 | 1157 #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
|
1158 |
995 | 1159 /* 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
|
1160 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
|
1161 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1162 class RawFile { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1163 public: |
995 | 1164 |
1008 | 1165 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
|
1166 ~RawFile(); |
995 | 1167 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1168 const Exiv2::Value *find(uint16_t tag, uint16_t group); |
995 | 1169 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1170 unsigned long preview_offset(); |
995 | 1171 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1172 private: |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1173 int type; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1174 Exiv2::TiffComponent::AutoPtr rootDir; |
1008 | 1175 Exiv2::BasicIo &io_; |
1176 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
|
1177 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
|
1178 unsigned long offset; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1179 }; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1180 |
1008 | 1181 typedef struct _UnmapData UnmapData; |
1182 struct _UnmapData | |
1183 { | |
1184 guchar *ptr; | |
1185 guchar *map_data; | |
1186 size_t map_len; | |
1187 }; | |
1188 | |
1189 static GList *exif_unmap_list = 0; | |
1190 | |
1060 | 1191 extern "C" guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height) |
1008 | 1192 { |
1193 unsigned long offset; | |
1194 | |
1195 if (!exif) return NULL; | |
1426
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
1196 if (!exif->image()) return NULL; |
cd88fe4e5588
handle sidecar files for raw formats that are not known to exiv2
nadvornik
parents:
1422
diff
changeset
|
1197 |
1069 | 1198 const char* path = exif->image()->io().path().c_str(); |
1008 | 1199 |
1200 /* 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
|
1201 if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return NULL; |
1008 | 1202 |
1203 try { | |
1204 struct stat st; | |
1205 guchar *map_data; | |
1206 size_t map_len; | |
1207 UnmapData *ud; | |
1208 int fd; | |
1209 | |
1069 | 1210 RawFile rf(exif->image()->io()); |
1008 | 1211 offset = rf.preview_offset(); |
1212 DEBUG_1("%s: offset %lu", path, offset); | |
1213 | |
1214 fd = open(path, O_RDONLY); | |
1215 if (fd == -1) | |
1216 { | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1217 return NULL; |
1008 | 1218 } |
1219 | |
1220 if (fstat(fd, &st) == -1) | |
1221 { | |
1222 close(fd); | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1223 return NULL; |
1008 | 1224 } |
1225 map_len = st.st_size; | |
1226 map_data = (guchar *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0); | |
1227 close(fd); | |
1228 if (map_data == MAP_FAILED) | |
1229 { | |
1048
95c418661be8
updated preview loader to work with current svn version of libexiv2
nadvornik
parents:
1025
diff
changeset
|
1230 return NULL; |
1008 | 1231 } |
1232 *data_len = map_len - offset; | |
1233 ud = g_new(UnmapData, 1); | |
1234 ud->ptr = map_data + offset; | |
1235 ud->map_data = map_data; | |
1236 ud->map_len = map_len; | |
1237 | |
1238 exif_unmap_list = g_list_prepend(exif_unmap_list, ud); | |
1239 return ud->ptr; | |
1240 | |
1241 } | |
1242 catch (Exiv2::AnyError& e) { | |
1243 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
1244 } | |
1245 return NULL; | |
1246 | |
1247 } | |
1248 | |
1249 void exif_free_preview(guchar *buf) | |
1250 { | |
1251 GList *work = exif_unmap_list; | |
1252 | |
1253 while (work) | |
1254 { | |
1255 UnmapData *ud = (UnmapData *)work->data; | |
1256 if (ud->ptr == buf) | |
1257 { | |
1258 munmap(ud->map_data, ud->map_len); | |
1259 exif_unmap_list = g_list_remove_link(exif_unmap_list, work); | |
1260 g_free(ud); | |
1261 return; | |
1262 } | |
1025 | 1263 work = work->next; |
1008 | 1264 } |
1265 g_assert_not_reached(); | |
1266 } | |
1267 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1268 using namespace Exiv2; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1269 |
1008 | 1270 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
|
1271 { |
1008 | 1272 /* |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1273 struct stat st; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1274 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
|
1275 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1276 throw Error(14); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1277 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1278 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
|
1279 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
|
1280 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
|
1281 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1282 throw Error(14); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1283 } |
1008 | 1284 */ |
1285 if (io.open() != 0) { | |
1286 throw Error(9, io.path(), strError()); | |
1287 } | |
1288 | |
1289 map_data = io.mmap(); | |
1290 map_len = io.size(); | |
1291 | |
1292 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1293 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
|
1294 |
200 | 1295 #if EXIV2_TEST_VERSION(0,16,0) |
201 | 1296 TiffHeaderBase *tiffHeader = NULL; |
200 | 1297 #else |
201 | 1298 TiffHeade2 *tiffHeader = NULL; |
200 | 1299 #endif |
201 | 1300 Cr2Header *cr2Header = NULL; |
1301 | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1302 switch (type) { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1303 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
|
1304 tiffHeader = new TiffHeade2(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1305 break; |
201 | 1306 case Exiv2::ImageType::cr2: |
1307 cr2Header = new Cr2Header(); | |
1308 break; | |
200 | 1309 #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
|
1310 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
|
1311 tiffHeader = new OrfHeader(); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1312 break; |
200 | 1313 #endif |
1314 #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
|
1315 case Exiv2::ImageType::raf: |
995 | 1316 if (map_len < 84 + 4) throw Error(14); |
1317 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
|
1318 return; |
200 | 1319 #endif |
191 | 1320 case Exiv2::ImageType::crw: |
1321 { | |
1322 // Parse the image, starting with a CIFF header component | |
1323 Exiv2::CiffHeader::AutoPtr parseTree(new Exiv2::CiffHeader); | |
1324 parseTree->read(map_data, map_len); | |
995 | 1325 CiffComponent *entry = parseTree->findComponent(0x2007, 0); |
191 | 1326 if (entry) offset = entry->pData() - map_data; |
1327 return; | |
1328 } | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1329 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1330 default: |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1331 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
|
1332 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1333 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1334 // 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
|
1335 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1336 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
|
1337 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1338 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
|
1339 if (0 == rootDir.get()) { |
995 | 1340 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
|
1341 } |
201 | 1342 |
1343 if (tiffHeader) | |
1344 { | |
1345 if (!tiffHeader->read(map_data, map_len)) throw Error(3, "TIFF"); | |
200 | 1346 #if EXIV2_TEST_VERSION(0,16,0) |
201 | 1347 rootDir->setStart(map_data + tiffHeader->offset()); |
200 | 1348 #else |
201 | 1349 rootDir->setStart(map_data + tiffHeader->ifdOffset()); |
200 | 1350 #endif |
201 | 1351 } |
1352 | |
1353 if (cr2Header) | |
1354 { | |
1355 rootDir->setStart(map_data + cr2Header->offset()); | |
1356 } | |
1357 | |
1358 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
|
1359 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1360 TiffReader reader(map_data, |
995 | 1361 map_len, |
1362 rootDir.get(), | |
1363 state); | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1364 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1365 rootDir->accept(reader); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1366 |
995 | 1367 if (tiffHeader) |
201 | 1368 delete tiffHeader; |
995 | 1369 if (cr2Header) |
201 | 1370 delete cr2Header; |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1371 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1372 |
609
b690cecbf5b8
Use function(void) instead of function() for declaring functions which
zas_
parents:
586
diff
changeset
|
1373 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
|
1374 { |
1008 | 1375 io_.munmap(); |
1376 io_.close(); | |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1377 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1378 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1379 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
|
1380 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1381 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
|
1382 rootDir->accept(finder); |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1383 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
|
1384 if (te) |
194 | 1385 { |
495 | 1386 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
|
1387 return te->pValue(); |
194 | 1388 } |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1389 else |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1390 return NULL; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1391 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1392 |
609
b690cecbf5b8
Use function(void) instead of function() for declaring functions which
zas_
parents:
586
diff
changeset
|
1393 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
|
1394 { |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1395 const Value *val; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1396 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
|
1397 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1398 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
|
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::ifd0); |
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(); |
995 | 1402 |
186
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 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
|
1407 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
|
1408 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1409 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
|
1410 if (val) return val->toLong(); |
995 | 1411 |
186
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1412 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
|
1413 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
|
1414 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1415 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
|
1416 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
|
1417 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1418 return 0; |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1419 } |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1420 |
bd3fc1aa7fe9
a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents:
185
diff
changeset
|
1421 |
1008 | 1422 #endif |
178 | 1423 |
1424 | |
995 | 1425 #endif |
178 | 1426 /* HAVE_EXIV2 */ |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1053
diff
changeset
|
1427 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |