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
This commit is contained in:
Colin McMillen 2023-07-24 17:13:19 -04:00
parent 6c7dbe5516
commit 25ca0d99ff

View File

@ -166,10 +166,12 @@ public class Photo {
ExifProfile? exifs = image.Metadata.ExifProfile; ExifProfile? exifs = image.Metadata.ExifProfile;
if (exifs != null) { if (exifs != null) {
// FIXME: handle Orientation // FIXME: handle Orientation
IExifValue<string>? model; IExifValue<string>? model;
if (exifs.TryGetValue(ExifTag.Model, out model)) { if (exifs.TryGetValue(ExifTag.Model, out model)) {
CameraModel = model.Value; CameraModel = model.Value;
} }
IExifValue<string>? lensModel; IExifValue<string>? lensModel;
if (exifs.TryGetValue(ExifTag.LensModel, out lensModel)) { if (exifs.TryGetValue(ExifTag.LensModel, out lensModel)) {
LensModel = lensModel.Value; LensModel = lensModel.Value;
@ -187,7 +189,9 @@ public class Photo {
if (r.Denominator == 1) { if (r.Denominator == 1) {
FNumber = $"f/{r.Numerator}"; FNumber = $"f/{r.Numerator}";
} else { } else {
// FIXME: assert that numerator is 10 if (r.Denominator != 10) {
Console.WriteLine($"*** WARNING: unexpected FNumber denominator: {r.Denominator}");
}
if (r.Numerator % 10 == 0) { if (r.Numerator % 10 == 0) {
FNumber = $"f/{r.Numerator / 10}"; FNumber = $"f/{r.Numerator / 10}";
} else { } else {
@ -203,8 +207,12 @@ public class Photo {
ExposureTime = $"1/{r.Denominator}"; ExposureTime = $"1/{r.Denominator}";
} else if (r.Numerator == 10) { } else if (r.Numerator == 10) {
ExposureTime = $"1/{r.Denominator / 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 { } else {
Console.WriteLine("*** WARNING: unexpected ExposureTime numerator"); Console.WriteLine($"*** WARNING: unexpected ExposureTime: {r.Numerator}/{r.Denominator}");
ExposureTime = r.ToString(); ExposureTime = r.ToString();
} }
} }
@ -212,8 +220,13 @@ public class Photo {
IExifValue<ushort[]>? isoSpeed; IExifValue<ushort[]>? isoSpeed;
if (exifs.TryGetValue(ExifTag.ISOSpeedRatings, out isoSpeed)) { if (exifs.TryGetValue(ExifTag.ISOSpeedRatings, out isoSpeed)) {
ushort[]? iso = isoSpeed.Value; ushort[]? iso = isoSpeed.Value;
if (iso != null && iso.Length >= 1) { if (iso != null) {
IsoSpeed = $"ISO {iso[0]}"; 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) { // foreach (IExifValue exif in exifs.Values) {
@ -364,6 +377,7 @@ public class Game : GameWindow {
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) {} public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) {}
private static Texture TEXTURE_WHITE = new(new Image<Rgba32>(1, 1, new Rgba32(255, 255, 255))); private static Texture TEXTURE_WHITE = new(new Image<Rgba32>(1, 1, new Rgba32(255, 255, 255)));
private static Texture TEXTURE_BLACK = new(new Image<Rgba32>(1, 1, new Rgba32(0, 0, 0)));
UiGeometry geometry = new(); UiGeometry geometry = new();
@ -507,7 +521,7 @@ public class Game : GameWindow {
for (int i = 0; i < files.Count(); i++) { for (int i = 0; i < files.Count(); i++) {
string file = files[i]; string file = files[i];
if (file.ToLower().EndsWith(".jpg")) { if (file.ToLower().EndsWith(".jpg")) {
Photo photo = new Photo(file, TEXTURE_WHITE); Photo photo = new Photo(file, TEXTURE_BLACK);
photos.Add(photo); photos.Add(photo);
await Task.Run( () => { photo.Load(); }); await Task.Run( () => { photo.Load(); });
if (photos.Count == 100) { if (photos.Count == 100) {