From 63c89ca9da9668fe7c14634806befb533aad60f4 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 1 Nov 2023 20:25:39 +1000 Subject: [PATCH] Use scaled Vector4 conversion and optimize --- .../Implementation/Icc/IccProfileConverter.cs | 15 +++++++-------- .../Colorspaces/Icc/IccProfileConverterTests.cs | 1 + 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Icc/IccProfileConverter.cs b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Icc/IccProfileConverter.cs index 66ec0b4340..2c11b0bc43 100644 --- a/src/ImageSharp/ColorSpaces/Conversion/Implementation/Icc/IccProfileConverter.cs +++ b/src/ImageSharp/ColorSpaces/Conversion/Implementation/Icc/IccProfileConverter.cs @@ -41,6 +41,12 @@ internal static class IccProfileConverter image.ProcessPixelRows(accessor => { + Vector3 illuminant = outputIccProfile.Header.PcsIlluminant; + ColorSpaceConverter converter = new(new ColorSpaceConverterOptions() + { + WhitePoint = new(illuminant), + }); + using IMemoryOwner vectors = configuration.MemoryAllocator.Allocate(accessor.Width); Span vectorsSpan = vectors.GetSpan(); for (int y = 0; y < accessor.Height; y++) @@ -51,7 +57,6 @@ internal static class IccProfileConverter if (inputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieLab && outputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieXyz) { - ColorSpaceConverter converter = new(); for (int x = 0; x < vectorsSpan.Length; x++) { Vector4 pcs = converterDataToPcs.Calculate(vectorsSpan[x]); @@ -65,12 +70,6 @@ internal static class IccProfileConverter else if (inputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieXyz && outputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieLab) { - Vector3 illuminant = outputIccProfile.Header.PcsIlluminant; - ColorSpaceConverter converter = new(new ColorSpaceConverterOptions() - { - WhitePoint = new(illuminant), - }); - for (int x = 0; x < vectorsSpan.Length; x++) { Vector4 pcs = converterDataToPcs.Calculate(vectorsSpan[x]); @@ -88,7 +87,7 @@ internal static class IccProfileConverter } } - PixelOperations.Instance.FromVector4Destructive(configuration, vectorsSpan, row); + PixelOperations.Instance.FromVector4Destructive(configuration, vectorsSpan, row, PixelConversionModifiers.Scale); } }); diff --git a/tests/ImageSharp.Tests/Colorspaces/Icc/IccProfileConverterTests.cs b/tests/ImageSharp.Tests/Colorspaces/Icc/IccProfileConverterTests.cs index 2153f14201..1decff7712 100644 --- a/tests/ImageSharp.Tests/Colorspaces/Icc/IccProfileConverterTests.cs +++ b/tests/ImageSharp.Tests/Colorspaces/Icc/IccProfileConverterTests.cs @@ -34,6 +34,7 @@ public class IccProfileConverterTests image.DebugSave(provider, extension: "png", appendPixelTypeToFileName: false, appendSourceFileOrDescription: true, encoder: Encoder); + // TODO: This is comparing the input image. It should compare the output. TPixel actual = image[0, 0]; Assert.Equal(expected, actual);