Browse Source

Using MemoryMarshal.AsBytes in Write8BitGray to get the bytes of a row

af/merge-core
Brian Popow 7 years ago
parent
commit
b51d127bd2
  1. 23
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

23
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

@ -4,6 +4,7 @@
using System;
using System.Buffers;
using System.IO;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Common.Helpers;
@ -389,23 +390,15 @@ namespace SixLabors.ImageSharp.Formats.Bmp
stream.Write(colorPalette);
using (IMemoryOwner<byte> rowSpanBuffer = this.memoryAllocator.AllocateManagedByteBuffer(image.Width, AllocationOptions.Clean))
for (int y = image.Height - 1; y >= 0; y--)
{
Span<byte> outputPixelRow = rowSpanBuffer.GetSpan();
for (int y = image.Height - 1; y >= 0; y--)
{
Span<TPixel> inputPixelRow = image.GetPixelRowSpan(y);
PixelOperations<TPixel>.Instance.ToGray8Bytes(
this.configuration,
inputPixelRow,
outputPixelRow,
image.Width);
stream.Write(outputPixelRow);
ReadOnlySpan<TPixel> inputPixelRow = image.GetPixelRowSpan(y);
ReadOnlySpan<byte> outputPixelRow = MemoryMarshal.AsBytes(inputPixelRow);
stream.Write(outputPixelRow);
for (int i = 0; i < this.padding; i++)
{
stream.WriteByte(0);
}
for (int i = 0; i < this.padding; i++)
{
stream.WriteByte(0);
}
}
}

Loading…
Cancel
Save