From 85b65d393ab131ca9afc1e439729ff9d07a8cdff Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 15 Nov 2020 19:20:59 +0100 Subject: [PATCH] Use colorPalette span as destination of bulk conversion --- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index c7e7a534b..01bdbd1c0 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -339,22 +339,13 @@ 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; - PixelOperations.Instance.ToRgba32(this.configuration, quantizedColors, rgbColors); - - int idx = 0; - foreach (Rgba32 color in rgbColors) + PixelOperations.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast(colorPalette)); + Span colorPaletteAsUInt = MemoryMarshal.Cast(colorPalette); + for (int i = 0; i < colorPaletteAsUInt.Length; i++) { - colorPalette[idx] = color.B; - colorPalette[idx + 1] = color.G; - colorPalette[idx + 2] = color.R; - - // Padding byte, always 0. - colorPalette[idx + 3] = 0; - idx += 4; + colorPaletteAsUInt[i] = colorPaletteAsUInt[i] & 0x00FFFFFF; // Padding byte, always 0. } stream.Write(colorPalette);