Skip to content

Commit

Permalink
Another attempt using Slice for the destination in PixelOperations co…
Browse files Browse the repository at this point in the history
…nvert From and To
  • Loading branch information
brianpopow committed Nov 29, 2020
1 parent 82ae5aa commit 7c77e7e
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ public partial struct Argb32
/// </summary>
internal partial class PixelOperations : PixelOperations<Argb32>
{

/// <inheritdoc />
/// <inheritdoc />
public override void FromArgb32(Configuration configuration, ReadOnlySpan<Argb32> source, Span<Argb32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));

source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}

/// <inheritdoc />
Expand All @@ -37,9 +36,8 @@ public override void ToArgb32(Configuration configuration, ReadOnlySpan<Argb32>
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));

sourcePixels.CopyTo(destinationPixels);
sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length));
}

/// <inheritdoc />
public override void FromVector4Destructive(
Configuration configuration,
Expand All @@ -59,7 +57,6 @@ public override void ToVector4(
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale));
}

/// <inheritdoc />
public override void ToRgba32(
Configuration configuration,
Expand Down Expand Up @@ -87,7 +84,6 @@ public override void FromRgba32(
Span<byte> dest = MemoryMarshal.Cast<Argb32, byte>(destinationPixels);
PixelConverter.FromRgba32.ToArgb32(source, dest);
}

/// <inheritdoc />
public override void ToBgra32(
Configuration configuration,
Expand Down Expand Up @@ -115,7 +111,6 @@ public override void FromBgra32(
Span<byte> dest = MemoryMarshal.Cast<Argb32, byte>(destinationPixels);
PixelConverter.FromBgra32.ToArgb32(source, dest);
}

/// <inheritdoc />
public override void ToRgb24(
Configuration configuration,
Expand Down Expand Up @@ -143,7 +138,6 @@ public override void FromRgb24(
Span<byte> dest = MemoryMarshal.Cast<Argb32, byte>(destinationPixels);
PixelConverter.FromRgb24.ToArgb32(source, dest);
}

/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
Expand Down Expand Up @@ -171,7 +165,6 @@ public override void FromBgr24(
Span<byte> dest = MemoryMarshal.Cast<Argb32, byte>(destinationPixels);
PixelConverter.FromBgr24.ToArgb32(source, dest);
}

/// <inheritdoc />
public override void ToL8(
Configuration configuration,
Expand All @@ -192,7 +185,6 @@ public override void ToL8(
dp.FromArgb32(sp);
}
}

/// <inheritdoc />
public override void ToL16(
Configuration configuration,
Expand All @@ -213,7 +205,6 @@ public override void ToL16(
dp.FromArgb32(sp);
}
}

/// <inheritdoc />
public override void ToLa16(
Configuration configuration,
Expand All @@ -234,7 +225,6 @@ public override void ToLa16(
dp.FromArgb32(sp);
}
}

/// <inheritdoc />
public override void ToLa32(
Configuration configuration,
Expand All @@ -255,7 +245,6 @@ public override void ToLa32(
dp.FromArgb32(sp);
}
}

/// <inheritdoc />
public override void ToRgb48(
Configuration configuration,
Expand All @@ -276,7 +265,6 @@ public override void ToRgb48(
dp.FromArgb32(sp);
}
}

/// <inheritdoc />
public override void ToRgba64(
Configuration configuration,
Expand All @@ -297,7 +285,6 @@ public override void ToRgba64(
dp.FromArgb32(sp);
}
}

/// <inheritdoc />
public override void ToBgra5551(
Configuration configuration,
Expand All @@ -318,14 +305,13 @@ public override void ToBgra5551(
dp.FromArgb32(sp);
}
}

/// <inheritdoc />
public override void From<TSourcePixel>(
Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Argb32> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToArgb32(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToArgb32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ public partial struct Bgr24
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgr24>
{

/// <inheritdoc />
/// <inheritdoc />
public override void FromBgr24(Configuration configuration, ReadOnlySpan<Bgr24> source, Span<Bgr24> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));

source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}

/// <inheritdoc />
Expand All @@ -37,9 +36,8 @@ public override void ToBgr24(Configuration configuration, ReadOnlySpan<Bgr24> so
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));

sourcePixels.CopyTo(destinationPixels);
sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length));
}

/// <inheritdoc />
public override void FromVector4Destructive(
Configuration configuration,
Expand All @@ -59,7 +57,6 @@ public override void ToVector4(
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply));
}

/// <inheritdoc />
public override void ToRgba32(
Configuration configuration,
Expand Down Expand Up @@ -87,7 +84,6 @@ public override void FromRgba32(
Span<byte> dest = MemoryMarshal.Cast<Bgr24, byte>(destinationPixels);
PixelConverter.FromRgba32.ToBgr24(source, dest);
}

/// <inheritdoc />
public override void ToArgb32(
Configuration configuration,
Expand Down Expand Up @@ -115,7 +111,6 @@ public override void FromArgb32(
Span<byte> dest = MemoryMarshal.Cast<Bgr24, byte>(destinationPixels);
PixelConverter.FromArgb32.ToBgr24(source, dest);
}

/// <inheritdoc />
public override void ToBgra32(
Configuration configuration,
Expand Down Expand Up @@ -143,7 +138,6 @@ public override void FromBgra32(
Span<byte> dest = MemoryMarshal.Cast<Bgr24, byte>(destinationPixels);
PixelConverter.FromBgra32.ToBgr24(source, dest);
}

/// <inheritdoc />
public override void ToRgb24(
Configuration configuration,
Expand Down Expand Up @@ -171,7 +165,6 @@ public override void FromRgb24(
Span<byte> dest = MemoryMarshal.Cast<Bgr24, byte>(destinationPixels);
PixelConverter.FromRgb24.ToBgr24(source, dest);
}

/// <inheritdoc />
public override void ToL8(
Configuration configuration,
Expand All @@ -192,7 +185,6 @@ public override void ToL8(
dp.FromBgr24(sp);
}
}

/// <inheritdoc />
public override void ToL16(
Configuration configuration,
Expand All @@ -213,7 +205,6 @@ public override void ToL16(
dp.FromBgr24(sp);
}
}

/// <inheritdoc />
public override void ToLa16(
Configuration configuration,
Expand All @@ -234,7 +225,6 @@ public override void ToLa16(
dp.FromBgr24(sp);
}
}

/// <inheritdoc />
public override void ToLa32(
Configuration configuration,
Expand All @@ -255,7 +245,6 @@ public override void ToLa32(
dp.FromBgr24(sp);
}
}

/// <inheritdoc />
public override void ToRgb48(
Configuration configuration,
Expand All @@ -276,7 +265,6 @@ public override void ToRgb48(
dp.FromBgr24(sp);
}
}

/// <inheritdoc />
public override void ToRgba64(
Configuration configuration,
Expand All @@ -297,7 +285,6 @@ public override void ToRgba64(
dp.FromBgr24(sp);
}
}

/// <inheritdoc />
public override void ToBgra5551(
Configuration configuration,
Expand All @@ -318,14 +305,13 @@ public override void ToBgra5551(
dp.FromBgr24(sp);
}
}

/// <inheritdoc />
public override void From<TSourcePixel>(
Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Bgr24> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToBgr24(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToBgr24(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ public partial struct Bgra32
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgra32>
{

/// <inheritdoc />
/// <inheritdoc />
public override void FromBgra32(Configuration configuration, ReadOnlySpan<Bgra32> source, Span<Bgra32> destinationPixels)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels));

source.CopyTo(destinationPixels);
source.CopyTo(destinationPixels.Slice(0, source.Length));
}

/// <inheritdoc />
Expand All @@ -37,9 +36,8 @@ public override void ToBgra32(Configuration configuration, ReadOnlySpan<Bgra32>
Guard.NotNull(configuration, nameof(configuration));
Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels));

sourcePixels.CopyTo(destinationPixels);
sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length));
}

/// <inheritdoc />
public override void FromVector4Destructive(
Configuration configuration,
Expand All @@ -59,7 +57,6 @@ public override void ToVector4(
{
Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale));
}

/// <inheritdoc />
public override void ToRgba32(
Configuration configuration,
Expand Down Expand Up @@ -87,7 +84,6 @@ public override void FromRgba32(
Span<byte> dest = MemoryMarshal.Cast<Bgra32, byte>(destinationPixels);
PixelConverter.FromRgba32.ToBgra32(source, dest);
}

/// <inheritdoc />
public override void ToArgb32(
Configuration configuration,
Expand Down Expand Up @@ -115,7 +111,6 @@ public override void FromArgb32(
Span<byte> dest = MemoryMarshal.Cast<Bgra32, byte>(destinationPixels);
PixelConverter.FromArgb32.ToBgra32(source, dest);
}

/// <inheritdoc />
public override void ToRgb24(
Configuration configuration,
Expand Down Expand Up @@ -143,7 +138,6 @@ public override void FromRgb24(
Span<byte> dest = MemoryMarshal.Cast<Bgra32, byte>(destinationPixels);
PixelConverter.FromRgb24.ToBgra32(source, dest);
}

/// <inheritdoc />
public override void ToBgr24(
Configuration configuration,
Expand Down Expand Up @@ -171,7 +165,6 @@ public override void FromBgr24(
Span<byte> dest = MemoryMarshal.Cast<Bgra32, byte>(destinationPixels);
PixelConverter.FromBgr24.ToBgra32(source, dest);
}

/// <inheritdoc />
public override void ToL8(
Configuration configuration,
Expand All @@ -192,7 +185,6 @@ public override void ToL8(
dp.FromBgra32(sp);
}
}

/// <inheritdoc />
public override void ToL16(
Configuration configuration,
Expand All @@ -213,7 +205,6 @@ public override void ToL16(
dp.FromBgra32(sp);
}
}

/// <inheritdoc />
public override void ToLa16(
Configuration configuration,
Expand All @@ -234,7 +225,6 @@ public override void ToLa16(
dp.FromBgra32(sp);
}
}

/// <inheritdoc />
public override void ToLa32(
Configuration configuration,
Expand All @@ -255,7 +245,6 @@ public override void ToLa32(
dp.FromBgra32(sp);
}
}

/// <inheritdoc />
public override void ToRgb48(
Configuration configuration,
Expand All @@ -276,7 +265,6 @@ public override void ToRgb48(
dp.FromBgra32(sp);
}
}

/// <inheritdoc />
public override void ToRgba64(
Configuration configuration,
Expand All @@ -297,7 +285,6 @@ public override void ToRgba64(
dp.FromBgra32(sp);
}
}

/// <inheritdoc />
public override void ToBgra5551(
Configuration configuration,
Expand All @@ -318,14 +305,13 @@ public override void ToBgra5551(
dp.FromBgra32(sp);
}
}

/// <inheritdoc />
public override void From<TSourcePixel>(
Configuration configuration,
ReadOnlySpan<TSourcePixel> sourcePixels,
Span<Bgra32> destinationPixels)
{
PixelOperations<TSourcePixel>.Instance.ToBgra32(configuration, sourcePixels, destinationPixels);
PixelOperations<TSourcePixel>.Instance.ToBgra32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length));
}

}
Expand Down
Loading

0 comments on commit 7c77e7e

Please sign in to comment.