From b3ecf0ec736ee60a8bc793de637a7892562649a2 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Fri, 16 Dec 2016 21:13:51 +0100 Subject: [PATCH] Fixed issue with incorrect X offset in the PixelAccessor that was reported by Anton Firsov. --- src/ImageSharp/Image/PixelAccessor.cs | 15 ++++++++------- src/ImageSharp/PixelAccessor.cs | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ImageSharp/Image/PixelAccessor.cs b/src/ImageSharp/Image/PixelAccessor.cs index 0dd43fd8cd..eba054955b 100644 --- a/src/ImageSharp/Image/PixelAccessor.cs +++ b/src/ImageSharp/Image/PixelAccessor.cs @@ -297,7 +297,7 @@ namespace ImageSharp for (int y = 0; y < height; y++) { byte* source = area.PixelBase + (y * area.RowByteCount); - byte* destination = this.GetRowPointer(targetY + y) + targetX; + byte* destination = this.GetRowPointer(targetX, targetY + y); for (int x = 0; x < width; x++) { @@ -326,7 +326,7 @@ namespace ImageSharp for (int y = 0; y < height; y++) { byte* source = area.PixelBase + (y * area.RowByteCount); - byte* destination = this.GetRowPointer(targetY + y) + targetX; + byte* destination = this.GetRowPointer(targetX, targetY + y); for (int x = 0; x < width; x++) { @@ -355,7 +355,7 @@ namespace ImageSharp for (int y = 0; y < height; y++) { byte* source = area.PixelBase + (y * area.RowByteCount); - byte* destination = this.GetRowPointer(targetY + y) + targetX; + byte* destination = this.GetRowPointer(targetX, targetY + y); for (int x = 0; x < width; x++) { @@ -384,7 +384,7 @@ namespace ImageSharp for (int y = 0; y < height; y++) { byte* source = area.PixelBase + (y * area.RowByteCount); - byte* destination = this.GetRowPointer(targetY + y) + targetX; + byte* destination = this.GetRowPointer(targetX, targetY + y); for (int x = 0; x < width; x++) { @@ -484,13 +484,14 @@ namespace ImageSharp /// /// Gets the pointer at the specified row. /// - /// The target row index. + /// The column index. + /// The row index. /// /// The . /// - protected byte* GetRowPointer(int targetY) + protected byte* GetRowPointer(int x, int y) { - return this.pixelsBase + ((targetY * this.Width) * Unsafe.SizeOf()); + return this.pixelsBase + (((y * this.Width) + x) * Unsafe.SizeOf()); } [Conditional("DEBUG")] diff --git a/src/ImageSharp/PixelAccessor.cs b/src/ImageSharp/PixelAccessor.cs index e4d1a9ea7b..45fad4e6a6 100644 --- a/src/ImageSharp/PixelAccessor.cs +++ b/src/ImageSharp/PixelAccessor.cs @@ -29,7 +29,7 @@ namespace ImageSharp for (int y = 0; y < height; y++) { byte* source = area.PixelBase + (y * area.RowByteCount); - byte* destination = this.GetRowPointer(targetY + y) + targetX; + byte* destination = this.GetRowPointer(targetX, targetY + y); Unsafe.CopyBlock(destination, source, byteCount); } @@ -41,7 +41,7 @@ namespace ImageSharp for (int y = 0; y < height; y++) { byte* source = area.PixelBase + (y * area.RowByteCount); - byte* destination = this.GetRowPointer(targetY + y) + targetX; + byte* destination = this.GetRowPointer(targetX, targetY + y); for (int x = 0; x < width; x++) { @@ -59,7 +59,7 @@ namespace ImageSharp for (int y = 0; y < height; y++) { byte* source = area.PixelBase + (y * area.RowByteCount); - byte* destination = this.GetRowPointer(targetY + y) + targetX; + byte* destination = this.GetRowPointer(targetX, targetY + y); for (int x = 0; x < width; x++) { @@ -77,7 +77,7 @@ namespace ImageSharp for (int y = 0; y < height; y++) { byte* source = area.PixelBase + (y * area.RowByteCount); - byte* destination = this.GetRowPointer(targetY + y) + targetX; + byte* destination = this.GetRowPointer(targetX, targetY + y); for (int x = 0; x < width; x++) { @@ -94,7 +94,7 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - byte* source = this.GetRowPointer(sourceY + y) + sourceX; + byte* source = this.GetRowPointer(sourceX, sourceY + y); byte* destination = area.PixelBase + (y * area.RowByteCount); for (int x = 0; x < width; x++) @@ -114,7 +114,7 @@ namespace ImageSharp { for (int y = 0; y < height; y++) { - byte* source = this.GetRowPointer(sourceY + y) + sourceX; + byte* source = this.GetRowPointer(sourceX, sourceY + y); byte* destination = area.PixelBase + (y * area.RowByteCount); for (int x = 0; x < width; x++)