diff --git a/src/ImageSharp/PixelFormats/Argb32.cs b/src/ImageSharp/PixelFormats/Argb32.cs index 0cf7e8532b..8581842890 100644 --- a/src/ImageSharp/PixelFormats/Argb32.cs +++ b/src/ImageSharp/PixelFormats/Argb32.cs @@ -41,26 +41,6 @@ namespace SixLabors.ImageSharp.PixelFormats /// public byte B; - /// - /// The shift count for the blue component - /// - private const int BlueShift = 0; - - /// - /// The shift count for the green component - /// - private const int GreenShift = 8; - - /// - /// The shift count for the red component - /// - private const int RedShift = 16; - - /// - /// The shift count for the alpha component - /// - private const int AlphaShift = 24; - /// /// The maximum byte value. /// @@ -123,7 +103,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// The vector containing the components for the packed vector. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Argb32(Vector3 vector) + public Argb32(Vector3 vector) : this() { this.Pack(ref vector); @@ -136,7 +116,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// The vector containing the components for the packed vector. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Argb32(Vector4 vector) + public Argb32(Vector4 vector) : this() { this.Pack(ref vector); @@ -149,7 +129,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// The packed value. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Argb32(uint packed) + public Argb32(uint packed) : this() { this.Argb = packed; @@ -158,20 +138,23 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Gets or sets the packed representation of the Argb32 struct. /// - public uint Argb { + public uint Argb + { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get { + get + { return Unsafe.As(ref this); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - set { + set + { Unsafe.As(ref this) = value; } } /// - public uint PackedValue + public uint PackedValue { get => this.Argb; set => this.Argb = value; @@ -244,7 +227,10 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromRgba32(Rgba32 source) { - this.PackedValue = Pack(source.R, source.G, source.B, source.A); + this.R = source.R; + this.G = source.G; + this.B = source.B; + this.A = source.A; } /// @@ -275,7 +261,8 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ToArgb32(ref Argb32 dest) { + public void ToArgb32(ref Argb32 dest) + { dest = this; } @@ -338,20 +325,6 @@ namespace SixLabors.ImageSharp.PixelFormats return new Vector4(this.R, this.G, this.B, this.A); } - /// - /// Packs the four floats into a . - /// - /// The x-component - /// The y-component - /// The z-component - /// The w-component - /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint Pack(byte x, byte y, byte z, byte w) - { - return (uint)(x << RedShift | y << GreenShift | z << BlueShift | w << AlphaShift); - } - /// /// Packs the four floats into a color. /// diff --git a/src/ImageSharp/PixelFormats/Bgr24.cs b/src/ImageSharp/PixelFormats/Bgr24.cs index 6ceaa2097b..5c1845768a 100644 --- a/src/ImageSharp/PixelFormats/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/Bgr24.cs @@ -85,9 +85,9 @@ namespace SixLabors.ImageSharp.PixelFormats /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromArgb32(Argb32 source) { - R = source.R; - G = source.G; - B = source.B; + this.R = source.R; + this.G = source.G; + this.B = source.B; } /// diff --git a/src/ImageSharp/PixelFormats/Rgb24.cs b/src/ImageSharp/PixelFormats/Rgb24.cs index 4d6dc2d9d5..db798e053c 100644 --- a/src/ImageSharp/PixelFormats/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/Rgb24.cs @@ -87,9 +87,9 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromArgb32(Argb32 source) { - R = source.R; - G = source.G; - B = source.B; + this.R = source.R; + this.G = source.G; + this.B = source.B; } ///