Browse Source

Fix failing tests

pull/1553/head
Brian Popow 5 years ago
parent
commit
508844ad60
  1. 21
      src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs
  2. 2
      tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs

21
src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs

@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
// TODO: This isn't correct.
// We're overwriting explicit BPP based upon the Mode. It should be the other way around.
// BPP should also be nullable and based upon the current TPixel if not set.
this.SetBitsPerPixel(rootFrameBitsPerPixel);
this.SetBitsPerPixel(rootFrameBitsPerPixel, photometricInterpretation);
this.SetMode(photometricInterpretation);
this.SetPhotometricInterpretation();
@ -286,6 +286,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
if (this.Mode == TiffEncodingMode.Default)
{
this.Mode = TiffEncodingMode.BiColor;
this.BitsPerPixel = TiffBitsPerPixel.Bit1;
return;
}
@ -321,9 +322,25 @@ namespace SixLabors.ImageSharp.Formats.Tiff
}
}
private void SetBitsPerPixel(TiffBitsPerPixel? rootFrameBitsPerPixel)
private void SetBitsPerPixel(TiffBitsPerPixel? rootFrameBitsPerPixel, TiffPhotometricInterpretation photometricInterpretation)
{
this.BitsPerPixel ??= rootFrameBitsPerPixel;
if (photometricInterpretation == TiffPhotometricInterpretation.PaletteColor)
{
if (this.BitsPerPixel != TiffBitsPerPixel.Bit8 && this.BitsPerPixel != TiffBitsPerPixel.Bit4)
{
this.BitsPerPixel = TiffBitsPerPixel.Bit8;
}
return;
}
if (this.BitsPerPixel.HasValue)
{
return;
}
switch (this.Mode)
{
case TiffEncodingMode.BiColor:

2
tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs

@ -236,7 +236,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
ExifProfile encodedImageExifProfile = rootFrameEncodedImage.Metadata.ExifProfile;
byte[] encodedImageXmpProfile = rootFrameEncodedImage.Metadata.XmpProfile;
Assert.Equal(TiffBitsPerPixel.Bit24, tiffMetaDataEncodedRootFrame.BitsPerPixel);
Assert.Equal(TiffBitsPerPixel.Bit4, tiffMetaDataEncodedRootFrame.BitsPerPixel);
Assert.Equal(TiffCompression.None, (TiffCompression)encodedImageExifProfile.GetValue(ExifTag.Compression).Value);
Assert.Equal(inputMetaData.HorizontalResolution, encodedImageMetaData.HorizontalResolution);

Loading…
Cancel
Save