Skip to content

Commit 9e6fbdb

Browse files
committed
Fix build issue, dispose decoded jpeg image
1 parent 7fcbcc7 commit 9e6fbdb

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/ImageSharp/Formats/Tiff/Compression/Decompressors/JpegTiffCompression.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
1717
/// <summary>
1818
/// Class to handle cases where TIFF image data is compressed as a jpeg stream.
1919
/// </summary>
20-
internal class JpegTiffCompression : TiffBaseDecompressor
20+
internal sealed class JpegTiffCompression : TiffBaseDecompressor
2121
{
2222
private readonly Configuration configuration;
2323

@@ -49,12 +49,11 @@ public JpegTiffCompression(
4949
}
5050

5151
/// <inheritdoc/>
52-
protected override void Decompress(BufferedReadStream stream, int byteCount, Span<byte> buffer)
52+
protected override void Decompress(BufferedReadStream stream, int byteCount, int stripHeight, Span<byte> buffer)
5353
{
54-
Image<Rgb24> image;
5554
if (this.jpegTables != null)
5655
{
57-
var jpegDecoder = new JpegDecoderCore(this.configuration, new JpegDecoder());
56+
using var jpegDecoder = new JpegDecoderCore(this.configuration, new JpegDecoder());
5857

5958
// TODO: Should we pass through the CancellationToken from the tiff decoder?
6059
// If the PhotometricInterpretation is YCbCr we explicitly assume the JPEG data is in RGB color space.
@@ -66,13 +65,18 @@ protected override void Decompress(BufferedReadStream stream, int byteCount, Spa
6665
scanDecoder.ResetInterval = 0;
6766
jpegDecoder.ParseStream(stream, scanDecoder, CancellationToken.None);
6867

69-
image = new Image<Rgb24>(this.configuration, spectralConverter.PixelBuffer, new ImageMetadata());
68+
using var image = new Image<Rgb24>(this.configuration, spectralConverter.PixelBuffer, new ImageMetadata());
69+
CopyImageBytesToBuffer(buffer, image);
7070
}
7171
else
7272
{
73-
image = Image.Load<Rgb24>(stream);
73+
using var image = Image.Load<Rgb24>(stream);
74+
CopyImageBytesToBuffer(buffer, image);
7475
}
76+
}
7577

78+
private static void CopyImageBytesToBuffer(Span<byte> buffer, Image<Rgb24> image)
79+
{
7680
int offset = 0;
7781
for (int y = 0; y < image.Height; y++)
7882
{

src/ImageSharp/Formats/Tiff/Compression/TiffDecoderCompressionType.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ internal enum TiffDecoderCompressionType
3636
/// <summary>
3737
/// Image data is compressed using CCITT T.6 fax compression.
3838
/// </summary>
39-
T6 = 6,
39+
T6 = 5,
4040

4141
/// <summary>
4242
/// Image data is compressed using modified huffman compression.
4343
/// </summary>
44-
HuffmanRle = 5,
44+
HuffmanRle = 6,
4545

4646
/// <summary>
4747
/// The image data is compressed as a JPEG stream.
4848
/// </summary>
49-
Jpeg = 6,
49+
Jpeg = 7,
5050
}
5151
}

tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public class TiffDecoderTests
2828
private static MagickReferenceDecoder ReferenceDecoder => new MagickReferenceDecoder();
2929

3030
[Theory]
31-
[WithFile(Calliphora_RgbJpeg, PixelTypes.Rgba32)]
32-
[WithFile(RgbJpeg, PixelTypes.Rgba32)]
3331
[WithFile(RgbUncompressedTiled, PixelTypes.Rgba32)]
3432
[WithFile(MultiframeDifferentSize, PixelTypes.Rgba32)]
3533
[WithFile(MultiframeDifferentVariants, PixelTypes.Rgba32)]

0 commit comments

Comments
 (0)