diff --git a/src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs b/src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs index 0822489d3d..228ce3e8da 100644 --- a/src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs +++ b/src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs @@ -128,12 +128,12 @@ public int WriteCoefficients( if (eob_offset_bits > 0) { int eob_shift = eob_offset_bits - 1; - int bit = Math.Max(1, eob_extra & 1 << eob_shift); + int bit = (eob_extra & (1 << eob_shift)) != 0 ? 1 : 0; w.WriteSymbol(bit, this.endOfBlockExtra[(int)transformSizeContext][(int)componentType][endOfBlockPosition]); for (int i = 1; i < eob_offset_bits; i++) { eob_shift = eob_offset_bits - 1 - i; - bit = Math.Max(1, eob_extra & 1 << eob_shift); + bit = (eob_extra & (1 << eob_shift)) != 0 ? 1 : 0; w.WriteLiteral((uint)bit, 1); } } diff --git a/src/ImageSharp/Formats/Heif/Av1/Tiling/Av1LevelBuffer.cs b/src/ImageSharp/Formats/Heif/Av1/Tiling/Av1LevelBuffer.cs index d3dd37836e..2fa4c03f03 100644 --- a/src/ImageSharp/Formats/Heif/Av1/Tiling/Av1LevelBuffer.cs +++ b/src/ImageSharp/Formats/Heif/Av1/Tiling/Av1LevelBuffer.cs @@ -50,7 +50,7 @@ public Span GetRow(int y) ObjectDisposedException.ThrowIf(this.memory == null, this); ArgumentOutOfRangeException.ThrowIfLessThan(y, -Av1Constants.TransformPadTop); int row = y + Av1Constants.TransformPadTop; - return this.memory.Memory.Span.Slice(row * this.Stride, this.Size.Width); + return this.memory.Memory.Span.Slice(row * this.Stride, this.Size.Width + Av1Constants.TransformPadHorizontal); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1CoefficientsEntropyTests.cs b/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1CoefficientsEntropyTests.cs index e877ef7130..3be90137a5 100644 --- a/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1CoefficientsEntropyTests.cs +++ b/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1CoefficientsEntropyTests.cs @@ -39,6 +39,7 @@ public void RoundTripZeroEndOfBlock() Configuration configuration = Configuration.Default; Av1SymbolEncoder encoder = new(configuration, 100 / 8, BaseQIndex); Span coefficientsBuffer = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; + Span expected = new int[16]; Span actuals = new int[16]; // Act @@ -51,7 +52,7 @@ public void RoundTripZeroEndOfBlock() decoder.ReadCoefficients(modeInfo, new Point(0, 0), aboveContexts, leftContexts, 0, 0, 0, 1, 1, transformBlockContext, transformSize, false, true, transformInfo, 0, 0, actuals); // Assert - Assert.Equal(coefficientsBuffer, actuals); + Assert.Equal(expected, actuals); } }