Skip to content

Commit

Permalink
Round trip empty Coefficients buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ynse01 committed Nov 24, 2024
1 parent e592ef6 commit c7c0039
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ImageSharp/Formats/Heif/Av1/Entropy/Av1SymbolEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Heif/Av1/Tiling/Av1LevelBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Span<byte> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void RoundTripZeroEndOfBlock()
Configuration configuration = Configuration.Default;
Av1SymbolEncoder encoder = new(configuration, 100 / 8, BaseQIndex);
Span<int> coefficientsBuffer = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
Span<int> expected = new int[16];
Span<int> actuals = new int[16];

// Act
Expand All @@ -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);
}

}

0 comments on commit c7c0039

Please sign in to comment.