Skip to content

Commit fd0dd72

Browse files
Merge pull request #98 from iron-software/PDF-1130-output-pdf-has-different-visual-from-the-original-tif
PDF-1130 Load Tiff image format should not include Thumbnail
2 parents a988a3a + f5dd615 commit fd0dd72

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed
Binary file not shown.

IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/AnyBitmapFunctionality.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,5 +853,18 @@ public void ExtractAlphaData_WithUnsupportedBppImage_ThrowsException()
853853
Assert.Equal($"Extracting alpha data is not supported for {bitmap.BitsPerPixel} bpp images.", exception.Message);
854854
}
855855

856+
[FactWithAutomaticDisplayName]
857+
public void LoadImage_TiffImage_ShouldLoadWithoutThumbnail()
858+
{
859+
// Arrange
860+
string imagePath = GetRelativeFilePath("example.tif");
861+
862+
// Act
863+
var bitmap = new AnyBitmap(imagePath);
864+
865+
// Assert
866+
bitmap.FrameCount.Should().Be(1);
867+
}
868+
856869
}
857870
}

IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,13 +2208,18 @@ private void OpenTiffToImageSharp(ReadOnlySpan<byte> bytes)
22082208
using MemoryStream tiffStream = new(bytes.ToArray());
22092209

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

2218+
if (IsThumbnail(tif))
2219+
{
2220+
continue;
2221+
}
2222+
22182223
var (width, height) = SetWidthHeight(tif, i, ref imageWidth, ref imageHeight);
22192224

22202225
// Read the image into the memory buffer
@@ -2281,6 +2286,22 @@ private void OpenTiffToImageSharp(ReadOnlySpan<byte> bytes)
22812286
}
22822287
}
22832288

2289+
/// <summary>
2290+
/// Determines if a TIFF frame contains a thumbnail.
2291+
/// </summary>
2292+
/// <param name="tif">The <see cref="Tiff"/> which set number of directory to analyze.</param>
2293+
/// <returns>True if the frame contains a thumbnail, otherwise false.</returns>
2294+
private bool IsThumbnail(Tiff tif)
2295+
{
2296+
FieldValue[] subFileTypeFieldValue = tif.GetField(TiffTag.SUBFILETYPE);
2297+
2298+
// Current thumbnail identification relies on the SUBFILETYPE tag with a value of FileType.REDUCEDIMAGE.
2299+
// This may need refinement in the future to include additional checks
2300+
// (e.g., FileType.COMPRESSION is NONE, Image Dimensions).
2301+
return subFileTypeFieldValue != null && subFileTypeFieldValue.Length > 0
2302+
&& (FileType)subFileTypeFieldValue[0].Value == FileType.REDUCEDIMAGE;
2303+
}
2304+
22842305
private ReadOnlySpan<byte> PrepareByteArray(Image<Rgba32> bmp, int[] raster, int width, int height)
22852306
{
22862307
byte[] bits = new byte[GetStride(bmp) * height];

NuGet/IronSoftware.Drawing.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Supports:
3939

4040
For general support and technical inquiries, please email us at: support@ironsoftware.com</description>
4141
<summary>IronSoftware.System.Drawing is an open-source solution for .NET developers to replace System.Drawing.Common with a universal and flexible library.</summary>
42-
<releaseNotes>- Update SixLabors.ImageSharp &amp; SixLabors.ImageSharp.Drawing to address known vulnerabilities.</releaseNotes>
42+
<releaseNotes>- TIFF images no longer load thumbnails as separate frames.</releaseNotes>
4343
<copyright>Copyright © Iron Software 2022-2024</copyright>
4444
<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>
4545
<repository type="git" url="https://github.com/iron-software/IronSoftware.Drawing.Common" commit="$commit$" />

0 commit comments

Comments
 (0)