|
|
|
@ -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; |
|
|
|
@ -342,20 +341,11 @@ namespace SixLabors.ImageSharp.Formats.Bmp |
|
|
|
using IndexedImageFrame<TPixel> quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image, image.Bounds()); |
|
|
|
|
|
|
|
ReadOnlySpan<TPixel> quantizedColors = quantized.Palette.Span; |
|
|
|
var color = default(Rgba32); |
|
|
|
|
|
|
|
// TODO: Use bulk conversion here for better perf
|
|
|
|
int idx = 0; |
|
|
|
foreach (TPixel quantizedColor in quantizedColors) |
|
|
|
PixelOperations<TPixel>.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast<byte, Bgra32>(colorPalette)); |
|
|
|
Span<uint> colorPaletteAsUInt = MemoryMarshal.Cast<byte, uint>(colorPalette); |
|
|
|
for (int i = 0; i < colorPaletteAsUInt.Length; i++) |
|
|
|
{ |
|
|
|
quantizedColor.ToRgba32(ref color); |
|
|
|
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); |
|
|
|
|