Compare commits

..

No commits in common. "6c7dbe551680070ec37e7dc127e9d65005d6985f" and "56311bc56c1ab5992accc7d27c9dc4658a6353bd" have entirely different histories.

View File

@ -142,15 +142,8 @@ void main() {
// FIXME: this should probably be IDisposable?
public class Photo {
public string File;
public bool Loaded = false;
public string? CameraModel;
public string? LensModel;
public string FocalLength = "<unk>";
public string FNumber = "<unk>";
public string ExposureTime = "<unk>";
public string IsoSpeed = "<unk>";
public string File;
private Texture texture;
private Texture placeholder;
private Image<Rgba32>? image = null;
@ -165,61 +158,12 @@ public class Photo {
image = await Image.LoadAsync<Rgba32>(File);
ExifProfile? exifs = image.Metadata.ExifProfile;
if (exifs != null) {
// FIXME: handle Orientation
IExifValue<string>? model;
if (exifs.TryGetValue(ExifTag.Model, out model)) {
CameraModel = model.Value;
}
IExifValue<string>? lensModel;
if (exifs.TryGetValue(ExifTag.LensModel, out lensModel)) {
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;
if (exifs.TryGetValue(ExifTag.FNumber, out fNumber)) {
Rational r = fNumber.Value;
if (r.Denominator == 1) {
FNumber = $"f/{r.Numerator}";
} else {
// FIXME: assert that numerator is 10
if (r.Numerator % 10 == 0) {
FNumber = $"f/{r.Numerator / 10}";
} else {
FNumber= $"f/{r.Numerator / 10}.{r.Numerator % 10}";
foreach (IExifValue exif in exifs.Values) {
if (exif.Tag.ToString() == "Model") {
Console.WriteLine($"{File} {exif.Tag}: {exif.GetValue()}");
}
}
}
IExifValue<Rational>? exposureTime;
if (exifs.TryGetValue(ExifTag.ExposureTime, out exposureTime)) {
Rational r = exposureTime.Value;
if (r.Numerator == 1) {
ExposureTime = $"1/{r.Denominator}";
} else if (r.Numerator == 10) {
ExposureTime = $"1/{r.Denominator / 10}";
} else {
Console.WriteLine("*** WARNING: unexpected ExposureTime numerator");
ExposureTime = r.ToString();
}
}
IExifValue<ushort[]>? isoSpeed;
if (exifs.TryGetValue(ExifTag.ISOSpeedRatings, out isoSpeed)) {
ushort[]? iso = isoSpeed.Value;
if (iso != null && iso.Length >= 1) {
IsoSpeed = $"ISO {iso[0]}";
}
}
// foreach (IExifValue exif in exifs.Values) {
// Console.WriteLine(exif.Tag.ToString() + " " + exif.GetValue().ToString());
// }
}
}
public Texture Texture() {
@ -231,15 +175,6 @@ public class Photo {
}
return texture;
}
public string Description() {
if (Loaded) {
string shootingInfo = $"{FocalLength}, {FNumber} at {ExposureTime}, {IsoSpeed}";
return String.Format("{0,-40} {1,-50} {2}", shootingInfo, $"{CameraModel} {LensModel}", File);
} else {
return String.Format("{0,-90} {1}", "", File);
}
}
}
public class Texture : IDisposable {
@ -358,6 +293,7 @@ public static class Util {
image.Dispose();
return texture;
}
}
public class Game : GameWindow {
@ -499,10 +435,8 @@ public class Game : GameWindow {
// Load textures from JPEGs.
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(@"G:\DCIM\100EOSR6\");
// 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\many-birds\");
for (int i = 0; i < files.Count(); i++) {
string file = files[i];
@ -510,9 +444,7 @@ public class Game : GameWindow {
Photo photo = new Photo(file, TEXTURE_WHITE);
photos.Add(photo);
await Task.Run( () => { photo.Load(); });
if (photos.Count == 100) {
break;
}
Console.WriteLine("file " + i);
}
}
}
@ -562,7 +494,7 @@ public class Game : GameWindow {
}
// Draw status box.
DrawText(activePhoto.Description(), geometry.StatusBox.Min.X + 80, geometry.StatusBox.Min.Y);
DrawText(activePhoto.File, geometry.StatusBox.Min.X + 80, geometry.StatusBox.Min.Y);
if (activePhoto.Loaded) {
DrawText($"{(scale * 100):F1}%", geometry.StatusBox.Min.X, geometry.StatusBox.Min.Y);
}