diff --git a/src/ImageSharp/Formats/WebP/LossyUtils.cs b/src/ImageSharp/Formats/WebP/LossyUtils.cs index 760f1bb1a..a10c0f417 100644 --- a/src/ImageSharp/Formats/WebP/LossyUtils.cs +++ b/src/ImageSharp/Formats/WebP/LossyUtils.cs @@ -682,6 +682,14 @@ namespace SixLabors.ImageSharp.Formats.WebP return Clip8(MultHi(y, 19077) + MultHi(u, 33050) - 17685); } + public static void Memset(Span dst, uint value, int startIdx, int count) + { + for (int i = 0; i < count; i++) + { + dst[startIdx + i] = value; + } + } + // Complex In-loop filtering (Paragraph 15.3) private static void FilterLoop24( byte[] p, diff --git a/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs b/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs index 43d723917..2826c624b 100644 --- a/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs +++ b/src/ImageSharp/Formats/WebP/WebPLossyDecoder.cs @@ -320,23 +320,23 @@ namespace SixLabors.ImageSharp.Formats.WebP // Predict and add residuals. if (block.IsI4x4) { - // uint32_t* const top_right = (uint32_t*)(y_dst - BPS + 16); - //Span topRight = MemoryMarshal.Cast(yuv.AsSpan(yOff - WebPConstants.Bps + 16)); + Span topRight = MemoryMarshal.Cast(yuv.AsSpan(yOff - WebPConstants.Bps + 16)); if (mby > 0) { if (mbx >= dec.MbWidth - 1) { // On rightmost border. - // memset(top_right, top_yuv[0].y[15], sizeof(*top_right)); + LossyUtils.Memset(topRight, topYuv.Y[15],0, 4); } else { - // memcpy(top_right, top_yuv[1].y, sizeof(*top_right)); + Span topYuvSamples = MemoryMarshal.Cast(dec.YuvTopSamples[mbx + 1].Y.AsSpan()); + topYuvSamples.Slice(0, 4).CopyTo(topRight); } } // Replicate the top-right pixels below. - //topRight[WebPConstants.Bps] = topRight[2 * WebPConstants.Bps] = topRight[3 * WebPConstants.Bps] = topRight[0]; + topRight[WebPConstants.Bps] = topRight[2 * WebPConstants.Bps] = topRight[3 * WebPConstants.Bps] = topRight[0]; // Predict and add residuals for all 4x4 blocks in turn. for (int n = 0; n < 16; ++n, bits <<= 2)