Skip to content

Commit ef78f98

Browse files
committed
Adding Channels and ColorSpace validations to De-/Encoder
I'm not sure the encoder is right
1 parent 3f1fe69 commit ef78f98

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed
Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using SixLabors.ImageSharp.Formats.Qoi;
45
using SixLabors.ImageSharp.PixelFormats;
56

67
namespace SixLabors.ImageSharp.Tests.Formats.Qoi;
@@ -10,40 +11,46 @@ namespace SixLabors.ImageSharp.Tests.Formats.Qoi;
1011
public class QoiDecoderTests
1112
{
1213
[Theory]
13-
[InlineData(TestImages.Qoi.Dice)]
14-
[InlineData(TestImages.Qoi.EdgeCase)]
15-
[InlineData(TestImages.Qoi.Kodim10)]
16-
[InlineData(TestImages.Qoi.Kodim23)]
17-
[InlineData(TestImages.Qoi.QoiLogo)]
18-
[InlineData(TestImages.Qoi.TestCard)]
19-
[InlineData(TestImages.Qoi.TestCardRGBA)]
20-
[InlineData(TestImages.Qoi.Wikipedia008)]
21-
public void Identify(string imagePath)
14+
[InlineData(TestImages.Qoi.Dice, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
15+
[InlineData(TestImages.Qoi.EdgeCase, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
16+
[InlineData(TestImages.Qoi.Kodim10, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
17+
[InlineData(TestImages.Qoi.Kodim23, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
18+
[InlineData(TestImages.Qoi.QoiLogo, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
19+
[InlineData(TestImages.Qoi.TestCard, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
20+
[InlineData(TestImages.Qoi.TestCardRGBA, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
21+
[InlineData(TestImages.Qoi.Wikipedia008, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
22+
public void Identify(string imagePath, QoiChannels channels, QoiColorSpace colorSpace)
2223
{
2324
TestFile testFile = TestFile.Create(imagePath);
2425
using MemoryStream stream = new(testFile.Bytes, false);
2526

2627
ImageInfo imageInfo = Image.Identify(stream);
28+
QoiMetadata qoiMetadata = imageInfo.Metadata.GetQoiMetadata();
2729

2830
Assert.NotNull(imageInfo);
29-
Assert.Equal(imageInfo.Metadata.DecodedImageFormat, ImageSharp.Formats.Qoi.QoiFormat.Instance);
31+
Assert.Equal(imageInfo.Metadata.DecodedImageFormat, QoiFormat.Instance);
32+
Assert.Equal(qoiMetadata.Channels, channels);
33+
Assert.Equal(qoiMetadata.ColorSpace, colorSpace);
3034
}
3135

3236
[Theory]
33-
[WithFile(TestImages.Qoi.Dice, PixelTypes.Rgba32)]
34-
[WithFile(TestImages.Qoi.EdgeCase, PixelTypes.Rgba32)]
35-
[WithFile(TestImages.Qoi.Kodim10, PixelTypes.Rgba32)]
36-
[WithFile(TestImages.Qoi.Kodim23, PixelTypes.Rgba32)]
37-
[WithFile(TestImages.Qoi.QoiLogo, PixelTypes.Rgba32)]
38-
[WithFile(TestImages.Qoi.TestCard, PixelTypes.Rgba32)]
39-
[WithFile(TestImages.Qoi.TestCardRGBA, PixelTypes.Rgba32)]
40-
[WithFile(TestImages.Qoi.Wikipedia008, PixelTypes.Rgba32)]
41-
public void Decode<TPixel>(TestImageProvider<TPixel> provider)
37+
[WithFile(TestImages.Qoi.Dice, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
38+
[WithFile(TestImages.Qoi.EdgeCase, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
39+
[WithFile(TestImages.Qoi.Kodim10, PixelTypes.Rgba32, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
40+
[WithFile(TestImages.Qoi.Kodim23, PixelTypes.Rgba32, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
41+
[WithFile(TestImages.Qoi.QoiLogo, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
42+
[WithFile(TestImages.Qoi.TestCard, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
43+
[WithFile(TestImages.Qoi.TestCardRGBA, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
44+
[WithFile(TestImages.Qoi.Wikipedia008, PixelTypes.Rgba32, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
45+
public void Decode<TPixel>(TestImageProvider<TPixel> provider, QoiChannels channels, QoiColorSpace colorSpace)
4246
where TPixel : unmanaged, IPixel<TPixel>
4347
{
4448
using Image<TPixel> image = provider.GetImage();
49+
QoiMetadata qoiMetadata = image.Metadata.GetQoiMetadata();
4550
image.DebugSave(provider);
4651

4752
image.CompareToReferenceOutput(provider);
53+
Assert.Equal(qoiMetadata.Channels, channels);
54+
Assert.Equal(qoiMetadata.ColorSpace, colorSpace);
4855
}
4956
}

tests/ImageSharp.Tests/Formats/Qoi/QoiEncoderTests.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,32 @@ namespace SixLabors.ImageSharp.Tests.Formats.Qoi;
1313
public class QoiEncoderTests
1414
{
1515
[Theory]
16-
[WithFile(TestImages.Qoi.Dice, PixelTypes.Rgba32)]
17-
[WithFile(TestImages.Qoi.EdgeCase, PixelTypes.Rgba32)]
18-
[WithFile(TestImages.Qoi.Kodim10, PixelTypes.Rgba32)]
19-
[WithFile(TestImages.Qoi.Kodim23, PixelTypes.Rgba32)]
20-
[WithFile(TestImages.Qoi.QoiLogo, PixelTypes.Rgba32)]
21-
[WithFile(TestImages.Qoi.TestCard, PixelTypes.Rgba32)]
22-
[WithFile(TestImages.Qoi.TestCardRGBA, PixelTypes.Rgba32)]
23-
[WithFile(TestImages.Qoi.Wikipedia008, PixelTypes.Rgba32)]
24-
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Quitar miembros privados no utilizados", Justification = "Function implicitly in tests")]
25-
private static void Encode<TPixel>(TestImageProvider<TPixel> provider)
16+
[WithFile(TestImages.Qoi.Dice, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
17+
[WithFile(TestImages.Qoi.EdgeCase, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
18+
[WithFile(TestImages.Qoi.Kodim10, PixelTypes.Rgba32, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
19+
[WithFile(TestImages.Qoi.Kodim23, PixelTypes.Rgba32, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
20+
[WithFile(TestImages.Qoi.QoiLogo, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
21+
[WithFile(TestImages.Qoi.TestCard, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
22+
[WithFile(TestImages.Qoi.TestCardRGBA, PixelTypes.Rgba32, QoiChannels.Rgba, QoiColorSpace.SrgbWithLinearAlpha)]
23+
[WithFile(TestImages.Qoi.Wikipedia008, PixelTypes.Rgba32, QoiChannels.Rgb, QoiColorSpace.SrgbWithLinearAlpha)]
24+
public static void Encode<TPixel>(TestImageProvider<TPixel> provider, QoiChannels channels, QoiColorSpace colorSpace)
2625
where TPixel : unmanaged, IPixel<TPixel>
2726
{
2827
using Image<TPixel> image = provider.GetImage(new MagickReferenceDecoder());
2928
using MemoryStream stream = new();
30-
QoiEncoder encoder = new();
29+
QoiEncoder encoder = new()
30+
{
31+
Channels = channels,
32+
ColorSpace = colorSpace
33+
};
3134
image.Save(stream, encoder);
3235
stream.Position = 0;
36+
3337
using Image<TPixel> encodedImage = (Image<TPixel>)Image.Load(stream);
38+
QoiMetadata qoiMetadata = encodedImage.Metadata.GetQoiMetadata();
39+
3440
ImageComparer.Exact.CompareImages(image, encodedImage);
41+
Assert.Equal(qoiMetadata.Channels, channels);
42+
Assert.Equal(qoiMetadata.ColorSpace, colorSpace);
3543
}
3644
}

0 commit comments

Comments
 (0)