|
|
@ -1,6 +1,10 @@ |
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
|
using System.Buffers.Binary; |
|
|
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Bmp |
|
|
namespace SixLabors.ImageSharp.Formats.Bmp |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -13,6 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp |
|
|
/// All of the other integer values are stored in little-endian format
|
|
|
/// All of the other integer values are stored in little-endian format
|
|
|
/// (i.e. least-significant byte first).
|
|
|
/// (i.e. least-significant byte first).
|
|
|
/// </remarks>
|
|
|
/// </remarks>
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)] |
|
|
internal readonly struct BmpFileHeader |
|
|
internal readonly struct BmpFileHeader |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -44,12 +49,31 @@ namespace SixLabors.ImageSharp.Formats.Bmp |
|
|
/// Gets any reserved data; actual value depends on the application
|
|
|
/// Gets any reserved data; actual value depends on the application
|
|
|
/// that creates the image.
|
|
|
/// that creates the image.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public int Reserved { get; } |
|
|
public int Reserved { get; } |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the offset, i.e. starting address, of the byte where
|
|
|
/// Gets the offset, i.e. starting address, of the byte where
|
|
|
/// the bitmap data can be found.
|
|
|
/// the bitmap data can be found.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public int Offset { get; } |
|
|
public int Offset { get; } |
|
|
|
|
|
|
|
|
|
|
|
public unsafe void WriteTo(Span<byte> buffer) |
|
|
|
|
|
{ |
|
|
|
|
|
if (BitConverter.IsLittleEndian) |
|
|
|
|
|
{ |
|
|
|
|
|
fixed (BmpFileHeader* pointer = &this) |
|
|
|
|
|
{ |
|
|
|
|
|
MemoryMarshal.AsBytes(new ReadOnlySpan<BmpFileHeader>(pointer, 1)).CopyTo(buffer); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
// Big Endian Platform
|
|
|
|
|
|
BinaryPrimitives.WriteInt16LittleEndian(buffer.Slice(0, 2), this.Type); |
|
|
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(2, 4), this.FileSize); |
|
|
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(6, 4), this.Reserved); |
|
|
|
|
|
BinaryPrimitives.WriteInt32LittleEndian(buffer.Slice(10, 4), this.Offset); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |