annotate src/exiv2.cc @ 187:9eafc4957f1a

write support in Exiv2 wrapper; for now only string values
author nadvornik
date Sat, 15 Mar 2008 19:53:33 +0000
parents bd3fc1aa7fe9
children 0584cb78aa14
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
1
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
2 #ifdef HAVE_CONFIG_H
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
3 # include "config.h"
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
4 #endif
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
5
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
6 #ifdef HAVE_EXIV2
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
7
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
8 #include <exiv2/image.hpp>
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
9 #include <exiv2/exif.hpp>
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
10 #include <iostream>
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
11
186
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
12 #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
13 #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
14 #include <unistd.h>
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
15 #include <fcntl.h>
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
16 #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
17
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
18 #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
19 #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
20 #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
21 #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
22 #include <exiv2/cr2image.hpp>
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
23 #include <exiv2/orfimage.hpp>
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
24 #include <exiv2/rafimage.hpp>
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
25 #include <exiv2/futils.hpp>
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
26
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
27
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
28
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
29 extern "C" {
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
30 #include <glib.h>
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
31 #include "exif.h"
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
32
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
33 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
34
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
35 struct _ExifData
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
36 {
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
37 Exiv2::Image::AutoPtr image;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
38 Exiv2::ExifData::const_iterator exifIter; /* for exif_get_next_item */
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
39 Exiv2::IptcData::const_iterator iptcIter; /* for exif_get_next_item */
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
40 Exiv2::XmpData::const_iterator xmpIter; /* for exif_get_next_item */
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
41
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
42 _ExifData(gchar *path, gint parse_color_profile)
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
43 {
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
44 image = Exiv2::ImageFactory::open(path);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
45 // g_assert (image.get() != 0);
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
46 image->readMetadata();
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
47 }
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
48
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
49 void writeMetadata()
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
50 {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
51 image->writeMetadata();
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
52 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
53
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
54
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
55 };
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
56
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
57 extern "C" {
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
58
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
59 ExifData *exif_read(gchar *path, gint parse_color_profile)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
60 {
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents: 180
diff changeset
61 printf("exif %s\n", path);
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
62 try {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
63 return new ExifData(path, parse_color_profile);
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
64 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
65 catch (Exiv2::AnyError& e) {
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
66 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
67 return 0;
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
68 }
179
37004d5a584a and first version that actually shows some exif data (see advanced view)
nadvornik
parents: 178
diff changeset
69
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
70 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
71
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
72 int exif_write(ExifData *exif)
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
73 {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
74 try {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
75 exif->writeMetadata();
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
76 return 1;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
77 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
78 catch (Exiv2::AnyError& e) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
79 std::cout << "Caught Exiv2 exception '" << e << "'\n";
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
80 return 0;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
81 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
82
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
83 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
84
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
85
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
86 void exif_free(ExifData *exif)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
87 {
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents: 180
diff changeset
88
8a417f10ba09 more exiv2 fixes
nadvornik
parents: 180
diff changeset
89 delete exif;
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
90 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
91
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
92 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
93 {
183
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
94 try {
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
95 Exiv2::Metadatum *item;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
96 try {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
97 Exiv2::ExifKey ekey(key);
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
98 Exiv2::ExifData::iterator pos = exif->image->exifData().findKey(ekey);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
99 if (pos == exif->image->exifData().end()) return NULL;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
100 item = &*pos;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
101 }
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
102 catch (Exiv2::AnyError& e) {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
103 try {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
104 Exiv2::IptcKey ekey(key);
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
105 Exiv2::IptcData::iterator pos = exif->image->iptcData().findKey(ekey);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
106 if (pos == exif->image->iptcData().end()) return NULL;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
107 item = &*pos;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
108 }
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
109 catch (Exiv2::AnyError& e) {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
110 Exiv2::XmpKey ekey(key);
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
111 Exiv2::XmpData::iterator pos = exif->image->xmpData().findKey(ekey);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
112 if (pos == exif->image->xmpData().end()) return NULL;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
113 item = &*pos;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
114 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
115 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
116 return (ExifItem *)item;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
117 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
118 catch (Exiv2::AnyError& e) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
119 std::cout << "Caught Exiv2 exception '" << e << "'\n";
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
120 return NULL;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
121 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
122 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
123
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
124 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
125 {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
126 try {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
127 Exiv2::Metadatum *item;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
128 try {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
129 Exiv2::ExifKey ekey(key);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
130 exif->image->exifData().add(ekey, NULL);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
131 Exiv2::ExifData::iterator pos = exif->image->exifData().end(); // a hack, there should be a better way to get the currently added item
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
132 pos--;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
133 item = &*pos;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
134 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
135 catch (Exiv2::AnyError& e) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
136 try {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
137 Exiv2::IptcKey ekey(key);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
138 exif->image->iptcData().add(ekey, NULL);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
139 Exiv2::IptcData::iterator pos = exif->image->iptcData().end();
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
140 pos--;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
141 item = &*pos;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
142 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
143 catch (Exiv2::AnyError& e) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
144 Exiv2::XmpKey ekey(key);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
145 exif->image->xmpData().add(ekey, NULL);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
146 Exiv2::XmpData::iterator pos = exif->image->xmpData().end();
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
147 pos--;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
148 item = &*pos;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
149 }
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
150 }
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
151 return (ExifItem *)item;
183
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
152 }
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
153 catch (Exiv2::AnyError& e) {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
154 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
155 return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
156 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
157 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
158
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
159
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
160 ExifItem *exif_get_first_item(ExifData *exif)
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
161 {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
162 try {
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
163 exif->exifIter = exif->image->exifData().begin();
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
164 exif->iptcIter = exif->image->iptcData().begin();
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
165 exif->xmpIter = exif->image->xmpData().begin();
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
166 if (exif->exifIter != exif->image->exifData().end())
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
167 {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
168 const Exiv2::Metadatum *item = &*exif->exifIter;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
169 exif->exifIter++;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
170 return (ExifItem *)item;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
171 }
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
172 if (exif->iptcIter != exif->image->iptcData().end())
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
173 {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
174 const Exiv2::Metadatum *item = &*exif->iptcIter;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
175 exif->iptcIter++;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
176 return (ExifItem *)item;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
177 }
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
178 if (exif->xmpIter != exif->image->xmpData().end())
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
179 {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
180 const Exiv2::Metadatum *item = &*exif->xmpIter;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
181 exif->xmpIter++;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
182 return (ExifItem *)item;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
183 }
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
184 return NULL;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
185
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
186 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
187 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
188 std::cout << "Caught Exiv2 exception '" << e << "'\n";
183
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
189 return NULL;
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
190 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
191 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
192
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
193 ExifItem *exif_get_next_item(ExifData *exif)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
194 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
195 try {
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
196 if (exif->exifIter != exif->image->exifData().end())
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
197 {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
198 const Exiv2::Metadatum *item = &*exif->exifIter;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
199 exif->exifIter++;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
200 return (ExifItem *)item;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
201 }
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
202 if (exif->iptcIter != exif->image->iptcData().end())
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
203 {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
204 const Exiv2::Metadatum *item = &*exif->iptcIter;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
205 exif->iptcIter++;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
206 return (ExifItem *)item;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
207 }
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
208 if (exif->xmpIter != exif->image->xmpData().end())
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
209 {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
210 const Exiv2::Metadatum *item = &*exif->xmpIter;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
211 exif->xmpIter++;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
212 return (ExifItem *)item;
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
213 }
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
214 return NULL;
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
215 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
216 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
217 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
218 return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
219 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
220 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
221
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
222 char *exif_item_get_tag_name(ExifItem *item)
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
223 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
224 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
225 if (!item) return NULL;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
226 return g_strdup(((Exiv2::Metadatum *)item)->key().c_str());
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
227 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
228 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
229 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
230 return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
231 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
232 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
233
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
234 guint exif_item_get_tag_id(ExifItem *item)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
235 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
236 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
237 if (!item) return 0;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
238 return ((Exiv2::Metadatum *)item)->tag();
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
239 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
240 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
241 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
242 return 0;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
243 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
244 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
245
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
246 guint exif_item_get_elements(ExifItem *item)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
247 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
248 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
249 if (!item) return 0;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
250 return ((Exiv2::Metadatum *)item)->count();
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
251 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
252 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
253 std::cout << "Caught Exiv2 exception '" << e << "'\n";
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
254 return 0;
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
255 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
256 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
257
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
258 char *exif_item_get_data(ExifItem *item, guint *data_len)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
259 {
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
260 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
261
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents: 180
diff changeset
262 char *exif_item_get_description(ExifItem *item)
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
263 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
264 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
265 if (!item) return NULL;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
266 return g_strdup(((Exiv2::Metadatum *)item)->tagLabel().c_str());
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
267 }
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
268 catch (std::exception& e) {
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
269 // std::cout << "Caught Exiv2 exception '" << e << "'\n";
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
270 return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
271 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
272 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
273
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
274 /*
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
275 invalidTypeId, unsignedByte, asciiString, unsignedShort,
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
276 unsignedLong, unsignedRational, signedByte, undefined,
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
277 signedShort, signedLong, signedRational, string,
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
278 date, time, comment, directory,
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
279 xmpText, xmpAlt, xmpBag, xmpSeq,
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
280 langAlt, lastTypeId
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
281 */
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
282
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
283 static guint format_id_trans_tbl [] = {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
284 EXIF_FORMAT_UNKNOWN,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
285 EXIF_FORMAT_BYTE_UNSIGNED,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
286 EXIF_FORMAT_STRING,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
287 EXIF_FORMAT_SHORT_UNSIGNED,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
288 EXIF_FORMAT_LONG_UNSIGNED,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
289 EXIF_FORMAT_RATIONAL_UNSIGNED,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
290 EXIF_FORMAT_BYTE,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
291 EXIF_FORMAT_UNDEFINED,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
292 EXIF_FORMAT_SHORT,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
293 EXIF_FORMAT_LONG,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
294 EXIF_FORMAT_RATIONAL,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
295 EXIF_FORMAT_STRING,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
296 EXIF_FORMAT_STRING,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
297 EXIF_FORMAT_STRING,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
298 EXIF_FORMAT_UNDEFINED,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
299 EXIF_FORMAT_STRING,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
300 EXIF_FORMAT_STRING,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
301 EXIF_FORMAT_STRING,
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
302 EXIF_FORMAT_STRING
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
303 };
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
304
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
305
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
306
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
307 guint exif_item_get_format_id(ExifItem *item)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
308 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
309 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
310 if (!item) return EXIF_FORMAT_UNKNOWN;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
311 guint id = ((Exiv2::Metadatum *)item)->typeId();
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
312 if (id >= (sizeof(format_id_trans_tbl) / sizeof(format_id_trans_tbl[0])) ) return EXIF_FORMAT_UNKNOWN;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
313 return format_id_trans_tbl[id];
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
314 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
315 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
316 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
317 return EXIF_FORMAT_UNKNOWN;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
318 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
319 }
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
320
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
321 const char *exif_item_get_format_name(ExifItem *item, gint brief)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
322 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
323 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
324 if (!item) return NULL;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
325 return ((Exiv2::Metadatum *)item)->typeName();
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
326 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
327 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
328 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
329 return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
330 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
331 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
332
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
333
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
334 gchar *exif_item_get_data_as_text(ExifItem *item)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
335 {
183
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
336 try {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
337 if (!item) return NULL;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
338 // std::stringstream str; // does not work with Exiv2::Metadatum because operator<< is not virtual
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
339 // str << *((Exiv2::Metadatum *)item);
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
340 // return g_strdup(str.str().c_str());
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
341 return g_strdup(((Exiv2::Metadatum *)item)->toString().c_str());
183
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
342 }
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
343 catch (Exiv2::AnyError& e) {
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
344 return NULL;
3962c9d3d6fd more exiv2 fixes
nadvornik
parents: 182
diff changeset
345 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
346 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
347
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
348
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
349 gint exif_item_get_integer(ExifItem *item, gint *value)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
350 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
351 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
352 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
353 *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
354 return 1;
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
355 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
356 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
357 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
358 return 0;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
359 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
360 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
361
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
362 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
363 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
364 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
365 if (!item) return NULL;
185
354da67a7ca2 read also iptc and xmp
nadvornik
parents: 184
diff changeset
366 Exiv2::Rational v = ((Exiv2::Metadatum *)item)->toRational();
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
367 static ExifRational ret;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
368 ret.num = v.first;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
369 ret.den = v.second;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
370 return &ret;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
371 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
372 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
373 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
374 return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
375 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
376 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
377
182
8a417f10ba09 more exiv2 fixes
nadvornik
parents: 180
diff changeset
378 const gchar *exif_get_tag_description_by_key(const gchar *key)
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
379 {
184
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
380 try {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
381 Exiv2::ExifKey ekey(key);
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
382 return Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ());
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
383 }
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
384 catch (Exiv2::AnyError& e) {
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
385 std::cout << "Caught Exiv2 exception '" << e << "'\n";
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
386 return NULL;
2507418ab7a2 more exiv2 fixes
nadvornik
parents: 183
diff changeset
387 }
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
388 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
389
187
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
390 int exif_item_set_string(ExifItem *item, const char *str)
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
391 {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
392 try {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
393 if (!item) return 0;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
394 ((Exiv2::Metadatum *)item)->setValue(std::string(str));
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
395 return 1;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
396 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
397 catch (Exiv2::AnyError& e) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
398 return 0;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
399 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
400 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
401
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
402 int exif_item_delete(ExifData *exif, ExifItem *item)
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
403 {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
404 try {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
405 if (!item) return 0;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
406 for (Exiv2::ExifData::iterator i = exif->image->exifData().begin(); i != exif->image->exifData().end(); ++i) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
407 if (((Exiv2::Metadatum *)item) == &*i) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
408 i = exif->image->exifData().erase(i);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
409 return 1;
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 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
412 for (Exiv2::IptcData::iterator i = exif->image->iptcData().begin(); i != exif->image->iptcData().end(); ++i) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
413 if (((Exiv2::Metadatum *)item) == &*i) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
414 i = exif->image->iptcData().erase(i);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
415 return 1;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
416 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
417 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
418 for (Exiv2::XmpData::iterator i = exif->image->xmpData().begin(); i != exif->image->xmpData().end(); ++i) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
419 if (((Exiv2::Metadatum *)item) == &*i) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
420 i = exif->image->xmpData().erase(i);
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
421 return 1;
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
422 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
423 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
424
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
425 return 0;
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 catch (Exiv2::AnyError& e) {
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
428 return 0;
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 }
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
431
9eafc4957f1a write support in Exiv2 wrapper; for now only string values
nadvornik
parents: 186
diff changeset
432
186
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
433
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
434 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
435
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
436 /* This is a dirty hack to support raw file preview, bassed on
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
437 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
438
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
439 class RawFile {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
440 public:
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
441
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
442 RawFile(int fd);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
443 ~RawFile();
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
444
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
445 const Exiv2::Value *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
446
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
447 unsigned long preview_offset();
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
448
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
449 private:
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
450 int type;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
451 Exiv2::TiffComponent::AutoPtr rootDir;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
452 Exiv2::byte *map_data;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
453 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
454 unsigned long offset;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
455 };
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
456
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
457 using namespace Exiv2;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
458
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
459 RawFile::RawFile(int fd) : map_data(NULL), map_len(0), offset(0)
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
460 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
461 struct stat st;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
462 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
463 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
464 throw Error(14);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
465 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
466 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
467 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
468 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
469 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
470 throw Error(14);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
471 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
472 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
473
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
474 TiffHeaderBase *tiffHeader;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
475 switch (type) {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
476 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
477 tiffHeader = new TiffHeade2();
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
478 break;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
479 case Exiv2::ImageType::cr2:
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
480 tiffHeader = new Cr2Header();
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
481 break;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
482 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
483 tiffHeader = new OrfHeader();
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
484 break;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
485 case Exiv2::ImageType::raf:
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
486 if (map_len < 84 + 4) throw Error(14);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
487 offset = getULong(map_data + 84, bigEndian);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
488 return;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
489
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
490 default:
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
491 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
492 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
493
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
494 // 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
495 if (!tiffHeader->read(map_data, map_len)) throw Error(3, "TIFF");
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
496
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
497 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
498
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
499 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
500 if (0 == rootDir.get()) {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
501 throw Error(1, "No root element defined in TIFF structure");
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
502 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
503 rootDir->setStart(map_data + tiffHeader->offset());
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
504
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
505 TiffRwState::AutoPtr state(
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
506 new TiffRwState(tiffHeader->byteOrder(), 0, createFct));
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
507
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
508 TiffReader reader(map_data,
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
509 map_len,
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
510 rootDir.get(),
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
511 state);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
512
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
513 rootDir->accept(reader);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
514
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
515 delete tiffHeader;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
516 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
517
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
518 RawFile::~RawFile()
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
519 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
520 if (map_data && munmap(map_data, map_len) == -1)
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
521 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
522 printf("Failed to unmap file \n");
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
523 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
524 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
525
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
526 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
527 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
528 printf("%04x %04x\n", tag, group);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
529 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
530 rootDir->accept(finder);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
531 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
532 if (te)
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
533 return te->pValue();
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
534 else
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
535 return NULL;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
536 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
537
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
538 unsigned long RawFile::preview_offset()
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
539 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
540 const Value *val;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
541 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
542
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
543 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
544 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
545 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
546 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
547
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
548 return 0;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
549 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
550
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
551 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
552 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
553
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
554 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
555 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
556
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
557 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
558 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
559
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
560 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
561 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
562
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
563 return 0;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
564 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
565
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
566
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
567 const static char *raw_ext_list[] = { ".cr2", ".nef", ".pef", ".arw", NULL };
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
568
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
569 extern "C" gint format_raw_img_exif_offsets_fd(int fd, const gchar *path,
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
570 unsigned char *header_data, const guint header_len,
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
571 guint *image_offset, guint *exif_offset)
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
572 {
186
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
573 int success;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
574 unsigned long offset;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
575
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
576 /* given image pathname, first do simple (and fast) file extension test */
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
577 /* if (path)
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
578 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
579 const gchar *ext;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
580 gint match = FALSE;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
581 gint i;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
582
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
583 ext = strrchr(path, '.');
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
584 if (!ext) return FALSE;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
585
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
586 for (i = 0; raw_ext_list[i]; i++)
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
587 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
588 if (strcasecmp(raw_ext_list[i], ext) == 0)
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
589 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
590 match = TRUE;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
591 break;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
592 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
593 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
594
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
595 if (!match) return FALSE;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
596
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
597 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
598 */
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
599 try {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
600 RawFile rf(fd);
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
601 offset = rf.preview_offset();
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
602 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
603 catch (Exiv2::AnyError& e) {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
604 std::cout << "Caught Exiv2 exception '" << e << "'\n";
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
605 return 0;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
606 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
607
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
608 if (image_offset)
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
609 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
610 *image_offset = offset;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
611 if (lseek(fd, *image_offset, SEEK_SET) != *image_offset)
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
612 {
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
613 printf("Failed to seek to embedded image\n");
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
614
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
615 *image_offset = 0;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
616 if (*exif_offset) *exif_offset = 0;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
617 success = FALSE;
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
618 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
619 }
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
620
bd3fc1aa7fe9 a hack to read raw previews with exiv2 0.16, however it should be fixed
nadvornik
parents: 185
diff changeset
621 return offset > 0;
178
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
622 }
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
623
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
624
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
625 #endif
9dc8bc9b2bb9 first exiv2 support that does not crash immediately
nadvornik
parents:
diff changeset
626 /* HAVE_EXIV2 */