From fa2e1b06108febab6542fa703ea05a292f1c1cf5 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Fri, 26 Jul 2024 19:44:43 +0200 Subject: [PATCH] Add tests for Orange4x4 image --- ImageSharp.sln | 1 + .../Formats/Heif/Av1/Av1BitStreamReader.cs | 3 +-- .../Formats/Heif/Av1/Av1TilingTests.cs | 14 ++++++++------ .../Formats/Heif/Av1/ObuFrameHeaderTests.cs | 1 + tests/ImageSharp.Tests/TestImages.cs | 3 +++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ImageSharp.sln b/ImageSharp.sln index e540101e5..1789a8d5d 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -671,6 +671,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Heif", "Heif", "{BA5D603A-C tests\Images\Input\Heif\IMG-20230508-0053.hif = tests\Images\Input\Heif\IMG-20230508-0053.hif tests\Images\Input\Heif\Irvine_CA.avif = tests\Images\Input\Heif\Irvine_CA.avif tests\Images\Input\Heif\jpeg444_xnconvert.avif = tests\Images\Input\Heif\jpeg444_xnconvert.avif + tests\Images\Input\Heif\Orange4x4.avif = tests\Images\Input\Heif\Orange4x4.avif EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Icon", "Icon", "{95E45DDE-A67D-48AD-BBA8-5FAA151B860D}" diff --git a/src/ImageSharp/Formats/Heif/Av1/Av1BitStreamReader.cs b/src/ImageSharp/Formats/Heif/Av1/Av1BitStreamReader.cs index 552f0a80b..1b96c26d9 100644 --- a/src/ImageSharp/Formats/Heif/Av1/Av1BitStreamReader.cs +++ b/src/ImageSharp/Formats/Heif/Av1/Av1BitStreamReader.cs @@ -150,8 +150,7 @@ internal ref struct Av1BitStreamReader { DebugGuard.IsTrue(Av1Math.Modulus8(this.BitPosition) == 0, "Symbol reading needs to start on byte boundary."); int bytesRead = Av1Math.DivideBy8Floor(this.BitPosition); - int spanLength = tileDataSize - bytesRead; - Span span = this.data.Slice(bytesRead, spanLength); + Span span = this.data.Slice(bytesRead, tileDataSize); this.Skip(tileDataSize << 3); return span; } diff --git a/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1TilingTests.cs b/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1TilingTests.cs index baf77ed48..7348e33f3 100644 --- a/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1TilingTests.cs +++ b/tests/ImageSharp.Tests/Formats/Heif/Av1/Av1TilingTests.cs @@ -10,24 +10,26 @@ namespace SixLabors.ImageSharp.Tests.Formats.Heif.Av1; [Trait("Format", "Avif")] public class Av1TilingTests { - // [Theory] - [InlineData(TestImages.Heif.XnConvert, 0x010E, 0x03CC, 18, 0x03CC - 18)] - public void ReadFirstTile(string filename, int headerOffset, int headerSize, int tileOffset, int tileSize) + [Theory] + /*[InlineData(TestImages.Heif.XnConvert, 0x010E, 0x03CC, 18)]*/ + [InlineData(TestImages.Heif.Orange4x4, 0x010E, 0x001d, 21)] + public void ReadFirstTile(string filename, int dataOffset, int dataSize, int tileOffset) { // Assign string filePath = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, filename); byte[] content = File.ReadAllBytes(filePath); - Span headerSpan = content.AsSpan(headerOffset, headerSize); - Span tileSpan = content.AsSpan(tileOffset, tileSize); + Span headerSpan = content.AsSpan(dataOffset, dataSize); + Span tileSpan = content.AsSpan(tileOffset, dataSize - tileOffset); Av1BitStreamReader reader = new(headerSpan); IAv1TileDecoder stub = new Av1TileDecoderStub(); ObuReader obuReader = new(); - obuReader.ReadAll(ref reader, headerSize, stub); + obuReader.ReadAll(ref reader, dataSize, stub); Av1TileDecoder decoder = new(obuReader.SequenceHeader, obuReader.FrameHeader); // Act decoder.DecodeTile(tileSpan, 0); // Assert + Assert.Equal(dataSize * 8, reader.BitPosition); } } diff --git a/tests/ImageSharp.Tests/Formats/Heif/Av1/ObuFrameHeaderTests.cs b/tests/ImageSharp.Tests/Formats/Heif/Av1/ObuFrameHeaderTests.cs index d17c49a17..bb2d99a2f 100644 --- a/tests/ImageSharp.Tests/Formats/Heif/Av1/ObuFrameHeaderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Heif/Av1/ObuFrameHeaderTests.cs @@ -25,6 +25,7 @@ public class ObuFrameHeaderTests // [InlineData(TestImages.Heif.IrvineAvif, 0x0102, 0x000D)] // [InlineData(TestImages.Heif.IrvineAvif, 0x0198, 0x6BD1)] [InlineData(TestImages.Heif.XnConvert, 0x010E, 0x03CC)] + [InlineData(TestImages.Heif.Orange4x4, 0x010E, 0x001d)] public void ReadFrameHeader(string filename, int fileOffset, int blockSize) { // Assign diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 11096df16..5f88847db 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -1144,6 +1144,9 @@ public static class TestImages public const string IrvineAvif = "Heif/Irvine_CA.avif"; public const string XnConvert = "Heif/jpeg444_xnconvert.avif"; + + // Extremely small image, 4x4 pixels with a single solid color. + public const string Orange4x4 = "Heif/Orange4x4.avif"; } public static class Ico