Hi,

waypoint creation from Exif data should better take host endianess into account, otherwise waypoints could be a bit off ;-)

Regards,

--
Michael

:wq
Index: src/CWptDB.cpp
===================================================================
--- src/CWptDB.cpp      (revision 2972)
+++ src/CWptDB.cpp      (working copy)
@@ -46,12 +46,16 @@
 typedef ExifData* (*exif_data_new_from_file_t)(const char *);
 typedef void (*exif_data_foreach_content_t)(ExifData *, 
ExifDataForeachContentFunc , void *);
 typedef ExifIfd (*exif_content_get_ifd_t)(ExifContent *);
+typedef ExifRational (*exif_get_rational_t)(const unsigned char *, 
ExifByteOrder);
+typedef ExifByteOrder (*exif_data_get_byte_order_t)(ExifData *);
 
 static exif_content_foreach_entry_t f_exif_content_foreach_entry;
 static exif_data_unref_t f_exif_data_unref;
 static exif_data_new_from_file_t f_exif_data_new_from_file;
 static exif_data_foreach_content_t f_exif_data_foreach_content;
 static exif_content_get_ifd_t f_exif_content_get_ifd;
+static exif_get_rational_t f_exif_get_rational;
+static exif_data_get_byte_order_t f_exif_data_get_byte_order;
 #endif
 
 CWptDB::CWptDB(QTabWidget * tb, QObject * parent)
@@ -75,12 +79,16 @@
     f_exif_data_new_from_file       = 
(exif_data_new_from_file_t)QLibrary::resolve("libexif-12", 
"exif_data_new_from_file");
     f_exif_data_foreach_content     = 
(exif_data_foreach_content_t)QLibrary::resolve("libexif-12", 
"exif_data_foreach_content");
     f_exif_content_get_ifd          = 
(exif_content_get_ifd_t)QLibrary::resolve("libexif-12", "exif_content_get_ifd");
+    f_exif_get_rational             = 
(exif_content_get_rational_t)QLibrary::resolve("libexif-12", 
"exif_get_rational");
+    f_exif_data_get_byte_order      = 
(exif_data_get_byte_order_t)QLibrary::resolve("libexif-12", 
"exif_data_get_byte_order");
 #else
-    f_exif_content_foreach_entry    = 
(exif_content_foreach_entry_t)QLibrary::resolve("libexif", 
"exif_content_foreach_entry");
-    f_exif_data_unref               = 
(exif_data_unref_t)QLibrary::resolve("libexif", "exif_data_unref");
-    f_exif_data_new_from_file       = 
(exif_data_new_from_file_t)QLibrary::resolve("libexif", 
"exif_data_new_from_file");
-    f_exif_data_foreach_content     = 
(exif_data_foreach_content_t)QLibrary::resolve("libexif", 
"exif_data_foreach_content");
-    f_exif_content_get_ifd          = 
(exif_content_get_ifd_t)QLibrary::resolve("libexif", "exif_content_get_ifd");
+    f_exif_content_foreach_entry    = exif_content_foreach_entry;
+    f_exif_data_unref               = exif_data_unref;
+    f_exif_data_new_from_file       = exif_data_new_from_file;
+    f_exif_data_foreach_content     = exif_data_foreach_content;
+    f_exif_content_get_ifd          = exif_content_get_ifd;
+    f_exif_get_rational             = exif_get_rational;
+    f_exif_data_get_byte_order      = exif_data_get_byte_order;
 #endif
 #endif
 
@@ -1039,14 +1047,13 @@
         }
         case EXIF_TAG_GPS_LATITUDE:
         {
-            ExifRational * p = (ExifRational*)exifEntry->data;
             if(exifEntry->components == 3)
             {
-                //                 qDebug() << "lat" << exifEntry->components;
-                //                 qDebug() <<  p[0].numerator <<  
p[0].denominator << ((double)p[0].numerator / p[0].denominator);
-                //                 qDebug() <<  p[1].numerator <<  
p[1].denominator << ((double)p[1].numerator / (p[1].denominator * 60));
-                //                 qDebug() <<  p[2].numerator <<  
p[2].denominator << ((double)p[2].numerator / ((double)p[2].denominator * 
3600.0));
-                exifGPS.lat = (double)p[0].numerator/p[0].denominator + 
(double)p[1].numerator/(p[1].denominator * 60) + 
(double)p[2].numerator/((double)p[2].denominator * 3600.0);
+                ExifRational * p = (ExifRational*)exifEntry->data;
+                ExifRational deg = f_exif_get_rational((const unsigned 
char*)p++, exifGPS.byte_order);
+                ExifRational min = f_exif_get_rational((const unsigned 
char*)p++, exifGPS.byte_order);
+                ExifRational sec = f_exif_get_rational((const unsigned 
char*)p++, exifGPS.byte_order);
+                exifGPS.lat = (double)deg.numerator/deg.denominator + 
(double)min.numerator/(min.denominator * 60) + 
(double)sec.numerator/((double)sec.denominator * 3600.0);
             }
             break;
         }
@@ -1060,16 +1067,14 @@
         }
         case EXIF_TAG_GPS_LONGITUDE:
         {
-            ExifRational * p = (ExifRational*)exifEntry->data;
             if(exifEntry->components == 3)
             {
-                //                 qDebug() << "lon" << exifEntry->components;
-                //                 qDebug() <<  p[0].numerator <<  
p[0].denominator << ((double)p[0].numerator / p[0].denominator);
-                //                 qDebug() <<  p[1].numerator <<  
p[1].denominator << ((double)p[1].numerator / (p[1].denominator * 60));
-                //                 qDebug() <<  p[2].numerator <<  
p[2].denominator << ((double)p[2].numerator / ((double)p[2].denominator * 
3600.0));
-                exifGPS.lon = (double)p[0].numerator/p[0].denominator + 
(double)p[1].numerator/(p[1].denominator * 60) + 
(double)p[2].numerator/((double)p[2].denominator * 3600.0);
+                ExifRational * p = (ExifRational*)exifEntry->data;
+                ExifRational deg = f_exif_get_rational((const unsigned 
char*)p++, exifGPS.byte_order);
+                ExifRational min = f_exif_get_rational((const unsigned 
char*)p++, exifGPS.byte_order);
+                ExifRational sec = f_exif_get_rational((const unsigned 
char*)p++, exifGPS.byte_order);
+                exifGPS.lon = (double)deg.numerator/deg.denominator + 
(double)min.numerator/(min.denominator * 60) + 
(double)sec.numerator/((double)sec.denominator * 3600.0);
             }
-
             break;
         }
         default:;
@@ -1161,7 +1166,7 @@
 
         ExifData * exifData = 
f_exif_data_new_from_file(dir.filePath(file).toLocal8Bit());
 
-        exifGPS_t exifGPS;
+        exifGPS_t exifGPS(f_exif_data_get_byte_order(exifData));
 
         f_exif_data_foreach_content(exifData, exifDataForeachContentFunc, 
&exifGPS);
 
Index: src/CWptDB.h
===================================================================
--- src/CWptDB.h        (revision 2972)
+++ src/CWptDB.h        (working copy)
@@ -25,6 +25,10 @@
 #include <QMap>
 #include <QStringList>
 
+#ifdef HAS_EXIF
+#include <libexif/exif-data.h>
+#endif
+
 class CWptToolWidget;
 class CWpt;
 
@@ -91,7 +95,7 @@
 
         struct exifGPS_t
         {
-            exifGPS_t(): lon(0.0), lat(0.0), lon_sign(1), lat_sign(1){}
+            exifGPS_t(ExifByteOrder exif_byte_order): lon(0.0), lat(0.0), 
lon_sign(1), lat_sign(1), byte_order(exif_byte_order) {}
             double lon;
             double lat;
 
@@ -99,6 +103,8 @@
             int lat_sign;
 
             int timestamp;
+
+            ExifByteOrder byte_order;
         };
 #endif
 
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Qlandkartegt-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qlandkartegt-users

Reply via email to