Skip to content

Commit 4224257

Browse files
Merge pull request #3007 from SixLabors/js/backport-2679
Backport v3 : Tiff decoder: Fix issue 2679
2 parents 6b7448e + 135324e commit 4224257

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,14 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
637637
{
638638
options.CompressionType = TiffDecoderCompressionType.Jpeg;
639639

640+
// Some tiff encoder set this to values different from [1, 1]. The jpeg decoder already handles this,
641+
// so we set this always to [1, 1], see: https://github.com/SixLabors/ImageSharp/issues/2679
642+
if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr && options.YcbcrSubSampling != null)
643+
{
644+
options.YcbcrSubSampling[0] = 1;
645+
options.YcbcrSubSampling[1] = 1;
646+
}
647+
640648
if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr && options.JpegTables is null)
641649
{
642650
// Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,23 @@ public void TiffDecoder_CanDecode_TiledWithNonEqualWidthAndHeight<TPixel>(TestIm
705705
public void TiffDecoder_CanDecode_BiColorWithMissingBitsPerSample<TPixel>(TestImageProvider<TPixel> provider)
706706
where TPixel : unmanaged, IPixel<TPixel> => TestTiffDecoder(provider);
707707

708+
// https://github.com/SixLabors/ImageSharp/issues/2679
709+
[Theory]
710+
[WithFile(Issues2679, PixelTypes.Rgba32)]
711+
public void TiffDecoder_CanDecode_JpegCompressedWithIssue2679<TPixel>(TestImageProvider<TPixel> provider)
712+
where TPixel : unmanaged, IPixel<TPixel>
713+
{
714+
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);
715+
716+
// The image is handcrafted to simulate issue 2679. ImageMagick will throw an expection here and wont decode,
717+
// so we compare to reference output instead.
718+
image.DebugSave(provider);
719+
image.CompareToReferenceOutput(
720+
ImageComparer.Exact,
721+
provider,
722+
appendPixelTypeToFileName: false);
723+
}
724+
708725
[Theory]
709726
[WithFile(JpegCompressedGray0000539558, PixelTypes.Rgba32)]
710727
public void TiffDecoder_ThrowsException_WithCircular_IFD_Offsets<TPixel>(TestImageProvider<TPixel> provider)

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ public static class Tiff
11121112
public const string Issues2255 = "Tiff/Issues/Issue2255.png";
11131113
public const string Issues2435 = "Tiff/Issues/Issue2435.tiff";
11141114
public const string Issues2587 = "Tiff/Issues/Issue2587.tiff";
1115+
public const string Issues2679 = "Tiff/Issues/Issue2679.tiff";
11151116
public const string JpegCompressedGray0000539558 = "Tiff/Issues/JpegCompressedGray-0000539558.tiff";
11161117
public const string Tiled0000023664 = "Tiff/Issues/tiled-0000023664.tiff";
11171118
public const string ExtraSamplesUnspecified = "Tiff/Issues/ExtraSamplesUnspecified.tif";
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:feb938396b9d5b4c258244197ba382937a52c93f72cc91081c7e6810e4a3b94c
3+
size 6136

0 commit comments

Comments
 (0)