From 121ffdd2031bc327ad7e3b15ce2c90e1a4ce6447 Mon Sep 17 00:00:00 2001 From: Wacton Date: Sun, 9 Feb 2025 15:21:31 +0000 Subject: [PATCH] Fix one test case, add boundary test cases --- .../Icc/Calculators/LutCalculator.cs | 2 ++ .../Icc/ColorProfileConverterTests.Icc.cs | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs index 824310b3ad..83704ae214 100644 --- a/src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs @@ -31,6 +31,8 @@ internal class LutCalculator : ISingleCalculator [MethodImpl(MethodImplOptions.AggressiveInlining)] private float Lookup(float value) { + value = Math.Max(value, 0); + float factor = value * (this.lut.Length - 1); int index = (int)factor; float low = this.lut[index]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs index 5393a62570..e7be6b793c 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs @@ -27,17 +27,31 @@ public class ColorProfileConverterTests(ITestOutputHelper testOutputHelper) [InlineData(TestIccProfiles.RommRgb, TestIccProfiles.StandardRgbV4)] // CMYK -> LAB -> CMYK (different bit depth v2 LUTs, 16-bit vs 8-bit) [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.StandardRgbV2)] // CMYK -> LAB -> XYZ -> RGB (different LUT tags, A2B vs TRC) [InlineData(TestIccProfiles.StandardRgbV2, TestIccProfiles.Fogra39)] // RGB -> XYZ -> LAB -> CMYK (different LUT tags, TRC vs A2B) - public void CanConvertCmykIccProfiles(string sourceProfile, string targetProfile) + public void CanConvertIccProfiles(string sourceProfile, string targetProfile) { - float[] input = [GetNormalizedRandomValue(), GetNormalizedRandomValue(), GetNormalizedRandomValue(), GetNormalizedRandomValue()]; - double[] expectedTargetValues = GetExpectedTargetValues(sourceProfile, targetProfile, input); - Vector4 actualTargetValues = GetActualTargetValues(input, sourceProfile, targetProfile); + List inputs = + [ + [0, 0, 0, 0], + [1, 0, 0, 0], + [0, 1, 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1], + [1, 1, 1, 1], + [0.5f, 0.5f, 0.5f, 0.5f], + [GetNormalizedRandomValue(), GetNormalizedRandomValue(), GetNormalizedRandomValue(), GetNormalizedRandomValue()] + ]; - testOutputHelper.WriteLine($"Input {string.Join(", ", input)} · Expected output {string.Join(", ", expectedTargetValues)}"); - const double tolerance = 0.00005; - for (int i = 0; i < expectedTargetValues.Length; i++) + foreach (float[] input in inputs) { - Assert.Equal(expectedTargetValues[i], actualTargetValues[i], tolerance); + double[] expectedTargetValues = GetExpectedTargetValues(sourceProfile, targetProfile, input); + Vector4 actualTargetValues = GetActualTargetValues(input, sourceProfile, targetProfile); + + testOutputHelper.WriteLine($"Input {string.Join(", ", input)} · Expected output {string.Join(", ", expectedTargetValues)}"); + const double tolerance = 0.00005; + for (int i = 0; i < expectedTargetValues.Length; i++) + { + Assert.Equal(expectedTargetValues[i], actualTargetValues[i], tolerance); + } } }