From c6f9050a5e06abdf815699f2f33885f71859b0dc Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Sat, 4 Dec 2021 20:55:41 +0100 Subject: [PATCH 01/10] Initial Abgr32 pixel format implementation --- shared-infrastructure | 2 +- src/ImageSharp/Advanced/AotCompilerTools.cs | 2 + src/ImageSharp/Color/Color.Conversions.cs | 24 ++ .../Helpers/Shuffle/IComponentShuffle.cs | 70 ++++ src/ImageSharp/ImageSharp.csproj | 9 + src/ImageSharp/PixelFormats/IPixel.cs | 6 + .../PixelFormats/PixelImplementations/A8.cs | 4 + .../PixelImplementations/Abgr32.cs | 394 ++++++++++++++++++ .../PixelImplementations/Argb32.cs | 10 + .../PixelImplementations/Bgr24.cs | 9 + .../PixelImplementations/Bgr565.cs | 4 + .../PixelImplementations/Bgra32.cs | 10 + .../PixelImplementations/Bgra4444.cs | 4 + .../PixelImplementations/Bgra5551.cs | 4 + .../PixelImplementations/Byte4.cs | 4 + .../PixelImplementations/HalfSingle.cs | 4 + .../PixelImplementations/HalfVector2.cs | 4 + .../PixelImplementations/HalfVector4.cs | 4 + .../PixelFormats/PixelImplementations/L16.cs | 7 + .../PixelFormats/PixelImplementations/L8.cs | 4 + .../PixelFormats/PixelImplementations/La16.cs | 8 + .../PixelFormats/PixelImplementations/La32.cs | 12 + .../PixelImplementations/NormalizedByte2.cs | 4 + .../PixelImplementations/NormalizedByte4.cs | 4 + .../PixelImplementations/NormalizedShort2.cs | 4 + .../PixelImplementations/NormalizedShort4.cs | 4 + .../PixelOperations/Abgr32.PixelOperations.cs | 26 ++ .../Abgr32.PixelOperations.Generated.cs | 346 +++++++++++++++ .../Abgr32.PixelOperations.Generated.tt | 18 + .../Generated/_Common.ttinclude | 3 + .../PixelFormats/PixelImplementations/Rg32.cs | 4 + .../PixelImplementations/Rgb24.cs | 9 + .../PixelImplementations/Rgb48.cs | 9 + .../PixelImplementations/Rgba1010102.cs | 4 + .../PixelImplementations/Rgba32.cs | 10 + .../PixelImplementations/Rgba64.cs | 37 ++ .../PixelImplementations/RgbaVector.cs | 4 + .../PixelImplementations/Short2.cs | 4 + .../PixelImplementations/Short4.cs | 4 + .../PixelOperations{TPixel}.Generated.cs | 72 ++++ .../PixelOperations{TPixel}.Generated.tt | 3 + .../PixelFormats/Utils/PixelConverter.cs | 125 +++++- .../Color/ColorTests.CastFrom.cs | 13 + .../Color/ColorTests.CastTo.cs | 13 + .../Color/ColorTests.ConstructFrom.cs | 13 + .../ImageSharp.Tests/Image/ImageCloneTests.cs | 26 ++ .../PixelFormats/Abgr32Tests.cs | 148 +++++++ .../PixelFormats/Bgra32Tests.cs | 11 +- ...ConverterTests.ReferenceImplementations.cs | 15 + .../PixelFormats/PixelConverterTests.cs | 59 +++ ...elOperationsTests.Specialized.Generated.cs | 47 +-- .../Generated/_Common.ttinclude | 2 + .../PixelOperations/PixelOperationsTests.cs | 45 ++ .../PixelFormats/Rgba32Tests.cs | 16 + .../PixelFormats/Rgba64Tests.cs | 24 ++ .../PixelFormats/Short4Tests.cs | 18 + tests/ImageSharp.Tests/TestFormat.cs | 4 + .../TestUtilities/PixelTypes.cs | 2 + .../Tests/TestUtilityExtensionsTests.cs | 5 +- 59 files changed, 1717 insertions(+), 37 deletions(-) create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs create mode 100644 src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.tt create mode 100644 tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs diff --git a/shared-infrastructure b/shared-infrastructure index 59ce17f5a4..a042aba176 160000 --- a/shared-infrastructure +++ b/shared-infrastructure @@ -1 +1 @@ -Subproject commit 59ce17f5a4e1f956811133f41add7638e74c2836 +Subproject commit a042aba176cdb840d800c6ed4cfe41a54fb7b1e3 diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index b90a6ce3cd..f5714fa5e7 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -74,6 +74,7 @@ private static void SeedPixelFormats() Seed(); Seed(); + Seed(); Seed(); Seed(); Seed(); @@ -148,6 +149,7 @@ private static unsafe void AotCompileImage() Image img = default; img.CloneAs(default); img.CloneAs(default); + img.CloneAs(default); img.CloneAs(default); img.CloneAs(default); img.CloneAs(default); diff --git a/src/ImageSharp/Color/Color.Conversions.cs b/src/ImageSharp/Color/Color.Conversions.cs index bf7869e53d..5c10bfaa09 100644 --- a/src/ImageSharp/Color/Color.Conversions.cs +++ b/src/ImageSharp/Color/Color.Conversions.cs @@ -89,6 +89,17 @@ public Color(Bgra32 pixel) this.boxedHighPrecisionPixel = null; } + /// + /// Initializes a new instance of the struct. + /// + /// The containing the color information. + [MethodImpl(InliningOptions.ShortMethod)] + public Color(Abgr32 pixel) + { + this.data = new Rgba64(pixel); + this.boxedHighPrecisionPixel = null; + } + /// /// Initializes a new instance of the struct. /// @@ -177,6 +188,19 @@ internal Argb32 ToArgb32() return value; } + [MethodImpl(InliningOptions.ShortMethod)] + internal Abgr32 ToAbgr32() + { + if (this.boxedHighPrecisionPixel is null) + { + return this.data.ToAbgr32(); + } + + Abgr32 value = default; + value.FromScaledVector4(this.boxedHighPrecisionPixel.ToScaledVector4()); + return value; + } + [MethodImpl(InliningOptions.ShortMethod)] internal Rgb24 ToRgb24() { diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 929b786921..8d1236ee99 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -194,4 +194,74 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) } } } + + internal readonly struct XWZYShuffle4 : IShuffle4 + { + public byte Control + { + [MethodImpl(InliningOptions.ShortMethod)] + get => SimdUtils.Shuffle.MmShuffle(1, 2, 3, 0); + } + + [MethodImpl(InliningOptions.ShortMethod)] + public void RunFallbackShuffle(ReadOnlySpan source, Span dest) + { + ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); + ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); + int n = source.Length / 4; + + for (int i = 0; i < n; i++) + { + uint packed = Unsafe.Add(ref sBase, i); + + // packed = [W Z Y X] + // tmp1 = [0 Z 0 X] + // tmp2 = [W 0 Y 0] + // tmp3=ROTL(16, tmp2) = [Y 0 W 0] + // tmp1 + tmp3 = [Y Z W X] + uint tmp1 = packed & 0xFF00FF00; + uint tmp2 = packed & 0x00FF00FF; + uint tmp3 = (tmp2 << 16) | (tmp2 >> 16); + + Unsafe.Add(ref dBase, i) = tmp1 + tmp3; + } + } + } + + internal readonly struct XZWYShuffle4 : IShuffle4 + { + public byte Control + { + [MethodImpl(InliningOptions.ShortMethod)] + get => SimdUtils.Shuffle.MmShuffle(1, 3, 2, 0); + } + + [MethodImpl(InliningOptions.ShortMethod)] + public void RunFallbackShuffle(ReadOnlySpan source, Span dest) + { + ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); + ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); + int n = source.Length / 4; + + for (int i = 0; i < n; i++) + { + uint packed = Unsafe.Add(ref sBase, i); + + // packed = [W Z Y X] + // tmp1 = [0 0 0 X] + // tmp2 = [W Z 0 0] + // tmp3 = [0 0 Y 0] + // tmp4=ROTR(8, tmp2) = [0 W Z 0] + // tmp5=ROTL(16, tmp3) = [Y 0 0 0] + // tmp1+ tmp3 + tmp4 = [Y W Z X] + uint tmp1 = packed & 0x000000FF; + uint tmp2 = packed & 0xFFFF0000; + uint tmp3 = packed & 0x0000FF00; + uint tmp4 = tmp2 >> 8; + uint tmp5 = tmp3 << 16; + + Unsafe.Add(ref dBase, i) = tmp1 + tmp4 + tmp5; + } + } + } } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index f90e40edb5..b138f8d5e1 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -75,6 +75,11 @@ True Block8x8F.Generated.tt + + True + True + Abgr32.PixelOperations.Generated.tt + True True @@ -166,6 +171,10 @@ TextTemplatingFileGenerator Block8x8F.Generated.cs + + TextTemplatingFileGenerator + Abgr32.PixelOperations.Generated.cs + TextTemplatingFileGenerator PixelOperations{TPixel}.Generated.cs diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs index 12b5bc7848..09f8cc9555 100644 --- a/src/ImageSharp/PixelFormats/IPixel.cs +++ b/src/ImageSharp/PixelFormats/IPixel.cs @@ -79,6 +79,12 @@ public interface IPixel /// The value. void FromBgra32(Bgra32 source); + /// + /// Initializes the pixel instance from an value. + /// + /// The value. + void FromAbgr32(Abgr32 source); + /// /// Initializes the pixel instance from an value. /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs index cca7ff7db9..afb07433f3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs @@ -87,6 +87,10 @@ public partial struct A8 : IPixel, IPackedVector [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.PackedValue = source.A; + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.PackedValue = source.A; + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs new file mode 100644 index 0000000000..157ac2a83f --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs @@ -0,0 +1,394 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. + /// The color components are stored in alpha, red, green, and blue order (least significant to most significant byte). + /// + /// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form. + /// + /// + /// + /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, + /// as it avoids the need to create new values for modification operations. + /// + [StructLayout(LayoutKind.Sequential)] + public partial struct Abgr32 : IPixel, IPackedVector + { + /// + /// Gets or sets the alpha component. + /// + public byte A; + + /// + /// Gets or sets the blue component. + /// + public byte B; + + /// + /// Gets or sets the green component. + /// + public byte G; + + /// + /// Gets or sets the red component. + /// + public byte R; + + /// + /// The maximum byte value. + /// + private static readonly Vector4 MaxBytes = new(255); + + /// + /// The half vector value. + /// + private static readonly Vector4 Half = new(0.5F); + + /// + /// Initializes a new instance of the struct. + /// + /// The red component. + /// The green component. + /// The blue component. + [MethodImpl(InliningOptions.ShortMethod)] + public Abgr32(byte r, byte g, byte b) + { + this.R = r; + this.G = g; + this.B = b; + this.A = byte.MaxValue; + } + + /// + /// Initializes a new instance of the struct. + /// + /// The red component. + /// The green component. + /// The blue component. + /// The alpha component. + [MethodImpl(InliningOptions.ShortMethod)] + public Abgr32(byte r, byte g, byte b, byte a) + { + this.R = r; + this.G = g; + this.B = b; + this.A = a; + } + + /// + /// Initializes a new instance of the struct. + /// + /// The red component. + /// The green component. + /// The blue component. + /// The alpha component. + [MethodImpl(InliningOptions.ShortMethod)] + public Abgr32(float r, float g, float b, float a = 1) + : this() => this.Pack(r, g, b, a); + + /// + /// Initializes a new instance of the struct. + /// + /// + /// The vector containing the components for the packed vector. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public Abgr32(Vector3 vector) + : this() => this.Pack(ref vector); + + /// + /// Initializes a new instance of the struct. + /// + /// + /// The vector containing the components for the packed vector. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public Abgr32(Vector4 vector) + : this() => this.Pack(ref vector); + + /// + /// Initializes a new instance of the struct. + /// + /// + /// The packed value. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public Abgr32(uint packed) + : this() => this.Abgr = packed; + + /// + /// Gets or sets the packed representation of the Abgrb32 struct. + /// + public uint Abgr + { + [MethodImpl(InliningOptions.ShortMethod)] + readonly get => Unsafe.As(ref Unsafe.AsRef(this)); + + [MethodImpl(InliningOptions.ShortMethod)] + set => Unsafe.As(ref this) = value; + } + + /// + public uint PackedValue + { + [MethodImpl(InliningOptions.ShortMethod)] + readonly get => this.Abgr; + + [MethodImpl(InliningOptions.ShortMethod)] + set => this.Abgr = value; + } + + /// + /// Converts an to . + /// + /// The . + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public static implicit operator Color(Abgr32 source) => new(source); + + /// + /// Converts a to . + /// + /// The . + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public static implicit operator Abgr32(Color color) => color.ToAbgr32(); + + /// + /// Compares two objects for equality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the parameter is equal to the parameter; otherwise, false. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static bool operator ==(Abgr32 left, Abgr32 right) => left.Equals(right); + + /// + /// Compares two objects for equality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the parameter is not equal to the parameter; otherwise, false. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static bool operator !=(Abgr32 left, Abgr32 right) => !left.Equals(right); + + /// + public readonly PixelOperations CreatePixelOperations() => new PixelOperations(); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public readonly Vector4 ToScaledVector4() => this.ToVector4(); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromVector4(Vector4 vector) => this.Pack(ref vector); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public readonly Vector4 ToVector4() => new Vector4(this.R, this.G, this.B, this.A) / MaxBytes; + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.PackedValue = source.PackedValue; + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromBgr24(Bgr24 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = byte.MaxValue; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromArgb32(Argb32 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = source.A; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromBgra32(Bgra32 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = source.A; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromL8(L8 source) + { + this.R = source.PackedValue; + this.G = source.PackedValue; + this.B = source.PackedValue; + this.A = byte.MaxValue; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromL16(L16 source) + { + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.PackedValue); + this.R = rgb; + this.G = rgb; + this.B = rgb; + this.A = byte.MaxValue; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromLa16(La16 source) + { + this.R = source.L; + this.G = source.L; + this.B = source.L; + this.A = source.A; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromLa32(La32 source) + { + byte rgb = ColorNumerics.DownScaleFrom16BitTo8Bit(source.L); + this.R = rgb; + this.G = rgb; + this.B = rgb; + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromRgb24(Rgb24 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = byte.MaxValue; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromRgba32(Rgba32 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = source.A; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void ToRgba32(ref Rgba32 dest) + { + dest.R = this.R; + dest.G = this.G; + dest.B = this.B; + dest.A = this.A; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromRgb48(Rgb48 source) + { + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); + this.A = byte.MaxValue; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromRgba64(Rgba64 source) + { + this.R = ColorNumerics.DownScaleFrom16BitTo8Bit(source.R); + this.G = ColorNumerics.DownScaleFrom16BitTo8Bit(source.G); + this.B = ColorNumerics.DownScaleFrom16BitTo8Bit(source.B); + this.A = ColorNumerics.DownScaleFrom16BitTo8Bit(source.A); + } + + /// + public override readonly bool Equals(object obj) => obj is Abgr32 abgr32 && this.Equals(abgr32); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public readonly bool Equals(Abgr32 other) => this.Abgr == other.Abgr; + + /// + /// Gets a string representation of the packed vector. + /// + /// A string representation of the packed vector. + public override readonly string ToString() => $"Abgr({this.A}, {this.B}, {this.G}, {this.R})"; + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public override readonly int GetHashCode() => this.Abgr.GetHashCode(); + + /// + /// Packs the four floats into a color. + /// + /// The x-component + /// The y-component + /// The z-component + /// The w-component + [MethodImpl(InliningOptions.ShortMethod)] + private void Pack(float x, float y, float z, float w) + { + var value = new Vector4(x, y, z, w); + this.Pack(ref value); + } + + /// + /// Packs a into a uint. + /// + /// The vector containing the values to pack. + [MethodImpl(InliningOptions.ShortMethod)] + private void Pack(ref Vector3 vector) + { + var value = new Vector4(vector, 1); + this.Pack(ref value); + } + + /// + /// Packs a into a color. + /// + /// The vector containing the values to pack. + [MethodImpl(InliningOptions.ShortMethod)] + private void Pack(ref Vector4 vector) + { + vector *= MaxBytes; + vector += Half; + vector = Numerics.Clamp(vector, Vector4.Zero, MaxBytes); + + this.R = (byte)vector.X; + this.G = (byte)vector.Y; + this.B = (byte)vector.Z; + this.A = (byte)vector.W; + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs index 8c1b04ff1f..2ec85de93c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs @@ -230,6 +230,16 @@ public void FromBgra32(Bgra32 source) this.A = source.A; } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = source.A; + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs index 22e983a654..882306928d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs @@ -185,6 +185,15 @@ public void FromRgb24(Rgb24 source) this.B = source.B; } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) => this = source.Bgr; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs index 5585310b91..bd21d04252 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs @@ -99,6 +99,10 @@ public void FromVector4(Vector4 vector) [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromVector4(source.ToVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromVector4(source.ToVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs index be4e178c24..34769e32d2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs @@ -165,6 +165,16 @@ public void FromArgb32(Argb32 source) this.A = source.A; } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = source.A; + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs index 3578f1dd38..059d611367 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs @@ -102,6 +102,10 @@ public readonly Vector4 ToVector4() [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs index 0254397c3f..b6cc1f878a 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs @@ -124,6 +124,10 @@ public Bgra5551(float x, float y, float z, float w) [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs index 0995f8417f..e1ed4577ef 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs @@ -124,6 +124,10 @@ public Byte4(float x, float y, float z, float w) [MethodImpl(InliningOptions.ShortMethod)] public void FromRgba32(Rgba32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs index b0ef0f6a9b..51b6af640e 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs @@ -88,6 +88,10 @@ public readonly Vector4 ToScaledVector4() [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs index 8be8261302..1fff37757d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs @@ -99,6 +99,10 @@ public readonly Vector4 ToVector4() [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs index 955b274acb..94051e263e 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs @@ -104,6 +104,10 @@ public readonly Vector4 ToScaledVector4() [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs index 6d1128dd2c..c40e301de7 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs @@ -91,6 +91,13 @@ public void FromBgra32(Bgra32 source) => this.PackedValue = ColorNumerics.Get16B ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.PackedValue = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs index ffff60be52..70d031aa1d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs @@ -83,6 +83,10 @@ public readonly Vector4 ToVector4() [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.PackedValue = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs index 877aaed81c..72f188fa3e 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs @@ -112,6 +112,14 @@ public void FromBgra32(Bgra32 source) this.A = source.A; } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.L = ColorNumerics.Get8BitBT709Luminance(source.R, source.G, source.B); + this.A = source.A; + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs index f19f228136..d9104aa4fa 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs @@ -127,6 +127,18 @@ public void FromBgra32(Bgra32 source) this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.L = ColorNumerics.Get16BitBT709Luminance( + ColorNumerics.UpscaleFrom8BitTo16Bit(source.R), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.G), + ColorNumerics.UpscaleFrom8BitTo16Bit(source.B)); + + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs index 62eaf949d1..78c83a5436 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs @@ -107,6 +107,10 @@ public void FromVector4(Vector4 vector) [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs index 2e81b3e2dc..432461f75d 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs @@ -109,6 +109,10 @@ public readonly Vector4 ToScaledVector4() [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs index b97aaacec8..60fe2368a8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs @@ -108,6 +108,10 @@ public void FromVector4(Vector4 vector) [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs index f2e8aedd8f..01b9777b08 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs @@ -110,6 +110,10 @@ public readonly Vector4 ToScaledVector4() [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs new file mode 100644 index 0000000000..439c5529ac --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Formats; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Abgr32 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + private static readonly Lazy LazyInfo = + new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true); + + /// + public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value; + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs new file mode 100644 index 0000000000..6386d315ca --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs @@ -0,0 +1,346 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +// + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.PixelFormats.Utils; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Abgr32 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + /// + public override void FromAbgr32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); + + source.CopyTo(destinationPixels.Slice(0, source.Length)); + } + + /// + public override void ToAbgr32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + sourcePixels.CopyTo(destinationPixels.Slice(0, sourcePixels.Length)); + } + /// + public override void FromVector4Destructive( + Configuration configuration, + Span sourceVectors, + Span destinationPixels, + PixelConversionModifiers modifiers) + { + Vector4Converters.RgbaCompatible.FromVector4(configuration, this, sourceVectors, destinationPixels, modifiers.Remove(PixelConversionModifiers.Scale)); + } + + /// + public override void ToVector4( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destVectors, + PixelConversionModifiers modifiers) + { + Vector4Converters.RgbaCompatible.ToVector4(configuration, this, sourcePixels, destVectors, modifiers.Remove(PixelConversionModifiers.Scale)); + } + /// + public override void ToRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToRgba32(source, dest); + } + + /// + public override void FromRgba32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromRgba32.ToAbgr32(source, dest); + } + /// + public override void ToArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToArgb32(source, dest); + } + + /// + public override void FromArgb32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromArgb32.ToAbgr32(source, dest); + } + /// + public override void ToBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToBgra32(source, dest); + } + + /// + public override void FromBgra32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromBgra32.ToAbgr32(source, dest); + } + /// + public override void ToRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToRgb24(source, dest); + } + + /// + public override void FromRgb24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromRgb24.ToAbgr32(source, dest); + } + /// + public override void ToBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToBgr24(source, dest); + } + + /// + public override void FromBgr24( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromBgr24.ToAbgr32(source, dest); + } + /// + public override void ToL8( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromAbgr32(sp); + } + } + /// + public override void ToL16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromAbgr32(sp); + } + } + /// + public override void ToLa16( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromAbgr32(sp); + } + } + /// + public override void ToLa32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromAbgr32(sp); + } + } + /// + public override void ToRgb48( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromAbgr32(sp); + } + } + /// + public override void ToRgba64( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromAbgr32(sp); + } + } + /// + public override void ToBgra5551( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromAbgr32(sp); + } + } + /// + public override void From( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + PixelOperations.Instance.ToAbgr32(configuration, sourcePixels, destinationPixels.Slice(0, sourcePixels.Length)); + } + + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.tt b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.tt new file mode 100644 index 0000000000..071c74fbb4 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.tt @@ -0,0 +1,18 @@ +<#@include file="_Common.ttinclude" #> +<#@ output extension=".cs" #> +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Abgr32 + { + /// + /// Provides optimized overrides for bulk operations. + /// + internal partial class PixelOperations : PixelOperations + { + <# GenerateAllDefaultConversionMethods("Abgr32"); #> + } + } +} diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index 784ecf6fb8..b6b0a14a70 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -17,6 +17,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; private static readonly string[] CommonPixelTypes = { "Argb32", + "Abgr32", "Bgr24", "Bgra32", "L8", @@ -34,6 +35,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; { "Rgba32", "Argb32", + "Abgr32", "Bgra32", "Rgb24", "Bgr24" @@ -43,6 +45,7 @@ using SixLabors.ImageSharp.PixelFormats.Utils; private static readonly string[] Rgba32CompatibleTypes = { "Argb32", + "Abgr32", "Bgra32", "Rgb24", "Bgr24" diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs index 12b6e153f9..d408f301ba 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs @@ -93,6 +93,10 @@ public void FromVector4(Vector4 vector) [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs index 3b5bdb3d5a..00f0722689 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs @@ -153,6 +153,15 @@ public void FromBgra32(Bgra32 source) this.B = source.B; } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromL8(L8 source) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs index d16b7db7ac..90c15ae267 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs @@ -186,6 +186,15 @@ public void FromRgba32(Rgba32 source) this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void ToRgba32(ref Rgba32 dest) diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs index e687260187..11e11bc6c9 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs @@ -96,6 +96,10 @@ public Rgba1010102(float x, float y, float z, float w) [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs index 3dc6490f1b..2d250f71dc 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs @@ -333,6 +333,16 @@ public void FromBgra32(Bgra32 source) this.A = source.A; } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = source.A; + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs index 4cfa0bf974..bf7452592c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs @@ -94,6 +94,19 @@ public Rgba64(Argb32 source) this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } + /// + /// Initializes a new instance of the struct. + /// + /// A structure of 4 bytes in ABGR byte order. + [MethodImpl(InliningOptions.ShortMethod)] + public Rgba64(Abgr32 source) + { + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); + } + /// /// Initializes a new instance of the struct. /// @@ -250,6 +263,16 @@ public void FromBgra32(Bgra32 source) this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); } + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) + { + this.R = ColorNumerics.UpscaleFrom8BitTo16Bit(source.R); + this.G = ColorNumerics.UpscaleFrom8BitTo16Bit(source.G); + this.B = ColorNumerics.UpscaleFrom8BitTo16Bit(source.B); + this.A = ColorNumerics.UpscaleFrom8BitTo16Bit(source.A); + } + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); @@ -380,6 +403,20 @@ public readonly Argb32 ToArgb32() return new Argb32(r, g, b, a); } + /// + /// Convert to . + /// + /// The . + [MethodImpl(InliningOptions.ShortMethod)] + public readonly Abgr32 ToAbgr32() + { + byte r = ColorNumerics.DownScaleFrom16BitTo8Bit(this.R); + byte g = ColorNumerics.DownScaleFrom16BitTo8Bit(this.G); + byte b = ColorNumerics.DownScaleFrom16BitTo8Bit(this.B); + byte a = ColorNumerics.DownScaleFrom16BitTo8Bit(this.A); + return new Abgr32(r, g, b, a); + } + /// /// Convert to . /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs index cd6f53c4ed..e582e61664 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs @@ -134,6 +134,10 @@ public void FromVector4(Vector4 vector) [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs index 24f6b4d1d4..f0117707c6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs @@ -111,6 +111,10 @@ public void FromVector4(Vector4 vector) [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs index 86a519297b..fd58477d93 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs @@ -116,6 +116,10 @@ public readonly Vector4 ToVector4() [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4()); + /// [MethodImpl(InliningOptions.ShortMethod)] public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4()); diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs index cc36c7d134..ea107b35a4 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs @@ -82,6 +82,78 @@ public void ToArgb32Bytes(Configuration configuration, ReadOnlySpan sour this.ToArgb32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); } + /// + /// Converts all pixels in 'source` span of into a span of -s. + /// + /// A to configure internal operations. + /// The source of data. + /// The to the destination pixels. + public virtual void FromAbgr32(Configuration configuration, ReadOnlySpan source, Span destinationPixels) + { + Guard.DestinationShouldNotBeTooShort(source, destinationPixels, nameof(destinationPixels)); + + ref Abgr32 sourceBaseRef = ref MemoryMarshal.GetReference(source); + ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < source.Length; i++) + { + ref Abgr32 sp = ref Unsafe.Add(ref sourceBaseRef, i); + ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i); + + dp.FromAbgr32(sp); + } + } + + /// + /// A helper for that expects a byte span. + /// The layout of the data in 'sourceBytes' must be compatible with layout. + /// + /// A to configure internal operations. + /// The to the source bytes. + /// The to the destination pixels. + /// The number of pixels to convert. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void FromAbgr32Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destinationPixels, int count) + { + this.FromAbgr32(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destinationPixels); + } + + /// + /// Converts all pixels of the 'sourcePixels` span to a span of -s. + /// + /// A to configure internal operations + /// The span of source pixels + /// The destination span of data. + public virtual void ToAbgr32(Configuration configuration, ReadOnlySpan sourcePixels, Span destinationPixels) + { + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Abgr32 destBaseRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destBaseRef, i); + + dp.FromScaledVector4(sp.ToScaledVector4()); + } + } + + /// + /// A helper for that expects a byte span as destination. + /// The layout of the data in 'destBytes' must be compatible with layout. + /// + /// A to configure internal operations + /// The to the source pixels. + /// The to the destination bytes. + /// The number of pixels to convert. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void ToAbgr32Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count) + { + this.ToAbgr32(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes)); + } + /// /// Converts all pixels in 'source` span of into a span of -s. /// diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt index 21ed328fac..e8cf6f9a52 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt @@ -112,6 +112,9 @@ namespace SixLabors.ImageSharp.PixelFormats GenerateFromMethods("Argb32"); GenerateToDestFormatMethods("Argb32"); + GenerateFromMethods("Abgr32"); + GenerateToDestFormatMethods("Abgr32"); + GenerateFromMethods("Bgr24"); GenerateToDestFormatMethods("Bgr24"); diff --git a/src/ImageSharp/PixelFormats/Utils/PixelConverter.cs b/src/ImageSharp/PixelFormats/Utils/PixelConverter.cs index 7215fa860b..907399d5f2 100644 --- a/src/ImageSharp/PixelFormats/Utils/PixelConverter.cs +++ b/src/ImageSharp/PixelFormats/Utils/PixelConverter.cs @@ -18,8 +18,13 @@ namespace SixLabors.ImageSharp.PixelFormats.Utils /// internal static class PixelConverter { + /// + /// Optimized converters from . + /// public static class FromRgba32 { + // Input pixels have: X = R, Y = G, Z = B and W = A. + /// /// Converts a representing a collection of /// pixels to a representing @@ -38,6 +43,15 @@ public static void ToArgb32(ReadOnlySpan source, Span dest) public static void ToBgra32(ReadOnlySpan source, Span dest) => SimdUtils.Shuffle4(source, dest, default); + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToAbgr32(ReadOnlySpan source, Span dest) + => SimdUtils.Shuffle4(source, dest, default); + /// /// Converts a representing a collection of /// pixels to a representing @@ -57,8 +71,13 @@ public static void ToBgr24(ReadOnlySpan source, Span dest) => SimdUtils.Shuffle4Slice3(source, dest, new DefaultShuffle4Slice3(3, 0, 1, 2)); } + /// + /// Optimized converters from . + /// public static class FromArgb32 { + // Input pixels have: X = A, Y = R, Z = G and W = B. + /// /// Converts a representing a collection of /// pixels to a representing @@ -77,6 +96,15 @@ public static void ToRgba32(ReadOnlySpan source, Span dest) public static void ToBgra32(ReadOnlySpan source, Span dest) => SimdUtils.Shuffle4(source, dest, default); + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToAbgr32(ReadOnlySpan source, Span dest) + => SimdUtils.Shuffle4(source, dest, default); + /// /// Converts a representing a collection of /// pixels to a representing @@ -96,8 +124,13 @@ public static void ToBgr24(ReadOnlySpan source, Span dest) => SimdUtils.Shuffle4Slice3(source, dest, new DefaultShuffle4Slice3(0, 1, 2, 3)); } + /// + /// Optimized converters from . + /// public static class FromBgra32 { + // Input pixels have: X = B, Y = G, Z = R and W = A. + /// /// Converts a representing a collection of /// pixels to a representing @@ -110,12 +143,21 @@ public static void ToArgb32(ReadOnlySpan source, Span dest) /// /// Converts a representing a collection of /// pixels to a representing - /// a collection of pixels. + /// a collection of pixels. /// [MethodImpl(InliningOptions.ShortMethod)] public static void ToRgba32(ReadOnlySpan source, Span dest) => SimdUtils.Shuffle4(source, dest, default); + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToAbgr32(ReadOnlySpan source, Span dest) + => SimdUtils.Shuffle4(source, dest, default); + /// /// Converts a representing a collection of /// pixels to a representing @@ -135,8 +177,66 @@ public static void ToBgr24(ReadOnlySpan source, Span dest) => SimdUtils.Shuffle4Slice3(source, dest, default); } + /// + /// Optimized converters from . + /// + public static class FromAbgr32 + { + // Input pixels have: X = A, Y = B, Z = G and W = R. + + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToArgb32(ReadOnlySpan source, Span dest) + => SimdUtils.Shuffle4(source, dest, default); + + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToRgba32(ReadOnlySpan source, Span dest) + => SimdUtils.Shuffle4(source, dest, default); + + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToBgra32(ReadOnlySpan source, Span dest) + => SimdUtils.Shuffle4(source, dest, default); + + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToRgb24(ReadOnlySpan source, Span dest) + => SimdUtils.Shuffle4Slice3(source, dest, new DefaultShuffle4Slice3(0, 1, 2, 3)); + + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToBgr24(ReadOnlySpan source, Span dest) + => SimdUtils.Shuffle4Slice3(source, dest, new DefaultShuffle4Slice3(0, 3, 2, 1)); + } + + /// + /// Optimized converters from . + /// public static class FromRgb24 { + // Input pixels have: X = R, Y = G and Z = B. + /// /// Converts a representing a collection of /// pixels to a representing @@ -164,6 +264,15 @@ public static void ToArgb32(ReadOnlySpan source, Span dest) public static void ToBgra32(ReadOnlySpan source, Span dest) => SimdUtils.Pad3Shuffle4(source, dest, new DefaultPad3Shuffle4(3, 0, 1, 2)); + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToAbgr32(ReadOnlySpan source, Span dest) + => SimdUtils.Pad3Shuffle4(source, dest, new DefaultPad3Shuffle4(0, 1, 2, 3)); + /// /// Converts a representing a collection of /// pixels to a representing @@ -174,8 +283,13 @@ public static void ToBgr24(ReadOnlySpan source, Span dest) => SimdUtils.Shuffle3(source, dest, new DefaultShuffle3(0, 1, 2)); } + /// + /// Optimized converters from . + /// public static class FromBgr24 { + // Input pixels have: X = B, Y = G and Z = R. + /// /// Converts a representing a collection of /// pixels to a representing @@ -203,6 +317,15 @@ public static void ToRgba32(ReadOnlySpan source, Span dest) public static void ToBgra32(ReadOnlySpan source, Span dest) => SimdUtils.Pad3Shuffle4(source, dest, default); + /// + /// Converts a representing a collection of + /// pixels to a representing + /// a collection of pixels. + /// + [MethodImpl(InliningOptions.ShortMethod)] + public static void ToAbgr32(ReadOnlySpan source, Span dest) + => SimdUtils.Pad3Shuffle4(source, dest, new DefaultPad3Shuffle4(2, 1, 0, 3)); + /// /// Converts a representing a collection of /// pixels to a representing diff --git a/tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs b/tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs index 38b94f486c..ec03847dfb 100644 --- a/tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs +++ b/tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs @@ -63,6 +63,19 @@ public void Bgra32() Assert.Equal(source, data); } + [Fact] + public void Abgr32() + { + var source = new Abgr32(1, 22, 33, 231); + + // Act: + Color color = source; + + // Assert: + Abgr32 data = color.ToPixel(); + Assert.Equal(source, data); + } + [Fact] public void Rgb24() { diff --git a/tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs b/tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs index bfc290c2e5..1997cc6b19 100644 --- a/tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs +++ b/tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs @@ -64,6 +64,19 @@ public void Bgra32() Assert.Equal(source, data); } + [Fact] + public void Abgr32() + { + var source = new Abgr32(1, 22, 33, 231); + + // Act: + var color = new Color(source); + + // Assert: + Abgr32 data = color; + Assert.Equal(source, data); + } + [Fact] public void Rgb24() { diff --git a/tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs b/tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs index 89276014b0..d61361c808 100644 --- a/tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs +++ b/tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs @@ -63,6 +63,19 @@ public void Bgra32() Assert.Equal(source, data); } + [Fact] + public void Abgr32() + { + var source = new Abgr32(1, 22, 33, 231); + + // Act: + var color = new Color(source); + + // Assert: + Abgr32 data = color.ToPixel(); + Assert.Equal(source, data); + } + [Fact] public void Rgb24() { diff --git a/tests/ImageSharp.Tests/Image/ImageCloneTests.cs b/tests/ImageSharp.Tests/Image/ImageCloneTests.cs index f602643341..c1012e2df2 100644 --- a/tests/ImageSharp.Tests/Image/ImageCloneTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageCloneTests.cs @@ -56,6 +56,32 @@ public void CloneAs_ToBgra32(TestImageProvider provider) }); } + [Theory] + [WithTestPatternImages(9, 9, PixelTypes.Rgba32)] + public void CloneAs_ToAbgr32(TestImageProvider provider) + { + using (Image image = provider.GetImage()) + using (Image clone = image.CloneAs()) + { + for (int y = 0; y < image.Height; y++) + { + Span row = image.GetPixelRowSpan(y); + Span rowClone = clone.GetPixelRowSpan(y); + + for (int x = 0; x < image.Width; x++) + { + Rgba32 expected = row[x]; + Abgr32 actual = rowClone[x]; + + Assert.Equal(expected.R, actual.R); + Assert.Equal(expected.G, actual.G); + Assert.Equal(expected.B, actual.B); + Assert.Equal(expected.A, actual.A); + } + } + } + } + [Theory] [WithTestPatternImages(9, 9, PixelTypes.Rgba32)] public void CloneAs_ToBgr24(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs new file mode 100644 index 0000000000..278de33579 --- /dev/null +++ b/tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs @@ -0,0 +1,148 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System.Numerics; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.PixelFormats +{ + [Trait("Category", "PixelFormats")] + public class Abgr32Tests + { + /// + /// Tests the equality operators for equality. + /// + [Fact] + public void AreEqual() + { + var color1 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); + var color2 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue); + + Assert.Equal(color1, color2); + } + + /// + /// Tests the equality operators for inequality. + /// + [Fact] + public void AreNotEqual() + { + var color1 = new Abgr32(0, 0, byte.MaxValue, byte.MaxValue); + var color2 = new Abgr32(byte.MaxValue, byte.MaxValue, byte.MaxValue); + + Assert.NotEqual(color1, color2); + } + + public static readonly TheoryData ColorData = + new() + { + { 1, 2, 3, 4 }, + { 4, 5, 6, 7 }, + { 0, 255, 42, 0 }, + { 1, 2, 3, 255 } + }; + + [Theory] + [MemberData(nameof(ColorData))] + public void Constructor(byte b, byte g, byte r, byte a) + { + var p = new Abgr32(r, g, b, a); + + Assert.Equal(r, p.R); + Assert.Equal(g, p.G); + Assert.Equal(b, p.B); + Assert.Equal(a, p.A); + } + + [Fact] + public unsafe void ByteLayoutIsSequentialBgra() + { + var color = new Abgr32(1, 2, 3, 4); + byte* ptr = (byte*)&color; + + Assert.Equal(4, ptr[0]); + Assert.Equal(3, ptr[1]); + Assert.Equal(2, ptr[2]); + Assert.Equal(1, ptr[3]); + } + + [Theory] + [MemberData(nameof(ColorData))] + public void Equality_WhenTrue(byte r, byte g, byte b, byte a) + { + var x = new Abgr32(r, g, b, a); + var y = new Abgr32(r, g, b, a); + + Assert.True(x.Equals(y)); + Assert.True(x.Equals((object)y)); + Assert.Equal(x.GetHashCode(), y.GetHashCode()); + } + + [Theory] + [InlineData(1, 2, 3, 4, 1, 2, 3, 5)] + [InlineData(0, 0, 255, 0, 0, 0, 244, 0)] + [InlineData(0, 255, 0, 0, 0, 244, 0, 0)] + [InlineData(1, 255, 0, 0, 0, 255, 0, 0)] + public void Equality_WhenFalse(byte b1, byte g1, byte r1, byte a1, byte b2, byte g2, byte r2, byte a2) + { + var x = new Abgr32(r1, g1, b1, a1); + var y = new Abgr32(r2, g2, b2, a2); + + Assert.False(x.Equals(y)); + Assert.False(x.Equals((object)y)); + } + + [Fact] + public void FromRgba32() + { + var abgr = default(Abgr32); + abgr.FromRgba32(new Rgba32(1, 2, 3, 4)); + + Assert.Equal(1, abgr.R); + Assert.Equal(2, abgr.G); + Assert.Equal(3, abgr.B); + Assert.Equal(4, abgr.A); + } + + private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new Vector4( + r / 255f, + g / 255f, + b / 255f, + a / 255f); + + [Fact] + public void FromVector4() + { + var c = default(Abgr32); + c.FromVector4(Vec(1, 2, 3, 4)); + + Assert.Equal(1, c.R); + Assert.Equal(2, c.G); + Assert.Equal(3, c.B); + Assert.Equal(4, c.A); + } + + [Fact] + public void ToVector4() + { + var abgr = new Abgr32(1, 2, 3, 4); + + Assert.Equal(Vec(1, 2, 3, 4), abgr.ToVector4()); + } + + [Fact] + public void Abgr32_FromBgra5551() + { + // arrange + var abgr = default(Abgr32); + uint expected = uint.MaxValue; + + // act + abgr.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f)); + + // assert + Assert.Equal(expected, abgr.PackedValue); + } + } +} diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs index 4b8f4c2eaf..7a2f29e2cb 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs @@ -96,12 +96,13 @@ public void Equality_WhenFalse(byte b1, byte g1, byte r1, byte a1, byte b2, byte [Fact] public void FromRgba32() { - var rgb = default(Rgb24); - rgb.FromRgba32(new Rgba32(1, 2, 3, 4)); + var bgra = default(Bgra32); + bgra.FromRgba32(new Rgba32(1, 2, 3, 4)); - Assert.Equal(1, rgb.R); - Assert.Equal(2, rgb.G); - Assert.Equal(3, rgb.B); + Assert.Equal(1, bgra.R); + Assert.Equal(2, bgra.G); + Assert.Equal(3, bgra.B); + Assert.Equal(4, bgra.A); } private static Vector4 Vec(byte r, byte g, byte b, byte a = 255) => new Vector4( diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs index 8b3483145c..e51ee233c8 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.ReferenceImplementations.cs @@ -60,6 +60,21 @@ public static byte[] MakeBgra32ByteArray(byte r, byte g, byte b, byte a) return buffer; } + public static byte[] MakeAbgr32ByteArray(byte r, byte g, byte b, byte a) + { + var buffer = new byte[256]; + + for (int i = 0; i < buffer.Length; i += 4) + { + buffer[i] = a; + buffer[i + 1] = b; + buffer[i + 2] = g; + buffer[i + 3] = r; + } + + return buffer; + } + internal static void To( Configuration configuration, ReadOnlySpan sourcePixels, diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs index 315f9f7761..986f4189b4 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelConverterTests.cs @@ -56,6 +56,20 @@ public void ToBgra32(byte r, byte g, byte b, byte a) Assert.Equal(expected, actual); } + + [Theory] + [MemberData(nameof(RgbaData))] + public void ToAbgr32(byte r, byte g, byte b, byte a) + { + byte[] source = ReferenceImplementations.MakeRgba32ByteArray(r, g, b, a); + byte[] actual = new byte[source.Length]; + + PixelConverter.FromRgba32.ToAbgr32(source, actual); + + byte[] expected = ReferenceImplementations.MakeAbgr32ByteArray(r, g, b, a); + + Assert.Equal(expected, actual); + } } public class FromArgb32 : PixelConverterTests @@ -119,5 +133,50 @@ public void ToRgba32(byte r, byte g, byte b, byte a) Assert.Equal(expected, actual); } } + + public class FromAbgr32 : PixelConverterTests + { + [Theory] + [MemberData(nameof(RgbaData))] + public void ToArgb32(byte r, byte g, byte b, byte a) + { + byte[] source = ReferenceImplementations.MakeAbgr32ByteArray(r, g, b, a); + byte[] actual = new byte[source.Length]; + + PixelConverter.FromAbgr32.ToArgb32(source, actual); + + byte[] expected = ReferenceImplementations.MakeArgb32ByteArray(r, g, b, a); + + Assert.Equal(expected, actual); + } + + [Theory] + [MemberData(nameof(RgbaData))] + public void ToRgba32(byte r, byte g, byte b, byte a) + { + byte[] source = ReferenceImplementations.MakeAbgr32ByteArray(r, g, b, a); + byte[] actual = new byte[source.Length]; + + PixelConverter.FromAbgr32.ToRgba32(source, actual); + + byte[] expected = ReferenceImplementations.MakeRgba32ByteArray(r, g, b, a); + + Assert.Equal(expected, actual); + } + + [Theory] + [MemberData(nameof(RgbaData))] + public void ToBgra32(byte r, byte g, byte b, byte a) + { + byte[] source = ReferenceImplementations.MakeAbgr32ByteArray(r, g, b, a); + byte[] actual = new byte[source.Length]; + + PixelConverter.FromAbgr32.ToBgra32(source, actual); + + byte[] expected = ReferenceImplementations.MakeBgra32ByteArray(r, g, b, a); + + Assert.Equal(expected, actual); + } + } } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs index 1069eb9aca..10b06df3bb 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/PixelOperationsTests.Specialized.Generated.cs @@ -12,8 +12,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations { public partial class PixelOperationsTests { - - public partial class A8_OperationsTests : PixelOperationsTests + public partial class A8_OperationsTests : PixelOperationsTests { public A8_OperationsTests(ITestOutputHelper output) : base(output) @@ -32,7 +31,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class Argb32_OperationsTests : PixelOperationsTests { public Argb32_OperationsTests(ITestOutputHelper output) @@ -52,7 +50,25 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } + public partial class Abgr32_OperationsTests : PixelOperationsTests + { + public Abgr32_OperationsTests(ITestOutputHelper output) + : base(output) + { + } + protected override PixelOperations Operations => Abgr32.PixelOperations.Instance; + + [Fact] + public void IsSpecialImplementation() => Assert.IsType(PixelOperations.Instance); + + [Fact] + public void PixelTypeInfoHasCorrectAlphaRepresentation() + { + var alphaRepresentation = this.Operations.GetPixelTypeInfo().AlphaRepresentation; + Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); + } + } public partial class Bgr24_OperationsTests : PixelOperationsTests { public Bgr24_OperationsTests(ITestOutputHelper output) @@ -72,7 +88,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class Bgr565_OperationsTests : PixelOperationsTests { public Bgr565_OperationsTests(ITestOutputHelper output) @@ -92,7 +107,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class Bgra32_OperationsTests : PixelOperationsTests { public Bgra32_OperationsTests(ITestOutputHelper output) @@ -112,7 +126,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class Bgra4444_OperationsTests : PixelOperationsTests { public Bgra4444_OperationsTests(ITestOutputHelper output) @@ -132,7 +145,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class Bgra5551_OperationsTests : PixelOperationsTests { public Bgra5551_OperationsTests(ITestOutputHelper output) @@ -152,7 +164,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class Byte4_OperationsTests : PixelOperationsTests { public Byte4_OperationsTests(ITestOutputHelper output) @@ -172,7 +183,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class HalfSingle_OperationsTests : PixelOperationsTests { public HalfSingle_OperationsTests(ITestOutputHelper output) @@ -192,7 +202,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class HalfVector2_OperationsTests : PixelOperationsTests { public HalfVector2_OperationsTests(ITestOutputHelper output) @@ -212,7 +221,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class HalfVector4_OperationsTests : PixelOperationsTests { public HalfVector4_OperationsTests(ITestOutputHelper output) @@ -232,7 +240,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class L16_OperationsTests : PixelOperationsTests { public L16_OperationsTests(ITestOutputHelper output) @@ -252,7 +259,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class L8_OperationsTests : PixelOperationsTests { public L8_OperationsTests(ITestOutputHelper output) @@ -272,7 +278,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class La16_OperationsTests : PixelOperationsTests { public La16_OperationsTests(ITestOutputHelper output) @@ -292,7 +297,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class La32_OperationsTests : PixelOperationsTests { public La32_OperationsTests(ITestOutputHelper output) @@ -312,7 +316,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class NormalizedByte2_OperationsTests : PixelOperationsTests { public NormalizedByte2_OperationsTests(ITestOutputHelper output) @@ -332,7 +335,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class NormalizedByte4_OperationsTests : PixelOperationsTests { public NormalizedByte4_OperationsTests(ITestOutputHelper output) @@ -352,7 +354,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class NormalizedShort2_OperationsTests : PixelOperationsTests { public NormalizedShort2_OperationsTests(ITestOutputHelper output) @@ -372,7 +373,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class NormalizedShort4_OperationsTests : PixelOperationsTests { public NormalizedShort4_OperationsTests(ITestOutputHelper output) @@ -392,7 +392,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class Rg32_OperationsTests : PixelOperationsTests { public Rg32_OperationsTests(ITestOutputHelper output) @@ -412,7 +411,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class Rgb24_OperationsTests : PixelOperationsTests { public Rgb24_OperationsTests(ITestOutputHelper output) @@ -432,7 +430,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class Rgb48_OperationsTests : PixelOperationsTests { public Rgb48_OperationsTests(ITestOutputHelper output) @@ -452,7 +449,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class Rgba1010102_OperationsTests : PixelOperationsTests { public Rgba1010102_OperationsTests(ITestOutputHelper output) @@ -472,7 +468,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class Rgba32_OperationsTests : PixelOperationsTests { public Rgba32_OperationsTests(ITestOutputHelper output) @@ -492,7 +487,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class Rgba64_OperationsTests : PixelOperationsTests { public Rgba64_OperationsTests(ITestOutputHelper output) @@ -512,7 +506,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class RgbaVector_OperationsTests : PixelOperationsTests { public RgbaVector_OperationsTests(ITestOutputHelper output) @@ -532,7 +525,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.Unassociated, alphaRepresentation); } } - public partial class Short2_OperationsTests : PixelOperationsTests { public Short2_OperationsTests(ITestOutputHelper output) @@ -552,7 +544,6 @@ public void PixelTypeInfoHasCorrectAlphaRepresentation() Assert.Equal(PixelAlphaRepresentation.None, alphaRepresentation); } } - public partial class Short4_OperationsTests : PixelOperationsTests { public Short4_OperationsTests(ITestOutputHelper output) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude index 8c436eecca..6ef3e914f0 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/Generated/_Common.ttinclude @@ -16,6 +16,7 @@ using Xunit.Abstractions; { "A8", "Argb32", + "Abgr32", "Bgra32", "Bgra4444", "Bgra5551", @@ -38,6 +39,7 @@ using Xunit.Abstractions; { "A8", "Argb32", + "Abgr32", "Bgr24", "Bgr565", "Bgra32", diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs index a2688359f1..2a89c1d39d 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs @@ -322,6 +322,7 @@ public void ToVector4(int count) public static readonly TheoryData Generic_To_Data = new TheoryData { + new TestPixel(), new TestPixel(), new TestPixel(), new TestPixel(), @@ -586,6 +587,50 @@ public void ToBgra32Bytes(int count) (s, d) => this.Operations.ToBgra32Bytes(this.Configuration, s, d.GetSpan(), count)); } + [Theory] + [MemberData(nameof(ArraySizesData))] + public void FromAbgr32Bytes(int count) + { + byte[] source = CreateByteTestData(count * 4); + var expected = new TPixel[count]; + + for (int i = 0; i < count; i++) + { + int i4 = i * 4; + + expected[i].FromAbgr32(new Abgr32(source[i4 + 3], source[i4 + 2], source[i4 + 1], source[i4 + 0])); + } + + TestOperation( + source, + expected, + (s, d) => this.Operations.FromAbgr32Bytes(this.Configuration, s, d.GetSpan(), count)); + } + + [Theory] + [MemberData(nameof(ArraySizesData))] + public void ToAbgr32Bytes(int count) + { + TPixel[] source = CreatePixelTestData(count); + byte[] expected = new byte[count * 4]; + var abgr = default(Abgr32); + + for (int i = 0; i < count; i++) + { + int i4 = i * 4; + abgr.FromScaledVector4(source[i].ToScaledVector4()); + expected[i4] = abgr.A; + expected[i4 + 1] = abgr.B; + expected[i4 + 2] = abgr.G; + expected[i4 + 3] = abgr.R; + } + + TestOperation( + source, + expected, + (s, d) => this.Operations.ToAbgr32Bytes(this.Configuration, s, d.GetSpan(), count)); + } + [Theory] [MemberData(nameof(ArraySizesData))] public void FromBgra5551Bytes(int count) diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs index bc66d404b6..aff16d6d8f 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs @@ -230,6 +230,22 @@ public void Rgba32_FromBgra32_ToRgba32() Assert.Equal(expected, actual); } + [Fact] + public void Rgba32_FromAbgr32_ToRgba32() + { + // arrange + var rgba = default(Rgba32); + var actual = default(Abgr32); + var expected = new Abgr32(0x1a, 0, 0x80, 0); + + // act + rgba.FromAbgr32(expected); + actual.FromRgba32(rgba); + + // assert + Assert.Equal(expected, actual); + } + [Fact] public void Rgba32_FromArgb32_ToArgb32() { diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs index 8daf960d6e..e08cd29503 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs @@ -183,6 +183,16 @@ public void ConstructFrom_Argb32() Assert.Equal(expected, actual); } + [Fact] + public void ConstructFrom_Abgr32() + { + var expected = new Rgba64(5140, 9766, 19532, 29555); + var source = new Abgr32(20, 38, 76, 115); + var actual = new Rgba64(source); + + Assert.Equal(expected, actual); + } + [Fact] public void ConstructFrom_Rgb24() { @@ -257,6 +267,20 @@ public void ToArgb32_Retval() Assert.Equal(expected, actual); } + [Fact] + public void ToAbgr32_Retval() + { + // arrange + var source = new Rgba64(5140, 9766, 19532, 29555); + var expected = new Abgr32(20, 38, 76, 115); + + // act + var actual = source.ToAbgr32(); + + // assert + Assert.Equal(expected, actual); + } + [Fact] public void ToRgb24_Retval() { diff --git a/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs index 3709205ac4..a95ac9ab98 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs @@ -150,6 +150,24 @@ public void Short4_FromArgb32_ToRgba32() Assert.Equal(expected, actual); } + [Fact] + public void Short4_FromAbgrb32_ToRgba32() + { + // arrange + var short4 = default(Short4); + var actual = default(Abgr32); + var expected = new Abgr32(20, 38, 0, 255); + + // act + short4.FromAbgr32(expected); + Rgba32 temp = default; + short4.ToRgba32(ref temp); + actual.FromRgba32(temp); + + // assert + Assert.Equal(expected, actual); + } + [Fact] public void Short4_FromRgb48_ToRgb48() { diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs index c8d0633d7e..6c2b97eb62 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -310,6 +310,10 @@ public void FromBgra32(Bgra32 source) { } + public void FromAbgr32(Abgr32 source) + { + } + public void FromL8(L8 source) { } diff --git a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs index eb840231c0..8ba383125c 100644 --- a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs +++ b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs @@ -69,6 +69,8 @@ public enum PixelTypes La32 = 1 << 26, + Abgr32 = 1 << 27, + // TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper // "All" is handled as a separate, individual case instead of using bitwise OR diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index bb9ed8260d..1a46f91e59 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -112,14 +112,15 @@ public void ExpandAllTypes_1() [Fact] public void ExpandAllTypes_2() { - PixelTypes pixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector; + PixelTypes pixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Abgr32 | PixelTypes.RgbaVector; IEnumerable> expanded = pixelTypes.ExpandAllTypes(); - Assert.Equal(3, expanded.Count()); + Assert.Equal(4, expanded.Count()); AssertContainsPixelType(PixelTypes.Rgba32, expanded); AssertContainsPixelType(PixelTypes.Bgra32, expanded); + AssertContainsPixelType(PixelTypes.Abgr32, expanded); AssertContainsPixelType(PixelTypes.RgbaVector, expanded); } From 98e44174293bbc0718e4cbdeca7039a2ea4b105c Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Mon, 6 Dec 2021 22:23:17 +0100 Subject: [PATCH 02/10] Fix pixel conversion tests --- .../Helpers/Shuffle/IComponentShuffle.cs | 4 +-- .../PixelImplementations/Abgr32.cs | 2 +- .../Argb32.PixelOperations.Generated.cs | 27 +++++++++++++++++++ .../Bgr24.PixelOperations.Generated.cs | 27 +++++++++++++++++++ .../Bgra32.PixelOperations.Generated.cs | 27 +++++++++++++++++++ .../Bgra5551.PixelOperations.Generated.cs | 20 ++++++++++++++ .../L16.PixelOperations.Generated.cs | 20 ++++++++++++++ .../Generated/L8.PixelOperations.Generated.cs | 20 ++++++++++++++ .../La16.PixelOperations.Generated.cs | 20 ++++++++++++++ .../La32.PixelOperations.Generated.cs | 20 ++++++++++++++ .../Rgb24.PixelOperations.Generated.cs | 27 +++++++++++++++++++ .../Rgb48.PixelOperations.Generated.cs | 20 ++++++++++++++ .../Rgba32.PixelOperations.Generated.cs | 27 +++++++++++++++++++ .../Rgba64.PixelOperations.Generated.cs | 20 ++++++++++++++ 14 files changed, 278 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 8d1236ee99..2fc2b44304 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -219,8 +219,8 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) // tmp2 = [W 0 Y 0] // tmp3=ROTL(16, tmp2) = [Y 0 W 0] // tmp1 + tmp3 = [Y Z W X] - uint tmp1 = packed & 0xFF00FF00; - uint tmp2 = packed & 0x00FF00FF; + uint tmp1 = packed & 0x00FF00FF; + uint tmp2 = packed & 0xFF00FF00; uint tmp3 = (tmp2 << 16) | (tmp2 >> 16); Unsafe.Add(ref dBase, i) = tmp1 + tmp3; diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs index 157ac2a83f..0a95fc1fff 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs @@ -204,7 +204,7 @@ public uint PackedValue /// [MethodImpl(InliningOptions.ShortMethod)] - public void FromAbgr32(Abgr32 source) => this.PackedValue = source.PackedValue; + public void FromAbgr32(Abgr32 source) => this = source; /// [MethodImpl(InliningOptions.ShortMethod)] 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 cedd1762d8..0f183df0d0 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -85,6 +85,33 @@ public override void FromRgba32( PixelConverter.FromRgba32.ToArgb32(source, dest); } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromArgb32.ToAbgr32(source, dest); + } + + /// + public override void FromAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToArgb32(source, dest); + } + /// public override void ToBgra32( Configuration configuration, ReadOnlySpan sourcePixels, 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 c98e356568..ea08c6391b 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -112,6 +112,33 @@ public override void FromArgb32( PixelConverter.FromArgb32.ToBgr24(source, dest); } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromBgr24.ToAbgr32(source, dest); + } + + /// + public override void FromAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToBgr24(source, dest); + } + /// public override void ToBgra32( Configuration configuration, ReadOnlySpan sourcePixels, 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 02bb675328..0ec9a552cc 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -112,6 +112,33 @@ public override void FromArgb32( PixelConverter.FromArgb32.ToBgra32(source, dest); } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromBgra32.ToAbgr32(source, dest); + } + + /// + public override void FromAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToBgra32(source, dest); + } + /// public override void ToRgb24( Configuration configuration, ReadOnlySpan sourcePixels, 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 a02ffc3a43..877ce1a6fb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -59,6 +59,26 @@ public override void ToArgb32( } } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromBgra5551(sp); + } + } + /// public override void ToBgr24( Configuration configuration, ReadOnlySpan sourcePixels, 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 954ef2d985..94eb3229bd 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -59,6 +59,26 @@ public override void ToArgb32( } } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromL16(sp); + } + } + /// public override void ToBgr24( Configuration configuration, ReadOnlySpan sourcePixels, 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 b3d809de5c..a748590f74 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -59,6 +59,26 @@ public override void ToArgb32( } } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromL8(sp); + } + } + /// public override void ToBgr24( Configuration configuration, ReadOnlySpan sourcePixels, 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 14618d0265..f47cd6c401 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -59,6 +59,26 @@ public override void ToArgb32( } } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromLa16(sp); + } + } + /// public override void ToBgr24( Configuration configuration, ReadOnlySpan sourcePixels, 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 9620a1df4d..f0c2c33232 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs @@ -59,6 +59,26 @@ public override void ToArgb32( } } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromLa32(sp); + } + } + /// public override void ToBgr24( Configuration configuration, ReadOnlySpan sourcePixels, 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 2fe7f3c20a..75f677cdd3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -112,6 +112,33 @@ public override void FromArgb32( PixelConverter.FromArgb32.ToRgb24(source, dest); } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromRgb24.ToAbgr32(source, dest); + } + + /// + public override void FromAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToRgb24(source, dest); + } + /// public override void ToBgra32( Configuration configuration, ReadOnlySpan sourcePixels, 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 031008fe1c..22b96fd5a8 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -59,6 +59,26 @@ public override void ToArgb32( } } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromRgb48(sp); + } + } + /// public override void ToBgr24( Configuration configuration, ReadOnlySpan sourcePixels, 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 16f96d2da1..093182c82e 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs @@ -66,6 +66,33 @@ public override void FromArgb32( PixelConverter.FromArgb32.ToRgba32(source, dest); } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromRgba32.ToAbgr32(source, dest); + } + + /// + public override void FromAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ReadOnlySpan source = MemoryMarshal.Cast(sourcePixels); + Span dest = MemoryMarshal.Cast(destinationPixels); + PixelConverter.FromAbgr32.ToRgba32(source, dest); + } + /// public override void ToBgra32( Configuration configuration, ReadOnlySpan sourcePixels, 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 1f1571e91d..ce1b53e664 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs @@ -59,6 +59,26 @@ public override void ToArgb32( } } /// + public override void ToAbgr32( + Configuration configuration, + ReadOnlySpan sourcePixels, + Span destinationPixels) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.DestinationShouldNotBeTooShort(sourcePixels, destinationPixels, nameof(destinationPixels)); + + ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); + ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); + + for (int i = 0; i < sourcePixels.Length; i++) + { + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + + dp.FromRgba64(sp); + } + } + /// public override void ToBgr24( Configuration configuration, ReadOnlySpan sourcePixels, From a8d3cebde8690896a1919df4fac585ad48360dd8 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Mon, 6 Dec 2021 22:31:23 +0100 Subject: [PATCH 03/10] Remove dead code from IComponentShuffle --- .../Helpers/Shuffle/IComponentShuffle.cs | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 2fc2b44304..4c02deb2d3 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -227,41 +227,4 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) } } } - - internal readonly struct XZWYShuffle4 : IShuffle4 - { - public byte Control - { - [MethodImpl(InliningOptions.ShortMethod)] - get => SimdUtils.Shuffle.MmShuffle(1, 3, 2, 0); - } - - [MethodImpl(InliningOptions.ShortMethod)] - public void RunFallbackShuffle(ReadOnlySpan source, Span dest) - { - ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); - ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; - - for (int i = 0; i < n; i++) - { - uint packed = Unsafe.Add(ref sBase, i); - - // packed = [W Z Y X] - // tmp1 = [0 0 0 X] - // tmp2 = [W Z 0 0] - // tmp3 = [0 0 Y 0] - // tmp4=ROTR(8, tmp2) = [0 W Z 0] - // tmp5=ROTL(16, tmp3) = [Y 0 0 0] - // tmp1+ tmp3 + tmp4 = [Y W Z X] - uint tmp1 = packed & 0x000000FF; - uint tmp2 = packed & 0xFFFF0000; - uint tmp3 = packed & 0x0000FF00; - uint tmp4 = tmp2 >> 8; - uint tmp5 = tmp3 << 16; - - Unsafe.Add(ref dBase, i) = tmp1 + tmp4 + tmp5; - } - } - } } From 296e412f3fe0ff9adc364d6139d45bb3f4d375f7 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Fri, 10 Dec 2021 16:57:05 +0100 Subject: [PATCH 04/10] Fixes after rebasing to latest master --- .gitattributes | 8 ++------ tests/ImageSharp.Tests/Image/ImageCloneTests.cs | 17 +++++++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.gitattributes b/.gitattributes index 355b64dce1..70ced69033 100644 --- a/.gitattributes +++ b/.gitattributes @@ -87,6 +87,7 @@ *.eot binary *.exe binary *.otf binary +*.pbm binary *.pdf binary *.ppt binary *.pptx binary @@ -94,6 +95,7 @@ *.snk binary *.ttc binary *.ttf binary +*.wbmp binary *.woff binary *.woff2 binary *.xls binary @@ -124,9 +126,3 @@ *.dds filter=lfs diff=lfs merge=lfs -text *.ktx filter=lfs diff=lfs merge=lfs -text *.ktx2 filter=lfs diff=lfs merge=lfs -text -*.pam filter=lfs diff=lfs merge=lfs -text -*.pbm filter=lfs diff=lfs merge=lfs -text -*.pgm filter=lfs diff=lfs merge=lfs -text -*.ppm filter=lfs diff=lfs merge=lfs -text -*.pnm filter=lfs diff=lfs merge=lfs -text -*.wbmp filter=lfs diff=lfs merge=lfs -text diff --git a/tests/ImageSharp.Tests/Image/ImageCloneTests.cs b/tests/ImageSharp.Tests/Image/ImageCloneTests.cs index c1012e2df2..9d978ee527 100644 --- a/tests/ImageSharp.Tests/Image/ImageCloneTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageCloneTests.cs @@ -60,15 +60,17 @@ public void CloneAs_ToBgra32(TestImageProvider provider) [WithTestPatternImages(9, 9, PixelTypes.Rgba32)] public void CloneAs_ToAbgr32(TestImageProvider provider) { - using (Image image = provider.GetImage()) - using (Image clone = image.CloneAs()) + using Image image = provider.GetImage(); + using Image clone = image.CloneAs(); + + image.ProcessPixelRows(clone, static (imageAccessor, cloneAccessor) => { - for (int y = 0; y < image.Height; y++) + for (int y = 0; y < imageAccessor.Height; y++) { - Span row = image.GetPixelRowSpan(y); - Span rowClone = clone.GetPixelRowSpan(y); + Span row = imageAccessor.GetRowSpan(y); + Span rowClone = cloneAccessor.GetRowSpan(y); - for (int x = 0; x < image.Width; x++) + for (int x = 0; x < cloneAccessor.Width; x++) { Rgba32 expected = row[x]; Abgr32 actual = rowClone[x]; @@ -76,10 +78,9 @@ public void CloneAs_ToAbgr32(TestImageProvider provider) Assert.Equal(expected.R, actual.R); Assert.Equal(expected.G, actual.G); Assert.Equal(expected.B, actual.B); - Assert.Equal(expected.A, actual.A); } } - } + }); } [Theory] From f7fc4c6c027c7748d392a62cd7300f91d9b1f975 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Sat, 11 Dec 2021 15:45:24 +0100 Subject: [PATCH 05/10] Use native integers as loop counters --- .../Common/Helpers/BitOperations.cs | 26 +++++++ .../Helpers/Shuffle/IComponentShuffle.cs | 46 ++++++------ .../PixelImplementations/Abgr32.cs | 8 ++- .../PixelImplementations/Bgr24.cs | 7 +- .../Abgr32.PixelOperations.Generated.cs | 42 +++++------ .../Argb32.PixelOperations.Generated.cs | 42 +++++------ .../Bgr24.PixelOperations.Generated.cs | 42 +++++------ .../Bgra32.PixelOperations.Generated.cs | 42 +++++------ .../Bgra5551.PixelOperations.Generated.cs | 72 +++++++++---------- .../L16.PixelOperations.Generated.cs | 72 +++++++++---------- .../Generated/L8.PixelOperations.Generated.cs | 72 +++++++++---------- .../La16.PixelOperations.Generated.cs | 72 +++++++++---------- .../La32.PixelOperations.Generated.cs | 72 +++++++++---------- .../Rgb24.PixelOperations.Generated.cs | 42 +++++------ .../Rgb48.PixelOperations.Generated.cs | 72 +++++++++---------- .../Rgba32.PixelOperations.Generated.cs | 42 +++++------ .../Rgba64.PixelOperations.Generated.cs | 72 +++++++++---------- .../Generated/_Common.ttinclude | 6 +- 18 files changed, 440 insertions(+), 409 deletions(-) create mode 100644 src/ImageSharp/Common/Helpers/BitOperations.cs diff --git a/src/ImageSharp/Common/Helpers/BitOperations.cs b/src/ImageSharp/Common/Helpers/BitOperations.cs new file mode 100644 index 0000000000..b4b6c890c4 --- /dev/null +++ b/src/ImageSharp/Common/Helpers/BitOperations.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using System.Runtime.CompilerServices; + +#if !NETCOREAPP3_1 +namespace SixLabors.ImageSharp.Common.Helpers +{ + /// + /// Polyfill for System.Numerics.BitOperations class, introduced in .NET Core 3.0. + /// + /// + public static class BitOperations + { + /// + /// Rotates the specified value left by the specified number of bits. + /// + /// The value to rotate. + /// The number of bits to roate with. + /// The rotated value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint RotateLeft(uint value, int offset) + => (value << offset) | (value >> (32 - offset)); + } +} +#endif diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 4c02deb2d3..89bac8e103 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -3,8 +3,10 @@ using System; using System.Buffers.Binary; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using SixLabors.ImageSharp.Common.Helpers; // The JIT can detect and optimize rotation idioms ROTL (Rotate Left) // and ROTR (Rotate Right) emitting efficient CPU instructions: @@ -97,15 +99,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (int i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (int)i); // packed = [W Z Y X] // ROTL(8, packed) = [Z Y X W] - Unsafe.Add(ref dBase, i) = (packed << 8) | (packed >> 24); + Unsafe.Add(ref dBase, (int)i) = (packed << 8) | (packed >> 24); } } } @@ -123,15 +125,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (int i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (int)i); // packed = [W Z Y X] // REVERSE(packedArgb) = [X Y Z W] - Unsafe.Add(ref dBase, i) = BinaryPrimitives.ReverseEndianness(packed); + Unsafe.Add(ref dBase, (int)i) = BinaryPrimitives.ReverseEndianness(packed); } } } @@ -149,15 +151,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (int i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (int)i); // packed = [W Z Y X] // ROTR(8, packedArgb) = [Y Z W X] - Unsafe.Add(ref dBase, i) = (packed >> 8) | (packed << 24); + Unsafe.Add(ref dBase, (int)i) = (packed >> 8) | (packed << 24); } } } @@ -175,11 +177,11 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (int i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (int)i); // packed = [W Z Y X] // tmp1 = [W 0 Y 0] @@ -188,9 +190,9 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) // tmp1 + tmp3 = [W X Y Z] uint tmp1 = packed & 0xFF00FF00; uint tmp2 = packed & 0x00FF00FF; - uint tmp3 = (tmp2 << 16) | (tmp2 >> 16); + uint tmp3 = BitOperations.RotateLeft(tmp2, 16); - Unsafe.Add(ref dBase, i) = tmp1 + tmp3; + Unsafe.Add(ref dBase, (int)i) = tmp1 + tmp3; } } } @@ -208,11 +210,11 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - int n = source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (int i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (int)i); // packed = [W Z Y X] // tmp1 = [0 Z 0 X] @@ -221,9 +223,9 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) // tmp1 + tmp3 = [Y Z W X] uint tmp1 = packed & 0x00FF00FF; uint tmp2 = packed & 0xFF00FF00; - uint tmp3 = (tmp2 << 16) | (tmp2 >> 16); + uint tmp3 = BitOperations.RotateLeft(tmp2, 16); - Unsafe.Add(ref dBase, i) = tmp1 + tmp3; + Unsafe.Add(ref dBase, (int)i) = tmp1 + tmp3; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs index 0a95fc1fff..ca8f5c1444 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Apache License, Version 2.0. +using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -214,9 +215,10 @@ public uint PackedValue [MethodImpl(InliningOptions.ShortMethod)] public void FromBgr24(Bgr24 source) { - this.R = source.R; - this.G = source.G; - this.B = source.B; + // We can assign the Bgr24 value directly to last three bytes of this instance. + ref byte thisRef = ref Unsafe.As(ref this); + ref byte thisRefFromB = ref Unsafe.AddByteOffset(ref thisRef, new IntPtr(1)); + Unsafe.As(ref thisRefFromB) = source; this.A = byte.MaxValue; } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs index 882306928d..81c1783485 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs @@ -189,9 +189,10 @@ public void FromRgb24(Rgb24 source) [MethodImpl(InliningOptions.ShortMethod)] public void FromAbgr32(Abgr32 source) { - this.R = source.R; - this.G = source.G; - this.B = source.B; + // We can assign this instances value directly to last three bytes of the Abgr32. + ref byte sourceRef = ref Unsafe.As(ref source); + ref byte sourceRefFromB = ref Unsafe.AddByteOffset(ref sourceRef, new IntPtr(1)); + this = Unsafe.As(ref sourceRefFromB); } /// diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs index 6386d315ca..1333fbb6ac 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs @@ -204,10 +204,10 @@ public override void ToL8( ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromAbgr32(sp); } @@ -224,10 +224,10 @@ public override void ToL16( ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromAbgr32(sp); } @@ -244,10 +244,10 @@ public override void ToLa16( ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromAbgr32(sp); } @@ -264,10 +264,10 @@ public override void ToLa32( ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromAbgr32(sp); } @@ -284,10 +284,10 @@ public override void ToRgb48( ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromAbgr32(sp); } @@ -304,10 +304,10 @@ public override void ToRgba64( ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromAbgr32(sp); } @@ -324,10 +324,10 @@ public override void ToBgra5551( ref Abgr32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromAbgr32(sp); } 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 0f183df0d0..fa646512d1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -204,10 +204,10 @@ public override void ToL8( ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromArgb32(sp); } @@ -224,10 +224,10 @@ public override void ToL16( ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromArgb32(sp); } @@ -244,10 +244,10 @@ public override void ToLa16( ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromArgb32(sp); } @@ -264,10 +264,10 @@ public override void ToLa32( ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromArgb32(sp); } @@ -284,10 +284,10 @@ public override void ToRgb48( ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromArgb32(sp); } @@ -304,10 +304,10 @@ public override void ToRgba64( ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromArgb32(sp); } @@ -324,10 +324,10 @@ public override void ToBgra5551( ref Argb32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromArgb32(sp); } 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 ea08c6391b..b193251cee 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -204,10 +204,10 @@ public override void ToL8( ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgr24(sp); } @@ -224,10 +224,10 @@ public override void ToL16( ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgr24(sp); } @@ -244,10 +244,10 @@ public override void ToLa16( ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgr24(sp); } @@ -264,10 +264,10 @@ public override void ToLa32( ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgr24(sp); } @@ -284,10 +284,10 @@ public override void ToRgb48( ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgr24(sp); } @@ -304,10 +304,10 @@ public override void ToRgba64( ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgr24(sp); } @@ -324,10 +324,10 @@ public override void ToBgra5551( ref Bgr24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgr24(sp); } 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 0ec9a552cc..4426bc0d96 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -204,10 +204,10 @@ public override void ToL8( ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra32(sp); } @@ -224,10 +224,10 @@ public override void ToL16( ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra32(sp); } @@ -244,10 +244,10 @@ public override void ToLa16( ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra32(sp); } @@ -264,10 +264,10 @@ public override void ToLa32( ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra32(sp); } @@ -284,10 +284,10 @@ public override void ToRgb48( ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra32(sp); } @@ -304,10 +304,10 @@ public override void ToRgba64( ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra32(sp); } @@ -324,10 +324,10 @@ public override void ToBgra5551( ref Bgra32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra32(sp); } 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 877ce1a6fb..90ace91813 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -50,10 +50,10 @@ public override void ToArgb32( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -70,10 +70,10 @@ public override void ToAbgr32( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -90,10 +90,10 @@ public override void ToBgr24( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -110,10 +110,10 @@ public override void ToBgra32( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -130,10 +130,10 @@ public override void ToL8( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -150,10 +150,10 @@ public override void ToL16( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -170,10 +170,10 @@ public override void ToLa16( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -190,10 +190,10 @@ public override void ToLa32( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -210,10 +210,10 @@ public override void ToRgb24( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -230,10 +230,10 @@ public override void ToRgba32( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -250,10 +250,10 @@ public override void ToRgb48( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } @@ -270,10 +270,10 @@ public override void ToRgba64( ref Bgra5551 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromBgra5551(sp); } 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 94eb3229bd..8c5b2e99a0 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -50,10 +50,10 @@ public override void ToArgb32( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -70,10 +70,10 @@ public override void ToAbgr32( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -90,10 +90,10 @@ public override void ToBgr24( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -110,10 +110,10 @@ public override void ToBgra32( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -130,10 +130,10 @@ public override void ToL8( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -150,10 +150,10 @@ public override void ToLa16( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -170,10 +170,10 @@ public override void ToLa32( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -190,10 +190,10 @@ public override void ToRgb24( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -210,10 +210,10 @@ public override void ToRgba32( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -230,10 +230,10 @@ public override void ToRgb48( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -250,10 +250,10 @@ public override void ToRgba64( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } @@ -270,10 +270,10 @@ public override void ToBgra5551( ref L16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL16(sp); } 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 a748590f74..f61dc25ec3 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -50,10 +50,10 @@ public override void ToArgb32( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -70,10 +70,10 @@ public override void ToAbgr32( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -90,10 +90,10 @@ public override void ToBgr24( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -110,10 +110,10 @@ public override void ToBgra32( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -130,10 +130,10 @@ public override void ToL16( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -150,10 +150,10 @@ public override void ToLa16( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -170,10 +170,10 @@ public override void ToLa32( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -190,10 +190,10 @@ public override void ToRgb24( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -210,10 +210,10 @@ public override void ToRgba32( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -230,10 +230,10 @@ public override void ToRgb48( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -250,10 +250,10 @@ public override void ToRgba64( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } @@ -270,10 +270,10 @@ public override void ToBgra5551( ref L8 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromL8(sp); } 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 f47cd6c401..feec776182 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -50,10 +50,10 @@ public override void ToArgb32( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -70,10 +70,10 @@ public override void ToAbgr32( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -90,10 +90,10 @@ public override void ToBgr24( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -110,10 +110,10 @@ public override void ToBgra32( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -130,10 +130,10 @@ public override void ToL8( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -150,10 +150,10 @@ public override void ToL16( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -170,10 +170,10 @@ public override void ToLa32( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -190,10 +190,10 @@ public override void ToRgb24( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -210,10 +210,10 @@ public override void ToRgba32( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -230,10 +230,10 @@ public override void ToRgb48( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -250,10 +250,10 @@ public override void ToRgba64( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } @@ -270,10 +270,10 @@ public override void ToBgra5551( ref La16 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa16(sp); } 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 f0c2c33232..ddf94261eb 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs @@ -50,10 +50,10 @@ public override void ToArgb32( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -70,10 +70,10 @@ public override void ToAbgr32( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -90,10 +90,10 @@ public override void ToBgr24( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -110,10 +110,10 @@ public override void ToBgra32( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -130,10 +130,10 @@ public override void ToL8( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -150,10 +150,10 @@ public override void ToL16( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -170,10 +170,10 @@ public override void ToLa16( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -190,10 +190,10 @@ public override void ToRgb24( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -210,10 +210,10 @@ public override void ToRgba32( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -230,10 +230,10 @@ public override void ToRgb48( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -250,10 +250,10 @@ public override void ToRgba64( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } @@ -270,10 +270,10 @@ public override void ToBgra5551( ref La32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromLa32(sp); } 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 75f677cdd3..e89b17f723 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -204,10 +204,10 @@ public override void ToL8( ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb24(sp); } @@ -224,10 +224,10 @@ public override void ToL16( ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb24(sp); } @@ -244,10 +244,10 @@ public override void ToLa16( ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb24(sp); } @@ -264,10 +264,10 @@ public override void ToLa32( ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb24(sp); } @@ -284,10 +284,10 @@ public override void ToRgb48( ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb24(sp); } @@ -304,10 +304,10 @@ public override void ToRgba64( ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb24(sp); } @@ -324,10 +324,10 @@ public override void ToBgra5551( ref Rgb24 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb24(sp); } 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 22b96fd5a8..017124ef19 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -50,10 +50,10 @@ public override void ToArgb32( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -70,10 +70,10 @@ public override void ToAbgr32( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -90,10 +90,10 @@ public override void ToBgr24( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -110,10 +110,10 @@ public override void ToBgra32( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -130,10 +130,10 @@ public override void ToL8( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -150,10 +150,10 @@ public override void ToL16( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -170,10 +170,10 @@ public override void ToLa16( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -190,10 +190,10 @@ public override void ToLa32( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -210,10 +210,10 @@ public override void ToRgb24( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -230,10 +230,10 @@ public override void ToRgba32( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -250,10 +250,10 @@ public override void ToRgba64( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } @@ -270,10 +270,10 @@ public override void ToBgra5551( ref Rgb48 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgb48(sp); } 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 093182c82e..483c3f69cc 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs @@ -185,10 +185,10 @@ public override void ToL8( ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba32(sp); } @@ -205,10 +205,10 @@ public override void ToL16( ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba32(sp); } @@ -225,10 +225,10 @@ public override void ToLa16( ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba32(sp); } @@ -245,10 +245,10 @@ public override void ToLa32( ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba32(sp); } @@ -265,10 +265,10 @@ public override void ToRgb48( ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba32(sp); } @@ -285,10 +285,10 @@ public override void ToRgba64( ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba64 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba32(sp); } @@ -305,10 +305,10 @@ public override void ToBgra5551( ref Rgba32 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba32(sp); } 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 ce1b53e664..a82fb26b47 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs @@ -50,10 +50,10 @@ public override void ToArgb32( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Argb32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -70,10 +70,10 @@ public override void ToAbgr32( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Abgr32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -90,10 +90,10 @@ public override void ToBgr24( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgr24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -110,10 +110,10 @@ public override void ToBgra32( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -130,10 +130,10 @@ public override void ToL8( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L8 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref L8 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -150,10 +150,10 @@ public override void ToL16( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref L16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref L16 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -170,10 +170,10 @@ public override void ToLa16( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La16 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref La16 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -190,10 +190,10 @@ public override void ToLa32( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref La32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref La32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -210,10 +210,10 @@ public override void ToRgb24( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb24 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -230,10 +230,10 @@ public override void ToRgba32( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgba32 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -250,10 +250,10 @@ public override void ToRgb48( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Rgb48 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } @@ -270,10 +270,10 @@ public override void ToBgra5551( ref Rgba64 sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref Bgra5551 destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); dp.FromRgba64(sp); } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index b6b0a14a70..9da66a5a98 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -104,10 +104,10 @@ using SixLabors.ImageSharp.PixelFormats.Utils; ref <#=fromPixelType#> sourceRef = ref MemoryMarshal.GetReference(sourcePixels); ref <#=toPixelType#> destRef = ref MemoryMarshal.GetReference(destinationPixels); - for (int i = 0; i < sourcePixels.Length; i++) + for (nint i = 0; i < sourcePixels.Length; i++) { - ref <#=fromPixelType#> sp = ref Unsafe.Add(ref sourceRef, i); - ref <#=toPixelType#> dp = ref Unsafe.Add(ref destRef, i); + ref <#=fromPixelType#> sp = ref Unsafe.Add(ref sourceRef, (int)i); + ref <#=toPixelType#> dp = ref Unsafe.Add(ref destRef, (int)i); dp.From<#=fromPixelType#>(sp); } From 1ce4429001258ab7d548f7f88eedfa3a60bd474b Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Sat, 11 Dec 2021 23:24:27 +0100 Subject: [PATCH 06/10] Optimizing native integer usage --- .../Common/Helpers/BitOperations.cs | 2 +- .../Helpers/Shuffle/IComponentShuffle.cs | 40 ++++++++-------- .../Abgr32.PixelOperations.Generated.cs | 28 +++++------ .../Argb32.PixelOperations.Generated.cs | 28 +++++------ .../Bgr24.PixelOperations.Generated.cs | 28 +++++------ .../Bgra32.PixelOperations.Generated.cs | 28 +++++------ .../Bgra5551.PixelOperations.Generated.cs | 48 +++++++++---------- .../L16.PixelOperations.Generated.cs | 48 +++++++++---------- .../Generated/L8.PixelOperations.Generated.cs | 48 +++++++++---------- .../La16.PixelOperations.Generated.cs | 48 +++++++++---------- .../La32.PixelOperations.Generated.cs | 48 +++++++++---------- .../Rgb24.PixelOperations.Generated.cs | 28 +++++------ .../Rgb48.PixelOperations.Generated.cs | 48 +++++++++---------- .../Rgba32.PixelOperations.Generated.cs | 28 +++++------ .../Rgba64.PixelOperations.Generated.cs | 48 +++++++++---------- .../Generated/_Common.ttinclude | 4 +- 16 files changed, 275 insertions(+), 275 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/BitOperations.cs b/src/ImageSharp/Common/Helpers/BitOperations.cs index b4b6c890c4..af56efd561 100644 --- a/src/ImageSharp/Common/Helpers/BitOperations.cs +++ b/src/ImageSharp/Common/Helpers/BitOperations.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; -#if !NETCOREAPP3_1 +#if !NETCOREAPP3_1_OR_GREATER namespace SixLabors.ImageSharp.Common.Helpers { /// diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 89bac8e103..1922c787c5 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -99,15 +99,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + nint n = (nint)source.Length / 4; - for (nuint i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (int)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // ROTL(8, packed) = [Z Y X W] - Unsafe.Add(ref dBase, (int)i) = (packed << 8) | (packed >> 24); + Unsafe.Add(ref dBase, i) = (packed << 8) | (packed >> 24); } } } @@ -125,15 +125,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + nint n = (nint)source.Length / 4; - for (nuint i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (int)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // REVERSE(packedArgb) = [X Y Z W] - Unsafe.Add(ref dBase, (int)i) = BinaryPrimitives.ReverseEndianness(packed); + Unsafe.Add(ref dBase, i) = BinaryPrimitives.ReverseEndianness(packed); } } } @@ -151,15 +151,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + nint n = (nint)source.Length / 4; - for (nuint i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (int)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // ROTR(8, packedArgb) = [Y Z W X] - Unsafe.Add(ref dBase, (int)i) = (packed >> 8) | (packed << 24); + Unsafe.Add(ref dBase, i) = (packed >> 8) | (packed << 24); } } } @@ -177,11 +177,11 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + nint n = (nint)source.Length / 4; - for (nuint i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (int)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // tmp1 = [W 0 Y 0] @@ -192,7 +192,7 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) uint tmp2 = packed & 0x00FF00FF; uint tmp3 = BitOperations.RotateLeft(tmp2, 16); - Unsafe.Add(ref dBase, (int)i) = tmp1 + tmp3; + Unsafe.Add(ref dBase, i) = tmp1 + tmp3; } } } @@ -210,11 +210,11 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + nint n = (nint)source.Length / 4; - for (nuint i = 0; i < n; i++) + for (nint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (int)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // tmp1 = [0 Z 0 X] @@ -225,7 +225,7 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) uint tmp2 = packed & 0xFF00FF00; uint tmp3 = BitOperations.RotateLeft(tmp2, 16); - Unsafe.Add(ref dBase, (int)i) = tmp1 + tmp3; + Unsafe.Add(ref dBase, i) = tmp1 + tmp3; } } } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs index 1333fbb6ac..026025f76e 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Abgr32.PixelOperations.Generated.cs @@ -206,8 +206,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromAbgr32(sp); } @@ -226,8 +226,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromAbgr32(sp); } @@ -246,8 +246,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromAbgr32(sp); } @@ -266,8 +266,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromAbgr32(sp); } @@ -286,8 +286,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromAbgr32(sp); } @@ -306,8 +306,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromAbgr32(sp); } @@ -326,8 +326,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Abgr32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromAbgr32(sp); } 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 fa646512d1..4b9f68a68c 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Argb32.PixelOperations.Generated.cs @@ -206,8 +206,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromArgb32(sp); } @@ -226,8 +226,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromArgb32(sp); } @@ -246,8 +246,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromArgb32(sp); } @@ -266,8 +266,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromArgb32(sp); } @@ -286,8 +286,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromArgb32(sp); } @@ -306,8 +306,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromArgb32(sp); } @@ -326,8 +326,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Argb32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Argb32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromArgb32(sp); } 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 b193251cee..c85e4ee3b1 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgr24.PixelOperations.Generated.cs @@ -206,8 +206,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgr24(sp); } @@ -226,8 +226,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgr24(sp); } @@ -246,8 +246,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgr24(sp); } @@ -266,8 +266,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgr24(sp); } @@ -286,8 +286,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgr24(sp); } @@ -306,8 +306,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgr24(sp); } @@ -326,8 +326,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgr24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgr24(sp); } 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 4426bc0d96..ed1366b0a6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra32.PixelOperations.Generated.cs @@ -206,8 +206,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra32(sp); } @@ -226,8 +226,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra32(sp); } @@ -246,8 +246,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra32(sp); } @@ -266,8 +266,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra32(sp); } @@ -286,8 +286,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra32(sp); } @@ -306,8 +306,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra32(sp); } @@ -326,8 +326,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra32(sp); } 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 90ace91813..0dfa46c145 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Bgra5551.PixelOperations.Generated.cs @@ -52,8 +52,8 @@ public override void ToArgb32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -72,8 +72,8 @@ public override void ToAbgr32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -92,8 +92,8 @@ public override void ToBgr24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -112,8 +112,8 @@ public override void ToBgra32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -132,8 +132,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -152,8 +152,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -172,8 +172,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -192,8 +192,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -212,8 +212,8 @@ public override void ToRgb24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -232,8 +232,8 @@ public override void ToRgba32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -252,8 +252,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } @@ -272,8 +272,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Bgra5551 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromBgra5551(sp); } 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 8c5b2e99a0..19e0548aee 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L16.PixelOperations.Generated.cs @@ -52,8 +52,8 @@ public override void ToArgb32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -72,8 +72,8 @@ public override void ToAbgr32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -92,8 +92,8 @@ public override void ToBgr24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -112,8 +112,8 @@ public override void ToBgra32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -132,8 +132,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -152,8 +152,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -172,8 +172,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -192,8 +192,8 @@ public override void ToRgb24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -212,8 +212,8 @@ public override void ToRgba32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -232,8 +232,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -252,8 +252,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } @@ -272,8 +272,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromL16(sp); } 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 f61dc25ec3..8997449d3f 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/L8.PixelOperations.Generated.cs @@ -52,8 +52,8 @@ public override void ToArgb32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -72,8 +72,8 @@ public override void ToAbgr32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -92,8 +92,8 @@ public override void ToBgr24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -112,8 +112,8 @@ public override void ToBgra32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -132,8 +132,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -152,8 +152,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -172,8 +172,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -192,8 +192,8 @@ public override void ToRgb24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -212,8 +212,8 @@ public override void ToRgba32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -232,8 +232,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -252,8 +252,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } @@ -272,8 +272,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref L8 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref L8 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromL8(sp); } 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 feec776182..8166862fe4 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La16.PixelOperations.Generated.cs @@ -52,8 +52,8 @@ public override void ToArgb32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -72,8 +72,8 @@ public override void ToAbgr32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -92,8 +92,8 @@ public override void ToBgr24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -112,8 +112,8 @@ public override void ToBgra32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -132,8 +132,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -152,8 +152,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -172,8 +172,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -192,8 +192,8 @@ public override void ToRgb24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -212,8 +212,8 @@ public override void ToRgba32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -232,8 +232,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -252,8 +252,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } @@ -272,8 +272,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La16 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La16 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa16(sp); } 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 ddf94261eb..32a0f24e37 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/La32.PixelOperations.Generated.cs @@ -52,8 +52,8 @@ public override void ToArgb32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -72,8 +72,8 @@ public override void ToAbgr32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -92,8 +92,8 @@ public override void ToBgr24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -112,8 +112,8 @@ public override void ToBgra32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -132,8 +132,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -152,8 +152,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -172,8 +172,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -192,8 +192,8 @@ public override void ToRgb24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -212,8 +212,8 @@ public override void ToRgba32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -232,8 +232,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -252,8 +252,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } @@ -272,8 +272,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref La32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref La32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromLa32(sp); } 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 e89b17f723..53a82989dc 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb24.PixelOperations.Generated.cs @@ -206,8 +206,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb24(sp); } @@ -226,8 +226,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb24(sp); } @@ -246,8 +246,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb24(sp); } @@ -266,8 +266,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb24(sp); } @@ -286,8 +286,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb24(sp); } @@ -306,8 +306,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb24(sp); } @@ -326,8 +326,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb24 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb24(sp); } 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 017124ef19..d1c5ab2e30 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgb48.PixelOperations.Generated.cs @@ -52,8 +52,8 @@ public override void ToArgb32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -72,8 +72,8 @@ public override void ToAbgr32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -92,8 +92,8 @@ public override void ToBgr24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -112,8 +112,8 @@ public override void ToBgra32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -132,8 +132,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -152,8 +152,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -172,8 +172,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -192,8 +192,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -212,8 +212,8 @@ public override void ToRgb24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -232,8 +232,8 @@ public override void ToRgba32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -252,8 +252,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } @@ -272,8 +272,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgb48 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgb48(sp); } 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 483c3f69cc..2608a74fc2 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba32.PixelOperations.Generated.cs @@ -187,8 +187,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba32(sp); } @@ -207,8 +207,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba32(sp); } @@ -227,8 +227,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba32(sp); } @@ -247,8 +247,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba32(sp); } @@ -267,8 +267,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba32(sp); } @@ -287,8 +287,8 @@ public override void ToRgba64( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba64 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba64 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba32(sp); } @@ -307,8 +307,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba32(sp); } 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 a82fb26b47..f6445039a4 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/Rgba64.PixelOperations.Generated.cs @@ -52,8 +52,8 @@ public override void ToArgb32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Argb32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Argb32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -72,8 +72,8 @@ public override void ToAbgr32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Abgr32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Abgr32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -92,8 +92,8 @@ public override void ToBgr24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgr24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgr24 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -112,8 +112,8 @@ public override void ToBgra32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -132,8 +132,8 @@ public override void ToL8( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L8 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref L8 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -152,8 +152,8 @@ public override void ToL16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref L16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref L16 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -172,8 +172,8 @@ public override void ToLa16( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La16 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref La16 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -192,8 +192,8 @@ public override void ToLa32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref La32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref La32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -212,8 +212,8 @@ public override void ToRgb24( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb24 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb24 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -232,8 +232,8 @@ public override void ToRgba32( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgba32 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -252,8 +252,8 @@ public override void ToRgb48( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Rgb48 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgb48 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } @@ -272,8 +272,8 @@ public override void ToBgra5551( for (nint i = 0; i < sourcePixels.Length; i++) { - ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref Bgra5551 dp = ref Unsafe.Add(ref destRef, (int)i); + ref Rgba64 sp = ref Unsafe.Add(ref sourceRef, i); + ref Bgra5551 dp = ref Unsafe.Add(ref destRef, i); dp.FromRgba64(sp); } diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude index 9da66a5a98..9a6ddd7d44 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude +++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Generated/_Common.ttinclude @@ -106,8 +106,8 @@ using SixLabors.ImageSharp.PixelFormats.Utils; for (nint i = 0; i < sourcePixels.Length; i++) { - ref <#=fromPixelType#> sp = ref Unsafe.Add(ref sourceRef, (int)i); - ref <#=toPixelType#> dp = ref Unsafe.Add(ref destRef, (int)i); + ref <#=fromPixelType#> sp = ref Unsafe.Add(ref sourceRef, i); + ref <#=toPixelType#> dp = ref Unsafe.Add(ref destRef, i); dp.From<#=fromPixelType#>(sp); } From e04ea46df19e47513d9cbffa87c4f0c43aae561a Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Sun, 12 Dec 2021 13:41:16 +0100 Subject: [PATCH 07/10] Use Numerics class as polyfill for BitOperations --- .../Common/Helpers/BitOperations.cs | 26 ----------------- src/ImageSharp/Common/Helpers/Numerics.cs | 28 +++++++++++++++++++ .../Helpers/Shuffle/IComponentShuffle.cs | 4 +-- 3 files changed, 30 insertions(+), 28 deletions(-) delete mode 100644 src/ImageSharp/Common/Helpers/BitOperations.cs diff --git a/src/ImageSharp/Common/Helpers/BitOperations.cs b/src/ImageSharp/Common/Helpers/BitOperations.cs deleted file mode 100644 index af56efd561..0000000000 --- a/src/ImageSharp/Common/Helpers/BitOperations.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System.Runtime.CompilerServices; - -#if !NETCOREAPP3_1_OR_GREATER -namespace SixLabors.ImageSharp.Common.Helpers -{ - /// - /// Polyfill for System.Numerics.BitOperations class, introduced in .NET Core 3.0. - /// - /// - public static class BitOperations - { - /// - /// Rotates the specified value left by the specified number of bits. - /// - /// The value to rotate. - /// The number of bits to roate with. - /// The rotated value. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint RotateLeft(uint value, int offset) - => (value << offset) | (value >> (32 - offset)); - } -} -#endif diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index fa0af823d5..df81c39e7f 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -907,5 +907,33 @@ ref MemoryMarshal.GetReference(Log2DeBruijn), /// Divisor value. /// Ceiled division result. public static uint DivideCeil(uint value, uint divisor) => (value + divisor - 1) / divisor; + + /// + /// Rotates the specified value left by the specified number of bits. + /// + /// The value to rotate. + /// The number of bits to roate with. + /// The rotated value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint RotateLeft(uint value, int offset) + { +#if SUPPORTS_BITOPERATIONS + return BitOperations.RotateLeft(value, offset); +#else + return RotateLeftSoftwareFallback(value, offset); +#endif + } + +#if !SUPPORTS_BITOPERATIONS + /// + /// Rotates the specified value left by the specified number of bits. + /// + /// The value to rotate. + /// The number of bits to roate with. + /// The rotated value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint RotateLeftSoftwareFallback(uint value, int offset) + => (value << offset) | (value >> (32 - offset)); +#endif } } diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index 1922c787c5..da60928d3f 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -190,7 +190,7 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) // tmp1 + tmp3 = [W X Y Z] uint tmp1 = packed & 0xFF00FF00; uint tmp2 = packed & 0x00FF00FF; - uint tmp3 = BitOperations.RotateLeft(tmp2, 16); + uint tmp3 = Numerics.RotateLeft(tmp2, 16); Unsafe.Add(ref dBase, i) = tmp1 + tmp3; } @@ -223,7 +223,7 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) // tmp1 + tmp3 = [Y Z W X] uint tmp1 = packed & 0x00FF00FF; uint tmp2 = packed & 0xFF00FF00; - uint tmp3 = BitOperations.RotateLeft(tmp2, 16); + uint tmp3 = Numerics.RotateLeft(tmp2, 16); Unsafe.Add(ref dBase, i) = tmp1 + tmp3; } From ed611ca48cb11f6421c1a4603c8eacf43f4fa22e Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Sun, 12 Dec 2021 16:51:11 +0100 Subject: [PATCH 08/10] Revert submodule changes --- .gitattributes | 8 ++++++-- shared-infrastructure | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index 70ced69033..355b64dce1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -87,7 +87,6 @@ *.eot binary *.exe binary *.otf binary -*.pbm binary *.pdf binary *.ppt binary *.pptx binary @@ -95,7 +94,6 @@ *.snk binary *.ttc binary *.ttf binary -*.wbmp binary *.woff binary *.woff2 binary *.xls binary @@ -126,3 +124,9 @@ *.dds filter=lfs diff=lfs merge=lfs -text *.ktx filter=lfs diff=lfs merge=lfs -text *.ktx2 filter=lfs diff=lfs merge=lfs -text +*.pam filter=lfs diff=lfs merge=lfs -text +*.pbm filter=lfs diff=lfs merge=lfs -text +*.pgm filter=lfs diff=lfs merge=lfs -text +*.ppm filter=lfs diff=lfs merge=lfs -text +*.pnm filter=lfs diff=lfs merge=lfs -text +*.wbmp filter=lfs diff=lfs merge=lfs -text diff --git a/shared-infrastructure b/shared-infrastructure index a042aba176..59ce17f5a4 160000 --- a/shared-infrastructure +++ b/shared-infrastructure @@ -1 +1 @@ -Subproject commit a042aba176cdb840d800c6ed4cfe41a54fb7b1e3 +Subproject commit 59ce17f5a4e1f956811133f41add7638e74c2836 From 752520cf08119897e3b05b22d36c780d39006a32 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Mon, 13 Dec 2021 01:36:35 +0100 Subject: [PATCH 09/10] Use nuint in IComponentShuffle again --- src/ImageSharp/Common/Helpers/Numerics.cs | 32 +++++++++++++- .../Helpers/Shuffle/IComponentShuffle.cs | 42 +++++++++---------- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index df81c39e7f..513db0c448 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -912,7 +912,7 @@ ref MemoryMarshal.GetReference(Log2DeBruijn), /// Rotates the specified value left by the specified number of bits. /// /// The value to rotate. - /// The number of bits to roate with. + /// The number of bits to rotate with. /// The rotated value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RotateLeft(uint value, int offset) @@ -929,11 +929,39 @@ public static uint RotateLeft(uint value, int offset) /// Rotates the specified value left by the specified number of bits. /// /// The value to rotate. - /// The number of bits to roate with. + /// The number of bits to rotate with. /// The rotated value. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RotateLeftSoftwareFallback(uint value, int offset) => (value << offset) | (value >> (32 - offset)); #endif + + /// + /// Rotates the specified value right by the specified number of bits. + /// + /// The value to rotate. + /// The number of bits to rotate with. + /// The rotated value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint RotateRight(uint value, int offset) + { +#if SUPPORTS_BITOPERATIONS + return BitOperations.RotateRight(value, offset); +#else + return RotateRightSoftwareFallback(value, offset); +#endif + } + +#if !SUPPORTS_BITOPERATIONS + /// + /// Rotates the specified value right by the specified number of bits. + /// + /// The value to rotate. + /// The number of bits to rotate with. + /// The rotated value. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint RotateRightSoftwareFallback(uint value, int offset) + => (value >> offset) | (value << (32 - offset)); +#endif } } diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index da60928d3f..a1224a7673 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -3,10 +3,8 @@ using System; using System.Buffers.Binary; -using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Common.Helpers; // The JIT can detect and optimize rotation idioms ROTL (Rotate Left) // and ROTR (Rotate Right) emitting efficient CPU instructions: @@ -99,15 +97,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); // packed = [W Z Y X] // ROTL(8, packed) = [Z Y X W] - Unsafe.Add(ref dBase, i) = (packed << 8) | (packed >> 24); + Unsafe.Add(ref dBase, (IntPtr)(uint)i) = (packed << 8) | (packed >> 24); } } } @@ -125,15 +123,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); // packed = [W Z Y X] // REVERSE(packedArgb) = [X Y Z W] - Unsafe.Add(ref dBase, i) = BinaryPrimitives.ReverseEndianness(packed); + Unsafe.Add(ref dBase, (IntPtr)(uint)i) = BinaryPrimitives.ReverseEndianness(packed); } } } @@ -151,15 +149,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); // packed = [W Z Y X] // ROTR(8, packedArgb) = [Y Z W X] - Unsafe.Add(ref dBase, i) = (packed >> 8) | (packed << 24); + Unsafe.Add(ref dBase, (IntPtr)(uint)i) = Numerics.RotateRight(packed, 8); } } } @@ -177,11 +175,11 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); // packed = [W Z Y X] // tmp1 = [W 0 Y 0] @@ -192,7 +190,7 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) uint tmp2 = packed & 0x00FF00FF; uint tmp3 = Numerics.RotateLeft(tmp2, 16); - Unsafe.Add(ref dBase, i) = tmp1 + tmp3; + Unsafe.Add(ref dBase, (IntPtr)(uint)i) = tmp1 + tmp3; } } } @@ -210,11 +208,11 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nint n = (nint)source.Length / 4; + nuint n = (nuint)(uint)source.Length / 4; - for (nint i = 0; i < n; i++) + for (nuint i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, i); + uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); // packed = [W Z Y X] // tmp1 = [0 Z 0 X] @@ -225,7 +223,7 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) uint tmp2 = packed & 0xFF00FF00; uint tmp3 = Numerics.RotateLeft(tmp2, 16); - Unsafe.Add(ref dBase, i) = tmp1 + tmp3; + Unsafe.Add(ref dBase, (IntPtr)(uint)i) = tmp1 + tmp3; } } } From 3ee73a89c535e379ec36e6edf032332a7d466bf5 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Thu, 16 Dec 2021 17:50:55 +0100 Subject: [PATCH 10/10] Update IComponentShuffle back to int again --- .../Helpers/Shuffle/IComponentShuffle.cs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs index a1224a7673..049c611851 100644 --- a/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs +++ b/src/ImageSharp/Common/Helpers/Shuffle/IComponentShuffle.cs @@ -97,15 +97,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + int n = source.Length / 4; - for (nuint i = 0; i < n; i++) + for (int i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // ROTL(8, packed) = [Z Y X W] - Unsafe.Add(ref dBase, (IntPtr)(uint)i) = (packed << 8) | (packed >> 24); + Unsafe.Add(ref dBase, i) = (packed << 8) | (packed >> 24); } } } @@ -123,15 +123,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + int n = source.Length / 4; - for (nuint i = 0; i < n; i++) + for (int i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // REVERSE(packedArgb) = [X Y Z W] - Unsafe.Add(ref dBase, (IntPtr)(uint)i) = BinaryPrimitives.ReverseEndianness(packed); + Unsafe.Add(ref dBase, i) = BinaryPrimitives.ReverseEndianness(packed); } } } @@ -149,15 +149,15 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + int n = source.Length / 4; - for (nuint i = 0; i < n; i++) + for (int i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // ROTR(8, packedArgb) = [Y Z W X] - Unsafe.Add(ref dBase, (IntPtr)(uint)i) = Numerics.RotateRight(packed, 8); + Unsafe.Add(ref dBase, i) = Numerics.RotateRight(packed, 8); } } } @@ -175,11 +175,11 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + int n = source.Length / 4; - for (nuint i = 0; i < n; i++) + for (int i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // tmp1 = [W 0 Y 0] @@ -190,7 +190,7 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) uint tmp2 = packed & 0x00FF00FF; uint tmp3 = Numerics.RotateLeft(tmp2, 16); - Unsafe.Add(ref dBase, (IntPtr)(uint)i) = tmp1 + tmp3; + Unsafe.Add(ref dBase, i) = tmp1 + tmp3; } } } @@ -208,11 +208,11 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) { ref uint sBase = ref Unsafe.As(ref MemoryMarshal.GetReference(source)); ref uint dBase = ref Unsafe.As(ref MemoryMarshal.GetReference(dest)); - nuint n = (nuint)(uint)source.Length / 4; + int n = source.Length / 4; - for (nuint i = 0; i < n; i++) + for (int i = 0; i < n; i++) { - uint packed = Unsafe.Add(ref sBase, (IntPtr)(uint)i); + uint packed = Unsafe.Add(ref sBase, i); // packed = [W Z Y X] // tmp1 = [0 Z 0 X] @@ -223,7 +223,7 @@ public void RunFallbackShuffle(ReadOnlySpan source, Span dest) uint tmp2 = packed & 0xFF00FF00; uint tmp3 = Numerics.RotateLeft(tmp2, 16); - Unsafe.Add(ref dBase, (IntPtr)(uint)i) = tmp1 + tmp3; + Unsafe.Add(ref dBase, i) = tmp1 + tmp3; } } }