From 33cbd588e84a1056f8b3c55789cdebde87f3448c Mon Sep 17 00:00:00 2001 From: rokleM Date: Wed, 7 Dec 2016 11:52:13 -0300 Subject: [PATCH] Changed Argb to be a struct instead of a class --- src/ImageSharp/Colors/PackedPixel/Argb.cs | 53 ++++++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/src/ImageSharp/Colors/PackedPixel/Argb.cs b/src/ImageSharp/Colors/PackedPixel/Argb.cs index 75150873a..8ce607e4d 100644 --- a/src/ImageSharp/Colors/PackedPixel/Argb.cs +++ b/src/ImageSharp/Colors/PackedPixel/Argb.cs @@ -11,16 +11,16 @@ namespace ImageSharp /// 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. /// - public class Argb : IPackedPixel, IEquatable + public struct Argb : IPackedPixel, IEquatable { - const int BlueShift = 0; - const uint BlueMask = 0xFFFFFF00; - const int GreenShift = 8; - const uint GreenMask = 0xFFFF00FF; - const int RedShift = 16; - const uint RedMask = 0xFF00FFFF; - const int AlphaShift = 24; - const uint AlphaMask = 0x00FFFFFF; + const int BlueShift = 0; + const uint BlueMask = 0xFFFFFF00; + const int GreenShift = 8; + const uint GreenMask = 0xFFFF00FF; + const int RedShift = 16; + const uint RedMask = 0xFF00FFFF; + const int AlphaShift = 24; + const uint AlphaMask = 0x00FFFFFF; /// /// The maximum byte value. @@ -257,11 +257,40 @@ namespace ImageSharp } } + /// + /// 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. + /// + public static bool operator ==(Argb left, Argb right) + { + return left.PackedValue == right.PackedValue; + } + + /// + /// 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. + /// + public static bool operator !=(Argb left, Argb right) + { + return left.PackedValue != right.PackedValue; + } + /// - public override bool Equals(object obj) + public override bool Equals(object obj) { - var a = obj as Argb; - return (a != null) && Equals(a); + return obj is Argb && Equals((Argb)obj); } ///