|
|
|
@ -13,41 +13,6 @@ namespace ImageSharp.Formats |
|
|
|
/// </summary>
|
|
|
|
public class JpegDecoder : IImageDecoder |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Gets the size of the header for this image type.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The size of the header.</value>
|
|
|
|
public int HeaderSize => 11; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Indicates if the image decoder supports the specified
|
|
|
|
/// file header.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="header">The file header.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// <c>true</c>, if the decoder supports the specified
|
|
|
|
/// file header; otherwise <c>false</c>.
|
|
|
|
/// </returns>
|
|
|
|
/// <exception cref="System.ArgumentNullException"><paramref name="header"/>
|
|
|
|
/// is null (Nothing in Visual Basic).</exception>
|
|
|
|
public bool IsSupportedFileFormat(byte[] header) |
|
|
|
{ |
|
|
|
Guard.NotNull(header, "header"); |
|
|
|
|
|
|
|
bool isSupported = false; |
|
|
|
|
|
|
|
if (header.Length >= 11) |
|
|
|
{ |
|
|
|
bool isJfif = IsJfif(header); |
|
|
|
bool isExif = IsExif(header); |
|
|
|
bool isJpeg = IsJpeg(header); |
|
|
|
|
|
|
|
isSupported = isJfif || isExif || isJpeg; |
|
|
|
} |
|
|
|
|
|
|
|
return isSupported; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream) |
|
|
|
where TColor : struct, IPackedPixel<TPacked> |
|
|
|
@ -61,54 +26,5 @@ namespace ImageSharp.Formats |
|
|
|
decoder.Decode(image, stream, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a value indicating whether the given bytes identify Jfif data.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
|
private static bool IsJfif(byte[] header) |
|
|
|
{ |
|
|
|
bool isJfif = |
|
|
|
header[6] == 0x4A && // J
|
|
|
|
header[7] == 0x46 && // F
|
|
|
|
header[8] == 0x49 && // I
|
|
|
|
header[9] == 0x46 && // F
|
|
|
|
header[10] == 0x00; |
|
|
|
|
|
|
|
return isJfif; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a value indicating whether the given bytes identify EXIF data.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
|
private static bool IsExif(byte[] header) |
|
|
|
{ |
|
|
|
bool isExif = |
|
|
|
header[6] == 0x45 && // E
|
|
|
|
header[7] == 0x78 && // X
|
|
|
|
header[8] == 0x69 && // I
|
|
|
|
header[9] == 0x66 && // F
|
|
|
|
header[10] == 0x00; |
|
|
|
|
|
|
|
return isExif; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a value indicating whether the given bytes identify Jpeg data.
|
|
|
|
/// This is a last chance resort for jpegs that contain ICC information.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="header">The bytes representing the file header.</param>
|
|
|
|
/// <returns>The <see cref="bool"/></returns>
|
|
|
|
private static bool IsJpeg(byte[] header) |
|
|
|
{ |
|
|
|
bool isJpg = |
|
|
|
header[0] == 0xFF && // 255
|
|
|
|
header[1] == 0xD8; // 216
|
|
|
|
|
|
|
|
return isJpg; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|