|
|
@ -16,12 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
public IImageFormat DetectFormat(ReadOnlySpan<byte> header) |
|
|
public IImageFormat DetectFormat(ReadOnlySpan<byte> header) |
|
|
{ |
|
|
{ |
|
|
if (this.IsSupportedFileFormat(header)) |
|
|
return this.IsSupportedFileFormat(header) ? ImageFormats.Jpeg : null; |
|
|
{ |
|
|
|
|
|
return ImageFormats.Jpeg; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header) |
|
|
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header) |
|
|
@ -35,36 +30,24 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
private bool IsJfif(ReadOnlySpan<byte> header) |
|
|
private bool IsJfif(ReadOnlySpan<byte> header) => |
|
|
{ |
|
|
header[6] == 0x4A && // J
|
|
|
// TODO: This should be in constants
|
|
|
header[7] == 0x46 && // F
|
|
|
bool isJfif = |
|
|
header[8] == 0x49 && // I
|
|
|
header[6] == 0x4A && // J
|
|
|
header[9] == 0x46 && // F
|
|
|
header[7] == 0x46 && // F
|
|
|
header[10] == 0x00; |
|
|
header[8] == 0x49 && // I
|
|
|
|
|
|
header[9] == 0x46 && // F
|
|
|
|
|
|
header[10] == 0x00; |
|
|
|
|
|
|
|
|
|
|
|
return isJfif; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Returns a value indicating whether the given bytes identify EXIF data.
|
|
|
/// Returns a value indicating whether the given bytes identify EXIF data.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
private bool IsExif(ReadOnlySpan<byte> header) |
|
|
private bool IsExif(ReadOnlySpan<byte> header) => |
|
|
{ |
|
|
header[6] == 0x45 && // E
|
|
|
// TODO: This should be in constants
|
|
|
header[7] == 0x78 && // X
|
|
|
bool isExif = |
|
|
header[8] == 0x69 && // I
|
|
|
header[6] == 0x45 && // E
|
|
|
header[9] == 0x66 && // F
|
|
|
header[7] == 0x78 && // X
|
|
|
header[10] == 0x00; |
|
|
header[8] == 0x69 && // I
|
|
|
|
|
|
header[9] == 0x66 && // F
|
|
|
|
|
|
header[10] == 0x00; |
|
|
|
|
|
|
|
|
|
|
|
return isExif; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Returns a value indicating whether the given bytes identify Jpeg data.
|
|
|
/// Returns a value indicating whether the given bytes identify Jpeg data.
|
|
|
@ -72,14 +55,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
private bool IsJpeg(ReadOnlySpan<byte> header) |
|
|
private bool IsJpeg(ReadOnlySpan<byte> header) => |
|
|
{ |
|
|
header[0] == 0xFF && // 255
|
|
|
// TODO: This should be in constants
|
|
|
header[1] == 0xD8; // 216
|
|
|
bool isJpg = |
|
|
|
|
|
header[0] == 0xFF && // 255
|
|
|
|
|
|
header[1] == 0xD8; // 216
|
|
|
|
|
|
|
|
|
|
|
|
return isJpg; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |