|
|
|
@ -28,6 +28,7 @@ |
|
|
|
ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source); |
|
|
|
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels); |
|
|
|
|
|
|
|
// For conversion methods writing only to RGB channels, we need to keep the alpha channel opaque! |
|
|
|
var temp = NamedColors<<#=tempPixelType#>>.Black; |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
@ -94,216 +95,6 @@ |
|
|
|
<# |
|
|
|
} |
|
|
|
|
|
|
|
void GeneratePackFromMethodUsingPackFromRgba64(string pixelType, string rgbaOperationCode) |
|
|
|
{ |
|
|
|
#> |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Converts 'count' elements in 'source` span of <see cref="<#=pixelType#>"/> data to a span of <typeparamref name="TPixel"/>-s. |
|
|
|
/// </summary> |
|
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="<#=pixelType#>"/> data.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
internal virtual void PackFrom<#=pixelType#>(ReadOnlySpan<<#=pixelType#>> source, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|
|
|
|
|
|
|
ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source); |
|
|
|
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels); |
|
|
|
|
|
|
|
var rgba = new Rgba64(0, 0, 0, 65535); |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
ref TPixel dp = ref Unsafe.Add(ref destRef, i); |
|
|
|
<#=rgbaOperationCode#> |
|
|
|
dp.PackFromRgba64(rgba); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// A helper for <see cref="PackFrom<#=pixelType#>(ReadOnlySpan{<#=pixelType#>}, Span{TPixel}, int)"/> that expects a byte span. |
|
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="<#=pixelType#>"/> layout. |
|
|
|
/// </summary> |
|
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
internal void PackFrom<#=pixelType#>Bytes(ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
this.PackFrom<#=pixelType#>(MemoryMarshal.Cast<byte, <#=pixelType#>>(sourceBytes), destPixels, count); |
|
|
|
} |
|
|
|
<# |
|
|
|
} |
|
|
|
|
|
|
|
void GeneratePackFromMethodUsingPackFromRgb48(string pixelType, string rgbaOperationCode) |
|
|
|
{ |
|
|
|
#> |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Converts 'count' elements in 'source` span of <see cref="<#=pixelType#>"/> data to a span of <typeparamref name="TPixel"/>-s. |
|
|
|
/// </summary> |
|
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="<#=pixelType#>"/> data.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
internal virtual void PackFrom<#=pixelType#>(ReadOnlySpan<<#=pixelType#>> source, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|
|
|
|
|
|
|
ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source); |
|
|
|
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels); |
|
|
|
|
|
|
|
var rgb = default(Rgb48); |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
ref TPixel dp = ref Unsafe.Add(ref destRef, i); |
|
|
|
<#=rgbaOperationCode#> |
|
|
|
dp.PackFromRgb48(rgb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// A helper for <see cref="PackFrom<#=pixelType#>(ReadOnlySpan{<#=pixelType#>}, Span{TPixel}, int)"/> that expects a byte span. |
|
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="<#=pixelType#>"/> layout. |
|
|
|
/// </summary> |
|
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
internal void PackFrom<#=pixelType#>Bytes(ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
this.PackFrom<#=pixelType#>(MemoryMarshal.Cast<byte, <#=pixelType#>>(sourceBytes), destPixels, count); |
|
|
|
} |
|
|
|
<# |
|
|
|
} |
|
|
|
|
|
|
|
void GeneratePackFromMethodUsingPackFromRgba32(string pixelType, string rgbaOperationCode) |
|
|
|
{ |
|
|
|
#> |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Converts 'count' elements in 'source` span of <see cref="<#=pixelType#>"/> data to a span of <typeparamref name="TPixel"/>-s. |
|
|
|
/// </summary> |
|
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="<#=pixelType#>"/> data.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
internal virtual void PackFrom<#=pixelType#>(ReadOnlySpan<<#=pixelType#>> source, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|
|
|
|
|
|
|
ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source); |
|
|
|
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels); |
|
|
|
|
|
|
|
var rgba = new Rgba32(0, 0, 0, 255); |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
ref TPixel dp = ref Unsafe.Add(ref destRef, i); |
|
|
|
<#=rgbaOperationCode#> |
|
|
|
dp.PackFromRgba32(rgba); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// A helper for <see cref="PackFrom<#=pixelType#>(ReadOnlySpan{<#=pixelType#>}, Span{TPixel}, int)"/> that expects a byte span. |
|
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="<#=pixelType#>"/> layout. |
|
|
|
/// </summary> |
|
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
internal void PackFrom<#=pixelType#>Bytes(ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
this.PackFrom<#=pixelType#>(MemoryMarshal.Cast<byte, <#=pixelType#>>(sourceBytes), destPixels, count); |
|
|
|
} |
|
|
|
<# |
|
|
|
} |
|
|
|
|
|
|
|
void GeneratePackFromMethodUsingPackFromArgb32(string pixelType, string argbOperationCode) |
|
|
|
{ |
|
|
|
#> |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Converts 'count' elements in 'source` span of <see cref="<#=pixelType#>"/> data to a span of <typeparamref name="TPixel"/>-s. |
|
|
|
/// </summary> |
|
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="<#=pixelType#>"/> data.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
internal virtual void PackFrom<#=pixelType#>(ReadOnlySpan<<#=pixelType#>> source, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|
|
|
|
|
|
|
ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source); |
|
|
|
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels); |
|
|
|
|
|
|
|
var argb = new Argb32(0, 0, 0, 255); |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
ref TPixel dp = ref Unsafe.Add(ref destRef, i); |
|
|
|
<#=argbOperationCode#> |
|
|
|
dp.PackFromArgb32(argb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// A helper for <see cref="PackFrom<#=pixelType#>(ReadOnlySpan{<#=pixelType#>}, Span{TPixel}, int)"/> that expects a byte span. |
|
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="<#=pixelType#>"/> layout. |
|
|
|
/// </summary> |
|
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
internal void PackFrom<#=pixelType#>Bytes(ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
this.PackFrom<#=pixelType#>(MemoryMarshal.Cast<byte, <#=pixelType#>>(sourceBytes), destPixels, count); |
|
|
|
} |
|
|
|
<# |
|
|
|
} |
|
|
|
|
|
|
|
void GeneratePackFromMethodUsingPackFromBgra32(string pixelType, string bgraOperationCode) |
|
|
|
{ |
|
|
|
#> |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Converts 'count' elements in 'source` span of <see cref="<#=pixelType#>"/> data to a span of <typeparamref name="TPixel"/>-s. |
|
|
|
/// </summary> |
|
|
|
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="<#=pixelType#>"/> data.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
internal virtual void PackFrom<#=pixelType#>(ReadOnlySpan<<#=pixelType#>> source, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count); |
|
|
|
|
|
|
|
ref <#=pixelType#> sourceRef = ref MemoryMarshal.GetReference(source); |
|
|
|
ref TPixel destRef = ref MemoryMarshal.GetReference(destPixels); |
|
|
|
|
|
|
|
var bgra = new Bgra32(0, 0, 0, 255); |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
ref TPixel dp = ref Unsafe.Add(ref destRef, i); |
|
|
|
<#=bgraOperationCode#> |
|
|
|
dp.PackFromBgra32(bgra); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// A helper for <see cref="PackFrom<#=pixelType#>(ReadOnlySpan{<#=pixelType#>}, Span{TPixel}, int)"/> that expects a byte span. |
|
|
|
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="<#=pixelType#>"/> layout. |
|
|
|
/// </summary> |
|
|
|
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param> |
|
|
|
/// <param name="destPixels">The <see cref="Span{T}"/> to the destination pixels.</param> |
|
|
|
/// <param name="count">The number of pixels to convert.</param> |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
internal void PackFrom<#=pixelType#>Bytes(ReadOnlySpan<byte> sourceBytes, Span<TPixel> destPixels, int count) |
|
|
|
{ |
|
|
|
this.PackFrom<#=pixelType#>(MemoryMarshal.Cast<byte, <#=pixelType#>>(sourceBytes), destPixels, count); |
|
|
|
} |
|
|
|
<# |
|
|
|
} |
|
|
|
|
|
|
|
#> |
|
|
|
// Copyright (c) Six Labors and contributors. |
|
|
|
// Licensed under the Apache License, Version 2.0. |
|
|
|
@ -318,35 +109,26 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
|
public partial class PixelOperations<TPixel> |
|
|
|
{ |
|
|
|
<# |
|
|
|
|
|
|
|
// GeneratePackFromMethodUsingPackFromRgba64("Rgba64", "rgba = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
|
|
|
|
GeneratePackFromMethods("Rgba64", "Rgba64", "temp = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GenerateToDestFormatMethods("Rgba64"); |
|
|
|
|
|
|
|
// GeneratePackFromMethodUsingPackFromRgb48("Rgb48", "rgb = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GeneratePackFromMethods("Rgb48", "Rgb48", "temp = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GenerateToDestFormatMethods("Rgb48"); |
|
|
|
|
|
|
|
GeneratePackFromMethods("Rgba32", "Rgba32", "temp = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GenerateToDestFormatMethods("Rgba32"); |
|
|
|
|
|
|
|
// GeneratePackFromMethodUsingPackFromBgra32("Bgra32", "bgra = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GeneratePackFromMethods("Bgra32", "Bgra32", "temp = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GenerateToDestFormatMethods("Bgra32"); |
|
|
|
|
|
|
|
// GeneratePackFromMethodUsingPackFromRgba32("Rgb24", "rgba.Rgb = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GeneratePackFromMethods("Rgb24", "Rgba32", "temp.Rgb = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GenerateToDestFormatMethods("Rgb24"); |
|
|
|
|
|
|
|
// GeneratePackFromMethodUsingPackFromRgba32("Bgr24", "rgba.Bgr = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GeneratePackFromMethods("Bgr24", "Rgba32", "temp.Bgr = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GenerateToDestFormatMethods("Bgr24"); |
|
|
|
|
|
|
|
// GeneratePackFromMethodUsingPackFromArgb32("Argb32", "argb = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GeneratePackFromMethods("Argb32", "Argb32", "temp = Unsafe.Add(ref sourceRef, i);"); |
|
|
|
GenerateToDestFormatMethods("Argb32"); |
|
|
|
|
|
|
|
#> |
|
|
|
|
|
|
|
} |
|
|
|
|