add focal length to EXIF display & tweak other EXIF display

This commit is contained in:
Colin McMillen 2023-07-24 16:39:01 -04:00
parent 4d63f64be6
commit 6c7dbe5516

View File

@ -146,6 +146,7 @@ public class Photo {
public bool Loaded = false; public bool Loaded = false;
public string? CameraModel; public string? CameraModel;
public string? LensModel; public string? LensModel;
public string FocalLength = "<unk>";
public string FNumber = "<unk>"; public string FNumber = "<unk>";
public string ExposureTime = "<unk>"; public string ExposureTime = "<unk>";
public string IsoSpeed = "<unk>"; public string IsoSpeed = "<unk>";
@ -164,7 +165,6 @@ public class Photo {
image = await Image.LoadAsync<Rgba32>(File); image = await Image.LoadAsync<Rgba32>(File);
ExifProfile? exifs = image.Metadata.ExifProfile; ExifProfile? exifs = image.Metadata.ExifProfile;
if (exifs != null) { if (exifs != null) {
Console.WriteLine("--------------------------------------");
// 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)) {
@ -175,6 +175,12 @@ public class Photo {
LensModel = lensModel.Value; LensModel = lensModel.Value;
} }
IExifValue<Rational>? focalLength;
if (exifs.TryGetValue(ExifTag.FocalLength, out focalLength)) {
Rational r = focalLength.Value;
FocalLength = $"{r.Numerator / r.Denominator}mm";
}
IExifValue<Rational>? fNumber; IExifValue<Rational>? fNumber;
if (exifs.TryGetValue(ExifTag.FNumber, out fNumber)) { if (exifs.TryGetValue(ExifTag.FNumber, out fNumber)) {
Rational r = fNumber.Value; Rational r = fNumber.Value;
@ -205,12 +211,14 @@ 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;
IsoSpeed = $"ISO {iso[0]}"; if (iso != null && iso.Length >= 1) {
} IsoSpeed = $"ISO {iso[0]}";
foreach (IExifValue exif in exifs.Values) { }
Console.WriteLine(exif.Tag.ToString() + " " + exif.GetValue().ToString());
} }
// foreach (IExifValue exif in exifs.Values) {
// Console.WriteLine(exif.Tag.ToString() + " " + exif.GetValue().ToString());
// }
} }
} }
@ -226,10 +234,10 @@ public class Photo {
public string Description() { public string Description() {
if (Loaded) { if (Loaded) {
string shootingInfo = $"{FNumber} at {ExposureTime}, {IsoSpeed}"; string shootingInfo = $"{FocalLength}, {FNumber} at {ExposureTime}, {IsoSpeed}";
return String.Format("{0,-30} {1,-50} {2}", shootingInfo, $"{CameraModel} {LensModel}", File); return String.Format("{0,-40} {1,-50} {2}", shootingInfo, $"{CameraModel} {LensModel}", File);
} else { } else {
return String.Format("{0,-81} {1}", "", File); return String.Format("{0,-90} {1}", "", File);
} }
} }
} }
@ -489,10 +497,12 @@ public class Game : GameWindow {
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float)); GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
// Load textures from JPEGs. // Load textures from JPEGs.
// 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\14\");
// string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
for (int i = 0; i < files.Count(); i++) { for (int i = 0; i < files.Count(); i++) {
string file = files[i]; string file = files[i];
@ -500,7 +510,9 @@ public class Game : GameWindow {
Photo photo = new Photo(file, TEXTURE_WHITE); Photo photo = new Photo(file, TEXTURE_WHITE);
photos.Add(photo); photos.Add(photo);
await Task.Run( () => { photo.Load(); }); await Task.Run( () => { photo.Load(); });
Console.WriteLine("file " + i); if (photos.Count == 100) {
break;
}
} }
} }
} }