Browse Source

Benchmark CopyRow touch #457 [skip ci]

Former-commit-id: 3ebb26faca837aeac974a67da676be409d902ae7
Former-commit-id: d7a8a733fabfb6621f8f3a04c56b9f2aa6913392
Former-commit-id: ec769799df83b3f7b1d4934aead8e6ae1e280736
af/merge-core
James Jackson-South 10 years ago
parent
commit
221e29be31
  1. 19
      src/ImageProcessorCore/Image/PixelAccessor.cs
  2. 2
      tests/ImageProcessorCore.Benchmarks/General/ArrayCopy.cs
  3. 57
      tests/ImageProcessorCore.Benchmarks/Image/CopyPixels.cs
  4. 4
      tests/ImageProcessorCore.Benchmarks/Samplers/Crop.cs

19
src/ImageProcessorCore/Image/PixelAccessor.cs

@ -108,6 +108,25 @@ namespace ImageProcessorCore
set { Unsafe.Write(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf<TColor>(), value); }
}
/// <summary>
/// Copies an entire row of pixels.
/// </summary>
/// <param name="sourceX">The x-coordinate of the source row.</param>
/// <param name="sourceY">The y-coordinate of the source row.</param>
/// <param name="target">The target pixel buffer accessor.</param>
/// <param name="targetX">The x-coordinate of the target row.</param>
/// <param name="targetY">The y-coordinate of the target row.</param>
/// <param name="pixelCount">The number of pixels to copy</param>
public void CopyRow(int sourceX, int sourceY, PixelAccessor<TColor, TPacked> target, int targetX, int targetY, int pixelCount)
{
int size = Unsafe.SizeOf<TColor>();
byte* sourcePtr = this.pixelsBase + (sourceY * this.Width + sourceX) * size;
byte* targetPtr = target.pixelsBase + (targetY * target.Width + targetX) * size;
uint byteCount = (uint)(pixelCount * size);
Unsafe.CopyBlock(targetPtr, sourcePtr, byteCount);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>

2
tests/ImageProcessorCore.Benchmarks/General/Copy.cs → tests/ImageProcessorCore.Benchmarks/General/ArrayCopy.cs

@ -5,7 +5,7 @@ namespace ImageProcessorCore.Benchmarks.General
{
using BenchmarkDotNet.Attributes;
public class Copy
public class ArrayCopy
{
private double[] source = new double[10000];

57
tests/ImageProcessorCore.Benchmarks/Image/CopyPixels.cs

@ -0,0 +1,57 @@
namespace ImageProcessorCore.Benchmarks.Image
{
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using CoreColor = ImageProcessorCore.Color;
using CoreImage = ImageProcessorCore.Image;
public class CopyPixels
{
[Benchmark(Description = "Copy by Pixel")]
public CoreColor CopyByPixel()
{
CoreImage source = new CoreImage(1024, 768);
CoreImage target = new CoreImage(1024, 768);
using (PixelAccessor<CoreColor, uint> sourcePixels = source.Lock())
using (PixelAccessor<CoreColor, uint> targetPixels = target.Lock())
{
Parallel.For(
0,
source.Height,
Bootstrapper.Instance.ParallelOptions,
y =>
{
for (int x = 0; x < source.Width; x++)
{
targetPixels[x, y] = sourcePixels[x, y];
}
});
return targetPixels[0, 0];
}
}
[Benchmark(Description = "Copy by Row")]
public CoreColor CopyByRow()
{
CoreImage source = new CoreImage(1024, 768);
CoreImage target = new CoreImage(1024, 768);
using (PixelAccessor<CoreColor, uint> sourcePixels = source.Lock())
using (PixelAccessor<CoreColor, uint> targetPixels = target.Lock())
{
Parallel.For(
0,
source.Height,
Bootstrapper.Instance.ParallelOptions,
y =>
{
sourcePixels.CopyRow(0, y, targetPixels, 0, y, source.Width);
});
return targetPixels[0, 0];
}
}
}
}

4
tests/ImageProcessorCore.Benchmarks/Samplers/Crop.cs

@ -12,7 +12,7 @@
[Benchmark(Baseline = true, Description = "System.Drawing Crop")]
public Size CropSystemDrawing()
{
using (Bitmap source = new Bitmap(400, 400))
using (Bitmap source = new Bitmap(800, 800))
{
using (Bitmap destination = new Bitmap(100, 100))
{
@ -32,7 +32,7 @@
[Benchmark(Description = "ImageProcessorCore Crop")]
public CoreSize CropResizeCore()
{
CoreImage image = new CoreImage(400, 400);
CoreImage image = new CoreImage(800, 800);
image.Crop(100, 100);
return new CoreSize(image.Width, image.Height);
}

Loading…
Cancel
Save