changeset 1048:95c418661be8

updated preview loader to work with current svn version of libexiv2
author nadvornik
date Sat, 27 Sep 2008 18:48:32 +0000
parents 81ec7d977d5f
children 85e50c989da5
files src/exiv2.cc
diffstat 1 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/exiv2.cc	Wed Sep 10 20:37:30 2008 +0000
+++ b/src/exiv2.cc	Sat Sep 27 18:48:32 2008 +0000
@@ -609,19 +609,28 @@
 guchar *exif_get_preview(ExifData *exif, guint *data_len)
 {
 	if (!exif) return NULL;
+
+	const char* path = exif->image->io().path().c_str();
+	/* given image pathname, first do simple (and fast) file extension test */
+	if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return NULL;
+
 	try {
 
-		Exiv2::PreviewImageList list(*exif->image);
-		list.read();
+		Exiv2::PreviewImageLoader loader(*exif->image);
+
+		Exiv2::PreviewPropertiesList list = loader.getPreviewPropertiesList();
 
-		Exiv2::PreviewImageList::iterator pos = list.begin();
-		if (pos != list.end())
+		if (!list.empty())
 			{
-			Exiv2::DataBuf buf = pos->copy();
+			Exiv2::PreviewPropertiesList::iterator pos = --list.end();
+
+			Exiv2::PreviewImage image = loader.getPreviewImage(*pos);
+
+			Exiv2::DataBuf &buf = image.data();
 			std::pair<Exiv2::byte*, long> p = buf.release();
 
 			*data_len = p.second;
-		        return p.first;
+			return p.first;
 			}
 		return NULL;
 	}
@@ -680,7 +689,7 @@
 	const char* path = exif->image->io().path().c_str();
 
 	/* given image pathname, first do simple (and fast) file extension test */
-	if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return 0;
+	if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return NULL;
 
 	try {
 		struct stat st;
@@ -696,20 +705,20 @@
 		fd = open(path, O_RDONLY);
 		if (fd == -1)
 			{
-			return 0;
+			return NULL;
 			}
 
 		if (fstat(fd, &st) == -1)
 			{
 			close(fd);
-			return 0;
+			return NULL;
 			}
 		map_len = st.st_size;
 		map_data = (guchar *) mmap(0, map_len, PROT_READ, MAP_PRIVATE, fd, 0);
 		close(fd);
 		if (map_data == MAP_FAILED)
 			{
-			return 0;
+			return NULL;
 			}
 		*data_len = map_len - offset;
 		ud = g_new(UnmapData, 1);