diff --git a/src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs b/src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs index 058d4adb97..b16792cef5 100644 --- a/src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs @@ -112,43 +112,38 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy } } - private void DecodePixelValues(int width, int height, Span pixelData, Buffer2D pixels) + private void DecodePixelValues(int width, int height, Span pixelData, Buffer2D decodedPixels) where TPixel : unmanaged, IPixel { int widthMul3 = width * 3; for (int y = 0; y < height; y++) { Span row = pixelData.Slice(y * widthMul3, widthMul3); - Span pixelSpan = pixels.GetRowSpan(y); + Span decodedPixelRow = decodedPixels.GetRowSpan(y); PixelOperations.Instance.FromBgr24Bytes( this.configuration, row, - pixelSpan, + decodedPixelRow, width); } } - private void DecodePixelValues(int width, int height, Span pixelData, Buffer2D pixels, IMemoryOwner alpha) + private void DecodePixelValues(int width, int height, Span pixelData, Buffer2D decodedPixels, IMemoryOwner alpha) where TPixel : unmanaged, IPixel { TPixel color = default; Span alphaSpan = alpha.Memory.Span; + Span pixelsBgr = MemoryMarshal.Cast(pixelData); for (int y = 0; y < height; y++) { - // TODO: Can we use span.Length here? int yMulWidth = y * width; - Span pixelRow = pixels.GetRowSpan(y); + Span decodedPixelRow = decodedPixels.GetRowSpan(y); for (int x = 0; x < width; x++) { - // TODO: Could use cast to Bgr24/Bgra32 then set alpha. int offset = yMulWidth + x; - int idxBgr = offset * 3; - byte b = pixelData[idxBgr]; - byte g = pixelData[idxBgr + 1]; - byte r = pixelData[idxBgr + 2]; - byte a = alphaSpan[offset]; - color.FromBgra32(new Bgra32(r, g, b, a)); - pixelRow[x] = color; + Bgr24 bgr = pixelsBgr[offset]; + color.FromBgra32(new Bgra32(bgr.R, bgr.G, bgr.B, alphaSpan[offset])); + decodedPixelRow[x] = color; } } }