mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-12 13:28:37 +00:00
Improved accuracy of Average
This commit is contained in:
parent
10f0c8c5b7
commit
44ff0bf5b0
@ -9,10 +9,10 @@ public static partial class ReferencePixelHelper
|
|||||||
float count = image.Width * image.Height;
|
float count = image.Width * image.Height;
|
||||||
|
|
||||||
ISum sum = Sum(image);
|
ISum sum = Sum(image);
|
||||||
return new ColorRGBA((byte)(sum.R / count),
|
return new ColorRGBA((byte)MathF.Round(sum.R / count),
|
||||||
(byte)(sum.G / count),
|
(byte)MathF.Round(sum.G / count),
|
||||||
(byte)(sum.B / count),
|
(byte)MathF.Round(sum.B / count),
|
||||||
(byte)(sum.A / count));
|
(byte)MathF.Round(sum.A / count));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T Average<T>(IImage<T> image)
|
public static T Average<T>(IImage<T> image)
|
||||||
@ -21,10 +21,10 @@ public static partial class ReferencePixelHelper
|
|||||||
float count = image.Width * image.Height;
|
float count = image.Width * image.Height;
|
||||||
|
|
||||||
ISum sum = Sum(image);
|
ISum sum = Sum(image);
|
||||||
return (T)T.Create((byte)(sum.R / count),
|
return (T)T.Create((byte)MathF.Round(sum.R / count),
|
||||||
(byte)(sum.G / count),
|
(byte)MathF.Round(sum.G / count),
|
||||||
(byte)(sum.B / count),
|
(byte)MathF.Round(sum.B / count),
|
||||||
(byte)(sum.A / count));
|
(byte)MathF.Round(sum.A / count));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T Average<T>(RefImage<T> image)
|
public static T Average<T>(RefImage<T> image)
|
||||||
@ -33,10 +33,10 @@ public static partial class ReferencePixelHelper
|
|||||||
float count = image.Width * image.Height;
|
float count = image.Width * image.Height;
|
||||||
|
|
||||||
ISum sum = Sum(image);
|
ISum sum = Sum(image);
|
||||||
return (T)T.Create((byte)(sum.R / count),
|
return (T)T.Create((byte)MathF.Round(sum.R / count),
|
||||||
(byte)(sum.G / count),
|
(byte)MathF.Round(sum.G / count),
|
||||||
(byte)(sum.B / count),
|
(byte)MathF.Round(sum.B / count),
|
||||||
(byte)(sum.A / count));
|
(byte)MathF.Round(sum.A / count));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T Average<T>(Span<T> colors)
|
public static T Average<T>(Span<T> colors)
|
||||||
@ -45,10 +45,10 @@ public static partial class ReferencePixelHelper
|
|||||||
float count = colors.Length;
|
float count = colors.Length;
|
||||||
|
|
||||||
ISum sum = Sum(colors);
|
ISum sum = Sum(colors);
|
||||||
return (T)T.Create((byte)(sum.R / count),
|
return (T)T.Create((byte)MathF.Round(sum.R / count),
|
||||||
(byte)(sum.G / count),
|
(byte)MathF.Round(sum.G / count),
|
||||||
(byte)(sum.B / count),
|
(byte)MathF.Round(sum.B / count),
|
||||||
(byte)(sum.A / count));
|
(byte)MathF.Round(sum.A / count));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T Average<T>(ReadOnlySpan<T> colors)
|
public static T Average<T>(ReadOnlySpan<T> colors)
|
||||||
@ -57,10 +57,10 @@ public static partial class ReferencePixelHelper
|
|||||||
float count = colors.Length;
|
float count = colors.Length;
|
||||||
|
|
||||||
ISum sum = Sum(colors);
|
ISum sum = Sum(colors);
|
||||||
return (T)T.Create((byte)(sum.R / count),
|
return (T)T.Create((byte)MathF.Round(sum.R / count),
|
||||||
(byte)(sum.G / count),
|
(byte)MathF.Round(sum.G / count),
|
||||||
(byte)(sum.B / count),
|
(byte)MathF.Round(sum.B / count),
|
||||||
(byte)(sum.A / count));
|
(byte)MathF.Round(sum.A / count));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -82,9 +82,9 @@ public static partial class PixelHelper
|
|||||||
Generic4LongData sum = Sum(data);
|
Generic4LongData sum = Sum(data);
|
||||||
|
|
||||||
float count = data.Length;
|
float count = data.Length;
|
||||||
return new Generic3ByteData((byte)(sum.L1 / count),
|
return new Generic3ByteData((byte)MathF.Round(sum.L1 / count),
|
||||||
(byte)(sum.L2 / count),
|
(byte)MathF.Round(sum.L2 / count),
|
||||||
(byte)(sum.L3 / count));
|
(byte)MathF.Round(sum.L3 / count));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Generic4ByteData Average(ReadOnlySpan<Generic4ByteData> data)
|
private static Generic4ByteData Average(ReadOnlySpan<Generic4ByteData> data)
|
||||||
@ -96,10 +96,10 @@ public static partial class PixelHelper
|
|||||||
Generic4LongData sum = Sum(data);
|
Generic4LongData sum = Sum(data);
|
||||||
|
|
||||||
float count = data.Length;
|
float count = data.Length;
|
||||||
return new Generic4ByteData((byte)(sum.L1 / count),
|
return new Generic4ByteData((byte)MathF.Round(sum.L1 / count),
|
||||||
(byte)(sum.L2 / count),
|
(byte)MathF.Round(sum.L2 / count),
|
||||||
(byte)(sum.L3 / count),
|
(byte)MathF.Round(sum.L3 / count),
|
||||||
(byte)(sum.L4 / count));
|
(byte)MathF.Round(sum.L4 / count));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user