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;
58 std::stringstream str;
59 str << exif->exifData[key];
60 return g_strdup(str.str().c_str());
62 catch (Exiv2::AnyError& e) {
67 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value)
69 Exiv2::ExifKey ekey(key);
70 Exiv2::ExifData::iterator pos = exif->exifData.findKey(ekey);
71 if (pos == exif->exifData.end()) return 0;
72 *value = pos->getValue()->toLong();
77 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign)
79 Exiv2::ExifKey ekey(key);
80 Exiv2::ExifData::iterator pos = exif->exifData.findKey(ekey);
81 if (pos == exif->exifData.end()) return NULL;
82 Exiv2::Rational v = pos->getValue()->toRational();
83 static ExifRational ret;
89 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
91 Exiv2::Exifdatum *item = &exif->exifData[key];
92 return (ExifItem *)item;
95 ExifItem *exif_get_first_item(ExifData *exif)
97 exif->iter = exif->exifData.begin();
98 if (exif->iter == exif->exifData.end()) return NULL;
99 const Exiv2::Exifdatum *item = &*exif->iter;
100 return (ExifItem *)item;
103 ExifItem *exif_get_next_item(ExifData *exif)
106 if (exif->iter == exif->exifData.end()) return NULL;
107 const Exiv2::Exifdatum *item = &*exif->iter;
108 return (ExifItem *)item;
111 const char *exif_item_get_tag_name(ExifItem *item)
113 return ((Exiv2::Exifdatum *)item)->key().c_str();
116 guint exif_item_get_tag_id(ExifItem *item)
118 return ((Exiv2::Exifdatum *)item)->tag();
121 guint exif_item_get_elements(ExifItem *item)
123 return ((Exiv2::Exifdatum *)item)->count();
126 char *exif_item_get_data(ExifItem *item, guint *data_len)
130 char *exif_item_get_description(ExifItem *item)
132 return g_strdup(((Exiv2::Exifdatum *)item)->tagLabel().c_str());
136 invalidTypeId, unsignedByte, asciiString, unsignedShort,
137 unsignedLong, unsignedRational, signedByte, undefined,
138 signedShort, signedLong, signedRational, string,
139 date, time, comment, directory,
140 xmpText, xmpAlt, xmpBag, xmpSeq,
143 EXIF_FORMAT_UNKNOWN = 0,
144 EXIF_FORMAT_BYTE_UNSIGNED = 1,
145 EXIF_FORMAT_STRING = 2,
146 EXIF_FORMAT_SHORT_UNSIGNED = 3,
147 EXIF_FORMAT_LONG_UNSIGNED = 4,
148 EXIF_FORMAT_RATIONAL_UNSIGNED = 5,
149 EXIF_FORMAT_BYTE = 6,
150 EXIF_FORMAT_UNDEFINED = 7,
151 EXIF_FORMAT_SHORT = 8,
152 EXIF_FORMAT_LONG = 9,
153 EXIF_FORMAT_RATIONAL = 10,
154 EXIF_FORMAT_FLOAT = 11,
155 EXIF_FORMAT_DOUBLE = 12
159 guint exif_item_get_format_id(ExifItem *item)
161 return ((Exiv2::Exifdatum *)item)->typeId();
163 const char *exif_item_get_format_name(ExifItem *item, gint brief)
165 return ((Exiv2::Exifdatum *)item)->typeName();
169 gchar *exif_item_get_data_as_text(ExifItem *item)
172 std::stringstream str;
173 str << *((Exiv2::Exifdatum *)item);
174 return g_strdup(str.str().c_str());
176 catch (Exiv2::AnyError& e) {
182 gint exif_item_get_integer(ExifItem *item, gint *value)
184 return ((Exiv2::Exifdatum *)item)->toLong();
187 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
189 Exiv2::Rational v = ((Exiv2::Exifdatum *)item)->toRational();
190 static ExifRational ret;
196 const gchar *exif_get_tag_description_by_key(const gchar *key)
198 Exiv2::ExifKey ekey(key);
199 return Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ());
202 gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
203 unsigned char *header_data, const guint header_len,
204 guint *image_offset, guint *exif_offset)