|
6 | 6 | using System.IO; |
7 | 7 | using System.Runtime.InteropServices; |
8 | 8 | using System.Threading; |
9 | | -using System.Threading.Tasks; |
10 | 9 | using SixLabors.ImageSharp.Advanced; |
11 | 10 | using SixLabors.ImageSharp.Common.Helpers; |
12 | 11 | using SixLabors.ImageSharp.Memory; |
@@ -342,20 +341,11 @@ private void Write8BitColor<TPixel>(Stream stream, ImageFrame<TPixel> image, Spa |
342 | 341 | using IndexedImageFrame<TPixel> quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image, image.Bounds()); |
343 | 342 |
|
344 | 343 | ReadOnlySpan<TPixel> quantizedColors = quantized.Palette.Span; |
345 | | - var color = default(Rgba32); |
346 | | - |
347 | | - // TODO: Use bulk conversion here for better perf |
348 | | - int idx = 0; |
349 | | - foreach (TPixel quantizedColor in quantizedColors) |
| 344 | + PixelOperations<TPixel>.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast<byte, Bgra32>(colorPalette)); |
| 345 | + Span<uint> colorPaletteAsUInt = MemoryMarshal.Cast<byte, uint>(colorPalette); |
| 346 | + for (int i = 0; i < colorPaletteAsUInt.Length; i++) |
350 | 347 | { |
351 | | - quantizedColor.ToRgba32(ref color); |
352 | | - colorPalette[idx] = color.B; |
353 | | - colorPalette[idx + 1] = color.G; |
354 | | - colorPalette[idx + 2] = color.R; |
355 | | - |
356 | | - // Padding byte, always 0. |
357 | | - colorPalette[idx + 3] = 0; |
358 | | - idx += 4; |
| 348 | + colorPaletteAsUInt[i] = colorPaletteAsUInt[i] & 0x00FFFFFF; // Padding byte, always 0. |
359 | 349 | } |
360 | 350 |
|
361 | 351 | stream.Write(colorPalette); |
|
0 commit comments