Browse Source

Tidying up file detection

Former-commit-id: d8bb807d08a118f2ba387eae4d75bb9959b9b6f3
af/merge-core
James South 12 years ago
parent
commit
e2b2602a6f
  1. 4
      src/ImageProcessor/Imaging/Formats/BitmapFormat.cs
  2. 2
      src/ImageProcessor/Imaging/Formats/FormatBase.cs
  3. 12
      src/ImageProcessor/Imaging/Formats/FormatUtilities.cs
  4. 4
      src/ImageProcessor/Imaging/Formats/GifFormat.cs
  5. 2
      src/ImageProcessor/Imaging/Formats/ISupportedImageFormat.cs
  6. 11
      src/ImageProcessor/Imaging/Formats/JpegFormat.cs
  7. 4
      src/ImageProcessor/Imaging/Formats/PngFormat.cs
  8. 4
      src/ImageProcessor/Imaging/Formats/TiffFormat.cs

4
src/ImageProcessor/Imaging/Formats/BitmapFormat.cs

@ -21,11 +21,11 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets the file header.
/// </summary>
public override byte[][] FileHeaders
public override byte[] FileHeader
{
get
{
return new[] { Encoding.ASCII.GetBytes("BM") };
return Encoding.ASCII.GetBytes("BM");
}
}

2
src/ImageProcessor/Imaging/Formats/FormatBase.cs

@ -23,7 +23,7 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets the file header.
/// </summary>
public abstract byte[][] FileHeaders { get; }
public abstract byte[] FileHeader { get; }
/// <summary>
/// Gets the list of file extensions.

12
src/ImageProcessor/Imaging/Formats/FormatUtilities.cs

@ -43,15 +43,11 @@ namespace ImageProcessor.Imaging.Formats
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (ISupportedImageFormat supportedImageFormat in supportedImageFormats)
{
byte[][] headers = supportedImageFormat.FileHeaders;
foreach (byte[] header in headers)
byte[] header = supportedImageFormat.FileHeader;
if (header.SequenceEqual(buffer.Take(header.Length)))
{
if (header.SequenceEqual(buffer.Take(header.Length)))
{
stream.Position = 0;
return supportedImageFormat;
}
stream.Position = 0;
return supportedImageFormat;
}
}

4
src/ImageProcessor/Imaging/Formats/GifFormat.cs

@ -25,11 +25,11 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets the file header.
/// </summary>
public override byte[][] FileHeaders
public override byte[] FileHeader
{
get
{
return new[] { Encoding.ASCII.GetBytes("GIF") };
return Encoding.ASCII.GetBytes("GIF");
}
}

2
src/ImageProcessor/Imaging/Formats/ISupportedImageFormat.cs

@ -23,7 +23,7 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets the file header.
/// </summary>
byte[][] FileHeaders { get; }
byte[] FileHeader { get; }
/// <summary>
/// Gets the list of file extensions.

11
src/ImageProcessor/Imaging/Formats/JpegFormat.cs

@ -25,18 +25,11 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets the file header.
/// </summary>
public override byte[][] FileHeaders
public override byte[] FileHeader
{
get
{
return new[]
{
new byte[] { 255, 216, 255, 232 },
new byte[] { 255, 216, 255, 227 },
new byte[] { 255, 216, 255, 226 },
new byte[] { 255, 216, 255, 224 },
new byte[] { 255, 216, 255, 225 }
};
return new byte[] { 255, 216, 255 };
}
}

4
src/ImageProcessor/Imaging/Formats/PngFormat.cs

@ -22,11 +22,11 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets the file header.
/// </summary>
public override byte[][] FileHeaders
public override byte[] FileHeader
{
get
{
return new[] { new byte[] { 137, 80, 78, 71 } };
return new byte[] { 137, 80, 78, 71 };
}
}

4
src/ImageProcessor/Imaging/Formats/TiffFormat.cs

@ -23,11 +23,11 @@ namespace ImageProcessor.Imaging.Formats
/// <summary>
/// Gets the file header.
/// </summary>
public override byte[][] FileHeaders
public override byte[] FileHeader
{
get
{
return new[] { new byte[] { 77, 77, 42 } };
return new byte[] { 77, 77, 42 };
}
}

Loading…
Cancel
Save