Skip to content

Commit

Permalink
Merge branch 'main' into js/multisize-tiff
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants authored Aug 8, 2024
2 parents 4d67be8 + 350e439 commit 7561f56
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ImageSharp/Formats/Tiff/TiffDecoderOptionsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
}

options.CompressionType = TiffDecoderCompressionType.OldJpeg;

if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr)
{
// Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.
Expand All @@ -585,6 +584,14 @@ private static void ParseCompression(this TiffDecoderCore options, TiffCompressi
case TiffCompression.Jpeg:
options.CompressionType = TiffDecoderCompressionType.Jpeg;

// Some tiff encoder set this to values different from [1, 1]. The jpeg decoder already handles this,
// so we set this always to [1, 1], see: https://github.com/SixLabors/ImageSharp/issues/2679
if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr && options.YcbcrSubSampling != null)
{
options.YcbcrSubSampling[0] = 1;
options.YcbcrSubSampling[1] = 1;
}

if (options.PhotometricInterpretation is TiffPhotometricInterpretation.YCbCr && options.JpegTables is null)
{
// Note: Setting PhotometricInterpretation and color type to RGB here, since the jpeg decoder will handle the conversion of the pixel data.
Expand Down
17 changes: 17 additions & 0 deletions tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,23 @@ public void TiffDecoder_CanDecode_TiledWithNonEqualWidthAndHeight<TPixel>(TestIm
public void TiffDecoder_CanDecode_BiColorWithMissingBitsPerSample<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffDecoder(provider);

// https://github.com/SixLabors/ImageSharp/issues/2679
[Theory]
[WithFile(Issues2679, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_JpegCompressedWithIssue2679<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(TiffDecoder.Instance);

// The image is handcrafted to simulate issue 2679. ImageMagick will throw an expection here and wont decode,
// so we compare to rererence output instead.
image.DebugSave(provider);
image.CompareToReferenceOutput(
ImageComparer.Exact,
provider,
appendPixelTypeToFileName: false);
}

[Theory]
[WithFile(JpegCompressedGray0000539558, PixelTypes.Rgba32)]
public void TiffDecoder_ThrowsException_WithCircular_IFD_Offsets<TPixel>(TestImageProvider<TPixel> provider)
Expand Down
1 change: 1 addition & 0 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ public static class Tiff
public const string Issues2255 = "Tiff/Issues/Issue2255.png";
public const string Issues2435 = "Tiff/Issues/Issue2435.tiff";
public const string Issues2587 = "Tiff/Issues/Issue2587.tiff";
public const string Issues2679 = "Tiff/Issues/Issue2679.tiff";
public const string JpegCompressedGray0000539558 = "Tiff/Issues/JpegCompressedGray-0000539558.tiff";
public const string Tiled0000023664 = "Tiff/Issues/tiled-0000023664.tiff";

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/Images/Input/Tiff/Issues/Issue2679.tiff
Git LFS file not shown

0 comments on commit 7561f56

Please sign in to comment.