Esempio n. 1
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 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);
                        }
                    }
        }
Esempio n. 3
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}");
                    }
        }