pull ParseExif() into a standalone function
This commit is contained in:
parent
e6d3f197ea
commit
9796827f96
73
Program.cs
73
Program.cs
@ -154,6 +154,7 @@ public class Photo {
|
||||
public string ExposureTime = "<unk>";
|
||||
public string IsoSpeed = "<unk>";
|
||||
public int Rating = 0;
|
||||
public ushort Orientation = 1;
|
||||
|
||||
private Texture texture;
|
||||
private Texture placeholder;
|
||||
@ -170,16 +171,47 @@ public class Photo {
|
||||
// edit the image due to rotation (etc) and don't want to try generating
|
||||
// a texture for it until that's already happened.
|
||||
Image<Rgba32> tmpImage = await Image.LoadAsync<Rgba32>(File);
|
||||
ParseExif(tmpImage.Metadata.ExifProfile);
|
||||
TryParseRating(tmpImage.Metadata.XmpProfile, out Rating);
|
||||
ExifProfile? exifs = tmpImage.Metadata.ExifProfile;
|
||||
if (exifs != null) {
|
||||
Util.RotateImageFromExif(tmpImage, Orientation);
|
||||
image = tmpImage;
|
||||
}
|
||||
|
||||
private bool TryParseRating(XmpProfile? xmp, out int rating) {
|
||||
rating = 0;
|
||||
if (xmp == null) {
|
||||
return false;
|
||||
}
|
||||
XDocument? doc = xmp.GetDocument();
|
||||
if (doc == null) {
|
||||
return false;
|
||||
}
|
||||
XElement? root = doc.Root;
|
||||
if (root == null) {
|
||||
return false;
|
||||
}
|
||||
foreach (XElement elt in root.Descendants()) {
|
||||
if (elt.Name == "{http://ns.adobe.com/xap/1.0/}Rating") {
|
||||
if (int.TryParse(elt.Value, out rating)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ParseExif(ExifProfile? exifs) {
|
||||
if (exifs == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: when we write out images, we'll want to correct the Exif Orientation to 1.
|
||||
// FIXME: handle date shot / edited (and sort by shot date?)
|
||||
// FIXME: PixelXDimension & PixelYDimension hold the image geometry in Exif.
|
||||
|
||||
IExifValue<ushort>? orientation;
|
||||
if (exifs.TryGetValue(ExifTag.Orientation, out orientation)) {
|
||||
Util.RotateImageFromExif(tmpImage, orientation.Value);
|
||||
Orientation = orientation.Value;
|
||||
}
|
||||
|
||||
IExifValue<string>? model;
|
||||
@ -247,31 +279,6 @@ public class Photo {
|
||||
// foreach (IExifValue exif in exifs.Values) {
|
||||
// Console.WriteLine(exif.Tag.ToString() + " " + exif.GetValue().ToString());
|
||||
// }
|
||||
image = tmpImage;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryParseRating(XmpProfile? xmp, out int rating) {
|
||||
rating = 0;
|
||||
if (xmp == null) {
|
||||
return false;
|
||||
}
|
||||
XDocument? doc = xmp.GetDocument();
|
||||
if (doc == null) {
|
||||
return false;
|
||||
}
|
||||
XElement? root = doc.Root;
|
||||
if (root == null) {
|
||||
return false;
|
||||
}
|
||||
foreach (XElement elt in root.Descendants()) {
|
||||
if (elt.Name == "{http://ns.adobe.com/xap/1.0/}Rating") {
|
||||
if (int.TryParse(elt.Value, out rating)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Texture Texture() {
|
||||
@ -578,6 +585,16 @@ public class Game : GameWindow {
|
||||
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
|
||||
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
|
||||
|
||||
Console.WriteLine(DateTime.Now.ToString());
|
||||
for (int i = 0; i < files.Count(); i++) {
|
||||
string file = files[i];
|
||||
if (file.ToLower().EndsWith(".jpg")) {
|
||||
ImageInfo info = Image.Identify(file);
|
||||
Console.WriteLine(file + " " + i + " " + info.Size);
|
||||
}
|
||||
}
|
||||
Console.WriteLine(DateTime.Now.ToString());
|
||||
|
||||
for (int i = 0; i < files.Count(); i++) {
|
||||
string file = files[i];
|
||||
if (file.ToLower().EndsWith(".jpg")) {
|
||||
|
Loading…
Reference in New Issue
Block a user