fix up GPS, sorta

This commit is contained in:
Colin McMillen 2023-08-30 01:06:00 -04:00
parent 32403ddeb5
commit 0ca67f2cef
2 changed files with 32 additions and 3 deletions

View File

@ -24,6 +24,8 @@ public class Photo {
public string IsoSpeed = "<unk>";
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<string>(ExifTag.DateTime, datetime);
exif.SetValue<Rational[]>(ExifTag.GPSLatitude, GpsLatitude);
exif.SetValue<Rational[]>(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<Rational[]>? gpsLatitude;
if (exifs.TryGetValue(ExifTag.GPSLatitude, out gpsLatitude)) {
GpsLatitude = gpsLatitude.Value;
}
IExifValue<Rational[]>? gpsLongitude;
if (exifs.TryGetValue(ExifTag.GPSLongitude, out gpsLongitude)) {
GpsLongitude = gpsLongitude.Value;
}
}
public string GetShortLensModel(string lensModel) {

View File

@ -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); });
}
}