From 9e6fbdb96b5a72a6173c708b4b3876e3c3d9d311 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 24 Aug 2021 13:44:15 +0200 Subject: [PATCH] Fix build issue, dispose decoded jpeg image --- .../Decompressors/JpegTiffCompression.cs | 16 ++++++++++------ .../Compression/TiffDecoderCompressionType.cs | 6 +++--- .../Formats/Tiff/TiffDecoderTests.cs | 2 -- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs index 8abaf20088..bd1c496b49 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors /// /// Class to handle cases where TIFF image data is compressed as a jpeg stream. /// - internal class JpegTiffCompression : TiffBaseDecompressor + internal sealed class JpegTiffCompression : TiffBaseDecompressor { private readonly Configuration configuration; @@ -49,12 +49,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors } /// - protected override void Decompress(BufferedReadStream stream, int byteCount, Span buffer) + protected override void Decompress(BufferedReadStream stream, int byteCount, int stripHeight, Span buffer) { - Image image; if (this.jpegTables != null) { - var jpegDecoder = new JpegDecoderCore(this.configuration, new JpegDecoder()); + 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. @@ -66,13 +65,18 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors scanDecoder.ResetInterval = 0; jpegDecoder.ParseStream(stream, scanDecoder, CancellationToken.None); - image = new Image(this.configuration, spectralConverter.PixelBuffer, new ImageMetadata()); + using var image = new Image(this.configuration, spectralConverter.PixelBuffer, new ImageMetadata()); + CopyImageBytesToBuffer(buffer, image); } else { - image = Image.Load(stream); + using var image = Image.Load(stream); + CopyImageBytesToBuffer(buffer, image); } + } + private static void CopyImageBytesToBuffer(Span buffer, Image image) + { int offset = 0; for (int y = 0; y < image.Height; y++) { diff --git a/src/ImageSharp/Formats/Tiff/Compression/TiffDecoderCompressionType.cs b/src/ImageSharp/Formats/Tiff/Compression/TiffDecoderCompressionType.cs index 4353cb1231..d8843c1078 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/TiffDecoderCompressionType.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/TiffDecoderCompressionType.cs @@ -36,16 +36,16 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression /// /// Image data is compressed using CCITT T.6 fax compression. /// - T6 = 6, + T6 = 5, /// /// Image data is compressed using modified huffman compression. /// - HuffmanRle = 5, + HuffmanRle = 6, /// /// The image data is compressed as a JPEG stream. /// - Jpeg = 6, + Jpeg = 7, } } diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs index c01237b6a9..b64d22991f 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs @@ -28,8 +28,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff private static MagickReferenceDecoder ReferenceDecoder => new MagickReferenceDecoder(); [Theory] - [WithFile(Calliphora_RgbJpeg, PixelTypes.Rgba32)] - [WithFile(RgbJpeg, PixelTypes.Rgba32)] [WithFile(RgbUncompressedTiled, PixelTypes.Rgba32)] [WithFile(MultiframeDifferentSize, PixelTypes.Rgba32)] [WithFile(MultiframeDifferentVariants, PixelTypes.Rgba32)]