Browse Source

Don't go through SpanHelper to Copy

af/merge-core
Jason Nelson 8 years ago
parent
commit
849c5961fc
  1. 19
      src/ImageSharp/Image.LoadPixelData.cs
  2. 7
      src/ImageSharp/ImageFrame.LoadPixelData.cs
  3. 2
      src/ImageSharp/ImageFrame{TPixel}.cs
  4. 2
      src/ImageSharp/PixelAccessor{TPixel}.cs
  5. 4
      src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
  6. 2
      src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs
  7. 2
      src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs

19
src/ImageSharp/Image.LoadPixelData.cs

@ -2,12 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
@ -102,14 +97,11 @@ namespace SixLabors.ImageSharp
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> LoadPixelData<TPixel>(Configuration config, TPixel[] data, int width, int height)
where TPixel : struct, IPixel<TPixel>
{
int count = width * height;
Guard.MustBeGreaterThanOrEqualTo(data.Length, count, nameof(data));
{
// There's an implict cast to Span from Array
// Should we remove this overload and expose Span<TPixel> ?
var image = new Image<TPixel>(config, width, height);
SpanHelper.Copy(data, image.GetPixelSpan(), count);
return image;
return LoadPixelData(config, new Span<TPixel>(data), width, height);
}
/// <summary>
@ -128,7 +120,8 @@ namespace SixLabors.ImageSharp
Guard.MustBeGreaterThanOrEqualTo(data.Length, count, nameof(data));
var image = new Image<TPixel>(config, width, height);
SpanHelper.Copy(data, image.Frames.RootFrame.GetPixelSpan(), count);
data.Slice(0, count).CopyTo(image.Frames.RootFrame.GetPixelSpan());
return image;
}

7
src/ImageSharp/ImageFrame.LoadPixelData.cs

@ -2,11 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
@ -46,7 +42,8 @@ namespace SixLabors.ImageSharp
Guard.MustBeGreaterThanOrEqualTo(data.Length, count, nameof(data));
var image = new ImageFrame<TPixel>(memoryManager, width, height);
SpanHelper.Copy(data, image.GetPixelSpan(), count);
data.Slice(0, count).CopyTo(image.GetPixelSpan());
return image;
}

2
src/ImageSharp/ImageFrame{TPixel}.cs

@ -181,7 +181,7 @@ namespace SixLabors.ImageSharp
throw new ArgumentException("ImageFrame<TPixel>.CopyTo(): target must be of the same size!", nameof(target));
}
SpanHelper.Copy(this.GetPixelSpan(), target.Span);
this.GetPixelSpan().CopyTo(target.Span);
}
/// <summary>

2
src/ImageSharp/PixelAccessor{TPixel}.cs

@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp
/// <param name="target">The target pixel buffer accessor.</param>
internal void CopyTo(PixelAccessor<TPixel> target)
{
SpanHelper.Copy(this.PixelBuffer.Span, target.PixelBuffer.Span);
this.PixelBuffer.Span.CopyTo(target.PixelBuffer.Span);
}
/// <summary>

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

@ -149,7 +149,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(source, nameof(source), destPixels, nameof(destPixels), count);
SpanHelper.Copy(source, destPixels, count);
source.Slice(0, count).CopyTo(destPixels);
}
/// <inheritdoc />
@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourcePixels, nameof(sourcePixels), dest, nameof(dest), count);
SpanHelper.Copy(sourcePixels, dest, count);
sourcePixels.Slice(0, count).CopyTo(dest);
}
/// <summary>

2
src/ImageSharp/PixelFormats/RgbaVector.PixelOperations.cs

@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.PixelFormats
{
GuardSpans(sourceColors, nameof(sourceColors), destVectors, nameof(destVectors), count);
SpanHelper.Copy(sourceColors.NonPortableCast<RgbaVector, Vector4>(), destVectors, count);
sourceColors.NonPortableCast<RgbaVector, Vector4>().Slice(0, count).CopyTo(destVectors);
}
}
}

2
src/ImageSharp/Processing/Transforms/Processors/CropProcessor.cs

@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{
Span<TPixel> sourceRow = source.GetPixelRowSpan(y).Slice(minX);
Span<TPixel> targetRow = destination.GetPixelRowSpan(y - minY);
SpanHelper.Copy(sourceRow, targetRow, maxX - minX);
sourceRow.Slice(0, maxX - minX).CopyTo(targetRow);
});
}
}

Loading…
Cancel
Save