From 1ba4cf54d1b9ed09edbeecd11d0db0630d1d49fc Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 13 Apr 2017 02:57:04 +0200 Subject: [PATCH] fix CopyTo***Bytes() --- .../Colors/PackedPixel/BulkPixelOperations{TColor}.cs | 8 ++++---- src/ImageSharp/Common/Memory/BufferSpan.cs | 2 +- tests/ImageSharp.Benchmarks/General/PixelIndexing.cs | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs b/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs index a3bd32825..ccb1c2261 100644 --- a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs +++ b/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs @@ -105,7 +105,7 @@ namespace ImageSharp for (int i = 0; i < count; i++) { ref TColor sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToXyzBytes(dest, i * 3); + sp.ToXyzBytes(dest, destBytes.Start + (i * 3)); } } @@ -152,7 +152,7 @@ namespace ImageSharp for (int i = 0; i < count; i++) { ref TColor sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToXyzwBytes(dest, i * 4); + sp.ToXyzwBytes(dest, destBytes.Start + (i * 4)); } } @@ -196,7 +196,7 @@ namespace ImageSharp for (int i = 0; i < count; i++) { ref TColor sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToZyxBytes(dest, i * 3); + sp.ToZyxBytes(dest, destBytes.Start + (i * 3)); } } @@ -243,7 +243,7 @@ namespace ImageSharp for (int i = 0; i < count; i++) { ref TColor sp = ref Unsafe.Add(ref sourceRef, i); - sp.ToZyxwBytes(dest, i * 4); + sp.ToZyxwBytes(dest, destBytes.Start + (i * 4)); } } } diff --git a/src/ImageSharp/Common/Memory/BufferSpan.cs b/src/ImageSharp/Common/Memory/BufferSpan.cs index 5db1cd7da..cf5d99746 100644 --- a/src/ImageSharp/Common/Memory/BufferSpan.cs +++ b/src/ImageSharp/Common/Memory/BufferSpan.cs @@ -35,7 +35,7 @@ namespace ImageSharp fixed (byte* pDest = &destRef) { #if NETSTANDARD1_1 - Unsafe.CopyBlock(pDest, pSrc, (uint) byteCount); + Unsafe.CopyBlock(pDest, pSrc, (uint)byteCount); #else if (byteCount > 512) { diff --git a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs index a5fa5d0f2..6db0eef36 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelIndexing.cs @@ -46,6 +46,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 GetPointersSrcsUnsafeImpl(int x, int y) { + // This is the original solution in PixelAccessor: return Unsafe.Read((byte*)this.pointer + (((y * this.width) + x) * Unsafe.SizeOf())); }