Exif Helper

This commit is contained in:
2024-10-20 18:56:57 -07:00
parent 19326df4c6
commit 80ca8f98eb
29 changed files with 1287 additions and 10 deletions

View File

@ -0,0 +1,11 @@
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models.Face;
public record FaceEncoding(double[] RawEncoding, int Size);
[JsonSourceGenerationOptions(WriteIndented = false)]
[JsonSerializable(typeof(FaceEncoding))]
public partial class FaceEncodingGenerationContext : JsonSerializerContext
{
}

33
Models/Face/FaceFile.cs Normal file
View File

@ -0,0 +1,33 @@
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models.Face;
public record FaceFile(int? AreaPermyriad,
int? ConfidencePercent,
string? DMS,
DateTime DateTime,
FaceEncoding? FaceEncoding,
Dictionary<FacePart, FacePoint[]>? FaceParts,
Location? Location,
string? Maker,
MappingFromPerson? MappingFromPerson,
string? Model,
OutputResolution? OutputResolution);
[JsonSourceGenerationOptions(WriteIndented = false)]
[JsonSerializable(typeof(FaceFile))]
public partial class FaceFileGenerationContext : JsonSerializerContext
{
}
[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(FaceFile[]))]
public partial class FaceFileCollectionGenerationContext : JsonSerializerContext
{
}
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(FaceFile[]))]
public partial class FaceFileCollectionWriteIndentedGenerationContext : JsonSerializerContext
{
}

54
Models/Face/FacePart.cs Normal file
View File

@ -0,0 +1,54 @@
namespace File_Folder_Helper.Models.Face;
/// <summary>
/// Specifies the part of face.
/// </summary>
public enum FacePart
{
/// <summary>
/// Specifies the chin.
/// </summary>
Chin = 0,
/// <summary>
/// Specifies the left eyebrow.
/// </summary>
LeftEyebrow = 17,
/// <summary>
/// Specifies the right eyebrow.
/// </summary>
RightEyebrow = 22,
/// <summary>
/// Specifies the nose bridge.
/// </summary>
NoseBridge = 27,
/// <summary>
/// Specifies the nose tip.
/// </summary>
NoseTip = 31,
/// <summary>
/// Specifies the left eye.
/// </summary>
LeftEye = 36,
/// <summary>
/// Specifies the right eye.
/// </summary>
RightEye = 42,
/// <summary>
/// Specifies the top lip.
/// </summary>
TopLip = 48,
/// <summary>
/// Specifies the bottom lip.
/// </summary>
BottomLip = 55
}

39
Models/Face/FacePoint.cs Normal file
View File

@ -0,0 +1,39 @@
using System.Drawing;
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models.Face;
[method: JsonConstructor]
public class FacePoint(int index, int x, int y)
{
public int Index { get; } = index;
public int X { get; } = x;
public int Y { get; } = y;
private readonly Point _Point = new(x, y);
public override bool Equals(object? obj) => obj is FacePoint point && Equals(point);
#pragma warning disable IDE0070
public override int GetHashCode()
#pragma warning restore IDE0070
{
int hashCode = 1861411795;
hashCode = (hashCode * -1521134295) + _Point.GetHashCode();
hashCode = (hashCode * -1521134295) + Index.GetHashCode();
return hashCode;
}
public bool Equals(FacePoint? facePoint)
{
return facePoint is not null
&& X == facePoint.X
&& Y == facePoint.Y
&& Index == facePoint.Index;
}
public static bool operator ==(FacePoint point1, FacePoint point2) => point1.Equals(point2);
public static bool operator !=(FacePoint point1, FacePoint point2) => !(point1 == point2);
}

42
Models/Face/Location.cs Normal file
View File

@ -0,0 +1,42 @@
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models.Face;
[method: JsonConstructor]
public class Location(int bottom, double confidence, int left, int right, int top) : IEquatable<Location>
{
public int Bottom { init; get; } = bottom;
public double Confidence { init; get; } = confidence;
public int Left { init; get; } = left;
public int Right { init; get; } = right;
public int Top { init; get; } = top;
public override bool Equals(object? obj) => Equals(obj as Location);
#pragma warning disable IDE0070
public override int GetHashCode()
#pragma warning restore IDE0070
{
int hashCode = -773114317;
hashCode = (hashCode * -1521134295) + Bottom.GetHashCode();
hashCode = (hashCode * -1521134295) + Left.GetHashCode();
hashCode = (hashCode * -1521134295) + Right.GetHashCode();
hashCode = (hashCode * -1521134295) + Top.GetHashCode();
return hashCode;
}
public bool Equals(Location? location)
{
return location is not null
&& Bottom == location.Bottom
&& Left == location.Left
&& Right == location.Right
&& Top == location.Top;
}
public static bool operator ==(Location location1, Location location2) => EqualityComparer<Location>.Default.Equals(location1, location2);
public static bool operator !=(Location location1, Location location2) => !(location1 == location2);
}

View File

@ -0,0 +1,24 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Models.Face;
public record MappingFromPerson(int? ApproximateYears,
string DisplayDirectoryName,
long PersonKey,
string SegmentB)
{
public override string ToString()
{
string result = JsonSerializer.Serialize(this, MappingFromPersonGenerationContext.Default.MappingFromPerson);
return result;
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(MappingFromPerson))]
public partial class MappingFromPersonGenerationContext : JsonSerializerContext
{
}

View File

@ -0,0 +1,5 @@
namespace File_Folder_Helper.Models.Face;
public record OutputResolution(int Height,
int Orientation,
int Width);