From 19c9143fa1902ccffde03d43e7e87f25aa778f80 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 14 Jul 2024 21:02:02 +0200 Subject: [PATCH] Added ConvertTo-method to IImage --- HPPH/Images/Image.cs | 9 ++++++++- HPPH/Images/Interfaces/IImage.cs | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/HPPH/Images/Image.cs b/HPPH/Images/Image.cs index 821797b..fb28136 100644 --- a/HPPH/Images/Image.cs +++ b/HPPH/Images/Image.cs @@ -58,7 +58,7 @@ public sealed class Image : IImage get { if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0) || ((x + width) > Width) || ((y + height) > Height)) throw new IndexOutOfRangeException(); - + return new Image(_buffer, _x + x, _y + y, width, height, _stride); } } @@ -123,6 +123,13 @@ public sealed class Image : IImage return new Image(data, 0, 0, width, height, stride); } + public void ConvertTo() + where TColor : struct, IColor + { + for (int i = 0; i < Height; i++) + MemoryMarshal.Cast(_buffer.AsSpan().Slice(((i + _y) * _stride) + _x, Width)).ConvertInPlace(); + } + public void CopyTo(Span destination) => CopyTo(MemoryMarshal.AsBytes(destination)); /// diff --git a/HPPH/Images/Interfaces/IImage.cs b/HPPH/Images/Interfaces/IImage.cs index ecc3d84..75d019b 100644 --- a/HPPH/Images/Interfaces/IImage.cs +++ b/HPPH/Images/Interfaces/IImage.cs @@ -60,6 +60,8 @@ public interface IImage : IEnumerable /// The . RefImage AsRefImage() where TColor : struct, IColor; + void ConvertTo() where T : struct, IColor; + /// /// Copies the contents of this into a destination instance. ///