Added additional tests and some small fixes and improvements

This commit is contained in:
DarthAffe committed 2024-07-18 23:09:49 +02:00
1 parent e1738845ea
commit c6ac54a936
24 files changed
+1503 -187

No files matched your search

+24
View File
@@ -15,6 +15,18 @@ public static partial class ReferencePixelHelper
(byte)(sum.A / count));
}
public static T Average<T>(IImage<T> image)
where T : struct, IColor
{
float count = image.Width * image.Height;
ISum sum = Sum(image);
return (T)T.Create((byte)(sum.R / count),
(byte)(sum.G / count),
(byte)(sum.B / count),
(byte)(sum.A / count));
}
public static T Average<T>(RefImage<T> image)
where T : struct, IColor
{
@@ -27,6 +39,18 @@ public static partial class ReferencePixelHelper
(byte)(sum.A / count));
}
public static T Average<T>(Span<T> colors)
where T : struct, IColor
{
float count = colors.Length;
ISum sum = Sum(colors);
return (T)T.Create((byte)(sum.R / count),
(byte)(sum.G / count),
(byte)(sum.B / count),
(byte)(sum.A / count));
}
public static T Average<T>(ReadOnlySpan<T> colors)
where T : struct, IColor
{
+22
View File
@@ -47,6 +47,28 @@ public static partial class ReferencePixelHelper
return new MinMaxRGBA(minR, maxR, minG, maxG, minB, maxB, minA, maxA);
}
public static IMinMax MinMax<T>(Span<T> colors)
where T : struct, IColor
{
byte minR = byte.MaxValue, minG = byte.MaxValue, minB = byte.MaxValue, minA = byte.MaxValue;
byte maxR = byte.MinValue, maxG = byte.MinValue, maxB = byte.MinValue, maxA = byte.MinValue;
foreach (T color in colors)
{
minR = Math.Min(minR, color.R);
minG = Math.Min(minG, color.G);
minB = Math.Min(minB, color.B);
minA = Math.Min(minA, color.A);
maxR = Math.Max(maxR, color.R);
maxG = Math.Max(maxG, color.G);
maxB = Math.Max(maxB, color.B);
maxA = Math.Max(maxA, color.A);
}
return new MinMaxRGBA(minR, maxR, minG, maxG, minB, maxB, minA, maxA);
}
public static IMinMax MinMax<T>(ReadOnlySpan<T> colors)
where T : struct, IColor
{
+16
View File
@@ -35,6 +35,22 @@ public static partial class ReferencePixelHelper
return new SumRGBA(sumR, sumG, sumB, sumA);
}
public static ISum Sum<T>(Span<T> colors)
where T : struct, IColor
{
long sumR = 0, sumG = 0, sumB = 0, sumA = 0;
foreach (T color in colors)
{
sumR += color.R;
sumG += color.G;
sumB += color.B;
sumA += color.A;
}
return new SumRGBA(sumR, sumG, sumB, sumA);
}
public static ISum Sum<T>(ReadOnlySpan<T> colors)
where T : struct, IColor
{