Browse Source

Add failing tests

pull/1567/head
James Jackson-South 3 years ago
parent
commit
c3984aa3bf
  1. 13
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Icc/Calculators/ClutCalculator.cs
  2. 2
      tests/ImageSharp.Tests/Colorspaces/Icc/IccProfileConverterTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Jpg/icc-profiles/issue-129.jpg

13
src/ImageSharp/ColorSpaces/Conversion/Implementation/Icc/Calculators/ClutCalculator.cs

@ -14,6 +14,7 @@ internal class ClutCalculator : IVector4Calculator
private readonly byte[] gridPointCount;
private readonly int[] indexFactor;
private readonly int nodeCount;
private readonly float[][] nodes;
public ClutCalculator(IccClut clut)
{
@ -25,6 +26,7 @@ internal class ClutCalculator : IVector4Calculator
this.gridPointCount = clut.GridPointCount;
this.indexFactor = CalculateIndexFactor(clut.InputChannelCount, clut.GridPointCount);
this.nodeCount = (int)Math.Pow(2, clut.InputChannelCount);
this.nodes = new float[this.nodeCount][];
}
public unsafe Vector4 Calculate(Vector4 value)
@ -50,8 +52,7 @@ internal class ClutCalculator : IVector4Calculator
private unsafe void Interpolate(float* values, int valueLength, float* result, int resultLength)
{
float[][] nodes = new float[this.nodeCount][];
for (int i = 0; i < nodes.Length; i++)
for (int i = 0; i < this.nodes.Length; i++)
{
int index = 0;
for (int j = 0; j < valueLength; j++)
@ -61,7 +62,9 @@ internal class ClutCalculator : IVector4Calculator
index += (int)((this.indexFactor[j] * (position * fraction)) + 0.5f);
}
nodes[i] = this.lut[index];
// TODO: The CMYK profile in our tests causes an out of range exception
// against 'lut'. Clamping the index leads to incorrect results.
this.nodes[i] = this.lut[index];
}
Span<float> factors = stackalloc float[this.nodeCount];
@ -92,9 +95,9 @@ internal class ClutCalculator : IVector4Calculator
for (int i = 0; i < resultLength; i++)
{
for (int j = 0; j < nodes.Length; j++)
for (int j = 0; j < this.nodes.Length; j++)
{
result[i] += nodes[j][i] * factors[j];
result[i] += this.nodes[j][i] * factors[j];
}
}
}

2
tests/ImageSharp.Tests/Colorspaces/Icc/IccProfileConverterTests.cs

@ -20,6 +20,7 @@ public class IccProfileConverterTests
[WithFile(TestImages.Jpeg.ICC.WideRGB, PixelTypes.Rgb24)]
[WithFile(TestImages.Jpeg.ICC.SRgb, PixelTypes.Rgb24)]
[WithFile(TestImages.Jpeg.ICC.ProPhoto, PixelTypes.Rgb24)]
[WithFile(TestImages.Jpeg.ICC.CMYK, PixelTypes.Rgb24)]
public void CanRoundTripProfile<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
@ -45,6 +46,7 @@ public class IccProfileConverterTests
[WithFile(TestImages.Jpeg.ICC.WideRGB, PixelTypes.Rgb24)]
[WithFile(TestImages.Jpeg.ICC.SRgb, PixelTypes.Rgb24)]
[WithFile(TestImages.Jpeg.ICC.ProPhoto, PixelTypes.Rgb24)]
[WithFile(TestImages.Jpeg.ICC.CMYK, PixelTypes.Rgb24)]
public void CanConvertToSRGB<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{

1
tests/ImageSharp.Tests/TestImages.cs

@ -176,6 +176,7 @@ public static class TestImages
public const string ProPhoto = "Jpg/icc-profiles/Momiji-ProPhoto-yes.jpg";
public const string WideRGB = "Jpg/icc-profiles/Momiji-WideRGB-yes.jpg";
public const string AppleRGB = "Jpg/icc-profiles/Momiji-AppleRGB-yes.jpg";
public const string CMYK = "Jpg/icc-profiles/issue-129.jpg";
}
public static class Progressive

3
tests/Images/Input/Jpg/icc-profiles/issue-129.jpg

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e1728dd548d862ef3f960c82528716e0ad1b8eb0119a5eed4dfde51026d7bb74
size 2903429
Loading…
Cancel
Save