Browse Source

Convert pixels to bgra with ToBgra32Bytes

pull/1552/head
Brian Popow 5 years ago
parent
commit
b0c6d73978
  1. 13
      src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs

13
src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs

@ -7,7 +7,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats.Webp.BitWriter; using SixLabors.ImageSharp.Formats.Webp.BitWriter;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -341,17 +341,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
Span<uint> bgra = this.Bgra.GetSpan(); Span<uint> bgra = this.Bgra.GetSpan();
using IMemoryOwner<Bgra32> bgraRowBuffer = this.memoryAllocator.Allocate<Bgra32>(width); Span<byte> bgraBytes = MemoryMarshal.Cast<uint, byte>(bgra);
Span<Bgra32> bgraRow = bgraRowBuffer.GetSpan(); int widthBytes = width * 4;
int idx = 0;
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
Span<TPixel> rowSpan = image.GetPixelRowSpan(y); Span<TPixel> rowSpan = image.GetPixelRowSpan(y);
PixelOperations<TPixel>.Instance.ToBgra32(this.configuration, rowSpan, bgraRow); PixelOperations<TPixel>.Instance.ToBgra32Bytes(this.configuration, rowSpan, bgraBytes.Slice(y * widthBytes, widthBytes), width);
for (int x = 0; x < width; x++)
{
bgra[idx++] = bgraRow[x].PackedValue;
}
} }
} }

Loading…
Cancel
Save