From ea7c8a157dcf90c85ff2a261dee541f372c8642d Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 26 Nov 2020 11:12:19 +0100 Subject: [PATCH 1/4] Ensure Span length of source and destination are equal during pixel conversions. --- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 01bdbd1c0..7819b1ebd 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -262,7 +262,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp private void Write24Bit(Stream stream, Buffer2D pixels) where TPixel : unmanaged, IPixel { - using (IManagedByteBuffer row = this.AllocateRow(pixels.Width, 3)) + int width = pixels.Width; + int rowBytesWithoutPadding = width * 3; + using (IManagedByteBuffer row = this.AllocateRow(width, 3)) { for (int y = pixels.Height - 1; y >= 0; y--) { @@ -270,8 +272,8 @@ namespace SixLabors.ImageSharp.Formats.Bmp PixelOperations.Instance.ToBgr24Bytes( this.configuration, pixelSpan, - row.GetSpan(), - pixelSpan.Length); + row.Slice(0, rowBytesWithoutPadding), + width); stream.Write(row.Array, 0, row.Length()); } } @@ -286,7 +288,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp private void Write16Bit(Stream stream, Buffer2D pixels) where TPixel : unmanaged, IPixel { - using (IManagedByteBuffer row = this.AllocateRow(pixels.Width, 2)) + int width = pixels.Width; + int rowBytesWithoutPadding = width * 2; + using (IManagedByteBuffer row = this.AllocateRow(width, 2)) { for (int y = pixels.Height - 1; y >= 0; y--) { @@ -295,7 +299,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp PixelOperations.Instance.ToBgra5551Bytes( this.configuration, pixelSpan, - row.GetSpan(), + row.Slice(0, rowBytesWithoutPadding), pixelSpan.Length); stream.Write(row.Array, 0, row.Length()); @@ -341,7 +345,8 @@ namespace SixLabors.ImageSharp.Formats.Bmp using IndexedImageFrame quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image, image.Bounds()); ReadOnlySpan quantizedColors = quantized.Palette.Span; - PixelOperations.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast(colorPalette)); + var quantizedColorBytes = quantizedColors.Length * 4; + PixelOperations.Instance.ToBgra32(this.configuration, quantizedColors, MemoryMarshal.Cast(colorPalette.Slice(0, quantizedColorBytes))); Span colorPaletteAsUInt = MemoryMarshal.Cast(colorPalette); for (int i = 0; i < colorPaletteAsUInt.Length; i++) { From 9323852f218abd7e7f72aa5d3910668219c76e06 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 29 Nov 2020 14:55:49 +0100 Subject: [PATCH 2/4] Slice destination to (0, count) --- .../PixelOperations{TPixel}.Generated.cs | 48 +++++++++---------- .../PixelOperations{TPixel}.Generated.tt | 4 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs index cc36c7d13..7919eb978 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromArgb32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromArgb32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromArgb32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToArgb32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgr24Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgr24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromBgr24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgr24Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -187,7 +187,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgra32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgra32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromBgra32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -223,7 +223,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -259,7 +259,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromL8Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromL8(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromL8(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -295,7 +295,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToL8Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -331,7 +331,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromL16Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromL16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromL16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -367,7 +367,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToL16Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -403,7 +403,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromLa16Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromLa16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromLa16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -439,7 +439,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToLa16Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -475,7 +475,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromLa32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromLa32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromLa32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -511,7 +511,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToLa32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -547,7 +547,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgb24Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgb24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromRgb24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -583,7 +583,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb24Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -619,7 +619,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgba32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgba32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromRgba32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -655,7 +655,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -691,7 +691,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgb48Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgb48(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromRgb48(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -727,7 +727,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb48Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -763,7 +763,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgba64Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgba64(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromRgba64(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -799,7 +799,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba64Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } /// @@ -835,7 +835,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgra5551Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } /// @@ -871,7 +871,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra5551Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); } } } diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt index 21ed328fa..75f884774 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt @@ -48,7 +48,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void From<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.From<#=pixelType#>(configuration, MemoryMarshal.Cast>(sourceBytes).Slice(0, count), destinationPixels); + this.From<#=pixelType#>(configuration, MemoryMarshal.Cast>(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); } <# @@ -90,7 +90,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void To<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast>(destBytes)); + this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast>(destBytes.Slice(0, count))); } <# } From 74b2e359c1414d1720567ac27e9b248c3f91a766 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 29 Nov 2020 15:56:41 +0100 Subject: [PATCH 3/4] Revert "Slice destination to (0, count)" This reverts commit 3fba6f81edd9297cd44ffffcc4a7a79cf0b76021. --- .../PixelOperations{TPixel}.Generated.cs | 48 +++++++++---------- .../PixelOperations{TPixel}.Generated.tt | 4 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs index 7919eb978..cc36c7d13 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromArgb32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromArgb32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromArgb32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToArgb32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgr24Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgr24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromBgr24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgr24Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToBgr24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -187,7 +187,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgra32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgra32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromBgra32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -223,7 +223,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToBgra32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -259,7 +259,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromL8Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromL8(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromL8(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -295,7 +295,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToL8Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToL8(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -331,7 +331,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromL16Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromL16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromL16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -367,7 +367,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToL16Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToL16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -403,7 +403,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromLa16Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromLa16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromLa16(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -439,7 +439,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToLa16Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToLa16(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -475,7 +475,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromLa32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromLa32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromLa32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -511,7 +511,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToLa32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToLa32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -547,7 +547,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgb24Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgb24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromRgb24(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -583,7 +583,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb24Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToRgb24(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -619,7 +619,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgba32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgba32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromRgba32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -655,7 +655,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToRgba32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -691,7 +691,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgb48Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgb48(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromRgb48(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -727,7 +727,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgb48Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToRgb48(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -763,7 +763,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromRgba64Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromRgba64(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromRgba64(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -799,7 +799,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToRgba64Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } /// @@ -835,7 +835,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void FromBgra5551Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); } /// @@ -871,7 +871,7 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToBgra5551Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes.Slice(0, count))); + this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } } } diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt index 75f884774..21ed328fa 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt @@ -48,7 +48,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void From<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) { - this.From<#=pixelType#>(configuration, MemoryMarshal.Cast>(sourceBytes).Slice(0, count), destinationPixels.Slice(0, count)); + this.From<#=pixelType#>(configuration, MemoryMarshal.Cast>(sourceBytes).Slice(0, count), destinationPixels); } <# @@ -90,7 +90,7 @@ [MethodImpl(MethodImplOptions.AggressiveInlining)] public void To<#=pixelType#>Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) { - this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast>(destBytes.Slice(0, count))); + this.To<#=pixelType#>(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast>(destBytes)); } <# } From 2fd1aa12cb05b7bd41c180ad089a655f4bfc29af Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 29 Nov 2020 16:27:11 +0100 Subject: [PATCH 4/4] Another attempt using Slice for the destination in PixelOperations convert From and To --- .../Argb32.PixelOperations.Generated.cs | 22 ++++--------------- .../Bgr24.PixelOperations.Generated.cs | 22 ++++--------------- .../Bgra32.PixelOperations.Generated.cs | 22 ++++--------------- .../Bgra5551.PixelOperations.Generated.cs | 21 ++++-------------- .../L16.PixelOperations.Generated.cs | 21 ++++-------------- .../Generated/L8.PixelOperations.Generated.cs | 21 ++++-------------- .../La16.PixelOperations.Generated.cs | 21 ++++-------------- .../La32.PixelOperations.Generated.cs | 21 ++++-------------- .../Rgb24.PixelOperations.Generated.cs | 22 ++++--------------- .../Rgb48.PixelOperations.Generated.cs | 21 ++++-------------- .../Rgba32.PixelOperations.Generated.cs | 21 ++++-------------- .../Rgba64.PixelOperations.Generated.cs | 21 ++++-------------- .../Generated/_Common.ttinclude | 6 ++--- 13 files changed, 51 insertions(+), 211 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs index 9df708d44..cedd1762d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromArgb32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void FromVector4Destructive( Configuration configuration, @@ -59,7 +57,6 @@ namespace SixLabors.ImageSharp.PixelFormats { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToArgb32(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -115,7 +111,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToArgb32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -143,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToArgb32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToArgb32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromArgb32(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToArgb32(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToArgb32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs index a66a6e12c..c98e35656 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromBgr24(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void FromVector4Destructive( Configuration configuration, @@ -59,7 +57,6 @@ namespace SixLabors.ImageSharp.PixelFormats { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgr24(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgr24(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -143,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToBgr24(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -171,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgr24(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgr24(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToBgr24(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToBgr24(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs index 77b665a4c..02bb67532 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromBgra32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void FromVector4Destructive( Configuration configuration, @@ -59,7 +57,6 @@ namespace SixLabors.ImageSharp.PixelFormats { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgra32(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgra32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -143,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgra32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToBgra32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra32(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToBgra32(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToBgra32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs index 1d13722e4..a02ffc3a4 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromBgra5551(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromBgra5551(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToBgra5551(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToBgra5551(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs index 03b84be5d..954ef2d98 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromL16(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL16(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToL16(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToL16(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs index f52e77b1a..b3d809de5 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromL8(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToL16( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromL8(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToL8(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToL8(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs index e01399b8a..14618d026 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromLa16(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa16(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToLa16(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToLa16(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs index 0aa2afef5..9620a1df4 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromLa32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromLa32(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToLa32(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToLa32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs index a9303f9d8..2fe7f3c20 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromRgb24(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void FromVector4Destructive( Configuration configuration, @@ -59,7 +57,6 @@ namespace SixLabors.ImageSharp.PixelFormats { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToRgb24(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgb24(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -143,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgb24(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgb24(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb24(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToRgb24(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToRgb24(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs index 30328366d..031008fe1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromRgb48(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgb48(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToRgb48(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToRgb48(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs index c23198e76..16f96d2da 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromRgba32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -67,7 +65,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgba32(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -95,7 +92,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgba32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -123,7 +119,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToRgba32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -151,7 +146,6 @@ namespace SixLabors.ImageSharp.PixelFormats Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgba32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -172,7 +166,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -193,7 +186,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -214,7 +206,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -235,7 +226,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -256,7 +246,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -277,7 +266,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -298,14 +286,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba32(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToRgba32(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToRgba32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs index 129e9ff0b..1f1571e91 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs @@ -21,14 +21,13 @@ namespace SixLabors.ImageSharp.PixelFormats /// internal partial class PixelOperations : PixelOperations { - - /// + /// public override void FromRgba64(Configuration configuration, ReadOnlySpan source, Span destinationPixels) { Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -37,9 +36,8 @@ namespace SixLabors.ImageSharp.PixelFormats Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } - /// public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -249,7 +238,6 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ namespace SixLabors.ImageSharp.PixelFormats dp.FromRgba64(sp); } } - /// public override void From( Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) { - PixelOperations.Instance.ToRgba64(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.ToRgba64(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index 7c2eccedc..784ecf6fb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -57,7 +57,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; ReadOnlySpan sourcePixels, Span<<#=pixelType#>> destinationPixels) { - PixelOperations.Instance.To<#=pixelType#>(configuration, sourcePixels, destinationPixels); + PixelOperations.Instance.To<#=pixelType#>(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); } <#+ @@ -72,7 +72,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); - source.CopyTo(destinationPixels); + source.CopyTo(destinationPixels.Slice(0, source.Length)); } /// @@ -81,7 +81,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; Guard.NotNull(configuration, nameof(configuration)); Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); - sourcePixels.CopyTo(destinationPixels); + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); } <#+ }