Compare commits
2 Commits
56311bc56c
...
6c7dbe5516
Author | SHA1 | Date | |
---|---|---|---|
6c7dbe5516 | |||
4d63f64be6 |
82
Program.cs
82
Program.cs
@ -142,8 +142,15 @@ void main() {
|
|||||||
|
|
||||||
// FIXME: this should probably be IDisposable?
|
// FIXME: this should probably be IDisposable?
|
||||||
public class Photo {
|
public class Photo {
|
||||||
public bool Loaded = false;
|
|
||||||
public string File;
|
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>";
|
||||||
|
|
||||||
private Texture texture;
|
private Texture texture;
|
||||||
private Texture placeholder;
|
private Texture placeholder;
|
||||||
private Image<Rgba32>? image = null;
|
private Image<Rgba32>? image = null;
|
||||||
@ -158,11 +165,60 @@ 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) {
|
||||||
foreach (IExifValue exif in exifs.Values) {
|
// FIXME: handle Orientation
|
||||||
if (exif.Tag.ToString() == "Model") {
|
IExifValue<string>? model;
|
||||||
Console.WriteLine($"{File} {exif.Tag}: {exif.GetValue()}");
|
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}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +231,15 @@ public class Photo {
|
|||||||
}
|
}
|
||||||
return texture;
|
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 {
|
public class Texture : IDisposable {
|
||||||
@ -293,7 +358,6 @@ public static class Util {
|
|||||||
image.Dispose();
|
image.Dispose();
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Game : GameWindow {
|
public class Game : GameWindow {
|
||||||
@ -435,8 +499,10 @@ public class Game : GameWindow {
|
|||||||
// 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];
|
||||||
@ -444,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -494,7 +562,7 @@ public class Game : GameWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw status box.
|
// Draw status box.
|
||||||
DrawText(activePhoto.File, geometry.StatusBox.Min.X + 80, geometry.StatusBox.Min.Y);
|
DrawText(activePhoto.Description(), geometry.StatusBox.Min.X + 80, geometry.StatusBox.Min.Y);
|
||||||
if (activePhoto.Loaded) {
|
if (activePhoto.Loaded) {
|
||||||
DrawText($"{(scale * 100):F1}%", geometry.StatusBox.Min.X, geometry.StatusBox.Min.Y);
|
DrawText($"{(scale * 100):F1}%", geometry.StatusBox.Min.X, geometry.StatusBox.Min.Y);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user