From b0c6d73978e8f3f9a394d30764f481d8993b0b35 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Wed, 30 Jun 2021 20:09:53 +0200 Subject: [PATCH] Convert pixels to bgra with ToBgra32Bytes --- src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs index 739529831c..dab1065247 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; - +using System.Runtime.InteropServices; using SixLabors.ImageSharp.Formats.Webp.BitWriter; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -341,17 +341,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless where TPixel : unmanaged, IPixel { Span bgra = this.Bgra.GetSpan(); - using IMemoryOwner bgraRowBuffer = this.memoryAllocator.Allocate(width); - Span bgraRow = bgraRowBuffer.GetSpan(); - int idx = 0; + Span bgraBytes = MemoryMarshal.Cast(bgra); + int widthBytes = width * 4; for (int y = 0; y < height; y++) { Span rowSpan = image.GetPixelRowSpan(y); - PixelOperations.Instance.ToBgra32(this.configuration, rowSpan, bgraRow); - for (int x = 0; x < width; x++) - { - bgra[idx++] = bgraRow[x].PackedValue; - } + PixelOperations.Instance.ToBgra32Bytes(this.configuration, rowSpan, bgraBytes.Slice(y * widthBytes, widthBytes), width); } }