Browse Source

Add optimized conversion overloads

pull/540/head
James Jackson-South 8 years ago
parent
commit
b7f07ee845
  1. 7
      src/ImageSharp/PixelFormats/Argb32.cs
  2. 32
      src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs
  3. 3
      src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt
  4. 17
      src/ImageSharp/PixelFormats/Rgba32.cs

7
src/ImageSharp/PixelFormats/Argb32.cs

@ -285,6 +285,13 @@ namespace SixLabors.ImageSharp.PixelFormats
dest.A = this.A;
}
/// <summary>
/// Converts the pixel to <see cref="Rgba32"/> format.
/// </summary>
/// <returns>The RGBA value</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Rgba32 ToRgba32() => new Rgba32(this.R, this.G, this.B, this.A);
/// <inheritdoc/>
public override bool Equals(object obj)
{

32
src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs

@ -112,6 +112,38 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
internal override void PackFromArgb32(ReadOnlySpan<Argb32> source, Span<Rgba32> destPixels, int count)
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
ref Argb32 sourceRef = ref MemoryMarshal.GetReference(source);
ref Rgba32 destRef = ref MemoryMarshal.GetReference(destPixels);
for (int i = 0; i < count; i++)
{
ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Rgba32 dp = ref Unsafe.Add(ref destRef, i);
dp = sp.ToRgba32();
}
}
/// <inheritdoc />
internal override void ToArgb32(ReadOnlySpan<Rgba32> sourcePixels, Span<Argb32> dest, int count)
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels);
ref Argb32 destRef = ref MemoryMarshal.GetReference(dest);
for (int i = 0; i < count; i++)
{
ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i);
ref Argb32 dp = ref Unsafe.Add(ref destRef, i);
dp = sp.ToArgb32();
}
}
}
}
}

3
src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt

@ -79,6 +79,9 @@ namespace SixLabors.ImageSharp.PixelFormats
GeneratePackFromMethod("Bgra32", "dp = sp.ToRgba32();");
GenerateConvertToMethod("Bgra32", "dp = sp.ToBgra32();");
GeneratePackFromMethod("Argb32", "dp = sp.ToRgba32();");
GenerateConvertToMethod("Argb32", "dp = sp.ToArgb32();");
#>
}

17
src/ImageSharp/PixelFormats/Rgba32.cs

@ -277,7 +277,8 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromArgb32(Argb32 source) {
public void PackFromArgb32(Argb32 source)
{
Pack(source.R, source.G, source.B, source.A);
}
@ -307,7 +308,8 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToArgb32(ref Argb32 dest) {
public void ToArgb32(ref Argb32 dest)
{
dest.R = this.R;
dest.G = this.G;
dest.B = this.B;
@ -372,6 +374,17 @@ namespace SixLabors.ImageSharp.PixelFormats
return new Bgra32(this.R, this.G, this.B, this.A);
}
/// <summary>
/// Gets the value of this struct as <see cref="Argb32"/>.
/// Useful for changing the component order.
/// </summary>
/// <returns>A <see cref="Argb32"/> value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Argb32 ToArgb32()
{
return new Argb32(this.R, this.G, this.B, this.A);
}
/// <inheritdoc/>
public override bool Equals(object obj)
{

Loading…
Cancel
Save