@ -25,6 +25,47 @@ public static class VonKriesChromaticAdaptation
/// <param name="matrix">The chromatic adaptation matrix.</param>
/// <param name="matrix">The chromatic adaptation matrix.</param>
/// <returns>The <see cref="CieXyz"/></returns>
/// <returns>The <see cref="CieXyz"/></returns>
public static CieXyz Transform ( in CieXyz source , ( CieXyz From , CieXyz To ) whitePoints , Matrix4x4 matrix )
public static CieXyz Transform ( in CieXyz source , ( CieXyz From , CieXyz To ) whitePoints , Matrix4x4 matrix )
{
Matrix4x4 . Invert ( matrix , out Matrix4x4 inverseMatrix ) ;
return Transform ( in source , whitePoints , matrix , inverseMatrix ) ;
}
/// <summary>
/// Performs a bulk linear transformation of a source color in to the destination color.
/// </summary>
/// <remarks>Doesn't crop the resulting color space coordinates (e. g. allows negative values for XYZ coordinates).</remarks>
/// <param name="source">The span to the source colors.</param>
/// <param name="destination">The span to the destination colors.</param>
/// <param name="whitePoints">The conversion white points.</param>
/// <param name="matrix">The chromatic adaptation matrix.</param>
public static void Transform (
ReadOnlySpan < CieXyz > source ,
Span < CieXyz > destination ,
( CieXyz From , CieXyz To ) whitePoints ,
Matrix4x4 matrix )
{
Matrix4x4 . Invert ( matrix , out Matrix4x4 inverseMatrix ) ;
Transform ( source , destination , whitePoints , matrix , inverseMatrix ) ;
}
/// <summary>
/// Performs a linear transformation of a source color in to the destination color using a
/// precomputed inverse of <paramref name="matrix"/>.
/// </summary>
/// <remarks>
/// For callers that already hold the inverse, e.g. <see cref="ColorConversionOptions.InverseAdaptationMatrix"/>,
/// to avoid repeating <see cref="Matrix4x4.Invert"/> on every call.
/// </remarks>
/// <param name="source">The source color.</param>
/// <param name="whitePoints">The conversion white points.</param>
/// <param name="matrix">The chromatic adaptation matrix.</param>
/// <param name="inverseMatrix">The inverse of <paramref name="matrix"/>.</param>
/// <returns>The <see cref="CieXyz"/></returns>
internal static CieXyz Transform (
in CieXyz source ,
( CieXyz From , CieXyz To ) whitePoints ,
Matrix4x4 matrix ,
Matrix4x4 inverseMatrix )
{
{
CieXyz from = whitePoints . From ;
CieXyz from = whitePoints . From ;
CieXyz to = whitePoints . To ;
CieXyz to = whitePoints . To ;
@ -41,23 +82,28 @@ public static class VonKriesChromaticAdaptation
Vector3 vector = targetWhitePointLms / sourceWhitePointLms ;
Vector3 vector = targetWhitePointLms / sourceWhitePointLms ;
Vector3 targetColorLms = Vector3 . Multiply ( vector , sourceColorLms ) ;
Vector3 targetColorLms = Vector3 . Multiply ( vector , sourceColorLms ) ;
Matrix4x4 . Invert ( matrix , out Matrix4x4 inverseMatrix ) ;
return new CieXyz ( Vector3 . Transform ( targetColorLms , inverseMatrix ) ) ;
return new CieXyz ( Vector3 . Transform ( targetColorLms , inverseMatrix ) ) ;
}
}
/// <summary>
/// <summary>
/// Performs a bulk linear transformation of a source color in to the destination color.
/// Performs a bulk linear transformation of a source color in to the destination color using a
/// precomputed inverse of <paramref name="matrix"/>.
/// </summary>
/// </summary>
/// <remarks>Doesn't crop the resulting color space coordinates (e. g. allows negative values for XYZ coordinates).</remarks>
/// <remarks>
/// For callers that already hold the inverse, e.g. <see cref="ColorConversionOptions.InverseAdaptationMatrix"/>,
/// to avoid repeating <see cref="Matrix4x4.Invert"/> on every call.
/// </remarks>
/// <param name="source">The span to the source colors.</param>
/// <param name="source">The span to the source colors.</param>
/// <param name="destination">The span to the destination colors.</param>
/// <param name="destination">The span to the destination colors.</param>
/// <param name="whitePoints">The conversion white points.</param>
/// <param name="whitePoints">The conversion white points.</param>
/// <param name="matrix">The chromatic adaptation matrix.</param>
/// <param name="matrix">The chromatic adaptation matrix.</param>
public static void Transform (
/// <param name="inverseMatrix">The inverse of <paramref name="matrix"/>.</param>
internal static void Transform (
ReadOnlySpan < CieXyz > source ,
ReadOnlySpan < CieXyz > source ,
Span < CieXyz > destination ,
Span < CieXyz > destination ,
( CieXyz From , CieXyz To ) whitePoints ,
( CieXyz From , CieXyz To ) whitePoints ,
Matrix4x4 matrix )
Matrix4x4 matrix ,
Matrix4x4 inverseMatrix )
{
{
Guard . DestinationShouldNotBeTooShort ( source , destination , nameof ( destination ) ) ;
Guard . DestinationShouldNotBeTooShort ( source , destination , nameof ( destination ) ) ;
int count = source . Length ;
int count = source . Length ;
@ -71,8 +117,6 @@ public static class VonKriesChromaticAdaptation
return ;
return ;
}
}
Matrix4x4 . Invert ( matrix , out Matrix4x4 inverseMatrix ) ;
ref CieXyz sourceBase = ref MemoryMarshal . GetReference ( source ) ;
ref CieXyz sourceBase = ref MemoryMarshal . GetReference ( source ) ;
ref CieXyz destinationBase = ref MemoryMarshal . GetReference ( destination ) ;
ref CieXyz destinationBase = ref MemoryMarshal . GetReference ( destination ) ;