Example #1
0
        public void TestGetBlpSKBitmap(string inputImagePath, string expectedImagePath, int mipMapLevel)
        {
            using (var fileStream = File.OpenRead(inputImagePath))
            {
                var expectedImage = new Bitmap(expectedImagePath);
                var blpFile       = new BlpFile(fileStream);
                var actualImage   = blpFile.GetSKBitmap(mipMapLevel);

                Assert.AreEqual(expectedImage.Width, actualImage.Width);
                Assert.AreEqual(expectedImage.Height, actualImage.Height);

                for (var y = 0; y < expectedImage.Height; y++)
                {
                    for (var x = 0; x < expectedImage.Width; x++)
                    {
                        // Allow pixel values to be slightly different, since some testcases were decoded with WPF (BitmapSource), not SkiaSharp.
                        const int delta = 1;

                        var expectedPixel = expectedImage.GetPixel(x, y);
                        var actualPixel   = actualImage.GetPixel(x, y);

                        var message = $"Expected:<{expectedPixel}>. Actual:<{actualPixel.ToColorString()}>";

                        Assert.IsTrue(Math.Abs(expectedPixel.A - actualPixel.Alpha) <= delta, message);
                        Assert.IsTrue(Math.Abs(expectedPixel.R - actualPixel.Red) <= delta, message);
                        Assert.IsTrue(Math.Abs(expectedPixel.G - actualPixel.Green) <= delta, message);
                        Assert.IsTrue(Math.Abs(expectedPixel.B - actualPixel.Blue) <= delta, message);
                    }
                }

                expectedImage.Dispose();
                blpFile.Dispose();
            }
        }