diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderMetadataCreator.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderMetadataCreator.cs
index 3001083417..327e366331 100644
--- a/src/ImageSharp/Formats/Tiff/TiffDecoderMetadataCreator.cs
+++ b/src/ImageSharp/Formats/Tiff/TiffDecoderMetadataCreator.cs
@@ -40,8 +40,6 @@ namespace SixLabors.ImageSharp.Formats.Tiff
TiffMetadata tiffMetadata = coreMetadata.GetTiffMetadata();
tiffMetadata.ByteOrder = byteOrder;
tiffMetadata.BitsPerPixel = GetBitsPerPixel(rootFrameMetadata);
- tiffMetadata.Compression = rootFrameMetadata.Compression;
- tiffMetadata.PhotometricInterpretation = rootFrameMetadata.PhotometricInterpretation;
if (!ignoreMetadata)
{
diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs
index 6654a6e4be..09fdffa249 100644
--- a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs
+++ b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs
@@ -112,8 +112,10 @@ namespace SixLabors.ImageSharp.Formats.Tiff
this.configuration = image.GetConfiguration();
ImageMetadata metadata = image.Metadata;
TiffMetadata tiffMetadata = metadata.GetTiffMetadata();
+ TiffFrameMetadata rootFrameMetaData = image.Frames.RootFrame.Metadata.GetTiffMetadata();
+ TiffPhotometricInterpretation photometricInterpretation = rootFrameMetaData.PhotometricInterpretation;
- this.SetMode(tiffMetadata);
+ this.SetMode(tiffMetadata, photometricInterpretation);
this.SetBitsPerPixel(tiffMetadata);
this.SetPhotometricInterpretation();
@@ -265,7 +267,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
return nextIfdMarker;
}
- private void SetMode(TiffMetadata tiffMetadata)
+ private void SetMode(TiffMetadata tiffMetadata, TiffPhotometricInterpretation photometricInterpretation)
{
// Make sure, that the fax compressions are only used together with the BiColor mode.
if (this.CompressionType == TiffCompression.CcittGroup3Fax || this.CompressionType == TiffCompression.Ccitt1D)
@@ -286,7 +288,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
if (this.Mode == TiffEncodingMode.Default && tiffMetadata.BitsPerPixel != null)
{
// Preserve input bits per pixel, if no encoding mode was specified.
- this.SetModeWithBitsPerPixel(tiffMetadata.BitsPerPixel, tiffMetadata.PhotometricInterpretation);
+ this.SetModeWithBitsPerPixel(tiffMetadata.BitsPerPixel, photometricInterpretation);
return;
}
@@ -294,7 +296,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
if (this.BitsPerPixel != null)
{
// The user has specified a bits per pixel, so use that to determine the encoding mode.
- this.SetModeWithBitsPerPixel(this.BitsPerPixel, tiffMetadata.PhotometricInterpretation);
+ this.SetModeWithBitsPerPixel(this.BitsPerPixel, photometricInterpretation);
}
}
diff --git a/src/ImageSharp/Formats/Tiff/TiffMetadata.cs b/src/ImageSharp/Formats/Tiff/TiffMetadata.cs
index 99777a0f31..5923e831aa 100644
--- a/src/ImageSharp/Formats/Tiff/TiffMetadata.cs
+++ b/src/ImageSharp/Formats/Tiff/TiffMetadata.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using SixLabors.ImageSharp.Formats.Tiff.Constants;
namespace SixLabors.ImageSharp.Formats.Tiff
{
@@ -26,8 +25,6 @@ namespace SixLabors.ImageSharp.Formats.Tiff
{
this.ByteOrder = other.ByteOrder;
this.BitsPerPixel = other.BitsPerPixel;
- this.Compression = other.Compression;
- this.PhotometricInterpretation = other.PhotometricInterpretation;
this.XmpProfile = other.XmpProfile != null ? new byte[other.XmpProfile.Length] : null;
other.XmpProfile?.AsSpan().CopyTo(this.XmpProfile.AsSpan());
}
@@ -38,21 +35,10 @@ namespace SixLabors.ImageSharp.Formats.Tiff
public ByteOrder ByteOrder { get; set; }
///
- /// Gets or sets the number of bits per pixel.
+ /// Gets or sets the number of bits per pixel for the root frame.
///
public TiffBitsPerPixel? BitsPerPixel { get; set; }
- ///
- /// Gets or sets the compression used to create the TIFF file.
- /// Defaults to None.
- ///
- public TiffCompression Compression { get; set; } = TiffCompression.None;
-
- ///
- /// Gets or sets the photometric interpretation which indicates how the pixels are to be interpreted, e.g. if the image is bicolor, RGB, color paletted etc.
- ///
- public TiffPhotometricInterpretation PhotometricInterpretation { get; set; }
-
///
/// Gets or sets the XMP profile.
/// For internal use only. ImageSharp not support XMP profile.
diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs
index 4242a73412..dda695568c 100644
--- a/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderTests.cs
@@ -49,8 +49,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
memStream.Position = 0;
using var output = Image.Load(Configuration, memStream);
TiffMetadata meta = output.Metadata.GetTiffMetadata();
+ TiffFrameMetadata frameMetaData = output.Frames.RootFrame.Metadata.GetTiffMetadata();
Assert.Equal(expectedBitsPerPixel, meta.BitsPerPixel);
- Assert.Equal(TiffCompression.None, meta.Compression);
+ Assert.Equal(TiffCompression.None, frameMetaData.Compression);
}
[Theory]
@@ -72,8 +73,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
memStream.Position = 0;
using var output = Image.Load(Configuration, memStream);
TiffMetadata meta = output.Metadata.GetTiffMetadata();
+ TiffFrameMetadata frameMetaData = output.Frames.RootFrame.Metadata.GetTiffMetadata();
Assert.Equal(bitsPerPixel, meta.BitsPerPixel);
- Assert.Equal(TiffCompression.None, meta.Compression);
+ Assert.Equal(TiffCompression.None, frameMetaData.Compression);
}
[Theory]
@@ -111,8 +113,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
memStream.Position = 0;
using var output = Image.Load(Configuration, memStream);
TiffMetadata meta = output.Metadata.GetTiffMetadata();
+ TiffFrameMetadata frameMetaData = output.Frames.RootFrame.Metadata.GetTiffMetadata();
Assert.Equal(expectedBitsPerPixel, meta.BitsPerPixel);
- Assert.Equal(expectedCompression, meta.Compression);
+ Assert.Equal(expectedCompression, frameMetaData.Compression);
}
[Theory]
@@ -160,9 +163,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
memStream.Position = 0;
using var output = Image.Load(Configuration, memStream);
TiffMetadata meta = output.Metadata.GetTiffMetadata();
-
+ TiffFrameMetadata frameMetaData = output.Frames.RootFrame.Metadata.GetTiffMetadata();
Assert.Equal(TiffBitsPerPixel.Bit1, meta.BitsPerPixel);
- Assert.Equal(expectedCompression, meta.Compression);
+ Assert.Equal(expectedCompression, frameMetaData.Compression);
}
[Theory]
diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs
index 5de1ce6e85..92412234bf 100644
--- a/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs
@@ -39,24 +39,18 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
byte[] xmpData = { 1, 1, 1 };
var meta = new TiffMetadata
{
- Compression = TiffCompression.Deflate,
BitsPerPixel = TiffBitsPerPixel.Bit8,
ByteOrder = ByteOrder.BigEndian,
- XmpProfile = xmpData,
- PhotometricInterpretation = TiffPhotometricInterpretation.Rgb
+ XmpProfile = xmpData
};
var clone = (TiffMetadata)meta.DeepClone();
- clone.Compression = TiffCompression.None;
clone.BitsPerPixel = TiffBitsPerPixel.Bit24;
clone.ByteOrder = ByteOrder.LittleEndian;
- clone.PhotometricInterpretation = TiffPhotometricInterpretation.YCbCr;
- Assert.False(meta.Compression == clone.Compression);
Assert.False(meta.BitsPerPixel == clone.BitsPerPixel);
Assert.False(meta.ByteOrder == clone.ByteOrder);
- Assert.False(meta.PhotometricInterpretation == clone.PhotometricInterpretation);
Assert.False(meta.XmpProfile.Equals(clone.XmpProfile));
Assert.True(meta.XmpProfile.SequenceEqual(clone.XmpProfile));
}
@@ -78,44 +72,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
Assert.Equal(expectedBitsPerPixel, tiffMetadata.BitsPerPixel);
}
- [Theory]
- [InlineData(GrayscaleUncompressed, TiffCompression.None)]
- [InlineData(RgbDeflate, TiffCompression.Deflate)]
- [InlineData(SmallRgbLzw, TiffCompression.Lzw)]
- [InlineData(Calliphora_Fax3Compressed, TiffCompression.CcittGroup3Fax)]
- [InlineData(Calliphora_Fax4Compressed, TiffCompression.CcittGroup4Fax)]
- [InlineData(Calliphora_HuffmanCompressed, TiffCompression.Ccitt1D)]
- [InlineData(Calliphora_RgbPackbits, TiffCompression.PackBits)]
- public void Identify_DetectsCorrectCompression(string imagePath, TiffCompression expectedCompression)
- {
- var testFile = TestFile.Create(imagePath);
- using var stream = new MemoryStream(testFile.Bytes, false);
-
- IImageInfo imageInfo = Image.Identify(this.configuration, stream);
-
- Assert.NotNull(imageInfo);
- TiffMetadata tiffMetadata = imageInfo.Metadata.GetTiffMetadata();
- Assert.NotNull(tiffMetadata);
- Assert.Equal(expectedCompression, tiffMetadata.Compression);
- }
-
- [Theory]
- [InlineData(Calliphora_RgbUncompressed, TiffPhotometricInterpretation.Rgb)]
- [InlineData(Calliphora_BiColorUncompressed, TiffPhotometricInterpretation.BlackIsZero)]
- [InlineData(Calliphora_PaletteUncompressed, TiffPhotometricInterpretation.PaletteColor)]
- public void Identify_DetectsCorrectPhotometricInterpretation(string imagePath, TiffPhotometricInterpretation expectedPhotometricInterpretation)
- {
- var testFile = TestFile.Create(imagePath);
- using var stream = new MemoryStream(testFile.Bytes, false);
-
- IImageInfo imageInfo = Image.Identify(this.configuration, stream);
-
- Assert.NotNull(imageInfo);
- TiffMetadata tiffMetadata = imageInfo.Metadata.GetTiffMetadata();
- Assert.NotNull(tiffMetadata);
- Assert.Equal(expectedPhotometricInterpretation, tiffMetadata.PhotometricInterpretation);
- }
-
[Theory]
[InlineData(GrayscaleUncompressed, ByteOrder.BigEndian)]
[InlineData(LittleEndianByteOrder, ByteOrder.LittleEndian)]
@@ -256,10 +212,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
// Load Tiff image
using Image image = provider.GetImage(new TiffDecoder() { IgnoreMetadata = false });
- ImageMetadata coreMeta = image.Metadata;
- TiffMetadata tiffMeta = image.Metadata.GetTiffMetadata();
- TiffFrameMetadata frameMeta = image.Frames.RootFrame.Metadata.GetTiffMetadata();
- ImageFrame frameRoot = image.Frames.RootFrame;
+ ImageMetadata inputMetaData = image.Metadata;
+ TiffMetadata tiffMetaInput = image.Metadata.GetTiffMetadata();
+ TiffFrameMetadata frameMetaInput = image.Frames.RootFrame.Metadata.GetTiffMetadata();
+ ImageFrame frameRootInput = image.Frames.RootFrame;
+
+ Assert.Equal(TiffCompression.Lzw, frameMetaInput.Compression);
+ Assert.Equal(TiffBitsPerPixel.Bit4, tiffMetaInput.BitsPerPixel);
// Save to Tiff
var tiffEncoder = new TiffEncoder() { Mode = TiffEncodingMode.Rgb };
@@ -273,54 +232,52 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
// Assert
ms.Position = 0;
- using var output = Image.Load(this.configuration, ms);
+ using var encodedImage = Image.Load(this.configuration, ms);
- ImageMetadata coreMetaOut = output.Metadata;
- TiffMetadata tiffMetaOut = output.Metadata.GetTiffMetadata();
- TiffFrameMetadata frameMetaOut = output.Frames.RootFrame.Metadata.GetTiffMetadata();
- ImageFrame rootFrameOut = output.Frames.RootFrame;
+ ImageMetadata encodedImageMetaData = encodedImage.Metadata;
+ TiffMetadata tiffMetaDataEncodedImage = encodedImage.Metadata.GetTiffMetadata();
+ TiffFrameMetadata tiffMetaDataEncodedRootFrame = encodedImage.Frames.RootFrame.Metadata.GetTiffMetadata();
+ ImageFrame rootFrameEncodedImage = encodedImage.Frames.RootFrame;
- Assert.Equal(TiffBitsPerPixel.Bit4, tiffMeta.BitsPerPixel);
- Assert.Equal(TiffBitsPerPixel.Bit24, tiffMetaOut.BitsPerPixel);
- Assert.Equal(TiffCompression.Lzw, tiffMeta.Compression);
- Assert.Equal(TiffCompression.None, tiffMetaOut.Compression);
+ Assert.Equal(TiffBitsPerPixel.Bit24, tiffMetaDataEncodedImage.BitsPerPixel);
+ Assert.Equal(TiffCompression.None, tiffMetaDataEncodedRootFrame.Compression);
- Assert.Equal(coreMeta.HorizontalResolution, coreMetaOut.HorizontalResolution);
- Assert.Equal(coreMeta.VerticalResolution, coreMetaOut.VerticalResolution);
- Assert.Equal(coreMeta.ResolutionUnits, coreMetaOut.ResolutionUnits);
+ Assert.Equal(inputMetaData.HorizontalResolution, encodedImageMetaData.HorizontalResolution);
+ Assert.Equal(inputMetaData.VerticalResolution, encodedImageMetaData.VerticalResolution);
+ Assert.Equal(inputMetaData.ResolutionUnits, encodedImageMetaData.ResolutionUnits);
- Assert.Equal(frameRoot.Width, rootFrameOut.Width);
- Assert.Equal(frameRoot.Height, rootFrameOut.Height);
- Assert.Equal(frameMeta.ResolutionUnit, frameMetaOut.ResolutionUnit);
- Assert.Equal(frameMeta.HorizontalResolution, frameMetaOut.HorizontalResolution);
- Assert.Equal(frameMeta.VerticalResolution, frameMetaOut.VerticalResolution);
+ Assert.Equal(frameRootInput.Width, rootFrameEncodedImage.Width);
+ Assert.Equal(frameRootInput.Height, rootFrameEncodedImage.Height);
+ Assert.Equal(frameMetaInput.ResolutionUnit, tiffMetaDataEncodedRootFrame.ResolutionUnit);
+ Assert.Equal(frameMetaInput.HorizontalResolution, tiffMetaDataEncodedRootFrame.HorizontalResolution);
+ Assert.Equal(frameMetaInput.VerticalResolution, tiffMetaDataEncodedRootFrame.VerticalResolution);
if (preserveMetadata)
{
- Assert.Equal(tiffMeta.XmpProfile, tiffMetaOut.XmpProfile);
+ Assert.Equal(tiffMetaInput.XmpProfile, tiffMetaDataEncodedImage.XmpProfile);
- Assert.Equal("IrfanView", frameMeta.ExifProfile.GetValue(ExifTag.Software).Value);
- Assert.Equal("This is Название", frameMeta.ExifProfile.GetValue(ExifTag.ImageDescription).Value);
- Assert.Equal("This is Изготовитель камеры", frameMeta.ExifProfile.GetValue(ExifTag.Make).Value);
- Assert.Equal("This is Авторские права", frameMeta.ExifProfile.GetValue(ExifTag.Copyright).Value);
+ Assert.Equal("IrfanView", frameMetaInput.ExifProfile.GetValue(ExifTag.Software).Value);
+ Assert.Equal("This is Название", frameMetaInput.ExifProfile.GetValue(ExifTag.ImageDescription).Value);
+ Assert.Equal("This is Изготовитель камеры", frameMetaInput.ExifProfile.GetValue(ExifTag.Make).Value);
+ Assert.Equal("This is Авторские права", frameMetaInput.ExifProfile.GetValue(ExifTag.Copyright).Value);
- Assert.Equal(frameMeta.ExifProfile.GetValue(ExifTag.ImageDescription).Value, frameMetaOut.ExifProfile.GetValue(ExifTag.ImageDescription).Value);
- Assert.Equal(frameMeta.ExifProfile.GetValue(ExifTag.Make).Value, frameMetaOut.ExifProfile.GetValue(ExifTag.Make).Value);
- Assert.Equal(frameMeta.ExifProfile.GetValue(ExifTag.Copyright).Value, frameMetaOut.ExifProfile.GetValue(ExifTag.Copyright).Value);
+ Assert.Equal(frameMetaInput.ExifProfile.GetValue(ExifTag.ImageDescription).Value, tiffMetaDataEncodedRootFrame.ExifProfile.GetValue(ExifTag.ImageDescription).Value);
+ Assert.Equal(frameMetaInput.ExifProfile.GetValue(ExifTag.Make).Value, tiffMetaDataEncodedRootFrame.ExifProfile.GetValue(ExifTag.Make).Value);
+ Assert.Equal(frameMetaInput.ExifProfile.GetValue(ExifTag.Copyright).Value, tiffMetaDataEncodedRootFrame.ExifProfile.GetValue(ExifTag.Copyright).Value);
}
else
{
- Assert.Null(tiffMetaOut.XmpProfile);
+ Assert.Null(tiffMetaDataEncodedImage.XmpProfile);
- Assert.Equal("ImageSharp", frameMetaOut.ExifProfile.GetValue(ExifTag.Software).Value);
- Assert.Null(frameMeta.ExifProfile.GetValue(ExifTag.Software)?.Value);
- Assert.Null(frameMeta.ExifProfile.GetValue(ExifTag.ImageDescription)?.Value);
- Assert.Null(frameMeta.ExifProfile.GetValue(ExifTag.Make)?.Value);
- Assert.Null(frameMeta.ExifProfile.GetValue(ExifTag.Copyright)?.Value);
+ Assert.Equal("ImageSharp", tiffMetaDataEncodedRootFrame.ExifProfile.GetValue(ExifTag.Software).Value);
+ Assert.Null(frameMetaInput.ExifProfile.GetValue(ExifTag.Software)?.Value);
+ Assert.Null(frameMetaInput.ExifProfile.GetValue(ExifTag.ImageDescription)?.Value);
+ Assert.Null(frameMetaInput.ExifProfile.GetValue(ExifTag.Make)?.Value);
+ Assert.Null(frameMetaInput.ExifProfile.GetValue(ExifTag.Copyright)?.Value);
- Assert.Null(frameMetaOut.ExifProfile.GetValue(ExifTag.ImageDescription)?.Value);
- Assert.Null(frameMetaOut.ExifProfile.GetValue(ExifTag.Make)?.Value);
- Assert.Null(frameMetaOut.ExifProfile.GetValue(ExifTag.Copyright)?.Value);
+ Assert.Null(tiffMetaDataEncodedRootFrame.ExifProfile.GetValue(ExifTag.ImageDescription)?.Value);
+ Assert.Null(tiffMetaDataEncodedRootFrame.ExifProfile.GetValue(ExifTag.Make)?.Value);
+ Assert.Null(tiffMetaDataEncodedRootFrame.ExifProfile.GetValue(ExifTag.Copyright)?.Value);
}
}