Implement Identify methods and add tests. Report not supported Predictor and SampleFormat features.pull/1330/head
@ -1,42 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff |
|||
{ |
|||
internal static class CompressionFactory |
|||
{ |
|||
/// <summary>
|
|||
/// Decompresses an image block from the input stream into the specified buffer.
|
|||
/// </summary>
|
|||
/// <param name="stream">The input stream.</param>
|
|||
/// <param name="compressionType">Type of the compression.</param>
|
|||
/// <param name="offset">The offset within the file of the image block.</param>
|
|||
/// <param name="byteCount">The size (in bytes) of the compressed data.</param>
|
|||
/// <param name="buffer">The buffer to write the uncompressed data.</param>
|
|||
public static void DecompressImageBlock(Stream stream, TiffCompressionType compressionType, uint offset, uint byteCount, byte[] buffer) |
|||
{ |
|||
stream.Seek(offset, SeekOrigin.Begin); |
|||
|
|||
switch (compressionType) |
|||
{ |
|||
case TiffCompressionType.None: |
|||
NoneTiffCompression.Decompress(stream, (int)byteCount, buffer); |
|||
break; |
|||
case TiffCompressionType.PackBits: |
|||
PackBitsTiffCompression.Decompress(stream, (int)byteCount, buffer); |
|||
break; |
|||
case TiffCompressionType.Deflate: |
|||
DeflateTiffCompression.Decompress(stream, (int)byteCount, buffer); |
|||
break; |
|||
case TiffCompressionType.Lzw: |
|||
LzwTiffCompression.Decompress(stream, (int)byteCount, buffer); |
|||
break; |
|||
default: |
|||
throw new InvalidOperationException(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff |
|||
{ |
|||
/// <summary>
|
|||
/// Base tiff decompressor class.
|
|||
/// </summary>
|
|||
internal abstract class TiffBaseCompression |
|||
{ |
|||
private readonly MemoryAllocator allocator; |
|||
|
|||
public TiffBaseCompression(MemoryAllocator allocator) => this.allocator = allocator; |
|||
|
|||
protected MemoryAllocator Allocator => this.allocator; |
|||
|
|||
/// <summary>
|
|||
/// Decompresses image data into the supplied buffer.
|
|||
/// </summary>
|
|||
/// <param name="stream">The <see cref="Stream"/> to read image data from.</param>
|
|||
/// <param name="byteCount">The number of bytes to read from the input stream.</param>
|
|||
/// <param name="buffer">The output buffer for uncompressed data.</param>
|
|||
public abstract void Decompress(Stream stream, int byteCount, Span<byte> buffer); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Memory; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff |
|||
{ |
|||
internal static class TiffCompressionFactory |
|||
{ |
|||
public static TiffBaseCompression Create(TiffCompressionType compressionType, MemoryAllocator allocator) |
|||
{ |
|||
switch (compressionType) |
|||
{ |
|||
case TiffCompressionType.None: |
|||
return new NoneTiffCompression(allocator); |
|||
case TiffCompressionType.PackBits: |
|||
return new PackBitsTiffCompression(allocator); |
|||
case TiffCompressionType.Deflate: |
|||
return new DeflateTiffCompression(allocator); |
|||
case TiffCompressionType.Lzw: |
|||
return new LzwTiffCompression(allocator); |
|||
default: |
|||
throw new InvalidOperationException(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff |
|||
{ |
|||
/// <summary>
|
|||
/// A mathematical operator that is applied to the image data before an encoding scheme is applied.
|
|||
/// </summary>
|
|||
public enum TiffPredictor : ushort |
|||
{ |
|||
/// <summary>
|
|||
/// No prediction scheme used before coding
|
|||
/// </summary>
|
|||
None = 1, |
|||
|
|||
/// <summary>
|
|||
/// Horizontal differencing.
|
|||
/// </summary>
|
|||
Horizontal = 2, |
|||
|
|||
/// <summary>
|
|||
/// Floating point horizontal differencing.
|
|||
/// </summary>
|
|||
FloatingPoint = 3 |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff |
|||
{ |
|||
/// <summary>
|
|||
/// Specifies how to interpret each data sample in a pixel.
|
|||
/// </summary>
|
|||
public enum TiffSampleFormat : ushort |
|||
{ |
|||
/// <summary>
|
|||
/// Unsigned integer data. Default value.
|
|||
/// </summary>
|
|||
UnsignedInteger = 1, |
|||
|
|||
/// <summary>
|
|||
/// Signed integer data.
|
|||
/// </summary>
|
|||
SignedInteger = 2, |
|||
|
|||
/// <summary>
|
|||
/// IEEE floating point data.
|
|||
/// </summary>
|
|||
Float = 3, |
|||
|
|||
/// <summary>
|
|||
/// Undefined data format.
|
|||
/// </summary>
|
|||
Undefined = 4, |
|||
|
|||
/// <summary>
|
|||
/// The complex int.
|
|||
/// </summary>
|
|||
ComplexInt = 5, |
|||
|
|||
/// <summary>
|
|||
/// The complex float.
|
|||
/// </summary>
|
|||
ComplexFloat = 6 |
|||
} |
|||
} |
|||
|
Before Width: | Height: | Size: 1.6 MiB |
|
Before Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 197 B |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 1.6 MiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.6 MiB |
|
Before Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 821 B |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 208 B |