diff --git a/src/ImageProcessorCore/Colors/Color.cs b/src/ImageProcessorCore/Colors/Color.cs
index 51d5391093..cad353a805 100644
--- a/src/ImageProcessorCore/Colors/Color.cs
+++ b/src/ImageProcessorCore/Colors/Color.cs
@@ -34,6 +34,71 @@ namespace ImageProcessorCore
///
private uint packedValue;
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The red component.
+ /// The green component.
+ /// The blue component.
+ /// The alpha component.
+ public Color(byte r, byte g, byte b, byte a = 255)
+ {
+ this.packedValue = (uint)(r << 24 | g << 16 | b << 8 | a);
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ ///
+ /// The hexadecimal representation of the combined color components arranged
+ /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
+ ///
+ public Color(string hex)
+ {
+ Guard.NotNullOrEmpty(hex, nameof(hex));
+
+ hex = ToRgbaHex(hex);
+
+ if (hex == null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out this.packedValue))
+ {
+ throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
+ }
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The red component.
+ /// The green component.
+ /// The blue component.
+ /// The alpha component.
+ public Color(float r, float g, float b, float a = 1)
+ {
+ this.packedValue = Pack(r, g, b, a);
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ ///
+ /// The vector containing the components for the packed vector.
+ ///
+ public Color(Vector3 vector)
+ {
+ this.packedValue = Pack(ref vector);
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ ///
+ /// The vector containing the components for the packed vector.
+ ///
+ public Color(Vector4 vector)
+ {
+ this.packedValue = Pack(ref vector);
+ }
+
///
/// Gets or sets the red component.
///
@@ -43,13 +108,13 @@ namespace ImageProcessorCore
{
return (byte)(this.packedValue >> 24);
}
+
set
{
this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << 24;
}
}
-
///
/// Gets or sets the green component.
///
@@ -59,6 +124,7 @@ namespace ImageProcessorCore
{
return (byte)(this.packedValue >> 16);
}
+
set
{
this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << 16;
@@ -74,6 +140,7 @@ namespace ImageProcessorCore
{
return (byte)(this.packedValue >> 8);
}
+
set
{
this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << 8;
@@ -89,80 +156,25 @@ namespace ImageProcessorCore
{
return (byte)this.packedValue;
}
+
set
{
this.packedValue = this.packedValue & 0xFFFFFF00 | value;
}
}
- ///
- /// The packed value.
- ///
- public uint PackedValue { get { return this.packedValue; } set { this.packedValue = value; } }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The red component.
- /// The green component.
- /// The blue component.
- /// The alpha component.
- public Color(byte r, byte g, byte b, byte a = 255)
- {
- this.packedValue = (uint)(r << 24 | g << 16 | b << 8 | a);
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- ///
- /// The hexadecimal representation of the combined color components arranged
- /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
- ///
- public Color(string hex)
+ ///
+ public uint PackedValue
{
- Guard.NotNullOrEmpty(hex, nameof(hex));
-
- hex = ToRgbaHex(hex);
-
- if (hex == null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out this.packedValue))
+ get
{
- throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
+ return this.packedValue;
}
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The red component.
- /// The green component.
- /// The blue component.
- /// The alpha component.
- public Color(float r, float g, float b, float a = 1)
- {
- this.packedValue = Pack(r, g, b, a);
- }
- ///
- /// Initializes a new instance of the struct.
- ///
- ///
- /// The vector containing the components for the packed vector.
- ///
- public Color(Vector3 vector)
- {
- this.packedValue = Pack(ref vector);
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- ///
- /// The vector containing the components for the packed vector.
- ///
- public Color(Vector4 vector)
- {
- this.packedValue = Pack(ref vector);
+ set
+ {
+ this.packedValue = value;
+ }
}
///
@@ -311,11 +323,13 @@ namespace ImageProcessorCore
{
return hex;
}
- else if (hex.Length == 6)
+
+ if (hex.Length == 6)
{
return hex + "FF";
}
- else if (hex.Length < 3 || hex.Length > 4)
+
+ if (hex.Length < 3 || hex.Length > 4)
{
return null;
}
diff --git a/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs b/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs
index 2deb378f4f..cb4662a010 100644
--- a/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs
+++ b/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs
@@ -15,6 +15,9 @@ namespace ImageProcessorCore
public interface IPackedVector : IPackedVector
where TPacked : struct
{
+ ///
+ /// Gets or sets the packed representation of the value.
+ ///
TPacked PackedValue { get; set; }
}