Browse Source

Handle white as zero based on photometric interpretation

pull/1570/head
Brian Popow 6 years ago
parent
commit
fbce81b604
  1. 8
      src/ImageSharp/Formats/Tiff/Compression/T4TiffCompression.cs
  2. 10
      src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs
  3. 4
      src/ImageSharp/Formats/Tiff/Compression/TiffCompressionFactory.cs
  4. 4
      src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs

8
src/ImageSharp/Formats/Tiff/Compression/T4TiffCompression.cs

@ -16,16 +16,16 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression
/// Initializes a new instance of the <see cref="T4TiffCompression" /> class.
/// </summary>
/// <param name="allocator">The memory allocator.</param>
public T4TiffCompression(MemoryAllocator allocator)
: base(allocator)
/// <param name="photometricInterpretation">The photometric interpretation.</param>
public T4TiffCompression(MemoryAllocator allocator, TiffPhotometricInterpretation photometricInterpretation)
: base(allocator, photometricInterpretation)
{
}
/// <inheritdoc/>
public override void Decompress(Stream stream, int byteCount, Span<byte> buffer)
{
// TODO: handle case when white is not zero.
bool isWhiteZero = true;
bool isWhiteZero = this.PhotometricInterpretation == TiffPhotometricInterpretation.WhiteIsZero;
int whiteValue = isWhiteZero ? 0 : 1;
int blackValue = isWhiteZero ? 1 : 0;

10
src/ImageSharp/Formats/Tiff/Compression/TiffBaseCompression.cs

@ -14,10 +14,20 @@ namespace SixLabors.ImageSharp.Formats.Tiff
{
private readonly MemoryAllocator allocator;
private TiffPhotometricInterpretation photometricInterpretation;
public TiffBaseCompression(MemoryAllocator allocator) => this.allocator = allocator;
public TiffBaseCompression(MemoryAllocator allocator, TiffPhotometricInterpretation photometricInterpretation)
{
this.allocator = allocator;
this.photometricInterpretation = photometricInterpretation;
}
protected MemoryAllocator Allocator => this.allocator;
protected TiffPhotometricInterpretation PhotometricInterpretation => this.photometricInterpretation;
/// <summary>
/// Decompresses image data into the supplied buffer.
/// </summary>

4
src/ImageSharp/Formats/Tiff/Compression/TiffCompressionFactory.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
{
internal static class TiffCompressionFactory
{
public static TiffBaseCompression Create(TiffCompressionType compressionType, MemoryAllocator allocator)
public static TiffBaseCompression Create(TiffCompressionType compressionType, MemoryAllocator allocator, TiffPhotometricInterpretation photometricInterpretation)
{
switch (compressionType)
{
@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
case TiffCompressionType.Lzw:
return new LzwTiffCompression(allocator);
case TiffCompressionType.T4:
return new T4TiffCompression(allocator);
return new T4TiffCompression(allocator, photometricInterpretation);
default:
throw TiffThrowHelper.NotSupportedCompression(nameof(compressionType));
}

4
src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs

@ -276,7 +276,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
stripBuffers[stripIndex] = this.memoryAllocator.AllocateManagedByteBuffer(uncompressedStripSize);
}
TiffBaseCompression decompressor = TiffCompressionFactory.Create(this.CompressionType, this.memoryAllocator);
TiffBaseCompression decompressor = TiffCompressionFactory.Create(this.CompressionType, this.memoryAllocator, this.PhotometricInterpretation);
RgbPlanarTiffColor<TPixel> colorDecoder = TiffColorDecoderFactory<TPixel>.CreatePlanar(this.ColorType, this.BitsPerSample, this.ColorMap);
@ -313,7 +313,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
Buffer2D<TPixel> pixels = frame.PixelBuffer;
TiffBaseCompression decompressor = TiffCompressionFactory.Create(this.CompressionType, this.memoryAllocator);
TiffBaseCompression decompressor = TiffCompressionFactory.Create(this.CompressionType, this.memoryAllocator, this.PhotometricInterpretation);
TiffBaseColorDecoder<TPixel> colorDecoder = TiffColorDecoderFactory<TPixel>.Create(this.ColorType, this.BitsPerSample, this.ColorMap);

Loading…
Cancel
Save