Browse Source

Merge branch 'master' into dp/jpeg-sampling-factor-validation

pull/1899/head
James Jackson-South 4 years ago
committed by GitHub
parent
commit
48c0d82a44
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/ImageSharp/Advanced/AotCompilerTools.cs
  2. 24
      src/ImageSharp/Color/Color.Conversions.cs
  3. 56
      src/ImageSharp/Common/Helpers/Numerics.cs
  4. 37
      src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs
  5. 9
      src/ImageSharp/ImageSharp.csproj
  6. 6
      src/ImageSharp/PixelFormats/IPixel.cs
  7. 4
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  8. 396
      src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
  9. 10
      src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
  10. 10
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
  11. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
  12. 10
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
  13. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
  14. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
  15. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
  16. 4
      src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
  17. 4
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
  18. 4
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
  19. 7
      src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
  20. 4
      src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
  21. 8
      src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
  22. 12
      src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
  23. 4
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
  24. 4
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
  25. 4
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
  26. 4
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
  27. 26
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs
  28. 346
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs
  29. 18
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.tt
  30. 41
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs
  31. 41
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs
  32. 41
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs
  33. 42
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs
  34. 42
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs
  35. 42
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs
  36. 42
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs
  37. 42
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs
  38. 41
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs
  39. 42
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs
  40. 41
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs
  41. 42
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs
  42. 5
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude
  43. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
  44. 9
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
  45. 9
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
  46. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
  47. 10
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
  48. 37
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
  49. 4
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
  50. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
  51. 4
      src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
  52. 72
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs
  53. 3
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt
  54. 125
      src/ImageSharp/PixelFormats/Utils/PixelConverter.cs
  55. 13
      tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs
  56. 13
      tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs
  57. 13
      tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs
  58. 27
      tests/ImageSharp.Tests/Image/ImageCloneTests.cs
  59. 148
      tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs
  60. 11
      tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs
  61. 15
      tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs
  62. 59
      tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs
  63. 47
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs
  64. 2
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude
  65. 45
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
  66. 16
      tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs
  67. 24
      tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs
  68. 18
      tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs
  69. 4
      tests/ImageSharp.Tests/TestFormat.cs
  70. 2
      tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
  71. 5
      tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

2
src/ImageSharp/Advanced/AotCompilerTools.cs

@ -75,6 +75,7 @@ namespace SixLabors.ImageSharp.Advanced
Seed<A8>();
Seed<Argb32>();
Seed<Abgr32>();
Seed<Bgr24>();
Seed<Bgr565>();
Seed<Bgra32>();
@ -149,6 +150,7 @@ namespace SixLabors.ImageSharp.Advanced
Image<TPixel> img = default;
img.CloneAs<A8>(default);
img.CloneAs<Argb32>(default);
img.CloneAs<Abgr32>(default);
img.CloneAs<Bgr24>(default);
img.CloneAs<Bgr565>(default);
img.CloneAs<Bgra32>(default);

24
src/ImageSharp/Color/Color.Conversions.cs

@ -89,6 +89,17 @@ namespace SixLabors.ImageSharp
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Abgr32"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Abgr32 pixel)
{
this.data = new Rgba64(pixel);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
@ -177,6 +188,19 @@ namespace SixLabors.ImageSharp
return value;
}
[MethodImpl(InliningOptions.ShortMethod)]
internal Abgr32 ToAbgr32()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.ToAbgr32();
}
Abgr32 value = default;
value.FromScaledVector4(this.boxedHighPrecisionPixel.ToScaledVector4());
return value;
}
[MethodImpl(InliningOptions.ShortMethod)]
internal Rgb24 ToRgb24()
{

56
src/ImageSharp/Common/Helpers/Numerics.cs

@ -907,5 +907,61 @@ namespace SixLabors.ImageSharp
/// <param name="divisor">Divisor value.</param>
/// <returns>Ceiled division result.</returns>
public static uint DivideCeil(uint value, uint divisor) => (value + divisor - 1) / divisor;
/// <summary>
/// Rotates the specified value left by the specified number of bits.
/// </summary>
/// <param name="value">The value to rotate.</param>
/// <param name="offset">The number of bits to rotate with.</param>
/// <returns>The rotated value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateLeft(uint value, int offset)
{
#if SUPPORTS_BITOPERATIONS
return BitOperations.RotateLeft(value, offset);
#else
return RotateLeftSoftwareFallback(value, offset);
#endif
}
#if !SUPPORTS_BITOPERATIONS
/// <summary>
/// Rotates the specified value left by the specified number of bits.
/// </summary>
/// <param name="value">The value to rotate.</param>
/// <param name="offset">The number of bits to rotate with.</param>
/// <returns>The rotated value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateLeftSoftwareFallback(uint value, int offset)
=> (value << offset) | (value >> (32 - offset));
#endif
/// <summary>
/// Rotates the specified value right by the specified number of bits.
/// </summary>
/// <param name="value">The value to rotate.</param>
/// <param name="offset">The number of bits to rotate with.</param>
/// <returns>The rotated value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateRight(uint value, int offset)
{
#if SUPPORTS_BITOPERATIONS
return BitOperations.RotateRight(value, offset);
#else
return RotateRightSoftwareFallback(value, offset);
#endif
}
#if !SUPPORTS_BITOPERATIONS
/// <summary>
/// Rotates the specified value right by the specified number of bits.
/// </summary>
/// <param name="value">The value to rotate.</param>
/// <param name="offset">The number of bits to rotate with.</param>
/// <returns>The rotated value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateRightSoftwareFallback(uint value, int offset)
=> (value >> offset) | (value << (32 - offset));
#endif
}
}

37
src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs

@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp
// packed = [W Z Y X]
// ROTR(8, packedArgb) = [Y Z W X]
Unsafe.Add(ref dBase, i) = (packed >> 8) | (packed << 24);
Unsafe.Add(ref dBase, i) = Numerics.RotateRight(packed, 8);
}
}
}
@ -188,7 +188,40 @@ namespace SixLabors.ImageSharp
// tmp1 + tmp3 = [W X Y Z]
uint tmp1 = packed & 0xFF00FF00;
uint tmp2 = packed & 0x00FF00FF;
uint tmp3 = (tmp2 << 16) | (tmp2 >> 16);
uint tmp3 = Numerics.RotateLeft(tmp2, 16);
Unsafe.Add(ref dBase, i) = tmp1 + tmp3;
}
}
}
internal readonly struct XWZYShuffle4 : IShuffle4
{
public byte Control
{
[MethodImpl(InliningOptions.ShortMethod)]
get => SimdUtils.Shuffle.MmShuffle(1, 2, 3, 0);
}
[MethodImpl(InliningOptions.ShortMethod)]
public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest)
{
ref uint sBase = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source));
ref uint dBase = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest));
int n = source.Length / 4;
for (int i = 0; i < n; i++)
{
uint packed = Unsafe.Add(ref sBase, i);
// packed = [W Z Y X]
// tmp1 = [0 Z 0 X]
// tmp2 = [W 0 Y 0]
// tmp3=ROTL(16, tmp2) = [Y 0 W 0]
// tmp1 + tmp3 = [Y Z W X]
uint tmp1 = packed & 0x00FF00FF;
uint tmp2 = packed & 0xFF00FF00;
uint tmp3 = Numerics.RotateLeft(tmp2, 16);
Unsafe.Add(ref dBase, i) = tmp1 + tmp3;
}

9
src/ImageSharp/ImageSharp.csproj

@ -75,6 +75,11 @@
<AutoGen>True</AutoGen>
<DependentUpon>Block8x8F.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Abgr32.PixelOperations.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Abgr32.PixelOperations.Generated.tt</DependentUpon>
</Compile>
<Compile Update="PixelFormats\PixelOperations{TPixel}.Generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@ -166,6 +171,10 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Block8x8F.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelImplementations\PixelOperations\Generated\Abgr32.PixelOperations.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Abgr32.PixelOperations.Generated.cs</LastGenOutput>
</None>
<None Update="PixelFormats\PixelOperations{TPixel}.Generated.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>PixelOperations{TPixel}.Generated.cs</LastGenOutput>

6
src/ImageSharp/PixelFormats/IPixel.cs

@ -79,6 +79,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <param name="source">The <see cref="Bgra32"/> value.</param>
void FromBgra32(Bgra32 source);
/// <summary>
/// Initializes the pixel instance from an <see cref="Abgr32"/> value.
/// </summary>
/// <param name="source">The <see cref="Abgr32"/> value.</param>
void FromAbgr32(Abgr32 source);
/// <summary>
/// Initializes the pixel instance from an <see cref="L8"/> value.
/// </summary>

4
src/ImageSharp/PixelFormats/PixelImplementations/A8.cs

@ -87,6 +87,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.PackedValue = source.A;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.PackedValue = source.A;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

396
src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs

@ -0,0 +1,396 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <summary>
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in alpha, red, green, and blue order (least significant to most significant byte).
/// <para>
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
/// </para>
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public partial struct Abgr32 : IPixel<Abgr32>, IPackedVector<uint>
{
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
public byte A;
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public byte B;
/// <summary>
/// Gets or sets the green component.
/// </summary>
public byte G;
/// <summary>
/// Gets or sets the red component.
/// </summary>
public byte R;
/// <summary>
/// The maximum byte value.
/// </summary>
private static readonly Vector4 MaxBytes = new(255);
/// <summary>
/// The half vector value.
/// </summary>
private static readonly Vector4 Half = new(0.5F);
/// <summary>
/// Initializes a new instance of the <see cref="Abgr32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Abgr32(byte r, byte g, byte b)
{
this.R = r;
this.G = g;
this.B = b;
this.A = byte.MaxValue;
}
/// <summary>
/// Initializes a new instance of the <see cref="Abgr32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Abgr32(byte r, byte g, byte b, byte a)
{
this.R = r;
this.G = g;
this.B = b;
this.A = a;
}
/// <summary>
/// Initializes a new instance of the <see cref="Abgr32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Abgr32(float r, float g, float b, float a = 1)
: this() => this.Pack(r, g, b, a);
/// <summary>
/// Initializes a new instance of the <see cref="Abgr32"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
[MethodImpl(InliningOptions.ShortMethod)]
public Abgr32(Vector3 vector)
: this() => this.Pack(ref vector);
/// <summary>
/// Initializes a new instance of the <see cref="Abgr32"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
[MethodImpl(InliningOptions.ShortMethod)]
public Abgr32(Vector4 vector)
: this() => this.Pack(ref vector);
/// <summary>
/// Initializes a new instance of the <see cref="Abgr32"/> struct.
/// </summary>
/// <param name="packed">
/// The packed value.
/// </param>
[MethodImpl(InliningOptions.ShortMethod)]
public Abgr32(uint packed)
: this() => this.Abgr = packed;
/// <summary>
/// Gets or sets the packed representation of the Abgrb32 struct.
/// </summary>
public uint Abgr
{
[MethodImpl(InliningOptions.ShortMethod)]
readonly get => Unsafe.As<Abgr32, uint>(ref Unsafe.AsRef(this));
[MethodImpl(InliningOptions.ShortMethod)]
set => Unsafe.As<Abgr32, uint>(ref this) = value;
}
/// <inheritdoc/>
public uint PackedValue
{
[MethodImpl(InliningOptions.ShortMethod)]
readonly get => this.Abgr;
[MethodImpl(InliningOptions.ShortMethod)]
set => this.Abgr = value;
}
/// <summary>
/// Converts an <see cref="Abgr32"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Abgr32"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Abgr32 source) => new(source);
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Abgr32"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Abgr32"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Abgr32(Color color) => color.ToAbgr32();
/// <summary>
/// Compares two <see cref="Argb32"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="Abgr32"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Abgr32"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator ==(Abgr32 left, Abgr32 right) => left.Equals(right);
/// <summary>
/// Compares two <see cref="Abgr32"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="Abgr32"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Abgr32"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Abgr32 left, Abgr32 right) => !left.Equals(right);
/// <inheritdoc />
public readonly PixelOperations<Abgr32> CreatePixelOperations() => new PixelOperations();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToScaledVector4() => this.ToVector4();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector) => this.Pack(ref vector);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A) / MaxBytes;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this = source;
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)
{
// We can assign the Bgr24 value directly to last three bytes of this instance.
ref byte thisRef = ref Unsafe.As<Abgr32, byte>(ref this);
ref byte thisRefFromB = ref Unsafe.AddByteOffset(ref thisRef, new IntPtr(1));
Unsafe.As<byte, Bgr24>(ref thisRefFromB) = source;
this.A = byte.MaxValue;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source)
{
this.R = source.R;
this.G = source.G;
this.B = source.B;
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source)
{
this.R = source.R;
this.G = source.G;
this.B = source.B;
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source)
{
this.R = source.PackedValue;
this.G = source.PackedValue;
this.B = source.PackedValue;
this.A = byte.MaxValue;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source)
{
byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue);
this.R = rgb;
this.G = rgb;
this.B = rgb;
this.A = byte.MaxValue;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa16(La16 source)
{
this.R = source.L;
this.G = source.L;
this.B = source.L;
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source)
{
byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L);
this.R = rgb;
this.G = rgb;
this.B = rgb;
this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source)
{
this.R = source.R;
this.G = source.G;
this.B = source.B;
this.A = byte.MaxValue;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source)
{
this.R = source.R;
this.G = source.G;
this.B = source.B;
this.A = source.A;
}
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)
{
dest.R = this.R;
dest.G = this.G;
dest.B = this.B;
dest.A = this.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source)
{
this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
this.A = byte.MaxValue;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source)
{
this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R);
this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G);
this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B);
this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A);
}
/// <inheritdoc/>
public override readonly bool Equals(object obj) => obj is Abgr32 abgr32 && this.Equals(abgr32);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public readonly bool Equals(Abgr32 other) => this.Abgr == other.Abgr;
/// <summary>
/// Gets a string representation of the packed vector.
/// </summary>
/// <returns>A string representation of the packed vector.</returns>
public override readonly string ToString() => $"Abgr({this.A}, {this.B}, {this.G}, {this.R})";
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public override readonly int GetHashCode() => this.Abgr.GetHashCode();
/// <summary>
/// Packs the four floats into a color.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
[MethodImpl(InliningOptions.ShortMethod)]
private void Pack(float x, float y, float z, float w)
{
var value = new Vector4(x, y, z, w);
this.Pack(ref value);
}
/// <summary>
/// Packs a <see cref="Vector3"/> into a uint.
/// </summary>
/// <param name="vector">The vector containing the values to pack.</param>
[MethodImpl(InliningOptions.ShortMethod)]
private void Pack(ref Vector3 vector)
{
var value = new Vector4(vector, 1);
this.Pack(ref value);
}
/// <summary>
/// Packs a <see cref="Vector4"/> into a color.
/// </summary>
/// <param name="vector">The vector containing the values to pack.</param>
[MethodImpl(InliningOptions.ShortMethod)]
private void Pack(ref Vector4 vector)
{
vector *= MaxBytes;
vector += Half;
vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes);
this.R = (byte)vector.X;
this.G = (byte)vector.Y;
this.B = (byte)vector.Z;
this.A = (byte)vector.W;
}
}
}

10
src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs

@ -230,6 +230,16 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
this.R = source.R;
this.G = source.G;
this.B = source.B;
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source)

10
src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs

@ -185,6 +185,16 @@ namespace SixLabors.ImageSharp.PixelFormats
this.B = source.B;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
// We can assign this instances value directly to last three bytes of the Abgr32.
ref byte sourceRef = ref Unsafe.As<Abgr32, byte>(ref source);
ref byte sourceRefFromB = ref Unsafe.AddByteOffset(ref sourceRef, new IntPtr(1));
this = Unsafe.As<byte, Bgr24>(ref sourceRefFromB);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source) => this = source.Bgr;

4
src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs

@ -99,6 +99,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromVector4(source.ToVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromVector4(source.ToVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source) => this.FromScaledVector4(source.ToScaledVector4());

10
src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs

@ -165,6 +165,16 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
this.R = source.R;
this.G = source.G;
this.B = source.B;
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)

4
src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs

@ -102,6 +102,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs

@ -124,6 +124,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs

@ -124,6 +124,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs

@ -88,6 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs

@ -99,6 +99,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs

@ -104,6 +104,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

7
src/ImageSharp/PixelFormats/PixelImplementations/L16.cs

@ -91,6 +91,13 @@ namespace SixLabors.ImageSharp.PixelFormats
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/L8.cs

@ -83,6 +83,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

8
src/ImageSharp/PixelFormats/PixelImplementations/La16.cs

@ -112,6 +112,14 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B);
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

12
src/ImageSharp/PixelFormats/PixelImplementations/La32.cs

@ -127,6 +127,18 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
this.L = ColorNumerics.Get16BitBT709Luminance(
ColorNumerics.UpscaleFrom8BitTo16Bit(source.R),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.G),
ColorNumerics.UpscaleFrom8BitTo16Bit(source.B));
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs

@ -107,6 +107,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs

@ -109,6 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs

@ -108,6 +108,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs

@ -110,6 +110,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

26
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs

@ -0,0 +1,26 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Abgr32
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Abgr32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Abgr32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
}
}

346
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs

@ -0,0 +1,346 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats.Utils;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Abgr32
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Abgr32>
{
/// <inheritdoc />
public override void FromAbgr32(Configuration configuration, ReadOnlySpan<Abgr32> source, Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
source.CopyTo(destinationPixels.Slice(0, source.Length));
}
/// <inheritdoc />
public override void ToAbgr32(Configuration configuration, ReadOnlySpan<Abgr32> sourcePixels, Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length));
}
/// <inheritdoc />
public override void FromVector4Destructive(
Configuration configuration,
Span<Vector4> sourceVectors,
Span<Abgr32> destinationPixels,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale));
}
/// <inheritdoc />
public override void ToVector4(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Vector4> destVectors,
PixelConversionModifiers modifiers)
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale));
}
/// <inheritdoc />
public override void ToRgba32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Rgba32, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToRgba32(source, dest);
}
/// <inheritdoc />
public override void FromRgba32(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Rgba32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromRgba32.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void ToArgb32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Argb32, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToArgb32(source, dest);
}
/// <inheritdoc />
public override void FromArgb32(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Argb32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromArgb32.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Bgra32, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToBgra32(source, dest);
}
/// <inheritdoc />
public override void FromBgra32(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Bgra32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromBgra32.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Rgb24, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToRgb24(source, dest);
}
/// <inheritdoc />
public override void FromRgb24(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Rgb24, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromRgb24.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Bgr24, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToBgr24(source, dest);
}
/// <inheritdoc />
public override void FromBgr24(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Bgr24, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromBgr24.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void ToL8(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<L8> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
dp.FromAbgr32(sp);
}
}
/// <inheritdoc />
public override void ToL16(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<L16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
dp.FromAbgr32(sp);
}
}
/// <inheritdoc />
public override void ToLa16(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<La16> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
dp.FromAbgr32(sp);
}
}
/// <inheritdoc />
public override void ToLa32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<La32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
dp.FromAbgr32(sp);
}
}
/// <inheritdoc />
public override void ToRgb48(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Rgb48> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
dp.FromAbgr32(sp);
}
}
/// <inheritdoc />
public override void ToRgba64(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Rgba64> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
dp.FromAbgr32(sp);
}
}
/// <inheritdoc />
public override void ToBgra5551(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Bgra5551> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);
dp.FromAbgr32(sp);
}
}
/// <inheritdoc />
public override void From<TSourcePixel>(
Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Abgr32> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToAbgr32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}
}
}
}

18
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.tt

@ -0,0 +1,18 @@
<#@include file="_Common.ttinclude" #>
<#@ output extension=".cs" #>
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Abgr32
{
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Abgr32>
{
<# GenerateAllDefaultConversionMethods("Abgr32"); #>
}
}
}

41
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs

@ -85,6 +85,33 @@ namespace SixLabors.ImageSharp.PixelFormats
PixelConverter.FromRgba32.ToArgb32(source, dest);
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Argb32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromArgb32.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void FromAbgr32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Argb32, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToArgb32(source, dest);
}
/// <inheritdoc />
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<Argb32> sourcePixels,
@ -177,7 +204,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -197,7 +224,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -217,7 +244,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -237,7 +264,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -257,7 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -277,7 +304,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -297,7 +324,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

41
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs

@ -112,6 +112,33 @@ namespace SixLabors.ImageSharp.PixelFormats
PixelConverter.FromArgb32.ToBgr24(source, dest);
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Bgr24, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromBgr24.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void FromAbgr32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Bgr24, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToBgr24(source, dest);
}
/// <inheritdoc />
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<Bgr24> sourcePixels,
@ -177,7 +204,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -197,7 +224,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -217,7 +244,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -237,7 +264,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -257,7 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -277,7 +304,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -297,7 +324,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

41
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs

@ -112,6 +112,33 @@ namespace SixLabors.ImageSharp.PixelFormats
PixelConverter.FromArgb32.ToBgra32(source, dest);
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Bgra32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromBgra32.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void FromAbgr32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Bgra32, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToBgra32(source, dest);
}
/// <inheritdoc />
public override void ToRgb24(
Configuration configuration,
ReadOnlySpan<Bgra32> sourcePixels,
@ -177,7 +204,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -197,7 +224,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -217,7 +244,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -237,7 +264,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -257,7 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -277,7 +304,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -297,7 +324,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

42
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref Argb32 dp = ref Unsafe.Add(ref destRef, i);
@ -59,6 +59,26 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref Abgr32 dp = ref Unsafe.Add(ref destRef, i);
dp.FromBgra5551(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<Bgra5551> sourcePixels,
@ -70,7 +90,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgr24 dp = ref Unsafe.Add(ref destRef, i);
@ -90,7 +110,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra32 dp = ref Unsafe.Add(ref destRef, i);
@ -110,7 +130,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -130,7 +150,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -150,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -170,7 +190,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -190,7 +210,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb24 dp = ref Unsafe.Add(ref destRef, i);
@ -210,7 +230,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i);
@ -230,7 +250,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -250,7 +270,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);

42
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Argb32 dp = ref Unsafe.Add(ref destRef, i);
@ -59,6 +59,26 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Abgr32 dp = ref Unsafe.Add(ref destRef, i);
dp.FromL16(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<L16> sourcePixels,
@ -70,7 +90,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgr24 dp = ref Unsafe.Add(ref destRef, i);
@ -90,7 +110,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra32 dp = ref Unsafe.Add(ref destRef, i);
@ -110,7 +130,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -130,7 +150,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -150,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -170,7 +190,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb24 dp = ref Unsafe.Add(ref destRef, i);
@ -190,7 +210,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i);
@ -210,7 +230,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -230,7 +250,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -250,7 +270,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

42
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Argb32 dp = ref Unsafe.Add(ref destRef, i);
@ -59,6 +59,26 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Abgr32 dp = ref Unsafe.Add(ref destRef, i);
dp.FromL8(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<L8> sourcePixels,
@ -70,7 +90,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgr24 dp = ref Unsafe.Add(ref destRef, i);
@ -90,7 +110,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra32 dp = ref Unsafe.Add(ref destRef, i);
@ -110,7 +130,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -130,7 +150,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -150,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -170,7 +190,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb24 dp = ref Unsafe.Add(ref destRef, i);
@ -190,7 +210,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i);
@ -210,7 +230,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -230,7 +250,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -250,7 +270,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref L8 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

42
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Argb32 dp = ref Unsafe.Add(ref destRef, i);
@ -59,6 +59,26 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Abgr32 dp = ref Unsafe.Add(ref destRef, i);
dp.FromLa16(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<La16> sourcePixels,
@ -70,7 +90,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgr24 dp = ref Unsafe.Add(ref destRef, i);
@ -90,7 +110,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra32 dp = ref Unsafe.Add(ref destRef, i);
@ -110,7 +130,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -130,7 +150,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -150,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -170,7 +190,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb24 dp = ref Unsafe.Add(ref destRef, i);
@ -190,7 +210,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i);
@ -210,7 +230,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -230,7 +250,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -250,7 +270,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La16 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

42
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Argb32 dp = ref Unsafe.Add(ref destRef, i);
@ -59,6 +59,26 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Abgr32 dp = ref Unsafe.Add(ref destRef, i);
dp.FromLa32(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<La32> sourcePixels,
@ -70,7 +90,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgr24 dp = ref Unsafe.Add(ref destRef, i);
@ -90,7 +110,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra32 dp = ref Unsafe.Add(ref destRef, i);
@ -110,7 +130,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -130,7 +150,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -150,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -170,7 +190,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb24 dp = ref Unsafe.Add(ref destRef, i);
@ -190,7 +210,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i);
@ -210,7 +230,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -230,7 +250,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -250,7 +270,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref La32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

41
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs

@ -112,6 +112,33 @@ namespace SixLabors.ImageSharp.PixelFormats
PixelConverter.FromArgb32.ToRgb24(source, dest);
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Rgb24, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromRgb24.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void FromAbgr32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Rgb24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Rgb24, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToRgb24(source, dest);
}
/// <inheritdoc />
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<Rgb24> sourcePixels,
@ -177,7 +204,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -197,7 +224,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -217,7 +244,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -237,7 +264,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -257,7 +284,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -277,7 +304,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -297,7 +324,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

42
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref Argb32 dp = ref Unsafe.Add(ref destRef, i);
@ -59,6 +59,26 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref Abgr32 dp = ref Unsafe.Add(ref destRef, i);
dp.FromRgb48(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<Rgb48> sourcePixels,
@ -70,7 +90,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgr24 dp = ref Unsafe.Add(ref destRef, i);
@ -90,7 +110,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra32 dp = ref Unsafe.Add(ref destRef, i);
@ -110,7 +130,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -130,7 +150,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -150,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -170,7 +190,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -190,7 +210,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb24 dp = ref Unsafe.Add(ref destRef, i);
@ -210,7 +230,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i);
@ -230,7 +250,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -250,7 +270,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

41
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs

@ -66,6 +66,33 @@ namespace SixLabors.ImageSharp.PixelFormats
PixelConverter.FromArgb32.ToRgba32(source, dest);
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Rgba32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Abgr32, byte>(destinationPixels);
PixelConverter.FromRgba32.ToAbgr32(source, dest);
}
/// <inheritdoc />
public override void FromAbgr32(
Configuration configuration,
ReadOnlySpan<Abgr32> sourcePixels,
Span<Rgba32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ReadOnlySpan<byte> source = MemoryMarshal.Cast<Abgr32, byte>(sourcePixels);
Span<byte> dest = MemoryMarshal.Cast<Rgba32, byte>(destinationPixels);
PixelConverter.FromAbgr32.ToRgba32(source, dest);
}
/// <inheritdoc />
public override void ToBgra32(
Configuration configuration,
ReadOnlySpan<Rgba32> sourcePixels,
@ -158,7 +185,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -178,7 +205,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -198,7 +225,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -218,7 +245,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -238,7 +265,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -258,7 +285,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba64 dp = ref Unsafe.Add(ref destRef, i);
@ -278,7 +305,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

42
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref Argb32 dp = ref Unsafe.Add(ref destRef, i);
@ -59,6 +59,26 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
public override void ToAbgr32(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
Span<Abgr32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref Abgr32 dp = ref Unsafe.Add(ref destRef, i);
dp.FromRgba64(sp);
}
}
/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
ReadOnlySpan<Rgba64> sourcePixels,
@ -70,7 +90,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgr24 dp = ref Unsafe.Add(ref destRef, i);
@ -90,7 +110,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra32 dp = ref Unsafe.Add(ref destRef, i);
@ -110,7 +130,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref L8 dp = ref Unsafe.Add(ref destRef, i);
@ -130,7 +150,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref L16 dp = ref Unsafe.Add(ref destRef, i);
@ -150,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref La16 dp = ref Unsafe.Add(ref destRef, i);
@ -170,7 +190,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref La32 dp = ref Unsafe.Add(ref destRef, i);
@ -190,7 +210,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb24 dp = ref Unsafe.Add(ref destRef, i);
@ -210,7 +230,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i);
@ -230,7 +250,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgb48 dp = ref Unsafe.Add(ref destRef, i);
@ -250,7 +270,7 @@ namespace SixLabors.ImageSharp.PixelFormats
ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i);
ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i);

5
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude

@ -17,6 +17,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils;
private static readonly string[] CommonPixelTypes =
{
"Argb32",
"Abgr32",
"Bgr24",
"Bgra32",
"L8",
@ -34,6 +35,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils;
{
"Rgba32",
"Argb32",
"Abgr32",
"Bgra32",
"Rgb24",
"Bgr24"
@ -43,6 +45,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils;
private static readonly string[] Rgba32CompatibleTypes =
{
"Argb32",
"Abgr32",
"Bgra32",
"Rgb24",
"Bgr24"
@ -101,7 +104,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils;
ref <#=fromPixelType#> sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref <#=toPixelType#> destRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
for (nint i = 0; i < sourcePixels.Length; i++)
{
ref <#=fromPixelType#> sp = ref Unsafe.Add(ref sourceRef, i);
ref <#=toPixelType#> dp = ref Unsafe.Add(ref destRef, i);

4
src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs

@ -93,6 +93,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

9
src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs

@ -153,6 +153,15 @@ namespace SixLabors.ImageSharp.PixelFormats
this.B = source.B;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
this.R = source.R;
this.G = source.G;
this.B = source.B;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source)

9
src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs

@ -186,6 +186,15 @@ namespace SixLabors.ImageSharp.PixelFormats
this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
}
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
}
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest)

4
src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs

@ -96,6 +96,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

10
src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs

@ -333,6 +333,16 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = source.A;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
this.R = source.R;
this.G = source.G;
this.B = source.B;
this.A = source.A;
}
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

37
src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs

@ -94,6 +94,19 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba64"/> struct.
/// </summary>
/// <param name="source">A structure of 4 bytes in ABGR byte order.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Rgba64(Abgr32 source)
{
this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba64"/> struct.
/// </summary>
@ -250,6 +263,16 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source)
{
this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R);
this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G);
this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B);
this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A);
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
@ -380,6 +403,20 @@ namespace SixLabors.ImageSharp.PixelFormats
return new Argb32(r, g, b, a);
}
/// <summary>
/// Convert to <see cref="Abgr32"/>.
/// </summary>
/// <returns>The <see cref="Abgr32"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Abgr32 ToAbgr32()
{
byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R);
byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G);
byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B);
byte a = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A);
return new Abgr32(r, g, b, a);
}
/// <summary>
/// Convert to <see cref="Rgb24"/>.
/// </summary>

4
src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs

@ -134,6 +134,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs

@ -111,6 +111,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

4
src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs

@ -116,6 +116,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());

72
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs

@ -82,6 +82,78 @@ namespace SixLabors.ImageSharp.PixelFormats
this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Argb32>(destBytes));
}
/// <summary>
/// Converts all pixels in 'source` span of <see cref="Abgr32"/> into a span of <typeparamref name="TPixel"/>-s.
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="source">The source <see cref="Span{T}"/> of <see cref="Abgr32"/> data.</param>
/// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
public virtual void FromAbgr32(Configuration configuration, ReadOnlySpan<Abgr32> source, Span<TPixel> destinationPixels)
{
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));
ref Abgr32 sourceBaseRef = ref MemoryMarshal.GetReference(source);
ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < source.Length; i++)
{
ref Abgr32 sp = ref Unsafe.Add(ref sourceBaseRef, i);
ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
dp.FromAbgr32(sp);
}
}
/// <summary>
/// A helper for <see cref="FromAbgr32(Configuration, ReadOnlySpan{Abgr32}, Span{TPixel})"/> that expects a byte span.
/// The layout of the data in 'sourceBytes' must be compatible with <see cref="Abgr32"/> layout.
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations.</param>
/// <param name="sourceBytes">The <see cref="ReadOnlySpan{T}"/> to the source bytes.</param>
/// <param name="destinationPixels">The <see cref="Span{T}"/> to the destination pixels.</param>
/// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void FromAbgr32Bytes(Configuration configuration, ReadOnlySpan<byte> sourceBytes, Span<TPixel> destinationPixels, int count)
{
this.FromAbgr32(configuration, MemoryMarshal.Cast<byte, Abgr32>(sourceBytes).Slice(0, count), destinationPixels);
}
/// <summary>
/// Converts all pixels of the 'sourcePixels` span to a span of <see cref="Abgr32"/>-s.
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The span of source pixels</param>
/// <param name="destinationPixels">The destination span of <see cref="Abgr32"/> data.</param>
public virtual void ToAbgr32(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<Abgr32> destinationPixels)
{
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));
ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Abgr32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels);
for (int i = 0; i < sourcePixels.Length; i++)
{
ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
ref Abgr32 dp = ref Unsafe.Add(ref destBaseRef, i);
dp.FromScaledVector4(sp.ToScaledVector4());
}
}
/// <summary>
/// A helper for <see cref="ToAbgr32(Configuration, ReadOnlySpan{TPixel}, Span{Abgr32})"/> that expects a byte span as destination.
/// The layout of the data in 'destBytes' must be compatible with <see cref="Abgr32"/> layout.
/// </summary>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source pixels.</param>
/// <param name="destBytes">The <see cref="Span{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToAbgr32Bytes(Configuration configuration, ReadOnlySpan<TPixel> sourcePixels, Span<byte> destBytes, int count)
{
this.ToAbgr32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast<byte, Abgr32>(destBytes));
}
/// <summary>
/// Converts all pixels in 'source` span of <see cref="Bgr24"/> into a span of <typeparamref name="TPixel"/>-s.
/// </summary>

3
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt

@ -112,6 +112,9 @@ namespace SixLabors.ImageSharp.PixelFormats
GenerateFromMethods("Argb32");
GenerateToDestFormatMethods("Argb32");
GenerateFromMethods("Abgr32");
GenerateToDestFormatMethods("Abgr32");
GenerateFromMethods("Bgr24");
GenerateToDestFormatMethods("Bgr24");

125
src/ImageSharp/PixelFormats/Utils/PixelConverter.cs

@ -18,8 +18,13 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
/// </remarks>
internal static class PixelConverter
{
/// <summary>
/// Optimized converters from <see cref="Rgba32"/>.
/// </summary>
public static class FromRgba32
{
// Input pixels have: X = R, Y = G, Z = B and W = A.
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Rgba32"/> pixels to a <see cref="Span{Byte}"/> representing
@ -38,6 +43,15 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
public static void ToBgra32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<ZYXWShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Argb32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Abgr32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToAbgr32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<WZYXShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Rgba32"/> pixels to a <see cref="Span{Byte}"/> representing
@ -57,8 +71,13 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
=> SimdUtils.Shuffle4Slice3(source, dest, new DefaultShuffle4Slice3(3, 0, 1, 2));
}
/// <summary>
/// Optimized converters from <see cref="Argb32"/>.
/// </summary>
public static class FromArgb32
{
// Input pixels have: X = A, Y = R, Z = G and W = B.
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Argb32"/> pixels to a <see cref="Span{Byte}"/> representing
@ -77,6 +96,15 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
public static void ToBgra32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<WZYXShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Argb32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Abgr32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToAbgr32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<XWZYShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Argb32"/> pixels to a <see cref="Span{Byte}"/> representing
@ -96,8 +124,13 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
=> SimdUtils.Shuffle4Slice3(source, dest, new DefaultShuffle4Slice3(0, 1, 2, 3));
}
/// <summary>
/// Optimized converters from <see cref="Bgra32"/>.
/// </summary>
public static class FromBgra32
{
// Input pixels have: X = B, Y = G, Z = R and W = A.
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Bgra32"/> pixels to a <see cref="Span{Byte}"/> representing
@ -110,12 +143,21 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Bgra32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Bgra32"/> pixels.
/// a collection of <see cref="Rgba32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToRgba32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<ZYXWShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Bgra32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Abgr32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToAbgr32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<WXYZShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Argb32"/> pixels to a <see cref="Span{Byte}"/> representing
@ -135,8 +177,66 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
=> SimdUtils.Shuffle4Slice3<XYZWShuffle4Slice3>(source, dest, default);
}
/// <summary>
/// Optimized converters from <see cref="Abgr32"/>.
/// </summary>
public static class FromAbgr32
{
// Input pixels have: X = A, Y = B, Z = G and W = R.
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Abgr32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Argb32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToArgb32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<XWZYShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Abgr32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Bgra32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToRgba32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<WZYXShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Abgr32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Bgra32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToBgra32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4<YZWXShuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Abgr32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Rgb24"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToRgb24(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4Slice3(source, dest, new DefaultShuffle4Slice3(0, 1, 2, 3));
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Abgr32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Bgr24"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToBgr24(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Shuffle4Slice3(source, dest, new DefaultShuffle4Slice3(0, 3, 2, 1));
}
/// <summary>
/// Optimized converters from <see cref="Rgb24"/>.
/// </summary>
public static class FromRgb24
{
// Input pixels have: X = R, Y = G and Z = B.
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Rgb24"/> pixels to a <see cref="Span{Byte}"/> representing
@ -164,6 +264,15 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
public static void ToBgra32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Pad3Shuffle4(source, dest, new DefaultPad3Shuffle4(3, 0, 1, 2));
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Rgba32"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Bgra32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToAbgr32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Pad3Shuffle4(source, dest, new DefaultPad3Shuffle4(0, 1, 2, 3));
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Rgb24"/> pixels to a <see cref="Span{Byte}"/> representing
@ -174,8 +283,13 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
=> SimdUtils.Shuffle3(source, dest, new DefaultShuffle3(0, 1, 2));
}
/// <summary>
/// Optimized converters from <see cref="Bgr24"/>.
/// </summary>
public static class FromBgr24
{
// Input pixels have: X = B, Y = G and Z = R.
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Bgr24"/> pixels to a <see cref="Span{Byte}"/> representing
@ -203,6 +317,15 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils
public static void ToBgra32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Pad3Shuffle4<XYZWPad3Shuffle4>(source, dest, default);
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Bgr24"/> pixels to a <see cref="Span{Byte}"/> representing
/// a collection of <see cref="Abgr32"/> pixels.
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public static void ToAbgr32(ReadOnlySpan<byte> source, Span<byte> dest)
=> SimdUtils.Pad3Shuffle4(source, dest, new DefaultPad3Shuffle4(2, 1, 0, 3));
/// <summary>
/// Converts a <see cref="ReadOnlySpan{Byte}"/> representing a collection of
/// <see cref="Bgr24"/> pixels to a <see cref="Span{Byte}"/> representing

13
tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs

@ -63,6 +63,19 @@ namespace SixLabors.ImageSharp.Tests
Assert.Equal(source, data);
}
[Fact]
public void Abgr32()
{
var source = new Abgr32(1, 22, 33, 231);
// Act:
Color color = source;
// Assert:
Abgr32 data = color.ToPixel<Abgr32>();
Assert.Equal(source, data);
}
[Fact]
public void Rgb24()
{

13
tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs

@ -64,6 +64,19 @@ namespace SixLabors.ImageSharp.Tests
Assert.Equal(source, data);
}
[Fact]
public void Abgr32()
{
var source = new Abgr32(1, 22, 33, 231);
// Act:
var color = new Color(source);
// Assert:
Abgr32 data = color;
Assert.Equal(source, data);
}
[Fact]
public void Rgb24()
{

13
tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs

@ -63,6 +63,19 @@ namespace SixLabors.ImageSharp.Tests
Assert.Equal(source, data);
}
[Fact]
public void Abgr32()
{
var source = new Abgr32(1, 22, 33, 231);
// Act:
var color = new Color(source);
// Assert:
Abgr32 data = color.ToPixel<Abgr32>();
Assert.Equal(source, data);
}
[Fact]
public void Rgb24()
{

27
tests/ImageSharp.Tests/Image/ImageCloneTests.cs

@ -56,6 +56,33 @@ namespace SixLabors.ImageSharp.Tests
});
}
[Theory]
[WithTestPatternImages(9, 9, PixelTypes.Rgba32)]
public void CloneAs_ToAbgr32(TestImageProvider<Rgba32> provider)
{
using Image<Rgba32> image = provider.GetImage();
using Image<Abgr32> clone = image.CloneAs<Abgr32>();
image.ProcessPixelRows(clone, static (imageAccessor, cloneAccessor) =>
{
for (int y = 0; y < imageAccessor.Height; y++)
{
Span<Rgba32> row = imageAccessor.GetRowSpan(y);
Span<Abgr32> rowClone = cloneAccessor.GetRowSpan(y);
for (int x = 0; x < cloneAccessor.Width; x++)
{
Rgba32 expected = row[x];
Abgr32 actual = rowClone[x];
Assert.Equal(expected.R, actual.R);
Assert.Equal(expected.G, actual.G);
Assert.Equal(expected.B, actual.B);
}
}
});
}
[Theory]
[WithTestPatternImages(9, 9, PixelTypes.Rgba32)]
public void CloneAs_ToBgr24(TestImageProvider<Rgba32> provider)

148
tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs

@ -0,0 +1,148 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
namespace SixLabors.ImageSharp.Tests.PixelFormats
{
[Trait("Category", "PixelFormats")]
public class Abgr32Tests
{
/// <summary>
/// Tests the equality operators for equality.
/// </summary>
[Fact]
public void AreEqual()
{
var color1 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
var color2 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Assert.Equal(color1, color2);
}
/// <summary>
/// Tests the equality operators for inequality.
/// </summary>
[Fact]
public void AreNotEqual()
{
var color1 = new Abgr32(0, 0, byte.MaxValue, byte.MaxValue);
var color2 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue);
Assert.NotEqual(color1, color2);
}
public static readonly TheoryData<byte, byte, byte, byte> ColorData =
new()
{
{ 1, 2, 3, 4 },
{ 4, 5, 6, 7 },
{ 0, 255, 42, 0 },
{ 1, 2, 3, 255 }
};
[Theory]
[MemberData(nameof(ColorData))]
public void Constructor(byte b, byte g, byte r, byte a)
{
var p = new Abgr32(r, g, b, a);
Assert.Equal(r, p.R);
Assert.Equal(g, p.G);
Assert.Equal(b, p.B);
Assert.Equal(a, p.A);
}
[Fact]
public unsafe void ByteLayoutIsSequentialBgra()
{
var color = new Abgr32(1, 2, 3, 4);
byte* ptr = (byte*)&color;
Assert.Equal(4, ptr[0]);
Assert.Equal(3, ptr[1]);
Assert.Equal(2, ptr[2]);
Assert.Equal(1, ptr[3]);
}
[Theory]
[MemberData(nameof(ColorData))]
public void Equality_WhenTrue(byte r, byte g, byte b, byte a)
{
var x = new Abgr32(r, g, b, a);
var y = new Abgr32(r, g, b, a);
Assert.True(x.Equals(y));
Assert.True(x.Equals((object)y));
Assert.Equal(x.GetHashCode(), y.GetHashCode());
}
[Theory]
[InlineData(1, 2, 3, 4, 1, 2, 3, 5)]
[InlineData(0, 0, 255, 0, 0, 0, 244, 0)]
[InlineData(0, 255, 0, 0, 0, 244, 0, 0)]
[InlineData(1, 255, 0, 0, 0, 255, 0, 0)]
public void Equality_WhenFalse(byte b1, byte g1, byte r1, byte a1, byte b2, byte g2, byte r2, byte a2)
{
var x = new Abgr32(r1, g1, b1, a1);
var y = new Abgr32(r2, g2, b2, a2);
Assert.False(x.Equals(y));
Assert.False(x.Equals((object)y));
}
[Fact]
public void FromRgba32()
{
var abgr = default(Abgr32);
abgr.FromRgba32(new Rgba32(1, 2, 3, 4));
Assert.Equal(1, abgr.R);
Assert.Equal(2, abgr.G);
Assert.Equal(3, abgr.B);
Assert.Equal(4, abgr.A);
}
private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new Vector4(
r / 255f,
g / 255f,
b / 255f,
a / 255f);
[Fact]
public void FromVector4()
{
var c = default(Abgr32);
c.FromVector4(Vec(1, 2, 3, 4));
Assert.Equal(1, c.R);
Assert.Equal(2, c.G);
Assert.Equal(3, c.B);
Assert.Equal(4, c.A);
}
[Fact]
public void ToVector4()
{
var abgr = new Abgr32(1, 2, 3, 4);
Assert.Equal(Vec(1, 2, 3, 4), abgr.ToVector4());
}
[Fact]
public void Abgr32_FromBgra5551()
{
// arrange
var abgr = default(Abgr32);
uint expected = uint.MaxValue;
// act
abgr.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
// assert
Assert.Equal(expected, abgr.PackedValue);
}
}
}

11
tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs

@ -96,12 +96,13 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
[Fact]
public void FromRgba32()
{
var rgb = default(Rgb24);
rgb.FromRgba32(new Rgba32(1, 2, 3, 4));
var bgra = default(Bgra32);
bgra.FromRgba32(new Rgba32(1, 2, 3, 4));
Assert.Equal(1, rgb.R);
Assert.Equal(2, rgb.G);
Assert.Equal(3, rgb.B);
Assert.Equal(1, bgra.R);
Assert.Equal(2, bgra.G);
Assert.Equal(3, bgra.B);
Assert.Equal(4, bgra.A);
}
private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new Vector4(

15
tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs

@ -60,6 +60,21 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
return buffer;
}
public static byte[] MakeAbgr32ByteArray(byte r, byte g, byte b, byte a)
{
var buffer = new byte[256];
for (int i = 0; i < buffer.Length; i += 4)
{
buffer[i] = a;
buffer[i + 1] = b;
buffer[i + 2] = g;
buffer[i + 3] = r;
}
return buffer;
}
internal static void To<TSourcePixel, TDestinationPixel>(
Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels,

59
tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs

@ -56,6 +56,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
[Theory]
[MemberData(nameof(RgbaData))]
public void ToAbgr32(byte r, byte g, byte b, byte a)
{
byte[] source = ReferenceImplementations.MakeRgba32ByteArray(r, g, b, a);
byte[] actual = new byte[source.Length];
PixelConverter.FromRgba32.ToAbgr32(source, actual);
byte[] expected = ReferenceImplementations.MakeAbgr32ByteArray(r, g, b, a);
Assert.Equal(expected, actual);
}
}
public class FromArgb32 : PixelConverterTests
@ -119,5 +133,50 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
}
public class FromAbgr32 : PixelConverterTests
{
[Theory]
[MemberData(nameof(RgbaData))]
public void ToArgb32(byte r, byte g, byte b, byte a)
{
byte[] source = ReferenceImplementations.MakeAbgr32ByteArray(r, g, b, a);
byte[] actual = new byte[source.Length];
PixelConverter.FromAbgr32.ToArgb32(source, actual);
byte[] expected = ReferenceImplementations.MakeArgb32ByteArray(r, g, b, a);
Assert.Equal(expected, actual);
}
[Theory]
[MemberData(nameof(RgbaData))]
public void ToRgba32(byte r, byte g, byte b, byte a)
{
byte[] source = ReferenceImplementations.MakeAbgr32ByteArray(r, g, b, a);
byte[] actual = new byte[source.Length];
PixelConverter.FromAbgr32.ToRgba32(source, actual);
byte[] expected = ReferenceImplementations.MakeRgba32ByteArray(r, g, b, a);
Assert.Equal(expected, actual);
}
[Theory]
[MemberData(nameof(RgbaData))]
public void ToBgra32(byte r, byte g, byte b, byte a)
{
byte[] source = ReferenceImplementations.MakeAbgr32ByteArray(r, g, b, a);
byte[] actual = new byte[source.Length];
PixelConverter.FromAbgr32.ToBgra32(source, actual);
byte[] expected = ReferenceImplementations.MakeBgra32ByteArray(r, g, b, a);
Assert.Equal(expected, actual);
}
}
}
}

47
tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs

@ -12,8 +12,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
{
public partial class PixelOperationsTests
{
public partial class A8_OperationsTests : PixelOperationsTests<A8>
public partial class A8_OperationsTests : PixelOperationsTests<A8>
{
public A8_OperationsTests(ITestOutputHelper output)
: base(output)
@ -32,7 +31,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Argb32_OperationsTests : PixelOperationsTests<Argb32>
{
public Argb32_OperationsTests(ITestOutputHelper output)
@ -52,7 +50,25 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Abgr32_OperationsTests : PixelOperationsTests<Abgr32>
{
public Abgr32_OperationsTests(ITestOutputHelper output)
: base(output)
{
}
protected override PixelOperations<Abgr32> Operations => Abgr32.PixelOperations.Instance;
[Fact]
public void IsSpecialImplementation() => Assert.IsType<Abgr32.PixelOperations>(PixelOperations<Abgr32>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Bgr24_OperationsTests : PixelOperationsTests<Bgr24>
{
public Bgr24_OperationsTests(ITestOutputHelper output)
@ -72,7 +88,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Bgr565_OperationsTests : PixelOperationsTests<Bgr565>
{
public Bgr565_OperationsTests(ITestOutputHelper output)
@ -92,7 +107,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Bgra32_OperationsTests : PixelOperationsTests<Bgra32>
{
public Bgra32_OperationsTests(ITestOutputHelper output)
@ -112,7 +126,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Bgra4444_OperationsTests : PixelOperationsTests<Bgra4444>
{
public Bgra4444_OperationsTests(ITestOutputHelper output)
@ -132,7 +145,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Bgra5551_OperationsTests : PixelOperationsTests<Bgra5551>
{
public Bgra5551_OperationsTests(ITestOutputHelper output)
@ -152,7 +164,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Byte4_OperationsTests : PixelOperationsTests<Byte4>
{
public Byte4_OperationsTests(ITestOutputHelper output)
@ -172,7 +183,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class HalfSingle_OperationsTests : PixelOperationsTests<HalfSingle>
{
public HalfSingle_OperationsTests(ITestOutputHelper output)
@ -192,7 +202,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class HalfVector2_OperationsTests : PixelOperationsTests<HalfVector2>
{
public HalfVector2_OperationsTests(ITestOutputHelper output)
@ -212,7 +221,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class HalfVector4_OperationsTests : PixelOperationsTests<HalfVector4>
{
public HalfVector4_OperationsTests(ITestOutputHelper output)
@ -232,7 +240,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class L16_OperationsTests : PixelOperationsTests<L16>
{
public L16_OperationsTests(ITestOutputHelper output)
@ -252,7 +259,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class L8_OperationsTests : PixelOperationsTests<L8>
{
public L8_OperationsTests(ITestOutputHelper output)
@ -272,7 +278,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class La16_OperationsTests : PixelOperationsTests<La16>
{
public La16_OperationsTests(ITestOutputHelper output)
@ -292,7 +297,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class La32_OperationsTests : PixelOperationsTests<La32>
{
public La32_OperationsTests(ITestOutputHelper output)
@ -312,7 +316,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class NormalizedByte2_OperationsTests : PixelOperationsTests<NormalizedByte2>
{
public NormalizedByte2_OperationsTests(ITestOutputHelper output)
@ -332,7 +335,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class NormalizedByte4_OperationsTests : PixelOperationsTests<NormalizedByte4>
{
public NormalizedByte4_OperationsTests(ITestOutputHelper output)
@ -352,7 +354,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class NormalizedShort2_OperationsTests : PixelOperationsTests<NormalizedShort2>
{
public NormalizedShort2_OperationsTests(ITestOutputHelper output)
@ -372,7 +373,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class NormalizedShort4_OperationsTests : PixelOperationsTests<NormalizedShort4>
{
public NormalizedShort4_OperationsTests(ITestOutputHelper output)
@ -392,7 +392,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Rg32_OperationsTests : PixelOperationsTests<Rg32>
{
public Rg32_OperationsTests(ITestOutputHelper output)
@ -412,7 +411,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Rgb24_OperationsTests : PixelOperationsTests<Rgb24>
{
public Rgb24_OperationsTests(ITestOutputHelper output)
@ -432,7 +430,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Rgb48_OperationsTests : PixelOperationsTests<Rgb48>
{
public Rgb48_OperationsTests(ITestOutputHelper output)
@ -452,7 +449,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Rgba1010102_OperationsTests : PixelOperationsTests<Rgba1010102>
{
public Rgba1010102_OperationsTests(ITestOutputHelper output)
@ -472,7 +468,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Rgba32_OperationsTests : PixelOperationsTests<Rgba32>
{
public Rgba32_OperationsTests(ITestOutputHelper output)
@ -492,7 +487,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Rgba64_OperationsTests : PixelOperationsTests<Rgba64>
{
public Rgba64_OperationsTests(ITestOutputHelper output)
@ -512,7 +506,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class RgbaVector_OperationsTests : PixelOperationsTests<RgbaVector>
{
public RgbaVector_OperationsTests(ITestOutputHelper output)
@ -532,7 +525,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation);
}
}
public partial class Short2_OperationsTests : PixelOperationsTests<Short2>
{
public Short2_OperationsTests(ITestOutputHelper output)
@ -552,7 +544,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation);
}
}
public partial class Short4_OperationsTests : PixelOperationsTests<Short4>
{
public Short4_OperationsTests(ITestOutputHelper output)

2
tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude

@ -16,6 +16,7 @@ using Xunit.Abstractions;
{
"A8",
"Argb32",
"Abgr32",
"Bgra32",
"Bgra4444",
"Bgra5551",
@ -38,6 +39,7 @@ using Xunit.Abstractions;
{
"A8",
"Argb32",
"Abgr32",
"Bgr24",
"Bgr565",
"Bgra32",

45
tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs

@ -322,6 +322,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
public static readonly TheoryData<object> Generic_To_Data = new TheoryData<object>
{
new TestPixel<Abgr32>(),
new TestPixel<Rgba32>(),
new TestPixel<Bgra32>(),
new TestPixel<Rgb24>(),
@ -586,6 +587,50 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
(s, d) => this.Operations.ToBgra32Bytes(this.Configuration, s, d.GetSpan(), count));
}
[Theory]
[MemberData(nameof(ArraySizesData))]
public void FromAbgr32Bytes(int count)
{
byte[] source = CreateByteTestData(count * 4);
var expected = new TPixel[count];
for (int i = 0; i < count; i++)
{
int i4 = i * 4;
expected[i].FromAbgr32(new Abgr32(source[i4 + 3], source[i4 + 2], source[i4 + 1], source[i4 + 0]));
}
TestOperation(
source,
expected,
(s, d) => this.Operations.FromAbgr32Bytes(this.Configuration, s, d.GetSpan(), count));
}
[Theory]
[MemberData(nameof(ArraySizesData))]
public void ToAbgr32Bytes(int count)
{
TPixel[] source = CreatePixelTestData(count);
byte[] expected = new byte[count * 4];
var abgr = default(Abgr32);
for (int i = 0; i < count; i++)
{
int i4 = i * 4;
abgr.FromScaledVector4(source[i].ToScaledVector4());
expected[i4] = abgr.A;
expected[i4 + 1] = abgr.B;
expected[i4 + 2] = abgr.G;
expected[i4 + 3] = abgr.R;
}
TestOperation(
source,
expected,
(s, d) => this.Operations.ToAbgr32Bytes(this.Configuration, s, d.GetSpan(), count));
}
[Theory]
[MemberData(nameof(ArraySizesData))]
public void FromBgra5551Bytes(int count)

16
tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs

@ -230,6 +230,22 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
[Fact]
public void Rgba32_FromAbgr32_ToRgba32()
{
// arrange
var rgba = default(Rgba32);
var actual = default(Abgr32);
var expected = new Abgr32(0x1a, 0, 0x80, 0);
// act
rgba.FromAbgr32(expected);
actual.FromRgba32(rgba);
// assert
Assert.Equal(expected, actual);
}
[Fact]
public void Rgba32_FromArgb32_ToArgb32()
{

24
tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs

@ -183,6 +183,16 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
[Fact]
public void ConstructFrom_Abgr32()
{
var expected = new Rgba64(5140, 9766, 19532, 29555);
var source = new Abgr32(20, 38, 76, 115);
var actual = new Rgba64(source);
Assert.Equal(expected, actual);
}
[Fact]
public void ConstructFrom_Rgb24()
{
@ -257,6 +267,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
[Fact]
public void ToAbgr32_Retval()
{
// arrange
var source = new Rgba64(5140, 9766, 19532, 29555);
var expected = new Abgr32(20, 38, 76, 115);
// act
var actual = source.ToAbgr32();
// assert
Assert.Equal(expected, actual);
}
[Fact]
public void ToRgb24_Retval()
{

18
tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs

@ -150,6 +150,24 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
[Fact]
public void Short4_FromAbgrb32_ToRgba32()
{
// arrange
var short4 = default(Short4);
var actual = default(Abgr32);
var expected = new Abgr32(20, 38, 0, 255);
// act
short4.FromAbgr32(expected);
Rgba32 temp = default;
short4.ToRgba32(ref temp);
actual.FromRgba32(temp);
// assert
Assert.Equal(expected, actual);
}
[Fact]
public void Short4_FromRgb48_ToRgb48()
{

4
tests/ImageSharp.Tests/TestFormat.cs

@ -310,6 +310,10 @@ namespace SixLabors.ImageSharp.Tests
{
}
public void FromAbgr32(Abgr32 source)
{
}
public void FromL8(L8 source)
{
}

2
tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

@ -69,6 +69,8 @@ namespace SixLabors.ImageSharp.Tests
La32 = 1 << 26,
Abgr32 = 1 << 27,
// TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper
// "All" is handled as a separate, individual case instead of using bitwise OR

5
tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

@ -112,14 +112,15 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void ExpandAllTypes_2()
{
PixelTypes pixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector;
PixelTypes pixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Abgr32 | PixelTypes.RgbaVector;
IEnumerable<KeyValuePair<PixelTypes, Type>> expanded = pixelTypes.ExpandAllTypes();
Assert.Equal(3, expanded.Count());
Assert.Equal(4, expanded.Count());
AssertContainsPixelType<Rgba32>(PixelTypes.Rgba32, expanded);
AssertContainsPixelType<Bgra32>(PixelTypes.Bgra32, expanded);
AssertContainsPixelType<Abgr32>(PixelTypes.Abgr32, expanded);
AssertContainsPixelType<RgbaVector>(PixelTypes.RgbaVector, expanded);
}

Loading…
Cancel
Save