public void PostProcess <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            string imageFile = provider.SourceFileOrDescription;

            using (JpegDecoderCore decoder = JpegFixture.ParseJpegStream(imageFile))
                using (var pp = new JpegImagePostProcessor(Configuration.Default, decoder))
                    using (var image = new Image <Rgba32>(decoder.ImageWidth, decoder.ImageHeight))
                    {
                        pp.PostProcess(image.Frames.RootFrame);

                        image.DebugSave(provider);

                        ImagingTestCaseUtility testUtil = provider.Utility;
                        testUtil.TestGroupName = nameof(JpegDecoderTests);
                        testUtil.TestName      = JpegDecoderTests.DecodeBaselineJpegOutputName;

                        using (Image <TPixel> referenceImage =
                                   provider.GetReferenceOutputImage <TPixel>(appendPixelTypeToFileName: false))
                        {
                            ImageSimilarityReport report = ImageComparer.Exact.CompareImagesOrFrames(referenceImage, image);

                            this.Output.WriteLine($"*** {imageFile} ***");
                            this.Output.WriteLine($"Difference: {report.DifferencePercentageString}");

                            // ReSharper disable once PossibleInvalidOperationException
                            Assert.True(report.TotalNormalizedDifference.Value < 0.005f);
                        }
                    }
        }
Exemplo n.º 2
0
        // DEBUG ONLY!
        // The PDF.js output should be saved by "tests\ImageSharp.Tests\Formats\Jpg\pdfjs\jpeg-converter.htm"
        // into "\tests\Images\ActualOutput\JpegDecoderTests\"
        //[Theory]
        //[WithFile(TestImages.Jpeg.Progressive.Progress, PixelTypes.Rgba32, "PdfJsOriginal_progress.png")]
        public void ValidateProgressivePdfJsOutput <TPixel>(TestImageProvider <TPixel> provider,
                                                            string pdfJsOriginalResultImage)
            where TPixel : struct, IPixel <TPixel>
        {
            // tests\ImageSharp.Tests\Formats\Jpg\pdfjs\jpeg-converter.htm
            string pdfJsOriginalResultPath = Path.Combine(
                provider.Utility.GetTestOutputDir(),
                pdfJsOriginalResultImage);

            byte[] sourceBytes = TestFile.Create(TestImages.Jpeg.Progressive.Progress).Bytes;

            provider.Utility.TestName = nameof(DecodeProgressiveJpegOutputName);

            var comparer = ImageComparer.Tolerant(0, 0);

            using (Image <TPixel> expectedImage = provider.GetReferenceOutputImage <TPixel>(appendPixelTypeToFileName: false))
                using (var pdfJsOriginalResult = Image.Load(pdfJsOriginalResultPath))
                    using (var pdfJsPortResult = Image.Load(sourceBytes, PdfJsJpegDecoder))
                    {
                        ImageSimilarityReport originalReport = comparer.CompareImagesOrFrames(expectedImage, pdfJsOriginalResult);
                        ImageSimilarityReport portReport     = comparer.CompareImagesOrFrames(expectedImage, pdfJsPortResult);

                        this.Output.WriteLine($"Difference for PDF.js ORIGINAL: {originalReport.DifferencePercentageString}");
                        this.Output.WriteLine($"Difference for PORT: {portReport.DifferencePercentageString}");
                    }
        }
Exemplo n.º 3
0
        public void Decoder_PixelBufferComparison <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            // Stream
            byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;
            using var ms             = new MemoryStream(sourceBytes);
            using var bufferedStream = new BufferedReadStream(Configuration.Default, ms);

            // Decoding
            using var converter = new SpectralConverter <TPixel>(Configuration.Default, cancellationToken: default);
            var decoder     = new JpegDecoderCore(Configuration.Default, new JpegDecoder());
            var scanDecoder = new HuffmanScanDecoder(bufferedStream, converter, cancellationToken: default);

            decoder.ParseStream(bufferedStream, scanDecoder, cancellationToken: default);

            // Test metadata
            provider.Utility.TestGroupName = nameof(JpegDecoderTests);
            provider.Utility.TestName      = JpegDecoderTests.DecodeBaselineJpegOutputName;

            // Comparison
            using (Image <TPixel> image = new Image <TPixel>(Configuration.Default, converter.GetPixelBuffer(), new ImageMetadata()))
                using (Image <TPixel> referenceImage = provider.GetReferenceOutputImage <TPixel>(appendPixelTypeToFileName: false))
                {
                    ImageSimilarityReport report = ImageComparer.Exact.CompareImagesOrFrames(referenceImage, image);

                    this.Output.WriteLine($"*** {provider.SourceFileOrDescription} ***");
                    this.Output.WriteLine($"Difference: {report.DifferencePercentageString}");

                    // ReSharper disable once PossibleInvalidOperationException
                    Assert.True(report.TotalNormalizedDifference.Value < 0.005f);
                }
        }
        public static IEnumerable <ImageSimilarityReport <TPixelA, TPixelB> > CompareImages <TPixelA, TPixelB>(
            this ImageComparer comparer,
            Image <TPixelA> expected,
            Image <TPixelB> actual)
            where TPixelA : unmanaged, IPixel <TPixelA>
            where TPixelB : unmanaged, IPixel <TPixelB>
        {
            var result = new List <ImageSimilarityReport <TPixelA, TPixelB> >();

            if (expected.Frames.Count != actual.Frames.Count)
            {
                throw new ImageFramesMismatchException(expected.Frames.Count, actual.Frames.Count);
            }

            for (int i = 0; i < expected.Frames.Count; i++)
            {
                ImageSimilarityReport <TPixelA, TPixelB> report = comparer.CompareImagesOrFrames(expected.Frames[i], actual.Frames[i]);
                if (!report.IsEmpty)
                {
                    result.Add(report);
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        private string GetDifferenceInPercentageString <TPixel>(Image <TPixel> image, TestImageProvider <TPixel> provider)
            where TPixel : struct, IPixel <TPixel>
        {
            var reportingComparer = ImageComparer.Tolerant(0, 0);

            ImageSimilarityReport report = image.GetReferenceOutputSimilarityReports(
                provider,
                reportingComparer,
                appendPixelTypeToFileName: false
                ).SingleOrDefault();

            if (report != null && report.TotalNormalizedDifference.HasValue)
            {
                return(report.DifferencePercentageString);
            }

            return("0%");
        }
        private static void CompareToSkiaResultsImpl(TestImageProvider <Rgba32> provider, IPath shape)
        {
            using Image <Rgba32> image = provider.GetImage();
            image.Mutate(c => c.Fill(Color.White, shape));
            image.DebugSave(provider, "ImageSharp", appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);

            using var bitmap = new SKBitmap(new SKImageInfo(image.Width, image.Height));

            using var skPath = new SKPath();

            foreach (ISimplePath loop in shape.Flatten())
            {
                ReadOnlySpan <SKPoint> points = MemoryMarshal.Cast <PointF, SKPoint>(loop.Points.Span);
                skPath.AddPoly(points.ToArray());
            }

            using var paint = new SKPaint
                  {
                      Style       = SKPaintStyle.Fill,
                      Color       = SKColors.White,
                      IsAntialias = true,
                  };

            using var canvas = new SKCanvas(bitmap);
            canvas.Clear(new SKColor(0, 0, 0));
            canvas.DrawPath(skPath, paint);

            using var skResultImage =
                      Image.LoadPixelData <Rgba32>(bitmap.GetPixelSpan(), image.Width, image.Height);
            skResultImage.DebugSave(
                provider,
                "SkiaSharp",
                appendPixelTypeToFileName: false,
                appendSourceFileOrDescription: false);

            ImageSimilarityReport <Rgba32, Rgba32> result = ImageComparer.Exact.CompareImagesOrFrames(image, skResultImage);

            throw new Exception(result.DifferencePercentageString);
        }
Exemplo n.º 7
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);
                    }
                }
        }
Exemplo n.º 8
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);
                    }
                }
        }