Browse Source

fix new 8bit bmp code

pull/908/head
Anton Firszov 7 years ago
parent
commit
5931537429
  1. 9
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  2. 2
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

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

@ -306,12 +306,15 @@ namespace SixLabors.ImageSharp.Formats.Bmp
where TPixel : struct, IPixel<TPixel>
{
using (IMemoryOwner<byte> colorPaletteBuffer = this.memoryAllocator.AllocateManagedByteBuffer(ColorPaletteSize8Bit, AllocationOptions.Clean))
using (QuantizedFrame<TPixel> quantized = this.quantizer.CreateFrameQuantizer<TPixel>(this.configuration, 256).QuantizeFrame(image))
using (IQuantizedFrame<TPixel> quantized = this.quantizer.CreateFrameQuantizer<TPixel>(this.configuration, 256).QuantizeFrame(image))
{
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
int idx = 0;
var color = default(Rgba32);
foreach (TPixel quantizedColor in quantized.Palette)
ReadOnlySpan<TPixel> paletteSpan = quantized.Palette.Span;
// TODO: Use bulk conversion here for better perf
foreach (TPixel quantizedColor in paletteSpan)
{
quantizedColor.ToRgba32(ref color);
colorPalette[idx] = color.B;
@ -327,7 +330,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
for (int y = image.Height - 1; y >= 0; y--)
{
Span<byte> pixelSpan = quantized.GetRowSpan(y);
ReadOnlySpan<byte> pixelSpan = quantized.GetRowSpan(y);
stream.Write(pixelSpan);
for (int i = 0; i < this.padding; i++)

2
tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
{
using static TestImages.Bmp;
public class BmpEncoderTests : FileTestBase
public class BmpEncoderTests
{
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel =
new TheoryData<BmpBitsPerPixel>

Loading…
Cancel
Save