From 7c6b73d2e2885e7c06fb644530fe277867b2c203 Mon Sep 17 00:00:00 2001 From: dirk Date: Fri, 11 Nov 2016 20:50:55 +0100 Subject: [PATCH] Added optimized implementation for CopyFromXYZW and CopyFromXYZ. --- src/ImageSharp/PixelAccessor.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/PixelAccessor.cs b/src/ImageSharp/PixelAccessor.cs index 28cdff54a..484173844 100644 --- a/src/ImageSharp/PixelAccessor.cs +++ b/src/ImageSharp/PixelAccessor.cs @@ -5,7 +5,6 @@ namespace ImageSharp { - using System; using System.Runtime.CompilerServices; /// @@ -22,6 +21,30 @@ namespace ImageSharp { } + /// + protected override void CopyFromXYZW(PixelRow row, int targetY, int targetX, int width) + { + byte* source = row.PixelBase; + byte* destination = this.GetRowPointer(targetY) + targetX; + + Unsafe.CopyBlock(destination, source, (uint) width * 4); + } + + /// + protected override void CopyFromXYZ(PixelRow row, int targetY, int targetX, int width) + { + byte* source = row.PixelBase; + byte* destination = this.GetRowPointer(targetY) + targetX; + + for (int x = 0; x < width; x++) + { + Unsafe.Write(destination, (uint)(*(source) << 0 | *(source + 1) << 8 | *(source + 2) << 16 | 255 << 24)); + + source += 3; + destination += 4; + } + } + /// protected override void CopyFromZYX(PixelRow row, int targetY, int targetX, int width) {