Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -853,5 +853,18 @@ public void ExtractAlphaData_WithUnsupportedBppImage_ThrowsException()
Assert.Equal($"Extracting alpha data is not supported for {bitmap.BitsPerPixel} bpp images.", exception.Message);
}

[FactWithAutomaticDisplayName]
public void LoadImage_TiffImage_ShouldLoadWithoutThumbnail()
{
// Arrange
string imagePath = GetRelativeFilePath("example.tif");

// Act
var bitmap = new AnyBitmap(imagePath);

// Assert
bitmap.FrameCount.Should().Be(1);
}

}
}
23 changes: 22 additions & 1 deletion IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,13 +2208,18 @@ private void OpenTiffToImageSharp(ReadOnlySpan<byte> bytes)
using MemoryStream tiffStream = new(bytes.ToArray());

// open a TIFF stored in the stream
using (var tif = Tiff.ClientOpen("in-memory", "r", tiffStream, new TiffStream()))
using (Tiff tif = Tiff.ClientOpen("in-memory", "r", tiffStream, new TiffStream()))
{
short num = tif.NumberOfDirectories();
for (short i = 0; i < num; i++)
{
_ = tif.SetDirectory(i);

if (IsThumbnail(tif))
{
continue;
}

var (width, height) = SetWidthHeight(tif, i, ref imageWidth, ref imageHeight);

// Read the image into the memory buffer
Expand Down Expand Up @@ -2281,6 +2286,22 @@ private void OpenTiffToImageSharp(ReadOnlySpan<byte> bytes)
}
}

/// <summary>
/// Determines if a TIFF frame contains a thumbnail.
/// </summary>
/// <param name="tif">The <see cref="Tiff"/> which set number of directory to analyze.</param>
/// <returns>True if the frame contains a thumbnail, otherwise false.</returns>
private bool IsThumbnail(Tiff tif)
{
FieldValue[] subFileTypeFieldValue = tif.GetField(TiffTag.SUBFILETYPE);

// Current thumbnail identification relies on the SUBFILETYPE tag with a value of FileType.REDUCEDIMAGE.
// This may need refinement in the future to include additional checks
// (e.g., FileType.COMPRESSION is NONE, Image Dimensions).
return subFileTypeFieldValue != null && subFileTypeFieldValue.Length > 0
&& (FileType)subFileTypeFieldValue[0].Value == FileType.REDUCEDIMAGE;
}

private ReadOnlySpan<byte> PrepareByteArray(Image<Rgba32> bmp, int[] raster, int width, int height)
{
byte[] bits = new byte[GetStride(bmp) * height];
Expand Down
2 changes: 1 addition & 1 deletion NuGet/IronSoftware.Drawing.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Supports:

For general support and technical inquiries, please email us at: support@ironsoftware.com</description>
<summary>IronSoftware.System.Drawing is an open-source solution for .NET developers to replace System.Drawing.Common with a universal and flexible library.</summary>
<releaseNotes>- Update SixLabors.ImageSharp &amp; SixLabors.ImageSharp.Drawing to address known vulnerabilities.</releaseNotes>
<releaseNotes>- TIFF images no longer load thumbnails as separate frames.</releaseNotes>
<copyright>Copyright © Iron Software 2022-2024</copyright>
<tags>Images, Bitmap, SkiaSharp, SixLabors, BitMiracle, Maui, SVG, TIFF, TIF, GIF, JPEG, PNG, Color, Rectangle, Drawing, C#, VB.NET, ASPX, create, render, generate, standard, netstandard2.0, core, netcore</tags>
<repository type="git" url="https://github.com/iron-software/IronSoftware.Drawing.Common" commit="$commit$" />
Expand Down