3 * Copyright (C) 2008 The Geeqie Team
5 * Author: Vladimir Nadvornik
7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information.
9 * This software comes with no warranty of any kind, use at your own risk!
16 #include <exiv2/image.hpp>
17 #include <exiv2/exif.hpp>
20 // EXIV2_TEST_VERSION is defined in Exiv2 0.15 and newer.
21 #ifndef EXIV2_TEST_VERSION
22 # define EXIV2_TEST_VERSION(major,minor,patch) \
23 ( EXIV2_VERSION >= EXIV2_MAKE_VERSION(major,minor,patch) )
27 #include <sys/types.h>
33 #if !EXIV2_TEST_VERSION(0,17,90)
34 #include <exiv2/tiffparser.hpp>
35 #include <exiv2/tiffcomposite.hpp>
36 #include <exiv2/tiffvisitor.hpp>
37 #include <exiv2/tiffimage.hpp>
38 #include <exiv2/cr2image.hpp>
39 #include <exiv2/crwimage.hpp>
40 #if EXIV2_TEST_VERSION(0,16,0)
41 #include <exiv2/orfimage.hpp>
43 #if EXIV2_TEST_VERSION(0,13,0)
44 #include <exiv2/rafimage.hpp>
46 #include <exiv2/futils.hpp>
48 #include <exiv2/preview.hpp>
51 #if EXIV2_TEST_VERSION(0,17,0)
52 #include <exiv2/convert.hpp>
62 #include "filefilter.h"
63 #include "ui_fileops.h"
68 Exiv2::ExifData::const_iterator exifIter; /* for exif_get_next_item */
69 Exiv2::IptcData::const_iterator iptcIter; /* for exif_get_next_item */
70 #if EXIV2_TEST_VERSION(0,16,0)
71 Exiv2::XmpData::const_iterator xmpIter; /* for exif_get_next_item */
78 virtual void writeMetadata()
80 g_critical("Unsupported method of writing metadata");
83 virtual ExifData *original()
88 virtual Exiv2::Image *image() = 0;
90 virtual Exiv2::ExifData &exifData() = 0;
92 virtual Exiv2::IptcData &iptcData() = 0;
94 #if EXIV2_TEST_VERSION(0,16,0)
95 virtual Exiv2::XmpData &xmpData() = 0;
98 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length) = 0;
100 virtual guchar *get_jpeg_color_profile(guint *data_len) = 0;
103 // This allows read-only access to the original metadata
104 struct _ExifDataOriginal : public _ExifData
107 Exiv2::Image::AutoPtr image_;
109 /* the icc profile in jpeg is not technically exif - store it here */
110 unsigned char *cp_data_;
115 _ExifDataOriginal(gchar *path)
119 gchar *pathl = path_from_utf8(path);
120 image_ = Exiv2::ImageFactory::open(pathl);
122 // g_assert (image.get() != 0);
123 image_->readMetadata();
125 #if EXIV2_TEST_VERSION(0,16,0)
126 if (image_->mimeType() == "application/rdf+xml")
128 //Exiv2 sidecar converts xmp to exif and iptc, we don't want it.
129 image_->clearExifData();
130 image_->clearIptcData();
134 #if EXIV2_TEST_VERSION(0,14,0)
135 if (image_->mimeType() == "image/jpeg")
137 /* try to get jpeg color profile */
138 Exiv2::BasicIo &io = image_->io();
139 gint open = io.isopen();
140 if (!open) io.open();
141 unsigned char *mapped = (unsigned char*)io.mmap();
142 if (mapped) exif_jpeg_parse_color(this, mapped, io.size());
144 if (!open) io.close();
149 virtual ~_ExifDataOriginal()
151 if (cp_data_) g_free(cp_data_);
154 virtual Exiv2::Image *image()
159 virtual Exiv2::ExifData &exifData ()
161 return image_->exifData();
164 virtual Exiv2::IptcData &iptcData ()
166 return image_->iptcData();
169 #if EXIV2_TEST_VERSION(0,16,0)
170 virtual Exiv2::XmpData &xmpData ()
172 return image_->xmpData();
176 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length)
178 if (cp_data_) g_free(cp_data_);
180 cp_length_ = cp_length;
183 virtual guchar *get_jpeg_color_profile(guint *data_len)
187 if (data_len) *data_len = cp_length_;
188 return (unsigned char *) g_memdup(cp_data_, cp_length_);
194 // This allows read-write access to the metadata
195 struct _ExifDataProcessed : public _ExifData
198 _ExifDataOriginal *imageData_;
199 _ExifDataOriginal *sidecarData_;
201 Exiv2::ExifData exifData_;
202 Exiv2::IptcData iptcData_;
203 #if EXIV2_TEST_VERSION(0,16,0)
204 Exiv2::XmpData xmpData_;
208 _ExifDataProcessed(gchar *path, gchar *sidecar_path)
210 imageData_ = new _ExifDataOriginal(path);
212 #if EXIV2_TEST_VERSION(0,16,0)
213 xmpData_ = imageData_->xmpData();
214 DEBUG_2("xmp count %li", xmpData_.count());
215 if (sidecar_path && xmpData_.empty())
217 sidecarData_ = new _ExifDataOriginal(sidecar_path);
218 xmpData_ = sidecarData_->xmpData();
221 exifData_ = imageData_->exifData();
222 iptcData_ = imageData_->iptcData();
223 #if EXIV2_TEST_VERSION(0,17,0)
224 syncExifWithXmp(exifData_, xmpData_);
228 virtual ~_ExifDataProcessed()
230 if (imageData_) delete imageData_;
231 if (sidecarData_) delete sidecarData_;
234 virtual ExifData *original()
239 virtual void writeMetadata()
241 #if EXIV2_TEST_VERSION(0,17,0)
242 syncExifWithXmp(exifData_, xmpData_);
243 copyXmpToIptc(xmpData_, iptcData_); //FIXME it should be configurable
247 sidecarData_->image()->setXmpData(xmpData_);
248 //Exiv2 sidecar converts xmp to exif and iptc, we don't want it.
249 sidecarData_->image()->clearExifData();
250 sidecarData_->image()->clearIptcData();
251 sidecarData_->image()->writeMetadata();
255 imageData_->image()->setExifData(exifData_);
256 imageData_->image()->setIptcData(iptcData_);
257 imageData_->image()->setXmpData(xmpData_);
258 imageData_->image()->writeMetadata();
262 virtual Exiv2::Image *image()
264 return imageData_->image();
267 virtual Exiv2::ExifData &exifData ()
272 virtual Exiv2::IptcData &iptcData ()
277 #if EXIV2_TEST_VERSION(0,16,0)
278 virtual Exiv2::XmpData &xmpData ()
284 virtual void add_jpeg_color_profile(unsigned char *cp_data, guint cp_length)
286 imageData_->add_jpeg_color_profile(cp_data, cp_length);
289 virtual guchar *get_jpeg_color_profile(guint *data_len)
291 return imageData_->get_jpeg_color_profile(data_len);
300 ExifData *exif_read(gchar *path, gchar *sidecar_path)
302 DEBUG_1("exif read %s, sidecar: %s", path, sidecar_path ? sidecar_path : "-");
304 return new _ExifDataProcessed(path, sidecar_path);
306 catch (Exiv2::AnyError& e) {
307 std::cout << "Caught Exiv2 exception '" << e << "'\n";
313 int exif_write(ExifData *exif)
316 exif->writeMetadata();
319 catch (Exiv2::AnyError& e) {
320 std::cout << "Caught Exiv2 exception '" << e << "'\n";
327 void exif_free(ExifData *exif)
329 g_assert(dynamic_cast<_ExifDataProcessed *>(exif)); // this should not be called on ExifDataOriginal
333 ExifData *exif_get_original(ExifData *exif)
335 return exif->original();
339 ExifItem *exif_get_item(ExifData *exif, const gchar *key)
342 Exiv2::Metadatum *item = NULL;
344 Exiv2::ExifKey ekey(key);
345 Exiv2::ExifData::iterator pos = exif->exifData().findKey(ekey);
346 if (pos == exif->exifData().end()) return NULL;
349 catch (Exiv2::AnyError& e) {
351 Exiv2::IptcKey ekey(key);
352 Exiv2::IptcData::iterator pos = exif->iptcData().findKey(ekey);
353 if (pos == exif->iptcData().end()) return NULL;
356 catch (Exiv2::AnyError& e) {
357 #if EXIV2_TEST_VERSION(0,16,0)
358 Exiv2::XmpKey ekey(key);
359 Exiv2::XmpData::iterator pos = exif->xmpData().findKey(ekey);
360 if (pos == exif->xmpData().end()) return NULL;
365 return (ExifItem *)item;
367 catch (Exiv2::AnyError& e) {
368 std::cout << "Caught Exiv2 exception '" << e << "'\n";
373 ExifItem *exif_add_item(ExifData *exif, const gchar *key)
376 Exiv2::Metadatum *item = NULL;
378 Exiv2::ExifKey ekey(key);
379 exif->exifData().add(ekey, NULL);
380 Exiv2::ExifData::iterator pos = exif->exifData().end(); // a hack, there should be a better way to get the currently added item
384 catch (Exiv2::AnyError& e) {
386 Exiv2::IptcKey ekey(key);
387 exif->iptcData().add(ekey, NULL);
388 Exiv2::IptcData::iterator pos = exif->iptcData().end();
392 catch (Exiv2::AnyError& e) {
393 #if EXIV2_TEST_VERSION(0,16,0)
394 Exiv2::XmpKey ekey(key);
395 exif->xmpData().add(ekey, NULL);
396 Exiv2::XmpData::iterator pos = exif->xmpData().end();
402 return (ExifItem *)item;
404 catch (Exiv2::AnyError& e) {
405 std::cout << "Caught Exiv2 exception '" << e << "'\n";
411 ExifItem *exif_get_first_item(ExifData *exif)
414 exif->exifIter = exif->exifData().begin();
415 exif->iptcIter = exif->iptcData().begin();
416 #if EXIV2_TEST_VERSION(0,16,0)
417 exif->xmpIter = exif->xmpData().begin();
419 if (exif->exifIter != exif->exifData().end())
421 const Exiv2::Metadatum *item = &*exif->exifIter;
423 return (ExifItem *)item;
425 if (exif->iptcIter != exif->iptcData().end())
427 const Exiv2::Metadatum *item = &*exif->iptcIter;
429 return (ExifItem *)item;
431 #if EXIV2_TEST_VERSION(0,16,0)
432 if (exif->xmpIter != exif->xmpData().end())
434 const Exiv2::Metadatum *item = &*exif->xmpIter;
436 return (ExifItem *)item;
442 catch (Exiv2::AnyError& e) {
443 std::cout << "Caught Exiv2 exception '" << e << "'\n";
448 ExifItem *exif_get_next_item(ExifData *exif)
451 if (exif->exifIter != exif->exifData().end())
453 const Exiv2::Metadatum *item = &*exif->exifIter;
455 return (ExifItem *)item;
457 if (exif->iptcIter != exif->iptcData().end())
459 const Exiv2::Metadatum *item = &*exif->iptcIter;
461 return (ExifItem *)item;
463 #if EXIV2_TEST_VERSION(0,16,0)
464 if (exif->xmpIter != exif->xmpData().end())
466 const Exiv2::Metadatum *item = &*exif->xmpIter;
468 return (ExifItem *)item;
473 catch (Exiv2::AnyError& e) {
474 std::cout << "Caught Exiv2 exception '" << e << "'\n";
479 char *exif_item_get_tag_name(ExifItem *item)
482 if (!item) return NULL;
483 return g_strdup(((Exiv2::Metadatum *)item)->key().c_str());
485 catch (Exiv2::AnyError& e) {
486 std::cout << "Caught Exiv2 exception '" << e << "'\n";
491 guint exif_item_get_tag_id(ExifItem *item)
495 return ((Exiv2::Metadatum *)item)->tag();
497 catch (Exiv2::AnyError& e) {
498 std::cout << "Caught Exiv2 exception '" << e << "'\n";
503 guint exif_item_get_elements(ExifItem *item)
507 return ((Exiv2::Metadatum *)item)->count();
509 catch (Exiv2::AnyError& e) {
510 std::cout << "Caught Exiv2 exception '" << e << "'\n";
515 char *exif_item_get_data(ExifItem *item, guint *data_len)
519 Exiv2::Metadatum *md = (Exiv2::Metadatum *)item;
520 if (data_len) *data_len = md->size();
521 char *data = (char *)g_malloc(md->size());
522 long res = md->copy((Exiv2::byte *)data, Exiv2::littleEndian /* should not matter */);
523 g_assert(res == md->size());
526 catch (Exiv2::AnyError& e) {
527 std::cout << "Caught Exiv2 exception '" << e << "'\n";
532 char *exif_item_get_description(ExifItem *item)
535 if (!item) return NULL;
536 return g_locale_to_utf8(((Exiv2::Metadatum *)item)->tagLabel().c_str(), -1, NULL, NULL, NULL);
538 catch (std::exception& e) {
539 // std::cout << "Caught Exiv2 exception '" << e << "'\n";
545 invalidTypeId, unsignedByte, asciiString, unsignedShort,
546 unsignedLong, unsignedRational, signedByte, undefined,
547 signedShort, signedLong, signedRational, string,
548 date, time, comment, directory,
549 xmpText, xmpAlt, xmpBag, xmpSeq,
553 static guint format_id_trans_tbl [] = {
555 EXIF_FORMAT_BYTE_UNSIGNED,
557 EXIF_FORMAT_SHORT_UNSIGNED,
558 EXIF_FORMAT_LONG_UNSIGNED,
559 EXIF_FORMAT_RATIONAL_UNSIGNED,
561 EXIF_FORMAT_UNDEFINED,
564 EXIF_FORMAT_RATIONAL,
568 EXIF_FORMAT_UNDEFINED,
577 guint exif_item_get_format_id(ExifItem *item)
580 if (!item) return EXIF_FORMAT_UNKNOWN;
581 guint id = ((Exiv2::Metadatum *)item)->typeId();
582 if (id >= (sizeof(format_id_trans_tbl) / sizeof(format_id_trans_tbl[0])) ) return EXIF_FORMAT_UNKNOWN;
583 return format_id_trans_tbl[id];
585 catch (Exiv2::AnyError& e) {
586 std::cout << "Caught Exiv2 exception '" << e << "'\n";
587 return EXIF_FORMAT_UNKNOWN;
591 const char *exif_item_get_format_name(ExifItem *item, gint brief)
594 if (!item) return NULL;
595 return ((Exiv2::Metadatum *)item)->typeName();
597 catch (Exiv2::AnyError& e) {
598 std::cout << "Caught Exiv2 exception '" << e << "'\n";
604 gchar *exif_item_get_data_as_text(ExifItem *item)
607 if (!item) return NULL;
608 Exiv2::Metadatum *metadatum = (Exiv2::Metadatum *)item;
609 #if EXIV2_TEST_VERSION(0,17,0)
610 return g_locale_to_utf8(metadatum->print().c_str(), -1, NULL, NULL, NULL);
612 std::stringstream str;
613 Exiv2::Exifdatum *exifdatum;
614 Exiv2::Iptcdatum *iptcdatum;
615 #if EXIV2_TEST_VERSION(0,16,0)
616 Exiv2::Xmpdatum *xmpdatum;
618 if ((exifdatum = dynamic_cast<Exiv2::Exifdatum *>(metadatum)))
620 else if ((iptcdatum = dynamic_cast<Exiv2::Iptcdatum *>(metadatum)))
622 #if EXIV2_TEST_VERSION(0,16,0)
623 else if ((xmpdatum = dynamic_cast<Exiv2::Xmpdatum *>(metadatum)))
627 return g_locale_to_utf8(str.str().c_str(), -1, NULL, NULL, NULL);
630 catch (Exiv2::AnyError& e) {
635 gchar *exif_item_get_string(ExifItem *item, int idx)
638 if (!item) return NULL;
639 Exiv2::Metadatum *em = (Exiv2::Metadatum *)item;
640 #if EXIV2_TEST_VERSION(0,16,0)
641 std::string str = em->toString(idx);
643 std::string str = em->toString(); // FIXME
645 if (idx == 0 && str == "") str = em->toString();
646 if (str.length() > 5 && str.substr(0, 5) == "lang=")
648 std::string::size_type pos = str.find_first_of(' ');
649 if (pos != std::string::npos) str = str.substr(pos+1);
652 // return g_locale_to_utf8(str.c_str(), -1, NULL, NULL, NULL); // FIXME
653 return g_strdup(str.c_str());
655 catch (Exiv2::AnyError& e) {
661 gint exif_item_get_integer(ExifItem *item, gint *value)
665 *value = ((Exiv2::Metadatum *)item)->toLong();
668 catch (Exiv2::AnyError& e) {
669 std::cout << "Caught Exiv2 exception '" << e << "'\n";
674 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, guint n)
677 if (!item) return NULL;
678 if (n >= exif_item_get_elements(item)) return NULL;
679 Exiv2::Rational v = ((Exiv2::Metadatum *)item)->toRational(n);
680 static ExifRational ret;
683 if (sign) *sign = (((Exiv2::Metadatum *)item)->typeId() == Exiv2::signedRational);
686 catch (Exiv2::AnyError& e) {
687 std::cout << "Caught Exiv2 exception '" << e << "'\n";
692 gchar *exif_get_tag_description_by_key(const gchar *key)
695 Exiv2::ExifKey ekey(key);
696 return g_locale_to_utf8(Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ()), -1, NULL, NULL, NULL);
698 catch (Exiv2::AnyError& e) {
699 std::cout << "Caught Exiv2 exception '" << e << "'\n";
704 int exif_item_set_string(ExifItem *item, const char *str)
708 ((Exiv2::Metadatum *)item)->setValue(std::string(str));
711 catch (Exiv2::AnyError& e) {
716 int exif_item_delete(ExifData *exif, ExifItem *item)
720 for (Exiv2::ExifData::iterator i = exif->exifData().begin(); i != exif->exifData().end(); ++i) {
721 if (((Exiv2::Metadatum *)item) == &*i) {
722 i = exif->exifData().erase(i);
726 for (Exiv2::IptcData::iterator i = exif->iptcData().begin(); i != exif->iptcData().end(); ++i) {
727 if (((Exiv2::Metadatum *)item) == &*i) {
728 i = exif->iptcData().erase(i);
732 #if EXIV2_TEST_VERSION(0,16,0)
733 for (Exiv2::XmpData::iterator i = exif->xmpData().begin(); i != exif->xmpData().end(); ++i) {
734 if (((Exiv2::Metadatum *)item) == &*i) {
735 i = exif->xmpData().erase(i);
742 catch (Exiv2::AnyError& e) {
747 void exif_add_jpeg_color_profile(ExifData *exif, unsigned char *cp_data, guint cp_length)
749 exif->add_jpeg_color_profile(cp_data, cp_length);
752 guchar *exif_get_color_profile(ExifData *exif, guint *data_len)
754 guchar *ret = exif->get_jpeg_color_profile(data_len);
757 ExifItem *prof_item = exif_get_item(exif, "Exif.Image.InterColorProfile");
758 if (prof_item && exif_item_get_format_id(prof_item) == EXIF_FORMAT_UNDEFINED)
759 ret = (guchar *)exif_item_get_data(prof_item, data_len);
763 #if EXIV2_TEST_VERSION(0,17,90)
765 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height)
767 if (!exif) return NULL;
769 const char* path = exif->image()->io().path().c_str();
770 /* given image pathname, first do simple (and fast) file extension test */
771 gboolean is_raw = filter_file_class(path, FORMAT_CLASS_RAWIMAGE);
773 if (!is_raw && requested_width == 0) return NULL;
777 Exiv2::PreviewManager pm(*exif->image());
779 Exiv2::PreviewPropertiesList list = pm.getPreviewProperties();
783 Exiv2::PreviewPropertiesList::iterator pos;
784 Exiv2::PreviewPropertiesList::iterator last = --list.end();
786 if (requested_width == 0)
788 pos = last; // the largest
795 if (pos->width_ >= (uint32_t)requested_width &&
796 pos->height_ >= (uint32_t)requested_height) break;
800 // we are not interested in smaller thumbnails in normal image formats - we can use full image instead
803 if (pos->width_ < (uint32_t)requested_width || pos->height_ < (uint32_t)requested_height) return NULL;
807 Exiv2::PreviewImage image = pm.getPreviewImage(*pos);
809 Exiv2::DataBuf buf = image.copy();
810 std::pair<Exiv2::byte*, long> p = buf.release();
812 *data_len = p.second;
817 catch (Exiv2::AnyError& e) {
818 std::cout << "Caught Exiv2 exception '" << e << "'\n";
823 void exif_free_preview(guchar *buf)
825 delete[] (Exiv2::byte*)buf;
830 #if !EXIV2_TEST_VERSION(0,17,90)
832 /* This is a dirty hack to support raw file preview, bassed on
833 tiffparse.cpp from Exiv2 examples */
838 RawFile(Exiv2::BasicIo &io);
841 const Exiv2::Value *find(uint16_t tag, uint16_t group);
843 unsigned long preview_offset();
847 Exiv2::TiffComponent::AutoPtr rootDir;
849 const Exiv2::byte *map_data;
851 unsigned long offset;
854 typedef struct _UnmapData UnmapData;
862 static GList *exif_unmap_list = 0;
864 extern "C" guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height)
866 unsigned long offset;
868 if (!exif) return NULL;
869 const char* path = exif->image()->io().path().c_str();
871 /* given image pathname, first do simple (and fast) file extension test */
872 if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return NULL;
881 RawFile rf(exif->image()->io());
882 offset = rf.preview_offset();
883 DEBUG_1("%s: offset %lu", path, offset);
885 fd = open(path, O_RDONLY);
891 if (fstat(fd, &st) == -1)
896 map_len = st.st_size;
897 map_data = (guchar *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0);
899 if (map_data == MAP_FAILED)
903 *data_len = map_len - offset;
904 ud = g_new(UnmapData, 1);
905 ud->ptr = map_data + offset;
906 ud->map_data = map_data;
907 ud->map_len = map_len;
909 exif_unmap_list = g_list_prepend(exif_unmap_list, ud);
913 catch (Exiv2::AnyError& e) {
914 std::cout << "Caught Exiv2 exception '" << e << "'\n";
920 void exif_free_preview(guchar *buf)
922 GList *work = exif_unmap_list;
926 UnmapData *ud = (UnmapData *)work->data;
929 munmap(ud->map_data, ud->map_len);
930 exif_unmap_list = g_list_remove_link(exif_unmap_list, work);
936 g_assert_not_reached();
939 using namespace Exiv2;
941 RawFile::RawFile(BasicIo &io) : io_(io), map_data(NULL), map_len(0), offset(0)
945 if (fstat(fd, &st) == -1)
949 map_len = st.st_size;
950 map_data = (Exiv2::byte *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0);
951 if (map_data == MAP_FAILED)
956 if (io.open() != 0) {
957 throw Error(9, io.path(), strError());
960 map_data = io.mmap();
964 type = Exiv2::ImageFactory::getType(map_data, map_len);
966 #if EXIV2_TEST_VERSION(0,16,0)
967 TiffHeaderBase *tiffHeader = NULL;
969 TiffHeade2 *tiffHeader = NULL;
971 Cr2Header *cr2Header = NULL;
974 case Exiv2::ImageType::tiff:
975 tiffHeader = new TiffHeade2();
977 case Exiv2::ImageType::cr2:
978 cr2Header = new Cr2Header();
980 #if EXIV2_TEST_VERSION(0,16,0)
981 case Exiv2::ImageType::orf:
982 tiffHeader = new OrfHeader();
985 #if EXIV2_TEST_VERSION(0,13,0)
986 case Exiv2::ImageType::raf:
987 if (map_len < 84 + 4) throw Error(14);
988 offset = getULong(map_data + 84, bigEndian);
991 case Exiv2::ImageType::crw:
993 // Parse the image, starting with a CIFF header component
994 Exiv2::CiffHeader::AutoPtr parseTree(new Exiv2::CiffHeader);
995 parseTree->read(map_data, map_len);
996 CiffComponent *entry = parseTree->findComponent(0x2007, 0);
997 if (entry) offset = entry->pData() - map_data;
1002 throw Error(3, "RAW");
1005 // process tiff-like formats
1007 TiffCompFactoryFct createFct = TiffCreator::create;
1009 rootDir = createFct(Tag::root, Group::none);
1010 if (0 == rootDir.get()) {
1011 throw Error(1, "No root element defined in TIFF structure");
1016 if (!tiffHeader->read(map_data, map_len)) throw Error(3, "TIFF");
1017 #if EXIV2_TEST_VERSION(0,16,0)
1018 rootDir->setStart(map_data + tiffHeader->offset());
1020 rootDir->setStart(map_data + tiffHeader->ifdOffset());
1026 rootDir->setStart(map_data + cr2Header->offset());
1029 TiffRwState::AutoPtr state(new TiffRwState(tiffHeader ? tiffHeader->byteOrder() : littleEndian, 0, createFct));
1031 TiffReader reader(map_data,
1036 rootDir->accept(reader);
1044 RawFile::~RawFile(void)
1050 const Value * RawFile::find(uint16_t tag, uint16_t group)
1052 TiffFinder finder(tag, group);
1053 rootDir->accept(finder);
1054 TiffEntryBase* te = dynamic_cast<TiffEntryBase*>(finder.result());
1057 DEBUG_1("(tag: %04x %04x) ", tag, group);
1058 return te->pValue();
1064 unsigned long RawFile::preview_offset(void)
1067 if (offset) return offset;
1069 if (type == Exiv2::ImageType::cr2)
1071 val = find(0x111, Group::ifd0);
1072 if (val) return val->toLong();
1077 val = find(0x201, Group::sub0_0);
1078 if (val) return val->toLong();
1080 val = find(0x201, Group::ifd0);
1081 if (val) return val->toLong();
1083 val = find(0x201, Group::ignr); // for PEF files, originally it was probably ifd2
1084 if (val) return val->toLong();
1086 val = find(0x111, Group::sub0_1); // dng
1087 if (val) return val->toLong();
1098 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */