diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs index a52297a5e5..e416bbc194 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs @@ -7,6 +7,8 @@ using SixLabors.ImageSharp.Memory; namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder { + using SixLabors.Primitives; + /// /// Represents a single color component /// @@ -222,6 +224,20 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder this.VerticalSamplingFactor = v; } + public Size CalculateJpegChannelSize(SubsampleRatio ratio) + { + Size size = new Size(this.WidthInBlocks, this.HeightInBlocks) * 8; + + if (this.Index > 0 && this.Index < 3) // Chroma component: + { + return ratio.CalculateChrominanceSize(size.Width, size.Height); + } + else + { + return size; + } + } + public void Dispose() { this.SpectralBlocks.Dispose(); diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/SubsampleRatio.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/SubsampleRatio.cs index 9d1f97d90c..86fde5e72b 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/SubsampleRatio.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/SubsampleRatio.cs @@ -1,11 +1,10 @@ -namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder -{ - using System.Collections.Generic; - using System.Linq; - - using SixLabors.ImageSharp.Formats.Jpeg.Common; - using SixLabors.Primitives; +using System.Collections.Generic; +using System.Linq; +using SixLabors.ImageSharp.Formats.Jpeg.Common; +using SixLabors.Primitives; +namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder +{ /// /// Provides enumeration of the various available subsample ratios. /// https://en.wikipedia.org/wiki/Chroma_subsampling diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index d7a037a06d..6fb367edca 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -203,10 +203,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort where TPixel : struct, IPixel { this.ParseStream(stream); - this.ProcessBlocksIntoJpegImageChannels(); - Image image = this.ConvertJpegPixelsToImagePixels(); - return image; + this.ProcessBlocksIntoJpegImageChannels(); + + return this.ConvertJpegPixelsToImagePixels(); } /// @@ -464,9 +464,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort /// are in a "raw" frequency-domain form. We need to apply IDCT, dequantization and unzigging to transform them into color-space blocks. /// We can copy these blocks into -s afterwards. /// - /// The pixel type - private void ProcessBlocksIntoJpegImageChannels() - where TPixel : struct, IPixel + private void ProcessBlocksIntoJpegImageChannels() { this.InitJpegImageChannels(); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index eb8261856e..15be5b7710 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -24,8 +24,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg { public static string[] BaselineTestJpegs = { - TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk, - TestImages.Jpeg.Baseline.Jpeg400, TestImages.Jpeg.Baseline.Jpeg444, + TestImages.Jpeg.Baseline.Calliphora, + TestImages.Jpeg.Baseline.Cmyk, + TestImages.Jpeg.Baseline.Ycck, + TestImages.Jpeg.Baseline.Jpeg400, + TestImages.Jpeg.Baseline.Jpeg444, TestImages.Jpeg.Baseline.Testimgorig, TestImages.Jpeg.Baseline.Bad.BadEOF, TestImages.Jpeg.Baseline.Bad.ExifUndefType, diff --git a/tests/Images/External b/tests/Images/External index 3b80ee0684..2f6b226b9f 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 3b80ee0684fedab0f5798eea5c5ed7b75cbff714 +Subproject commit 2f6b226b9fbaf8b23808755bd7e7752a0560644e