@ -17,6 +17,12 @@ namespace SixLabors.ImageSharp.PixelFormats
SRgbCompand = 1 < < 2 ,
}
internal static class PixelConversionModifiersExtensions
{
public static bool IsDefined ( this PixelConversionModifiers modifiers , PixelConversionModifiers expected ) = >
( modifiers & expected ) = = expected ;
}
/// <summary>
/// A stateless class implementing Strategy Pattern for batched pixel-data conversion operations
/// for pixel buffers of type <typeparamref name="TPixel"/>.
@ -32,71 +38,93 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// Bulk version of <see cref="IPixel.FromVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'.
/// TODO: Rename to DestructiveFromVector4() + add explain behavior
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination colors.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the conversion</param>
internal virtual void FromVector4 (
Configuration configuration ,
Span < Vector4 > sourceVectors ,
Span < TPixel > destPixels )
Span < TPixel > destPixels ,
PixelConversionModifiers modifiers )
{
Guard . NotNull ( configuration , nameof ( configuration ) ) ;
Guard . DestinationShouldNotBeTooShort ( sourceVectors , destPixels , nameof ( destPixels ) ) ;
Utils . Vector4Converters . Default . DangerousFromVector4 ( sourceVectors , destPixels ) ;
if ( modifiers . IsDefined ( PixelConversionModifiers . Scale ) )
{
Utils . Vector4Converters . Default . DangerousFromScaledVector4 ( sourceVectors , destPixels ) ;
}
else
{
Utils . Vector4Converters . Default . DangerousFromVector4 ( sourceVectors , destPixels ) ;
}
}
/// <summary>
/// TODO: For compatibility, should be inlined!
/// </summary>
internal void FromScaledVector4 (
Configuration configuration ,
Span < Vector4 > sourceVectors ,
Span < TPixel > destPixels ) = >
this . FromVector4 ( configuration , sourceVectors , destPixels , PixelConversionModifiers . Scale ) ;
/// <summary>
/// Bulk version of <see cref="IPixel.FromVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'.
/// TODO: Rename to DestructiveFromVector4() + add explain behavior
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param>
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination colors.</param>
internal void FromVector4 ( Configuration configuration , Span < Vector4 > sourceVectors , Span < TPixel > destPixels ) = >
this . FromVector4 ( configuration , sourceVectors , destPixels , PixelConversionModifiers . None ) ;
/// <summary>
/// Bulk version of <see cref="IPixel.ToVector4()"/> converting 'sourceColors.Length' pixels into 'destinationVectors'.
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source colors.</param>
/// <param name="destVectors">The <see cref="Span{T}"/> to the destination vectors.</param>
/// <param name="modifiers">The <see cref="PixelConversionModifiers"/> to apply during the conversion</param>
internal virtual void ToVector4 (
Configuration configuration ,
ReadOnlySpan < TPixel > sourcePixels ,
Span < Vector4 > destVectors )
Span < Vector4 > destVectors ,
PixelConversionModifiers modifiers )
{
Guard . NotNull ( configuration , nameof ( configuration ) ) ;
Guard . DestinationShouldNotBeTooShort ( sourcePixels , destVectors , nameof ( destVectors ) ) ;
Utils . Vector4Converters . Default . DangerousToVector4 ( sourcePixels , destVectors ) ;
if ( modifiers . IsDefined ( PixelConversionModifiers . Scale ) )
{
Utils . Vector4Converters . Default . DangerousToScaledVector4 ( sourcePixels , destVectors ) ;
}
else
{
Utils . Vector4Converters . Default . DangerousToVector4 ( sourcePixels , destVectors ) ;
}
}
/// <summary>
/// Bulk version of <see cref="IPixel.FromScaledVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'.
/// Bulk version of <see cref="IPixel.ToVector4()"/> converting 'sourceColors.Length' pixels into 'destinationVect ors'.
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourceVectors">The <see cref="Span{T}"/> to the source vectors.</param>
/// <param name="destinationColors">The <see cref="Span{T}"/> to the destination col ors.</param>
internal virtual void FromScaled Vector4(
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source col ors.</param>
/// <param name="destVectors">The <see cref="Span{T}"/> to the destination vect ors.</param>
internal virtual void To Vector4(
Configuration configuration ,
Span < Vector4 > sourceVectors ,
Span < TPixel > destinationColors )
{
Guard . NotNull ( configuration , nameof ( configuration ) ) ;
Guard . DestinationShouldNotBeTooShort ( sourceVectors , destinationColors , nameof ( destinationColors ) ) ;
Utils . Vector4Converters . Default . DangerousFromScaledVector4 ( sourceVectors , destinationColors ) ;
}
ReadOnlySpan < TPixel > sourcePixels ,
Span < Vector4 > destVectors ) = >
this . ToVector4 ( configuration , sourcePixels , destVectors , PixelConversionModifiers . None ) ;
/// <summary>
/// Bulk version of <see cref="IPixel.ToScaledVector4()"/> converting 'sourceColors.Length' pixels into 'destinationVectors'.
/// TODO: For compatibility, should be inlined!
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourceColors">The <see cref="Span{T}"/> to the source colors.</param>
/// <param name="destinationVectors">The <see cref="Span{T}"/> to the destination vectors.</param>
internal virtual void ToScaledVector4 (
Configuration configuration ,
ReadOnlySpan < TPixel > sourceColors ,
Span < Vector4 > destinationVectors )
{
Guard . NotNull ( configuration , nameof ( configuration ) ) ;
Guard . DestinationShouldNotBeTooShort ( sourceColors , destinationVectors , nameof ( destinationVectors ) ) ;
Utils . Vector4Converters . Default . DangerousToScaledVector4 ( sourceColors , destinationVectors ) ;
}
internal void ToScaledVector4 ( Configuration configuration , ReadOnlySpan < TPixel > sourcePixels , Span < Vector4 > destVectors ) = >
this . ToVector4 ( configuration , sourcePixels , destVectors , PixelConversionModifiers . Scale ) ;
/// <summary>
/// Converts 'sourceColors.Length' pixels from 'sourceColors' into 'destinationColors'.