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
{
private const int WordSize = 1 << WordSizeLog2;
public const int WordSize = 1 << WordSizeLog2;
private const int WordSizeLog2 = 5;
private const int WordSizeInBytesLog2 = WordSizeLog2 - Log2Of8;
private const int Log2Of8 = 3;
@ -182,7 +182,7 @@ internal ref struct Av1BitStreamReader
// TODO: Pass exact byte iso Word start.
int spanLength = tileDataSize >> WordSizeInBytesLog2;
Span<uint> span = this.data.Slice(this.bitOffset >> WordSizeLog2, spanLength);
this.bitOffset += tileDataSize << Log2Of8;
this.Skip(tileDataSize << Log2Of8);
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.
/// </summary>
public static int Get4x4WidthLog2(this Av1BlockSize blockSize)
=> Get4x4WideCount(blockSize) << 2;
=> Av1Math.Log2(Get4x4WideCount(blockSize));
/// <summary>
/// Returns base 2 logarithm of the height of the block in units of 4 samples.
/// </summary>
public static int Get4x4HeightLog2(this Av1BlockSize blockSize)
=> Get4x4HighCount(blockSize) << 2;
=> Av1Math.Log2(Get4x4HighCount(blockSize));
/// <summary>
/// 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.FrameHeader);
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)]
// public void BinaryIdenticalRoundTripFrameHeader(string filename, int fileOffset, int blockSize)
// {
// // Assign
// string filePath = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, filename);
// byte[] content = File.ReadAllBytes(filePath);
// Span<byte> span = content.AsSpan(fileOffset, blockSize);
// IAv1TileDecoder tileDecoder = new Av1TileDecoderStub();
// Av1BitStreamReader reader = new(span);
// // Act 1
// ObuReader.Read(ref reader, blockSize, tileDecoder);
// // Assign 2
// MemoryStream encoded = new();
// // Act 2
// ObuWriter.Write(encoded, tileDecoder);
// // Assert
// Assert.Equal(span, encoded.ToArray());
//}
/*
[Theory]
[InlineData(TestImages.Heif.XnConvert, 0x010E, 0x03CC)]
public void BinaryIdenticalRoundTripFrameHeader(string filename, int fileOffset, int blockSize)
{
// Assign
string filePath = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, filename);
byte[] content = File.ReadAllBytes(filePath);
Span<byte> span = content.AsSpan(fileOffset, blockSize);
Av1TileDecoderStub tileDecoder = new();
Av1BitStreamReader reader = new(span);
ObuReader obuReader = new();
// Act 1
obuReader.Read(ref reader, blockSize, tileDecoder);
// Assign 2
MemoryStream encoded = new();
// Act 2
ObuWriter obuWriter = new();
ObuWriter.Write(encoded, obuReader.SequenceHeader, obuReader.FrameHeader);
// Assert
Assert.Equal(span, encoded.ToArray());
}
*/
[Theory]

Loading…
Cancel
Save