Browse Source

Minor cleanup

af/merge-core
Jason Nelson 8 years ago
parent
commit
12554abf89
  1. 28
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

28
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -163,18 +163,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int Invert(int y, int height, bool inverted) private static int Invert(int y, int height, bool inverted)
{ {
int row; return (!inverted) ? height - y - 1 : y;
if (!inverted)
{
row = height - y - 1;
}
else
{
row = y;
}
return row;
} }
/// <summary> /// <summary>
@ -348,7 +337,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
using (IManagedByteBuffer row = this.memoryManager.AllocateCleanManagedByteBuffer(arrayWidth + padding)) using (IManagedByteBuffer row = this.memoryManager.AllocateCleanManagedByteBuffer(arrayWidth + padding))
{ {
var color = default(TPixel); TPixel color = default;
var rgba = new Rgba32(0, 0, 0, 255); var rgba = new Rgba32(0, 0, 0, 255);
Span<byte> rowSpan = row.Span; Span<byte> rowSpan = row.Span;
@ -478,14 +467,15 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// </summary> /// </summary>
private void ReadInfoHeader() private void ReadInfoHeader()
{ {
byte[] buffer = new byte[BmpInfoHeader.MaxHeaderSize]; // TODO: Stackalloc byte[] buffer = new byte[BmpInfoHeader.MaxHeaderSize]; // TODO: stackalloc
// read header size // read header size
this.stream.Read(buffer, 0, BmpInfoHeader.HeaderSizeSize); this.stream.Read(buffer, 0, BmpInfoHeader.HeaderSizeSize);
int headerSize = BitConverter.ToInt32(buffer, 0); int headerSize = BitConverter.ToInt32(buffer, 0);
if (headerSize < BmpInfoHeader.CoreSize) if (headerSize < BmpInfoHeader.CoreSize)
{ {
throw new NotSupportedException($"This kind of bitmap files (header size $headerSize) is not supported."); throw new NotSupportedException($"ImageSharp does not support this BMP file. HeaderSize: {headerSize}.");
} }
int skipAmount = 0; int skipAmount = 0;
@ -522,11 +512,11 @@ namespace SixLabors.ImageSharp.Formats.Bmp
/// </summary> /// </summary>
private void ReadFileHeader() private void ReadFileHeader()
{ {
byte[] data = new byte[BmpFileHeader.Size]; // TODO: Stackalloc byte[] buffer = new byte[BmpFileHeader.Size]; // TODO: stackalloc
this.stream.Read(data, 0, BmpFileHeader.Size); this.stream.Read(buffer, 0, BmpFileHeader.Size);
this.fileHeader = BmpFileHeader.Parse(data); this.fileHeader = BmpFileHeader.Parse(buffer);
} }
/// <summary> /// <summary>
@ -587,7 +577,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
if (this.infoHeader.Width > int.MaxValue || this.infoHeader.Height > int.MaxValue) if (this.infoHeader.Width > int.MaxValue || this.infoHeader.Height > int.MaxValue)
{ {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(
$"The input bitmap '{this.infoHeader.Width}x{this.infoHeader.Height}' is " $"The input bmp '{this.infoHeader.Width}x{this.infoHeader.Height}' is "
+ $"bigger then the max allowed size '{int.MaxValue}x{int.MaxValue}'"); + $"bigger then the max allowed size '{int.MaxValue}x{int.MaxValue}'");
} }
} }

Loading…
Cancel
Save