mirror of https://github.com/SixLabors/ImageSharp
Browse Source
-Adding validation for size, channels and colorspace -Refactoring to throw general exceptions -Creating tests -Using other better data typesqoi
8 changed files with 120 additions and 17 deletions
@ -0,0 +1,18 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Qoi; |
|||
|
|||
/// <summary>
|
|||
/// Registers the image encoders, decoders and mime type detectors for the qoi format.
|
|||
/// </summary>
|
|||
public sealed class QoiConfigurationModule : IImageFormatConfigurationModule |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public void Configure(Configuration configuration) |
|||
{ |
|||
configuration.ImageFormatsManager.SetDecoder(QoiFormat.Instance, QoiDecoder.Instance); |
|||
//configuration.ImageFormatsManager.SetEncoder(QoiFormat.Instance, new QoiEncoder());
|
|||
configuration.ImageFormatsManager.AddImageFormatDetector(new QoiImageFormatDetector()); |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Buffers.Binary; |
|||
using System.Diagnostics.CodeAnalysis; |
|||
using SixLabors.ImageSharp.Formats.Png; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Qoi; |
|||
|
|||
/// <summary>
|
|||
/// Detects qoi file headers
|
|||
/// </summary>
|
|||
public class QoiImageFormatDetector : IImageFormatDetector |
|||
{ |
|||
/// <inheritdoc/>
|
|||
public int HeaderSize => 14; |
|||
|
|||
/// <inheritdoc/>
|
|||
public bool TryDetectFormat(ReadOnlySpan<byte> header, [NotNullWhen(true)] out IImageFormat? format) |
|||
{ |
|||
format = this.IsSupportedFileFormat(header) ? QoiFormat.Instance : null; |
|||
return format != null; |
|||
} |
|||
|
|||
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header) |
|||
=> header.Length == this.HeaderSize && header[..4] == QoiConstants.Magic; |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Formats.Qoi; |
|||
|
|||
[Trait("Format", "Qoi")] |
|||
[ValidateDisposedMemoryAllocations] |
|||
public class QoiDecoderTests |
|||
{ |
|||
[Theory] |
|||
[InlineData(TestImages.Qoi.Dice)] |
|||
[InlineData(TestImages.Qoi.EdgeCase)] |
|||
[InlineData(TestImages.Qoi.Kodim10)] |
|||
[InlineData(TestImages.Qoi.Kodim23)] |
|||
[InlineData(TestImages.Qoi.QoiLogo)] |
|||
[InlineData(TestImages.Qoi.TestCard)] |
|||
[InlineData(TestImages.Qoi.TestCardRGBA)] |
|||
[InlineData(TestImages.Qoi.Wikipedia008)] |
|||
public void Identify(string imagePath) |
|||
{ |
|||
TestFile testFile = TestFile.Create(imagePath); |
|||
using MemoryStream stream = new(testFile.Bytes, false); |
|||
|
|||
ImageInfo imageInfo = Image.Identify(stream); |
|||
|
|||
Assert.NotNull(imageInfo); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue