Tests project and Resize bug
This commit is contained in:
@ -20,21 +20,31 @@ public class C_Resize
|
||||
public List<string> AngleBracketCollection { get; }
|
||||
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly int _TempResolutionWidth;
|
||||
private readonly int _TempResolutionHeight;
|
||||
private readonly string[] _ValidResolutions;
|
||||
private readonly ASCIIEncoding _ASCIIEncoding;
|
||||
private readonly bool _OverrideForResizeImages;
|
||||
private readonly ImageCodecInfo _ImageCodecInfo;
|
||||
private readonly ConstructorInfo _ConstructorInfo;
|
||||
private readonly int _OutputResolutionWidthIndex;
|
||||
private readonly bool _PropertiesChangedForResize;
|
||||
private readonly ConstructorInfo _ConstructorInfo;
|
||||
private readonly int _OutputResolutionHeightIndex;
|
||||
private readonly EncoderParameters _EncoderParameters;
|
||||
private readonly int _OutputResolutionOrientationIndex;
|
||||
private readonly bool _ForceResizeLastWriteTimeToCreationTime;
|
||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||
|
||||
public C_Resize(bool forceResizeLastWriteTimeToCreationTime, bool overrideForResizeImages, bool propertiesChangedForResize, string[] validResolutions, ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters)
|
||||
{
|
||||
_TempResolutionWidth = 3;
|
||||
_TempResolutionHeight = 4;
|
||||
_OutputResolutionWidthIndex = 0;
|
||||
_ImageCodecInfo = imageCodecInfo;
|
||||
_OutputResolutionHeightIndex = 1;
|
||||
_ASCIIEncoding = new ASCIIEncoding();
|
||||
_ValidResolutions = validResolutions;
|
||||
_OutputResolutionOrientationIndex = 2;
|
||||
_EncoderParameters = encoderParameters;
|
||||
_Log = Serilog.Log.ForContext<C_Resize>();
|
||||
AngleBracketCollection = new List<string>();
|
||||
@ -93,10 +103,19 @@ public class C_Resize
|
||||
{
|
||||
bool hasId = false;
|
||||
int id = (int)IExif.Tags.DateTimeDigitized;
|
||||
int imageWidth = (int)IExif.Tags.ImageWidth;
|
||||
int imageLength = (int)IExif.Tags.ImageLength;
|
||||
int orientation = (int)IExif.Tags.Orientation;
|
||||
foreach (PropertyItem propertyItem in propertyItems)
|
||||
{
|
||||
if (propertyItem.Id == id)
|
||||
hasId = true;
|
||||
else if (propertyItem.Id == imageWidth)
|
||||
continue;
|
||||
else if (propertyItem.Id == imageLength)
|
||||
continue;
|
||||
else if (propertyItem.Id == orientation)
|
||||
continue;
|
||||
bitmap.SetPropertyItem(propertyItem);
|
||||
}
|
||||
if (!hasId)
|
||||
@ -114,11 +133,11 @@ public class C_Resize
|
||||
{
|
||||
byte[] results;
|
||||
Bitmap bitmap;
|
||||
int outputResolutionWidth = resize[0];
|
||||
int outputResolutionHeight = resize[1];
|
||||
int outputResolutionOrientation = resize[2];
|
||||
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
||||
using Bitmap temp = new(subFile, useIcm: false);
|
||||
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
||||
PropertyItem[] propertyItems = temp.PropertyItems;
|
||||
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
|
||||
bitmap = new(temp, outputResolutionWidth, outputResolutionHeight);
|
||||
switch (outputResolutionOrientation) // exif 274
|
||||
{
|
||||
@ -166,13 +185,13 @@ public class C_Resize
|
||||
{
|
||||
byte[] results;
|
||||
Bitmap bitmap;
|
||||
int tempResolutionWidth = resize[3];
|
||||
int tempResolutionHeight = resize[4];
|
||||
int outputResolutionWidth = resize[0];
|
||||
int outputResolutionHeight = resize[1];
|
||||
int outputResolutionOrientation = resize[2];
|
||||
using Bitmap temp = new(subFile, useIcm: false);
|
||||
PropertyItem[] propertyItems = temp.PropertyItems;
|
||||
int tempResolutionWidth = resize[_TempResolutionWidth];
|
||||
int tempResolutionHeight = resize[_TempResolutionHeight];
|
||||
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
||||
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
||||
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
|
||||
bitmap = new(temp, tempResolutionWidth, tempResolutionHeight);
|
||||
switch (outputResolutionOrientation) // exif 274
|
||||
{
|
||||
@ -271,9 +290,9 @@ public class C_Resize
|
||||
if (!imageResizes.ContainsKey(outputResolution))
|
||||
throw new Exception();
|
||||
int[] resize = imageResizes[outputResolution];
|
||||
int outputResolutionWidth = resize[0];
|
||||
int outputResolutionHeight = resize[1];
|
||||
int outputResolutionOrientation = resize[2];
|
||||
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
||||
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
||||
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
|
||||
results = SaveResizedSubfile(subFile, property, resize, fileInfo: null);
|
||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||
return results;
|
||||
@ -295,11 +314,11 @@ public class C_Resize
|
||||
}
|
||||
}
|
||||
int[] resize = imageResizes[outputResolution];
|
||||
int outputResolutionWidth = resize[0];
|
||||
int outputResolutionHeight = resize[1];
|
||||
int outputResolutionOrientation = resize[2];
|
||||
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
||||
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
||||
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
|
||||
int[] originalCollection = imageResizes[original];
|
||||
if (outputResolutionWidth == originalCollection[0] && outputResolutionHeight == originalCollection[1] && outputResolutionOrientation == originalCollection[2])
|
||||
if (outputResolutionWidth == originalCollection[_OutputResolutionWidthIndex] && outputResolutionHeight == originalCollection[_OutputResolutionHeightIndex] && outputResolutionOrientation == originalCollection[_OutputResolutionOrientationIndex])
|
||||
{
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
@ -349,7 +368,7 @@ public class C_Resize
|
||||
return result;
|
||||
}
|
||||
|
||||
private Dictionary<string, int[]> GetImageResizes(List<KeyValuePair<string, string>> metadataCollection, A_Property property, string original)
|
||||
private Dictionary<string, int[]> GetImageResizes(A_Property property, List<KeyValuePair<string, string>> metadataCollection, string original)
|
||||
{
|
||||
Dictionary<string, int[]> results = new();
|
||||
int[] desired;
|
||||
@ -364,49 +383,8 @@ public class C_Resize
|
||||
orientation = propertyOrientation;
|
||||
else
|
||||
orientation = GetOrientation(metadataCollection);
|
||||
switch (orientation) // exif 274
|
||||
{
|
||||
case 0:
|
||||
checkWidth = property.Width.Value;
|
||||
checkHeight = property.Height.Value;
|
||||
break;
|
||||
case 1:
|
||||
checkWidth = property.Width.Value;
|
||||
checkHeight = property.Height.Value;
|
||||
break; // 1 = Horizontal (normal)
|
||||
case 2:
|
||||
checkWidth = property.Width.Value;
|
||||
checkHeight = property.Height.Value;
|
||||
break; // 2 = Mirror horizontal
|
||||
case 3:
|
||||
checkWidth = property.Width.Value;
|
||||
checkHeight = property.Height.Value;
|
||||
break; // 3 = Rotate 180
|
||||
case 4:
|
||||
checkWidth = property.Width.Value;
|
||||
checkHeight = property.Height.Value;
|
||||
break; // 4 = Mirror vertical
|
||||
case 5:
|
||||
checkWidth = property.Height.Value;
|
||||
checkHeight = property.Width.Value;
|
||||
break; // 5 = Mirror horizontal and rotate 270 CW
|
||||
case 6:
|
||||
checkWidth = property.Height.Value;
|
||||
checkHeight = property.Width.Value;
|
||||
break; // 6 = Rotate 90 CW
|
||||
case 7:
|
||||
checkWidth = property.Height.Value;
|
||||
checkHeight = property.Width.Value;
|
||||
break; // 7 = Mirror horizontal and rotate 90 CW
|
||||
case 8:
|
||||
checkWidth = property.Height.Value;
|
||||
checkHeight = property.Width.Value;
|
||||
break; // 8 = Rotate 270 CW
|
||||
default:
|
||||
checkWidth = property.Width.Value;
|
||||
checkHeight = property.Height.Value;
|
||||
break;
|
||||
}
|
||||
checkWidth = property.Width.Value;
|
||||
checkHeight = property.Height.Value;
|
||||
results.Add(original, new int[] { checkWidth, checkHeight, orientation });
|
||||
foreach (string validResolution in _ValidResolutions)
|
||||
{
|
||||
@ -468,6 +446,8 @@ public class C_Resize
|
||||
results = new();
|
||||
else if (!fileInfo.Exists)
|
||||
results = new();
|
||||
else if (!fileInfo.FullName.EndsWith(".json") && !fileInfo.FullName.EndsWith(".old"))
|
||||
throw new ArgumentException("must be a *.json file");
|
||||
else if (dateTimes.Any() && dateTimes.Max() > fileInfo.LastWriteTime)
|
||||
results = new();
|
||||
else
|
||||
@ -482,7 +462,7 @@ public class C_Resize
|
||||
results = keyValuePairs;
|
||||
if ((from l in results where l.Value[0] == l.Value[1] select true).Any())
|
||||
{
|
||||
results = GetImageResizes(metadataCollection, property, original);
|
||||
results = GetImageResizes(property, metadataCollection, original);
|
||||
if (!(from l in results where l.Value[0] == l.Value[1] select true).Any())
|
||||
throw new Exception("Was square!");
|
||||
}
|
||||
@ -496,7 +476,7 @@ public class C_Resize
|
||||
}
|
||||
if (results is null || !results.Any())
|
||||
{
|
||||
results = GetImageResizes(metadataCollection, property, original);
|
||||
results = GetImageResizes(property, metadataCollection, original);
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||
if (Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, compareBeforeWrite: true))
|
||||
{
|
||||
|
Reference in New Issue
Block a user