Skip to content

Commit 247834f

Browse files
committed
Use bulk conversion to rgba in Write8BitColor
1 parent abc1573 commit 247834f

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.IO;
77
using System.Runtime.InteropServices;
88
using System.Threading;
9-
using System.Threading.Tasks;
109
using SixLabors.ImageSharp.Advanced;
1110
using SixLabors.ImageSharp.Common.Helpers;
1211
using SixLabors.ImageSharp.Memory;
@@ -340,15 +339,15 @@ private void Write8BitColor<TPixel>(Stream stream, ImageFrame<TPixel> image, Spa
340339
{
341340
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(this.configuration);
342341
using IndexedImageFrame<TPixel> quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image, image.Bounds());
342+
using IMemoryOwner<Rgba32> rgbColorsBuffer = this.memoryAllocator.Allocate<Rgba32>(quantized.Palette.Length);
343+
Span<Rgba32> rgbColors = rgbColorsBuffer.GetSpan();
343344

344345
ReadOnlySpan<TPixel> quantizedColors = quantized.Palette.Span;
345-
var color = default(Rgba32);
346+
PixelOperations<TPixel>.Instance.ToRgba32(Configuration.Default, quantizedColors, rgbColors);
346347

347-
// TODO: Use bulk conversion here for better perf
348348
int idx = 0;
349-
foreach (TPixel quantizedColor in quantizedColors)
349+
foreach (Rgba32 color in rgbColors)
350350
{
351-
quantizedColor.ToRgba32(ref color);
352351
colorPalette[idx] = color.B;
353352
colorPalette[idx + 1] = color.G;
354353
colorPalette[idx + 2] = color.R;

0 commit comments

Comments
 (0)