public void InsertFrame_clones_sourceFrame() { using var otherFrame = new ImageFrame <Rgba32>(Configuration.Default, 10, 10); using ImageFrame <Rgba32> addedFrame = this.Image.Frames.InsertFrame(0, otherFrame); Assert.True(otherFrame.DangerousTryGetSinglePixelMemory(out Memory <Rgba32> otherFrameMem)); addedFrame.ComparePixelBufferTo(otherFrameMem.Span); Assert.NotEqual(otherFrame, addedFrame); }
/// <summary> /// All pixels in the frame should be exactly equal to 'expectedPixel'. /// </summary> /// <typeparam name="TPixel">The pixel type of the image.</typeparam> /// <returns>The image.</returns> public static ImageFrame <TPixel> ComparePixelBufferTo <TPixel>(this ImageFrame <TPixel> imageFrame, TPixel expectedPixel) where TPixel : unmanaged, IPixel <TPixel> { Assert.True(imageFrame.DangerousTryGetSinglePixelMemory(out Memory <TPixel> actualPixelMem)); Span <TPixel> actualPixels = actualPixelMem.Span; for (int i = 0; i < actualPixels.Length; i++) { Assert.True(expectedPixel.Equals(actualPixels[i]), $"Pixels are different on position {i}!"); } return(imageFrame); }
public static ImageFrame <TPixel> ComparePixelBufferTo <TPixel>( this ImageFrame <TPixel> image, Span <TPixel> expectedPixels) where TPixel : unmanaged, IPixel <TPixel> { Assert.True(image.DangerousTryGetSinglePixelMemory(out Memory <TPixel> actualMem)); Span <TPixel> actual = actualMem.Span; Assert.True(expectedPixels.Length == actual.Length, "Buffer sizes are not equal!"); for (int i = 0; i < expectedPixels.Length; i++) { Assert.True(expectedPixels[i].Equals(actual[i]), $"Pixels are different on position {i}!"); } return(image); }