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);
                }
        }
        /// <inheritdoc/>
        protected override void Decompress(BufferedReadStream stream, int byteCount, int stripHeight, Span <byte> buffer)
        {
            if (this.jpegTables != null)
            {
                using var jpegDecoder = new JpegDecoderCore(this.configuration, new JpegDecoder());

                // TODO: Should we pass through the CancellationToken from the tiff decoder?
                // If the PhotometricInterpretation is YCbCr we explicitly assume the JPEG data is in RGB color space.
                // There seems no other way to determine that the JPEG data is RGB colorspace (no APP14 marker, componentId's are not RGB).
                using SpectralConverter <Rgb24> spectralConverter = this.photometricInterpretation == TiffPhotometricInterpretation.YCbCr ?
                                                                    new RgbJpegSpectralConverter <Rgb24>(this.configuration, CancellationToken.None) : new SpectralConverter <Rgb24>(this.configuration, CancellationToken.None);
                var scanDecoder = new HuffmanScanDecoder(stream, spectralConverter, CancellationToken.None);
                jpegDecoder.LoadTables(this.jpegTables, scanDecoder);
                scanDecoder.ResetInterval = 0;
                jpegDecoder.ParseStream(stream, scanDecoder, CancellationToken.None);

                using var image = new Image <Rgb24>(this.configuration, spectralConverter.PixelBuffer, new ImageMetadata());
                CopyImageBytesToBuffer(buffer, image);
            }
            else
            {
                using var image = Image.Load <Rgb24>(stream);
                CopyImageBytesToBuffer(buffer, image);
            }
        }
Esempio n. 3
0
 internal static JpegDecoderCore ParseJpegStream(string testFileName, bool metaDataOnly = false)
 {
     byte[] bytes = TestFile.Create(testFileName).Bytes;
     using (var ms = new MemoryStream(bytes))
     {
         var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder());
         decoder.ParseStream(ms, metaDataOnly);
         return(decoder);
     }
 }
        public void ParseStream()
        {
            using var memoryStream   = new MemoryStream(this.jpegBytes);
            using var bufferedStream = new BufferedReadStream(Configuration.Default, memoryStream);

            using var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder { IgnoreMetadata = true });
            var scanDecoder = new HuffmanScanDecoder(bufferedStream, new NoopSpectralConverter(), cancellationToken: default);

            decoder.ParseStream(bufferedStream, scanDecoder, cancellationToken: default);
        }
Esempio n. 5
0
 public void ParseStreamPdfJs()
 {
     using (var memoryStream = new MemoryStream(this.jpegBytes))
     {
         var decoder = new JpegDecoderCore(Configuration.Default, new Formats.Jpeg.JpegDecoder {
             IgnoreMetadata = true
         });
         decoder.ParseStream(memoryStream);
         decoder.Dispose();
     }
 }
Esempio n. 6
0
        public void ParseStreamPdfJs()
        {
            using var memoryStream   = new MemoryStream(this.jpegBytes);
            using var bufferedStream = new BufferedReadStream(Configuration.Default, memoryStream);

            var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder {
                IgnoreMetadata = true
            });

            decoder.ParseStream(bufferedStream);
            decoder.Dispose();
        }
Esempio n. 7
0
        public void ParseStream_BasicPropertiesAreCorrect()
        {
            byte[] bytes = TestFile.Create(TestImages.Jpeg.Progressive.Progress).Bytes;
            using var ms             = new MemoryStream(bytes);
            using var bufferedStream = new BufferedReadStream(Configuration.Default, ms);
            var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder());

            decoder.ParseStream(bufferedStream);

            // I don't know why these numbers are different. All I know is that the decoder works
            // and spectral data is exactly correct also.
            // VerifyJpeg.VerifyComponentSizes3(decoder.Frame.Components, 43, 61, 22, 31, 22, 31);
            VerifyJpeg.VerifyComponentSizes3(decoder.Frame.Components, 44, 62, 22, 31, 22, 31);
        }
Esempio n. 8
0
        public void Decoder_ParseStream_SaveSpectralResult <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder());

            byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;

            using (var ms = new MemoryStream(sourceBytes))
            {
                decoder.ParseStream(ms);

                var data = LibJpegTools.SpectralData.LoadFromImageSharpDecoder(decoder);
                VerifyJpeg.SaveSpectralImage(provider, data);
            }
        }
Esempio n. 9
0
        public void VerifySpectralCorrectness <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            if (!TestEnvironment.IsWindows)
            {
                return;
            }

            var decoder = new JpegDecoderCore(Configuration.Default, new JpegDecoder());

            byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;

            using (var ms = new MemoryStream(sourceBytes))
            {
                decoder.ParseStream(ms);
                var imageSharpData = LibJpegTools.SpectralData.LoadFromImageSharpDecoder(decoder);

                this.VerifySpectralCorrectnessImpl(provider, imageSharpData);
            }
        }