Browse Source

Added optional targetX argument to the PixelAccessor.

pull/30/head
dirk 9 years ago
committed by Dirk Lemstra
parent
commit
bb23eb3999
  1. 31
      src/ImageSharp/Image/PixelAccessor.cs
  2. 8
      src/ImageSharp/PixelAccessor.cs

31
src/ImageSharp/Image/PixelAccessor.cs

@ -141,24 +141,25 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="row">The row.</param> /// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param> /// <param name="targetY">The target row index.</param>
/// <param name="targetX">The target column index.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed. /// Thrown when an unsupported component order value is passed.
/// </exception> /// </exception>
public void CopyFrom(PixelRow<TColor, TPacked> row, int targetY) public void CopyFrom(PixelRow<TColor, TPacked> row, int targetY, int targetX = 0)
{ {
switch (row.ComponentOrder) switch (row.ComponentOrder)
{ {
case ComponentOrder.ZYX: case ComponentOrder.ZYX:
this.CopyFromZYX(row, targetY, Math.Min(row.Width, this.Width)); this.CopyFromZYX(row, targetY, targetX, Math.Min(row.Width, this.Width));
break; break;
case ComponentOrder.ZYXW: case ComponentOrder.ZYXW:
this.CopyFromZYXW(row, targetY, Math.Min(row.Width, this.Width)); this.CopyFromZYXW(row, targetY, targetX, Math.Min(row.Width, this.Width));
break; break;
case ComponentOrder.XYZ: case ComponentOrder.XYZ:
this.CopyFromXYZ(row, targetY, Math.Min(row.Width, this.Width)); this.CopyFromXYZ(row, targetY, targetX, Math.Min(row.Width, this.Width));
break; break;
case ComponentOrder.XYZW: case ComponentOrder.XYZW:
this.CopyFromXYZW(row, targetY, Math.Min(row.Width, this.Width)); this.CopyFromXYZW(row, targetY, targetX, Math.Min(row.Width, this.Width));
break; break;
default: default:
throw new NotSupportedException(); throw new NotSupportedException();
@ -228,11 +229,12 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="row">The row.</param> /// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param> /// <param name="targetY">The target row index.</param>
/// <param name="targetX">The target column index.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
protected virtual void CopyFromZYX(PixelRow<TColor, TPacked> row, int targetY, int width) protected virtual void CopyFromZYX(PixelRow<TColor, TPacked> row, int targetY, int targetX, int width)
{ {
byte* source = row.PixelBase; byte* source = row.PixelBase;
byte* destination = this.GetRowPointer(targetY); byte* destination = this.GetRowPointer(targetY) + targetX;
TColor packed = default(TColor); TColor packed = default(TColor);
int size = Unsafe.SizeOf<TColor>(); int size = Unsafe.SizeOf<TColor>();
@ -252,11 +254,12 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="row">The row.</param> /// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param> /// <param name="targetY">The target row index.</param>
/// <param name="targetX">The target column index.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
protected virtual void CopyFromZYXW(PixelRow<TColor, TPacked> row, int targetY, int width) protected virtual void CopyFromZYXW(PixelRow<TColor, TPacked> row, int targetY, int targetX, int width)
{ {
byte* source = row.PixelBase; byte* source = row.PixelBase;
byte* destination = this.GetRowPointer(targetY); byte* destination = this.GetRowPointer(targetY) + targetX;
TColor packed = default(TColor); TColor packed = default(TColor);
int size = Unsafe.SizeOf<TColor>(); int size = Unsafe.SizeOf<TColor>();
@ -276,11 +279,12 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="row">The row.</param> /// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param> /// <param name="targetY">The target row index.</param>
/// <param name="targetX">The target column index.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
protected virtual void CopyFromXYZ(PixelRow<TColor, TPacked> row, int targetY, int width) protected virtual void CopyFromXYZ(PixelRow<TColor, TPacked> row, int targetY, int targetX, int width)
{ {
byte* source = row.PixelBase; byte* source = row.PixelBase;
byte* destination = this.GetRowPointer(targetY); byte* destination = this.GetRowPointer(targetY) + targetX;
TColor packed = default(TColor); TColor packed = default(TColor);
int size = Unsafe.SizeOf<TColor>(); int size = Unsafe.SizeOf<TColor>();
@ -300,11 +304,12 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="row">The row.</param> /// <param name="row">The row.</param>
/// <param name="targetY">The target row index.</param> /// <param name="targetY">The target row index.</param>
/// <param name="targetX">The target column index.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
protected virtual void CopyFromXYZW(PixelRow<TColor, TPacked> row, int targetY, int width) protected virtual void CopyFromXYZW(PixelRow<TColor, TPacked> row, int targetY, int targetX, int width)
{ {
byte* source = row.PixelBase; byte* source = row.PixelBase;
byte* destination = this.GetRowPointer(targetY); byte* destination = this.GetRowPointer(targetY) + targetX;
TColor packed = default(TColor); TColor packed = default(TColor);
int size = Unsafe.SizeOf<TColor>(); int size = Unsafe.SizeOf<TColor>();

8
src/ImageSharp/PixelAccessor.cs

@ -23,10 +23,10 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void CopyFromZYX(PixelRow<Color, uint> row, int targetY, int width) protected override void CopyFromZYX(PixelRow<Color, uint> row, int targetY, int targetX, int width)
{ {
byte* source = row.PixelBase; byte* source = row.PixelBase;
byte* destination = this.GetRowPointer(targetY); byte* destination = this.GetRowPointer(targetY) + targetX;
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
@ -38,10 +38,10 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void CopyFromZYXW(PixelRow<Color, uint> row, int targetY, int width) protected override void CopyFromZYXW(PixelRow<Color, uint> row, int targetY, int targetX, int width)
{ {
byte* source = row.PixelBase; byte* source = row.PixelBase;
byte* destination = this.GetRowPointer(targetY); byte* destination = this.GetRowPointer(targetY) + targetX;
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {

Loading…
Cancel
Save