8 #include <exiv2/image.hpp>
9 #include <exiv2/exif.hpp>
21 Exiv2::ExifData exifData;
22 Exiv2::ExifData::const_iterator iter;
24 _ExifData(gchar *path, gint parse_color_profile)
26 Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
27 g_assert (image.get() != 0);
28 image->readMetadata();
29 exifData = image->exifData();
36 ExifData *exif_read(gchar *path, gint parse_color_profile)
38 printf("exif %s\n", path);
40 return new ExifData(path, parse_color_profile);
42 catch (Exiv2::AnyError& e) {
43 std::cout << "Caught Exiv2 exception '" << e << "'\n";
49 void exif_free(ExifData *exif)
55 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
58 Exiv2::ExifKey ekey(key);
59 Exiv2::ExifData::iterator pos = exif->exifData.findKey(ekey);
60 if (pos == exif->exifData.end()) return NULL;
61 Exiv2::Exifdatum *item = &*pos;
62 return (ExifItem *)item;
64 catch (Exiv2::AnyError& e) {
65 std::cout << "Caught Exiv2 exception '" << e << "'\n";
71 ExifItem *exif_get_first_item(ExifData *exif)
74 exif->iter = exif->exifData.begin();
75 if (exif->iter == exif->exifData.end()) return NULL;
76 const Exiv2::Exifdatum *item = &*exif->iter;
77 return (ExifItem *)item;
79 catch (Exiv2::AnyError& e) {
80 std::cout << "Caught Exiv2 exception '" << e << "'\n";
85 ExifItem *exif_get_next_item(ExifData *exif)
89 if (exif->iter == exif->exifData.end()) return NULL;
90 const Exiv2::Exifdatum *item = &*exif->iter;
91 return (ExifItem *)item;
93 catch (Exiv2::AnyError& e) {
94 std::cout << "Caught Exiv2 exception '" << e << "'\n";
99 const char *exif_item_get_tag_name(ExifItem *item)
102 if (!item) return NULL;
103 return ((Exiv2::Exifdatum *)item)->key().c_str();
105 catch (Exiv2::AnyError& e) {
106 std::cout << "Caught Exiv2 exception '" << e << "'\n";
111 guint exif_item_get_tag_id(ExifItem *item)
115 return ((Exiv2::Exifdatum *)item)->tag();
117 catch (Exiv2::AnyError& e) {
118 std::cout << "Caught Exiv2 exception '" << e << "'\n";
123 guint exif_item_get_elements(ExifItem *item)
127 return ((Exiv2::Exifdatum *)item)->count();
129 catch (Exiv2::AnyError& e) {
130 std::cout << "Caught Exiv2 exception '" << e << "'\n";
135 char *exif_item_get_data(ExifItem *item, guint *data_len)
139 char *exif_item_get_description(ExifItem *item)
142 if (!item) return NULL;
143 return g_strdup(((Exiv2::Exifdatum *)item)->tagLabel().c_str());
145 catch (Exiv2::AnyError& e) {
146 std::cout << "Caught Exiv2 exception '" << e << "'\n";
152 invalidTypeId, unsignedByte, asciiString, unsignedShort,
153 unsignedLong, unsignedRational, signedByte, undefined,
154 signedShort, signedLong, signedRational, string,
155 date, time, comment, directory,
156 xmpText, xmpAlt, xmpBag, xmpSeq,
160 static guint format_id_trans_tbl [] = {
162 EXIF_FORMAT_BYTE_UNSIGNED,
164 EXIF_FORMAT_SHORT_UNSIGNED,
165 EXIF_FORMAT_LONG_UNSIGNED,
166 EXIF_FORMAT_RATIONAL_UNSIGNED,
168 EXIF_FORMAT_UNDEFINED,
171 EXIF_FORMAT_RATIONAL,
175 EXIF_FORMAT_UNDEFINED,
184 guint exif_item_get_format_id(ExifItem *item)
187 if (!item) return EXIF_FORMAT_UNKNOWN;
188 guint id = ((Exiv2::Exifdatum *)item)->typeId();
189 if (id >= (sizeof(format_id_trans_tbl) / sizeof(format_id_trans_tbl[0])) ) return EXIF_FORMAT_UNKNOWN;
190 return format_id_trans_tbl[id];
192 catch (Exiv2::AnyError& e) {
193 std::cout << "Caught Exiv2 exception '" << e << "'\n";
194 return EXIF_FORMAT_UNKNOWN;
198 const char *exif_item_get_format_name(ExifItem *item, gint brief)
201 if (!item) return NULL;
202 return ((Exiv2::Exifdatum *)item)->typeName();
204 catch (Exiv2::AnyError& e) {
205 std::cout << "Caught Exiv2 exception '" << e << "'\n";
211 gchar *exif_item_get_data_as_text(ExifItem *item)
214 if (!item) return NULL;
215 std::stringstream str;
216 str << *((Exiv2::Exifdatum *)item);
217 return g_strdup(str.str().c_str());
219 catch (Exiv2::AnyError& e) {
225 gint exif_item_get_integer(ExifItem *item, gint *value)
229 return ((Exiv2::Exifdatum *)item)->toLong();
231 catch (Exiv2::AnyError& e) {
232 std::cout << "Caught Exiv2 exception '" << e << "'\n";
237 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
240 if (!item) return NULL;
241 Exiv2::Rational v = ((Exiv2::Exifdatum *)item)->toRational();
242 static ExifRational ret;
247 catch (Exiv2::AnyError& e) {
248 std::cout << "Caught Exiv2 exception '" << e << "'\n";
253 const gchar *exif_get_tag_description_by_key(const gchar *key)
256 Exiv2::ExifKey ekey(key);
257 return Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ());
259 catch (Exiv2::AnyError& e) {
260 std::cout << "Caught Exiv2 exception '" << e << "'\n";
265 gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
266 unsigned char *header_data, const guint header_len,
267 guint *image_offset, guint *exif_offset)