parse star ratings from canon image metadata
This commit is contained in:
parent
7f375a6446
commit
3a9192b478
31
Program.cs
31
Program.cs
@ -7,9 +7,11 @@ using OpenTK.Windowing.GraphicsLibraryFramework;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
||||
using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SemiColinGames;
|
||||
|
||||
@ -150,6 +152,7 @@ public class Photo {
|
||||
public string FNumber = "<unk>";
|
||||
public string ExposureTime = "<unk>";
|
||||
public string IsoSpeed = "<unk>";
|
||||
public int Rating = 0;
|
||||
|
||||
private Texture texture;
|
||||
private Texture placeholder;
|
||||
@ -163,6 +166,7 @@ public class Photo {
|
||||
|
||||
public async void Load() {
|
||||
image = await Image.LoadAsync<Rgba32>(File);
|
||||
ParseRating(image);
|
||||
ExifProfile? exifs = image.Metadata.ExifProfile;
|
||||
if (exifs != null) {
|
||||
// FIXME: handle Orientation
|
||||
@ -236,6 +240,29 @@ public class Photo {
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseRating(Image image) {
|
||||
XmpProfile? xmp = image.Metadata.XmpProfile;
|
||||
if (xmp == null) {
|
||||
return;
|
||||
}
|
||||
XDocument? doc = xmp.GetDocument();
|
||||
if (doc == null) {
|
||||
return;
|
||||
}
|
||||
XElement? root = doc.Root;
|
||||
if (root == null) {
|
||||
return;
|
||||
}
|
||||
foreach (XElement elt in root.Descendants()) {
|
||||
if (elt.Name == "{http://ns.adobe.com/xap/1.0/}Rating") {
|
||||
int rating;
|
||||
if (int.TryParse(elt.Value, out rating)) {
|
||||
Rating = rating;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Texture Texture() {
|
||||
if (texture == placeholder && image != null) {
|
||||
texture = new Texture(image);
|
||||
@ -512,9 +539,9 @@ public class Game : GameWindow {
|
||||
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
|
||||
|
||||
// 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(@"G:\DCIM\100EOSR6\");
|
||||
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\");
|
||||
|
Loading…
Reference in New Issue
Block a user