Browse Source

Strength test criteria

pull/2633/head
Ynse Hoornenborg 2 years ago
parent
commit
6aa609fa34
  1. 4
      src/ImageSharp/Formats/Heif/Av1/Av1BitStreamReader.cs
  2. 4
      src/ImageSharp/Formats/Heif/Av1/Av1BlockSizeExtensions.cs
  3. 51
      tests/ImageSharp.Tests/Formats/Heif/Av1/ObuFrameHeaderTests.cs

4
src/ImageSharp/Formats/Heif/Av1/Av1BitStreamReader.cs

@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Formats.Heif.Av1;
internal ref struct Av1BitStreamReader internal ref struct Av1BitStreamReader
{ {
private const int WordSize = 1 << WordSizeLog2; public const int WordSize = 1 << WordSizeLog2;
private const int WordSizeLog2 = 5; private const int WordSizeLog2 = 5;
private const int WordSizeInBytesLog2 = WordSizeLog2 - Log2Of8; private const int WordSizeInBytesLog2 = WordSizeLog2 - Log2Of8;
private const int Log2Of8 = 3; private const int Log2Of8 = 3;
@ -182,7 +182,7 @@ internal ref struct Av1BitStreamReader
// TODO: Pass exact byte iso Word start. // TODO: Pass exact byte iso Word start.
int spanLength = tileDataSize >> WordSizeInBytesLog2; int spanLength = tileDataSize >> WordSizeInBytesLog2;
Span<uint> span = this.data.Slice(this.bitOffset >> WordSizeLog2, spanLength); Span<uint> span = this.data.Slice(this.bitOffset >> WordSizeLog2, spanLength);
this.bitOffset += tileDataSize << Log2Of8; this.Skip(tileDataSize << Log2Of8);
return MemoryMarshal.Cast<uint, byte>(span); return MemoryMarshal.Cast<uint, byte>(span);
} }
} }

4
src/ImageSharp/Formats/Heif/Av1/Av1BlockSizeExtensions.cs

@ -68,13 +68,13 @@ internal static class Av1BlockSizeExtensions
/// Returns base 2 logarithm of the width of the block in units of 4 samples. /// Returns base 2 logarithm of the width of the block in units of 4 samples.
/// </summary> /// </summary>
public static int Get4x4WidthLog2(this Av1BlockSize blockSize) public static int Get4x4WidthLog2(this Av1BlockSize blockSize)
=> Get4x4WideCount(blockSize) << 2; => Av1Math.Log2(Get4x4WideCount(blockSize));
/// <summary> /// <summary>
/// Returns base 2 logarithm of the height of the block in units of 4 samples. /// Returns base 2 logarithm of the height of the block in units of 4 samples.
/// </summary> /// </summary>
public static int Get4x4HeightLog2(this Av1BlockSize blockSize) public static int Get4x4HeightLog2(this Av1BlockSize blockSize)
=> Get4x4HighCount(blockSize) << 2; => Av1Math.Log2(Get4x4HighCount(blockSize));
/// <summary> /// <summary>
/// Returns the block size of a sub sampled block. /// Returns the block size of a sub sampled block.

51
tests/ImageSharp.Tests/Formats/Heif/Av1/ObuFrameHeaderTests.cs

@ -32,31 +32,36 @@ public class ObuFrameHeaderTests
Assert.NotNull(obuReader.SequenceHeader); Assert.NotNull(obuReader.SequenceHeader);
Assert.NotNull(obuReader.FrameHeader); Assert.NotNull(obuReader.FrameHeader);
Assert.NotNull(obuReader.FrameHeader.TilesInfo); Assert.NotNull(obuReader.FrameHeader.TilesInfo);
Assert.Equal(reader.Length * Av1BitStreamReader.WordSize, reader.BitPosition);
Assert.Equal(reader.Length * 4, blockSize);
} }
/* [Theory] /*
// [InlineData(TestImages.Heif.XnConvert, 0x010E, 0x03CC)] [Theory]
// public void BinaryIdenticalRoundTripFrameHeader(string filename, int fileOffset, int blockSize) [InlineData(TestImages.Heif.XnConvert, 0x010E, 0x03CC)]
// { public void BinaryIdenticalRoundTripFrameHeader(string filename, int fileOffset, int blockSize)
// // Assign {
// string filePath = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, filename); // Assign
// byte[] content = File.ReadAllBytes(filePath); string filePath = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, filename);
// Span<byte> span = content.AsSpan(fileOffset, blockSize); byte[] content = File.ReadAllBytes(filePath);
// IAv1TileDecoder tileDecoder = new Av1TileDecoderStub(); Span<byte> span = content.AsSpan(fileOffset, blockSize);
// Av1BitStreamReader reader = new(span); Av1TileDecoderStub tileDecoder = new();
Av1BitStreamReader reader = new(span);
// // Act 1 ObuReader obuReader = new();
// ObuReader.Read(ref reader, blockSize, tileDecoder);
// Act 1
// // Assign 2 obuReader.Read(ref reader, blockSize, tileDecoder);
// MemoryStream encoded = new();
// Assign 2
// // Act 2 MemoryStream encoded = new();
// ObuWriter.Write(encoded, tileDecoder);
// Act 2
// // Assert ObuWriter obuWriter = new();
// Assert.Equal(span, encoded.ToArray()); ObuWriter.Write(encoded, obuReader.SequenceHeader, obuReader.FrameHeader);
//}
// Assert
Assert.Equal(span, encoded.ToArray());
}
*/ */
[Theory] [Theory]

Loading…
Cancel
Save