diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 454440f634..322d08e4c8 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -6,7 +6,6 @@ using System.Buffers; using System.IO; using System.Runtime.InteropServices; using System.Threading; -using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Memory; @@ -340,15 +339,15 @@ namespace SixLabors.ImageSharp.Formats.Bmp { using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(this.configuration); using IndexedImageFrame quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image, image.Bounds()); + using IMemoryOwner rgbColorsBuffer = this.memoryAllocator.Allocate(quantized.Palette.Length); + Span rgbColors = rgbColorsBuffer.GetSpan(); ReadOnlySpan quantizedColors = quantized.Palette.Span; - var color = default(Rgba32); + PixelOperations.Instance.ToRgba32(Configuration.Default, quantizedColors, rgbColors); - // TODO: Use bulk conversion here for better perf int idx = 0; - foreach (TPixel quantizedColor in quantizedColors) + foreach (Rgba32 color in rgbColors) { - quantizedColor.ToRgba32(ref color); colorPalette[idx] = color.B; colorPalette[idx + 1] = color.G; colorPalette[idx + 2] = color.R;