Mercurial > geeqie.yaz
annotate src/exiv2.cc @ 183:3962c9d3d6fd
more exiv2 fixes
author | nadvornik |
---|---|
date | Thu, 14 Feb 2008 11:03:20 +0000 |
parents | 8a417f10ba09 |
children | 2507418ab7a2 |
rev | line source |
---|---|
178 | 1 |
2 #ifdef HAVE_CONFIG_H | |
3 # include "config.h" | |
4 #endif | |
5 | |
6 #ifdef HAVE_EXIV2 | |
7 | |
8 #include <exiv2/image.hpp> | |
9 #include <exiv2/exif.hpp> | |
10 #include <iostream> | |
11 | |
12 extern "C" { | |
13 | |
14 #include <glib.h> | |
15 #include "exif.h" | |
16 | |
17 | |
18 struct _ExifData | |
19 { | |
20 Exiv2::ExifData exifData; | |
21 Exiv2::ExifData::const_iterator iter; | |
22 }; | |
23 | |
24 | |
25 ExifData *exif_read(gchar *path, gint parse_color_profile) | |
26 { | |
182 | 27 printf("exif %s\n", path); |
178 | 28 try { |
182 | 29 ExifData *exif = new ExifData; |
178 | 30 |
31 Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path); | |
32 g_assert (image.get() != 0); | |
33 image->readMetadata(); | |
34 exif->exifData = image->exifData(); | |
179
37004d5a584a
and first version that actually shows some exif data (see advanced view)
nadvornik
parents:
178
diff
changeset
|
35 return exif; |
178 | 36 } |
37 catch (Exiv2::AnyError& e) { | |
38 std::cout << "Caught Exiv2 exception '" << e << "'\n"; | |
179
37004d5a584a
and first version that actually shows some exif data (see advanced view)
nadvornik
parents:
178
diff
changeset
|
39 return 0; |
178 | 40 } |
179
37004d5a584a
and first version that actually shows some exif data (see advanced view)
nadvornik
parents:
178
diff
changeset
|
41 |
178 | 42 } |
43 | |
44 void exif_free(ExifData *exif) | |
45 { | |
182 | 46 |
47 delete exif; | |
178 | 48 } |
49 | |
50 | |
51 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key) | |
52 { | |
182 | 53 gint key_valid; |
54 gchar *text = exif_get_formatted_by_key(exif, key, &key_valid); | |
55 if (key_valid) return text; | |
183 | 56 |
57 try { | |
58 std::stringstream str; | |
59 str << exif->exifData[key]; | |
60 return g_strdup(str.str().c_str()); | |
61 } | |
62 catch (Exiv2::AnyError& e) { | |
63 return NULL; | |
64 } | |
178 | 65 } |
66 | |
67 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value) | |
68 { | |
180 | 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(); | |
73 | |
74 return 1; | |
178 | 75 } |
76 | |
77 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign) | |
78 { | |
183 | 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; | |
84 ret.num = v.first; | |
85 ret.den = v.second; | |
86 return &ret; | |
178 | 87 } |
88 | |
89 ExifItem *exif_get_item(ExifData *exif, const gchar *key) | |
90 { | |
91 Exiv2::Exifdatum *item = &exif->exifData[key]; | |
92 return (ExifItem *)item; | |
93 } | |
94 | |
95 ExifItem *exif_get_first_item(ExifData *exif) | |
96 { | |
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; | |
101 } | |
102 | |
103 ExifItem *exif_get_next_item(ExifData *exif) | |
104 { | |
105 exif->iter++; | |
106 if (exif->iter == exif->exifData.end()) return NULL; | |
107 const Exiv2::Exifdatum *item = &*exif->iter; | |
108 return (ExifItem *)item; | |
109 } | |
110 | |
111 const char *exif_item_get_tag_name(ExifItem *item) | |
112 { | |
180 | 113 return ((Exiv2::Exifdatum *)item)->key().c_str(); |
178 | 114 } |
115 | |
116 guint exif_item_get_tag_id(ExifItem *item) | |
117 { | |
180 | 118 return ((Exiv2::Exifdatum *)item)->tag(); |
178 | 119 } |
120 | |
121 guint exif_item_get_elements(ExifItem *item) | |
122 { | |
123 return ((Exiv2::Exifdatum *)item)->count(); | |
124 } | |
125 | |
126 char *exif_item_get_data(ExifItem *item, guint *data_len) | |
127 { | |
128 } | |
129 | |
182 | 130 char *exif_item_get_description(ExifItem *item) |
178 | 131 { |
182 | 132 return g_strdup(((Exiv2::Exifdatum *)item)->tagLabel().c_str()); |
178 | 133 } |
134 | |
135 /* | |
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, | |
141 langAlt, lastTypeId | |
142 | |
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 | |
156 */ | |
157 | |
158 | |
159 guint exif_item_get_format_id(ExifItem *item) | |
160 { | |
161 return ((Exiv2::Exifdatum *)item)->typeId(); | |
162 } | |
163 const char *exif_item_get_format_name(ExifItem *item, gint brief) | |
164 { | |
180 | 165 return ((Exiv2::Exifdatum *)item)->typeName(); |
178 | 166 } |
167 | |
168 | |
169 gchar *exif_item_get_data_as_text(ExifItem *item) | |
170 { | |
183 | 171 try { |
172 std::stringstream str; | |
173 str << *((Exiv2::Exifdatum *)item); | |
174 return g_strdup(str.str().c_str()); | |
175 } | |
176 catch (Exiv2::AnyError& e) { | |
177 return NULL; | |
178 } | |
178 | 179 } |
180 | |
181 | |
182 gint exif_item_get_integer(ExifItem *item, gint *value) | |
183 { | |
183 | 184 return ((Exiv2::Exifdatum *)item)->toLong(); |
178 | 185 } |
186 | |
187 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign) | |
188 { | |
183 | 189 Exiv2::Rational v = ((Exiv2::Exifdatum *)item)->toRational(); |
190 static ExifRational ret; | |
191 ret.num = v.first; | |
192 ret.den = v.second; | |
193 return &ret; | |
178 | 194 } |
195 | |
182 | 196 const gchar *exif_get_tag_description_by_key(const gchar *key) |
178 | 197 { |
182 | 198 Exiv2::ExifKey ekey(key); |
199 return Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ()); | |
178 | 200 } |
201 | |
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) | |
205 { | |
206 return 0; | |
207 } | |
208 | |
209 } | |
210 | |
211 #endif | |
212 /* HAVE_EXIV2 */ |