Browse Source

Merge pull request #179 from JimBobSquarePants/experiments-no-packed-color

Add ColorVector, refactor Color
af/merge-core
James Jackson-South 9 years ago
committed by GitHub
parent
commit
4fe932ad2a
  1. 48
      src/ImageSharp/Colors/Color.BulkOperations.cs
  2. 2
      src/ImageSharp/Colors/Color.Definitions.cs
  3. 32
      src/ImageSharp/Colors/Color.Transforms.cs
  4. 233
      src/ImageSharp/Colors/Color.cs
  5. 27
      src/ImageSharp/Colors/ColorVector.BulkOperations.cs
  6. 728
      src/ImageSharp/Colors/ColorVector.Definitions.cs
  7. 253
      src/ImageSharp/Colors/ColorVector.Transforms.cs
  8. 316
      src/ImageSharp/Colors/ColorVector.cs
  9. 2
      src/ImageSharp/Colors/ColorspaceTransforms.cs
  10. 286
      src/ImageSharp/Colors/NamedColors{TColor}.cs
  11. 40
      src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs
  12. 398
      src/ImageSharp/Colors/PackedPixel/Rgba32.cs
  13. 2
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs
  14. 4
      tests/ImageSharp.Benchmarks/General/ClearBuffer.cs
  15. 21
      tests/ImageSharp.Benchmarks/Samplers/Resize.cs
  16. 6
      tests/ImageSharp.Sandbox46/Program.cs
  17. 38
      tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs
  18. 50
      tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs
  19. 132
      tests/ImageSharp.Tests/Colors/ColorVectorTests.cs
  20. 118
      tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs
  21. 45
      tests/ImageSharp.Tests/Colors/PackedPixelTests.cs
  22. 148
      tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs
  23. 14
      tests/ImageSharp.Tests/Common/BufferSpanTests.cs
  24. 10
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

48
src/ImageSharp/Colors/Color.BulkOperations.cs

@ -10,9 +10,14 @@ namespace ImageSharp
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
/// <content> /// <summary>
/// Conains the definition of <see cref="BulkOperations"/> /// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// </content> /// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public partial struct Color public partial struct Color
{ {
/// <summary> /// <summary>
@ -37,15 +42,12 @@ namespace ImageSharp
/// <cref>https://github.com/dotnet/corefx/issues/15957</cref> /// <cref>https://github.com/dotnet/corefx/issues/15957</cref>
/// </see> /// </see>
/// </remarks> /// </remarks>
internal static unsafe void ToVector4SimdAligned( internal static unsafe void ToVector4SimdAligned(BufferSpan<Color> sourceColors, BufferSpan<Vector4> destVectors, int count)
BufferSpan<Color> sourceColors,
BufferSpan<Vector4> destVectors,
int count)
{ {
if (!Vector.IsHardwareAccelerated) if (!Vector.IsHardwareAccelerated)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
"Color.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); "Color32.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!");
} }
int vecSize = Vector<uint>.Count; int vecSize = Vector<uint>.Count;
@ -125,10 +127,7 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void PackFromXyzBytes( internal override void PackFromXyzBytes(BufferSpan<byte> sourceBytes, BufferSpan<Color> destColors, int count)
BufferSpan<byte> sourceBytes,
BufferSpan<Color> destColors,
int count)
{ {
ref RGB24 sourceRef = ref Unsafe.As<byte, RGB24>(ref sourceBytes.DangerousGetPinnableReference()); ref RGB24 sourceRef = ref Unsafe.As<byte, RGB24>(ref sourceBytes.DangerousGetPinnableReference());
ref Color destRef = ref destColors.DangerousGetPinnableReference(); ref Color destRef = ref destColors.DangerousGetPinnableReference();
@ -159,10 +158,7 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
internal override unsafe void PackFromXyzwBytes( internal override unsafe void PackFromXyzwBytes(BufferSpan<byte> sourceBytes, BufferSpan<Color> destColors, int count)
BufferSpan<byte> sourceBytes,
BufferSpan<Color> destColors,
int count)
{ {
BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Color)); BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Color));
} }
@ -174,10 +170,7 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void PackFromZyxBytes( internal override void PackFromZyxBytes(BufferSpan<byte> sourceBytes, BufferSpan<Color> destColors, int count)
BufferSpan<byte> sourceBytes,
BufferSpan<Color> destColors,
int count)
{ {
ref RGB24 sourceRef = ref Unsafe.As<byte, RGB24>(ref sourceBytes.DangerousGetPinnableReference()); ref RGB24 sourceRef = ref Unsafe.As<byte, RGB24>(ref sourceBytes.DangerousGetPinnableReference());
ref Color destRef = ref destColors.DangerousGetPinnableReference(); ref Color destRef = ref destColors.DangerousGetPinnableReference();
@ -193,10 +186,7 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToZyxBytes( internal override void ToZyxBytes(BufferSpan<Color> sourceColors, BufferSpan<byte> destBytes, int count)
BufferSpan<Color> sourceColors,
BufferSpan<byte> destBytes,
int count)
{ {
ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference();
ref RGB24 destRef = ref Unsafe.As<byte, RGB24>(ref destBytes.DangerousGetPinnableReference()); ref RGB24 destRef = ref Unsafe.As<byte, RGB24>(ref destBytes.DangerousGetPinnableReference());
@ -211,10 +201,7 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void PackFromZyxwBytes( internal override void PackFromZyxwBytes(BufferSpan<byte> sourceBytes, BufferSpan<Color> destColors, int count)
BufferSpan<byte> sourceBytes,
BufferSpan<Color> destColors,
int count)
{ {
ref RGBA32 sourceRef = ref Unsafe.As<byte, RGBA32>(ref sourceBytes.DangerousGetPinnableReference()); ref RGBA32 sourceRef = ref Unsafe.As<byte, RGBA32>(ref sourceBytes.DangerousGetPinnableReference());
ref Color destRef = ref destColors.DangerousGetPinnableReference(); ref Color destRef = ref destColors.DangerousGetPinnableReference();
@ -229,10 +216,7 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
internal override void ToZyxwBytes( internal override void ToZyxwBytes(BufferSpan<Color> sourceColors, BufferSpan<byte> destBytes, int count)
BufferSpan<Color> sourceColors,
BufferSpan<byte> destBytes,
int count)
{ {
ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference();
ref RGBA32 destRef = ref Unsafe.As<byte, RGBA32>(ref destBytes.DangerousGetPinnableReference()); ref RGBA32 destRef = ref Unsafe.As<byte, RGBA32>(ref destBytes.DangerousGetPinnableReference());

2
src/ImageSharp/Colors/ColorDefinitions.cs → src/ImageSharp/Colors/Color.Definitions.cs

@ -1,4 +1,4 @@
// <copyright file="ColorDefinitions.cs" company="James Jackson-South"> // <copyright file="Color.Definitions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>

32
src/ImageSharp/Colors/ColorTransforms.cs → src/ImageSharp/Colors/Color.Transforms.cs

@ -1,4 +1,4 @@
// <copyright file="ColorTransforms.cs" company="James Jackson-South"> // <copyright file="Color.Transforms.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -8,7 +8,7 @@ namespace ImageSharp
using System.Numerics; using System.Numerics;
/// <summary> /// <summary>
/// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// Unpacked 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. /// The color components are stored in red, green, blue, and alpha order.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
@ -28,7 +28,7 @@ namespace ImageSharp
public static Color operator +(Color left, Color right) public static Color operator +(Color left, Color right)
{ {
Vector4 add = left.ToVector4() + right.ToVector4(); Vector4 add = left.ToVector4() + right.ToVector4();
return new Color(Pack(ref add)); return Pack(ref add);
} }
/// <summary> /// <summary>
@ -42,7 +42,7 @@ namespace ImageSharp
public static Color operator -(Color left, Color right) public static Color operator -(Color left, Color right)
{ {
Vector4 sub = left.ToVector4() - right.ToVector4(); Vector4 sub = left.ToVector4() - right.ToVector4();
return new Color(Pack(ref sub)); return Pack(ref sub);
} }
/// <summary> /// <summary>
@ -56,7 +56,7 @@ namespace ImageSharp
public static Color Normal(Color backdrop, Color source) public static Color Normal(Color backdrop, Color source)
{ {
Vector4 normal = Vector4BlendTransforms.Normal(backdrop.ToVector4(), source.ToVector4()); Vector4 normal = Vector4BlendTransforms.Normal(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref normal)); return Pack(ref normal);
} }
/// <summary> /// <summary>
@ -76,7 +76,7 @@ namespace ImageSharp
public static Color Multiply(Color backdrop, Color source) public static Color Multiply(Color backdrop, Color source)
{ {
Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.ToVector4(), source.ToVector4()); Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref multiply)); return Pack(ref multiply);
} }
/// <summary> /// <summary>
@ -95,7 +95,7 @@ namespace ImageSharp
public static Color Screen(Color backdrop, Color source) public static Color Screen(Color backdrop, Color source)
{ {
Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.ToVector4(), source.ToVector4()); Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref subtract)); return Pack(ref subtract);
} }
/// <summary> /// <summary>
@ -110,7 +110,7 @@ namespace ImageSharp
public static Color HardLight(Color backdrop, Color source) public static Color HardLight(Color backdrop, Color source)
{ {
Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.ToVector4(), source.ToVector4()); Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref hardlight)); return Pack(ref hardlight);
} }
/// <summary> /// <summary>
@ -129,7 +129,7 @@ namespace ImageSharp
public static Color Overlay(Color backdrop, Color source) public static Color Overlay(Color backdrop, Color source)
{ {
Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.ToVector4(), source.ToVector4()); Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref overlay)); return Pack(ref overlay);
} }
/// <summary> /// <summary>
@ -144,7 +144,7 @@ namespace ImageSharp
public static Color Darken(Color backdrop, Color source) public static Color Darken(Color backdrop, Color source)
{ {
Vector4 darken = Vector4BlendTransforms.Darken(backdrop.ToVector4(), source.ToVector4()); Vector4 darken = Vector4BlendTransforms.Darken(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref darken)); return Pack(ref darken);
} }
/// <summary> /// <summary>
@ -159,7 +159,7 @@ namespace ImageSharp
public static Color Lighten(Color backdrop, Color source) public static Color Lighten(Color backdrop, Color source)
{ {
Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.ToVector4(), source.ToVector4()); Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref lighten)); return Pack(ref lighten);
} }
/// <summary> /// <summary>
@ -174,7 +174,7 @@ namespace ImageSharp
public static Color SoftLight(Color backdrop, Color source) public static Color SoftLight(Color backdrop, Color source)
{ {
Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.ToVector4(), source.ToVector4()); Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref softlight)); return Pack(ref softlight);
} }
/// <summary> /// <summary>
@ -188,7 +188,7 @@ namespace ImageSharp
public static Color ColorDodge(Color backdrop, Color source) public static Color ColorDodge(Color backdrop, Color source)
{ {
Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.ToVector4(), source.ToVector4()); Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref dodge)); return Pack(ref dodge);
} }
/// <summary> /// <summary>
@ -202,7 +202,7 @@ namespace ImageSharp
public static Color ColorBurn(Color backdrop, Color source) public static Color ColorBurn(Color backdrop, Color source)
{ {
Vector4 burn = Vector4BlendTransforms.Burn(backdrop.ToVector4(), source.ToVector4()); Vector4 burn = Vector4BlendTransforms.Burn(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref burn)); return Pack(ref burn);
} }
/// <summary> /// <summary>
@ -217,7 +217,7 @@ namespace ImageSharp
public static Color Difference(Color backdrop, Color source) public static Color Difference(Color backdrop, Color source)
{ {
Vector4 difference = Vector4BlendTransforms.Difference(backdrop.ToVector4(), source.ToVector4()); Vector4 difference = Vector4BlendTransforms.Difference(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref difference)); return Pack(ref difference);
} }
/// <summary> /// <summary>
@ -232,7 +232,7 @@ namespace ImageSharp
public static Color Exclusion(Color backdrop, Color source) public static Color Exclusion(Color backdrop, Color source)
{ {
Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.ToVector4(), source.ToVector4()); Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.ToVector4(), source.ToVector4());
return new Color(Pack(ref exclusion)); return Pack(ref exclusion);
} }
/// <summary> /// <summary>

233
src/ImageSharp/Colors/Color.cs

@ -5,21 +5,45 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using System.Globalization;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
/// <summary> /// <summary>
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// Unpacked 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. /// The color components are stored in red, green, blue, and alpha order.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, /// 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. /// as it avoids the need to create new values for modification operations.
/// </remarks> /// </remarks>
public partial struct Color : IPixel<Color>, IPackedVector<uint> [StructLayout(LayoutKind.Explicit)]
public partial struct Color : IPixel<Color>
{ {
/// <summary>
/// Gets or sets the red component.
/// </summary>
[FieldOffset(0)]
public byte R;
/// <summary>
/// Gets or sets the green component.
/// </summary>
[FieldOffset(1)]
public byte G;
/// <summary>
/// Gets or sets the blue component.
/// </summary>
[FieldOffset(2)]
public byte B;
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
[FieldOffset(3)]
public byte A;
/// <summary> /// <summary>
/// The shift count for the red component /// The shift count for the red component
/// </summary> /// </summary>
@ -50,11 +74,6 @@ namespace ImageSharp
/// </summary> /// </summary>
private static readonly Vector4 Half = new Vector4(0.5F); private static readonly Vector4 Half = new Vector4(0.5F);
/// <summary>
/// The packed value.
/// </summary>
private uint packedValue;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct. /// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary> /// </summary>
@ -62,10 +81,13 @@ namespace ImageSharp
/// <param name="g">The green component.</param> /// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param> /// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param> /// <param name="a">The alpha component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(byte r, byte g, byte b, byte a = 255) public Color(byte r, byte g, byte b, byte a = 255)
: this()
{ {
this.packedValue = Pack(r, g, b, a); this.R = r;
this.G = g;
this.B = b;
this.A = a;
} }
/// <summary> /// <summary>
@ -75,10 +97,10 @@ namespace ImageSharp
/// <param name="g">The green component.</param> /// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param> /// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param> /// <param name="a">The alpha component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(float r, float g, float b, float a = 1) public Color(float r, float g, float b, float a = 1)
: this()
{ {
this.packedValue = Pack(r, g, b, a); this = Pack(r, g, b, a);
} }
/// <summary> /// <summary>
@ -87,10 +109,10 @@ namespace ImageSharp
/// <param name="vector"> /// <param name="vector">
/// The vector containing the components for the packed vector. /// The vector containing the components for the packed vector.
/// </param> /// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(Vector3 vector) public Color(Vector3 vector)
: this()
{ {
this.packedValue = Pack(ref vector); this = Pack(ref vector);
} }
/// <summary> /// <summary>
@ -99,108 +121,10 @@ namespace ImageSharp
/// <param name="vector"> /// <param name="vector">
/// The vector containing the components for the packed vector. /// The vector containing the components for the packed vector.
/// </param> /// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(Vector4 vector) public Color(Vector4 vector)
: this()
{ {
this.packedValue = Pack(ref vector); this = Pack(ref vector);
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="packed">
/// The packed value.
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Color(uint packed)
{
this.packedValue = packed;
}
/// <summary>
/// Gets or sets the red component.
/// </summary>
public byte R
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> RedShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFFFFFF00 | (uint)value << RedShift;
}
}
/// <summary>
/// Gets or sets the green component.
/// </summary>
public byte G
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> GreenShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << GreenShift;
}
}
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public byte B
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> BlueShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << BlueShift;
}
}
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
public byte A
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> AlphaShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << AlphaShift;
}
}
/// <inheritdoc/>
public uint PackedValue
{
get
{
return this.packedValue;
}
set
{
this.packedValue = value;
}
} }
/// <summary> /// <summary>
@ -218,7 +142,10 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Color left, Color right) public static bool operator ==(Color left, Color right)
{ {
return left.packedValue == right.packedValue; return left.R == right.R
&& left.G == right.G
&& left.B == right.B
&& left.A == right.A;
} }
/// <summary> /// <summary>
@ -232,7 +159,10 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Color left, Color right) public static bool operator !=(Color left, Color right)
{ {
return left.packedValue != right.packedValue; return left.R != right.R
&& left.G != right.G
&& left.B != right.B
&& left.A != right.A;
} }
/// <summary> /// <summary>
@ -251,13 +181,16 @@ namespace ImageSharp
} }
/// <inheritdoc /> /// <inheritdoc />
public BulkPixelOperations<Color> CreateBulkOperations() => new Color.BulkOperations(); public BulkPixelOperations<Color> CreateBulkOperations() => new BulkOperations();
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromBytes(byte x, byte y, byte z, byte w) public void PackFromBytes(byte x, byte y, byte z, byte w)
{ {
this.packedValue = Pack(x, y, z, w); this.R = x;
this.G = y;
this.B = z;
this.A = w;
} }
/// <summary> /// <summary>
@ -312,7 +245,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromVector4(Vector4 vector) public void PackFromVector4(Vector4 vector)
{ {
this.packedValue = Pack(ref vector); this = Pack(ref vector);
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -332,7 +265,10 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Color other) public bool Equals(Color other)
{ {
return this.packedValue == other.packedValue; return this.R == other.R
&& this.G == other.G
&& this.B == other.B
&& this.A == other.A;
} }
/// <summary> /// <summary>
@ -347,33 +283,52 @@ namespace ImageSharp
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override int GetHashCode()
{ {
return this.packedValue.GetHashCode(); unchecked
{
int hashCode = this.R.GetHashCode();
hashCode = (hashCode * 397) ^ this.G.GetHashCode();
hashCode = (hashCode * 397) ^ this.B.GetHashCode();
hashCode = (hashCode * 397) ^ this.A.GetHashCode();
return hashCode;
}
}
/// <summary>
/// Packs the four floats into a <see cref="uint"/>.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
/// <returns>The <see cref="uint"/></returns>
[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);
} }
/// <summary> /// <summary>
/// Packs a <see cref="Vector4"/> into a uint. /// Packs a <see cref="Vector4"/> into a uint.
/// </summary> /// </summary>
/// <param name="vector">The vector containing the values to pack.</param> /// <param name="vector">The vector containing the values to pack.</param>
/// <returns>The <see cref="uint"/> containing the packed values.</returns> /// <returns>The <see cref="Color"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint Pack(ref Vector4 vector) private static Color Pack(ref Vector4 vector)
{ {
vector *= MaxBytes; vector *= MaxBytes;
vector += Half; vector += Half;
vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes); vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes);
return (uint)(((byte)vector.X << RedShift)
| ((byte)vector.Y << GreenShift) return new Color((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W);
| ((byte)vector.Z << BlueShift)
| (byte)vector.W << AlphaShift);
} }
/// <summary> /// <summary>
/// Packs a <see cref="Vector3"/> into a uint. /// Packs a <see cref="Vector3"/> into a uint.
/// </summary> /// </summary>
/// <param name="vector">The vector containing the values to pack.</param> /// <param name="vector">The vector containing the values to pack.</param>
/// <returns>The <see cref="uint"/> containing the packed values.</returns> /// <returns>The <see cref="Color"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint Pack(ref Vector3 vector) private static Color Pack(ref Vector3 vector)
{ {
Vector4 value = new Vector4(vector, 1); Vector4 value = new Vector4(vector, 1);
return Pack(ref value); return Pack(ref value);
@ -386,26 +341,12 @@ namespace ImageSharp
/// <param name="y">The y-component</param> /// <param name="y">The y-component</param>
/// <param name="z">The z-component</param> /// <param name="z">The z-component</param>
/// <param name="w">The w-component</param> /// <param name="w">The w-component</param>
/// <returns>The <see cref="uint"/></returns> /// <returns>The <see cref="Color"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint Pack(float x, float y, float z, float w) private static Color Pack(float x, float y, float z, float w)
{ {
Vector4 value = new Vector4(x, y, z, w); Vector4 value = new Vector4(x, y, z, w);
return Pack(ref value); return Pack(ref value);
} }
/// <summary>
/// Packs the four floats into a <see cref="uint"/>.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
/// <returns>The <see cref="uint"/></returns>
[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);
}
} }
} }

27
src/ImageSharp/Colors/ColorVector.BulkOperations.cs

@ -0,0 +1,27 @@
namespace ImageSharp
{
using System.Numerics;
/// <summary>
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public partial struct ColorVector
{
/// <summary>
/// <see cref="BulkPixelOperations{TColor}"/> implementation optimized for <see cref="ColorVector"/>.
/// </summary>
internal class BulkOperations : BulkPixelOperations<ColorVector>
{
/// <inheritdoc />
internal override unsafe void ToVector4(BufferSpan<ColorVector> sourceColors, BufferSpan<Vector4> destVectors, int count)
{
BufferSpan.Copy(sourceColors.AsBytes(), destVectors.AsBytes(), count * sizeof(Vector4));
}
}
}
}

728
src/ImageSharp/Colors/ColorVector.Definitions.cs

@ -0,0 +1,728 @@
// <copyright file="ColorVector.Definitions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
/// <summary>
/// Unpacked 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.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public partial struct ColorVector
{
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0F8FF.
/// </summary>
public static readonly ColorVector AliceBlue = NamedColors<ColorVector>.AliceBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAEBD7.
/// </summary>
public static readonly ColorVector AntiqueWhite = NamedColors<ColorVector>.AntiqueWhite;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly ColorVector Aqua = NamedColors<ColorVector>.Aqua;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7FFFD4.
/// </summary>
public static readonly ColorVector Aquamarine = NamedColors<ColorVector>.Aquamarine;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0FFFF.
/// </summary>
public static readonly ColorVector Azure = NamedColors<ColorVector>.Azure;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5F5DC.
/// </summary>
public static readonly ColorVector Beige = NamedColors<ColorVector>.Beige;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4C4.
/// </summary>
public static readonly ColorVector Bisque = NamedColors<ColorVector>.Bisque;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #000000.
/// </summary>
public static readonly ColorVector Black = NamedColors<ColorVector>.Black;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFEBCD.
/// </summary>
public static readonly ColorVector BlanchedAlmond = NamedColors<ColorVector>.BlanchedAlmond;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #0000FF.
/// </summary>
public static readonly ColorVector Blue = NamedColors<ColorVector>.Blue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8A2BE2.
/// </summary>
public static readonly ColorVector BlueViolet = NamedColors<ColorVector>.BlueViolet;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A52A2A.
/// </summary>
public static readonly ColorVector Brown = NamedColors<ColorVector>.Brown;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DEB887.
/// </summary>
public static readonly ColorVector BurlyWood = NamedColors<ColorVector>.BurlyWood;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #5F9EA0.
/// </summary>
public static readonly ColorVector CadetBlue = NamedColors<ColorVector>.CadetBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7FFF00.
/// </summary>
public static readonly ColorVector Chartreuse = NamedColors<ColorVector>.Chartreuse;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D2691E.
/// </summary>
public static readonly ColorVector Chocolate = NamedColors<ColorVector>.Chocolate;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF7F50.
/// </summary>
public static readonly ColorVector Coral = NamedColors<ColorVector>.Coral;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6495ED.
/// </summary>
public static readonly ColorVector CornflowerBlue = NamedColors<ColorVector>.CornflowerBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF8DC.
/// </summary>
public static readonly ColorVector Cornsilk = NamedColors<ColorVector>.Cornsilk;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DC143C.
/// </summary>
public static readonly ColorVector Crimson = NamedColors<ColorVector>.Crimson;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly ColorVector Cyan = NamedColors<ColorVector>.Cyan;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00008B.
/// </summary>
public static readonly ColorVector DarkBlue = NamedColors<ColorVector>.DarkBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008B8B.
/// </summary>
public static readonly ColorVector DarkCyan = NamedColors<ColorVector>.DarkCyan;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B8860B.
/// </summary>
public static readonly ColorVector DarkGoldenrod = NamedColors<ColorVector>.DarkGoldenrod;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A9A9A9.
/// </summary>
public static readonly ColorVector DarkGray = NamedColors<ColorVector>.DarkGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #006400.
/// </summary>
public static readonly ColorVector DarkGreen = NamedColors<ColorVector>.DarkGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BDB76B.
/// </summary>
public static readonly ColorVector DarkKhaki = NamedColors<ColorVector>.DarkKhaki;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B008B.
/// </summary>
public static readonly ColorVector DarkMagenta = NamedColors<ColorVector>.DarkMagenta;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #556B2F.
/// </summary>
public static readonly ColorVector DarkOliveGreen = NamedColors<ColorVector>.DarkOliveGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF8C00.
/// </summary>
public static readonly ColorVector DarkOrange = NamedColors<ColorVector>.DarkOrange;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9932CC.
/// </summary>
public static readonly ColorVector DarkOrchid = NamedColors<ColorVector>.DarkOrchid;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B0000.
/// </summary>
public static readonly ColorVector DarkRed = NamedColors<ColorVector>.DarkRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E9967A.
/// </summary>
public static readonly ColorVector DarkSalmon = NamedColors<ColorVector>.DarkSalmon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8FBC8B.
/// </summary>
public static readonly ColorVector DarkSeaGreen = NamedColors<ColorVector>.DarkSeaGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #483D8B.
/// </summary>
public static readonly ColorVector DarkSlateBlue = NamedColors<ColorVector>.DarkSlateBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #2F4F4F.
/// </summary>
public static readonly ColorVector DarkSlateGray = NamedColors<ColorVector>.DarkSlateGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00CED1.
/// </summary>
public static readonly ColorVector DarkTurquoise = NamedColors<ColorVector>.DarkTurquoise;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9400D3.
/// </summary>
public static readonly ColorVector DarkViolet = NamedColors<ColorVector>.DarkViolet;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF1493.
/// </summary>
public static readonly ColorVector DeepPink = NamedColors<ColorVector>.DeepPink;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00BFFF.
/// </summary>
public static readonly ColorVector DeepSkyBlue = NamedColors<ColorVector>.DeepSkyBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #696969.
/// </summary>
public static readonly ColorVector DimGray = NamedColors<ColorVector>.DimGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #1E90FF.
/// </summary>
public static readonly ColorVector DodgerBlue = NamedColors<ColorVector>.DodgerBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B22222.
/// </summary>
public static readonly ColorVector Firebrick = NamedColors<ColorVector>.Firebrick;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFAF0.
/// </summary>
public static readonly ColorVector FloralWhite = NamedColors<ColorVector>.FloralWhite;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #228B22.
/// </summary>
public static readonly ColorVector ForestGreen = NamedColors<ColorVector>.ForestGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly ColorVector Fuchsia = NamedColors<ColorVector>.Fuchsia;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DCDCDC.
/// </summary>
public static readonly ColorVector Gainsboro = NamedColors<ColorVector>.Gainsboro;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F8F8FF.
/// </summary>
public static readonly ColorVector GhostWhite = NamedColors<ColorVector>.GhostWhite;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFD700.
/// </summary>
public static readonly ColorVector Gold = NamedColors<ColorVector>.Gold;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DAA520.
/// </summary>
public static readonly ColorVector Goldenrod = NamedColors<ColorVector>.Goldenrod;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #808080.
/// </summary>
public static readonly ColorVector Gray = NamedColors<ColorVector>.Gray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008000.
/// </summary>
public static readonly ColorVector Green = NamedColors<ColorVector>.Green;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #ADFF2F.
/// </summary>
public static readonly ColorVector GreenYellow = NamedColors<ColorVector>.GreenYellow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0FFF0.
/// </summary>
public static readonly ColorVector Honeydew = NamedColors<ColorVector>.Honeydew;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF69B4.
/// </summary>
public static readonly ColorVector HotPink = NamedColors<ColorVector>.HotPink;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #CD5C5C.
/// </summary>
public static readonly ColorVector IndianRed = NamedColors<ColorVector>.IndianRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4B0082.
/// </summary>
public static readonly ColorVector Indigo = NamedColors<ColorVector>.Indigo;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFF0.
/// </summary>
public static readonly ColorVector Ivory = NamedColors<ColorVector>.Ivory;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0E68C.
/// </summary>
public static readonly ColorVector Khaki = NamedColors<ColorVector>.Khaki;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E6E6FA.
/// </summary>
public static readonly ColorVector Lavender = NamedColors<ColorVector>.Lavender;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF0F5.
/// </summary>
public static readonly ColorVector LavenderBlush = NamedColors<ColorVector>.LavenderBlush;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7CFC00.
/// </summary>
public static readonly ColorVector LawnGreen = NamedColors<ColorVector>.LawnGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFACD.
/// </summary>
public static readonly ColorVector LemonChiffon = NamedColors<ColorVector>.LemonChiffon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #ADD8E6.
/// </summary>
public static readonly ColorVector LightBlue = NamedColors<ColorVector>.LightBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F08080.
/// </summary>
public static readonly ColorVector LightCoral = NamedColors<ColorVector>.LightCoral;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E0FFFF.
/// </summary>
public static readonly ColorVector LightCyan = NamedColors<ColorVector>.LightCyan;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAFAD2.
/// </summary>
public static readonly ColorVector LightGoldenrodYellow = NamedColors<ColorVector>.LightGoldenrodYellow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D3D3D3.
/// </summary>
public static readonly ColorVector LightGray = NamedColors<ColorVector>.LightGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #90EE90.
/// </summary>
public static readonly ColorVector LightGreen = NamedColors<ColorVector>.LightGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFB6C1.
/// </summary>
public static readonly ColorVector LightPink = NamedColors<ColorVector>.LightPink;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFA07A.
/// </summary>
public static readonly ColorVector LightSalmon = NamedColors<ColorVector>.LightSalmon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #20B2AA.
/// </summary>
public static readonly ColorVector LightSeaGreen = NamedColors<ColorVector>.LightSeaGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #87CEFA.
/// </summary>
public static readonly ColorVector LightSkyBlue = NamedColors<ColorVector>.LightSkyBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #778899.
/// </summary>
public static readonly ColorVector LightSlateGray = NamedColors<ColorVector>.LightSlateGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B0C4DE.
/// </summary>
public static readonly ColorVector LightSteelBlue = NamedColors<ColorVector>.LightSteelBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFE0.
/// </summary>
public static readonly ColorVector LightYellow = NamedColors<ColorVector>.LightYellow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FF00.
/// </summary>
public static readonly ColorVector Lime = NamedColors<ColorVector>.Lime;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #32CD32.
/// </summary>
public static readonly ColorVector LimeGreen = NamedColors<ColorVector>.LimeGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAF0E6.
/// </summary>
public static readonly ColorVector Linen = NamedColors<ColorVector>.Linen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly ColorVector Magenta = NamedColors<ColorVector>.Magenta;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #800000.
/// </summary>
public static readonly ColorVector Maroon = NamedColors<ColorVector>.Maroon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #66CDAA.
/// </summary>
public static readonly ColorVector MediumAquamarine = NamedColors<ColorVector>.MediumAquamarine;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #0000CD.
/// </summary>
public static readonly ColorVector MediumBlue = NamedColors<ColorVector>.MediumBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BA55D3.
/// </summary>
public static readonly ColorVector MediumOrchid = NamedColors<ColorVector>.MediumOrchid;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9370DB.
/// </summary>
public static readonly ColorVector MediumPurple = NamedColors<ColorVector>.MediumPurple;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #3CB371.
/// </summary>
public static readonly ColorVector MediumSeaGreen = NamedColors<ColorVector>.MediumSeaGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7B68EE.
/// </summary>
public static readonly ColorVector MediumSlateBlue = NamedColors<ColorVector>.MediumSlateBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FA9A.
/// </summary>
public static readonly ColorVector MediumSpringGreen = NamedColors<ColorVector>.MediumSpringGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #48D1CC.
/// </summary>
public static readonly ColorVector MediumTurquoise = NamedColors<ColorVector>.MediumTurquoise;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #C71585.
/// </summary>
public static readonly ColorVector MediumVioletRed = NamedColors<ColorVector>.MediumVioletRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #191970.
/// </summary>
public static readonly ColorVector MidnightBlue = NamedColors<ColorVector>.MidnightBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5FFFA.
/// </summary>
public static readonly ColorVector MintCream = NamedColors<ColorVector>.MintCream;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4E1.
/// </summary>
public static readonly ColorVector MistyRose = NamedColors<ColorVector>.MistyRose;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4B5.
/// </summary>
public static readonly ColorVector Moccasin = NamedColors<ColorVector>.Moccasin;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFDEAD.
/// </summary>
public static readonly ColorVector NavajoWhite = NamedColors<ColorVector>.NavajoWhite;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #000080.
/// </summary>
public static readonly ColorVector Navy = NamedColors<ColorVector>.Navy;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FDF5E6.
/// </summary>
public static readonly ColorVector OldLace = NamedColors<ColorVector>.OldLace;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #808000.
/// </summary>
public static readonly ColorVector Olive = NamedColors<ColorVector>.Olive;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6B8E23.
/// </summary>
public static readonly ColorVector OliveDrab = NamedColors<ColorVector>.OliveDrab;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFA500.
/// </summary>
public static readonly ColorVector Orange = NamedColors<ColorVector>.Orange;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF4500.
/// </summary>
public static readonly ColorVector OrangeRed = NamedColors<ColorVector>.OrangeRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DA70D6.
/// </summary>
public static readonly ColorVector Orchid = NamedColors<ColorVector>.Orchid;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #EEE8AA.
/// </summary>
public static readonly ColorVector PaleGoldenrod = NamedColors<ColorVector>.PaleGoldenrod;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #98FB98.
/// </summary>
public static readonly ColorVector PaleGreen = NamedColors<ColorVector>.PaleGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #AFEEEE.
/// </summary>
public static readonly ColorVector PaleTurquoise = NamedColors<ColorVector>.PaleTurquoise;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DB7093.
/// </summary>
public static readonly ColorVector PaleVioletRed = NamedColors<ColorVector>.PaleVioletRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFEFD5.
/// </summary>
public static readonly ColorVector PapayaWhip = NamedColors<ColorVector>.PapayaWhip;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFDAB9.
/// </summary>
public static readonly ColorVector PeachPuff = NamedColors<ColorVector>.PeachPuff;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #CD853F.
/// </summary>
public static readonly ColorVector Peru = NamedColors<ColorVector>.Peru;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFC0CB.
/// </summary>
public static readonly ColorVector Pink = NamedColors<ColorVector>.Pink;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DDA0DD.
/// </summary>
public static readonly ColorVector Plum = NamedColors<ColorVector>.Plum;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B0E0E6.
/// </summary>
public static readonly ColorVector PowderBlue = NamedColors<ColorVector>.PowderBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #800080.
/// </summary>
public static readonly ColorVector Purple = NamedColors<ColorVector>.Purple;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #663399.
/// </summary>
public static readonly ColorVector RebeccaPurple = NamedColors<ColorVector>.RebeccaPurple;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF0000.
/// </summary>
public static readonly ColorVector Red = NamedColors<ColorVector>.Red;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BC8F8F.
/// </summary>
public static readonly ColorVector RosyBrown = NamedColors<ColorVector>.RosyBrown;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4169E1.
/// </summary>
public static readonly ColorVector RoyalBlue = NamedColors<ColorVector>.RoyalBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B4513.
/// </summary>
public static readonly ColorVector SaddleBrown = NamedColors<ColorVector>.SaddleBrown;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FA8072.
/// </summary>
public static readonly ColorVector Salmon = NamedColors<ColorVector>.Salmon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F4A460.
/// </summary>
public static readonly ColorVector SandyBrown = NamedColors<ColorVector>.SandyBrown;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #2E8B57.
/// </summary>
public static readonly ColorVector SeaGreen = NamedColors<ColorVector>.SeaGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF5EE.
/// </summary>
public static readonly ColorVector SeaShell = NamedColors<ColorVector>.SeaShell;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A0522D.
/// </summary>
public static readonly ColorVector Sienna = NamedColors<ColorVector>.Sienna;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #C0C0C0.
/// </summary>
public static readonly ColorVector Silver = NamedColors<ColorVector>.Silver;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #87CEEB.
/// </summary>
public static readonly ColorVector SkyBlue = NamedColors<ColorVector>.SkyBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6A5ACD.
/// </summary>
public static readonly ColorVector SlateBlue = NamedColors<ColorVector>.SlateBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #708090.
/// </summary>
public static readonly ColorVector SlateGray = NamedColors<ColorVector>.SlateGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFAFA.
/// </summary>
public static readonly ColorVector Snow = NamedColors<ColorVector>.Snow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FF7F.
/// </summary>
public static readonly ColorVector SpringGreen = NamedColors<ColorVector>.SpringGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4682B4.
/// </summary>
public static readonly ColorVector SteelBlue = NamedColors<ColorVector>.SteelBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D2B48C.
/// </summary>
public static readonly ColorVector Tan = NamedColors<ColorVector>.Tan;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008080.
/// </summary>
public static readonly ColorVector Teal = NamedColors<ColorVector>.Teal;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D8BFD8.
/// </summary>
public static readonly ColorVector Thistle = NamedColors<ColorVector>.Thistle;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF6347.
/// </summary>
public static readonly ColorVector Tomato = NamedColors<ColorVector>.Tomato;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly ColorVector Transparent = NamedColors<ColorVector>.Transparent;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #40E0D0.
/// </summary>
public static readonly ColorVector Turquoise = NamedColors<ColorVector>.Turquoise;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #EE82EE.
/// </summary>
public static readonly ColorVector Violet = NamedColors<ColorVector>.Violet;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5DEB3.
/// </summary>
public static readonly ColorVector Wheat = NamedColors<ColorVector>.Wheat;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly ColorVector White = NamedColors<ColorVector>.White;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5F5F5.
/// </summary>
public static readonly ColorVector WhiteSmoke = NamedColors<ColorVector>.WhiteSmoke;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFF00.
/// </summary>
public static readonly ColorVector Yellow = NamedColors<ColorVector>.Yellow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9ACD32.
/// </summary>
public static readonly ColorVector YellowGreen = NamedColors<ColorVector>.YellowGreen;
}
}

253
src/ImageSharp/Colors/ColorVector.Transforms.cs

@ -0,0 +1,253 @@
// <copyright file="ColorVector.Transforms.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System.Numerics;
/// <summary>
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public partial struct ColorVector
{
/// <summary>
/// Adds the second color to the first.
/// </summary>
/// <param name="left">The first source color.</param>
/// <param name="right">The second source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector operator +(ColorVector left, ColorVector right)
{
return new ColorVector(left.backingVector + right.backingVector);
}
/// <summary>
/// Subtracts the second color from the first.
/// </summary>
/// <param name="left">The first source color.</param>
/// <param name="right">The second source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector operator -(ColorVector left, ColorVector right)
{
return new ColorVector(left.backingVector - right.backingVector);
}
/// <summary>
/// The blending formula simply selects the source color.
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector Normal(ColorVector backdrop, ColorVector source)
{
Vector4 normal = Vector4BlendTransforms.Normal(backdrop.backingVector, source.backingVector);
return new ColorVector(normal);
}
/// <summary>
/// Blends two colors by multiplication.
/// <remarks>
/// The source color is multiplied by the destination color and replaces the destination.
/// The resultant color is always at least as dark as either the source or destination color.
/// Multiplying any color with black results in black. Multiplying any color with white preserves the
/// original color.
/// </remarks>
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector Multiply(ColorVector backdrop, ColorVector source)
{
Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.backingVector, source.backingVector);
return new ColorVector(multiply);
}
/// <summary>
/// Multiplies the complements of the backdrop and source color values, then complements the result.
/// <remarks>
/// The result color is always at least as light as either of the two constituent colors. Screening any
/// color with white produces white; screening with black leaves the original color unchanged.
/// The effect is similar to projecting multiple photographic slides simultaneously onto a single screen.
/// </remarks>
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector Screen(ColorVector backdrop, ColorVector source)
{
Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.backingVector, source.backingVector);
return new ColorVector(subtract);
}
/// <summary>
/// Multiplies or screens the colors, depending on the source color value. The effect is similar to
/// shining a harsh spotlight on the backdrop.
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector HardLight(ColorVector backdrop, ColorVector source)
{
Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.backingVector, source.backingVector);
return new ColorVector(hardlight);
}
/// <summary>
/// Multiplies or screens the colors, depending on the backdrop color value.
/// <remarks>
/// Source colors overlay the backdrop while preserving its highlights and shadows.
/// The backdrop color is not replaced but is mixed with the source color to reflect the lightness or darkness
/// of the backdrop.
/// </remarks>
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector Overlay(ColorVector backdrop, ColorVector source)
{
Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.backingVector, source.backingVector);
return new ColorVector(overlay);
}
/// <summary>
/// Selects the darker of the backdrop and source colors.
/// The backdrop is replaced with the source where the source is darker; otherwise, it is left unchanged.
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector Darken(ColorVector backdrop, ColorVector source)
{
Vector4 darken = Vector4BlendTransforms.Darken(backdrop.backingVector, source.backingVector);
return new ColorVector(darken);
}
/// <summary>
/// Selects the lighter of the backdrop and source colors.
/// The backdrop is replaced with the source where the source is lighter; otherwise, it is left unchanged.
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector Lighten(ColorVector backdrop, ColorVector source)
{
Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.backingVector, source.backingVector);
return new ColorVector(lighten);
}
/// <summary>
/// Darkens or lightens the colors, depending on the source color value. The effect is similar to shining
/// a diffused spotlight on the backdrop.
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector SoftLight(ColorVector backdrop, ColorVector source)
{
Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.backingVector, source.backingVector);
return new ColorVector(softlight);
}
/// <summary>
/// Brightens the backdrop color to reflect the source color. Painting with black produces no changes.
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector ColorDodge(ColorVector backdrop, ColorVector source)
{
Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.backingVector, source.backingVector);
return new ColorVector(dodge);
}
/// <summary>
/// Darkens the backdrop color to reflect the source color. Painting with white produces no change.
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector ColorBurn(ColorVector backdrop, ColorVector source)
{
Vector4 burn = Vector4BlendTransforms.Burn(backdrop.backingVector, source.backingVector);
return new ColorVector(burn);
}
/// <summary>
/// Subtracts the darker of the two constituent colors from the lighter color.
/// Painting with white inverts the backdrop color; painting with black produces no change.
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector Difference(ColorVector backdrop, ColorVector source)
{
Vector4 difference = Vector4BlendTransforms.Difference(backdrop.backingVector, source.backingVector);
return new ColorVector(difference);
}
/// <summary>
/// Produces an effect similar to that of the <see cref="Difference"/> mode but lower in contrast. Painting with white
/// inverts the backdrop color; painting with black produces no change
/// </summary>
/// <param name="backdrop">The backdrop color.</param>
/// <param name="source">The source color.</param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector Exclusion(ColorVector backdrop, ColorVector source)
{
Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.backingVector, source.backingVector);
return new ColorVector(exclusion);
}
/// <summary>
/// Linearly interpolates from one color to another based on the given weighting.
/// </summary>
/// <param name="from">The first color value.</param>
/// <param name="to">The second color value.</param>
/// <param name="amount">
/// A value between 0 and 1 indicating the weight of the second source vector.
/// At amount = 0, "from" is returned, at amount = 1, "to" is returned.
/// </param>
/// <returns>
/// The <see cref="ColorVector"/>
/// </returns>
public static ColorVector Lerp(ColorVector from, ColorVector to, float amount)
{
return new ColorVector(Vector4.Lerp(from.backingVector, to.backingVector, amount));
}
}
}

316
src/ImageSharp/Colors/ColorVector.cs

@ -0,0 +1,316 @@
// <copyright file="ColorVector.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public partial struct ColorVector : IPixel<ColorVector>
{
/// <summary>
/// The maximum byte value.
/// </summary>
private static readonly Vector4 MaxBytes = new Vector4(255);
/// <summary>
/// The half vector value.
/// </summary>
private static readonly Vector4 Half = new Vector4(0.5F);
/// <summary>
/// The backing vector for SIMD support.
/// </summary>
private Vector4 backingVector;
/// <summary>
/// Initializes a new instance of the <see cref="ColorVector"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public ColorVector(byte r, byte g, byte b, byte a = 255)
: this()
{
this.backingVector = new Vector4(r, g, b, a) / MaxBytes;
}
/// <summary>
/// Initializes a new instance of the <see cref="ColorVector"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public ColorVector(float r, float g, float b, float a = 1)
: this()
{
this.backingVector = new Vector4(r, g, b, a);
}
/// <summary>
/// Initializes a new instance of the <see cref="ColorVector"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
public ColorVector(Vector3 vector)
: this()
{
this.backingVector = new Vector4(vector, 1);
}
/// <summary>
/// Initializes a new instance of the <see cref="ColorVector"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
public ColorVector(Vector4 vector)
: this()
{
this.backingVector = vector;
}
/// <summary>
/// Gets or sets the red component.
/// </summary>
public float R
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.backingVector.X;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.backingVector.X = value;
}
}
/// <summary>
/// Gets or sets the green component.
/// </summary>
public float G
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.backingVector.Y;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.backingVector.Y = value;
}
}
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public float B
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.backingVector.Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.backingVector.Z = value;
}
}
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
public float A
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.backingVector.W;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.backingVector.W = value;
}
}
/// <summary>
/// Compares two <see cref="ColorVector"/> objects for equality.
/// </summary>
/// <param name="left">
/// The <see cref="ColorVector"/> on the left side of the operand.
/// </param>
/// <param name="right">
/// The <see cref="ColorVector"/> on the right side of the operand.
/// </param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(ColorVector left, ColorVector right)
{
return left.backingVector == right.backingVector;
}
/// <summary>
/// Compares two <see cref="ColorVector"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="ColorVector"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="ColorVector"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(ColorVector left, ColorVector right)
{
return left.backingVector != right.backingVector;
}
/// <summary>
/// Creates a new instance of the <see cref="ColorVector"/> struct.
/// </summary>
/// <param name="hex">
/// The hexadecimal representation of the combined color components arranged
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </param>
/// <returns>
/// The <see cref="ColorVector"/>.
/// </returns>
public static ColorVector FromHex(string hex)
{
return ColorBuilder<ColorVector>.FromHex(hex);
}
/// <inheritdoc />
public BulkPixelOperations<ColorVector> CreateBulkOperations() => new ColorVector.BulkOperations();
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromBytes(byte x, byte y, byte z, byte w)
{
this.backingVector = new Vector4(x, y, z, w) / MaxBytes;
}
/// <summary>
/// Converts the value of this instance to a hexadecimal string.
/// </summary>
/// <returns>A hexadecimal string representation of the value.</returns>
public string ToHex()
{
// Hex is RRGGBBAA
Vector4 vector = this.backingVector * MaxBytes;
vector += Half;
uint hexOrder = (uint)((byte)vector.W | (byte)vector.Z << 8 | (byte)vector.Y << 16 | (byte)vector.X << 24);
return hexOrder.ToString("X8");
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToXyzBytes(byte[] bytes, int startIndex)
{
Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes;
vector += Half;
bytes[startIndex] = (byte)vector.X;
bytes[startIndex + 1] = (byte)vector.Y;
bytes[startIndex + 2] = (byte)vector.Z;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToXyzwBytes(byte[] bytes, int startIndex)
{
Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes;
vector += Half;
bytes[startIndex] = (byte)vector.X;
bytes[startIndex + 1] = (byte)vector.Y;
bytes[startIndex + 2] = (byte)vector.Z;
bytes[startIndex + 3] = (byte)vector.W;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToZyxBytes(byte[] bytes, int startIndex)
{
Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes;
vector += Half;
bytes[startIndex] = (byte)vector.Z;
bytes[startIndex + 1] = (byte)vector.Y;
bytes[startIndex + 2] = (byte)vector.X;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToZyxwBytes(byte[] bytes, int startIndex)
{
Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes;
vector += Half;
bytes[startIndex] = (byte)vector.Z;
bytes[startIndex + 1] = (byte)vector.Y;
bytes[startIndex + 2] = (byte)vector.X;
bytes[startIndex + 3] = (byte)vector.W;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromVector4(Vector4 vector)
{
this.backingVector = vector;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4 ToVector4()
{
return this.backingVector;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
return (obj is ColorVector) && this.Equals((ColorVector)obj);
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(ColorVector other)
{
return this.backingVector == other.backingVector;
}
/// <summary>
/// Gets a string representation of the packed vector.
/// </summary>
/// <returns>A string representation of the packed vector.</returns>
public override string ToString()
{
return this.ToVector4().ToString();
}
/// <inheritdoc/>
public override int GetHashCode()
{
return this.backingVector.GetHashCode();
}
}
}

2
src/ImageSharp/Colors/ColorspaceTransforms.cs

@ -10,7 +10,7 @@ namespace ImageSharp
using Colors.Spaces; using Colors.Spaces;
/// <summary> /// <summary>
/// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// Unpacked 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. /// The color components are stored in red, green, blue, and alpha order.
/// </summary> /// </summary>
/// <remarks> /// <remarks>

286
src/ImageSharp/Colors/NamedColors{TColor}.cs

@ -8,719 +8,719 @@ namespace ImageSharp
using System; using System;
/// <summary> /// <summary>
/// A set of named colors mapped to the provided Color space. /// A set of named colors mapped to the provided color space.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TColor">The type of the color.</typeparam>
public static class NamedColors<TColor> public static class NamedColors<TColor>
where TColor : struct, IPixel<TColor> where TColor : struct, IPixel<TColor>
{ {
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0F8FF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F0F8FF.
/// </summary> /// </summary>
public static readonly TColor AliceBlue = ColorBuilder<TColor>.FromRGBA(240, 248, 255, 255); public static readonly TColor AliceBlue = ColorBuilder<TColor>.FromRGBA(240, 248, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FAEBD7. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FAEBD7.
/// </summary> /// </summary>
public static readonly TColor AntiqueWhite = ColorBuilder<TColor>.FromRGBA(250, 235, 215, 255); public static readonly TColor AntiqueWhite = ColorBuilder<TColor>.FromRGBA(250, 235, 215, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FFFF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary> /// </summary>
public static readonly TColor Aqua = ColorBuilder<TColor>.FromRGBA(0, 255, 255, 255); public static readonly TColor Aqua = ColorBuilder<TColor>.FromRGBA(0, 255, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7FFFD4. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #7FFFD4.
/// </summary> /// </summary>
public static readonly TColor Aquamarine = ColorBuilder<TColor>.FromRGBA(127, 255, 212, 255); public static readonly TColor Aquamarine = ColorBuilder<TColor>.FromRGBA(127, 255, 212, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0FFFF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F0FFFF.
/// </summary> /// </summary>
public static readonly TColor Azure = ColorBuilder<TColor>.FromRGBA(240, 255, 255, 255); public static readonly TColor Azure = ColorBuilder<TColor>.FromRGBA(240, 255, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5F5DC. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F5F5DC.
/// </summary> /// </summary>
public static readonly TColor Beige = ColorBuilder<TColor>.FromRGBA(245, 245, 220, 255); public static readonly TColor Beige = ColorBuilder<TColor>.FromRGBA(245, 245, 220, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFE4C4. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFE4C4.
/// </summary> /// </summary>
public static readonly TColor Bisque = ColorBuilder<TColor>.FromRGBA(255, 228, 196, 255); public static readonly TColor Bisque = ColorBuilder<TColor>.FromRGBA(255, 228, 196, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #000000. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #000000.
/// </summary> /// </summary>
public static readonly TColor Black = ColorBuilder<TColor>.FromRGBA(0, 0, 0, 255); public static readonly TColor Black = ColorBuilder<TColor>.FromRGBA(0, 0, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFEBCD. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFEBCD.
/// </summary> /// </summary>
public static readonly TColor BlanchedAlmond = ColorBuilder<TColor>.FromRGBA(255, 235, 205, 255); public static readonly TColor BlanchedAlmond = ColorBuilder<TColor>.FromRGBA(255, 235, 205, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #0000FF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #0000FF.
/// </summary> /// </summary>
public static readonly TColor Blue = ColorBuilder<TColor>.FromRGBA(0, 0, 255, 255); public static readonly TColor Blue = ColorBuilder<TColor>.FromRGBA(0, 0, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8A2BE2. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8A2BE2.
/// </summary> /// </summary>
public static readonly TColor BlueViolet = ColorBuilder<TColor>.FromRGBA(138, 43, 226, 255); public static readonly TColor BlueViolet = ColorBuilder<TColor>.FromRGBA(138, 43, 226, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A52A2A. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #A52A2A.
/// </summary> /// </summary>
public static readonly TColor Brown = ColorBuilder<TColor>.FromRGBA(165, 42, 42, 255); public static readonly TColor Brown = ColorBuilder<TColor>.FromRGBA(165, 42, 42, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DEB887. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DEB887.
/// </summary> /// </summary>
public static readonly TColor BurlyWood = ColorBuilder<TColor>.FromRGBA(222, 184, 135, 255); public static readonly TColor BurlyWood = ColorBuilder<TColor>.FromRGBA(222, 184, 135, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #5F9EA0. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #5F9EA0.
/// </summary> /// </summary>
public static readonly TColor CadetBlue = ColorBuilder<TColor>.FromRGBA(95, 158, 160, 255); public static readonly TColor CadetBlue = ColorBuilder<TColor>.FromRGBA(95, 158, 160, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7FFF00. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #7FFF00.
/// </summary> /// </summary>
public static readonly TColor Chartreuse = ColorBuilder<TColor>.FromRGBA(127, 255, 0, 255); public static readonly TColor Chartreuse = ColorBuilder<TColor>.FromRGBA(127, 255, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D2691E. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #D2691E.
/// </summary> /// </summary>
public static readonly TColor Chocolate = ColorBuilder<TColor>.FromRGBA(210, 105, 30, 255); public static readonly TColor Chocolate = ColorBuilder<TColor>.FromRGBA(210, 105, 30, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF7F50. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF7F50.
/// </summary> /// </summary>
public static readonly TColor Coral = ColorBuilder<TColor>.FromRGBA(255, 127, 80, 255); public static readonly TColor Coral = ColorBuilder<TColor>.FromRGBA(255, 127, 80, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6495ED. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #6495ED.
/// </summary> /// </summary>
public static readonly TColor CornflowerBlue = ColorBuilder<TColor>.FromRGBA(100, 149, 237, 255); public static readonly TColor CornflowerBlue = ColorBuilder<TColor>.FromRGBA(100, 149, 237, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF8DC. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFF8DC.
/// </summary> /// </summary>
public static readonly TColor Cornsilk = ColorBuilder<TColor>.FromRGBA(255, 248, 220, 255); public static readonly TColor Cornsilk = ColorBuilder<TColor>.FromRGBA(255, 248, 220, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DC143C. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DC143C.
/// </summary> /// </summary>
public static readonly TColor Crimson = ColorBuilder<TColor>.FromRGBA(220, 20, 60, 255); public static readonly TColor Crimson = ColorBuilder<TColor>.FromRGBA(220, 20, 60, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FFFF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary> /// </summary>
public static readonly TColor Cyan = ColorBuilder<TColor>.FromRGBA(0, 255, 255, 255); public static readonly TColor Cyan = ColorBuilder<TColor>.FromRGBA(0, 255, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00008B. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00008B.
/// </summary> /// </summary>
public static readonly TColor DarkBlue = ColorBuilder<TColor>.FromRGBA(0, 0, 139, 255); public static readonly TColor DarkBlue = ColorBuilder<TColor>.FromRGBA(0, 0, 139, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008B8B. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #008B8B.
/// </summary> /// </summary>
public static readonly TColor DarkCyan = ColorBuilder<TColor>.FromRGBA(0, 139, 139, 255); public static readonly TColor DarkCyan = ColorBuilder<TColor>.FromRGBA(0, 139, 139, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B8860B. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #B8860B.
/// </summary> /// </summary>
public static readonly TColor DarkGoldenrod = ColorBuilder<TColor>.FromRGBA(184, 134, 11, 255); public static readonly TColor DarkGoldenrod = ColorBuilder<TColor>.FromRGBA(184, 134, 11, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A9A9A9. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #A9A9A9.
/// </summary> /// </summary>
public static readonly TColor DarkGray = ColorBuilder<TColor>.FromRGBA(169, 169, 169, 255); public static readonly TColor DarkGray = ColorBuilder<TColor>.FromRGBA(169, 169, 169, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #006400. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #006400.
/// </summary> /// </summary>
public static readonly TColor DarkGreen = ColorBuilder<TColor>.FromRGBA(0, 100, 0, 255); public static readonly TColor DarkGreen = ColorBuilder<TColor>.FromRGBA(0, 100, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BDB76B. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #BDB76B.
/// </summary> /// </summary>
public static readonly TColor DarkKhaki = ColorBuilder<TColor>.FromRGBA(189, 183, 107, 255); public static readonly TColor DarkKhaki = ColorBuilder<TColor>.FromRGBA(189, 183, 107, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B008B. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8B008B.
/// </summary> /// </summary>
public static readonly TColor DarkMagenta = ColorBuilder<TColor>.FromRGBA(139, 0, 139, 255); public static readonly TColor DarkMagenta = ColorBuilder<TColor>.FromRGBA(139, 0, 139, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #556B2F. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #556B2F.
/// </summary> /// </summary>
public static readonly TColor DarkOliveGreen = ColorBuilder<TColor>.FromRGBA(85, 107, 47, 255); public static readonly TColor DarkOliveGreen = ColorBuilder<TColor>.FromRGBA(85, 107, 47, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF8C00. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF8C00.
/// </summary> /// </summary>
public static readonly TColor DarkOrange = ColorBuilder<TColor>.FromRGBA(255, 140, 0, 255); public static readonly TColor DarkOrange = ColorBuilder<TColor>.FromRGBA(255, 140, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9932CC. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #9932CC.
/// </summary> /// </summary>
public static readonly TColor DarkOrchid = ColorBuilder<TColor>.FromRGBA(153, 50, 204, 255); public static readonly TColor DarkOrchid = ColorBuilder<TColor>.FromRGBA(153, 50, 204, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B0000. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8B0000.
/// </summary> /// </summary>
public static readonly TColor DarkRed = ColorBuilder<TColor>.FromRGBA(139, 0, 0, 255); public static readonly TColor DarkRed = ColorBuilder<TColor>.FromRGBA(139, 0, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E9967A. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #E9967A.
/// </summary> /// </summary>
public static readonly TColor DarkSalmon = ColorBuilder<TColor>.FromRGBA(233, 150, 122, 255); public static readonly TColor DarkSalmon = ColorBuilder<TColor>.FromRGBA(233, 150, 122, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8FBC8B. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8FBC8B.
/// </summary> /// </summary>
public static readonly TColor DarkSeaGreen = ColorBuilder<TColor>.FromRGBA(143, 188, 139, 255); public static readonly TColor DarkSeaGreen = ColorBuilder<TColor>.FromRGBA(143, 188, 139, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #483D8B. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #483D8B.
/// </summary> /// </summary>
public static readonly TColor DarkSlateBlue = ColorBuilder<TColor>.FromRGBA(72, 61, 139, 255); public static readonly TColor DarkSlateBlue = ColorBuilder<TColor>.FromRGBA(72, 61, 139, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #2F4F4F. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #2F4F4F.
/// </summary> /// </summary>
public static readonly TColor DarkSlateGray = ColorBuilder<TColor>.FromRGBA(47, 79, 79, 255); public static readonly TColor DarkSlateGray = ColorBuilder<TColor>.FromRGBA(47, 79, 79, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00CED1. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00CED1.
/// </summary> /// </summary>
public static readonly TColor DarkTurquoise = ColorBuilder<TColor>.FromRGBA(0, 206, 209, 255); public static readonly TColor DarkTurquoise = ColorBuilder<TColor>.FromRGBA(0, 206, 209, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9400D3. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #9400D3.
/// </summary> /// </summary>
public static readonly TColor DarkViolet = ColorBuilder<TColor>.FromRGBA(148, 0, 211, 255); public static readonly TColor DarkViolet = ColorBuilder<TColor>.FromRGBA(148, 0, 211, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF1493. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF1493.
/// </summary> /// </summary>
public static readonly TColor DeepPink = ColorBuilder<TColor>.FromRGBA(255, 20, 147, 255); public static readonly TColor DeepPink = ColorBuilder<TColor>.FromRGBA(255, 20, 147, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00BFFF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00BFFF.
/// </summary> /// </summary>
public static readonly TColor DeepSkyBlue = ColorBuilder<TColor>.FromRGBA(0, 191, 255, 255); public static readonly TColor DeepSkyBlue = ColorBuilder<TColor>.FromRGBA(0, 191, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #696969. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #696969.
/// </summary> /// </summary>
public static readonly TColor DimGray = ColorBuilder<TColor>.FromRGBA(105, 105, 105, 255); public static readonly TColor DimGray = ColorBuilder<TColor>.FromRGBA(105, 105, 105, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #1E90FF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #1E90FF.
/// </summary> /// </summary>
public static readonly TColor DodgerBlue = ColorBuilder<TColor>.FromRGBA(30, 144, 255, 255); public static readonly TColor DodgerBlue = ColorBuilder<TColor>.FromRGBA(30, 144, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B22222. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #B22222.
/// </summary> /// </summary>
public static readonly TColor Firebrick = ColorBuilder<TColor>.FromRGBA(178, 34, 34, 255); public static readonly TColor Firebrick = ColorBuilder<TColor>.FromRGBA(178, 34, 34, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFAF0. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFAF0.
/// </summary> /// </summary>
public static readonly TColor FloralWhite = ColorBuilder<TColor>.FromRGBA(255, 250, 240, 255); public static readonly TColor FloralWhite = ColorBuilder<TColor>.FromRGBA(255, 250, 240, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #228B22. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #228B22.
/// </summary> /// </summary>
public static readonly TColor ForestGreen = ColorBuilder<TColor>.FromRGBA(34, 139, 34, 255); public static readonly TColor ForestGreen = ColorBuilder<TColor>.FromRGBA(34, 139, 34, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF00FF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary> /// </summary>
public static readonly TColor Fuchsia = ColorBuilder<TColor>.FromRGBA(255, 0, 255, 255); public static readonly TColor Fuchsia = ColorBuilder<TColor>.FromRGBA(255, 0, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DCDCDC. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DCDCDC.
/// </summary> /// </summary>
public static readonly TColor Gainsboro = ColorBuilder<TColor>.FromRGBA(220, 220, 220, 255); public static readonly TColor Gainsboro = ColorBuilder<TColor>.FromRGBA(220, 220, 220, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F8F8FF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F8F8FF.
/// </summary> /// </summary>
public static readonly TColor GhostWhite = ColorBuilder<TColor>.FromRGBA(248, 248, 255, 255); public static readonly TColor GhostWhite = ColorBuilder<TColor>.FromRGBA(248, 248, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFD700. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFD700.
/// </summary> /// </summary>
public static readonly TColor Gold = ColorBuilder<TColor>.FromRGBA(255, 215, 0, 255); public static readonly TColor Gold = ColorBuilder<TColor>.FromRGBA(255, 215, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DAA520. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DAA520.
/// </summary> /// </summary>
public static readonly TColor Goldenrod = ColorBuilder<TColor>.FromRGBA(218, 165, 32, 255); public static readonly TColor Goldenrod = ColorBuilder<TColor>.FromRGBA(218, 165, 32, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #808080. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #808080.
/// </summary> /// </summary>
public static readonly TColor Gray = ColorBuilder<TColor>.FromRGBA(128, 128, 128, 255); public static readonly TColor Gray = ColorBuilder<TColor>.FromRGBA(128, 128, 128, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008000. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #008000.
/// </summary> /// </summary>
public static readonly TColor Green = ColorBuilder<TColor>.FromRGBA(0, 128, 0, 255); public static readonly TColor Green = ColorBuilder<TColor>.FromRGBA(0, 128, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #ADFF2F. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #ADFF2F.
/// </summary> /// </summary>
public static readonly TColor GreenYellow = ColorBuilder<TColor>.FromRGBA(173, 255, 47, 255); public static readonly TColor GreenYellow = ColorBuilder<TColor>.FromRGBA(173, 255, 47, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0FFF0. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F0FFF0.
/// </summary> /// </summary>
public static readonly TColor Honeydew = ColorBuilder<TColor>.FromRGBA(240, 255, 240, 255); public static readonly TColor Honeydew = ColorBuilder<TColor>.FromRGBA(240, 255, 240, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF69B4. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF69B4.
/// </summary> /// </summary>
public static readonly TColor HotPink = ColorBuilder<TColor>.FromRGBA(255, 105, 180, 255); public static readonly TColor HotPink = ColorBuilder<TColor>.FromRGBA(255, 105, 180, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #CD5C5C. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #CD5C5C.
/// </summary> /// </summary>
public static readonly TColor IndianRed = ColorBuilder<TColor>.FromRGBA(205, 92, 92, 255); public static readonly TColor IndianRed = ColorBuilder<TColor>.FromRGBA(205, 92, 92, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4B0082. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #4B0082.
/// </summary> /// </summary>
public static readonly TColor Indigo = ColorBuilder<TColor>.FromRGBA(75, 0, 130, 255); public static readonly TColor Indigo = ColorBuilder<TColor>.FromRGBA(75, 0, 130, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFF0. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFFF0.
/// </summary> /// </summary>
public static readonly TColor Ivory = ColorBuilder<TColor>.FromRGBA(255, 255, 240, 255); public static readonly TColor Ivory = ColorBuilder<TColor>.FromRGBA(255, 255, 240, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0E68C. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F0E68C.
/// </summary> /// </summary>
public static readonly TColor Khaki = ColorBuilder<TColor>.FromRGBA(240, 230, 140, 255); public static readonly TColor Khaki = ColorBuilder<TColor>.FromRGBA(240, 230, 140, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E6E6FA. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #E6E6FA.
/// </summary> /// </summary>
public static readonly TColor Lavender = ColorBuilder<TColor>.FromRGBA(230, 230, 250, 255); public static readonly TColor Lavender = ColorBuilder<TColor>.FromRGBA(230, 230, 250, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF0F5. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFF0F5.
/// </summary> /// </summary>
public static readonly TColor LavenderBlush = ColorBuilder<TColor>.FromRGBA(255, 240, 245, 255); public static readonly TColor LavenderBlush = ColorBuilder<TColor>.FromRGBA(255, 240, 245, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7CFC00. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #7CFC00.
/// </summary> /// </summary>
public static readonly TColor LawnGreen = ColorBuilder<TColor>.FromRGBA(124, 252, 0, 255); public static readonly TColor LawnGreen = ColorBuilder<TColor>.FromRGBA(124, 252, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFACD. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFACD.
/// </summary> /// </summary>
public static readonly TColor LemonChiffon = ColorBuilder<TColor>.FromRGBA(255, 250, 205, 255); public static readonly TColor LemonChiffon = ColorBuilder<TColor>.FromRGBA(255, 250, 205, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #ADD8E6. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #ADD8E6.
/// </summary> /// </summary>
public static readonly TColor LightBlue = ColorBuilder<TColor>.FromRGBA(173, 216, 230, 255); public static readonly TColor LightBlue = ColorBuilder<TColor>.FromRGBA(173, 216, 230, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F08080. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F08080.
/// </summary> /// </summary>
public static readonly TColor LightCoral = ColorBuilder<TColor>.FromRGBA(240, 128, 128, 255); public static readonly TColor LightCoral = ColorBuilder<TColor>.FromRGBA(240, 128, 128, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E0FFFF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #E0FFFF.
/// </summary> /// </summary>
public static readonly TColor LightCyan = ColorBuilder<TColor>.FromRGBA(224, 255, 255, 255); public static readonly TColor LightCyan = ColorBuilder<TColor>.FromRGBA(224, 255, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FAFAD2. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FAFAD2.
/// </summary> /// </summary>
public static readonly TColor LightGoldenrodYellow = ColorBuilder<TColor>.FromRGBA(250, 250, 210, 255); public static readonly TColor LightGoldenrodYellow = ColorBuilder<TColor>.FromRGBA(250, 250, 210, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D3D3D3. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #D3D3D3.
/// </summary> /// </summary>
public static readonly TColor LightGray = ColorBuilder<TColor>.FromRGBA(211, 211, 211, 255); public static readonly TColor LightGray = ColorBuilder<TColor>.FromRGBA(211, 211, 211, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #90EE90. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #90EE90.
/// </summary> /// </summary>
public static readonly TColor LightGreen = ColorBuilder<TColor>.FromRGBA(144, 238, 144, 255); public static readonly TColor LightGreen = ColorBuilder<TColor>.FromRGBA(144, 238, 144, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFB6C1. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFB6C1.
/// </summary> /// </summary>
public static readonly TColor LightPink = ColorBuilder<TColor>.FromRGBA(255, 182, 193, 255); public static readonly TColor LightPink = ColorBuilder<TColor>.FromRGBA(255, 182, 193, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFA07A. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFA07A.
/// </summary> /// </summary>
public static readonly TColor LightSalmon = ColorBuilder<TColor>.FromRGBA(255, 160, 122, 255); public static readonly TColor LightSalmon = ColorBuilder<TColor>.FromRGBA(255, 160, 122, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #20B2AA. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #20B2AA.
/// </summary> /// </summary>
public static readonly TColor LightSeaGreen = ColorBuilder<TColor>.FromRGBA(32, 178, 170, 255); public static readonly TColor LightSeaGreen = ColorBuilder<TColor>.FromRGBA(32, 178, 170, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #87CEFA. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #87CEFA.
/// </summary> /// </summary>
public static readonly TColor LightSkyBlue = ColorBuilder<TColor>.FromRGBA(135, 206, 250, 255); public static readonly TColor LightSkyBlue = ColorBuilder<TColor>.FromRGBA(135, 206, 250, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #778899. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #778899.
/// </summary> /// </summary>
public static readonly TColor LightSlateGray = ColorBuilder<TColor>.FromRGBA(119, 136, 153, 255); public static readonly TColor LightSlateGray = ColorBuilder<TColor>.FromRGBA(119, 136, 153, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B0C4DE. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #B0C4DE.
/// </summary> /// </summary>
public static readonly TColor LightSteelBlue = ColorBuilder<TColor>.FromRGBA(176, 196, 222, 255); public static readonly TColor LightSteelBlue = ColorBuilder<TColor>.FromRGBA(176, 196, 222, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFE0. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFFE0.
/// </summary> /// </summary>
public static readonly TColor LightYellow = ColorBuilder<TColor>.FromRGBA(255, 255, 224, 255); public static readonly TColor LightYellow = ColorBuilder<TColor>.FromRGBA(255, 255, 224, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FF00. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FF00.
/// </summary> /// </summary>
public static readonly TColor Lime = ColorBuilder<TColor>.FromRGBA(0, 255, 0, 255); public static readonly TColor Lime = ColorBuilder<TColor>.FromRGBA(0, 255, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #32CD32. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #32CD32.
/// </summary> /// </summary>
public static readonly TColor LimeGreen = ColorBuilder<TColor>.FromRGBA(50, 205, 50, 255); public static readonly TColor LimeGreen = ColorBuilder<TColor>.FromRGBA(50, 205, 50, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FAF0E6. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FAF0E6.
/// </summary> /// </summary>
public static readonly TColor Linen = ColorBuilder<TColor>.FromRGBA(250, 240, 230, 255); public static readonly TColor Linen = ColorBuilder<TColor>.FromRGBA(250, 240, 230, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF00FF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary> /// </summary>
public static readonly TColor Magenta = ColorBuilder<TColor>.FromRGBA(255, 0, 255, 255); public static readonly TColor Magenta = ColorBuilder<TColor>.FromRGBA(255, 0, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #800000. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #800000.
/// </summary> /// </summary>
public static readonly TColor Maroon = ColorBuilder<TColor>.FromRGBA(128, 0, 0, 255); public static readonly TColor Maroon = ColorBuilder<TColor>.FromRGBA(128, 0, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #66CDAA. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #66CDAA.
/// </summary> /// </summary>
public static readonly TColor MediumAquamarine = ColorBuilder<TColor>.FromRGBA(102, 205, 170, 255); public static readonly TColor MediumAquamarine = ColorBuilder<TColor>.FromRGBA(102, 205, 170, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #0000CD. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #0000CD.
/// </summary> /// </summary>
public static readonly TColor MediumBlue = ColorBuilder<TColor>.FromRGBA(0, 0, 205, 255); public static readonly TColor MediumBlue = ColorBuilder<TColor>.FromRGBA(0, 0, 205, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BA55D3. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #BA55D3.
/// </summary> /// </summary>
public static readonly TColor MediumOrchid = ColorBuilder<TColor>.FromRGBA(186, 85, 211, 255); public static readonly TColor MediumOrchid = ColorBuilder<TColor>.FromRGBA(186, 85, 211, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9370DB. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #9370DB.
/// </summary> /// </summary>
public static readonly TColor MediumPurple = ColorBuilder<TColor>.FromRGBA(147, 112, 219, 255); public static readonly TColor MediumPurple = ColorBuilder<TColor>.FromRGBA(147, 112, 219, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #3CB371. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #3CB371.
/// </summary> /// </summary>
public static readonly TColor MediumSeaGreen = ColorBuilder<TColor>.FromRGBA(60, 179, 113, 255); public static readonly TColor MediumSeaGreen = ColorBuilder<TColor>.FromRGBA(60, 179, 113, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7B68EE. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #7B68EE.
/// </summary> /// </summary>
public static readonly TColor MediumSlateBlue = ColorBuilder<TColor>.FromRGBA(123, 104, 238, 255); public static readonly TColor MediumSlateBlue = ColorBuilder<TColor>.FromRGBA(123, 104, 238, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FA9A. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FA9A.
/// </summary> /// </summary>
public static readonly TColor MediumSpringGreen = ColorBuilder<TColor>.FromRGBA(0, 250, 154, 255); public static readonly TColor MediumSpringGreen = ColorBuilder<TColor>.FromRGBA(0, 250, 154, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #48D1CC. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #48D1CC.
/// </summary> /// </summary>
public static readonly TColor MediumTurquoise = ColorBuilder<TColor>.FromRGBA(72, 209, 204, 255); public static readonly TColor MediumTurquoise = ColorBuilder<TColor>.FromRGBA(72, 209, 204, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #C71585. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #C71585.
/// </summary> /// </summary>
public static readonly TColor MediumVioletRed = ColorBuilder<TColor>.FromRGBA(199, 21, 133, 255); public static readonly TColor MediumVioletRed = ColorBuilder<TColor>.FromRGBA(199, 21, 133, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #191970. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #191970.
/// </summary> /// </summary>
public static readonly TColor MidnightBlue = ColorBuilder<TColor>.FromRGBA(25, 25, 112, 255); public static readonly TColor MidnightBlue = ColorBuilder<TColor>.FromRGBA(25, 25, 112, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5FFFA. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F5FFFA.
/// </summary> /// </summary>
public static readonly TColor MintCream = ColorBuilder<TColor>.FromRGBA(245, 255, 250, 255); public static readonly TColor MintCream = ColorBuilder<TColor>.FromRGBA(245, 255, 250, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFE4E1. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFE4E1.
/// </summary> /// </summary>
public static readonly TColor MistyRose = ColorBuilder<TColor>.FromRGBA(255, 228, 225, 255); public static readonly TColor MistyRose = ColorBuilder<TColor>.FromRGBA(255, 228, 225, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFE4B5. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFE4B5.
/// </summary> /// </summary>
public static readonly TColor Moccasin = ColorBuilder<TColor>.FromRGBA(255, 228, 181, 255); public static readonly TColor Moccasin = ColorBuilder<TColor>.FromRGBA(255, 228, 181, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFDEAD. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFDEAD.
/// </summary> /// </summary>
public static readonly TColor NavajoWhite = ColorBuilder<TColor>.FromRGBA(255, 222, 173, 255); public static readonly TColor NavajoWhite = ColorBuilder<TColor>.FromRGBA(255, 222, 173, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #000080. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #000080.
/// </summary> /// </summary>
public static readonly TColor Navy = ColorBuilder<TColor>.FromRGBA(0, 0, 128, 255); public static readonly TColor Navy = ColorBuilder<TColor>.FromRGBA(0, 0, 128, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FDF5E6. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FDF5E6.
/// </summary> /// </summary>
public static readonly TColor OldLace = ColorBuilder<TColor>.FromRGBA(253, 245, 230, 255); public static readonly TColor OldLace = ColorBuilder<TColor>.FromRGBA(253, 245, 230, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #808000. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #808000.
/// </summary> /// </summary>
public static readonly TColor Olive = ColorBuilder<TColor>.FromRGBA(128, 128, 0, 255); public static readonly TColor Olive = ColorBuilder<TColor>.FromRGBA(128, 128, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6B8E23. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #6B8E23.
/// </summary> /// </summary>
public static readonly TColor OliveDrab = ColorBuilder<TColor>.FromRGBA(107, 142, 35, 255); public static readonly TColor OliveDrab = ColorBuilder<TColor>.FromRGBA(107, 142, 35, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFA500. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFA500.
/// </summary> /// </summary>
public static readonly TColor Orange = ColorBuilder<TColor>.FromRGBA(255, 165, 0, 255); public static readonly TColor Orange = ColorBuilder<TColor>.FromRGBA(255, 165, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF4500. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF4500.
/// </summary> /// </summary>
public static readonly TColor OrangeRed = ColorBuilder<TColor>.FromRGBA(255, 69, 0, 255); public static readonly TColor OrangeRed = ColorBuilder<TColor>.FromRGBA(255, 69, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DA70D6. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DA70D6.
/// </summary> /// </summary>
public static readonly TColor Orchid = ColorBuilder<TColor>.FromRGBA(218, 112, 214, 255); public static readonly TColor Orchid = ColorBuilder<TColor>.FromRGBA(218, 112, 214, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #EEE8AA. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #EEE8AA.
/// </summary> /// </summary>
public static readonly TColor PaleGoldenrod = ColorBuilder<TColor>.FromRGBA(238, 232, 170, 255); public static readonly TColor PaleGoldenrod = ColorBuilder<TColor>.FromRGBA(238, 232, 170, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #98FB98. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #98FB98.
/// </summary> /// </summary>
public static readonly TColor PaleGreen = ColorBuilder<TColor>.FromRGBA(152, 251, 152, 255); public static readonly TColor PaleGreen = ColorBuilder<TColor>.FromRGBA(152, 251, 152, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #AFEEEE. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #AFEEEE.
/// </summary> /// </summary>
public static readonly TColor PaleTurquoise = ColorBuilder<TColor>.FromRGBA(175, 238, 238, 255); public static readonly TColor PaleTurquoise = ColorBuilder<TColor>.FromRGBA(175, 238, 238, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DB7093. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DB7093.
/// </summary> /// </summary>
public static readonly TColor PaleVioletRed = ColorBuilder<TColor>.FromRGBA(219, 112, 147, 255); public static readonly TColor PaleVioletRed = ColorBuilder<TColor>.FromRGBA(219, 112, 147, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFEFD5. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFEFD5.
/// </summary> /// </summary>
public static readonly TColor PapayaWhip = ColorBuilder<TColor>.FromRGBA(255, 239, 213, 255); public static readonly TColor PapayaWhip = ColorBuilder<TColor>.FromRGBA(255, 239, 213, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFDAB9. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFDAB9.
/// </summary> /// </summary>
public static readonly TColor PeachPuff = ColorBuilder<TColor>.FromRGBA(255, 218, 185, 255); public static readonly TColor PeachPuff = ColorBuilder<TColor>.FromRGBA(255, 218, 185, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #CD853F. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #CD853F.
/// </summary> /// </summary>
public static readonly TColor Peru = ColorBuilder<TColor>.FromRGBA(205, 133, 63, 255); public static readonly TColor Peru = ColorBuilder<TColor>.FromRGBA(205, 133, 63, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFC0CB. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFC0CB.
/// </summary> /// </summary>
public static readonly TColor Pink = ColorBuilder<TColor>.FromRGBA(255, 192, 203, 255); public static readonly TColor Pink = ColorBuilder<TColor>.FromRGBA(255, 192, 203, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DDA0DD. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DDA0DD.
/// </summary> /// </summary>
public static readonly TColor Plum = ColorBuilder<TColor>.FromRGBA(221, 160, 221, 255); public static readonly TColor Plum = ColorBuilder<TColor>.FromRGBA(221, 160, 221, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B0E0E6. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #B0E0E6.
/// </summary> /// </summary>
public static readonly TColor PowderBlue = ColorBuilder<TColor>.FromRGBA(176, 224, 230, 255); public static readonly TColor PowderBlue = ColorBuilder<TColor>.FromRGBA(176, 224, 230, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #800080. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #800080.
/// </summary> /// </summary>
public static readonly TColor Purple = ColorBuilder<TColor>.FromRGBA(128, 0, 128, 255); public static readonly TColor Purple = ColorBuilder<TColor>.FromRGBA(128, 0, 128, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #663399. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #663399.
/// </summary> /// </summary>
public static readonly TColor RebeccaPurple = ColorBuilder<TColor>.FromRGBA(102, 51, 153, 255); public static readonly TColor RebeccaPurple = ColorBuilder<TColor>.FromRGBA(102, 51, 153, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF0000. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF0000.
/// </summary> /// </summary>
public static readonly TColor Red = ColorBuilder<TColor>.FromRGBA(255, 0, 0, 255); public static readonly TColor Red = ColorBuilder<TColor>.FromRGBA(255, 0, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BC8F8F. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #BC8F8F.
/// </summary> /// </summary>
public static readonly TColor RosyBrown = ColorBuilder<TColor>.FromRGBA(188, 143, 143, 255); public static readonly TColor RosyBrown = ColorBuilder<TColor>.FromRGBA(188, 143, 143, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4169E1. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #4169E1.
/// </summary> /// </summary>
public static readonly TColor RoyalBlue = ColorBuilder<TColor>.FromRGBA(65, 105, 225, 255); public static readonly TColor RoyalBlue = ColorBuilder<TColor>.FromRGBA(65, 105, 225, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B4513. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8B4513.
/// </summary> /// </summary>
public static readonly TColor SaddleBrown = ColorBuilder<TColor>.FromRGBA(139, 69, 19, 255); public static readonly TColor SaddleBrown = ColorBuilder<TColor>.FromRGBA(139, 69, 19, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FA8072. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FA8072.
/// </summary> /// </summary>
public static readonly TColor Salmon = ColorBuilder<TColor>.FromRGBA(250, 128, 114, 255); public static readonly TColor Salmon = ColorBuilder<TColor>.FromRGBA(250, 128, 114, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F4A460. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F4A460.
/// </summary> /// </summary>
public static readonly TColor SandyBrown = ColorBuilder<TColor>.FromRGBA(244, 164, 96, 255); public static readonly TColor SandyBrown = ColorBuilder<TColor>.FromRGBA(244, 164, 96, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #2E8B57. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #2E8B57.
/// </summary> /// </summary>
public static readonly TColor SeaGreen = ColorBuilder<TColor>.FromRGBA(46, 139, 87, 255); public static readonly TColor SeaGreen = ColorBuilder<TColor>.FromRGBA(46, 139, 87, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF5EE. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFF5EE.
/// </summary> /// </summary>
public static readonly TColor SeaShell = ColorBuilder<TColor>.FromRGBA(255, 245, 238, 255); public static readonly TColor SeaShell = ColorBuilder<TColor>.FromRGBA(255, 245, 238, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A0522D. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #A0522D.
/// </summary> /// </summary>
public static readonly TColor Sienna = ColorBuilder<TColor>.FromRGBA(160, 82, 45, 255); public static readonly TColor Sienna = ColorBuilder<TColor>.FromRGBA(160, 82, 45, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #C0C0C0. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #C0C0C0.
/// </summary> /// </summary>
public static readonly TColor Silver = ColorBuilder<TColor>.FromRGBA(192, 192, 192, 255); public static readonly TColor Silver = ColorBuilder<TColor>.FromRGBA(192, 192, 192, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #87CEEB. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #87CEEB.
/// </summary> /// </summary>
public static readonly TColor SkyBlue = ColorBuilder<TColor>.FromRGBA(135, 206, 235, 255); public static readonly TColor SkyBlue = ColorBuilder<TColor>.FromRGBA(135, 206, 235, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6A5ACD. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #6A5ACD.
/// </summary> /// </summary>
public static readonly TColor SlateBlue = ColorBuilder<TColor>.FromRGBA(106, 90, 205, 255); public static readonly TColor SlateBlue = ColorBuilder<TColor>.FromRGBA(106, 90, 205, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #708090. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #708090.
/// </summary> /// </summary>
public static readonly TColor SlateGray = ColorBuilder<TColor>.FromRGBA(112, 128, 144, 255); public static readonly TColor SlateGray = ColorBuilder<TColor>.FromRGBA(112, 128, 144, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFAFA. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFAFA.
/// </summary> /// </summary>
public static readonly TColor Snow = ColorBuilder<TColor>.FromRGBA(255, 250, 250, 255); public static readonly TColor Snow = ColorBuilder<TColor>.FromRGBA(255, 250, 250, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FF7F. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FF7F.
/// </summary> /// </summary>
public static readonly TColor SpringGreen = ColorBuilder<TColor>.FromRGBA(0, 255, 127, 255); public static readonly TColor SpringGreen = ColorBuilder<TColor>.FromRGBA(0, 255, 127, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4682B4. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #4682B4.
/// </summary> /// </summary>
public static readonly TColor SteelBlue = ColorBuilder<TColor>.FromRGBA(70, 130, 180, 255); public static readonly TColor SteelBlue = ColorBuilder<TColor>.FromRGBA(70, 130, 180, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D2B48C. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #D2B48C.
/// </summary> /// </summary>
public static readonly TColor Tan = ColorBuilder<TColor>.FromRGBA(210, 180, 140, 255); public static readonly TColor Tan = ColorBuilder<TColor>.FromRGBA(210, 180, 140, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008080. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #008080.
/// </summary> /// </summary>
public static readonly TColor Teal = ColorBuilder<TColor>.FromRGBA(0, 128, 128, 255); public static readonly TColor Teal = ColorBuilder<TColor>.FromRGBA(0, 128, 128, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D8BFD8. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #D8BFD8.
/// </summary> /// </summary>
public static readonly TColor Thistle = ColorBuilder<TColor>.FromRGBA(216, 191, 216, 255); public static readonly TColor Thistle = ColorBuilder<TColor>.FromRGBA(216, 191, 216, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF6347. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF6347.
/// </summary> /// </summary>
public static readonly TColor Tomato = ColorBuilder<TColor>.FromRGBA(255, 99, 71, 255); public static readonly TColor Tomato = ColorBuilder<TColor>.FromRGBA(255, 99, 71, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFFF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary> /// </summary>
public static readonly TColor Transparent = ColorBuilder<TColor>.FromRGBA(255, 255, 255, 0); public static readonly TColor Transparent = ColorBuilder<TColor>.FromRGBA(255, 255, 255, 0);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #40E0D0. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #40E0D0.
/// </summary> /// </summary>
public static readonly TColor Turquoise = ColorBuilder<TColor>.FromRGBA(64, 224, 208, 255); public static readonly TColor Turquoise = ColorBuilder<TColor>.FromRGBA(64, 224, 208, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #EE82EE. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #EE82EE.
/// </summary> /// </summary>
public static readonly TColor Violet = ColorBuilder<TColor>.FromRGBA(238, 130, 238, 255); public static readonly TColor Violet = ColorBuilder<TColor>.FromRGBA(238, 130, 238, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5DEB3. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F5DEB3.
/// </summary> /// </summary>
public static readonly TColor Wheat = ColorBuilder<TColor>.FromRGBA(245, 222, 179, 255); public static readonly TColor Wheat = ColorBuilder<TColor>.FromRGBA(245, 222, 179, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFFF. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary> /// </summary>
public static readonly TColor White = ColorBuilder<TColor>.FromRGBA(255, 255, 255, 255); public static readonly TColor White = ColorBuilder<TColor>.FromRGBA(255, 255, 255, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5F5F5. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F5F5F5.
/// </summary> /// </summary>
public static readonly TColor WhiteSmoke = ColorBuilder<TColor>.FromRGBA(245, 245, 245, 255); public static readonly TColor WhiteSmoke = ColorBuilder<TColor>.FromRGBA(245, 245, 245, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFF00. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFF00.
/// </summary> /// </summary>
public static readonly TColor Yellow = ColorBuilder<TColor>.FromRGBA(255, 255, 0, 255); public static readonly TColor Yellow = ColorBuilder<TColor>.FromRGBA(255, 255, 0, 255);
/// <summary> /// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9ACD32. /// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #9ACD32.
/// </summary> /// </summary>
public static readonly TColor YellowGreen = ColorBuilder<TColor>.FromRGBA(154, 205, 50, 255); public static readonly TColor YellowGreen = ColorBuilder<TColor>.FromRGBA(154, 205, 50, 255);
} }

40
src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs

@ -27,10 +27,7 @@ namespace ImageSharp
/// <param name="sourceVectors">The <see cref="BufferSpan{T}"/> to the source vectors.</param> /// <param name="sourceVectors">The <see cref="BufferSpan{T}"/> to the source vectors.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromVector4( internal virtual void PackFromVector4(BufferSpan<Vector4> sourceVectors, BufferSpan<TColor> destColors, int count)
BufferSpan<Vector4> sourceVectors,
BufferSpan<TColor> destColors,
int count)
{ {
ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference(); ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference();
@ -49,10 +46,7 @@ namespace ImageSharp
/// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param> /// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param>
/// <param name="destVectors">The <see cref="BufferSpan{T}"/> to the destination vectors.</param> /// <param name="destVectors">The <see cref="BufferSpan{T}"/> to the destination vectors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void ToVector4( internal virtual void ToVector4(BufferSpan<TColor> sourceColors, BufferSpan<Vector4> destVectors, int count)
BufferSpan<TColor> sourceColors,
BufferSpan<Vector4> destVectors,
int count)
{ {
ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference();
ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference(); ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference();
@ -71,10 +65,7 @@ namespace ImageSharp
/// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromXyzBytes( internal virtual void PackFromXyzBytes(BufferSpan<byte> sourceBytes, BufferSpan<TColor> destColors, int count)
BufferSpan<byte> sourceBytes,
BufferSpan<TColor> destColors,
int count)
{ {
ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference();
@ -115,10 +106,7 @@ namespace ImageSharp
/// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromXyzwBytes( internal virtual void PackFromXyzwBytes(BufferSpan<byte> sourceBytes, BufferSpan<TColor> destColors, int count)
BufferSpan<byte> sourceBytes,
BufferSpan<TColor> destColors,
int count)
{ {
ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference();
@ -141,10 +129,7 @@ namespace ImageSharp
/// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param> /// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param>
/// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void ToXyzwBytes( internal virtual void ToXyzwBytes(BufferSpan<TColor> sourceColors, BufferSpan<byte> destBytes, int count)
BufferSpan<TColor> sourceColors,
BufferSpan<byte> destBytes,
int count)
{ {
ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference();
byte[] dest = destBytes.Array; byte[] dest = destBytes.Array;
@ -162,10 +147,7 @@ namespace ImageSharp
/// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromZyxBytes( internal virtual void PackFromZyxBytes(BufferSpan<byte> sourceBytes, BufferSpan<TColor> destColors, int count)
BufferSpan<byte> sourceBytes,
BufferSpan<TColor> destColors,
int count)
{ {
ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference();
@ -206,10 +188,7 @@ namespace ImageSharp
/// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromZyxwBytes( internal virtual void PackFromZyxwBytes(BufferSpan<byte> sourceBytes, BufferSpan<TColor> destColors, int count)
BufferSpan<byte> sourceBytes,
BufferSpan<TColor> destColors,
int count)
{ {
ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TColor destRef = ref destColors.DangerousGetPinnableReference();
@ -232,10 +211,7 @@ namespace ImageSharp
/// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param> /// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param>
/// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void ToZyxwBytes( internal virtual void ToZyxwBytes(BufferSpan<TColor> sourceColors, BufferSpan<byte> destBytes, int count)
BufferSpan<TColor> sourceColors,
BufferSpan<byte> destBytes,
int count)
{ {
ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference();
byte[] dest = destBytes.Array; byte[] dest = destBytes.Array;

398
src/ImageSharp/Colors/PackedPixel/Rgba32.cs

@ -0,0 +1,398 @@
// <copyright file="Rgba32.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint>
{
/// <summary>
/// The shift count for the red component
/// </summary>
private const int RedShift = 0;
/// <summary>
/// The shift count for the green component
/// </summary>
private const int GreenShift = 8;
/// <summary>
/// The shift count for the blue component
/// </summary>
private const int BlueShift = 16;
/// <summary>
/// The shift count for the alpha component
/// </summary>
private const int AlphaShift = 24;
/// <summary>
/// The maximum byte value.
/// </summary>
private static readonly Vector4 MaxBytes = new Vector4(255);
/// <summary>
/// The half vector value.
/// </summary>
private static readonly Vector4 Half = new Vector4(0.5F);
/// <summary>
/// The packed value.
/// </summary>
private uint packedValue;
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public Rgba32(byte r, byte g, byte b, byte a = 255)
{
this.packedValue = Pack(r, g, b, a);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
public Rgba32(float r, float g, float b, float a = 1)
{
this.packedValue = Pack(r, g, b, a);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
public Rgba32(Vector3 vector)
{
this.packedValue = Pack(ref vector);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="vector">
/// The vector containing the components for the packed vector.
/// </param>
public Rgba32(Vector4 vector)
{
this.packedValue = Pack(ref vector);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="packed">
/// The packed value.
/// </param>
public Rgba32(uint packed)
{
this.packedValue = packed;
}
/// <summary>
/// Gets or sets the red component.
/// </summary>
public byte R
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> RedShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFFFFFF00 | (uint)value << RedShift;
}
}
/// <summary>
/// Gets or sets the green component.
/// </summary>
public byte G
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> GreenShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << GreenShift;
}
}
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public byte B
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> BlueShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << BlueShift;
}
}
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
public byte A
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (byte)(this.packedValue >> AlphaShift);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << AlphaShift;
}
}
/// <inheritdoc/>
public uint PackedValue
{
get => this.packedValue;
set => this.packedValue = value;
}
/// <summary>
/// Compares two <see cref="Rgba32"/> objects for equality.
/// </summary>
/// <param name="left">
/// The <see cref="Rgba32"/> on the left side of the operand.
/// </param>
/// <param name="right">
/// The <see cref="Rgba32"/> on the right side of the operand.
/// </param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Rgba32 left, Rgba32 right)
{
return left.packedValue == right.packedValue;
}
/// <summary>
/// Compares two <see cref="Rgba32"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="Rgba32"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Rgba32"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Rgba32 left, Rgba32 right)
{
return left.packedValue != right.packedValue;
}
/// <summary>
/// Creates a new instance of the <see cref="Rgba32"/> struct.
/// </summary>
/// <param name="hex">
/// The hexadecimal representation of the combined color components arranged
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </param>
/// <returns>
/// The <see cref="Rgba32"/>.
/// </returns>
public static Rgba32 FromHex(string hex)
{
return ColorBuilder<Rgba32>.FromHex(hex);
}
/// <inheritdoc />
public BulkPixelOperations<Rgba32> CreateBulkOperations() => new BulkPixelOperations<Rgba32>();
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromBytes(byte x, byte y, byte z, byte w)
{
this.packedValue = Pack(x, y, z, w);
}
/// <summary>
/// Converts the value of this instance to a hexadecimal string.
/// </summary>
/// <returns>A hexadecimal string representation of the value.</returns>
public string ToHex()
{
uint hexOrder = Pack(this.A, this.B, this.G, this.R);
return hexOrder.ToString("X8");
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToXyzBytes(byte[] bytes, int startIndex)
{
bytes[startIndex] = this.R;
bytes[startIndex + 1] = this.G;
bytes[startIndex + 2] = this.B;
}
/// <inheritdoc/>
[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;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ToZyxBytes(byte[] bytes, int startIndex)
{
bytes[startIndex] = this.B;
bytes[startIndex + 1] = this.G;
bytes[startIndex + 2] = this.R;
}
/// <inheritdoc/>
[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;
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PackFromVector4(Vector4 vector)
{
this.packedValue = Pack(ref vector);
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4 ToVector4()
{
return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
return (obj is Rgba32) && this.Equals((Rgba32)obj);
}
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Rgba32 other)
{
return this.packedValue == other.packedValue;
}
/// <summary>
/// Gets a string representation of the packed vector.
/// </summary>
/// <returns>A string representation of the packed vector.</returns>
public override string ToString()
{
return this.ToVector4().ToString();
}
/// <inheritdoc/>
public override int GetHashCode()
{
return this.packedValue.GetHashCode();
}
/// <summary>
/// Packs a <see cref="Vector4"/> into a uint.
/// </summary>
/// <param name="vector">The vector containing the values to pack.</param>
/// <returns>The <see cref="uint"/> containing the packed values.</returns>
[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);
}
/// <summary>
/// Packs a <see cref="Vector3"/> into a uint.
/// </summary>
/// <param name="vector">The vector containing the values to pack.</param>
/// <returns>The <see cref="uint"/> containing the packed values.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static uint Pack(ref Vector3 vector)
{
Vector4 value = new Vector4(vector, 1);
return Pack(ref value);
}
/// <summary>
/// Packs the four floats into a <see cref="uint"/>.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
/// <returns>The <see cref="uint"/></returns>
[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);
}
/// <summary>
/// Packs the four floats into a <see cref="uint"/>.
/// </summary>
/// <param name="x">The x-component</param>
/// <param name="y">The y-component</param>
/// <param name="z">The z-component</param>
/// <param name="w">The w-component</param>
/// <returns>The <see cref="uint"/></returns>
[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);
}
}
}

2
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs

@ -6,7 +6,7 @@
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using ImageSharp; using ImageSharp;
/// <summary> /// <summary>
/// Compares two implementation candidates for general BulkPixelOperations.ToVector4(): /// Compares two implementation candidates for general BulkPixelOperations.ToVector4():
/// - One iterating with pointers /// - One iterating with pointers

4
tests/ImageSharp.Benchmarks/General/ClearBuffer.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Benchmarks.General
public unsafe class ClearBuffer public unsafe class ClearBuffer
{ {
private Buffer<Color> buffer; private Buffer<Color> buffer;
[Params(32, 128, 512)] [Params(32, 128, 512)]
public int Count { get; set; } public int Count { get; set; }
@ -37,7 +37,7 @@ namespace ImageSharp.Benchmarks.General
[Benchmark] [Benchmark]
public void Unsafe_InitBlock() public void Unsafe_InitBlock()
{ {
Unsafe.InitBlock((void*)this.buffer.Pin(), default(byte), (uint)this.Count*sizeof(uint)); Unsafe.InitBlock((void*)this.buffer.Pin(), default(byte), (uint)this.Count * sizeof(uint));
} }
} }
} }

21
tests/ImageSharp.Benchmarks/Samplers/Resize.cs

@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using CoreSize = ImageSharp.Size; using CoreSize = ImageSharp.Size;
using CoreImage = ImageSharp.Image; using CoreImage = ImageSharp.Image;
using CoreVectorImage = ImageSharp.Image<ImageSharp.ColorVector>;
public class Resize : BenchmarkBase public class Resize : BenchmarkBase
{ {
@ -44,6 +45,16 @@ namespace ImageSharp.Benchmarks
} }
} }
[Benchmark(Description = "ImageSharp Vector Resize")]
public CoreSize ResizeCoreVector()
{
using (CoreVectorImage image = new CoreVectorImage(2000, 2000))
{
image.Resize(400, 400);
return new CoreSize(image.Width, image.Height);
}
}
[Benchmark(Description = "ImageSharp Compand Resize")] [Benchmark(Description = "ImageSharp Compand Resize")]
public CoreSize ResizeCoreCompand() public CoreSize ResizeCoreCompand()
{ {
@ -53,5 +64,15 @@ namespace ImageSharp.Benchmarks
return new CoreSize(image.Width, image.Height); return new CoreSize(image.Width, image.Height);
} }
} }
[Benchmark(Description = "ImageSharp Vector Compand Resize")]
public CoreSize ResizeCoreVectorCompand()
{
using (CoreVectorImage image = new CoreVectorImage(2000, 2000))
{
image.Resize(400, 400, true);
return new CoreSize(image.Width, image.Height);
}
}
} }
} }

6
tests/ImageSharp.Sandbox46/Program.cs

@ -7,7 +7,7 @@ namespace ImageSharp.Sandbox46
{ {
using System; using System;
using System.Runtime.DesignerServices; using System.Runtime.DesignerServices;
using ImageSharp.Tests; using ImageSharp.Tests;
using ImageSharp.Tests.Colors; using ImageSharp.Tests.Colors;
@ -53,10 +53,10 @@ namespace ImageSharp.Sandbox46
private static void RunToVector4ProfilingTest() private static void RunToVector4ProfilingTest()
{ {
BulkPixelOperationsTests.Color tests = new BulkPixelOperationsTests.Color(new ConsoleOutput()); BulkPixelOperationsTests.Color32 tests = new BulkPixelOperationsTests.Color32(new ConsoleOutput());
tests.Benchmark_ToVector4(); tests.Benchmark_ToVector4();
} }
private static void RunDecodeJpegProfilingTests() private static void RunDecodeJpegProfilingTests()
{ {
Console.WriteLine("RunDecodeJpegProfilingTests..."); Console.WriteLine("RunDecodeJpegProfilingTests...");

38
tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs

@ -10,9 +10,9 @@ namespace ImageSharp.Tests.Colors
public class BulkPixelOperationsTests public class BulkPixelOperationsTests
{ {
public class Color : BulkPixelOperationsTests<ImageSharp.Color> public class Color32 : BulkPixelOperationsTests<ImageSharp.Color>
{ {
public Color(ITestOutputHelper output) public Color32(ITestOutputHelper output)
: base(output) : base(output)
{ {
} }
@ -25,7 +25,7 @@ namespace ImageSharp.Tests.Colors
{ {
Assert.IsType<ImageSharp.Color.BulkOperations>(BulkPixelOperations<ImageSharp.Color>.Instance); Assert.IsType<ImageSharp.Color.BulkOperations>(BulkPixelOperations<ImageSharp.Color>.Instance);
} }
[Fact] [Fact]
public void ToVector4SimdAligned() public void ToVector4SimdAligned()
{ {
@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => ImageSharp.Color.BulkOperations.ToVector4SimdAligned(s, d, 64) (s, d) => ImageSharp.Color.BulkOperations.ToVector4SimdAligned(s, d, 64)
); );
} }
// [Fact] // Profiling benchmark - enable manually! // [Fact] // Profiling benchmark - enable manually!
@ -72,7 +72,7 @@ namespace ImageSharp.Tests.Colors
[Theory] [Theory]
[WithBlankImages(1, 1, PixelTypes.All)] [WithBlankImages(1, 1, PixelTypes.All)]
public void GetGlobalInstance<TColor>(TestImageProvider<TColor> dummy) public void GetGlobalInstance<TColor>(TestImageProvider<TColor> dummy)
where TColor:struct, IPixel<TColor> where TColor : struct, IPixel<TColor>
{ {
Assert.NotNull(BulkPixelOperations<TColor>.Instance); Assert.NotNull(BulkPixelOperations<TColor>.Instance);
} }
@ -112,7 +112,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.PackFromVector4(s, d, count) (s, d) => Operations.PackFromVector4(s, d, count)
); );
} }
internal static Vector4[] CreateExpectedVector4Data(TColor[] source) internal static Vector4[] CreateExpectedVector4Data(TColor[] source)
@ -137,7 +137,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.ToVector4(s, d, count) (s, d) => Operations.ToVector4(s, d, count)
); );
} }
@ -156,10 +156,10 @@ namespace ImageSharp.Tests.Colors
} }
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.PackFromXyzBytes(s, d, count) (s, d) => Operations.PackFromXyzBytes(s, d, count)
); );
} }
[Theory] [Theory]
@ -179,7 +179,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.ToXyzBytes(s, d, count) (s, d) => Operations.ToXyzBytes(s, d, count)
); );
} }
[Theory] [Theory]
@ -200,7 +200,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.PackFromXyzwBytes(s, d, count) (s, d) => Operations.PackFromXyzwBytes(s, d, count)
); );
} }
[Theory] [Theory]
@ -220,7 +220,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.ToXyzwBytes(s, d, count) (s, d) => Operations.ToXyzwBytes(s, d, count)
); );
} }
[Theory] [Theory]
@ -241,7 +241,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.PackFromZyxBytes(s, d, count) (s, d) => Operations.PackFromZyxBytes(s, d, count)
); );
} }
[Theory] [Theory]
@ -261,7 +261,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.ToZyxBytes(s, d, count) (s, d) => Operations.ToZyxBytes(s, d, count)
); );
} }
[Theory] [Theory]
@ -282,7 +282,7 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.PackFromZyxwBytes(s, d, count) (s, d) => Operations.PackFromZyxwBytes(s, d, count)
); );
} }
[Theory] [Theory]
@ -302,10 +302,10 @@ namespace ImageSharp.Tests.Colors
source, source,
expected, expected,
(s, d) => Operations.ToZyxwBytes(s, d, count) (s, d) => Operations.ToZyxwBytes(s, d, count)
); );
} }
private class TestBuffers<TSource, TDest> : IDisposable private class TestBuffers<TSource, TDest> : IDisposable
where TSource : struct where TSource : struct
where TDest : struct where TDest : struct
@ -316,7 +316,7 @@ namespace ImageSharp.Tests.Colors
public BufferSpan<TSource> Source => this.SourceBuffer; public BufferSpan<TSource> Source => this.SourceBuffer;
public BufferSpan<TDest> ActualDest => this.ActualDestBuffer; public BufferSpan<TDest> ActualDest => this.ActualDestBuffer;
public TestBuffers(TSource[] source, TDest[] expectedDest) public TestBuffers(TSource[] source, TDest[] expectedDest)
{ {
this.SourceBuffer = new Buffer<TSource>(source); this.SourceBuffer = new Buffer<TSource>(source);

50
tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs

@ -33,6 +33,7 @@ namespace ImageSharp.Tests.Colors
{ new NormalizedShort4(Vector4.One), new NormalizedShort4(Vector4.One), typeof(NormalizedShort4) }, { new NormalizedShort4(Vector4.One), new NormalizedShort4(Vector4.One), typeof(NormalizedShort4) },
{ new Rg32(Vector2.One), new Rg32(Vector2.One), typeof(Rg32) }, { new Rg32(Vector2.One), new Rg32(Vector2.One), typeof(Rg32) },
{ new Rgba1010102(Vector4.One), new Rgba1010102(Vector4.One), typeof(Rgba1010102) }, { new Rgba1010102(Vector4.One), new Rgba1010102(Vector4.One), typeof(Rgba1010102) },
{ new Rgba32(Vector4.One), new Rgba32(Vector4.One), typeof(Rgba32) },
{ new Rgba64(Vector4.One), new Rgba64(Vector4.One), typeof(Rgba64) }, { new Rgba64(Vector4.One), new Rgba64(Vector4.One), typeof(Rgba64) },
{ new Short2(Vector2.One * 0x7FFF), new Short2(Vector2.One * 0x7FFF), typeof(Short2) }, { new Short2(Vector2.One * 0x7FFF), new Short2(Vector2.One * 0x7FFF), typeof(Short2) },
{ new Short4(Vector4.One * 0x7FFF), new Short4(Vector4.One * 0x7FFF), typeof(Short4) }, { new Short4(Vector4.One * 0x7FFF), new Short4(Vector4.One * 0x7FFF), typeof(Short4) },
@ -144,6 +145,7 @@ namespace ImageSharp.Tests.Colors
{ new NormalizedShort4(Vector4.One), new NormalizedShort4(Vector4.Zero), typeof(NormalizedShort4) }, { new NormalizedShort4(Vector4.One), new NormalizedShort4(Vector4.Zero), typeof(NormalizedShort4) },
{ new Rg32(Vector2.One), new Rg32(Vector2.Zero), typeof(Rg32) }, { new Rg32(Vector2.One), new Rg32(Vector2.Zero), typeof(Rg32) },
{ new Rgba1010102(Vector4.One), new Rgba1010102(Vector4.Zero), typeof(Rgba1010102) }, { new Rgba1010102(Vector4.One), new Rgba1010102(Vector4.Zero), typeof(Rgba1010102) },
{ new Rgba32(Vector4.One), new Rgba32(Vector4.Zero), typeof(Rgba32) },
{ new Rgba64(Vector4.One), new Rgba64(Vector4.Zero), typeof(Rgba64) }, { new Rgba64(Vector4.One), new Rgba64(Vector4.Zero), typeof(Rgba64) },
{ new Short2(Vector2.One * 0x7FFF), new Short2(Vector2.Zero), typeof(Short2) }, { new Short2(Vector2.One * 0x7FFF), new Short2(Vector2.Zero), typeof(Short2) },
{ new Short4(Vector4.One * 0x7FFF), new Short4(Vector4.Zero), typeof(Short4) }, { new Short4(Vector4.One * 0x7FFF), new Short4(Vector4.Zero), typeof(Short4) },
@ -289,10 +291,10 @@ namespace ImageSharp.Tests.Colors
[MemberData(nameof(EqualityDataColorSpaces))] [MemberData(nameof(EqualityDataColorSpaces))]
public void EqualityObject(object first, object second, Type type) public void EqualityObject(object first, object second, Type type)
{ {
// Arrange // Arrange
// Cast to the known object types, this is so that we can hit the // Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the // equality operator on the concrete type, otherwise it goes to the
// default "object" one :) // default "object" one :)
dynamic firstObject = Convert.ChangeType(first, type); dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type); dynamic secondObject = Convert.ChangeType(second, type);
@ -308,10 +310,10 @@ namespace ImageSharp.Tests.Colors
[MemberData(nameof(NotEqualityDataColorSpaces))] [MemberData(nameof(NotEqualityDataColorSpaces))]
public void NotEqualityObject(object first, object second, Type type) public void NotEqualityObject(object first, object second, Type type)
{ {
// Arrange // Arrange
// Cast to the known object types, this is so that we can hit the // Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the // equality operator on the concrete type, otherwise it goes to the
// default "object" one :) // default "object" one :)
dynamic firstObject = Convert.ChangeType(first, type); dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type); dynamic secondObject = Convert.ChangeType(second, type);
@ -327,10 +329,10 @@ namespace ImageSharp.Tests.Colors
[MemberData(nameof(EqualityDataColorSpaces))] [MemberData(nameof(EqualityDataColorSpaces))]
public void EqualityOperator(object first, object second, Type type) public void EqualityOperator(object first, object second, Type type)
{ {
// Arrange // Arrange
// Cast to the known object types, this is so that we can hit the // Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the // equality operator on the concrete type, otherwise it goes to the
// default "object" one :) // default "object" one :)
dynamic firstObject = Convert.ChangeType(first, type); dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type); dynamic secondObject = Convert.ChangeType(second, type);
@ -346,10 +348,10 @@ namespace ImageSharp.Tests.Colors
[MemberData(nameof(NotEqualityDataColorSpaces))] [MemberData(nameof(NotEqualityDataColorSpaces))]
public void NotEqualityOperator(object first, object second, Type type) public void NotEqualityOperator(object first, object second, Type type)
{ {
// Arrange // Arrange
// Cast to the known object types, this is so that we can hit the // Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the // equality operator on the concrete type, otherwise it goes to the
// default "object" one :) // default "object" one :)
dynamic firstObject = Convert.ChangeType(first, type); dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type); dynamic secondObject = Convert.ChangeType(second, type);
@ -364,10 +366,10 @@ namespace ImageSharp.Tests.Colors
[MemberData(nameof(AlmostEqualsData))] [MemberData(nameof(AlmostEqualsData))]
public void AlmostEquals(object first, object second, Type type, float precision) public void AlmostEquals(object first, object second, Type type, float precision)
{ {
// Arrange // Arrange
// Cast to the known object types, this is so that we can hit the // Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the // equality operator on the concrete type, otherwise it goes to the
// default "object" one :) // default "object" one :)
dynamic firstObject = Convert.ChangeType(first, type); dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type); dynamic secondObject = Convert.ChangeType(second, type);
@ -382,10 +384,10 @@ namespace ImageSharp.Tests.Colors
[MemberData(nameof(AlmostNotEqualsData))] [MemberData(nameof(AlmostNotEqualsData))]
public void AlmostNotEquals(object first, object second, Type type, float precision) public void AlmostNotEquals(object first, object second, Type type, float precision)
{ {
// Arrange // Arrange
// Cast to the known object types, this is so that we can hit the // Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the // equality operator on the concrete type, otherwise it goes to the
// default "object" one :) // default "object" one :)
dynamic firstObject = Convert.ChangeType(first, type); dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type); dynamic secondObject = Convert.ChangeType(second, type);

132
tests/ImageSharp.Tests/Colors/ColorVectorTests.cs

@ -0,0 +1,132 @@
// <copyright file="ColorVectorTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System.Numerics;
using System.Runtime.CompilerServices;
using Xunit;
/// <summary>
/// Tests the <see cref="ColorVector"/> struct.
/// </summary>
public class ColorVectorTests
{
/// <summary>
/// Tests the equality operators for equality.
/// </summary>
[Fact]
public void AreEqual()
{
ColorVector color1 = new ColorVector(0, 0, 0F);
ColorVector color2 = new ColorVector(0, 0, 0, 1F);
ColorVector color3 = ColorVector.FromHex("#000");
ColorVector color4 = ColorVector.FromHex("#000F");
ColorVector color5 = ColorVector.FromHex("#000000");
ColorVector color6 = ColorVector.FromHex("#000000FF");
Assert.Equal(color1, color2);
Assert.Equal(color1, color3);
Assert.Equal(color1, color4);
Assert.Equal(color1, color5);
Assert.Equal(color1, color6);
}
/// <summary>
/// Tests the equality operators for inequality.
/// </summary>
[Fact]
public void AreNotEqual()
{
ColorVector color1 = new ColorVector(1, 0, 0, 1);
ColorVector color2 = new ColorVector(0, 0, 0, 1);
ColorVector color3 = ColorVector.FromHex("#000");
ColorVector color4 = ColorVector.FromHex("#000000");
ColorVector color5 = ColorVector.FromHex("#FF000000");
Assert.NotEqual(color1, color2);
Assert.NotEqual(color1, color3);
Assert.NotEqual(color1, color4);
Assert.NotEqual(color1, color5);
}
/// <summary>
/// Tests whether the color constructor correctly assign properties.
/// </summary>
[Fact]
public void ConstructorAssignsProperties()
{
ColorVector color1 = new ColorVector(1, .1F, .133F, .864F);
Assert.Equal(1F, color1.R);
Assert.Equal(.1F, color1.G);
Assert.Equal(.133F, color1.B);
Assert.Equal(.864F, color1.A);
ColorVector color2 = new ColorVector(1, .1f, .133f);
Assert.Equal(1F, color2.R);
Assert.Equal(.1F, color2.G);
Assert.Equal(.133F, color2.B);
Assert.Equal(1F, color2.A);
ColorVector color4 = new ColorVector(new Vector3(1, .1f, .133f));
Assert.Equal(1F, color4.R);
Assert.Equal(.1F, color4.G);
Assert.Equal(.133F, color4.B);
Assert.Equal(1F, color4.A);
ColorVector color5 = new ColorVector(new Vector4(1, .1f, .133f, .5f));
Assert.Equal(1F, color5.R);
Assert.Equal(.1F, color5.G);
Assert.Equal(.133F, color5.B);
Assert.Equal(.5F, color5.A);
}
/// <summary>
/// Tests whether FromHex and ToHex work correctly.
/// </summary>
[Fact]
public void FromAndToHex()
{
ColorVector color = ColorVector.FromHex("#AABBCCDD");
Assert.Equal(170 / 255F, color.R);
Assert.Equal(187 / 255F, color.G);
Assert.Equal(204 / 255F, color.B);
Assert.Equal(221 / 255F, color.A);
color.A = 170 / 255F;
color.B = 187 / 255F;
color.G = 204 / 255F;
color.R = 221 / 255F;
Assert.Equal("DDCCBBAA", color.ToHex());
color.R = 0;
Assert.Equal("00CCBBAA", color.ToHex());
color.A = 255 / 255F;
Assert.Equal("00CCBBFF", color.ToHex());
}
/// <summary>
/// Tests that the individual float elements are layed out in RGBA order.
/// </summary>
[Fact]
public void FloatLayout()
{
ColorVector color = new ColorVector(1F, 2, 3, 4);
Vector4 colorBase = Unsafe.As<ColorVector, Vector4>(ref Unsafe.Add(ref color, 0));
float[] ordered = new float[4];
colorBase.CopyTo(ordered);
Assert.Equal(1, ordered[0]);
Assert.Equal(2, ordered[1]);
Assert.Equal(3, ordered[2]);
Assert.Equal(4, ordered[3]);
}
}
}

118
tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs

@ -0,0 +1,118 @@
// <copyright file="ColorVectorTransformTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Colors
{
using Xunit;
/// <summary>
/// Tests the color transform algorithms. Test results match the output of CSS equivalents.
/// <see href="https://jsfiddle.net/jamessouth/L1v8r6kh/"/>
/// </summary>
public class ColorVectorTransformTests
{
private static readonly ApproximateFloatComparer FloatComparer = new ApproximateFloatComparer(0.01F);
/// <summary>
/// Orange backdrop
/// </summary>
private static readonly ColorVector Backdrop = new ColorVector(204, 102, 0);
/// <summary>
/// Blue source
/// </summary>
private static readonly ColorVector Source = new ColorVector(0, 102, 153);
[Fact]
public void Normal()
{
ColorVector normal = ColorVector.Normal(Backdrop, Source);
Assert.True(normal == Source);
}
[Fact]
public void Multiply()
{
Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.Black).ToVector4(), Color.Black.ToVector4(), FloatComparer);
Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.White).ToVector4(), Backdrop.ToVector4(), FloatComparer);
ColorVector multiply = ColorVector.Multiply(Backdrop, Source);
Assert.Equal(multiply.ToVector4(), new ColorVector(0, 41, 0).ToVector4(), FloatComparer);
}
[Fact]
public void Screen()
{
Assert.Equal(ColorVector.Screen(Backdrop, ColorVector.Black).ToVector4(), Backdrop.ToVector4(), FloatComparer);
Assert.Equal(ColorVector.Screen(Backdrop, ColorVector.White).ToVector4(), ColorVector.White.ToVector4(), FloatComparer);
ColorVector screen = ColorVector.Screen(Backdrop, Source);
Assert.Equal(screen.ToVector4(), new ColorVector(204, 163, 153).ToVector4(), FloatComparer);
}
[Fact]
public void HardLight()
{
ColorVector hardLight = ColorVector.HardLight(Backdrop, Source);
Assert.Equal(hardLight.ToVector4(), new ColorVector(0, 82, 51).ToVector4(), FloatComparer);
}
[Fact]
public void Overlay()
{
ColorVector overlay = ColorVector.Overlay(Backdrop, Source);
Assert.Equal(overlay.ToVector4(), new ColorVector(153, 82, 0).ToVector4(), FloatComparer);
}
[Fact]
public void Darken()
{
ColorVector darken = ColorVector.Darken(Backdrop, Source);
Assert.Equal(darken.ToVector4(), new ColorVector(0, 102, 0).ToVector4(), FloatComparer);
}
[Fact]
public void Lighten()
{
ColorVector lighten = ColorVector.Lighten(Backdrop, Source);
Assert.Equal(lighten.ToVector4(), new ColorVector(204, 102, 153).ToVector4(), FloatComparer);
}
[Fact]
public void SoftLight()
{
ColorVector softLight = ColorVector.SoftLight(Backdrop, Source);
Assert.Equal(softLight.ToVector4(), new ColorVector(163, 90, 0).ToVector4(), FloatComparer);
}
[Fact]
public void ColorDodge()
{
ColorVector colorDodge = ColorVector.ColorDodge(Backdrop, Source);
Assert.Equal(colorDodge.ToVector4(), new ColorVector(204, 170, 0).ToVector4(), FloatComparer);
}
[Fact]
public void ColorBurn()
{
ColorVector colorBurn = ColorVector.ColorBurn(Backdrop, Source);
Assert.Equal(colorBurn.ToVector4(), new ColorVector(0, 0, 0).ToVector4(), FloatComparer);
}
[Fact]
public void Difference()
{
ColorVector difference = ColorVector.Difference(Backdrop, Source);
Assert.Equal(difference.ToVector4(), new ColorVector(204, 0, 153).ToVector4(), FloatComparer);
}
[Fact]
public void Exclusion()
{
ColorVector exclusion = ColorVector.Exclusion(Backdrop, Source);
Assert.Equal(exclusion.ToVector4(), new ColorVector(204, 122, 153).ToVector4(), FloatComparer);
}
}
}

45
tests/ImageSharp.Tests/Colors/PackedPixelTests.cs

@ -711,6 +711,51 @@ namespace ImageSharp.Tests.Colors
Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 }); Assert.Equal(rgba, new byte[] { 25, 0, 128, 0 });
} }
[Fact]
public void Rgba32()
{
// Test the limits.
Assert.Equal((uint)0x0, new Rgba32(Vector4.Zero).PackedValue);
Assert.Equal(0xFFFFFFFF, new Rgba32(Vector4.One).PackedValue);
// Test ToVector4.
Assert.True(Equal(Vector4.One, new Rgba32(Vector4.One).ToVector4()));
Assert.True(Equal(Vector4.Zero, new Rgba32(Vector4.Zero).ToVector4()));
Assert.True(Equal(Vector4.UnitX, new Rgba32(Vector4.UnitX).ToVector4()));
Assert.True(Equal(Vector4.UnitY, new Rgba32(Vector4.UnitY).ToVector4()));
Assert.True(Equal(Vector4.UnitZ, new Rgba32(Vector4.UnitZ).ToVector4()));
Assert.True(Equal(Vector4.UnitW, new Rgba32(Vector4.UnitW).ToVector4()));
// Test clamping.
Assert.True(Equal(Vector4.Zero, new Rgba32(Vector4.One * -1234.0f).ToVector4()));
Assert.True(Equal(Vector4.One, new Rgba32(Vector4.One * +1234.0f).ToVector4()));
float x = +0.1f;
float y = -0.3f;
float z = +0.5f;
float w = -0.7f;
Rgba32 rgba32 = new Rgba32(x, y, z, w);
Assert.Equal(0x80001Au, rgba32.PackedValue);
// Test ordering
byte[] rgb = new byte[3];
byte[] rgba = new byte[4];
byte[] bgr = new byte[3];
byte[] bgra = new byte[4];
rgba32.ToXyzBytes(rgb, 0);
Assert.Equal(rgb, new byte[] { 0x1a, 0, 0x80 });
rgba32.ToXyzwBytes(rgba, 0);
Assert.Equal(rgba, new byte[] { 0x1a, 0, 0x80, 0 });
rgba32.ToZyxBytes(bgr, 0);
Assert.Equal(bgr, new byte[] { 0x80, 0, 0x1a });
rgba32.ToZyxwBytes(bgra, 0);
Assert.Equal(bgra, new byte[] { 0x80, 0, 0x1a, 0 });
}
[Fact] [Fact]
public void Rgba64() public void Rgba64()
{ {

148
tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs

@ -0,0 +1,148 @@
namespace ImageSharp.Tests.Colors
{
using System.Numerics;
using Xunit;
public class UnPackedPixelTests
{
[Fact]
public void Color_Types_From_Bytes_Produce_Equal_Scaled_Component_OutPut()
{
Color color = new Color(24, 48, 96, 192);
ColorVector colorVector = new ColorVector(24, 48, 96, 192);
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
Assert.Equal(color.B, (byte)(colorVector.B * 255));
Assert.Equal(color.A, (byte)(colorVector.A * 255));
}
[Fact]
public void Color_Types_From_Floats_Produce_Equal_Scaled_Component_OutPut()
{
Color color = new Color(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
ColorVector colorVector = new ColorVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F);
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
Assert.Equal(color.B, (byte)(colorVector.B * 255));
Assert.Equal(color.A, (byte)(colorVector.A * 255));
}
[Fact]
public void Color_Types_From_Vector4_Produce_Equal_Scaled_Component_OutPut()
{
Color color = new Color(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
ColorVector colorVector = new ColorVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F));
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
Assert.Equal(color.B, (byte)(colorVector.B * 255));
Assert.Equal(color.A, (byte)(colorVector.A * 255));
}
[Fact]
public void Color_Types_From_Vector3_Produce_Equal_Scaled_Component_OutPut()
{
Color color = new Color(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
ColorVector colorVector = new ColorVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F));
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
Assert.Equal(color.B, (byte)(colorVector.B * 255));
Assert.Equal(color.A, (byte)(colorVector.A * 255));
}
[Fact]
public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut()
{
Color color = Color.FromHex("183060C0");
ColorVector colorVector = ColorVector.FromHex("183060C0");
Assert.Equal(color.R, (byte)(colorVector.R * 255));
Assert.Equal(color.G, (byte)(colorVector.G * 255));
Assert.Equal(color.B, (byte)(colorVector.B * 255));
Assert.Equal(color.A, (byte)(colorVector.A * 255));
}
[Fact]
public void Color_Types_To_Vector4_Produce_Equal_OutPut()
{
Color color = new Color(24, 48, 96, 192);
ColorVector colorVector = new ColorVector(24, 48, 96, 192);
Assert.Equal(color.ToVector4(), colorVector.ToVector4());
}
[Fact]
public void Color_Types_To_RgbBytes_Produce_Equal_OutPut()
{
Color color = new Color(24, 48, 96, 192);
ColorVector colorVector = new ColorVector(24, 48, 96, 192);
byte[] rgb = new byte[3];
byte[] rgbVector = new byte[3];
color.ToXyzBytes(rgb, 0);
colorVector.ToXyzBytes(rgbVector, 0);
Assert.Equal(rgb, rgbVector);
}
[Fact]
public void Color_Types_To_RgbaBytes_Produce_Equal_OutPut()
{
Color color = new Color(24, 48, 96, 192);
ColorVector colorVector = new ColorVector(24, 48, 96, 192);
byte[] rgba = new byte[4];
byte[] rgbaVector = new byte[4];
color.ToXyzwBytes(rgba, 0);
colorVector.ToXyzwBytes(rgbaVector, 0);
Assert.Equal(rgba, rgbaVector);
}
[Fact]
public void Color_Types_To_BgrBytes_Produce_Equal_OutPut()
{
Color color = new Color(24, 48, 96, 192);
ColorVector colorVector = new ColorVector(24, 48, 96, 192);
byte[] bgr = new byte[3];
byte[] bgrVector = new byte[3];
color.ToZyxBytes(bgr, 0);
colorVector.ToZyxBytes(bgrVector, 0);
Assert.Equal(bgr, bgrVector);
}
[Fact]
public void Color_Types_To_BgraBytes_Produce_Equal_OutPut()
{
Color color = new Color(24, 48, 96, 192);
ColorVector colorVector = new ColorVector(24, 48, 96, 192);
byte[] bgra = new byte[4];
byte[] bgraVector = new byte[4];
color.ToZyxwBytes(bgra, 0);
colorVector.ToZyxwBytes(bgraVector, 0);
Assert.Equal(bgra, bgraVector);
}
[Fact]
public void Color_Types_To_Hex_Produce_Equal_OutPut()
{
Color color = new Color(24, 48, 96, 192);
ColorVector colorVector = new ColorVector(24, 48, 96, 192);
// 183060C0
Assert.Equal(color.ToHex(), colorVector.ToHex());
}
}
}

14
tests/ImageSharp.Tests/Common/BufferSpanTests.cs

@ -9,7 +9,7 @@ namespace ImageSharp.Tests.Common
using Xunit; using Xunit;
using static TestStructs; using static TestStructs;
public unsafe class BufferSpanTests public unsafe class BufferSpanTests
{ {
// ReSharper disable once ClassNeverInstantiated.Local // ReSharper disable once ClassNeverInstantiated.Local
@ -38,7 +38,7 @@ namespace ImageSharp.Tests.Common
Assert.SameRefs(ref orig.DangerousGetPinnableReference(), ref asBytes.DangerousGetPinnableReference()); Assert.SameRefs(ref orig.DangerousGetPinnableReference(), ref asBytes.DangerousGetPinnableReference());
} }
} }
public class Construct public class Construct
{ {
[Fact] [Fact]
@ -331,7 +331,7 @@ namespace ImageSharp.Tests.Common
BufferSpan<Foo> apSource = new BufferSpan<Foo>(source, 1); BufferSpan<Foo> apSource = new BufferSpan<Foo>(source, 1);
BufferSpan<byte> apDest = new BufferSpan<byte>(dest, sizeof(Foo)); BufferSpan<byte> apDest = new BufferSpan<byte>(dest, sizeof(Foo));
BufferSpan.Copy(apSource.AsBytes(), apDest, (count - 1)*sizeof(Foo)); BufferSpan.Copy(apSource.AsBytes(), apDest, (count - 1) * sizeof(Foo));
AssertNotDefault(source, 1); AssertNotDefault(source, 1);
@ -377,7 +377,7 @@ namespace ImageSharp.Tests.Common
BufferSpan<int> apSource = new BufferSpan<int>(source); BufferSpan<int> apSource = new BufferSpan<int>(source);
BufferSpan<byte> apDest = new BufferSpan<byte>(dest); BufferSpan<byte> apDest = new BufferSpan<byte>(dest);
BufferSpan.Copy(apSource.AsBytes(), apDest, count*sizeof(int)); BufferSpan.Copy(apSource.AsBytes(), apDest, count * sizeof(int));
AssertNotDefault(source, 1); AssertNotDefault(source, 1);
@ -398,7 +398,7 @@ namespace ImageSharp.Tests.Common
BufferSpan<byte> apSource = new BufferSpan<byte>(source); BufferSpan<byte> apSource = new BufferSpan<byte>(source);
BufferSpan<Foo> apDest = new BufferSpan<Foo>(dest); BufferSpan<Foo> apDest = new BufferSpan<Foo>(dest);
BufferSpan.Copy(apSource, apDest.AsBytes(), count*sizeof(Foo)); BufferSpan.Copy(apSource, apDest.AsBytes(), count * sizeof(Foo));
AssertNotDefault(source, sizeof(Foo) + 1); AssertNotDefault(source, sizeof(Foo) + 1);
AssertNotDefault(dest, 1); AssertNotDefault(dest, 1);
@ -410,14 +410,14 @@ namespace ImageSharp.Tests.Common
} }
[Fact] [Fact]
public void ColorToBytes() public void Color32ToBytes()
{ {
Color[] colors = { new Color(0, 1, 2, 3), new Color(4, 5, 6, 7), new Color(8, 9, 10, 11), }; Color[] colors = { new Color(0, 1, 2, 3), new Color(4, 5, 6, 7), new Color(8, 9, 10, 11), };
using (Buffer<Color> colorBuf = new Buffer<Color>(colors)) using (Buffer<Color> colorBuf = new Buffer<Color>(colors))
using (Buffer<byte> byteBuf = new Buffer<byte>(colors.Length * 4)) using (Buffer<byte> byteBuf = new Buffer<byte>(colors.Length * 4))
{ {
BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length*sizeof(Color)); BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length * sizeof(Color));
byte[] a = byteBuf.Array; byte[] a = byteBuf.Array;

10
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

@ -61,7 +61,7 @@ namespace ImageSharp.Tests
BlackWhiteChecker(pixels); // top left BlackWhiteChecker(pixels); // top left
VirticalBars(pixels); // top right VirticalBars(pixels); // top right
TransparentGradients(pixels); // bottom left TransparentGradients(pixels); // bottom left
Rainbow(pixels); // bottom right Rainbow(pixels); // bottom right
} }
} }
/// <summary> /// <summary>
@ -70,7 +70,7 @@ namespace ImageSharp.Tests
/// <param name="pixels"></param> /// <param name="pixels"></param>
private static void VirticalBars(PixelAccessor<TColor> pixels) private static void VirticalBars(PixelAccessor<TColor> pixels)
{ {
// topLeft // topLeft
int left = pixels.Width / 2; int left = pixels.Width / 2;
int right = pixels.Width; int right = pixels.Width;
int top = 0; int top = 0;
@ -101,7 +101,7 @@ namespace ImageSharp.Tests
/// <param name="pixels"></param> /// <param name="pixels"></param>
private static void BlackWhiteChecker(PixelAccessor<TColor> pixels) private static void BlackWhiteChecker(PixelAccessor<TColor> pixels)
{ {
// topLeft // topLeft
int left = 0; int left = 0;
int right = pixels.Width / 2; int right = pixels.Width / 2;
int top = 0; int top = 0;
@ -140,7 +140,7 @@ namespace ImageSharp.Tests
/// <param name="pixels"></param> /// <param name="pixels"></param>
private static void TransparentGradients(PixelAccessor<TColor> pixels) private static void TransparentGradients(PixelAccessor<TColor> pixels)
{ {
// topLeft // topLeft
int left = 0; int left = 0;
int right = pixels.Width / 2; int right = pixels.Width / 2;
int top = pixels.Height / 2; int top = pixels.Height / 2;
@ -193,7 +193,7 @@ namespace ImageSharp.Tests
int pixelCount = left * top; int pixelCount = left * top;
uint stepsPerPixel = (uint)(uint.MaxValue / pixelCount); uint stepsPerPixel = (uint)(uint.MaxValue / pixelCount);
TColor c = default(TColor); TColor c = default(TColor);
Color t = new Color(0); Rgba32 t = new Rgba32(0);
for (int x = left; x < right; x++) for (int x = left; x < right; x++)
for (int y = top; y < bottom; y++) for (int y = top; y < bottom; y++)

Loading…
Cancel
Save