Browse Source

Removed CopyBlock and added new method to copy all the pixels.

af/merge-core
Dirk Lemstra 9 years ago
parent
commit
8fa4206aaf
  1. 2
      src/ImageSharp/Image/ImageBase{TColor}.cs
  2. 39
      src/ImageSharp/Image/PixelAccessor{TColor}.cs
  3. 21
      tests/ImageSharp.Benchmarks/Image/CopyPixels.cs

2
src/ImageSharp/Image/ImageBase{TColor}.cs

@ -64,7 +64,7 @@ namespace ImageSharp
using (PixelAccessor<TColor> sourcePixels = other.Lock())
using (PixelAccessor<TColor> target = this.Lock())
{
sourcePixels.CopyImage(target);
sourcePixels.CopyTo(target);
}
}

39
src/ImageSharp/Image/PixelAccessor{TColor}.cs

@ -144,34 +144,6 @@ namespace ImageSharp
}
}
/// <summary>
/// Copies a block of pixels at the specified position.
/// </summary>
/// <param name="sourceX">The x-coordinate of the source image.</param>
/// <param name="sourceY">The y-coordinate of the source image.</param>
/// <param name="target">The target pixel buffer accessor.</param>
/// <param name="targetX">The x-coordinate of the target image.</param>
/// <param name="targetY">The y-coordinate of the target image.</param>
/// <param name="pixelCount">The number of pixels to copy</param>
public void CopyBlock(int sourceX, int sourceY, PixelAccessor<TColor> 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>
/// Copies an entire image.
/// </summary>
/// <param name="target">The target pixel buffer accessor.</param>
public void CopyImage(PixelAccessor<TColor> target)
{
this.CopyBlock(0, 0, target, 0, 0, target.Width * target.Height);
}
/// <summary>
/// Copied a row of pixels from the image.
/// </summary>
@ -259,6 +231,17 @@ namespace ImageSharp
GC.SuppressFinalize(this);
}
/// <summary>
/// Copies the pixels to another <see cref="PixelAccessor{TColor}"/> of the same size.
/// </summary>
/// <param name="target">The target pixel buffer accessor.</param>
internal void CopyTo(PixelAccessor<TColor> target)
{
uint byteCount = (uint)(this.Width * this.Height * Unsafe.SizeOf<TColor>());
Unsafe.CopyBlock(target.pixelsBase, this.pixelsBase, byteCount);
}
/// <summary>
/// Resets all the pixels to it's initial value.
/// </summary>

21
tests/ImageSharp.Benchmarks/Image/CopyPixels.cs

@ -37,26 +37,5 @@ namespace ImageSharp.Benchmarks.Image
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> sourcePixels = source.Lock())
using (PixelAccessor<CoreColor> targetPixels = target.Lock())
{
Parallel.For(
0,
source.Height,
Bootstrapper.ParallelOptions,
y =>
{
sourcePixels.CopyBlock(0, y, targetPixels, 0, y, source.Width);
});
return targetPixels[0, 0];
}
}
}
}

Loading…
Cancel
Save