From d66f34cbdc93ffe37c86fcf8858d1cae9d2bdabe Mon Sep 17 00:00:00 2001 From: woutware <35376607+woutware@users.noreply.github.com> Date: Thu, 19 Apr 2018 19:36:08 +0200 Subject: [PATCH] Revert "Fixed color component order (should be reversed) for Argb32, Rgba32, Bgr24, Rgb24, Bgra32. Tests still need to be updated." This reverts commit a481a3e621f546161c83821a3c7a2e558d3e7a38. --- src/ImageSharp/PixelFormats/Argb32.cs | 34 +++++-------------- src/ImageSharp/PixelFormats/Bgr24.cs | 8 ++--- src/ImageSharp/PixelFormats/Bgra32.cs | 16 ++++----- src/ImageSharp/PixelFormats/Rgb24.cs | 24 ++++++------- src/ImageSharp/PixelFormats/Rgba32.cs | 24 ++++++------- .../PixelFormats/PackedPixelTests.cs | 4 +-- .../PixelFormats/Rgb24Tests.cs | 4 +-- 7 files changed, 47 insertions(+), 67 deletions(-) diff --git a/src/ImageSharp/PixelFormats/Argb32.cs b/src/ImageSharp/PixelFormats/Argb32.cs index 05a3a9c74..603821410 100644 --- a/src/ImageSharp/PixelFormats/Argb32.cs +++ b/src/ImageSharp/PixelFormats/Argb32.cs @@ -22,24 +22,24 @@ namespace SixLabors.ImageSharp.PixelFormats public struct Argb32 : IPixel, IPackedVector { /// - /// Gets or sets the blue component. + /// Gets or sets the alpha component. /// - public byte B; + public byte A; /// - /// Gets or sets the green component. + /// Gets or sets the red component. /// - public byte G; + public byte R; /// - /// Gets or sets the red component. + /// Gets or sets the green component. /// - public byte R; + public byte G; /// - /// Gets or sets the alpha component. + /// Gets or sets the blue component. /// - public byte A; + public byte B; /// /// The maximum byte value. @@ -153,24 +153,6 @@ namespace SixLabors.ImageSharp.PixelFormats } } - /// - /// Gets or sets the RGB components of this struct as - /// - public Rgb24 Rgb - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return Unsafe.As(ref this); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - Unsafe.As(ref this) = value; - } - } - /// public uint PackedValue { diff --git a/src/ImageSharp/PixelFormats/Bgr24.cs b/src/ImageSharp/PixelFormats/Bgr24.cs index d33c48161..5c1845768 100644 --- a/src/ImageSharp/PixelFormats/Bgr24.cs +++ b/src/ImageSharp/PixelFormats/Bgr24.cs @@ -18,9 +18,9 @@ namespace SixLabors.ImageSharp.PixelFormats public struct Bgr24 : IPixel { /// - /// The red component. + /// The blue component. /// - public byte R; + public byte B; /// /// The green component. @@ -28,9 +28,9 @@ namespace SixLabors.ImageSharp.PixelFormats public byte G; /// - /// The blue component. + /// The red component. /// - public byte B; + public byte R; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/PixelFormats/Bgra32.cs b/src/ImageSharp/PixelFormats/Bgra32.cs index 83c69f5b1..91875671a 100644 --- a/src/ImageSharp/PixelFormats/Bgra32.cs +++ b/src/ImageSharp/PixelFormats/Bgra32.cs @@ -19,24 +19,24 @@ namespace SixLabors.ImageSharp.PixelFormats public struct Bgra32 : IPixel, IPackedVector { /// - /// Gets or sets the alpha component. + /// Gets or sets the blue component. /// - public byte A; + public byte B; /// - /// Gets or sets the red component. + /// Gets or sets the green component. /// - public byte R; + public byte G; /// - /// Gets or sets the green component. + /// Gets or sets the red component. /// - public byte G; + public byte R; /// - /// Gets or sets the blue component. + /// Gets or sets the alpha component. /// - public byte B; + public byte A; /// /// Initializes a new instance of the struct. diff --git a/src/ImageSharp/PixelFormats/Rgb24.cs b/src/ImageSharp/PixelFormats/Rgb24.cs index 94a503e92..db798e053 100644 --- a/src/ImageSharp/PixelFormats/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/Rgb24.cs @@ -19,9 +19,9 @@ namespace SixLabors.ImageSharp.PixelFormats public struct Rgb24 : IPixel { /// - /// The blue component. + /// The red component. /// - public byte B; + public byte R; /// /// The green component. @@ -29,9 +29,9 @@ namespace SixLabors.ImageSharp.PixelFormats public byte G; /// - /// The red component. + /// The blue component. /// - public byte R; + public byte B; /// /// Initializes a new instance of the struct. @@ -80,16 +80,16 @@ namespace SixLabors.ImageSharp.PixelFormats [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromRgba32(Rgba32 source) { - this.R = source.R; - this.G = source.G; - this.B = source.B; + this = Unsafe.As(ref source); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromArgb32(Argb32 source) { - this = Unsafe.As(ref source); + this.R = source.R; + this.G = source.G; + this.B = source.B; } /// @@ -132,15 +132,15 @@ namespace SixLabors.ImageSharp.PixelFormats /// public void ToRgba32(ref Rgba32 dest) { - dest.R = this.R; - dest.G = this.G; - dest.B = this.B; + dest.Rgb = this; dest.A = 255; } /// public void ToArgb32(ref Argb32 dest) { - dest.Rgb = this; + dest.R = this.R; + dest.G = this.G; + dest.B = this.B; dest.A = 255; } diff --git a/src/ImageSharp/PixelFormats/Rgba32.cs b/src/ImageSharp/PixelFormats/Rgba32.cs index a06cd7d2f..220f835b9 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -22,24 +22,24 @@ namespace SixLabors.ImageSharp.PixelFormats public partial struct Rgba32 : IPixel, IPackedVector { /// - /// Gets or sets the alpha component. + /// Gets or sets the red component. /// - public byte A; + public byte R; /// - /// Gets or sets the blue component. + /// Gets or sets the green component. /// - public byte B; + public byte G; /// - /// Gets or sets the green component. + /// Gets or sets the blue component. /// - public byte G; + public byte B; /// - /// Gets or sets the red component. + /// Gets or sets the alpha component. /// - public byte R; + public byte A; /// /// The shift count for the red component @@ -174,22 +174,20 @@ namespace SixLabors.ImageSharp.PixelFormats } /// - /// Gets or sets the RGB components of this struct as . + /// Gets or sets the RGB components of this struct as /// public Rgb24 Rgb { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - return new Rgb24(this.R, this.G, this.B); + return Unsafe.As(ref this); } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { - this.R = value.R; - this.G = value.G; - this.B = value.B; + Unsafe.As(ref this) = value; } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs b/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs index 95e823998..028153142 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PackedPixelTests.cs @@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.Tests.Colors float z = +0.5f; float w = -0.7f; var argb = new Argb32(x, y, z, w); - Assert.Equal(0x001a0080u, argb.PackedValue); + Assert.Equal(0x80001a00u, argb.PackedValue); // Test ordering var rgb = default(Rgb24); @@ -925,7 +925,7 @@ namespace SixLabors.ImageSharp.Tests.Colors float z = +0.5f; float w = -0.7f; var rgba32 = new Rgba32(x, y, z, w); - Assert.Equal(0x1a008000u, rgba32.PackedValue); + Assert.Equal(0x80001Au, rgba32.PackedValue); // Test ordering var rgb = default(Rgb24); diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs index 29de303d8..4e85fe7e3 100644 --- a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs @@ -30,9 +30,9 @@ namespace SixLabors.ImageSharp.Tests var color = new Rgb24(1, 2, 3); byte* ptr = (byte*)&color; - Assert.Equal(3, ptr[0]); + Assert.Equal(1, ptr[0]); Assert.Equal(2, ptr[1]); - Assert.Equal(1, ptr[2]); + Assert.Equal(3, ptr[2]); } [Theory]