diff --git a/HPPH.Test/Image/ImageTest.cs b/HPPH.Test/Image/ImageTest.cs index ff74615..8a4a6b5 100644 --- a/HPPH.Test/Image/ImageTest.cs +++ b/HPPH.Test/Image/ImageTest.cs @@ -748,7 +748,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexerWrongXBig() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -756,7 +756,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexerWrongYBig() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -764,7 +764,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexerWrongXSmall() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -772,7 +772,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexerWrongYSmall() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -780,7 +780,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageWrongX() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -788,7 +788,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageWrongY() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -796,7 +796,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageWrongWidth() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -804,7 +804,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageWrongHeight() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -812,7 +812,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInvalidSizeWidth() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -820,7 +820,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInvalidSizeHeight() { Image image = TestDataHelper.CreateTestImage(10, 20); @@ -828,7 +828,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInterfaceWrongX() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -836,7 +836,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInterfaceWrongY() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -844,7 +844,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInterfaceWrongWidth() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -852,7 +852,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInterfaceWrongHeight() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -860,7 +860,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInterfaceInvalidSizeWidth() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -868,7 +868,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInterfaceInvalidSizeHeight() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -876,7 +876,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ColumnsIndexerToBig() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -884,7 +884,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ColumnsIndexerToSmall() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -892,7 +892,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RowsIndexerToBig() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -900,7 +900,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RowsIndexerToSmall() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -908,7 +908,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ColumnIndexerToBig() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -916,7 +916,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ColumnIndexerToSmall() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -924,7 +924,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RowIndexerToBig() { IImage image = TestDataHelper.CreateTestImage(10, 20); @@ -932,7 +932,7 @@ public class ImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RowIndexerToSmall() { IImage image = TestDataHelper.CreateTestImage(10, 20); diff --git a/HPPH.Test/Image/RefImageTest.cs b/HPPH.Test/Image/RefImageTest.cs index e1197ec..9bb9495 100644 --- a/HPPH.Test/Image/RefImageTest.cs +++ b/HPPH.Test/Image/RefImageTest.cs @@ -296,7 +296,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexerWrongXBig() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -304,7 +304,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexerWrongYBig() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -312,7 +312,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexerWrongXSmall() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -320,7 +320,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void IndexerWrongYSmall() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -328,7 +328,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageWrongX() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -336,7 +336,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageWrongY() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -344,7 +344,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageWrongWidth() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -352,7 +352,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageWrongHeight() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -360,7 +360,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInvalidSizeWidth() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -368,7 +368,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void SubImageInvalidSizeHeight() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -376,7 +376,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ColumnsIndexerToBig() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -384,7 +384,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ColumnsIndexerToSmall() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -392,7 +392,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RowsIndexerToBig() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -400,7 +400,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RowsIndexerToSmall() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -408,7 +408,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ColumnIndexerToBig() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -416,7 +416,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void ColumnIndexerToSmall() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -424,7 +424,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RowIndexerToBig() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); @@ -432,7 +432,7 @@ public class RefImageTest } [TestMethod] - [ExpectedException(typeof(IndexOutOfRangeException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void RowIndexerToSmall() { RefImage image = TestDataHelper.CreateTestImage(10, 20).AsRefImage(); diff --git a/HPPH.Test/PixelHelper/ConvertTests.cs b/HPPH.Test/PixelHelper/ConvertTests.cs index 3e2c125..e1c280e 100644 --- a/HPPH.Test/PixelHelper/ConvertTests.cs +++ b/HPPH.Test/PixelHelper/ConvertTests.cs @@ -33,6 +33,12 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + Assert.AreEqual(TestDataHelper.GetColorFromLocation(x, y), converted[x, y], $"Wrong color at x: {x}, y: {y}"); } [TestMethod] @@ -63,6 +69,12 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + Assert.AreEqual(TestDataHelper.GetColorFromLocation(x, y), converted[x, y], $"Wrong color at x: {x}, y: {y}"); } [TestMethod] @@ -93,6 +105,12 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + Assert.AreEqual(TestDataHelper.GetColorFromLocation(x, y), converted[x, y], $"Wrong color at x: {x}, y: {y}"); } [TestMethod] @@ -123,6 +141,12 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + Assert.AreEqual(TestDataHelper.GetColorFromLocation(x, y), converted[x, y], $"Wrong color at x: {x}, y: {y}"); } [TestMethod] @@ -153,6 +177,12 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + Assert.AreEqual(TestDataHelper.GetColorFromLocation(x, y), converted[x, y], $"Wrong color at x: {x}, y: {y}"); } [TestMethod] @@ -183,6 +213,20 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + { + ColorABGR refColor = TestDataHelper.GetColorFromLocation(x, y); + ColorRGBA color = converted[x, y]; + + Assert.AreEqual(255, color.A, $"Wrong A at x: {x}, y: {y}"); + Assert.AreEqual(refColor.R, color.R, $"Wrong R at x: {x}, y: {y}"); + Assert.AreEqual(refColor.G, color.G, $"Wrong G at x: {x}, y: {y}"); + Assert.AreEqual(refColor.B, color.B, $"Wrong B at x: {x}, y: {y}"); + } } [TestMethod] @@ -213,6 +257,20 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + { + ColorABGR refColor = TestDataHelper.GetColorFromLocation(x, y); + ColorARGB color = converted[x, y]; + + Assert.AreEqual(255, color.A, $"Wrong A at x: {x}, y: {y}"); + Assert.AreEqual(refColor.R, color.R, $"Wrong R at x: {x}, y: {y}"); + Assert.AreEqual(refColor.G, color.G, $"Wrong G at x: {x}, y: {y}"); + Assert.AreEqual(refColor.B, color.B, $"Wrong B at x: {x}, y: {y}"); + } } [TestMethod] @@ -243,6 +301,20 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + { + ColorABGR refColor = TestDataHelper.GetColorFromLocation(x, y); + ColorBGRA color = converted[x, y]; + + Assert.AreEqual(255, color.A, $"Wrong A at x: {x}, y: {y}"); + Assert.AreEqual(refColor.R, color.R, $"Wrong R at x: {x}, y: {y}"); + Assert.AreEqual(refColor.G, color.G, $"Wrong G at x: {x}, y: {y}"); + Assert.AreEqual(refColor.B, color.B, $"Wrong B at x: {x}, y: {y}"); + } } [TestMethod] @@ -273,6 +345,20 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + { + ColorABGR refColor = TestDataHelper.GetColorFromLocation(x, y); + ColorABGR color = converted[x, y]; + + Assert.AreEqual(255, color.A, $"Wrong A at x: {x}, y: {y}"); + Assert.AreEqual(refColor.R, color.R, $"Wrong R at x: {x}, y: {y}"); + Assert.AreEqual(refColor.G, color.G, $"Wrong G at x: {x}, y: {y}"); + Assert.AreEqual(refColor.B, color.B, $"Wrong B at x: {x}, y: {y}"); + } } [TestMethod] @@ -303,5 +389,11 @@ public class ConvertTests } } } + + IImage converted = TestDataHelper.CreateTestImage(1920, 1080).ConvertTo(); + + for (int y = 0; y < converted.Height; y++) + for (int x = 0; x < converted.Width; x++) + Assert.AreEqual(TestDataHelper.GetColorFromLocation(x, y), converted[x, y], $"Wrong color at x: {x}, y: {y}"); } } \ No newline at end of file diff --git a/HPPH.Test/SystemDrawing/SystemDrawingTests.cs b/HPPH.Test/SystemDrawing/SystemDrawingTests.cs index 4b65a35..474b965 100644 --- a/HPPH.Test/SystemDrawing/SystemDrawingTests.cs +++ b/HPPH.Test/SystemDrawing/SystemDrawingTests.cs @@ -16,6 +16,14 @@ public class SystemDrawingTests IImage image2 = bitmap.ToImage(); Assert.AreEqual(IColorFormat.BGR, image2.ColorFormat); + for (int y = 0; y < image.Height; y++) + for (int x = 0; x < image.Width; x++) + { + Assert.AreEqual(image[x, y].A, image2[x, y].A, $"{x}-{y}"); + Assert.AreEqual(image[x, y].R, image2[x, y].R, $"{x}-{y}"); + Assert.AreEqual(image[x, y].G, image2[x, y].G, $"{x}-{y}"); + Assert.AreEqual(image[x, y].B, image2[x, y].B, $"{x}-{y}"); + } image2 = image2.ConvertTo(); @@ -30,6 +38,14 @@ public class SystemDrawingTests IImage image2 = bitmap.ToImage(); Assert.AreEqual(IColorFormat.BGRA, image2.ColorFormat); + for (int y = 0; y < image.Height; y++) + for (int x = 0; x < image.Width; x++) + { + Assert.AreEqual(image[x, y].A, image2[x, y].A); + Assert.AreEqual(image[x, y].R, image2[x, y].R); + Assert.AreEqual(image[x, y].G, image2[x, y].G); + Assert.AreEqual(image[x, y].B, image2[x, y].B); + } image2 = image2.ConvertTo(); diff --git a/HPPH/PixelHelper.Convert.cs b/HPPH/PixelHelper.Convert.cs index 4e89ba1..43f1e5b 100644 --- a/HPPH/PixelHelper.Convert.cs +++ b/HPPH/PixelHelper.Convert.cs @@ -174,12 +174,14 @@ public static unsafe partial class PixelHelper tar += bytesPerVector; } + Span buffer = stackalloc byte[missingElements * BPP]; for (int i = 0; i < missingElements; i++) { - tar[(i * BPP) + 0] = src[(i * BPP) + maskVector[0]]; - tar[(i * BPP) + 1] = src[(i * BPP) + maskVector[1]]; - tar[(i * BPP) + 2] = src[(i * BPP) + maskVector[2]]; + buffer[(i * BPP) + 0] = src[(i * BPP) + maskVector[0]]; + buffer[(i * BPP) + 1] = src[(i * BPP) + maskVector[1]]; + buffer[(i * BPP) + 2] = src[(i * BPP) + maskVector[2]]; } + buffer.CopyTo(new Span(tar, buffer.Length)); } else { @@ -191,12 +193,14 @@ public static unsafe partial class PixelHelper byte* missingSrc = sourcePtr + (batches * batchSize * BPP); byte* missingTar = targetPtr + (batches * batchSize * BPP); + Span buffer = stackalloc byte[missing * BPP]; for (int i = 0; i < missing; i++) { - missingTar[(i * BPP) + 0] = missingSrc[(i * BPP) + maskVector[0]]; - missingTar[(i * BPP) + 1] = missingSrc[(i * BPP) + maskVector[1]]; - missingTar[(i * BPP) + 2] = missingSrc[(i * BPP) + maskVector[2]]; + buffer[(i * BPP) + 0] = missingSrc[(i * BPP) + maskVector[0]]; + buffer[(i * BPP) + 1] = missingSrc[(i * BPP) + maskVector[1]]; + buffer[(i * BPP) + 2] = missingSrc[(i * BPP) + maskVector[2]]; } + buffer.CopyTo(new Span(missingTar, buffer.Length)); } void Process(int index) @@ -217,12 +221,14 @@ public static unsafe partial class PixelHelper tar += bytesPerVector; } + Span buffer = stackalloc byte[missingElements * BPP]; for (int i = 0; i < missingElements; i++) { - tar[(i * BPP) + 0] = src[(i * BPP) + maskVector[0]]; - tar[(i * BPP) + 1] = src[(i * BPP) + maskVector[1]]; - tar[(i * BPP) + 2] = src[(i * BPP) + maskVector[2]]; + buffer[(i * BPP) + 0] = src[(i * BPP) + maskVector[0]]; + buffer[(i * BPP) + 1] = src[(i * BPP) + maskVector[1]]; + buffer[(i * BPP) + 2] = src[(i * BPP) + maskVector[2]]; } + buffer.CopyTo(new Span(tar, buffer.Length)); } } } @@ -292,13 +298,15 @@ public static unsafe partial class PixelHelper tar += bytesPerVector; } + Span buffer = stackalloc byte[missingElements * BPP]; for (int i = 0; i < missingElements; i++) { - tar[(i * BPP) + 0] = src[(i * BPP) + maskVector[0]]; - tar[(i * BPP) + 1] = src[(i * BPP) + maskVector[1]]; - tar[(i * BPP) + 2] = src[(i * BPP) + maskVector[2]]; - tar[(i * BPP) + 3] = src[(i * BPP) + maskVector[3]]; + buffer[(i * BPP) + 0] = src[(i * BPP) + maskVector[0]]; + buffer[(i * BPP) + 1] = src[(i * BPP) + maskVector[1]]; + buffer[(i * BPP) + 2] = src[(i * BPP) + maskVector[2]]; + buffer[(i * BPP) + 3] = src[(i * BPP) + maskVector[3]]; } + buffer.CopyTo(new Span(tar, buffer.Length)); } else { @@ -310,13 +318,15 @@ public static unsafe partial class PixelHelper byte* missingSrc = sourcePtr + (batches * batchSize * BPP); byte* missingTar = targetPtr + (batches * batchSize * BPP); + Span buffer = stackalloc byte[missing * BPP]; for (int i = 0; i < missing; i++) { - missingTar[(i * BPP) + 0] = missingSrc[(i * BPP) + maskVector[0]]; - missingTar[(i * BPP) + 1] = missingSrc[(i * BPP) + maskVector[1]]; - missingTar[(i * BPP) + 2] = missingSrc[(i * BPP) + maskVector[2]]; - missingTar[(i * BPP) + 3] = missingSrc[(i * BPP) + maskVector[3]]; + buffer[(i * BPP) + 0] = missingSrc[(i * BPP) + maskVector[0]]; + buffer[(i * BPP) + 1] = missingSrc[(i * BPP) + maskVector[1]]; + buffer[(i * BPP) + 2] = missingSrc[(i * BPP) + maskVector[2]]; + buffer[(i * BPP) + 3] = missingSrc[(i * BPP) + maskVector[3]]; } + buffer.CopyTo(new Span(missingTar, buffer.Length)); } void Process(int index) @@ -337,18 +347,20 @@ public static unsafe partial class PixelHelper tar += bytesPerVector; } + Span buffer = stackalloc byte[missingElements * BPP]; for (int i = 0; i < missingElements; i++) { - tar[(i * BPP) + 0] = src[(i * BPP) + maskVector[0]]; - tar[(i * BPP) + 1] = src[(i * BPP) + maskVector[1]]; - tar[(i * BPP) + 2] = src[(i * BPP) + maskVector[2]]; - tar[(i * BPP) + 3] = src[(i * BPP) + maskVector[3]]; + buffer[(i * BPP) + 0] = src[(i * BPP) + maskVector[0]]; + buffer[(i * BPP) + 1] = src[(i * BPP) + maskVector[1]]; + buffer[(i * BPP) + 2] = src[(i * BPP) + maskVector[2]]; + buffer[(i * BPP) + 3] = src[(i * BPP) + maskVector[3]]; } + buffer.CopyTo(new Span(tar, buffer.Length)); } } } } - + private static void ConvertWiden3To4Bytes(ReadOnlySpan source, Span target, IColorFormat sourceFormat, IColorFormat targetFormat) { const int SOURCE_BPP = 3;