From 25ca0d99ff674d483d0fb1277b243a84f2f06087 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Mon, 24 Jul 2023 17:13:19 -0400 Subject: [PATCH] handle ExposureTime edge cases (for long exposures) use a black texture while loading instead of white print some more error messages in EXIF edge cases --- Program.cs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Program.cs b/Program.cs index b0f66f2..3d40259 100644 --- a/Program.cs +++ b/Program.cs @@ -166,10 +166,12 @@ public class Photo { ExifProfile? exifs = image.Metadata.ExifProfile; if (exifs != null) { // FIXME: handle Orientation + IExifValue? model; if (exifs.TryGetValue(ExifTag.Model, out model)) { CameraModel = model.Value; } + IExifValue? lensModel; if (exifs.TryGetValue(ExifTag.LensModel, out lensModel)) { LensModel = lensModel.Value; @@ -187,7 +189,9 @@ public class Photo { if (r.Denominator == 1) { FNumber = $"f/{r.Numerator}"; } else { - // FIXME: assert that numerator is 10 + if (r.Denominator != 10) { + Console.WriteLine($"*** WARNING: unexpected FNumber denominator: {r.Denominator}"); + } if (r.Numerator % 10 == 0) { FNumber = $"f/{r.Numerator / 10}"; } else { @@ -203,8 +207,12 @@ public class Photo { ExposureTime = $"1/{r.Denominator}"; } else if (r.Numerator == 10) { ExposureTime = $"1/{r.Denominator / 10}"; + } else if (r.Denominator == 1) { + ExposureTime = $"{r.Numerator }\""; + } else if (r.Denominator == 10) { + ExposureTime = $"{r.Numerator / 10}.{r.Numerator % 10}\""; } else { - Console.WriteLine("*** WARNING: unexpected ExposureTime numerator"); + Console.WriteLine($"*** WARNING: unexpected ExposureTime: {r.Numerator}/{r.Denominator}"); ExposureTime = r.ToString(); } } @@ -212,8 +220,13 @@ public class Photo { IExifValue? isoSpeed; if (exifs.TryGetValue(ExifTag.ISOSpeedRatings, out isoSpeed)) { ushort[]? iso = isoSpeed.Value; - if (iso != null && iso.Length >= 1) { - IsoSpeed = $"ISO {iso[0]}"; + if (iso != null) { + if (iso.Length != 1) { + Console.WriteLine($"*** WARNING: unexpected ISOSpeedRatings array length: {iso.Length}"); + } + if (iso.Length >= 1) { + IsoSpeed = $"ISO {iso[0]}"; + } } } // foreach (IExifValue exif in exifs.Values) { @@ -364,6 +377,7 @@ public class Game : GameWindow { public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) {} private static Texture TEXTURE_WHITE = new(new Image(1, 1, new Rgba32(255, 255, 255))); + private static Texture TEXTURE_BLACK = new(new Image(1, 1, new Rgba32(0, 0, 0))); UiGeometry geometry = new(); @@ -507,7 +521,7 @@ public class Game : GameWindow { for (int i = 0; i < files.Count(); i++) { string file = files[i]; if (file.ToLower().EndsWith(".jpg")) { - Photo photo = new Photo(file, TEXTURE_WHITE); + Photo photo = new Photo(file, TEXTURE_BLACK); photos.Add(photo); await Task.Run( () => { photo.Load(); }); if (photos.Count == 100) {