/// <summary> /// Asserts that two images are equal. /// </summary> /// <typeparam name="TPixel">The type of image pixels to analyze.</typeparam> /// <param name="expected">The reference image.</param> /// <param name="actual">The expected image.</param> /// <param name="threshold">The allowed difference threshold for the normalized delta.</param> public static void AssertEqual <TPixel>(Image <TPixel> expected, Image <TPixel> actual, float threshold) where TPixel : unmanaged, IPixel <TPixel> { if (expected.Size() != actual.Size()) { Assert.Fail($"The input images have different sizes: {expected.Size()} and {actual.Size()}"); } if (expected.Frames.Count != actual.Frames.Count || expected.Frames.Count != 1 || actual.Frames.Count != 1) { Assert.Fail("The two input images must have 1 frame each"); } int width = actual.Width; float totalDifference = 0F; var differences = new List <PixelDifference>(20); Span <ImageSharpRgba32> aBuffer = new ImageSharpRgba32[actual.Width]; Span <ImageSharpRgba32> bBuffer = new ImageSharpRgba32[actual.Width]; for (int y = 0; y < actual.Height; y++) { Memory <TPixel> aMemory = expected.DangerousGetPixelRowMemory(y); Memory <TPixel> bMemory = actual.DangerousGetPixelRowMemory(y); PixelOperations <TPixel> .Instance.ToRgba32(actual.GetConfiguration(), aMemory.Span, aBuffer); PixelOperations <TPixel> .Instance.ToRgba32(actual.GetConfiguration(), bMemory.Span, bBuffer); for (int x = 0; x < width; x++) {
public PixelDifference(Point position, ImageSharpRgba32 expected, ImageSharpRgba32 actual) { this.Position = position; this.RedDifference = actual.R - expected.R; this.GreenDifference = actual.G - expected.G; this.BlueDifference = actual.B - expected.B; this.AlphaDifference = actual.A - expected.A; }
static int GetManhattanDistanceInRgbaSpace(ref ImageSharpRgba32 a, ref ImageSharpRgba32 b) {
public void ToRgba32(ref Rgba32 dest) { dest.FromScaledVector4(this.ToScaledVector4()); }
public void PackFromRgba32(Rgba32 source) { this.PackFromVector4(source.ToVector4()); }
public void FromRgba32(Rgba32 source) => this.FromScaledVector4(source.ToScaledVector4());
public void FromRgba32(Rgba32 source) => this.FromVector4(source.ToVector4());
public void FromRgba32(Rgba32 source) => this = source.Bgr;
public void PackFromRgba32(Rgba32 source) { this.backingVector = source.ToVector4(); }
public void PackFromRgba32(Rgba32 source) { this.PackedValue = Pack(source.R, source.G, source.B, source.A); }
public void PackFromRgba32(Rgba32 source) { this = source.Bgr; }
public void FromRgba32(Rgba32 source) { this.R = ImageMaths.UpscaleFrom8BitTo16Bit(source.R); this.G = ImageMaths.UpscaleFrom8BitTo16Bit(source.G); this.B = ImageMaths.UpscaleFrom8BitTo16Bit(source.B); }