Exemple #1
0
        public void ShouldNotConvertPixelDataIfTheFormatIsSame()
        {
            var width   = 10;
            var height  = 10;
            var surface = Surface.Create(width, height, PixelFormat.Format_RGBA8888);
            var pixels  = Enumerable.Repeat <ColorRGBA8888>(
                new ColorRGBA8888(TestColor), surface.PixelCount).ToArray();

            // Read and convert the current pixel data
            var currentPixels = new ColorRGBA8888[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();
        }
Exemple #2
0
        public void ShouldSaveAndLoadAsPNG()
        {
            var surface = Surface.Create(10, 10);

            surface.Fill(TestColor);

            var ms = new MemoryStream();

            surface.SaveAsPng(ms);
            surface.SaveAsPng("ShouldSaveAndLoadAsPNG.png");
            ms.Seek(0, SeekOrigin.Begin);
            var sameSurface = SurfaceFactory.FromStream(ms, new PngDecoder());

            ms.Dispose();

            var pixels     = new ColorRGBA8888[surface.PixelCount];
            var samePixels = new ColorRGBA8888[surface.PixelCount];

            surface.ReadPixels(ref pixels);
            sameSurface.ReadPixels(ref samePixels);
            samePixels.Should().BeEquivalentTo(pixels);
        }
Exemple #3
0
        public void ShouldConvertToSpecifiedFormat()
        {
            var width  = 10;
            var height = 10;
            var source = Surface.Create(width, height, PixelFormat.Format_RGBA8888);
            var pixels = Enumerable.Repeat <ColorRGBA8888>(
                new ColorRGBA8888(TestColor), source.PixelCount
                ).ToArray();

            // Set the pixel data and check it
            source.SetPixelData(ref pixels);
            var currentPixels = new ColorRGBA8888[source.PixelCount];

            source.ReadPixels(ref currentPixels);
            currentPixels.Should().BeEquivalentTo(pixels);
            // Convert the surface and check it again
            var converted = source.ConvertTo(PixelFormat.Format_ARGB8888);

            source.ReadPixels(ref currentPixels);
            currentPixels.Should().BeEquivalentTo(pixels);

            source.Dispose();
            converted.Dispose();
        }