private void AllPixelsShouldBeEqualTo(Surface surface, Color color) { var pixels = new ColorARGB8888[surface.PixelCount]; surface.ReadPixels(ref pixels); AllPixelsShouldBeEqualTo(pixels, color); }
public void ShouldBlitInSpecifiedRectangles() { var color = Color.Red; var source = Surface.Create(2, 2); var destination = Surface.Create(10, 10); var expected = new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }.Select(v => v > 0 ? color : new Color()) .Select(c => new ColorARGB8888(c)); source.Fill(color, new Rectangle(0, 0, 1, 1)); source.BlitTo(destination, srcRect: new Rectangle(0, 0, 1, 1), dstRect: new Rectangle(2, 1, 5, 4)); var actual = new ColorARGB8888[destination.PixelCount]; destination.ReadPixels(ref actual); actual.Should().BeEquivalentTo(expected); source.Dispose(); destination.Dispose(); }
public void ShouldFillSpecifiedRectangles() { var surface = Surface.Create(10, 10); var expected = new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }.Select(v => v > 0 ? TestColor : new Color()) .Select(c => new ColorARGB8888(c)); surface.Fill(TestColor, new Rectangle(2, 1, 5, 4), new Rectangle(3, 4, 5, 3)); var actual = new ColorARGB8888[expected.Count()]; surface.ReadPixels(ref actual); actual.Should().BeEquivalentTo(expected); surface.Dispose(); }
public void ShouldConvertPixels() { var width = 10; var height = 10; var count = width * height; var stride = width * 4; // 4 bytes per pixel var before = Enumerable.Repeat <ColorRGBA8888>( new ColorRGBA8888(Color.FromArgb(unchecked ((int)0xDEADBEEF))), count ).ToArray(); var after = new ColorARGB8888[count]; Pixels.Convert(width, height, stride, stride, ref before, ref after); ShouldBeEquivalent(before, after); }
public void ShouldConvertPixelDataIfFormatsAreDifferent() { var surface = Surface.Create(10, 10, PixelFormat.Format_RGBA8888); var pixels = Enumerable.Repeat <ColorARGB8888>( new ColorARGB8888(TestColor), surface.PixelCount).ToArray(); // Read and convert the current pixel data var currentPixels = new ColorARGB8888[surface.PixelCount]; surface.ReadPixels(ref currentPixels); AllPixelsShouldBeEqualTo(currentPixels, new Color()); // Convert and set the pixel data surface.SetPixelData(ref pixels); surface.ReadPixels(ref currentPixels); currentPixels.Should().BeEquivalentTo(pixels); surface.Dispose(); }