Revision: 1522
          http://geeqie.svn.sourceforge.net/geeqie/?rev=1522&view=rev
Author:   nadvornik
Date:     2009-03-13 10:36:32 +0000 (Fri, 13 Mar 2009)

Log Message:
-----------
handle sidecar files for raw formats that are not known to exiv2

Modified Paths:
--------------
    trunk/src/exiv2.cc

Modified: trunk/src/exiv2.cc
===================================================================
--- trunk/src/exiv2.cc  2009-03-13 09:03:06 UTC (rev 1521)
+++ trunk/src/exiv2.cc  2009-03-13 10:36:32 UTC (rev 1522)
@@ -129,50 +129,67 @@
        /* the icc profile in jpeg is not technically exif - store it here */
        unsigned char *cp_data_;
        guint cp_length_;
+       gboolean valid_;
 
+       Exiv2::ExifData emptyExifData_;
+       Exiv2::IptcData emptyIptcData_;
+#if EXIV2_TEST_VERSION(0,16,0)
+       Exiv2::XmpData emptyXmpData_;
+#endif
+
 public:
        _ExifDataOriginal(Exiv2::Image::AutoPtr image)
        {
                cp_data_ = NULL;
                cp_length_ = 0;
                image_ = image;
+               valid_ = TRUE;
        }
 
        _ExifDataOriginal(gchar *path)
        {
                cp_data_ = NULL;
                cp_length_ = 0;
+               valid_ = TRUE;
+               
                gchar *pathl = path_from_utf8(path);
-               image_ = Exiv2::ImageFactory::open(pathl);
-               g_free(pathl);
-//             g_assert (image.get() != 0);
-               image_->readMetadata();
+               try 
+                       {
+                       image_ = Exiv2::ImageFactory::open(pathl);
+//                     g_assert (image.get() != 0);
+                       image_->readMetadata();
 
 #if EXIV2_TEST_VERSION(0,16,0)
-               if (image_->mimeType() == "application/rdf+xml")
-                       {
-                       //Exiv2 sidecar converts xmp to exif and iptc, we don't 
want it.
-                       image_->clearExifData();
-                       image_->clearIptcData();
-                       }
+                       if (image_->mimeType() == "application/rdf+xml")
+                               {
+                               //Exiv2 sidecar converts xmp to exif and iptc, 
we don't want it.
+                               image_->clearExifData();
+                               image_->clearIptcData();
+                               }
 #endif
 
 #if EXIV2_TEST_VERSION(0,14,0)
-               if (image_->mimeType() == "image/jpeg")
-                       {
-                       /* try to get jpeg color profile */
-                       Exiv2::BasicIo &io = image_->io();
-                       gint open = io.isopen();
-                       if (!open) io.open();
-                       if (io.isopen())
+                       if (image_->mimeType() == "image/jpeg")
                                {
-                               unsigned char *mapped = (unsigned 
char*)io.mmap();
-                               if (mapped) exif_jpeg_parse_color(this, mapped, 
io.size());
-                               io.munmap();
+                               /* try to get jpeg color profile */
+                               Exiv2::BasicIo &io = image_->io();
+                               gint open = io.isopen();
+                               if (!open) io.open();
+                               if (io.isopen())
+                                       {
+                                       unsigned char *mapped = (unsigned 
char*)io.mmap();
+                                       if (mapped) exif_jpeg_parse_color(this, 
mapped, io.size());
+                                       io.munmap();
+                                       }
+                               if (!open) io.close();
                                }
-                       if (!open) io.close();
+#endif
                        }
-#endif
+               catch (Exiv2::AnyError& e) 
+                       {
+                       valid_ = FALSE;
+                       }
+               g_free(pathl);
        }
        
        virtual ~_ExifDataOriginal()
@@ -182,22 +199,26 @@
        
        virtual Exiv2::Image *image()
        {
+               if (!valid_) return NULL;
                return image_.get();
        }
        
        virtual Exiv2::ExifData &exifData ()
        {
+               if (!valid_) return emptyExifData_;
                return image_->exifData();
        }
 
        virtual Exiv2::IptcData &iptcData ()
        {
+               if (!valid_) return emptyIptcData_;
                return image_->iptcData();
        }
 
 #if EXIV2_TEST_VERSION(0,16,0)
        virtual Exiv2::XmpData &xmpData ()
        {
+               if (!valid_) return emptyXmpData_;
                return image_->xmpData();
        }
 #endif
@@ -288,12 +309,15 @@
 
                        copyXmpToExif(xmpData_, exifData_);
 #endif
-                       imageData_->image()->setExifData(exifData_);
-                       imageData_->image()->setIptcData(iptcData_);
+                       Exiv2::Image *image = imageData_->image();
+                       
+                       if (!image) Exiv2::Error(21);
+                       image->setExifData(exifData_);
+                       image->setIptcData(iptcData_);
 #if EXIV2_TEST_VERSION(0,16,0)
-                       imageData_->image()->setXmpData(xmpData_);
+                       image->setXmpData(xmpData_);
 #endif
-                       imageData_->image()->writeMetadata();
+                       image->writeMetadata();
                        } 
                else
                        {
@@ -1052,6 +1076,8 @@
 {
        if (!exif) return NULL;
 
+       if (!exif->image()) return NULL;
+       
        const char* path = exif->image()->io().path().c_str();
        /* given image pathname, first do simple (and fast) file extension test 
*/
        gboolean is_raw = filter_file_class(path, FORMAT_CLASS_RAWIMAGE);
@@ -1152,6 +1178,8 @@
        unsigned long offset;
 
        if (!exif) return NULL;
+       if (!exif->image()) return NULL;
+
        const char* path = exif->image()->io().path().c_str();
 
        /* given image pathname, first do simple (and fast) file extension test 
*/


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Geeqie-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geeqie-svn

Reply via email to