|
| 1 | +// Copyright (c) Six Labors. |
| 2 | +// Licensed under the Six Labors Split License. |
| 3 | + |
| 4 | +using SixLabors.ImageSharp.ColorProfiles; |
| 5 | + |
| 6 | +namespace SixLabors.ImageSharp.Tests.ColorProfiles; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Tests <see cref="CieLuv"/>-<see cref="HunterLab"/> conversions. |
| 10 | +/// </summary> |
| 11 | +public class CieLuvAndHunterLabConversionTests |
| 12 | +{ |
| 13 | + private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); |
| 14 | + |
| 15 | + [Theory] |
| 16 | + [InlineData(0, 0, 0, 0, 0, 0)] |
| 17 | + [InlineData(36.0555, 93.6901, 10.01514, 30.59289, 48.55542, 9.80487)] |
| 18 | + public void Convert_CieLuv_to_HunterLab(float l, float u, float v, float l2, float a, float b) |
| 19 | + { |
| 20 | + // Arrange |
| 21 | + CieLuv input = new(l, u, v); |
| 22 | + HunterLab expected = new(l2, a, b); |
| 23 | + ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 }; |
| 24 | + ColorProfileConverter converter = new(options); |
| 25 | + |
| 26 | + Span<CieLuv> inputSpan = new CieLuv[5]; |
| 27 | + inputSpan.Fill(input); |
| 28 | + |
| 29 | + Span<HunterLab> actualSpan = new HunterLab[5]; |
| 30 | + |
| 31 | + // Act |
| 32 | + HunterLab actual = converter.Convert<CieLuv, HunterLab>(input); |
| 33 | + converter.Convert<CieLuv, HunterLab>(inputSpan, actualSpan); |
| 34 | + |
| 35 | + // Assert |
| 36 | + Assert.Equal(expected, actual, Comparer); |
| 37 | + |
| 38 | + for (int i = 0; i < actualSpan.Length; i++) |
| 39 | + { |
| 40 | + Assert.Equal(expected, actualSpan[i], Comparer); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + [Theory] |
| 45 | + [InlineData(0, 0, 0, 0, 0, 0)] |
| 46 | + [InlineData(30.59289, 48.55542, 9.80487, 36.0555, 93.6901, 10.01514)] |
| 47 | + public void Convert_HunterLab_to_CieLuv(float l2, float a, float b, float l, float u, float v) |
| 48 | + { |
| 49 | + // Arrange |
| 50 | + HunterLab input = new(l2, a, b); |
| 51 | + CieLuv expected = new(l, u, v); |
| 52 | + ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 }; |
| 53 | + ColorProfileConverter converter = new(options); |
| 54 | + |
| 55 | + Span<HunterLab> inputSpan = new HunterLab[5]; |
| 56 | + inputSpan.Fill(input); |
| 57 | + |
| 58 | + Span<CieLuv> actualSpan = new CieLuv[5]; |
| 59 | + |
| 60 | + // Act |
| 61 | + CieLuv actual = converter.Convert<HunterLab, CieLuv>(input); |
| 62 | + converter.Convert<HunterLab, CieLuv>(inputSpan, actualSpan); |
| 63 | + |
| 64 | + // Assert |
| 65 | + Assert.Equal(expected, actual, Comparer); |
| 66 | + |
| 67 | + for (int i = 0; i < actualSpan.Length; i++) |
| 68 | + { |
| 69 | + Assert.Equal(expected, actualSpan[i], Comparer); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments