|
| 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.Conversion; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Tests <see cref="CieLab"/>-<see cref="CieLchuv"/> conversions. |
| 10 | +/// </summary> |
| 11 | +/// <remarks> |
| 12 | +/// Test data generated using: |
| 13 | +/// <see href="http://www.brucelindbloom.com/index.html?ColorCalculator.html"/> |
| 14 | +/// </remarks> |
| 15 | +public class CieLabAndCieLchuvConversionTests |
| 16 | +{ |
| 17 | + private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); |
| 18 | + |
| 19 | + [Theory] |
| 20 | + [InlineData(0, 0, 0, 0, 0, 0)] |
| 21 | + [InlineData(30.66194, 200, 352.7564, 31.95653, 116.8745, 2.388602)] |
| 22 | + public void Convert_Lchuv_to_Lab(float l, float c, float h, float l2, float a, float b) |
| 23 | + { |
| 24 | + // Arrange |
| 25 | + CieLchuv input = new(l, c, h); |
| 26 | + CieLab expected = new(l2, a, b); |
| 27 | + ColorConversionOptions options = new() { WhitePoint = Illuminants.D65, TargetWhitePoint = Illuminants.D50 }; |
| 28 | + ColorProfileConverter converter = new(options); |
| 29 | + |
| 30 | + Span<CieLchuv> inputSpan = new CieLchuv[5]; |
| 31 | + inputSpan.Fill(input); |
| 32 | + |
| 33 | + Span<CieLab> actualSpan = new CieLab[5]; |
| 34 | + |
| 35 | + // Act |
| 36 | + CieLab actual = converter.Convert<CieLchuv, CieLab>(input); |
| 37 | + converter.Convert<CieLchuv, CieLab>(inputSpan, actualSpan); |
| 38 | + |
| 39 | + // Assert |
| 40 | + Assert.Equal(expected, actual, Comparer); |
| 41 | + |
| 42 | + for (int i = 0; i < actualSpan.Length; i++) |
| 43 | + { |
| 44 | + Assert.Equal(expected, actualSpan[i], Comparer); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + [Theory] |
| 49 | + [InlineData(0, 0, 0, 0, 0, 0)] |
| 50 | + [InlineData(36.0555, 303.6901, 10.01514, 29.4713573, 200, 352.6346)] |
| 51 | + public void Convert_Lab_to_Lchuv(float l, float a, float b, float l2, float c, float h) |
| 52 | + { |
| 53 | + // Arrange |
| 54 | + CieLab input = new(l, a, b); |
| 55 | + CieLchuv expected = new(l2, c, h); |
| 56 | + ColorConversionOptions options = new() { WhitePoint = Illuminants.D50, TargetWhitePoint = Illuminants.D65 }; |
| 57 | + ColorProfileConverter converter = new(options); |
| 58 | + |
| 59 | + Span<CieLab> inputSpan = new CieLab[5]; |
| 60 | + inputSpan.Fill(input); |
| 61 | + |
| 62 | + Span<CieLchuv> actualSpan = new CieLchuv[5]; |
| 63 | + |
| 64 | + // Act |
| 65 | + CieLchuv actual = converter.Convert<CieLab, CieLchuv>(input); |
| 66 | + converter.Convert<CieLab, CieLchuv>(inputSpan, actualSpan); |
| 67 | + |
| 68 | + // Assert |
| 69 | + Assert.Equal(expected, actual, Comparer); |
| 70 | + |
| 71 | + for (int i = 0; i < actualSpan.Length; i++) |
| 72 | + { |
| 73 | + Assert.Equal(expected, actualSpan[i], Comparer); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments