private void DecodeJpegBenchmarkImpl(string fileName, IImageDecoder decoder, int executionCount)
        {
            // do not run this on CI even by accident
            if (TestEnvironment.RunsOnCI)
            {
                return;
            }

            if (!Vector.IsHardwareAccelerated)
            {
                throw new Exception("Vector.IsHardwareAccelerated == false! ('prefer32 bit' enabled?)");
            }

            string path = TestFile.GetInputFileFullPath(fileName);

            byte[] bytes = File.ReadAllBytes(path);

            this.Measure(
                executionCount,
                () =>
            {
                var img = Image.Load <Rgba32>(bytes, decoder);
                img.Dispose();
            },
#pragma warning disable SA1515 // Single-line comment should be preceded by blank line
                // ReSharper disable once ExplicitCallerInfoArgument
                $"Decode {fileName}");
#pragma warning restore SA1515 // Single-line comment should be preceded by blank line
        }
        public void Setup()
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(TestImages.GeoJson.States));

            FeatureCollection featureCollection = JsonConvert.DeserializeObject <FeatureCollection>(jsonContent);

            this.points   = this.GetPoints(featureCollection);
            this.polygons = this.points.Select(pts => new Polygon(new LinearLineSegment(pts))).ToArray();

            this.sdPoints = this.points.Select(pts => pts.Select(p => new SDPointF(p.X, p.Y)).ToArray()).ToArray();

            this.skPaths = new List <SKPath>();
            foreach (PointF[] ptArr in this.points.Where(pts => pts.Length > 2))
            {
                var skPath = new SKPath();
                skPath.MoveTo(ptArr[0].X, ptArr[1].Y);
                for (int i = 1; i < ptArr.Length; i++)
                {
                    skPath.LineTo(ptArr[i].X, ptArr[i].Y);
                }

                skPath.LineTo(ptArr[0].X, ptArr[1].Y);
                this.skPaths.Add(skPath);
            }

            this.image      = new Image <Rgba32>(this.Width, this.Height);
            this.sdBitmap   = new SDBitmap(this.Width, this.Height);
            this.sdGraphics = Graphics.FromImage(this.sdBitmap);
            this.sdGraphics.InterpolationMode = InterpolationMode.Default;
            this.sdGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
            this.skBitmap = new SKBitmap(this.Width, this.Height);
            this.skCanvas = new SKCanvas(this.skBitmap);
        }
        public void LargeGeoJson_Mississippi_Lines(TestImageProvider <Rgba32> provider, int pixelOffset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(TestImages.GeoJson.States));

            FeatureCollection features = JsonConvert.DeserializeObject <FeatureCollection>(jsonContent);

            Feature missisipiGeom = features.Features.Single(f => (string)f.Properties["NAME"] == "Mississippi");

            Matrix3x2 transform = Matrix3x2.CreateTranslation(-87, -54)
                                  * Matrix3x2.CreateScale(60, 60)
                                  * Matrix3x2.CreateTranslation(pixelOffset, pixelOffset);
            IReadOnlyList <PointF[]> points = PolygonFactory.GetGeoJsonPoints(missisipiGeom, transform);

            using Image <Rgba32> image = provider.GetImage();

            foreach (PointF[] loop in points)
            {
                image.Mutate(c => c.DrawLines(Color.White, 1.0f, loop));
            }

            // Very strict tolerance, since the image is sparse (relaxed on .NET Framework)
            ImageComparer comparer = TestEnvironment.IsFramework
                ? ImageComparer.TolerantPercentage(1e-3f)
                : ImageComparer.TolerantPercentage(1e-7f);

            string details = $"PixelOffset({pixelOffset})";

            image.DebugSave(provider, details, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
            image.CompareToReferenceOutput(comparer, provider, testOutputDetails: details, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
        }
        public void LargeGeoJson_Lines(TestImageProvider <Rgba32> provider, string geoJsonFile, int aa, float sx, float sy)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(geoJsonFile));

            PointF[][] points = PolygonFactory.GetGeoJsonPoints(jsonContent, Matrix3x2.CreateScale(sx, sy));

            using Image <Rgba32> image = provider.GetImage();
            var options = new DrawingOptions()
            {
                GraphicsOptions = new GraphicsOptions()
                {
                    Antialias = aa > 0, AntialiasSubpixelDepth = aa
                },
            };

            foreach (PointF[] loop in points)
            {
                image.Mutate(c => c.DrawLines(options, Color.White, 1.0f, loop));
            }

            string details = $"_{System.IO.Path.GetFileName(geoJsonFile)}_{sx}x{sy}_aa{aa}";

            image.DebugSave(
                provider,
                details,
                appendPixelTypeToFileName: false,
                appendSourceFileOrDescription: false);
        }
        private Image <Rgba32> FillGeoJsonPolygons(TestImageProvider <Rgba32> provider, string geoJsonFile, int aa, Vector2 scale, Vector2 pixelOffset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(geoJsonFile));

            PointF[][] points = PolygonFactory.GetGeoJsonPoints(jsonContent, Matrix3x2.CreateScale(scale) * Matrix3x2.CreateTranslation(pixelOffset));

            Image <Rgba32> image   = provider.GetImage();
            var            options = new DrawingOptions()
            {
                GraphicsOptions = new GraphicsOptions()
                {
                    Antialias = aa > 0, AntialiasSubpixelDepth = aa
                },
            };
            var rnd = new Random(42);

            byte[] rgb = new byte[3];
            foreach (PointF[] loop in points)
            {
                rnd.NextBytes(rgb);

                var color = Color.FromRgb(rgb[0], rgb[1], rgb[2]);
                image.Mutate(c => c.FillPolygon(options, color, loop));
            }

            return(image);
        }
Esempio n. 6
0
        private void DecodeJpegBenchmarkImpl(string fileName, IImageDecoder decoder)
        {
            // do not run this on CI even by accident
            if (TestEnvironment.RunsOnCI)
            {
                return;
            }

            const int ExecutionCount = 30;

            if (!Vector.IsHardwareAccelerated)
            {
                throw new Exception("Vector.IsHardwareAccelerated == false! ('prefer32 bit' enabled?)");
            }

            string path = TestFile.GetInputFileFullPath(fileName);

            byte[] bytes = File.ReadAllBytes(path);

            this.Measure(
                ExecutionCount,
                () =>
            {
                Image <Rgba32> img = Image.Load <Rgba32>(bytes, decoder);
            },
                // ReSharper disable once ExplicitCallerInfoArgument
                $"Decode {fileName}");
        }
Esempio n. 7
0
        public void OpenWithReferenceDecoder <TPixel>(TestImageProvider <TPixel> dummyProvider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            string path = TestFile.GetInputFileFullPath(TestImages.Png.Splash);

            using (var image = Image.Load <TPixel>(path, SystemDrawingReferenceDecoder.Instance))
            {
                image.DebugSave(dummyProvider);
            }
        }
        public DrawingProfilingBenchmarks()
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(TestImages.GeoJson.States));

            FeatureCollection featureCollection = JsonConvert.DeserializeObject <FeatureCollection>(jsonContent);

            PointF[][] points = GetPoints(featureCollection);
            this.polygons = points.Select(pts => new Polygon(new LinearLineSegment(pts))).ToArray();

            this.image = new Image <Rgba32>(1000, 1000);
        public void Missisippi_Skia(int offset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(TestImages.GeoJson.States));

            FeatureCollection features = JsonConvert.DeserializeObject <FeatureCollection>(jsonContent);

            Feature missisipiGeom = features.Features.Single(f => (string)f.Properties["NAME"] == "Mississippi");

            Matrix3x2 transform = Matrix3x2.CreateTranslation(-87, -54)
                                  * Matrix3x2.CreateScale(60, 60)
                                  * Matrix3x2.CreateTranslation(offset, offset);
            IReadOnlyList <PointF[]> points = PolygonFactory.GetGeoJsonPoints(missisipiGeom, transform);

            var path = new SKPath();

            foreach (PointF[] pts in points.Where(p => p.Length > 2))
            {
                path.MoveTo(pts[0].X, pts[0].Y);

                for (int i = 0; i < pts.Length; i++)
                {
                    path.LineTo(pts[i].X, pts[i].Y);
                }

                path.LineTo(pts[0].X, pts[0].Y);
            }

            var imageInfo = new SKImageInfo(10000, 10000);

            using var paint = new SKPaint
                  {
                      Style       = SKPaintStyle.Stroke,
                      Color       = SKColors.White,
                      StrokeWidth = 1f,
                      IsAntialias = true,
                  };

            using var surface = SKSurface.Create(imageInfo);
            SKCanvas canvas = surface.Canvas;

            canvas.Clear(new SKColor(0, 0, 0));
            canvas.DrawPath(path, paint);

            string outDir = TestEnvironment.CreateOutputDirectory("Skia");
            string fn     = System.IO.Path.Combine(outDir, $"Missisippi_Skia_{offset}.png");

            using SKImage image = surface.Snapshot();
            using SKData data   = image.Encode(SKEncodedImageFormat.Png, 100);

            using FileStream fs = File.Create(fn);
            data.SaveTo(fs);
        }
Esempio n. 10
0
        public void From32bppArgbSystemDrawingBitmap <TPixel>(TestImageProvider <TPixel> dummyProvider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            string path = TestFile.GetInputFileFullPath(TestImages.Png.Splash);

            using (var sdBitmap = new System.Drawing.Bitmap(path))
            {
                using (Image <TPixel> image = SystemDrawingBridge.From32bppArgbSystemDrawingBitmap <TPixel>(sdBitmap))
                {
                    image.DebugSave(dummyProvider);
                }
            }
        }
Esempio n. 11
0
        public void Resize_PixelAgnostic()
        {
            string filePath = TestFile.GetInputFileFullPath(TestImages.Jpeg.Baseline.Calliphora);

            using (var image = Image.Load(filePath))
            {
                image.Mutate(x => x.Resize(image.Size() / 2));
                string path = System.IO.Path.Combine(
                    TestEnvironment.CreateOutputDirectory(nameof(ResizeTests)),
                    nameof(this.Resize_PixelAgnostic) + ".png");

                image.Save(path);
            }
        }
        public void EncodeJpeg_SingleMidSize()
        {
            string path = TestFile.GetInputFileFullPath(TestImages.Jpeg.BenchmarkSuite.Jpeg420Exif_MidSizeYCbCr);

            using var image            = Image.Load(path);
            image.Metadata.ExifProfile = null;

            using var ms = new MemoryStream();
            for (int i = 0; i < 30; i++)
            {
                image.SaveAsJpeg(ms);
                ms.Seek(0, SeekOrigin.Begin);
            }
        }
Esempio n. 13
0
        public void RunDumpJpegCoeffsTool()
        {
            if (!TestEnvironment.IsWindows)
            {
                return;
            }

            string inputFile  = TestFile.GetInputFileFullPath(TestImages.Jpeg.Progressive.Progress);
            string outputDir  = TestEnvironment.CreateOutputDirectory(nameof(SpectralJpegTests));
            string outputFile = Path.Combine(outputDir, "progress.dctdump");

            LibJpegTools.RunDumpJpegCoeffsTool(inputFile, outputFile);

            Assert.True(File.Exists(outputFile));
        }
Esempio n. 14
0
        public void MagickDecode_8BitDepthImage_IsEquivalentTo_SystemDrawingResult <TPixel>(TestImageProvider <TPixel> dummyProvider, string testImage)
            where TPixel : struct, IPixel <TPixel>
        {
            string path = TestFile.GetInputFileFullPath(testImage);

            var magickDecoder = new MagickReferenceDecoder();
            var sdDecoder     = new SystemDrawingReferenceDecoder();

            ImageComparer comparer = ImageComparer.Exact;

            using (var mImage = Image.Load <TPixel>(path, magickDecoder))
                using (var sdImage = Image.Load <TPixel>(path, sdDecoder))
                {
                    ImageSimilarityReport <TPixel, TPixel> report = comparer.CompareImagesOrFrames(mImage, sdImage);

                    mImage.DebugSave(dummyProvider);

                    if (TestEnvironment.IsWindows)
                    {
                        Assert.True(report.IsEmpty);
                    }
                }
        }
Esempio n. 15
0
        public void MagickDecode_16BitDepthImage_IsApproximatelyEquivalentTo_SystemDrawingResult <TPixel>(TestImageProvider <TPixel> dummyProvider, string testImage)
            where TPixel : struct, IPixel <TPixel>
        {
            string path = TestFile.GetInputFileFullPath(testImage);

            var magickDecoder = new MagickReferenceDecoder();
            var sdDecoder     = new SystemDrawingReferenceDecoder();

            // 1020 == 4 * 255 (Equivalent to manhattan distance of 1+1+1+1=4 in Rgba32 space)
            var comparer = ImageComparer.TolerantPercentage(1, 1020);

            using (var mImage = Image.Load <TPixel>(path, magickDecoder))
                using (var sdImage = Image.Load <TPixel>(path, sdDecoder))
                {
                    ImageSimilarityReport <TPixel, TPixel> report = comparer.CompareImagesOrFrames(mImage, sdImage);

                    mImage.DebugSave(dummyProvider);

                    if (TestEnvironment.IsWindows)
                    {
                        Assert.True(report.IsEmpty);
                    }
                }
        }