diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 01bdbd1c0b..7819b1ebdb 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -262,7 +262,9 @@ private void Write32Bit(Stream stream, Buffer2D pixels) 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 @@ private void Write24Bit(Stream stream, Buffer2D pixels) 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 @@ private void Write24Bit(Stream stream, Buffer2D pixels) 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 @@ private void Write16Bit(Stream stream, Buffer2D pixels) 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 @@ private void Write8BitColor(Stream stream, ImageFrame image, Spa 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++) { 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 9df708d44d..cedd1762d8 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 @@ public partial struct Argb32 /// 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 @@ public override void ToArgb32(Configuration configuration, ReadOnlySpan 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 @@ public override void ToVector4( { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ public override void FromRgba32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToArgb32(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -115,7 +111,6 @@ public override void FromBgra32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToArgb32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -143,7 +138,6 @@ public override void FromRgb24( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToArgb32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ public override void FromBgr24( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToArgb32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ public override void ToL8( dp.FromArgb32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ public override void ToL16( dp.FromArgb32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ public override void ToLa16( dp.FromArgb32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ public override void ToLa32( dp.FromArgb32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ public override void ToRgb48( dp.FromArgb32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ public override void ToRgba64( dp.FromArgb32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ public override void ToBgra5551( 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 a66a6e12c8..c98e356568 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 @@ public partial struct Bgr24 /// 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 @@ public override void ToBgr24(Configuration configuration, ReadOnlySpan so 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 @@ public override void ToVector4( { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ public override void FromRgba32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgr24(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ public override void FromArgb32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgr24(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -143,7 +138,6 @@ public override void FromBgra32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToBgr24(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -171,7 +165,6 @@ public override void FromRgb24( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgr24(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ public override void ToL8( dp.FromBgr24(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ public override void ToL16( dp.FromBgr24(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ public override void ToLa16( dp.FromBgr24(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ public override void ToLa32( dp.FromBgr24(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ public override void ToRgb48( dp.FromBgr24(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ public override void ToRgba64( dp.FromBgr24(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ public override void ToBgra5551( 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 77b665a4c7..02bb675328 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 @@ public partial struct Bgra32 /// 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 @@ public override void ToBgra32(Configuration configuration, ReadOnlySpan 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 @@ public override void ToVector4( { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ public override void FromRgba32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToBgra32(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ public override void FromArgb32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToBgra32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -143,7 +138,6 @@ public override void FromRgb24( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToBgra32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ public override void FromBgr24( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToBgra32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ public override void ToL8( dp.FromBgra32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ public override void ToL16( dp.FromBgra32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ public override void ToLa16( dp.FromBgra32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ public override void ToLa32( dp.FromBgra32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ public override void ToRgb48( dp.FromBgra32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ public override void ToRgba64( dp.FromBgra32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ public override void ToBgra5551( 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 1d13722e42..a02ffc3a43 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 @@ public partial struct Bgra5551 /// 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 @@ public override void ToBgra5551(Configuration configuration, ReadOnlySpan public override void ToArgb32( Configuration configuration, @@ -60,7 +58,6 @@ public override void ToArgb32( dp.FromBgra5551(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ public override void ToBgr24( dp.FromBgra5551(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ public override void ToBgra32( dp.FromBgra5551(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ public override void ToL8( dp.FromBgra5551(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ public override void ToL16( dp.FromBgra5551(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ public override void ToLa16( dp.FromBgra5551(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ public override void ToLa32( dp.FromBgra5551(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ public override void ToRgb24( dp.FromBgra5551(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ public override void ToRgba32( dp.FromBgra5551(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -249,7 +238,6 @@ public override void ToRgb48( dp.FromBgra5551(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -270,14 +258,13 @@ public override void ToRgba64( 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 03b84be5d7..954ef2d985 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 @@ public partial struct L16 /// 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 @@ public override void ToL16(Configuration configuration, ReadOnlySpan source 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 @@ public override void ToArgb32( dp.FromL16(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ public override void ToBgr24( dp.FromL16(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ public override void ToBgra32( dp.FromL16(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ public override void ToL8( dp.FromL16(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -144,7 +138,6 @@ public override void ToLa16( dp.FromL16(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ public override void ToLa32( dp.FromL16(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ public override void ToRgb24( dp.FromL16(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ public override void ToRgba32( dp.FromL16(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ public override void ToRgb48( dp.FromL16(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ public override void ToRgba64( dp.FromL16(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ public override void ToBgra5551( 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 f52e77b1a3..b3d809de5c 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 @@ public partial struct L8 /// 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 @@ public override void ToL8(Configuration configuration, ReadOnlySpan sourcePi 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 @@ public override void ToArgb32( dp.FromL8(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ public override void ToBgr24( dp.FromL8(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ public override void ToBgra32( dp.FromL8(sp); } } - /// public override void ToL16( Configuration configuration, @@ -123,7 +118,6 @@ public override void ToL16( dp.FromL8(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -144,7 +138,6 @@ public override void ToLa16( dp.FromL8(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ public override void ToLa32( dp.FromL8(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ public override void ToRgb24( dp.FromL8(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ public override void ToRgba32( dp.FromL8(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ public override void ToRgb48( dp.FromL8(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ public override void ToRgba64( dp.FromL8(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ public override void ToBgra5551( 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 e01399b8af..14618d0265 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 @@ public partial struct La16 /// 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 @@ public override void ToLa16(Configuration configuration, ReadOnlySpan sour 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 @@ public override void ToArgb32( dp.FromLa16(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ public override void ToBgr24( dp.FromLa16(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ public override void ToBgra32( dp.FromLa16(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ public override void ToL8( dp.FromLa16(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ public override void ToL16( dp.FromLa16(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -165,7 +158,6 @@ public override void ToLa32( dp.FromLa16(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ public override void ToRgb24( dp.FromLa16(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ public override void ToRgba32( dp.FromLa16(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ public override void ToRgb48( dp.FromLa16(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ public override void ToRgba64( dp.FromLa16(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ public override void ToBgra5551( 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 0aa2afef52..9620a1df4d 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 @@ public partial struct La32 /// 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 @@ public override void ToLa32(Configuration configuration, ReadOnlySpan sour 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 @@ public override void ToArgb32( dp.FromLa32(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ public override void ToBgr24( dp.FromLa32(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ public override void ToBgra32( dp.FromLa32(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ public override void ToL8( dp.FromLa32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ public override void ToL16( dp.FromLa32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ public override void ToLa16( dp.FromLa32(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -186,7 +178,6 @@ public override void ToRgb24( dp.FromLa32(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -207,7 +198,6 @@ public override void ToRgba32( dp.FromLa32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -228,7 +218,6 @@ public override void ToRgb48( dp.FromLa32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ public override void ToRgba64( dp.FromLa32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ public override void ToBgra5551( 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 a9303f9d8a..2fe7f3c20a 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 @@ public partial struct Rgb24 /// 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 @@ public override void ToRgb24(Configuration configuration, ReadOnlySpan so 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 @@ public override void ToVector4( { Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale | PixelConversionModifiers.Premultiply)); } - /// public override void ToRgba32( Configuration configuration, @@ -87,7 +84,6 @@ public override void FromRgba32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgba32.ToRgb24(source, dest); } - /// public override void ToArgb32( Configuration configuration, @@ -115,7 +111,6 @@ public override void FromArgb32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgb24(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -143,7 +138,6 @@ public override void FromBgra32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgb24(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -171,7 +165,6 @@ public override void FromBgr24( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgb24(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -192,7 +185,6 @@ public override void ToL8( dp.FromRgb24(sp); } } - /// public override void ToL16( Configuration configuration, @@ -213,7 +205,6 @@ public override void ToL16( dp.FromRgb24(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -234,7 +225,6 @@ public override void ToLa16( dp.FromRgb24(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -255,7 +245,6 @@ public override void ToLa32( dp.FromRgb24(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -276,7 +265,6 @@ public override void ToRgb48( dp.FromRgb24(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -297,7 +285,6 @@ public override void ToRgba64( dp.FromRgb24(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -318,14 +305,13 @@ public override void ToBgra5551( 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 30328366d8..031008fe1c 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 @@ public partial struct Rgb48 /// 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 @@ public override void ToRgb48(Configuration configuration, ReadOnlySpan so 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 @@ public override void ToArgb32( dp.FromRgb48(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ public override void ToBgr24( dp.FromRgb48(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ public override void ToBgra32( dp.FromRgb48(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ public override void ToL8( dp.FromRgb48(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ public override void ToL16( dp.FromRgb48(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ public override void ToLa16( dp.FromRgb48(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ public override void ToLa32( dp.FromRgb48(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ public override void ToRgb24( dp.FromRgb48(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ public override void ToRgba32( dp.FromRgb48(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -249,7 +238,6 @@ public override void ToRgba64( dp.FromRgb48(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ public override void ToBgra5551( 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 c23198e760..16f96d2da1 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 @@ public partial struct Rgba32 /// 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 @@ public override void ToRgba32(Configuration configuration, ReadOnlySpan 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 @@ public override void FromArgb32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromArgb32.ToRgba32(source, dest); } - /// public override void ToBgra32( Configuration configuration, @@ -95,7 +92,6 @@ public override void FromBgra32( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgra32.ToRgba32(source, dest); } - /// public override void ToRgb24( Configuration configuration, @@ -123,7 +119,6 @@ public override void FromRgb24( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromRgb24.ToRgba32(source, dest); } - /// public override void ToBgr24( Configuration configuration, @@ -151,7 +146,6 @@ public override void FromBgr24( Span dest = MemoryMarshal.Cast(destinationPixels); PixelConverter.FromBgr24.ToRgba32(source, dest); } - /// public override void ToL8( Configuration configuration, @@ -172,7 +166,6 @@ public override void ToL8( dp.FromRgba32(sp); } } - /// public override void ToL16( Configuration configuration, @@ -193,7 +186,6 @@ public override void ToL16( dp.FromRgba32(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -214,7 +206,6 @@ public override void ToLa16( dp.FromRgba32(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -235,7 +226,6 @@ public override void ToLa32( dp.FromRgba32(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -256,7 +246,6 @@ public override void ToRgb48( dp.FromRgba32(sp); } } - /// public override void ToRgba64( Configuration configuration, @@ -277,7 +266,6 @@ public override void ToRgba64( dp.FromRgba32(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -298,14 +286,13 @@ public override void ToBgra5551( 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 129e9ff0b5..1f1571e91d 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 @@ public partial struct Rgba64 /// 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 @@ public override void ToRgba64(Configuration configuration, ReadOnlySpan 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 @@ public override void ToArgb32( dp.FromRgba64(sp); } } - /// public override void ToBgr24( Configuration configuration, @@ -81,7 +78,6 @@ public override void ToBgr24( dp.FromRgba64(sp); } } - /// public override void ToBgra32( Configuration configuration, @@ -102,7 +98,6 @@ public override void ToBgra32( dp.FromRgba64(sp); } } - /// public override void ToL8( Configuration configuration, @@ -123,7 +118,6 @@ public override void ToL8( dp.FromRgba64(sp); } } - /// public override void ToL16( Configuration configuration, @@ -144,7 +138,6 @@ public override void ToL16( dp.FromRgba64(sp); } } - /// public override void ToLa16( Configuration configuration, @@ -165,7 +158,6 @@ public override void ToLa16( dp.FromRgba64(sp); } } - /// public override void ToLa32( Configuration configuration, @@ -186,7 +178,6 @@ public override void ToLa32( dp.FromRgba64(sp); } } - /// public override void ToRgb24( Configuration configuration, @@ -207,7 +198,6 @@ public override void ToRgb24( dp.FromRgba64(sp); } } - /// public override void ToRgba32( Configuration configuration, @@ -228,7 +218,6 @@ public override void ToRgba32( dp.FromRgba64(sp); } } - /// public override void ToRgb48( Configuration configuration, @@ -249,7 +238,6 @@ public override void ToRgb48( dp.FromRgba64(sp); } } - /// public override void ToBgra5551( Configuration configuration, @@ -270,14 +258,13 @@ public override void ToBgra5551( 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 7c2eccedcc..784ecf6fb8 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)); } <#+ }