From 7a67f771687182847fdf2b80041c430d2a7280c6 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 7 Jul 2024 18:01:55 +0200 Subject: [PATCH] Added Convert-method for ReadOnly-data --- HPPH/PixelHelper.Convert.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/HPPH/PixelHelper.Convert.cs b/HPPH/PixelHelper.Convert.cs index 80cfdf1..0a0201b 100644 --- a/HPPH/PixelHelper.Convert.cs +++ b/HPPH/PixelHelper.Convert.cs @@ -7,6 +7,18 @@ public static unsafe partial class PixelHelper { #region Methods + public static Span Convert(ReadOnlySpan data) + where TSource : struct, IColor + where TTarget : struct, IColor + { + if (data == null) throw new ArgumentNullException(nameof(data)); + + Span dataCopy = new TSource[data.Length]; + data.CopyTo(dataCopy); + + return Convert(dataCopy); + } + public static Span Convert(Span data) where TSource : struct, IColor where TTarget : struct, IColor @@ -106,7 +118,7 @@ public static unsafe partial class PixelHelper } } - // DarthAffe 07.07.2024: No fallback-implementation here. Shuffle Requires only Seee3 which should be supported nearly anywhere and if not the fallback of Vector128.Shuffle is perfectly fine. + // DarthAffe 07.07.2024: No fallback-implementation here. Shuffle Requires only Ssse3 which should be supported nearly anywhere and if not the fallback of Vector128.Shuffle is perfectly fine. private static void ConvertEqualBpp(Span data, ReadOnlySpan mask, int bpp) { int elementsPerVector = Vector128.Count / bpp;