From 1b6e824f6d8e77b0bfad5aef1450aeed0d0a9864 Mon Sep 17 00:00:00 2001 From: winscripter <142818255+winscripter@users.noreply.github.com> Date: Mon, 31 Aug 2026 20:39:47 +0400 Subject: [PATCH] Don't use GetWReference (it should return span) --- .../Encoding/ContextPrediction/JxlContextPrediction.cs | 4 +--- .../Modular/Encoding/ContextPrediction/JxlModularHeader.cs | 6 +++--- .../Modular/Encoding/ContextPrediction/JxlModularState.cs | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlContextPrediction.cs b/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlContextPrediction.cs index fcbef7afd7..f856ef0e39 100644 --- a/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlContextPrediction.cs +++ b/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlContextPrediction.cs @@ -2,7 +2,6 @@ // Licensed under the Six Labors Split License. using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.Formats.Jxl.Processing.Modular.Encoding.ContextPrediction; @@ -17,8 +16,7 @@ internal static class JxlContextPrediction public static void SetPredictorMode(int i, JxlModularHeader header) { - ref uint wr = ref header.GetWReference(); - Span w = MemoryMarshal.CreateSpan(ref wr, 4); + Span w = header.GetW(); switch (i) { diff --git a/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlModularHeader.cs b/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlModularHeader.cs index 4db1a00dc9..04a50fe270 100644 --- a/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlModularHeader.cs +++ b/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlModularHeader.cs @@ -101,10 +101,10 @@ internal sealed class JxlModularHeader : IJxlFields } /// - /// Returns a reference to the first w item. + /// Returns a span to the w array. /// - /// Reference to w[0] - public ref uint GetWReference() => ref this.w[0]; + /// Reference to w + public Span GetW() => this.w; public bool Visit(JxlVisitor v) { diff --git a/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlModularState.cs b/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlModularState.cs index f731dc9677..7e52a62e57 100644 --- a/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlModularState.cs +++ b/src/ImageSharp/Formats/Jxl/Processing/Modular/Encoding/ContextPrediction/JxlModularState.cs @@ -109,13 +109,13 @@ internal sealed class JxlModularState int posNW = x > 0 ? posN - 1 : posN; Span weights = stackalloc uint[4]; - ref uint headerW = ref this.header.GetWReference(); + Span headerW = this.header.GetW(); for (int i = 0; i < 4; i++) { Span error = this.predErrors[i].AsSpan(); weights[i] = error[posN] + error[posNE] + error[posNW]; - weights[i] = ErrorWeight((int)weights[i], Unsafe.Add(ref headerW, i)); + weights[i] = ErrorWeight((int)weights[i], headerW[i]); } n = AddBits(n);