From a1342bf30a99c3a9b1d5a25716ce34c883d2f5dd Mon Sep 17 00:00:00 2001 From: LuisAlfredo92 <92luisalfredo@protonmail.com> Date: Mon, 12 Jun 2023 21:00:22 -0600 Subject: [PATCH] Fixing Qoi detector -I had several errors about header size comparison and comparing byte arrays, but I've fixed them and tested the Identify function and it works perfect! --- src/ImageSharp/Formats/Qoi/QoiImageFormatDetector.cs | 2 +- tests/ImageSharp.Tests/Formats/Qoi/QoiDecoderTests.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Qoi/QoiImageFormatDetector.cs b/src/ImageSharp/Formats/Qoi/QoiImageFormatDetector.cs index 720e308b36..380e1a41d9 100644 --- a/src/ImageSharp/Formats/Qoi/QoiImageFormatDetector.cs +++ b/src/ImageSharp/Formats/Qoi/QoiImageFormatDetector.cs @@ -23,5 +23,5 @@ public class QoiImageFormatDetector : IImageFormatDetector } private bool IsSupportedFileFormat(ReadOnlySpan header) - => header.Length == this.HeaderSize && header[..4] == QoiConstants.Magic; + => header.Length >= this.HeaderSize && QoiConstants.Magic.SequenceEqual(header[..4]); } diff --git a/tests/ImageSharp.Tests/Formats/Qoi/QoiDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Qoi/QoiDecoderTests.cs index 9a5e0bfafd..cf432e82dd 100644 --- a/tests/ImageSharp.Tests/Formats/Qoi/QoiDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Qoi/QoiDecoderTests.cs @@ -24,5 +24,6 @@ public class QoiDecoderTests ImageInfo imageInfo = Image.Identify(stream); Assert.NotNull(imageInfo); + Assert.Equal(imageInfo.Metadata.DecodedImageFormat, ImageSharp.Formats.Qoi.QoiFormat.Instance); } }