Browse Source

Use PixelOperations

af/merge-core
James Jackson-South 8 years ago
parent
commit
525153834a
  1. 18
      src/ImageSharp/ImageFrame{TPixel}.cs
  2. 13
      src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs

18
src/ImageSharp/ImageFrame{TPixel}.cs

@ -248,20 +248,20 @@ namespace SixLabors.ImageSharp
var target = new ImageFrame<TPixel2>(this.MemoryManager, this.Width, this.Height, this.MetaData.Clone());
Parallel.For(
// TODO: ImageFrame has no visibility of the current configuration. It should have.
ParallelFor.WithTemporaryBuffer(
0,
target.Height,
Configuration.Default.ParallelOptions,
y =>
this.Height,
Configuration.Default,
this.Width,
(int y, IBuffer<Vector4> tempRowBuffer) =>
{
Span<TPixel> sourceRow = this.GetPixelRowSpan(y);
Span<TPixel2> targetRow = target.GetPixelRowSpan(y);
Span<Vector4> tempRowSpan = tempRowBuffer.Span;
for (int x = 0; x < target.Width; x++)
{
ref var pixel = ref targetRow[x];
pixel.PackFromScaledVector4(sourceRow[x].ToScaledVector4());
}
PixelOperations<TPixel>.Instance.ToScaledVector4(sourceRow, tempRowSpan, sourceRow.Length);
PixelOperations<TPixel2>.Instance.PackFromScaledVector4(tempRowSpan, targetRow, targetRow.Length);
});
return target;

13
src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs

@ -115,6 +115,7 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
internal override void PackFromVector4(ReadOnlySpan<Vector4> sourceVectors, Span<Rgba32> destColors, int count)
{
GuardSpans(sourceVectors, nameof(sourceVectors), destColors, nameof(destColors), count);
@ -144,6 +145,18 @@ namespace SixLabors.ImageSharp.PixelFormats
}
}
/// <inheritdoc />
internal override void ToScaledVector4(ReadOnlySpan<Rgba32> sourceColors, Span<Vector4> destinationVectors, int count)
{
this.ToVector4(sourceColors, destinationVectors, count);
}
/// <inheritdoc />
internal override void PackFromScaledVector4(ReadOnlySpan<Vector4> sourceVectors, Span<Rgba32> destinationColors, int count)
{
this.PackFromVector4(sourceVectors, destinationColors, count);
}
/// <inheritdoc />
internal override void PackFromRgba32(ReadOnlySpan<Rgba32> source, Span<Rgba32> destPixels, int count)
{

Loading…
Cancel
Save