From 0ca67f2cefe351a406a9d1ded417e8d3170c310b Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 30 Aug 2023 01:06:00 -0400 Subject: [PATCH] fix up GPS, sorta --- Photo.cs | 14 ++++++++++++++ Program.cs | 21 ++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Photo.cs b/Photo.cs index 34e8995..e6e6ab1 100644 --- a/Photo.cs +++ b/Photo.cs @@ -24,6 +24,8 @@ public class Photo { public string IsoSpeed = ""; public int Rating = 0; public ushort Orientation = 1; + public Rational[]? GpsLatitude = null; + public Rational[]? GpsLongitude = null; public Rectangle CropRectangle = Rectangle.Empty; private static long touchCounter = 0; @@ -110,6 +112,8 @@ public class Photo { "{0:D4}:{1:D2}:{2:D2} {3:D2}:{4:D2}:{5:D2}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); exif.SetValue(ExifTag.DateTime, datetime); + exif.SetValue(ExifTag.GPSLatitude, GpsLatitude); + exif.SetValue(ExifTag.GPSLongitude, GpsLongitude); image.Metadata.XmpProfile = UpdateXmp(image.Metadata.XmpProfile); @@ -267,6 +271,16 @@ public class Photo { Console.WriteLine($"*** WARNING: unexpected DateTimeOriginal value: {dateTimeOriginal.Value}"); } } + + IExifValue? gpsLatitude; + if (exifs.TryGetValue(ExifTag.GPSLatitude, out gpsLatitude)) { + GpsLatitude = gpsLatitude.Value; + } + + IExifValue? gpsLongitude; + if (exifs.TryGetValue(ExifTag.GPSLongitude, out gpsLongitude)) { + GpsLongitude = gpsLongitude.Value; + } } public string GetShortLensModel(string lensModel) { diff --git a/Program.cs b/Program.cs index de51972..d027409 100644 --- a/Program.cs +++ b/Program.cs @@ -684,10 +684,10 @@ public class Game : GameWindow { false, 5 * sizeof(float), 3 * sizeof(float)); // Load photos from a directory. - string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); + // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\23\"); - // string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); + string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\07\31"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); @@ -703,6 +703,21 @@ public class Game : GameWindow { } allPhotos.Sort(ComparePhotosByDate); + + // Fix up photos with missing GPS. + Rational[]? lastLatitude = null; + Rational[]? lastLongitude = null; + foreach (Photo p in allPhotos) { + if (p.GpsLatitude != null && p.GpsLongitude != null) { + lastLatitude = p.GpsLatitude; + lastLongitude = p.GpsLongitude; + } + if (p.GpsLatitude == null || p.GpsLongitude == null) { + Console.WriteLine("fixing GPS for " + p.Filename); + p.GpsLatitude = lastLatitude; + p.GpsLongitude = lastLongitude; + } + } photos = allPhotos; LoadThumbnailsAsync(); @@ -767,7 +782,7 @@ public class Game : GameWindow { } } foreach (Photo p in toLoad) { - await Task.Run( () => { p.LoadAsync(geometry.PhotoBox.Size); }); + await Task.Run( () => { p.LoadAsync(p.Size); }); } }