public void ShouldSetBytesInRectangle() { var width = 10; var height = 10; var rectangle = new Rectangle(5, 5, width, height); var format = PixelFormat.Format_RGB888; var texture = graphics.CreateTexture( graphics.OutputSize.Width, graphics.OutputSize.Height, format: format); var pixels = new byte[width * height * format.GetBytesPerPixel()]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = 255; } texture.SetPixels(ref pixels, rectangle); graphics.Draw(texture); var actual = new ColorRGB888[width * height]; graphics.ReadPixels(ref actual, rectangle); actual.Distinct().Should().BeEquivalentTo( new ColorRGB888(Color.White) ); }
public void ShouldReadPixelsFromFramebuffer() { var color = Color.CornflowerBlue; var readBuffer = new ColorRGB888[graphics.PixelCount]; graphics.Clear(Color.Black); graphics.ReadPixels(ref readBuffer); readBuffer.Distinct().Should().BeEquivalentTo(new ColorRGB888()); graphics.Clear(color); app.Tick(); graphics.Clear(color); graphics.ReadPixels(ref readBuffer); readBuffer.Distinct().Should().BeEquivalentTo(new ColorRGB888(color)); }
public void ShouldReadPixelsFromFramebufferInRectangle() { var color = Color.CornflowerBlue; var rectangle = new Rectangle(5, 5, 10, 10); var readBuffer = new ColorRGB888[graphics.GetPixelBufferSize(rectangle)]; graphics.Clear(Color.Black); graphics.ReadPixels(ref readBuffer, rectangle); readBuffer.Distinct().Should().BeEquivalentTo(new ColorRGB888()); var texture = graphics.CreateTexture(rectangle.Width, rectangle.Height); var textureData = Enumerable.Repeat(new ColorRGB888(color), texture.PixelCount).ToArray(); texture.SetPixels(ref textureData); graphics.Draw(texture, dstRect: rectangle); graphics.ReadPixels(ref readBuffer, rectangle); readBuffer.Distinct().Should().BeEquivalentTo(new ColorRGB888(color)); }
public void ShouldSaveFramebufferData() { var color = Color.CornflowerBlue.WithoutName(); graphics.Clear(color); var ms = new MemoryStream(); graphics.SaveAsPng(ms); ms.Seek(0, SeekOrigin.Begin); var surface = SurfaceFactory.FromStream(ms, new PngDecoder()); var pixels = new ColorRGB888[surface.PixelCount]; surface.ReadPixels(ref pixels); pixels.Distinct().Select(c => c.AsColor()) .Should().BeEquivalentTo(color); }
public void ShouldDrawInSpecifiedRectangles(Rectangle?src, Rectangle?dst) { var color = new ColorRGB888(Color.CornflowerBlue); var size = graphics.OutputSize; var texture = graphics.CreateTexture( dst?.Width ?? size.Width, dst?.Height ?? size.Height); var pixels = Enumerable.Repeat( color, texture.GetPixelBufferSize <ColorRGB888>(src) ).ToArray(); texture.SetPixels(ref pixels, src); graphics.Clear(Color.Black); graphics.Draw(texture, src, dst); var portion = Project(texture, src, dst); var actual = new ColorRGB888[graphics.GetPixelBufferSize(portion)]; graphics.ReadPixels(ref actual, portion); actual.Distinct().Should().BeEquivalentTo(color); }