LocationContainer
This commit is contained in:
@ -140,6 +140,12 @@ public class D_Face
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
private static (int width, int height) Get(string file)
|
||||
{
|
||||
using Bitmap source = new(file);
|
||||
return new(source.Width, source.Height);
|
||||
}
|
||||
|
||||
private PropertyItem GetPropertyItem(int id, string value)
|
||||
{
|
||||
PropertyItem result = (PropertyItem)_ConstructorInfo.Invoke(null);
|
||||
@ -291,12 +297,60 @@ public class D_Face
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
||||
public List<Shared.Models.Face> GetFaces(string dResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Shared.Models.Property property, MappingFromItem mappingFromItem, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, List<MappingFromPhotoPrism>? mappingFromPhotoPrismCollection)
|
||||
private static List<LocationContainer<MetadataExtractor.Directory>> GetCollection(int outputResolutionWidth, int outputResolutionHeight, List<LocationContainer<MetadataExtractor.Directory>> collection, List<Shared.Models.Face> faces)
|
||||
{
|
||||
List<LocationContainer<MetadataExtractor.Directory>> results = new();
|
||||
string? json;
|
||||
int width, height;
|
||||
Location? location;
|
||||
Rectangle? rectangle;
|
||||
List<int> skip = new();
|
||||
OutputResolution? outputResolution = null;
|
||||
foreach (Shared.Models.Face face in faces)
|
||||
{
|
||||
if (face.Location is null || face.OutputResolution is null)
|
||||
continue;
|
||||
skip.Add(Shared.Models.Stateless.Methods.ILocation.GetNormalizedRectangle(face.Location, ILocation.Digits, face.OutputResolution));
|
||||
}
|
||||
foreach (LocationContainer<MetadataExtractor.Directory> locationContainer in collection)
|
||||
{
|
||||
if (locationContainer.Directories is null)
|
||||
continue;
|
||||
if (skip.Contains(locationContainer.NormalizedRectangle))
|
||||
continue;
|
||||
foreach (Shared.Models.Face face in faces)
|
||||
{
|
||||
if (face.Location is not null && face.OutputResolution is not null)
|
||||
continue;
|
||||
json = Metadata.Models.Stateless.IMetadata.GetOutputResolution(locationContainer.Directories);
|
||||
if (json is not null)
|
||||
{
|
||||
outputResolution = JsonSerializer.Deserialize<OutputResolution>(json);
|
||||
if (outputResolution is not null && (outputResolution.Width != outputResolutionWidth || outputResolution.Height != outputResolutionHeight))
|
||||
continue;
|
||||
}
|
||||
(width, height) = Get(locationContainer.File);
|
||||
rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(height, ILocation.Digits, ILocation.Factor, locationContainer.NormalizedRectangle, outputResolutionHeight, outputResolutionWidth, width);
|
||||
if (rectangle is null)
|
||||
continue;
|
||||
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(outputResolutionHeight, rectangle.Value, outputResolutionWidth);
|
||||
if (location is null)
|
||||
continue;
|
||||
if (!results.Any(l => l.NormalizedRectangle == locationContainer.NormalizedRectangle))
|
||||
results.Add(new(locationContainer.FromDistanceContent, locationContainer.File, locationContainer.NormalizedRectangle, locationContainer.Directories, rectangle.Value, location));
|
||||
}
|
||||
}
|
||||
if (results.Any())
|
||||
outputResolution = null;
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<Shared.Models.Face> GetFaces(string dResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Shared.Models.Property property, MappingFromItem mappingFromItem, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, List<LocationContainer<MetadataExtractor.Directory>>? collection, List<MappingFromPhotoPrism>? mappingFromPhotoPrismCollection)
|
||||
{
|
||||
List<Shared.Models.Face>? results;
|
||||
if (string.IsNullOrEmpty(dResultsFullGroupDirectory))
|
||||
throw new NullReferenceException(nameof(dResultsFullGroupDirectory));
|
||||
string json;
|
||||
string? json;
|
||||
List<Location>? locations;
|
||||
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
@ -334,10 +388,15 @@ public class D_Face
|
||||
parseExceptions.Add(nameof(D_Face));
|
||||
}
|
||||
}
|
||||
if (mappingFromPhotoPrismCollection is null || results is null)
|
||||
locations = null;
|
||||
List<LocationContainer<MetadataExtractor.Directory>> containers;
|
||||
if (results is null || collection is null)
|
||||
containers = new();
|
||||
else
|
||||
locations = Shared.Models.Stateless.Methods.ILocation.GetLocations(mappingFromPhotoPrismCollection, results);
|
||||
containers = GetCollection(outputResolutionWidth, outputResolutionHeight, collection, results);
|
||||
if (mappingFromPhotoPrismCollection is null || results is null)
|
||||
locations = (from l in containers where l is not null select l.Location).ToList();
|
||||
else
|
||||
locations = Shared.Models.Stateless.Methods.ILocation.GetLocations(mappingFromPhotoPrismCollection, results, containers);
|
||||
if (results is null || (locations is not null && locations.Any()))
|
||||
{
|
||||
results = GetFaces(property, mappingFromItem, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, locations);
|
||||
|
Reference in New Issue
Block a user