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. 13
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

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

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

Loading…
Cancel
Save