|
|
|
@ -4,12 +4,11 @@ |
|
|
|
using System.Buffers; |
|
|
|
using System.Numerics; |
|
|
|
using SixLabors.ImageSharp.Advanced; |
|
|
|
using SixLabors.ImageSharp.ColorSpaces.Conversion.Icc; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using SixLabors.ImageSharp.Metadata.Profiles.Icc; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.Icc; |
|
|
|
namespace SixLabors.ImageSharp.ColorProfiles.Icc; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Allows the conversion between ICC profiles.
|
|
|
|
@ -41,10 +40,10 @@ internal static class IccProfileConverter |
|
|
|
|
|
|
|
image.ProcessPixelRows(accessor => |
|
|
|
{ |
|
|
|
Vector3 illuminant = outputIccProfile.Header.PcsIlluminant; |
|
|
|
ColorSpaceConverter converter = new(new ColorSpaceConverterOptions() |
|
|
|
ColorProfileConverter converter = new(new ColorConversionOptions() |
|
|
|
{ |
|
|
|
WhitePoint = new(illuminant), |
|
|
|
WhitePoint = new CieXyz(inputIccProfile.Header.PcsIlluminant), |
|
|
|
TargetWhitePoint = new CieXyz(outputIccProfile.Header.PcsIlluminant), |
|
|
|
}); |
|
|
|
|
|
|
|
// TODO: Our Xxy/Lab conversion are dependent on the version number. We are applying the conversion using V4
|
|
|
|
@ -61,27 +60,29 @@ internal static class IccProfileConverter |
|
|
|
Span<TPixel> row = accessor.GetRowSpan(y); |
|
|
|
PixelOperations<TPixel>.Instance.ToVector4(configuration, row, vectorsSpan, PixelConversionModifiers.Scale); |
|
|
|
|
|
|
|
if (inputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieLab |
|
|
|
&& outputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieXyz) |
|
|
|
if (inputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieLab && |
|
|
|
outputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieXyz) |
|
|
|
{ |
|
|
|
for (int x = 0; x < vectorsSpan.Length; x++) |
|
|
|
{ |
|
|
|
Vector4 pcs = converterDataToPcs.Calculate(vectorsSpan[x]); |
|
|
|
temp[x] = pcs; |
|
|
|
pcs = PcsToLab(pcs); |
|
|
|
CieXyz xyz = converter.ToCieXyz(new CieLab(pcs.X, pcs.Y, pcs.Z, new CieXyz(inputIccProfile.Header.PcsIlluminant))); |
|
|
|
CieLab lab = new(pcs.X, pcs.Y, pcs.Z); |
|
|
|
CieXyz xyz = converter.Convert<CieLab, CieXyz>(in lab); |
|
|
|
pcs = XyzToPcs(pcs, xyz); |
|
|
|
|
|
|
|
vectorsSpan[x] = converterPcsToData.Calculate(pcs); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (inputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieXyz |
|
|
|
&& outputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieLab) |
|
|
|
else if (inputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieXyz && |
|
|
|
outputIccProfile.Header.ProfileConnectionSpace == IccColorSpaceType.CieLab) |
|
|
|
{ |
|
|
|
for (int x = 0; x < vectorsSpan.Length; x++) |
|
|
|
{ |
|
|
|
Vector4 pcs = converterDataToPcs.Calculate(vectorsSpan[x]); |
|
|
|
CieLab lab = converter.ToCieLab(new CieXyz(pcs.X, pcs.Y, pcs.Z)); |
|
|
|
CieXyz xyz = new(pcs.X, pcs.Y, pcs.Z); |
|
|
|
CieLab lab = converter.Convert<CieXyz, CieLab>(in xyz); |
|
|
|
pcs = LabToPcs(pcs, lab); |
|
|
|
vectorsSpan[x] = converterPcsToData.Calculate(pcs); |
|
|
|
} |
|
|
|
@ -121,6 +122,7 @@ internal static class IccProfileConverter |
|
|
|
private static unsafe Vector4 XyzToPcs(Vector4 input, CieXyz xyz) |
|
|
|
{ |
|
|
|
Vector3* v = (Vector3*)&input; |
|
|
|
v[0] = xyz.ToVector3(); |
|
|
|
v[0] *= 32768 / 65535f; |
|
|
|
return input; |
|
|
|
} |