Browse Source

Fix one test case, add boundary test cases

pull/1567/head
Wacton 1 year ago
parent
commit
121ffdd203
  1. 2
      src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs
  2. 30
      tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs

2
src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs

@ -31,6 +31,8 @@ internal class LutCalculator : ISingleCalculator
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private float Lookup(float value) private float Lookup(float value)
{ {
value = Math.Max(value, 0);
float factor = value * (this.lut.Length - 1); float factor = value * (this.lut.Length - 1);
int index = (int)factor; int index = (int)factor;
float low = this.lut[index]; float low = this.lut[index];

30
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.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.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) [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()]; List<float[]> inputs =
double[] expectedTargetValues = GetExpectedTargetValues(sourceProfile, targetProfile, input); [
Vector4 actualTargetValues = GetActualTargetValues(input, sourceProfile, targetProfile); [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)}"); foreach (float[] input in inputs)
const double tolerance = 0.00005;
for (int i = 0; i < expectedTargetValues.Length; i++)
{ {
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);
}
} }
} }

Loading…
Cancel
Save