Skip to content

Commit 5931537

Browse files
committed
fix new 8bit bmp code
1 parent 86d884c commit 5931537

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,15 @@ private void Write8Bit<TPixel>(Stream stream, ImageFrame<TPixel> image)
306306
where TPixel : struct, IPixel<TPixel>
307307
{
308308
using (IMemoryOwner<byte> colorPaletteBuffer = this.memoryAllocator.AllocateManagedByteBuffer(ColorPaletteSize8Bit, AllocationOptions.Clean))
309-
using (QuantizedFrame<TPixel> quantized = this.quantizer.CreateFrameQuantizer<TPixel>(this.configuration, 256).QuantizeFrame(image))
309+
using (IQuantizedFrame<TPixel> quantized = this.quantizer.CreateFrameQuantizer<TPixel>(this.configuration, 256).QuantizeFrame(image))
310310
{
311311
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
312312
int idx = 0;
313313
var color = default(Rgba32);
314-
foreach (TPixel quantizedColor in quantized.Palette)
314+
ReadOnlySpan<TPixel> paletteSpan = quantized.Palette.Span;
315+
316+
// TODO: Use bulk conversion here for better perf
317+
foreach (TPixel quantizedColor in paletteSpan)
315318
{
316319
quantizedColor.ToRgba32(ref color);
317320
colorPalette[idx] = color.B;
@@ -327,7 +330,7 @@ private void Write8Bit<TPixel>(Stream stream, ImageFrame<TPixel> image)
327330

328331
for (int y = image.Height - 1; y >= 0; y--)
329332
{
330-
Span<byte> pixelSpan = quantized.GetRowSpan(y);
333+
ReadOnlySpan<byte> pixelSpan = quantized.GetRowSpan(y);
331334
stream.Write(pixelSpan);
332335

333336
for (int i = 0; i < this.padding; i++)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
1616
{
1717
using static TestImages.Bmp;
1818

19-
public class BmpEncoderTests : FileTestBase
19+
public class BmpEncoderTests
2020
{
2121
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel =
2222
new TheoryData<BmpBitsPerPixel>

0 commit comments

Comments
 (0)