8 #include <exiv2/image.hpp>
9 #include <exiv2/exif.hpp>
20 Exiv2::ExifData exifData;
21 Exiv2::ExifData::const_iterator iter;
25 ExifData *exif_read(gchar *path, gint parse_color_profile)
27 printf("exif %s\n", path);
29 ExifData *exif = new ExifData;
31 Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
32 g_assert (image.get() != 0);
33 image->readMetadata();
34 exif->exifData = image->exifData();
37 catch (Exiv2::AnyError& e) {
38 std::cout << "Caught Exiv2 exception '" << e << "'\n";
44 void exif_free(ExifData *exif)
51 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key)
54 gchar *text = exif_get_formatted_by_key(exif, key, &key_valid);
55 if (key_valid) return text;
57 return g_strdup(exif->exifData[key].toString().c_str());
60 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value)
62 Exiv2::ExifKey ekey(key);
63 Exiv2::ExifData::iterator pos = exif->exifData.findKey(ekey);
64 if (pos == exif->exifData.end()) return 0;
65 *value = pos->getValue()->toLong();
70 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign)
72 /* Exiv2::Rational v = exif->exifData[key];
74 return exif->exifData[key];
78 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
80 Exiv2::Exifdatum *item = &exif->exifData[key];
81 return (ExifItem *)item;
84 ExifItem *exif_get_first_item(ExifData *exif)
86 exif->iter = exif->exifData.begin();
87 if (exif->iter == exif->exifData.end()) return NULL;
88 const Exiv2::Exifdatum *item = &*exif->iter;
89 return (ExifItem *)item;
92 ExifItem *exif_get_next_item(ExifData *exif)
95 if (exif->iter == exif->exifData.end()) return NULL;
96 const Exiv2::Exifdatum *item = &*exif->iter;
97 return (ExifItem *)item;
100 const char *exif_item_get_tag_name(ExifItem *item)
102 return ((Exiv2::Exifdatum *)item)->key().c_str();
105 guint exif_item_get_tag_id(ExifItem *item)
107 return ((Exiv2::Exifdatum *)item)->tag();
110 guint exif_item_get_elements(ExifItem *item)
112 return ((Exiv2::Exifdatum *)item)->count();
115 char *exif_item_get_data(ExifItem *item, guint *data_len)
119 char *exif_item_get_description(ExifItem *item)
121 return g_strdup(((Exiv2::Exifdatum *)item)->tagLabel().c_str());
125 invalidTypeId, unsignedByte, asciiString, unsignedShort,
126 unsignedLong, unsignedRational, signedByte, undefined,
127 signedShort, signedLong, signedRational, string,
128 date, time, comment, directory,
129 xmpText, xmpAlt, xmpBag, xmpSeq,
132 EXIF_FORMAT_UNKNOWN = 0,
133 EXIF_FORMAT_BYTE_UNSIGNED = 1,
134 EXIF_FORMAT_STRING = 2,
135 EXIF_FORMAT_SHORT_UNSIGNED = 3,
136 EXIF_FORMAT_LONG_UNSIGNED = 4,
137 EXIF_FORMAT_RATIONAL_UNSIGNED = 5,
138 EXIF_FORMAT_BYTE = 6,
139 EXIF_FORMAT_UNDEFINED = 7,
140 EXIF_FORMAT_SHORT = 8,
141 EXIF_FORMAT_LONG = 9,
142 EXIF_FORMAT_RATIONAL = 10,
143 EXIF_FORMAT_FLOAT = 11,
144 EXIF_FORMAT_DOUBLE = 12
148 guint exif_item_get_format_id(ExifItem *item)
150 return ((Exiv2::Exifdatum *)item)->typeId();
152 const char *exif_item_get_format_name(ExifItem *item, gint brief)
154 return ((Exiv2::Exifdatum *)item)->typeName();
158 gchar *exif_item_get_data_as_text(ExifItem *item)
160 return g_strdup(((Exiv2::Exifdatum *)item)->toString().c_str());
164 gint exif_item_get_integer(ExifItem *item, gint *value)
168 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
172 const gchar *exif_get_tag_description_by_key(const gchar *key)
174 Exiv2::ExifKey ekey(key);
175 return Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ());
178 gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
179 unsigned char *header_data, const guint header_len,
180 guint *image_offset, guint *exif_offset)