From bb23eb39993c26a9cfdb94809ce61dced19bf64c Mon Sep 17 00:00:00 2001 From: dirk Date: Fri, 11 Nov 2016 20:18:06 +0100 Subject: [PATCH] Added optional targetX argument to the PixelAccessor. --- src/ImageSharp/Image/PixelAccessor.cs | 31 ++++++++++++++++----------- src/ImageSharp/PixelAccessor.cs | 8 +++---- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/ImageSharp/Image/PixelAccessor.cs b/src/ImageSharp/Image/PixelAccessor.cs index fec50b972..0cd634126 100644 --- a/src/ImageSharp/Image/PixelAccessor.cs +++ b/src/ImageSharp/Image/PixelAccessor.cs @@ -141,24 +141,25 @@ namespace ImageSharp /// /// The row. /// The target row index. + /// The target column index. /// /// Thrown when an unsupported component order value is passed. /// - public void CopyFrom(PixelRow row, int targetY) + public void CopyFrom(PixelRow row, int targetY, int targetX = 0) { switch (row.ComponentOrder) { 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; 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; 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; 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; default: throw new NotSupportedException(); @@ -228,11 +229,12 @@ namespace ImageSharp /// /// The row. /// The target row index. + /// The target column index. /// The width. - protected virtual void CopyFromZYX(PixelRow row, int targetY, int width) + protected virtual void CopyFromZYX(PixelRow row, int targetY, int targetX, int width) { byte* source = row.PixelBase; - byte* destination = this.GetRowPointer(targetY); + byte* destination = this.GetRowPointer(targetY) + targetX; TColor packed = default(TColor); int size = Unsafe.SizeOf(); @@ -252,11 +254,12 @@ namespace ImageSharp /// /// The row. /// The target row index. + /// The target column index. /// The width. - protected virtual void CopyFromZYXW(PixelRow row, int targetY, int width) + protected virtual void CopyFromZYXW(PixelRow row, int targetY, int targetX, int width) { byte* source = row.PixelBase; - byte* destination = this.GetRowPointer(targetY); + byte* destination = this.GetRowPointer(targetY) + targetX; TColor packed = default(TColor); int size = Unsafe.SizeOf(); @@ -276,11 +279,12 @@ namespace ImageSharp /// /// The row. /// The target row index. + /// The target column index. /// The width. - protected virtual void CopyFromXYZ(PixelRow row, int targetY, int width) + protected virtual void CopyFromXYZ(PixelRow row, int targetY, int targetX, int width) { byte* source = row.PixelBase; - byte* destination = this.GetRowPointer(targetY); + byte* destination = this.GetRowPointer(targetY) + targetX; TColor packed = default(TColor); int size = Unsafe.SizeOf(); @@ -300,11 +304,12 @@ namespace ImageSharp /// /// The row. /// The target row index. + /// The target column index. /// The width. - protected virtual void CopyFromXYZW(PixelRow row, int targetY, int width) + protected virtual void CopyFromXYZW(PixelRow row, int targetY, int targetX, int width) { byte* source = row.PixelBase; - byte* destination = this.GetRowPointer(targetY); + byte* destination = this.GetRowPointer(targetY) + targetX; TColor packed = default(TColor); int size = Unsafe.SizeOf(); diff --git a/src/ImageSharp/PixelAccessor.cs b/src/ImageSharp/PixelAccessor.cs index 5c2ec5065..28cdff54a 100644 --- a/src/ImageSharp/PixelAccessor.cs +++ b/src/ImageSharp/PixelAccessor.cs @@ -23,10 +23,10 @@ namespace ImageSharp } /// - protected override void CopyFromZYX(PixelRow row, int targetY, int width) + protected override void CopyFromZYX(PixelRow row, int targetY, int targetX, int width) { byte* source = row.PixelBase; - byte* destination = this.GetRowPointer(targetY); + byte* destination = this.GetRowPointer(targetY) + targetX; for (int x = 0; x < width; x++) { @@ -38,10 +38,10 @@ namespace ImageSharp } /// - protected override void CopyFromZYXW(PixelRow row, int targetY, int width) + protected override void CopyFromZYXW(PixelRow row, int targetY, int targetX, int width) { byte* source = row.PixelBase; - byte* destination = this.GetRowPointer(targetY); + byte* destination = this.GetRowPointer(targetY) + targetX; for (int x = 0; x < width; x++) {