Skip to content

Commit 1e65e08

Browse files
Add additional unit tests to improve code coverage. Update licensing version
1 parent 2b1c7e0 commit 1e65e08

19 files changed

Lines changed: 524 additions & 114 deletions

File tree

.gitattributes

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,12 @@
8585
###############################################################################
8686
*.basis binary
8787
*.dll binary
88-
*.eot binary
8988
*.exe binary
90-
*.otf binary
9189
*.pdf binary
9290
*.ppt binary
9391
*.pptx binary
9492
*.pvr binary
9593
*.snk binary
96-
*.ttc binary
97-
*.ttf binary
98-
*.woff binary
99-
*.woff2 binary
10094
*.xls binary
10195
*.xlsx binary
10296
###############################################################################
@@ -126,6 +120,7 @@
126120
*.dds filter=lfs diff=lfs merge=lfs -text
127121
*.ktx filter=lfs diff=lfs merge=lfs -text
128122
*.ktx2 filter=lfs diff=lfs merge=lfs -text
123+
*.astc filter=lfs diff=lfs merge=lfs -text
129124
*.pam filter=lfs diff=lfs merge=lfs -text
130125
*.pbm filter=lfs diff=lfs merge=lfs -text
131126
*.pgm filter=lfs diff=lfs merge=lfs -text
@@ -143,3 +138,12 @@
143138
# Handle ICC files by git lfs
144139
###############################################################################
145140
*.icc filter=lfs diff=lfs merge=lfs -text
141+
###############################################################################
142+
# Handle font files by git lfs
143+
###############################################################################
144+
*.eot filter=lfs diff=lfs merge=lfs -text
145+
*.otf filter=lfs diff=lfs merge=lfs -text
146+
*.ttc filter=lfs diff=lfs merge=lfs -text
147+
*.ttf filter=lfs diff=lfs merge=lfs -text
148+
*.woff filter=lfs diff=lfs merge=lfs -text
149+
*.woff2 filter=lfs diff=lfs merge=lfs -text

ImageSharp.sln

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.31903.59
3+
# Visual Studio Version 18
4+
VisualStudioVersion = 18.5.11723.231 stable
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}"
77
ProjectSection(SolutionItems) = preProject
@@ -45,6 +45,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp", "src\ImageShar
4545
EndProject
4646
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{56801022-D71A-4FBE-BC5B-CBA08E2284EC}"
4747
ProjectSection(SolutionItems) = preProject
48+
tests\coverlet.runsettings = tests\coverlet.runsettings
4849
tests\Directory.Build.props = tests\Directory.Build.props
4950
tests\Directory.Build.targets = tests\Directory.Build.targets
5051
tests\ImageSharp.Tests.ruleset = tests\ImageSharp.Tests.ruleset

src/ImageSharp/ColorProfiles/WorkingSpaces/GammaWorkingSpace.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public override bool Equals(object? obj)
6262

6363
/// <inheritdoc/>
6464
public override int GetHashCode() => HashCode.Combine(
65+
typeof(GammaWorkingSpace),
6566
this.WhitePoint,
6667
this.ChromaticityCoordinates,
6768
this.Gamma);

src/ImageSharp/ColorProfiles/WorkingSpaces/RgbWorkingSpace.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ public override bool Equals(object? obj)
7070
return true;
7171
}
7272

73-
if (obj is RgbWorkingSpace other)
73+
if (obj.GetType() == this.GetType())
7474
{
75+
RgbWorkingSpace other = (RgbWorkingSpace)obj;
76+
7577
return this.WhitePoint.Equals(other.WhitePoint)
7678
&& this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates);
7779
}
@@ -81,5 +83,5 @@ public override bool Equals(object? obj)
8183

8284
/// <inheritdoc/>
8385
public override int GetHashCode()
84-
=> HashCode.Combine(this.WhitePoint, this.ChromaticityCoordinates);
86+
=> HashCode.Combine(this.GetType(), this.WhitePoint, this.ChromaticityCoordinates);
8587
}

src/ImageSharp/Common/Tuples/Octet{T}.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.

tests/Directory.Build.targets

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
<ItemGroup>
2020
<!-- Test Dependencies -->
2121
<PackageReference Update="Colourful" Version="3.2.0" />
22-
23-
<!--
24-
Do not update to 14+ yet. There's differnce in how the BMP decoder handles rounding in 16 bit images.
25-
See https://github.com/ImageMagick/ImageMagick/commit/27a0a9c37f18af9c8d823a3ea076f600843b553c
26-
-->
2722
<PackageReference Update="Magick.NET-Q16-AnyCPU" Version="14.11.1" />
2823
<PackageReference Update="Microsoft.DotNet.RemoteExecutor" Version="10.0.0-beta.25563.105" />
2924
<PackageReference Update="Microsoft.DotNet.XUnitExtensions" Version="8.0.0-beta.23580.1" />

tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_Rgba32_To_Bgra32.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using BenchmarkDotNet.Attributes;
88

99
using SixLabors.ImageSharp.PixelFormats;
10-
using SixLabors.ImageSharp.Tuples;
1110

1211
namespace SixLabors.ImageSharp.Benchmarks.General.PixelConversion;
1312

@@ -225,8 +224,8 @@ public void Bitops_SingleTuple()
225224
// [Benchmark]
226225
public void Bitops_Simd()
227226
{
228-
ref Octet<uint> sBase = ref Unsafe.As<Rgba32, Octet<uint>>(ref this.source[0]);
229-
ref Octet<uint> dBase = ref Unsafe.As<Bgra32, Octet<uint>>(ref this.dest[0]);
227+
ref InlineArray8<uint> sBase = ref Unsafe.As<Rgba32, InlineArray8<uint>>(ref this.source[0]);
228+
ref InlineArray8<uint> dBase = ref Unsafe.As<Bgra32, InlineArray8<uint>>(ref this.dest[0]);
230229

231230
for (nuint i = 0; i < (uint)this.Count / 8; i++)
232231
{
@@ -249,9 +248,9 @@ private struct C
249248
#pragma warning restore SA1132 // Do not combine fields
250249

251250
[MethodImpl(MethodImplOptions.AggressiveInlining)]
252-
private static void BitopsSimdImpl(ref Octet<uint> s, ref Octet<uint> d)
251+
private static void BitopsSimdImpl(ref InlineArray8<uint> s, ref InlineArray8<uint> d)
253252
{
254-
Vector<uint> sVec = Unsafe.As<Octet<uint>, Vector<uint>>(ref s);
253+
Vector<uint> sVec = Unsafe.As<InlineArray8<uint>, Vector<uint>>(ref s);
255254
Vector<uint> aMask = new(0xFF00FF00);
256255
Vector<uint> bMask = new(0x00FF00FF);
257256

@@ -274,7 +273,7 @@ private static void BitopsSimdImpl(ref Octet<uint> s, ref Octet<uint> d)
274273
Vector<uint> cc = Unsafe.As<C, Vector<uint>>(ref c);
275274
Vector<uint> dd = aa + cc;
276275

277-
d = Unsafe.As<Vector<uint>, Octet<uint>>(ref dd);
276+
d = Unsafe.As<Vector<uint>, InlineArray8<uint>>(ref dd);
278277
}
279278

280279
// [Benchmark]

tests/ImageSharp.Benchmarks/General/Vectorization/WidenBytesToUInt32.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using System.Runtime.CompilerServices;
66
using BenchmarkDotNet.Attributes;
77

8-
using SixLabors.ImageSharp.Tuples;
9-
108
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization;
119

1210
[Config(typeof(Config.Short))]
@@ -30,12 +28,22 @@ public void Standard()
3028
{
3129
const int N = Count / 8;
3230

33-
ref Octet<byte> sBase = ref Unsafe.As<byte, Octet<byte>>(ref this.source[0]);
34-
ref Octet<uint> dBase = ref Unsafe.As<uint, Octet<uint>>(ref this.dest[0]);
31+
ref InlineArray8<byte> sBase = ref Unsafe.As<byte, InlineArray8<byte>>(ref this.source[0]);
32+
ref InlineArray8<uint> dBase = ref Unsafe.As<uint, InlineArray8<uint>>(ref this.dest[0]);
3533

3634
for (nuint i = 0; i < N; i++)
3735
{
38-
Unsafe.Add(ref dBase, i).LoadFrom(ref Unsafe.Add(ref sBase, i));
36+
ref InlineArray8<byte> source = ref Unsafe.Add(ref sBase, i);
37+
ref InlineArray8<uint> destination = ref Unsafe.Add(ref dBase, i);
38+
39+
destination[0] = source[0];
40+
destination[1] = source[1];
41+
destination[2] = source[2];
42+
destination[3] = source[3];
43+
destination[4] = source[4];
44+
destination[5] = source[5];
45+
destination[6] = source[6];
46+
destination[7] = source[7];
3947
}
4048
}
4149

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Six Labors Split License.
3+
4+
using System.Numerics;
5+
using SixLabors.ImageSharp.ColorProfiles;
6+
using SixLabors.ImageSharp.ColorProfiles.WorkingSpaces;
7+
8+
namespace SixLabors.ImageSharp.Tests.ColorProfiles;
9+
10+
/// <summary>
11+
/// Tests the <see cref="RgbWorkingSpace"/> class.
12+
/// </summary>
13+
[Trait("Color", "Conversion")]
14+
public class RgbWorkingSpaceTests
15+
{
16+
private static readonly ApproximateFloatComparer TolerantComparer = new(1e-5F);
17+
18+
public static readonly TheoryData<RgbWorkingSpace> WorkingSpaces = new()
19+
{
20+
KnownRgbWorkingSpaces.SRgb,
21+
KnownRgbWorkingSpaces.SRgbSimplified,
22+
KnownRgbWorkingSpaces.Rec709,
23+
KnownRgbWorkingSpaces.Rec2020,
24+
KnownRgbWorkingSpaces.ECIRgbv2,
25+
KnownRgbWorkingSpaces.AdobeRgb1998,
26+
KnownRgbWorkingSpaces.ApplesRgb,
27+
KnownRgbWorkingSpaces.BestRgb,
28+
KnownRgbWorkingSpaces.BetaRgb,
29+
KnownRgbWorkingSpaces.BruceRgb,
30+
KnownRgbWorkingSpaces.CIERgb,
31+
KnownRgbWorkingSpaces.ColorMatchRgb,
32+
KnownRgbWorkingSpaces.DonRgb4,
33+
KnownRgbWorkingSpaces.EktaSpacePS5,
34+
KnownRgbWorkingSpaces.NTSCRgb,
35+
KnownRgbWorkingSpaces.PALSECAMRgb,
36+
KnownRgbWorkingSpaces.ProPhotoRgb,
37+
KnownRgbWorkingSpaces.SMPTECRgb,
38+
KnownRgbWorkingSpaces.WideGamutRgb
39+
};
40+
41+
[Fact]
42+
public void RgbWorkingSpaceEqualityRequiresSameConcreteType()
43+
{
44+
RgbWorkingSpace sRgb = KnownRgbWorkingSpaces.SRgb;
45+
RgbWorkingSpace sRgbSimplified = KnownRgbWorkingSpaces.SRgbSimplified;
46+
RgbWorkingSpace rec709 = KnownRgbWorkingSpaces.Rec709;
47+
48+
Assert.False(sRgb.Equals(sRgbSimplified));
49+
Assert.False(sRgbSimplified.Equals(sRgb));
50+
Assert.False(sRgb.Equals(rec709));
51+
Assert.False(rec709.Equals(sRgb));
52+
53+
Assert.NotEqual(sRgb.GetHashCode(), sRgbSimplified.GetHashCode());
54+
Assert.NotEqual(sRgb.GetHashCode(), rec709.GetHashCode());
55+
}
56+
57+
[Fact]
58+
public void RgbWorkingSpaceEqualityMatchesSameConcreteTypeValues()
59+
{
60+
RgbWorkingSpace x = new SRgbWorkingSpace(
61+
KnownRgbWorkingSpaces.SRgb.WhitePoint,
62+
KnownRgbWorkingSpaces.SRgb.ChromaticityCoordinates);
63+
64+
RgbWorkingSpace y = new SRgbWorkingSpace(
65+
KnownRgbWorkingSpaces.SRgb.WhitePoint,
66+
KnownRgbWorkingSpaces.SRgb.ChromaticityCoordinates);
67+
68+
Assert.Equal(x, y);
69+
Assert.Equal(x.GetHashCode(), y.GetHashCode());
70+
}
71+
72+
[Fact]
73+
public void GammaWorkingSpaceEqualityIncludesGamma()
74+
{
75+
GammaWorkingSpace x = new(
76+
2.2F,
77+
KnownRgbWorkingSpaces.SRgbSimplified.WhitePoint,
78+
KnownRgbWorkingSpaces.SRgbSimplified.ChromaticityCoordinates);
79+
80+
GammaWorkingSpace y = new(
81+
1.8F,
82+
KnownRgbWorkingSpaces.SRgbSimplified.WhitePoint,
83+
KnownRgbWorkingSpaces.SRgbSimplified.ChromaticityCoordinates);
84+
85+
Assert.NotEqual(x, y);
86+
Assert.NotEqual(x.GetHashCode(), y.GetHashCode());
87+
}
88+
89+
[Theory]
90+
[MemberData(nameof(WorkingSpaces))]
91+
public void CompressAndExpand_RoundTripsWithTolerance(RgbWorkingSpace workingSpace)
92+
{
93+
Vector4[] linear =
94+
[
95+
new(0F, .001F, .18F, 1F), // Endpoint, below the sRGB breakpoint, common middle gray, and opaque alpha.
96+
new(.0031308F, .25F, .5F, .75F), // sRGB linear/gamma breakpoint with interior values and partial alpha.
97+
new(.75F, .5F, .25F, .5F), // Reversed interior values ensure channel order does not hide errors.
98+
new(1F, .8F, .2F, .25F) // Upper endpoint, high/low interior values, and low alpha.
99+
];
100+
101+
Vector4[] expectedCompressed = new Vector4[linear.Length];
102+
103+
for (int i = 0; i < linear.Length; i++)
104+
{
105+
Vector4 compressed = workingSpace.Compress(linear[i]);
106+
Vector4 expanded = workingSpace.Expand(compressed);
107+
108+
expectedCompressed[i] = compressed;
109+
110+
Assert.Equal(linear[i], expanded, TolerantComparer);
111+
}
112+
113+
Vector4[] actualCompressed = linear.ToArray();
114+
workingSpace.Compress(actualCompressed);
115+
116+
Assert.Equal(expectedCompressed, actualCompressed, TolerantComparer);
117+
118+
workingSpace.Expand(actualCompressed);
119+
120+
Assert.Equal(linear, actualCompressed, TolerantComparer);
121+
}
122+
}

0 commit comments

Comments
 (0)