|
|
|
@ -10,16 +10,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff |
|
|
|
/// </summary>
|
|
|
|
public sealed class TiffImageFormatDetector : IImageFormatDetector |
|
|
|
{ |
|
|
|
private readonly bool isBigTiff; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="TiffImageFormatDetector"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="isBigTiff">if set to <c>true</c> is BigTiff.</param>
|
|
|
|
public TiffImageFormatDetector(bool isBigTiff) => this.isBigTiff = isBigTiff; |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public int HeaderSize => this.isBigTiff ? 8 : 4; |
|
|
|
public int HeaderSize => 8; |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public IImageFormat DetectFormat(ReadOnlySpan<byte> header) |
|
|
|
@ -39,39 +31,32 @@ namespace SixLabors.ImageSharp.Formats.Tiff |
|
|
|
if (header[0] == 0x49 && header[1] == 0x49) |
|
|
|
{ |
|
|
|
// Little-endian
|
|
|
|
if (this.isBigTiff is false) |
|
|
|
if (header[2] == 0x2A && header[3] == 0x00) |
|
|
|
{ |
|
|
|
if (header[2] == 0x2A && header[3] == 0x00) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
// tiff
|
|
|
|
return true; |
|
|
|
} |
|
|
|
else |
|
|
|
else if (header[2] == 0x2B && header[3] == 0x00 |
|
|
|
&& header[4] == 8 && header[5] == 0 && header[6] == 0 && header[7] == 0) |
|
|
|
{ |
|
|
|
if (header[2] == 0x2B && header[3] == 0x00 |
|
|
|
&& header[4] == 8 && header[5] == 0 && header[6] == 0 && header[7] == 0) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
// big tiff
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (header[0] == 0x4D && header[1] == 0x4D) |
|
|
|
{ |
|
|
|
// Big-endian
|
|
|
|
if (this.isBigTiff is false) |
|
|
|
if (header[2] == 0 && header[3] == 0x2A) |
|
|
|
{ |
|
|
|
if (header[2] == 0 && header[3] == 0x2A) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
// tiff
|
|
|
|
return true; |
|
|
|
} |
|
|
|
else |
|
|
|
if (header[2] == 0 && header[3] == 0x2B |
|
|
|
&& header[4] == 0 && header[5] == 8 && header[6] == 0 && header[7] == 0) |
|
|
|
{ |
|
|
|
if (header[2] == 0 && header[3] == 0x2B |
|
|
|
&& header[4] == 0 && header[5] == 8 && header[6] == 0 && header[7] == 0) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
// big tiff
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|