diff --git a/src/ImageSharp/Colors/Color.Transforms.cs b/src/ImageSharp/Colors/Color.Transforms.cs
index 31b4aa5be..15935afc4 100644
--- a/src/ImageSharp/Colors/Color.Transforms.cs
+++ b/src/ImageSharp/Colors/Color.Transforms.cs
@@ -6,9 +6,10 @@
namespace ImageSharp
{
using System.Numerics;
+ using System.Runtime.CompilerServices;
///
- /// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
+ /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in red, green, blue, and alpha order.
///
///
@@ -25,10 +26,11 @@ namespace ImageSharp
///
/// The .
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color operator +(Color left, Color right)
{
Vector4 add = left.ToVector4() + right.ToVector4();
- return Pack(ref add);
+ return PackNew(ref add);
}
///
@@ -39,10 +41,11 @@ namespace ImageSharp
///
/// The .
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Color operator -(Color left, Color right)
{
Vector4 sub = left.ToVector4() - right.ToVector4();
- return Pack(ref sub);
+ return PackNew(ref sub);
}
///
@@ -56,7 +59,7 @@ namespace ImageSharp
public static Color Normal(Color backdrop, Color source)
{
Vector4 normal = Vector4BlendTransforms.Normal(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref normal);
+ return PackNew(ref normal);
}
///
@@ -76,7 +79,7 @@ namespace ImageSharp
public static Color Multiply(Color backdrop, Color source)
{
Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref multiply);
+ return PackNew(ref multiply);
}
///
@@ -95,7 +98,7 @@ namespace ImageSharp
public static Color Screen(Color backdrop, Color source)
{
Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref subtract);
+ return PackNew(ref subtract);
}
///
@@ -110,7 +113,7 @@ namespace ImageSharp
public static Color HardLight(Color backdrop, Color source)
{
Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref hardlight);
+ return PackNew(ref hardlight);
}
///
@@ -129,7 +132,7 @@ namespace ImageSharp
public static Color Overlay(Color backdrop, Color source)
{
Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref overlay);
+ return PackNew(ref overlay);
}
///
@@ -144,7 +147,7 @@ namespace ImageSharp
public static Color Darken(Color backdrop, Color source)
{
Vector4 darken = Vector4BlendTransforms.Darken(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref darken);
+ return PackNew(ref darken);
}
///
@@ -159,7 +162,7 @@ namespace ImageSharp
public static Color Lighten(Color backdrop, Color source)
{
Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref lighten);
+ return PackNew(ref lighten);
}
///
@@ -174,7 +177,7 @@ namespace ImageSharp
public static Color SoftLight(Color backdrop, Color source)
{
Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref softlight);
+ return PackNew(ref softlight);
}
///
@@ -188,7 +191,7 @@ namespace ImageSharp
public static Color ColorDodge(Color backdrop, Color source)
{
Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref dodge);
+ return PackNew(ref dodge);
}
///
@@ -202,7 +205,7 @@ namespace ImageSharp
public static Color ColorBurn(Color backdrop, Color source)
{
Vector4 burn = Vector4BlendTransforms.Burn(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref burn);
+ return PackNew(ref burn);
}
///
@@ -217,7 +220,7 @@ namespace ImageSharp
public static Color Difference(Color backdrop, Color source)
{
Vector4 difference = Vector4BlendTransforms.Difference(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref difference);
+ return PackNew(ref difference);
}
///
@@ -232,7 +235,7 @@ namespace ImageSharp
public static Color Exclusion(Color backdrop, Color source)
{
Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.ToVector4(), source.ToVector4());
- return Pack(ref exclusion);
+ return PackNew(ref exclusion);
}
///
@@ -249,7 +252,8 @@ namespace ImageSharp
///
public static Color Lerp(Color from, Color to, float amount)
{
- return new Color(Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount));
+ Vector4 lerp = Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount);
+ return PackNew(ref lerp);
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs
index fb2ce38ac..fa83429df 100644
--- a/src/ImageSharp/Colors/Color.cs
+++ b/src/ImageSharp/Colors/Color.cs
@@ -10,7 +10,7 @@ namespace ImageSharp
using System.Runtime.InteropServices;
///
- /// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
+ /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in red, green, blue, and alpha order.
///
///
@@ -18,7 +18,7 @@ namespace ImageSharp
/// as it avoids the need to create new values for modification operations.
///
[StructLayout(LayoutKind.Explicit)]
- public partial struct Color : IPixel
+ public partial struct Color : IPixel, IPackedVector
{
///
/// Gets or sets the red component.
@@ -44,6 +44,12 @@ namespace ImageSharp
[FieldOffset(3)]
public byte A;
+ ///
+ /// The packed representation of the value.
+ ///
+ [FieldOffset(0)]
+ public uint Rgba;
+
///
/// The shift count for the red component
///
@@ -81,6 +87,7 @@ namespace ImageSharp
/// The green component.
/// The blue component.
/// The alpha component.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(byte r, byte g, byte b, byte a = 255)
: this()
{
@@ -97,10 +104,11 @@ namespace ImageSharp
/// The green component.
/// The blue component.
/// The alpha component.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(float r, float g, float b, float a = 1)
: this()
{
- this = Pack(r, g, b, a);
+ this.Pack(r, g, b, a);
}
///
@@ -109,10 +117,11 @@ namespace ImageSharp
///
/// The vector containing the components for the packed vector.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(Vector3 vector)
: this()
{
- this = Pack(ref vector);
+ this.Pack(ref vector);
}
///
@@ -121,12 +130,29 @@ namespace ImageSharp
///
/// The vector containing the components for the packed vector.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(Vector4 vector)
: this()
{
- this = Pack(ref vector);
+ this = PackNew(ref vector);
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ ///
+ /// The packed value.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public Color(uint packed)
+ : this()
+ {
+ this.Rgba = packed;
}
+ ///
+ public uint PackedValue { get => this.Rgba; set => this.Rgba = value; }
+
///
/// Compares two objects for equality.
///
@@ -142,10 +168,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Color left, Color right)
{
- return left.R == right.R
- && left.G == right.G
- && left.B == right.B
- && left.A == right.A;
+ return left.Rgba == right.Rgba;
}
///
@@ -159,10 +182,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Color left, Color right)
{
- return left.R != right.R
- && left.G != right.G
- && left.B != right.B
- && left.A != right.A;
+ return left.Rgba != right.Rgba;
}
///
@@ -245,7 +265,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromVector4(Vector4 vector)
{
- this = Pack(ref vector);
+ this.Pack(ref vector);
}
///
@@ -265,10 +285,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Color other)
{
- return this.R == other.R
- && this.G == other.G
- && this.B == other.B
- && this.A == other.A;
+ return this.Rgba == other.Rgba;
}
///
@@ -308,12 +325,12 @@ namespace ImageSharp
}
///
- /// Packs a into a uint.
+ /// Packs a into a color returning a new instance as a result.
///
/// The vector containing the values to pack.
/// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static Color Pack(ref Vector4 vector)
+ private static Color PackNew(ref Vector4 vector)
{
vector *= MaxBytes;
vector += Half;
@@ -322,31 +339,46 @@ namespace ImageSharp
return new Color((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W);
}
+ ///
+ /// Packs the four floats into a color.
+ ///
+ /// The x-component
+ /// The y-component
+ /// The z-component
+ /// The w-component
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void Pack(float x, float y, float z, float w)
+ {
+ Vector4 value = new Vector4(x, y, z, w);
+ this.Pack(ref value);
+ }
+
///
/// Packs a into a uint.
///
/// The vector containing the values to pack.
- /// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static Color Pack(ref Vector3 vector)
+ private void Pack(ref Vector3 vector)
{
Vector4 value = new Vector4(vector, 1);
- return Pack(ref value);
+ this.Pack(ref value);
}
///
- /// Packs the four floats into a .
+ /// Packs a into a color.
///
- /// The x-component
- /// The y-component
- /// The z-component
- /// The w-component
- /// The
+ /// The vector containing the values to pack.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static Color Pack(float x, float y, float z, float w)
+ private void Pack(ref Vector4 vector)
{
- Vector4 value = new Vector4(x, y, z, w);
- return Pack(ref value);
+ vector *= MaxBytes;
+ vector += Half;
+ vector = Vector4.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;
}
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/Colors/ColorVector.Definitions.cs b/src/ImageSharp/Colors/ColorVector.Definitions.cs
index 955c0b9db..150b7209c 100644
--- a/src/ImageSharp/Colors/ColorVector.Definitions.cs
+++ b/src/ImageSharp/Colors/ColorVector.Definitions.cs
@@ -6,7 +6,7 @@
namespace ImageSharp
{
///
- /// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
+ /// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
///
///
diff --git a/src/ImageSharp/Colors/ColorVector.Transforms.cs b/src/ImageSharp/Colors/ColorVector.Transforms.cs
index e9666a351..a884f2618 100644
--- a/src/ImageSharp/Colors/ColorVector.Transforms.cs
+++ b/src/ImageSharp/Colors/ColorVector.Transforms.cs
@@ -6,9 +6,10 @@
namespace ImageSharp
{
using System.Numerics;
+ using System.Runtime.CompilerServices;
///
- /// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
+ /// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
///
///
@@ -25,6 +26,7 @@ namespace ImageSharp
///
/// The .
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorVector operator +(ColorVector left, ColorVector right)
{
return new ColorVector(left.backingVector + right.backingVector);
@@ -38,6 +40,7 @@ namespace ImageSharp
///
/// The .
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorVector operator -(ColorVector left, ColorVector right)
{
return new ColorVector(left.backingVector - right.backingVector);
diff --git a/src/ImageSharp/Colors/ColorVector.cs b/src/ImageSharp/Colors/ColorVector.cs
index 354553982..06ee5b805 100644
--- a/src/ImageSharp/Colors/ColorVector.cs
+++ b/src/ImageSharp/Colors/ColorVector.cs
@@ -9,7 +9,7 @@ namespace ImageSharp
using System.Runtime.CompilerServices;
///
- /// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
+ /// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
///
///
@@ -40,6 +40,7 @@ namespace ImageSharp
/// The green component.
/// The blue component.
/// The alpha component.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ColorVector(byte r, byte g, byte b, byte a = 255)
: this()
{
@@ -53,6 +54,7 @@ namespace ImageSharp
/// The green component.
/// The blue component.
/// The alpha component.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ColorVector(float r, float g, float b, float a = 1)
: this()
{
@@ -65,6 +67,7 @@ namespace ImageSharp
///
/// The vector containing the components for the packed vector.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ColorVector(Vector3 vector)
: this()
{
@@ -77,6 +80,7 @@ namespace ImageSharp
///
/// The vector containing the components for the packed vector.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ColorVector(Vector4 vector)
: this()
{
diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs
index cbf40724e..480caab33 100644
--- a/src/ImageSharp/Colors/ColorspaceTransforms.cs
+++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs
@@ -10,7 +10,7 @@ namespace ImageSharp
using Colors.Spaces;
///
- /// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
+ /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in red, green, blue, and alpha order.
///
///
diff --git a/src/ImageSharp/Colors/PackedPixel/Argb.cs b/src/ImageSharp/Colors/PackedPixel/Argb32.cs
similarity index 87%
rename from src/ImageSharp/Colors/PackedPixel/Argb.cs
rename to src/ImageSharp/Colors/PackedPixel/Argb32.cs
index d03c098cd..64255a53b 100644
--- a/src/ImageSharp/Colors/PackedPixel/Argb.cs
+++ b/src/ImageSharp/Colors/PackedPixel/Argb32.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
@@ -17,7 +17,7 @@ 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 struct Argb : IPixel, IPackedVector
+ public struct Argb32 : IPixel, IPackedVector
{
///
/// The shift count for the blue component
@@ -50,58 +50,58 @@ namespace ImageSharp
private static readonly Vector4 Half = new Vector4(0.5F);
///
- /// Initializes a new instance of the struct.
+ /// Initializes a new instance of the struct.
///
/// The red component.
/// The green component.
/// The blue component.
/// The alpha component.
- public Argb(byte r, byte g, byte b, byte a = 255)
+ public Argb32(byte r, byte g, byte b, byte a = 255)
{
this.PackedValue = Pack(r, g, b, a);
}
///
- /// Initializes a new instance of the struct.
+ /// Initializes a new instance of the struct.
///
/// The red component.
/// The green component.
/// The blue component.
/// The alpha component.
- public Argb(float r, float g, float b, float a = 1)
+ public Argb32(float r, float g, float b, float a = 1)
{
this.PackedValue = Pack(r, g, b, a);
}
///
- /// Initializes a new instance of the struct.
+ /// Initializes a new instance of the struct.
///
///
/// The vector containing the components for the packed vector.
///
- public Argb(Vector3 vector)
+ public Argb32(Vector3 vector)
{
this.PackedValue = Pack(ref vector);
}
///
- /// Initializes a new instance of the struct.
+ /// Initializes a new instance of the struct.
///
///
/// The vector containing the components for the packed vector.
///
- public Argb(Vector4 vector)
+ public Argb32(Vector4 vector)
{
this.PackedValue = Pack(ref vector);
}
///
- /// Initializes a new instance of the struct.
+ /// Initializes a new instance of the struct.
///
///
/// The packed value.
///
- public Argb(uint packed = 0)
+ public Argb32(uint packed = 0)
{
this.PackedValue = packed;
}
@@ -182,33 +182,33 @@ namespace ImageSharp
}
///
- /// Compares two objects for equality.
+ /// Compares two objects for equality.
///
///
- /// The on the left side of the operand.
+ /// The on the left side of the operand.
///
///
- /// The on the right side of the operand.
+ /// The on the right side of the operand.
///
///
/// True if the parameter is equal to the parameter; otherwise, false.
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Argb left, Argb right)
+ public static bool operator ==(Argb32 left, Argb32 right)
{
return left.PackedValue == right.PackedValue;
}
///
- /// Compares two objects for equality.
+ /// Compares two objects for equality.
///
- /// The on the left side of the operand.
- /// The on the right side of the operand.
+ /// 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(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Argb left, Argb right)
+ public static bool operator !=(Argb32 left, Argb32 right)
{
return left.PackedValue != right.PackedValue;
}
@@ -221,7 +221,7 @@ namespace ImageSharp
}
///
- public BulkPixelOperations CreateBulkOperations() => new BulkPixelOperations();
+ public BulkPixelOperations CreateBulkOperations() => new BulkPixelOperations();
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -278,12 +278,12 @@ namespace ImageSharp
///
public override bool Equals(object obj)
{
- return obj is Argb && this.Equals((Argb)obj);
+ return obj is Argb32 && this.Equals((Argb32)obj);
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool Equals(Argb other)
+ public bool Equals(Argb32 other)
{
return this.PackedValue == other.PackedValue;
}
diff --git a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs b/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs
index 949e44cc0..13727870c 100644
--- a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs
+++ b/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs
@@ -300,7 +300,7 @@ namespace ImageSharp
private static bool IsStandardNormalizedType(Type type)
{
return type == typeof(Color)
- || type == typeof(Argb)
+ || type == typeof(Argb32)
|| type == typeof(Alpha8)
|| type == typeof(Bgr565)
|| type == typeof(Bgra4444)
diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba32.cs b/src/ImageSharp/Colors/PackedPixel/Rgba32.cs
deleted file mode 100644
index 727d91c93..000000000
--- a/src/ImageSharp/Colors/PackedPixel/Rgba32.cs
+++ /dev/null
@@ -1,398 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp
-{
- using System.Numerics;
- using System.Runtime.CompilerServices;
-
- ///
- /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
- /// The color components are stored in red, green, blue, and alpha order.
- ///
- ///
- /// 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 struct Rgba32 : IPixel, IPackedVector
- {
- ///
- /// The shift count for the red component
- ///
- private const int RedShift = 0;
-
- ///
- /// The shift count for the green component
- ///
- private const int GreenShift = 8;
-
- ///
- /// The shift count for the blue component
- ///
- private const int BlueShift = 16;
-
- ///
- /// The shift count for the alpha component
- ///
- private const int AlphaShift = 24;
-
- ///
- /// The maximum byte value.
- ///
- private static readonly Vector4 MaxBytes = new Vector4(255);
-
- ///
- /// The half vector value.
- ///
- private static readonly Vector4 Half = new Vector4(0.5F);
-
- ///
- /// The packed value.
- ///
- private uint packedValue;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The red component.
- /// The green component.
- /// The blue component.
- /// The alpha component.
- public Rgba32(byte r, byte g, byte b, byte a = 255)
- {
- this.packedValue = Pack(r, g, b, a);
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The red component.
- /// The green component.
- /// The blue component.
- /// The alpha component.
- public Rgba32(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 Rgba32(Vector3 vector)
- {
- this.packedValue = Pack(ref vector);
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- ///
- /// The vector containing the components for the packed vector.
- ///
- public Rgba32(Vector4 vector)
- {
- this.packedValue = Pack(ref vector);
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- ///
- /// The packed value.
- ///
- public Rgba32(uint packed)
- {
- this.packedValue = packed;
- }
-
- ///
- /// Gets or sets the red component.
- ///
- public byte R
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- return (byte)(this.packedValue >> RedShift);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- set
- {
- this.packedValue = this.packedValue & 0xFFFFFF00 | (uint)value << RedShift;
- }
- }
-
- ///
- /// Gets or sets the green component.
- ///
- public byte G
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- return (byte)(this.packedValue >> GreenShift);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- set
- {
- this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << GreenShift;
- }
- }
-
- ///
- /// Gets or sets the blue component.
- ///
- public byte B
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- return (byte)(this.packedValue >> BlueShift);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- set
- {
- this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << BlueShift;
- }
- }
-
- ///
- /// Gets or sets the alpha component.
- ///
- public byte A
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get
- {
- return (byte)(this.packedValue >> AlphaShift);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- set
- {
- this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << AlphaShift;
- }
- }
-
- ///
- public uint PackedValue
- {
- get => this.packedValue;
-
- set => this.packedValue = value;
- }
-
- ///
- /// 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(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(Rgba32 left, Rgba32 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.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(Rgba32 left, Rgba32 right)
- {
- return left.packedValue != right.packedValue;
- }
-
- ///
- /// Creates 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.
- ///
- ///
- /// The .
- ///
- public static Rgba32 FromHex(string hex)
- {
- return ColorBuilder.FromHex(hex);
- }
-
- ///
- public BulkPixelOperations CreateBulkOperations() => new BulkPixelOperations();
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void PackFromBytes(byte x, byte y, byte z, byte w)
- {
- this.packedValue = Pack(x, y, z, w);
- }
-
- ///
- /// Converts the value of this instance to a hexadecimal string.
- ///
- /// A hexadecimal string representation of the value.
- public string ToHex()
- {
- uint hexOrder = Pack(this.A, this.B, this.G, this.R);
- return hexOrder.ToString("X8");
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void ToXyzBytes(byte[] bytes, int startIndex)
- {
- bytes[startIndex] = this.R;
- bytes[startIndex + 1] = this.G;
- bytes[startIndex + 2] = this.B;
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void ToXyzwBytes(byte[] bytes, int startIndex)
- {
- bytes[startIndex] = this.R;
- bytes[startIndex + 1] = this.G;
- bytes[startIndex + 2] = this.B;
- bytes[startIndex + 3] = this.A;
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void ToZyxBytes(byte[] bytes, int startIndex)
- {
- bytes[startIndex] = this.B;
- bytes[startIndex + 1] = this.G;
- bytes[startIndex + 2] = this.R;
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void ToZyxwBytes(byte[] bytes, int startIndex)
- {
- bytes[startIndex] = this.B;
- bytes[startIndex + 1] = this.G;
- bytes[startIndex + 2] = this.R;
- bytes[startIndex + 3] = this.A;
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void PackFromVector4(Vector4 vector)
- {
- this.packedValue = Pack(ref vector);
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Vector4 ToVector4()
- {
- return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes;
- }
-
- ///
- public override bool Equals(object obj)
- {
- return (obj is Rgba32) && this.Equals((Rgba32)obj);
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool Equals(Rgba32 other)
- {
- return this.packedValue == other.packedValue;
- }
-
- ///
- /// Gets a string representation of the packed vector.
- ///
- /// A string representation of the packed vector.
- public override string ToString()
- {
- return this.ToVector4().ToString();
- }
-
- ///
- public override int GetHashCode()
- {
- return this.packedValue.GetHashCode();
- }
-
- ///
- /// Packs a into a uint.
- ///
- /// The vector containing the values to pack.
- /// The containing the packed values.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint Pack(ref Vector4 vector)
- {
- vector *= MaxBytes;
- vector += Half;
- vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
- return (uint)(((byte)vector.X << RedShift)
- | ((byte)vector.Y << GreenShift)
- | ((byte)vector.Z << BlueShift)
- | (byte)vector.W << AlphaShift);
- }
-
- ///
- /// Packs a into a uint.
- ///
- /// The vector containing the values to pack.
- /// The containing the packed values.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static uint Pack(ref Vector3 vector)
- {
- Vector4 value = new Vector4(vector, 1);
- return Pack(ref value);
- }
-
- ///
- /// 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(float x, float y, float z, float w)
- {
- Vector4 value = new Vector4(x, y, z, w);
- return Pack(ref value);
- }
-
- ///
- /// 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);
- }
- }
-}
\ No newline at end of file
diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
index 05fc4094e..f23ca3e5c 100644
--- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
+++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs
@@ -64,7 +64,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk
{
}
- public class ToXyzw_Argb : ToXyzw
+ public class ToXyzw_Argb : ToXyzw
{
}
}
diff --git a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs
index 0b1e6dc7b..d4b9f6f3a 100644
--- a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs
+++ b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs
@@ -58,7 +58,7 @@ namespace ImageSharp.Tests.Colors
}
}
- public class Argb : BulkPixelOperationsTests
+ public class Argb : BulkPixelOperationsTests
{
// For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class:
public Argb(ITestOutputHelper output)
diff --git a/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs b/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs
index 83c02635a..d2c5cf845 100644
--- a/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs
+++ b/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs
@@ -30,7 +30,7 @@ namespace ImageSharp.Tests.Colors
// using float array to work around a bug in xunit corruptint the state of any Vector4 passed as MemberData
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
- yield return new object[] { new Argb(vector4), vector4Components };
+ yield return new object[] { new Argb32(vector4), vector4Components };
yield return new object[] { new Bgra4444(vector4), vector4Components };
yield return new object[] { new Bgra5551(vector4), vector4Components };
yield return new object[] { new Byte4(vector4), vector4Components };
@@ -63,7 +63,7 @@ namespace ImageSharp.Tests.Colors
// using float array to work around a bug in xunit corruptint the state of any Vector4 passed as MemberData
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
- yield return new object[] { new Argb(vector3), vector4Components };
+ yield return new object[] { new Argb32(vector3), vector4Components };
yield return new object[] { new Bgr565(vector3), vector4Components };
}
}
@@ -88,7 +88,7 @@ namespace ImageSharp.Tests.Colors
// using float array to work around a bug in xunit corruptint the state of any Vector4 passed as MemberData
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
- yield return new object[] { new Argb(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
+ yield return new object[] { new Argb32(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
yield return new object[] { new Bgra4444(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
yield return new object[] { new Bgra5551(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
yield return new object[] { new Byte4(vector4.X, vector4.Y, vector4.Z, vector4.W), vector4Components };
@@ -121,7 +121,7 @@ namespace ImageSharp.Tests.Colors
// using float array to work around a bug in xunit corruptint the state of any Vector4 passed as MemberData
float[] vector4Components = new float[] { vector4.X, vector4.Y, vector4.Z, vector4.W };
- yield return new object[] { new Argb(vector3.X, vector3.Y, vector3.Z), vector4Components };
+ yield return new object[] { new Argb32(vector3.X, vector3.Y, vector3.Z), vector4Components };
yield return new object[] { new Bgr565(vector3.X, vector3.Y, vector3.Z), vector4Components };
}
}
diff --git a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs b/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs
index 42481799f..ffb04e8b2 100644
--- a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs
+++ b/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs
@@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Colors
new TheoryData