Browse Source

Merge pull request #1104 from SixLabors/js/feature-color-parse

Add new Color parsing methods.
af/octree-no-pixelmap
James Jackson-South 6 years ago
committed by GitHub
parent
commit
ee6d0c87d5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 200
      src/ImageSharp/Color/Color.NamedColors.cs
  2. 222
      src/ImageSharp/Color/Color.WernerPalette.cs
  3. 91
      src/ImageSharp/Color/Color.cs
  4. 278
      src/ImageSharp/PixelFormats/ColorConstants.cs
  5. 721
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.Definitions.cs
  6. 42
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
  7. 2
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
  8. 4
      tests/ImageSharp.Benchmarks/Codecs/GetSetPixel.cs
  9. 2
      tests/ImageSharp.Benchmarks/Samplers/Diffuse.cs
  10. 2
      tests/ImageSharp.Benchmarks/Samplers/GaussianBlur.cs
  11. 2
      tests/ImageSharp.Benchmarks/Samplers/Rotate.cs
  12. 2
      tests/ImageSharp.Benchmarks/Samplers/Skew.cs
  13. 138
      tests/ImageSharp.Tests/Color/ColorTests.cs
  14. 665
      tests/ImageSharp.Tests/Color/ReferencePalette.cs
  15. 4
      tests/ImageSharp.Tests/Drawing/DrawImageTests.cs
  16. 4
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs
  17. 8
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs
  18. 22
      tests/ImageSharp.Tests/Image/ImageTests.LoadPixelData.cs
  19. 2
      tests/ImageSharp.Tests/Image/ImageTests.cs
  20. 42
      tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs
  21. 16
      tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs
  22. 2
      tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs
  23. 2
      tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs
  24. 4
      tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs
  25. 2
      tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs
  26. 4
      tests/ImageSharp.Tests/Quantization/WuQuantizerTests.cs
  27. 6
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

200
src/ImageSharp/Color/Color.NamedColors.cs

@ -1,6 +1,9 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp
{ {
/// <content> /// <content>
@ -8,6 +11,8 @@ namespace SixLabors.ImageSharp
/// </content> /// </content>
public readonly partial struct Color public readonly partial struct Color
{ {
private static readonly Lazy<Dictionary<string, Color>> NamedColorsLookupLazy = new Lazy<Dictionary<string, Color>>(CreateNamedColorsLookup, true);
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #F0F8FF. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #F0F8FF.
/// </summary> /// </summary>
@ -111,7 +116,7 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #00FFFF. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary> /// </summary>
public static readonly Color Cyan = FromRgba(0, 255, 255, 255); public static readonly Color Cyan = Aqua;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #00008B. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #00008B.
@ -138,6 +143,11 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public static readonly Color DarkGreen = FromRgba(0, 100, 0, 255); public static readonly Color DarkGreen = FromRgba(0, 100, 0, 255);
/// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #A9A9A9.
/// </summary>
public static readonly Color DarkGrey = DarkGray;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #BDB76B. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #BDB76B.
/// </summary> /// </summary>
@ -188,6 +198,11 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public static readonly Color DarkSlateGray = FromRgba(47, 79, 79, 255); public static readonly Color DarkSlateGray = FromRgba(47, 79, 79, 255);
/// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #2F4F4F.
/// </summary>
public static readonly Color DarkSlateGrey = DarkSlateGray;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #00CED1. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #00CED1.
/// </summary> /// </summary>
@ -213,6 +228,11 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public static readonly Color DimGray = FromRgba(105, 105, 105, 255); public static readonly Color DimGray = FromRgba(105, 105, 105, 255);
/// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #696969.
/// </summary>
public static readonly Color DimGrey = DimGray;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #1E90FF. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #1E90FF.
/// </summary> /// </summary>
@ -273,6 +293,11 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public static readonly Color GreenYellow = FromRgba(173, 255, 47, 255); public static readonly Color GreenYellow = FromRgba(173, 255, 47, 255);
/// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #808080.
/// </summary>
public static readonly Color Grey = Gray;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #F0FFF0. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #F0FFF0.
/// </summary> /// </summary>
@ -353,6 +378,11 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public static readonly Color LightGreen = FromRgba(144, 238, 144, 255); public static readonly Color LightGreen = FromRgba(144, 238, 144, 255);
/// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #D3D3D3.
/// </summary>
public static readonly Color LightGrey = LightGray;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #FFB6C1. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #FFB6C1.
/// </summary> /// </summary>
@ -378,6 +408,11 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public static readonly Color LightSlateGray = FromRgba(119, 136, 153, 255); public static readonly Color LightSlateGray = FromRgba(119, 136, 153, 255);
/// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #778899.
/// </summary>
public static readonly Color LightSlateGrey = LightSlateGray;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #B0C4DE. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #B0C4DE.
/// </summary> /// </summary>
@ -406,7 +441,7 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #FF00FF. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary> /// </summary>
public static readonly Color Magenta = FromRgba(255, 0, 255, 255); public static readonly Color Magenta = Fuchsia;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #800000. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #800000.
@ -643,6 +678,11 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public static readonly Color SlateGray = FromRgba(112, 128, 144, 255); public static readonly Color SlateGray = FromRgba(112, 128, 144, 255);
/// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #708090.
/// </summary>
public static readonly Color SlateGrey = SlateGray;
/// <summary> /// <summary>
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #FFFAFA. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #FFFAFA.
/// </summary> /// </summary>
@ -717,5 +757,161 @@ namespace SixLabors.ImageSharp
/// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #9ACD32. /// Represents a <see paramref="Color"/> matching the W3C definition that has an hex value of #9ACD32.
/// </summary> /// </summary>
public static readonly Color YellowGreen = FromRgba(154, 205, 50, 255); public static readonly Color YellowGreen = FromRgba(154, 205, 50, 255);
private static Dictionary<string, Color> CreateNamedColorsLookup()
{
return new Dictionary<string, Color>(StringComparer.OrdinalIgnoreCase)
{
{ nameof(AliceBlue), AliceBlue },
{ nameof(AntiqueWhite), AntiqueWhite },
{ nameof(Aqua), Aqua },
{ nameof(Aquamarine), Aquamarine },
{ nameof(Azure), Azure },
{ nameof(Beige), Beige },
{ nameof(Bisque), Bisque },
{ nameof(Black), Black },
{ nameof(BlanchedAlmond), BlanchedAlmond },
{ nameof(Blue), Blue },
{ nameof(BlueViolet), BlueViolet },
{ nameof(Brown), Brown },
{ nameof(BurlyWood), BurlyWood },
{ nameof(CadetBlue), CadetBlue },
{ nameof(Chartreuse), Chartreuse },
{ nameof(Chocolate), Chocolate },
{ nameof(Coral), Coral },
{ nameof(CornflowerBlue), CornflowerBlue },
{ nameof(Cornsilk), Cornsilk },
{ nameof(Crimson), Crimson },
{ nameof(Cyan), Cyan },
{ nameof(DarkBlue), DarkBlue },
{ nameof(DarkCyan), DarkCyan },
{ nameof(DarkGoldenrod), DarkGoldenrod },
{ nameof(DarkGray), DarkGray },
{ nameof(DarkGreen), DarkGreen },
{ nameof(DarkGrey), DarkGrey },
{ nameof(DarkKhaki), DarkKhaki },
{ nameof(DarkMagenta), DarkMagenta },
{ nameof(DarkOliveGreen), DarkOliveGreen },
{ nameof(DarkOrange), DarkOrange },
{ nameof(DarkOrchid), DarkOrchid },
{ nameof(DarkRed), DarkRed },
{ nameof(DarkSalmon), DarkSalmon },
{ nameof(DarkSeaGreen), DarkSeaGreen },
{ nameof(DarkSlateBlue), DarkSlateBlue },
{ nameof(DarkSlateGray), DarkSlateGray },
{ nameof(DarkSlateGrey), DarkSlateGrey },
{ nameof(DarkTurquoise), DarkTurquoise },
{ nameof(DarkViolet), DarkViolet },
{ nameof(DeepPink), DeepPink },
{ nameof(DeepSkyBlue), DeepSkyBlue },
{ nameof(DimGray), DimGray },
{ nameof(DimGrey), DimGrey },
{ nameof(DodgerBlue), DodgerBlue },
{ nameof(Firebrick), Firebrick },
{ nameof(FloralWhite), FloralWhite },
{ nameof(ForestGreen), ForestGreen },
{ nameof(Fuchsia), Fuchsia },
{ nameof(Gainsboro), Gainsboro },
{ nameof(GhostWhite), GhostWhite },
{ nameof(Gold), Gold },
{ nameof(Goldenrod), Goldenrod },
{ nameof(Gray), Gray },
{ nameof(Green), Green },
{ nameof(GreenYellow), GreenYellow },
{ nameof(Grey), Grey },
{ nameof(Honeydew), Honeydew },
{ nameof(HotPink), HotPink },
{ nameof(IndianRed), IndianRed },
{ nameof(Indigo), Indigo },
{ nameof(Ivory), Ivory },
{ nameof(Khaki), Khaki },
{ nameof(Lavender), Lavender },
{ nameof(LavenderBlush), LavenderBlush },
{ nameof(LawnGreen), LawnGreen },
{ nameof(LemonChiffon), LemonChiffon },
{ nameof(LightBlue), LightBlue },
{ nameof(LightCoral), LightCoral },
{ nameof(LightCyan), LightCyan },
{ nameof(LightGoldenrodYellow), LightGoldenrodYellow },
{ nameof(LightGray), LightGray },
{ nameof(LightGreen), LightGreen },
{ nameof(LightGrey), LightGrey },
{ nameof(LightPink), LightPink },
{ nameof(LightSalmon), LightSalmon },
{ nameof(LightSeaGreen), LightSeaGreen },
{ nameof(LightSkyBlue), LightSkyBlue },
{ nameof(LightSlateGray), LightSlateGray },
{ nameof(LightSlateGrey), LightSlateGrey },
{ nameof(LightSteelBlue), LightSteelBlue },
{ nameof(LightYellow), LightYellow },
{ nameof(Lime), Lime },
{ nameof(LimeGreen), LimeGreen },
{ nameof(Linen), Linen },
{ nameof(Magenta), Magenta },
{ nameof(Maroon), Maroon },
{ nameof(MediumAquamarine), MediumAquamarine },
{ nameof(MediumBlue), MediumBlue },
{ nameof(MediumOrchid), MediumOrchid },
{ nameof(MediumPurple), MediumPurple },
{ nameof(MediumSeaGreen), MediumSeaGreen },
{ nameof(MediumSlateBlue), MediumSlateBlue },
{ nameof(MediumSpringGreen), MediumSpringGreen },
{ nameof(MediumTurquoise), MediumTurquoise },
{ nameof(MediumVioletRed), MediumVioletRed },
{ nameof(MidnightBlue), MidnightBlue },
{ nameof(MintCream), MintCream },
{ nameof(MistyRose), MistyRose },
{ nameof(Moccasin), Moccasin },
{ nameof(NavajoWhite), NavajoWhite },
{ nameof(Navy), Navy },
{ nameof(OldLace), OldLace },
{ nameof(Olive), Olive },
{ nameof(OliveDrab), OliveDrab },
{ nameof(Orange), Orange },
{ nameof(OrangeRed), OrangeRed },
{ nameof(Orchid), Orchid },
{ nameof(PaleGoldenrod), PaleGoldenrod },
{ nameof(PaleGreen), PaleGreen },
{ nameof(PaleTurquoise), PaleTurquoise },
{ nameof(PaleVioletRed), PaleVioletRed },
{ nameof(PapayaWhip), PapayaWhip },
{ nameof(PeachPuff), PeachPuff },
{ nameof(Peru), Peru },
{ nameof(Pink), Pink },
{ nameof(Plum), Plum },
{ nameof(PowderBlue), PowderBlue },
{ nameof(Purple), Purple },
{ nameof(RebeccaPurple), RebeccaPurple },
{ nameof(Red), Red },
{ nameof(RosyBrown), RosyBrown },
{ nameof(RoyalBlue), RoyalBlue },
{ nameof(SaddleBrown), SaddleBrown },
{ nameof(Salmon), Salmon },
{ nameof(SandyBrown), SandyBrown },
{ nameof(SeaGreen), SeaGreen },
{ nameof(SeaShell), SeaShell },
{ nameof(Sienna), Sienna },
{ nameof(Silver), Silver },
{ nameof(SkyBlue), SkyBlue },
{ nameof(SlateBlue), SlateBlue },
{ nameof(SlateGray), SlateGray },
{ nameof(SlateGrey), SlateGrey },
{ nameof(Snow), Snow },
{ nameof(SpringGreen), SpringGreen },
{ nameof(SteelBlue), SteelBlue },
{ nameof(Tan), Tan },
{ nameof(Teal), Teal },
{ nameof(Thistle), Thistle },
{ nameof(Tomato), Tomato },
{ nameof(Transparent), Transparent },
{ nameof(Turquoise), Turquoise },
{ nameof(Violet), Violet },
{ nameof(Wheat), Wheat },
{ nameof(White), White },
{ nameof(WhiteSmoke), WhiteSmoke },
{ nameof(Yellow), Yellow },
{ nameof(YellowGreen), YellowGreen }
};
}
} }
} }

222
src/ImageSharp/Color/Color.WernerPalette.cs

@ -20,116 +20,116 @@ namespace SixLabors.ImageSharp
private static Color[] CreateWernerPalette() => new[] private static Color[] CreateWernerPalette() => new[]
{ {
FromHex("#f1e9cd"), ParseHex("#f1e9cd"),
FromHex("#f2e7cf"), ParseHex("#f2e7cf"),
FromHex("#ece6d0"), ParseHex("#ece6d0"),
FromHex("#f2eacc"), ParseHex("#f2eacc"),
FromHex("#f3e9ca"), ParseHex("#f3e9ca"),
FromHex("#f2ebcd"), ParseHex("#f2ebcd"),
FromHex("#e6e1c9"), ParseHex("#e6e1c9"),
FromHex("#e2ddc6"), ParseHex("#e2ddc6"),
FromHex("#cbc8b7"), ParseHex("#cbc8b7"),
FromHex("#bfbbb0"), ParseHex("#bfbbb0"),
FromHex("#bebeb3"), ParseHex("#bebeb3"),
FromHex("#b7b5ac"), ParseHex("#b7b5ac"),
FromHex("#bab191"), ParseHex("#bab191"),
FromHex("#9c9d9a"), ParseHex("#9c9d9a"),
FromHex("#8a8d84"), ParseHex("#8a8d84"),
FromHex("#5b5c61"), ParseHex("#5b5c61"),
FromHex("#555152"), ParseHex("#555152"),
FromHex("#413f44"), ParseHex("#413f44"),
FromHex("#454445"), ParseHex("#454445"),
FromHex("#423937"), ParseHex("#423937"),
FromHex("#433635"), ParseHex("#433635"),
FromHex("#252024"), ParseHex("#252024"),
FromHex("#241f20"), ParseHex("#241f20"),
FromHex("#281f3f"), ParseHex("#281f3f"),
FromHex("#1c1949"), ParseHex("#1c1949"),
FromHex("#4f638d"), ParseHex("#4f638d"),
FromHex("#383867"), ParseHex("#383867"),
FromHex("#5c6b8f"), ParseHex("#5c6b8f"),
FromHex("#657abb"), ParseHex("#657abb"),
FromHex("#6f88af"), ParseHex("#6f88af"),
FromHex("#7994b5"), ParseHex("#7994b5"),
FromHex("#6fb5a8"), ParseHex("#6fb5a8"),
FromHex("#719ba2"), ParseHex("#719ba2"),
FromHex("#8aa1a6"), ParseHex("#8aa1a6"),
FromHex("#d0d5d3"), ParseHex("#d0d5d3"),
FromHex("#8590ae"), ParseHex("#8590ae"),
FromHex("#3a2f52"), ParseHex("#3a2f52"),
FromHex("#39334a"), ParseHex("#39334a"),
FromHex("#6c6d94"), ParseHex("#6c6d94"),
FromHex("#584c77"), ParseHex("#584c77"),
FromHex("#533552"), ParseHex("#533552"),
FromHex("#463759"), ParseHex("#463759"),
FromHex("#bfbac0"), ParseHex("#bfbac0"),
FromHex("#77747f"), ParseHex("#77747f"),
FromHex("#4a475c"), ParseHex("#4a475c"),
FromHex("#b8bfaf"), ParseHex("#b8bfaf"),
FromHex("#b2b599"), ParseHex("#b2b599"),
FromHex("#979c84"), ParseHex("#979c84"),
FromHex("#5d6161"), ParseHex("#5d6161"),
FromHex("#61ac86"), ParseHex("#61ac86"),
FromHex("#a4b6a7"), ParseHex("#a4b6a7"),
FromHex("#adba98"), ParseHex("#adba98"),
FromHex("#93b778"), ParseHex("#93b778"),
FromHex("#7d8c55"), ParseHex("#7d8c55"),
FromHex("#33431e"), ParseHex("#33431e"),
FromHex("#7c8635"), ParseHex("#7c8635"),
FromHex("#8e9849"), ParseHex("#8e9849"),
FromHex("#c2c190"), ParseHex("#c2c190"),
FromHex("#67765b"), ParseHex("#67765b"),
FromHex("#ab924b"), ParseHex("#ab924b"),
FromHex("#c8c76f"), ParseHex("#c8c76f"),
FromHex("#ccc050"), ParseHex("#ccc050"),
FromHex("#ebdd99"), ParseHex("#ebdd99"),
FromHex("#ab9649"), ParseHex("#ab9649"),
FromHex("#dbc364"), ParseHex("#dbc364"),
FromHex("#e6d058"), ParseHex("#e6d058"),
FromHex("#ead665"), ParseHex("#ead665"),
FromHex("#d09b2c"), ParseHex("#d09b2c"),
FromHex("#a36629"), ParseHex("#a36629"),
FromHex("#a77d35"), ParseHex("#a77d35"),
FromHex("#f0d696"), ParseHex("#f0d696"),
FromHex("#d7c485"), ParseHex("#d7c485"),
FromHex("#f1d28c"), ParseHex("#f1d28c"),
FromHex("#efcc83"), ParseHex("#efcc83"),
FromHex("#f3daa7"), ParseHex("#f3daa7"),
FromHex("#dfa837"), ParseHex("#dfa837"),
FromHex("#ebbc71"), ParseHex("#ebbc71"),
FromHex("#d17c3f"), ParseHex("#d17c3f"),
FromHex("#92462f"), ParseHex("#92462f"),
FromHex("#be7249"), ParseHex("#be7249"),
FromHex("#bb603c"), ParseHex("#bb603c"),
FromHex("#c76b4a"), ParseHex("#c76b4a"),
FromHex("#a75536"), ParseHex("#a75536"),
FromHex("#b63e36"), ParseHex("#b63e36"),
FromHex("#b5493a"), ParseHex("#b5493a"),
FromHex("#cd6d57"), ParseHex("#cd6d57"),
FromHex("#711518"), ParseHex("#711518"),
FromHex("#e9c49d"), ParseHex("#e9c49d"),
FromHex("#eedac3"), ParseHex("#eedac3"),
FromHex("#eecfbf"), ParseHex("#eecfbf"),
FromHex("#ce536b"), ParseHex("#ce536b"),
FromHex("#b74a70"), ParseHex("#b74a70"),
FromHex("#b7757c"), ParseHex("#b7757c"),
FromHex("#612741"), ParseHex("#612741"),
FromHex("#7a4848"), ParseHex("#7a4848"),
FromHex("#3f3033"), ParseHex("#3f3033"),
FromHex("#8d746f"), ParseHex("#8d746f"),
FromHex("#4d3635"), ParseHex("#4d3635"),
FromHex("#6e3b31"), ParseHex("#6e3b31"),
FromHex("#864735"), ParseHex("#864735"),
FromHex("#553d3a"), ParseHex("#553d3a"),
FromHex("#613936"), ParseHex("#613936"),
FromHex("#7a4b3a"), ParseHex("#7a4b3a"),
FromHex("#946943"), ParseHex("#946943"),
FromHex("#c39e6d"), ParseHex("#c39e6d"),
FromHex("#513e32"), ParseHex("#513e32"),
FromHex("#8b7859"), ParseHex("#8b7859"),
FromHex("#9b856b"), ParseHex("#9b856b"),
FromHex("#766051"), ParseHex("#766051"),
FromHex("#453b32") ParseHex("#453b32")
}; };
} }
} }

91
src/ImageSharp/Color/Color.cs

@ -95,21 +95,102 @@ namespace SixLabors.ImageSharp
public static Color FromRgb(byte r, byte g, byte b) => new Color(r, g, b); public static Color FromRgb(byte r, byte g, byte b) => new Color(r, g, b);
/// <summary> /// <summary>
/// Creates a new <see cref="Color"/> instance from the string representing a color in hexadecimal form. /// Creates a new instance of the <see cref="Color"/> struct
/// from the given hexadecimal string.
/// </summary> /// </summary>
/// <param name="hex"> /// <param name="hex">
/// The hexadecimal representation of the combined color components arranged /// The hexadecimal representation of the combined color components arranged
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax. /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </param> /// </param>
/// <returns>Returns a <see cref="Color"/> that represents the color defined by the provided RGBA hex string.</returns> /// <returns>
/// The <see cref="Color"/>.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public static Color FromHex(string hex) public static Color ParseHex(string hex)
{ {
var rgba = Rgba32.FromHex(hex); var rgba = Rgba32.ParseHex(hex);
return new Color(rgba); return new Color(rgba);
} }
/// <summary>
/// Attempts to creates a new instance of the <see cref="Color"/> struct
/// from the given hexadecimal string.
/// </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>
/// <param name="result">When this method returns, contains the <see cref="Color"/> equivalent of the hexadecimal input.</param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool TryParseHex(string hex, out Color result)
{
result = default;
if (Rgba32.TryParseHex(hex, out Rgba32 rgba))
{
result = new Color(rgba);
return true;
}
return false;
}
/// <summary>
/// Creates a new instance of the <see cref="Color"/> struct
/// from the given input string.
/// </summary>
/// <param name="input">
/// The name of the color or 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="Color"/>.
/// </returns>
public static Color Parse(string input)
{
Guard.NotNull(input, nameof(input));
if (!TryParse(input, out Color color))
{
throw new ArgumentException("Input string is not in the correct format.", nameof(input));
}
return color;
}
/// <summary>
/// Attempts to creates a new instance of the <see cref="Color"/> struct
/// from the given input string.
/// </summary>
/// <param name="input">
/// The name of the color or the hexadecimal representation of the combined color components arranged
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </param>
/// <param name="result">When this method returns, contains the <see cref="Color"/> equivalent of the hexadecimal input.</param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public static bool TryParse(string input, out Color result)
{
result = default;
if (string.IsNullOrWhiteSpace(input))
{
return false;
}
if (NamedColorsLookupLazy.Value.TryGetValue(input, out result))
{
return true;
}
return TryParseHex(input, out result);
}
/// <summary> /// <summary>
/// Alters the alpha channel of the color, returning a new instance. /// Alters the alpha channel of the color, returning a new instance.
/// </summary> /// </summary>
@ -117,7 +198,7 @@ namespace SixLabors.ImageSharp
/// <returns>The color having it's alpha channel altered.</returns> /// <returns>The color having it's alpha channel altered.</returns>
public Color WithAlpha(float alpha) public Color WithAlpha(float alpha)
{ {
Vector4 v = (Vector4)this; var v = (Vector4)this;
v.W = alpha; v.W = alpha;
return new Color(v); return new Color(v);
} }

278
src/ImageSharp/PixelFormats/ColorConstants.cs

@ -1,278 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.PixelFormats
{
/// <summary>
/// Provides useful color definitions.
/// </summary>
public static class ColorConstants
{
/// <summary>
/// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4.
/// </summary>
public static readonly Rgba32[] WebSafeColors =
{
Rgba32.AliceBlue,
Rgba32.AntiqueWhite,
Rgba32.Aqua,
Rgba32.Aquamarine,
Rgba32.Azure,
Rgba32.Beige,
Rgba32.Bisque,
Rgba32.Black,
Rgba32.BlanchedAlmond,
Rgba32.Blue,
Rgba32.BlueViolet,
Rgba32.Brown,
Rgba32.BurlyWood,
Rgba32.CadetBlue,
Rgba32.Chartreuse,
Rgba32.Chocolate,
Rgba32.Coral,
Rgba32.CornflowerBlue,
Rgba32.Cornsilk,
Rgba32.Crimson,
Rgba32.Cyan,
Rgba32.DarkBlue,
Rgba32.DarkCyan,
Rgba32.DarkGoldenrod,
Rgba32.DarkGray,
Rgba32.DarkGreen,
Rgba32.DarkKhaki,
Rgba32.DarkMagenta,
Rgba32.DarkOliveGreen,
Rgba32.DarkOrange,
Rgba32.DarkOrchid,
Rgba32.DarkRed,
Rgba32.DarkSalmon,
Rgba32.DarkSeaGreen,
Rgba32.DarkSlateBlue,
Rgba32.DarkSlateGray,
Rgba32.DarkTurquoise,
Rgba32.DarkViolet,
Rgba32.DeepPink,
Rgba32.DeepSkyBlue,
Rgba32.DimGray,
Rgba32.DodgerBlue,
Rgba32.Firebrick,
Rgba32.FloralWhite,
Rgba32.ForestGreen,
Rgba32.Fuchsia,
Rgba32.Gainsboro,
Rgba32.GhostWhite,
Rgba32.Gold,
Rgba32.Goldenrod,
Rgba32.Gray,
Rgba32.Green,
Rgba32.GreenYellow,
Rgba32.Honeydew,
Rgba32.HotPink,
Rgba32.IndianRed,
Rgba32.Indigo,
Rgba32.Ivory,
Rgba32.Khaki,
Rgba32.Lavender,
Rgba32.LavenderBlush,
Rgba32.LawnGreen,
Rgba32.LemonChiffon,
Rgba32.LightBlue,
Rgba32.LightCoral,
Rgba32.LightCyan,
Rgba32.LightGoldenrodYellow,
Rgba32.LightGray,
Rgba32.LightGreen,
Rgba32.LightPink,
Rgba32.LightSalmon,
Rgba32.LightSeaGreen,
Rgba32.LightSkyBlue,
Rgba32.LightSlateGray,
Rgba32.LightSteelBlue,
Rgba32.LightYellow,
Rgba32.Lime,
Rgba32.LimeGreen,
Rgba32.Linen,
Rgba32.Magenta,
Rgba32.Maroon,
Rgba32.MediumAquamarine,
Rgba32.MediumBlue,
Rgba32.MediumOrchid,
Rgba32.MediumPurple,
Rgba32.MediumSeaGreen,
Rgba32.MediumSlateBlue,
Rgba32.MediumSpringGreen,
Rgba32.MediumTurquoise,
Rgba32.MediumVioletRed,
Rgba32.MidnightBlue,
Rgba32.MintCream,
Rgba32.MistyRose,
Rgba32.Moccasin,
Rgba32.NavajoWhite,
Rgba32.Navy,
Rgba32.OldLace,
Rgba32.Olive,
Rgba32.OliveDrab,
Rgba32.Orange,
Rgba32.OrangeRed,
Rgba32.Orchid,
Rgba32.PaleGoldenrod,
Rgba32.PaleGreen,
Rgba32.PaleTurquoise,
Rgba32.PaleVioletRed,
Rgba32.PapayaWhip,
Rgba32.PeachPuff,
Rgba32.Peru,
Rgba32.Pink,
Rgba32.Plum,
Rgba32.PowderBlue,
Rgba32.Purple,
Rgba32.RebeccaPurple,
Rgba32.Red,
Rgba32.RosyBrown,
Rgba32.RoyalBlue,
Rgba32.SaddleBrown,
Rgba32.Salmon,
Rgba32.SandyBrown,
Rgba32.SeaGreen,
Rgba32.SeaShell,
Rgba32.Sienna,
Rgba32.Silver,
Rgba32.SkyBlue,
Rgba32.SlateBlue,
Rgba32.SlateGray,
Rgba32.Snow,
Rgba32.SpringGreen,
Rgba32.SteelBlue,
Rgba32.Tan,
Rgba32.Teal,
Rgba32.Thistle,
Rgba32.Tomato,
Rgba32.Transparent,
Rgba32.Turquoise,
Rgba32.Violet,
Rgba32.Wheat,
Rgba32.White,
Rgba32.WhiteSmoke,
Rgba32.Yellow,
Rgba32.YellowGreen
};
/// <summary>
/// Gets a collection of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821.
/// The hex codes were collected and defined by Nicholas Rougeux <see href="https://www.c82.net/werner"/>
/// </summary>
public static readonly Rgba32[] WernerColors =
{
Rgba32.FromHex("#f1e9cd"),
Rgba32.FromHex("#f2e7cf"),
Rgba32.FromHex("#ece6d0"),
Rgba32.FromHex("#f2eacc"),
Rgba32.FromHex("#f3e9ca"),
Rgba32.FromHex("#f2ebcd"),
Rgba32.FromHex("#e6e1c9"),
Rgba32.FromHex("#e2ddc6"),
Rgba32.FromHex("#cbc8b7"),
Rgba32.FromHex("#bfbbb0"),
Rgba32.FromHex("#bebeb3"),
Rgba32.FromHex("#b7b5ac"),
Rgba32.FromHex("#bab191"),
Rgba32.FromHex("#9c9d9a"),
Rgba32.FromHex("#8a8d84"),
Rgba32.FromHex("#5b5c61"),
Rgba32.FromHex("#555152"),
Rgba32.FromHex("#413f44"),
Rgba32.FromHex("#454445"),
Rgba32.FromHex("#423937"),
Rgba32.FromHex("#433635"),
Rgba32.FromHex("#252024"),
Rgba32.FromHex("#241f20"),
Rgba32.FromHex("#281f3f"),
Rgba32.FromHex("#1c1949"),
Rgba32.FromHex("#4f638d"),
Rgba32.FromHex("#383867"),
Rgba32.FromHex("#5c6b8f"),
Rgba32.FromHex("#657abb"),
Rgba32.FromHex("#6f88af"),
Rgba32.FromHex("#7994b5"),
Rgba32.FromHex("#6fb5a8"),
Rgba32.FromHex("#719ba2"),
Rgba32.FromHex("#8aa1a6"),
Rgba32.FromHex("#d0d5d3"),
Rgba32.FromHex("#8590ae"),
Rgba32.FromHex("#3a2f52"),
Rgba32.FromHex("#39334a"),
Rgba32.FromHex("#6c6d94"),
Rgba32.FromHex("#584c77"),
Rgba32.FromHex("#533552"),
Rgba32.FromHex("#463759"),
Rgba32.FromHex("#bfbac0"),
Rgba32.FromHex("#77747f"),
Rgba32.FromHex("#4a475c"),
Rgba32.FromHex("#b8bfaf"),
Rgba32.FromHex("#b2b599"),
Rgba32.FromHex("#979c84"),
Rgba32.FromHex("#5d6161"),
Rgba32.FromHex("#61ac86"),
Rgba32.FromHex("#a4b6a7"),
Rgba32.FromHex("#adba98"),
Rgba32.FromHex("#93b778"),
Rgba32.FromHex("#7d8c55"),
Rgba32.FromHex("#33431e"),
Rgba32.FromHex("#7c8635"),
Rgba32.FromHex("#8e9849"),
Rgba32.FromHex("#c2c190"),
Rgba32.FromHex("#67765b"),
Rgba32.FromHex("#ab924b"),
Rgba32.FromHex("#c8c76f"),
Rgba32.FromHex("#ccc050"),
Rgba32.FromHex("#ebdd99"),
Rgba32.FromHex("#ab9649"),
Rgba32.FromHex("#dbc364"),
Rgba32.FromHex("#e6d058"),
Rgba32.FromHex("#ead665"),
Rgba32.FromHex("#d09b2c"),
Rgba32.FromHex("#a36629"),
Rgba32.FromHex("#a77d35"),
Rgba32.FromHex("#f0d696"),
Rgba32.FromHex("#d7c485"),
Rgba32.FromHex("#f1d28c"),
Rgba32.FromHex("#efcc83"),
Rgba32.FromHex("#f3daa7"),
Rgba32.FromHex("#dfa837"),
Rgba32.FromHex("#ebbc71"),
Rgba32.FromHex("#d17c3f"),
Rgba32.FromHex("#92462f"),
Rgba32.FromHex("#be7249"),
Rgba32.FromHex("#bb603c"),
Rgba32.FromHex("#c76b4a"),
Rgba32.FromHex("#a75536"),
Rgba32.FromHex("#b63e36"),
Rgba32.FromHex("#b5493a"),
Rgba32.FromHex("#cd6d57"),
Rgba32.FromHex("#711518"),
Rgba32.FromHex("#e9c49d"),
Rgba32.FromHex("#eedac3"),
Rgba32.FromHex("#eecfbf"),
Rgba32.FromHex("#ce536b"),
Rgba32.FromHex("#b74a70"),
Rgba32.FromHex("#b7757c"),
Rgba32.FromHex("#612741"),
Rgba32.FromHex("#7a4848"),
Rgba32.FromHex("#3f3033"),
Rgba32.FromHex("#8d746f"),
Rgba32.FromHex("#4d3635"),
Rgba32.FromHex("#6e3b31"),
Rgba32.FromHex("#864735"),
Rgba32.FromHex("#553d3a"),
Rgba32.FromHex("#613936"),
Rgba32.FromHex("#7a4b3a"),
Rgba32.FromHex("#946943"),
Rgba32.FromHex("#c39e6d"),
Rgba32.FromHex("#513e32"),
Rgba32.FromHex("#8b7859"),
Rgba32.FromHex("#9b856b"),
Rgba32.FromHex("#766051"),
Rgba32.FromHex("#453b32")
};
}
}

721
src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.Definitions.cs

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

42
src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs

@ -230,7 +230,8 @@ namespace SixLabors.ImageSharp.PixelFormats
public static bool operator !=(Rgba32 left, Rgba32 right) => !left.Equals(right); public static bool operator !=(Rgba32 left, Rgba32 right) => !left.Equals(right);
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="Rgba32"/> struct. /// Creates a new instance of the <see cref="Rgba32"/> struct
/// from the given hexadecimal string.
/// </summary> /// </summary>
/// <param name="hex"> /// <param name="hex">
/// The hexadecimal representation of the combined color components arranged /// The hexadecimal representation of the combined color components arranged
@ -239,19 +240,50 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <returns> /// <returns>
/// The <see cref="Rgba32"/>. /// The <see cref="Rgba32"/>.
/// </returns> /// </returns>
public static Rgba32 FromHex(string hex) [MethodImpl(InliningOptions.ShortMethod)]
public static Rgba32 ParseHex(string hex)
{
Guard.NotNull(hex, nameof(hex));
if (!TryParseHex(hex, out Rgba32 rgba))
{
throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
}
return rgba;
}
/// <summary>
/// Attempts to creates a new instance of the <see cref="Rgba32"/> struct
/// from the given hexadecimal string.
/// </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>
/// <param name="result">When this method returns, contains the <see cref="Rgba32"/> equivalent of the hexadecimal input.</param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool TryParseHex(string hex, out Rgba32 result)
{ {
Guard.NotNullOrWhiteSpace(hex, nameof(hex)); result = default;
if (string.IsNullOrWhiteSpace(hex))
{
return false;
}
hex = ToRgbaHex(hex); hex = ToRgbaHex(hex);
if (hex is null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint packedValue)) if (hex is null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint packedValue))
{ {
throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex)); return false;
} }
packedValue = BinaryPrimitives.ReverseEndianness(packedValue); packedValue = BinaryPrimitives.ReverseEndianness(packedValue);
return Unsafe.As<uint, Rgba32>(ref packedValue); result = Unsafe.As<uint, Rgba32>(ref packedValue);
return true;
} }
/// <inheritdoc /> /// <inheritdoc />

2
src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs

@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <returns> /// <returns>
/// The <see cref="RgbaVector"/>. /// The <see cref="RgbaVector"/>.
/// </returns> /// </returns>
public static RgbaVector FromHex(string hex) => Color.FromHex(hex).ToPixel<RgbaVector>(); public static RgbaVector FromHex(string hex) => Color.ParseHex(hex).ToPixel<RgbaVector>();
/// <inheritdoc /> /// <inheritdoc />
public PixelOperations<RgbaVector> CreatePixelOperations() => new PixelOperations(); public PixelOperations<RgbaVector> CreatePixelOperations() => new PixelOperations();

4
tests/ImageSharp.Benchmarks/Codecs/GetSetPixel.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.Drawing; using System.Drawing;
@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
{ {
using (var image = new Image<Rgba32>(400, 400)) using (var image = new Image<Rgba32>(400, 400))
{ {
image[200, 200] = Rgba32.White; image[200, 200] = Color.White;
return image[200, 200]; return image[200, 200];
} }
} }

2
tests/ImageSharp.Benchmarks/Samplers/Diffuse.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Samplers
[Benchmark] [Benchmark]
public Size DoDiffuse() public Size DoDiffuse()
{ {
using (var image = new Image<Rgba32>(Configuration.Default, 800, 800, Rgba32.BlanchedAlmond)) using (var image = new Image<Rgba32>(Configuration.Default, 800, 800, Color.BlanchedAlmond))
{ {
image.Mutate(x => x.Diffuse()); image.Mutate(x => x.Diffuse());

2
tests/ImageSharp.Benchmarks/Samplers/GaussianBlur.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Samplers
[Benchmark] [Benchmark]
public void Blur() public void Blur()
{ {
using (var image = new Image<Rgba32>(Configuration.Default, 400, 400, Rgba32.White)) using (var image = new Image<Rgba32>(Configuration.Default, 400, 400, Color.White))
{ {
image.Mutate(c => c.GaussianBlur()); image.Mutate(c => c.GaussianBlur());
} }

2
tests/ImageSharp.Benchmarks/Samplers/Rotate.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Samplers
[Benchmark] [Benchmark]
public Size DoRotate() public Size DoRotate()
{ {
using (var image = new Image<Rgba32>(Configuration.Default, 400, 400, Rgba32.BlanchedAlmond)) using (var image = new Image<Rgba32>(Configuration.Default, 400, 400, Color.BlanchedAlmond))
{ {
image.Mutate(x => x.Rotate(37.5F)); image.Mutate(x => x.Rotate(37.5F));

2
tests/ImageSharp.Benchmarks/Samplers/Skew.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Samplers
[Benchmark] [Benchmark]
public Size DoSkew() public Size DoSkew()
{ {
using (var image = new Image<Rgba32>(Configuration.Default, 400, 400, Rgba32.BlanchedAlmond)) using (var image = new Image<Rgba32>(Configuration.Default, 400, 400, Color.BlanchedAlmond))
{ {
image.Mutate(x => x.Skew(20, 10)); image.Mutate(x => x.Skew(20, 10));

138
tests/ImageSharp.Tests/Color/ColorTests.cs

@ -3,9 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
@ -15,7 +13,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void WithAlpha() public void WithAlpha()
{ {
Color c1 = Color.FromRgba(111, 222, 55, 255); var c1 = Color.FromRgba(111, 222, 55, 255);
Color c2 = c1.WithAlpha(0.5f); Color c2 = c1.WithAlpha(0.5f);
var expected = new Rgba32(111, 222, 55, 128); var expected = new Rgba32(111, 222, 55, 128);
@ -56,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests
public void ToHex() public void ToHex()
{ {
string expected = "ABCD1234"; string expected = "ABCD1234";
Color color = Color.FromHex(expected); var color = Color.ParseHex(expected);
string actual = color.ToHex(); string actual = color.ToHex();
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
@ -66,14 +64,22 @@ namespace SixLabors.ImageSharp.Tests
public void WebSafePalette_IsCorrect() public void WebSafePalette_IsCorrect()
{ {
Rgba32[] actualPalette = Color.WebSafePalette.ToArray().Select(c => (Rgba32)c).ToArray(); Rgba32[] actualPalette = Color.WebSafePalette.ToArray().Select(c => (Rgba32)c).ToArray();
Assert.Equal(ReferencePalette.WebSafeColors, actualPalette);
for (int i = 0; i < ReferencePalette.WebSafeColors.Length; i++)
{
Assert.Equal((Rgba32)ReferencePalette.WebSafeColors[i], actualPalette[i]);
}
} }
[Fact] [Fact]
public void WernerPalette_IsCorrect() public void WernerPalette_IsCorrect()
{ {
Rgba32[] actualPalette = Color.WernerPalette.ToArray().Select(c => (Rgba32)c).ToArray(); Rgba32[] actualPalette = Color.WernerPalette.ToArray().Select(c => (Rgba32)c).ToArray();
Assert.Equal(ReferencePalette.WernerColors, actualPalette);
for (int i = 0; i < ReferencePalette.WernerColors.Length; i++)
{
Assert.Equal((Rgba32)ReferencePalette.WernerColors[i], actualPalette[i]);
}
} }
public class FromHex public class FromHex
@ -81,28 +87,134 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void ShortHex() public void ShortHex()
{ {
Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)Color.FromHex("#fff")); Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)Color.ParseHex("#fff"));
Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)Color.FromHex("fff")); Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)Color.ParseHex("fff"));
Assert.Equal(new Rgba32(0, 0, 0, 255), (Rgba32)Color.FromHex("000f")); Assert.Equal(new Rgba32(0, 0, 0, 255), (Rgba32)Color.ParseHex("000f"));
}
[Fact]
public void TryShortHex()
{
Assert.True(Color.TryParseHex("#fff", out Color actual));
Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)actual);
Assert.True(Color.TryParseHex("fff", out actual));
Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)actual);
Assert.True(Color.TryParseHex("000f", out actual));
Assert.Equal(new Rgba32(0, 0, 0, 255), (Rgba32)actual);
} }
[Fact] [Fact]
public void LeadingPoundIsOptional() public void LeadingPoundIsOptional()
{ {
Assert.Equal(new Rgb24(0, 128, 128), (Rgb24)Color.FromHex("#008080")); Assert.Equal(new Rgb24(0, 128, 128), (Rgb24)Color.ParseHex("#008080"));
Assert.Equal(new Rgb24(0, 128, 128), (Rgb24)Color.FromHex("008080")); Assert.Equal(new Rgb24(0, 128, 128), (Rgb24)Color.ParseHex("008080"));
} }
[Fact] [Fact]
public void ThrowsOnEmpty() public void ThrowsOnEmpty()
{ {
Assert.Throws<ArgumentException>(() => Color.FromHex(string.Empty)); Assert.Throws<ArgumentException>(() => Color.ParseHex(string.Empty));
}
[Fact]
public void ThrowsOnInvalid()
{
Assert.Throws<ArgumentException>(() => Color.ParseHex("!"));
} }
[Fact] [Fact]
public void ThrowsOnNull() public void ThrowsOnNull()
{ {
Assert.Throws<ArgumentNullException>(() => Color.FromHex(null)); Assert.Throws<ArgumentNullException>(() => Color.ParseHex(null));
}
[Fact]
public void FalseOnEmpty()
{
Assert.False(Color.TryParseHex(string.Empty, out Color _));
}
[Fact]
public void FalseOnInvalid()
{
Assert.False(Color.TryParseHex("!", out Color _));
}
[Fact]
public void FalseOnNull()
{
Assert.False(Color.TryParseHex(null, out Color _));
}
}
public class FromString
{
[Fact]
public void ColorNames()
{
foreach (string name in ReferencePalette.ColorNames.Keys)
{
Rgba32 expected = ReferencePalette.ColorNames[name];
Assert.Equal(expected, (Rgba32)Color.Parse(name));
Assert.Equal(expected, (Rgba32)Color.Parse(name.ToLowerInvariant()));
Assert.Equal(expected, (Rgba32)Color.Parse(expected.ToHex()));
}
}
[Fact]
public void TryColorNames()
{
foreach (string name in ReferencePalette.ColorNames.Keys)
{
Rgba32 expected = ReferencePalette.ColorNames[name];
Assert.True(Color.TryParse(name, out Color actual));
Assert.Equal(expected, (Rgba32)actual);
Assert.True(Color.TryParse(name.ToLowerInvariant(), out actual));
Assert.Equal(expected, (Rgba32)actual);
Assert.True(Color.TryParse(expected.ToHex(), out actual));
Assert.Equal(expected, (Rgba32)actual);
}
}
[Fact]
public void ThrowsOnEmpty()
{
Assert.Throws<ArgumentException>(() => Color.Parse(string.Empty));
}
[Fact]
public void ThrowsOnInvalid()
{
Assert.Throws<ArgumentException>(() => Color.Parse("!"));
}
[Fact]
public void ThrowsOnNull()
{
Assert.Throws<ArgumentNullException>(() => Color.Parse(null));
}
[Fact]
public void FalseOnEmpty()
{
Assert.False(Color.TryParse(string.Empty, out Color _));
}
[Fact]
public void FalseOnInvalid()
{
Assert.False(Color.TryParse("!", out Color _));
}
[Fact]
public void FalseOnNull()
{
Assert.False(Color.TryParse(null, out Color _));
} }
} }
} }

665
tests/ImageSharp.Tests/Color/ReferencePalette.cs

@ -1,7 +1,8 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using System;
using System.Collections.Generic;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
@ -10,268 +11,422 @@ namespace SixLabors.ImageSharp.Tests
/// <summary> /// <summary>
/// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4. /// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4.
/// </summary> /// </summary>
public static readonly Rgba32[] WebSafeColors = public static readonly Color[] WebSafeColors =
{ {
Rgba32.AliceBlue, Color.AliceBlue,
Rgba32.AntiqueWhite, Color.AntiqueWhite,
Rgba32.Aqua, Color.Aqua,
Rgba32.Aquamarine, Color.Aquamarine,
Rgba32.Azure, Color.Azure,
Rgba32.Beige, Color.Beige,
Rgba32.Bisque, Color.Bisque,
Rgba32.Black, Color.Black,
Rgba32.BlanchedAlmond, Color.BlanchedAlmond,
Rgba32.Blue, Color.Blue,
Rgba32.BlueViolet, Color.BlueViolet,
Rgba32.Brown, Color.Brown,
Rgba32.BurlyWood, Color.BurlyWood,
Rgba32.CadetBlue, Color.CadetBlue,
Rgba32.Chartreuse, Color.Chartreuse,
Rgba32.Chocolate, Color.Chocolate,
Rgba32.Coral, Color.Coral,
Rgba32.CornflowerBlue, Color.CornflowerBlue,
Rgba32.Cornsilk, Color.Cornsilk,
Rgba32.Crimson, Color.Crimson,
Rgba32.Cyan, Color.Cyan,
Rgba32.DarkBlue, Color.DarkBlue,
Rgba32.DarkCyan, Color.DarkCyan,
Rgba32.DarkGoldenrod, Color.DarkGoldenrod,
Rgba32.DarkGray, Color.DarkGray,
Rgba32.DarkGreen, Color.DarkGreen,
Rgba32.DarkKhaki, Color.DarkKhaki,
Rgba32.DarkMagenta, Color.DarkMagenta,
Rgba32.DarkOliveGreen, Color.DarkOliveGreen,
Rgba32.DarkOrange, Color.DarkOrange,
Rgba32.DarkOrchid, Color.DarkOrchid,
Rgba32.DarkRed, Color.DarkRed,
Rgba32.DarkSalmon, Color.DarkSalmon,
Rgba32.DarkSeaGreen, Color.DarkSeaGreen,
Rgba32.DarkSlateBlue, Color.DarkSlateBlue,
Rgba32.DarkSlateGray, Color.DarkSlateGray,
Rgba32.DarkTurquoise, Color.DarkTurquoise,
Rgba32.DarkViolet, Color.DarkViolet,
Rgba32.DeepPink, Color.DeepPink,
Rgba32.DeepSkyBlue, Color.DeepSkyBlue,
Rgba32.DimGray, Color.DimGray,
Rgba32.DodgerBlue, Color.DodgerBlue,
Rgba32.Firebrick, Color.Firebrick,
Rgba32.FloralWhite, Color.FloralWhite,
Rgba32.ForestGreen, Color.ForestGreen,
Rgba32.Fuchsia, Color.Fuchsia,
Rgba32.Gainsboro, Color.Gainsboro,
Rgba32.GhostWhite, Color.GhostWhite,
Rgba32.Gold, Color.Gold,
Rgba32.Goldenrod, Color.Goldenrod,
Rgba32.Gray, Color.Gray,
Rgba32.Green, Color.Green,
Rgba32.GreenYellow, Color.GreenYellow,
Rgba32.Honeydew, Color.Honeydew,
Rgba32.HotPink, Color.HotPink,
Rgba32.IndianRed, Color.IndianRed,
Rgba32.Indigo, Color.Indigo,
Rgba32.Ivory, Color.Ivory,
Rgba32.Khaki, Color.Khaki,
Rgba32.Lavender, Color.Lavender,
Rgba32.LavenderBlush, Color.LavenderBlush,
Rgba32.LawnGreen, Color.LawnGreen,
Rgba32.LemonChiffon, Color.LemonChiffon,
Rgba32.LightBlue, Color.LightBlue,
Rgba32.LightCoral, Color.LightCoral,
Rgba32.LightCyan, Color.LightCyan,
Rgba32.LightGoldenrodYellow, Color.LightGoldenrodYellow,
Rgba32.LightGray, Color.LightGray,
Rgba32.LightGreen, Color.LightGreen,
Rgba32.LightPink, Color.LightPink,
Rgba32.LightSalmon, Color.LightSalmon,
Rgba32.LightSeaGreen, Color.LightSeaGreen,
Rgba32.LightSkyBlue, Color.LightSkyBlue,
Rgba32.LightSlateGray, Color.LightSlateGray,
Rgba32.LightSteelBlue, Color.LightSteelBlue,
Rgba32.LightYellow, Color.LightYellow,
Rgba32.Lime, Color.Lime,
Rgba32.LimeGreen, Color.LimeGreen,
Rgba32.Linen, Color.Linen,
Rgba32.Magenta, Color.Magenta,
Rgba32.Maroon, Color.Maroon,
Rgba32.MediumAquamarine, Color.MediumAquamarine,
Rgba32.MediumBlue, Color.MediumBlue,
Rgba32.MediumOrchid, Color.MediumOrchid,
Rgba32.MediumPurple, Color.MediumPurple,
Rgba32.MediumSeaGreen, Color.MediumSeaGreen,
Rgba32.MediumSlateBlue, Color.MediumSlateBlue,
Rgba32.MediumSpringGreen, Color.MediumSpringGreen,
Rgba32.MediumTurquoise, Color.MediumTurquoise,
Rgba32.MediumVioletRed, Color.MediumVioletRed,
Rgba32.MidnightBlue, Color.MidnightBlue,
Rgba32.MintCream, Color.MintCream,
Rgba32.MistyRose, Color.MistyRose,
Rgba32.Moccasin, Color.Moccasin,
Rgba32.NavajoWhite, Color.NavajoWhite,
Rgba32.Navy, Color.Navy,
Rgba32.OldLace, Color.OldLace,
Rgba32.Olive, Color.Olive,
Rgba32.OliveDrab, Color.OliveDrab,
Rgba32.Orange, Color.Orange,
Rgba32.OrangeRed, Color.OrangeRed,
Rgba32.Orchid, Color.Orchid,
Rgba32.PaleGoldenrod, Color.PaleGoldenrod,
Rgba32.PaleGreen, Color.PaleGreen,
Rgba32.PaleTurquoise, Color.PaleTurquoise,
Rgba32.PaleVioletRed, Color.PaleVioletRed,
Rgba32.PapayaWhip, Color.PapayaWhip,
Rgba32.PeachPuff, Color.PeachPuff,
Rgba32.Peru, Color.Peru,
Rgba32.Pink, Color.Pink,
Rgba32.Plum, Color.Plum,
Rgba32.PowderBlue, Color.PowderBlue,
Rgba32.Purple, Color.Purple,
Rgba32.RebeccaPurple, Color.RebeccaPurple,
Rgba32.Red, Color.Red,
Rgba32.RosyBrown, Color.RosyBrown,
Rgba32.RoyalBlue, Color.RoyalBlue,
Rgba32.SaddleBrown, Color.SaddleBrown,
Rgba32.Salmon, Color.Salmon,
Rgba32.SandyBrown, Color.SandyBrown,
Rgba32.SeaGreen, Color.SeaGreen,
Rgba32.SeaShell, Color.SeaShell,
Rgba32.Sienna, Color.Sienna,
Rgba32.Silver, Color.Silver,
Rgba32.SkyBlue, Color.SkyBlue,
Rgba32.SlateBlue, Color.SlateBlue,
Rgba32.SlateGray, Color.SlateGray,
Rgba32.Snow, Color.Snow,
Rgba32.SpringGreen, Color.SpringGreen,
Rgba32.SteelBlue, Color.SteelBlue,
Rgba32.Tan, Color.Tan,
Rgba32.Teal, Color.Teal,
Rgba32.Thistle, Color.Thistle,
Rgba32.Tomato, Color.Tomato,
Rgba32.Transparent, Color.Transparent,
Rgba32.Turquoise, Color.Turquoise,
Rgba32.Violet, Color.Violet,
Rgba32.Wheat, Color.Wheat,
Rgba32.White, Color.White,
Rgba32.WhiteSmoke, Color.WhiteSmoke,
Rgba32.Yellow, Color.Yellow,
Rgba32.YellowGreen Color.YellowGreen
}; };
/// <summary> /// <summary>
/// Gets a collection of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821. /// Gets a collection of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821.
/// The hex codes were collected and defined by Nicholas Rougeux <see href="https://www.c82.net/werner"/> /// The hex codes were collected and defined by Nicholas Rougeux <see href="https://www.c82.net/werner"/>
/// </summary> /// </summary>
public static readonly Rgba32[] WernerColors = public static readonly Color[] WernerColors =
{ {
Rgba32.FromHex("#f1e9cd"), Color.ParseHex("#f1e9cd"),
Rgba32.FromHex("#f2e7cf"), Color.ParseHex("#f2e7cf"),
Rgba32.FromHex("#ece6d0"), Color.ParseHex("#ece6d0"),
Rgba32.FromHex("#f2eacc"), Color.ParseHex("#f2eacc"),
Rgba32.FromHex("#f3e9ca"), Color.ParseHex("#f3e9ca"),
Rgba32.FromHex("#f2ebcd"), Color.ParseHex("#f2ebcd"),
Rgba32.FromHex("#e6e1c9"), Color.ParseHex("#e6e1c9"),
Rgba32.FromHex("#e2ddc6"), Color.ParseHex("#e2ddc6"),
Rgba32.FromHex("#cbc8b7"), Color.ParseHex("#cbc8b7"),
Rgba32.FromHex("#bfbbb0"), Color.ParseHex("#bfbbb0"),
Rgba32.FromHex("#bebeb3"), Color.ParseHex("#bebeb3"),
Rgba32.FromHex("#b7b5ac"), Color.ParseHex("#b7b5ac"),
Rgba32.FromHex("#bab191"), Color.ParseHex("#bab191"),
Rgba32.FromHex("#9c9d9a"), Color.ParseHex("#9c9d9a"),
Rgba32.FromHex("#8a8d84"), Color.ParseHex("#8a8d84"),
Rgba32.FromHex("#5b5c61"), Color.ParseHex("#5b5c61"),
Rgba32.FromHex("#555152"), Color.ParseHex("#555152"),
Rgba32.FromHex("#413f44"), Color.ParseHex("#413f44"),
Rgba32.FromHex("#454445"), Color.ParseHex("#454445"),
Rgba32.FromHex("#423937"), Color.ParseHex("#423937"),
Rgba32.FromHex("#433635"), Color.ParseHex("#433635"),
Rgba32.FromHex("#252024"), Color.ParseHex("#252024"),
Rgba32.FromHex("#241f20"), Color.ParseHex("#241f20"),
Rgba32.FromHex("#281f3f"), Color.ParseHex("#281f3f"),
Rgba32.FromHex("#1c1949"), Color.ParseHex("#1c1949"),
Rgba32.FromHex("#4f638d"), Color.ParseHex("#4f638d"),
Rgba32.FromHex("#383867"), Color.ParseHex("#383867"),
Rgba32.FromHex("#5c6b8f"), Color.ParseHex("#5c6b8f"),
Rgba32.FromHex("#657abb"), Color.ParseHex("#657abb"),
Rgba32.FromHex("#6f88af"), Color.ParseHex("#6f88af"),
Rgba32.FromHex("#7994b5"), Color.ParseHex("#7994b5"),
Rgba32.FromHex("#6fb5a8"), Color.ParseHex("#6fb5a8"),
Rgba32.FromHex("#719ba2"), Color.ParseHex("#719ba2"),
Rgba32.FromHex("#8aa1a6"), Color.ParseHex("#8aa1a6"),
Rgba32.FromHex("#d0d5d3"), Color.ParseHex("#d0d5d3"),
Rgba32.FromHex("#8590ae"), Color.ParseHex("#8590ae"),
Rgba32.FromHex("#3a2f52"), Color.ParseHex("#3a2f52"),
Rgba32.FromHex("#39334a"), Color.ParseHex("#39334a"),
Rgba32.FromHex("#6c6d94"), Color.ParseHex("#6c6d94"),
Rgba32.FromHex("#584c77"), Color.ParseHex("#584c77"),
Rgba32.FromHex("#533552"), Color.ParseHex("#533552"),
Rgba32.FromHex("#463759"), Color.ParseHex("#463759"),
Rgba32.FromHex("#bfbac0"), Color.ParseHex("#bfbac0"),
Rgba32.FromHex("#77747f"), Color.ParseHex("#77747f"),
Rgba32.FromHex("#4a475c"), Color.ParseHex("#4a475c"),
Rgba32.FromHex("#b8bfaf"), Color.ParseHex("#b8bfaf"),
Rgba32.FromHex("#b2b599"), Color.ParseHex("#b2b599"),
Rgba32.FromHex("#979c84"), Color.ParseHex("#979c84"),
Rgba32.FromHex("#5d6161"), Color.ParseHex("#5d6161"),
Rgba32.FromHex("#61ac86"), Color.ParseHex("#61ac86"),
Rgba32.FromHex("#a4b6a7"), Color.ParseHex("#a4b6a7"),
Rgba32.FromHex("#adba98"), Color.ParseHex("#adba98"),
Rgba32.FromHex("#93b778"), Color.ParseHex("#93b778"),
Rgba32.FromHex("#7d8c55"), Color.ParseHex("#7d8c55"),
Rgba32.FromHex("#33431e"), Color.ParseHex("#33431e"),
Rgba32.FromHex("#7c8635"), Color.ParseHex("#7c8635"),
Rgba32.FromHex("#8e9849"), Color.ParseHex("#8e9849"),
Rgba32.FromHex("#c2c190"), Color.ParseHex("#c2c190"),
Rgba32.FromHex("#67765b"), Color.ParseHex("#67765b"),
Rgba32.FromHex("#ab924b"), Color.ParseHex("#ab924b"),
Rgba32.FromHex("#c8c76f"), Color.ParseHex("#c8c76f"),
Rgba32.FromHex("#ccc050"), Color.ParseHex("#ccc050"),
Rgba32.FromHex("#ebdd99"), Color.ParseHex("#ebdd99"),
Rgba32.FromHex("#ab9649"), Color.ParseHex("#ab9649"),
Rgba32.FromHex("#dbc364"), Color.ParseHex("#dbc364"),
Rgba32.FromHex("#e6d058"), Color.ParseHex("#e6d058"),
Rgba32.FromHex("#ead665"), Color.ParseHex("#ead665"),
Rgba32.FromHex("#d09b2c"), Color.ParseHex("#d09b2c"),
Rgba32.FromHex("#a36629"), Color.ParseHex("#a36629"),
Rgba32.FromHex("#a77d35"), Color.ParseHex("#a77d35"),
Rgba32.FromHex("#f0d696"), Color.ParseHex("#f0d696"),
Rgba32.FromHex("#d7c485"), Color.ParseHex("#d7c485"),
Rgba32.FromHex("#f1d28c"), Color.ParseHex("#f1d28c"),
Rgba32.FromHex("#efcc83"), Color.ParseHex("#efcc83"),
Rgba32.FromHex("#f3daa7"), Color.ParseHex("#f3daa7"),
Rgba32.FromHex("#dfa837"), Color.ParseHex("#dfa837"),
Rgba32.FromHex("#ebbc71"), Color.ParseHex("#ebbc71"),
Rgba32.FromHex("#d17c3f"), Color.ParseHex("#d17c3f"),
Rgba32.FromHex("#92462f"), Color.ParseHex("#92462f"),
Rgba32.FromHex("#be7249"), Color.ParseHex("#be7249"),
Rgba32.FromHex("#bb603c"), Color.ParseHex("#bb603c"),
Rgba32.FromHex("#c76b4a"), Color.ParseHex("#c76b4a"),
Rgba32.FromHex("#a75536"), Color.ParseHex("#a75536"),
Rgba32.FromHex("#b63e36"), Color.ParseHex("#b63e36"),
Rgba32.FromHex("#b5493a"), Color.ParseHex("#b5493a"),
Rgba32.FromHex("#cd6d57"), Color.ParseHex("#cd6d57"),
Rgba32.FromHex("#711518"), Color.ParseHex("#711518"),
Rgba32.FromHex("#e9c49d"), Color.ParseHex("#e9c49d"),
Rgba32.FromHex("#eedac3"), Color.ParseHex("#eedac3"),
Rgba32.FromHex("#eecfbf"), Color.ParseHex("#eecfbf"),
Rgba32.FromHex("#ce536b"), Color.ParseHex("#ce536b"),
Rgba32.FromHex("#b74a70"), Color.ParseHex("#b74a70"),
Rgba32.FromHex("#b7757c"), Color.ParseHex("#b7757c"),
Rgba32.FromHex("#612741"), Color.ParseHex("#612741"),
Rgba32.FromHex("#7a4848"), Color.ParseHex("#7a4848"),
Rgba32.FromHex("#3f3033"), Color.ParseHex("#3f3033"),
Rgba32.FromHex("#8d746f"), Color.ParseHex("#8d746f"),
Rgba32.FromHex("#4d3635"), Color.ParseHex("#4d3635"),
Rgba32.FromHex("#6e3b31"), Color.ParseHex("#6e3b31"),
Rgba32.FromHex("#864735"), Color.ParseHex("#864735"),
Rgba32.FromHex("#553d3a"), Color.ParseHex("#553d3a"),
Rgba32.FromHex("#613936"), Color.ParseHex("#613936"),
Rgba32.FromHex("#7a4b3a"), Color.ParseHex("#7a4b3a"),
Rgba32.FromHex("#946943"), Color.ParseHex("#946943"),
Rgba32.FromHex("#c39e6d"), Color.ParseHex("#c39e6d"),
Rgba32.FromHex("#513e32"), Color.ParseHex("#513e32"),
Rgba32.FromHex("#8b7859"), Color.ParseHex("#8b7859"),
Rgba32.FromHex("#9b856b"), Color.ParseHex("#9b856b"),
Rgba32.FromHex("#766051"), Color.ParseHex("#766051"),
Rgba32.FromHex("#453b32") Color.ParseHex("#453b32")
}; };
public static readonly Dictionary<string, Color> ColorNames =
new Dictionary<string, Color>(StringComparer.OrdinalIgnoreCase)
{
{ nameof(Color.AliceBlue), Color.AliceBlue },
{ nameof(Color.AntiqueWhite), Color.AntiqueWhite },
{ nameof(Color.Aqua), Color.Aqua },
{ nameof(Color.Aquamarine), Color.Aquamarine },
{ nameof(Color.Azure), Color.Azure },
{ nameof(Color.Beige), Color.Beige },
{ nameof(Color.Bisque), Color.Bisque },
{ nameof(Color.Black), Color.Black },
{ nameof(Color.BlanchedAlmond), Color.BlanchedAlmond },
{ nameof(Color.Blue), Color.Blue },
{ nameof(Color.BlueViolet), Color.BlueViolet },
{ nameof(Color.Brown), Color.Brown },
{ nameof(Color.BurlyWood), Color.BurlyWood },
{ nameof(Color.CadetBlue), Color.CadetBlue },
{ nameof(Color.Chartreuse), Color.Chartreuse },
{ nameof(Color.Chocolate), Color.Chocolate },
{ nameof(Color.Coral), Color.Coral },
{ nameof(Color.CornflowerBlue), Color.CornflowerBlue },
{ nameof(Color.Cornsilk), Color.Cornsilk },
{ nameof(Color.Crimson), Color.Crimson },
{ nameof(Color.Cyan), Color.Cyan },
{ nameof(Color.DarkBlue), Color.DarkBlue },
{ nameof(Color.DarkCyan), Color.DarkCyan },
{ nameof(Color.DarkGoldenrod), Color.DarkGoldenrod },
{ nameof(Color.DarkGray), Color.DarkGray },
{ nameof(Color.DarkGreen), Color.DarkGreen },
{ nameof(Color.DarkGrey), Color.DarkGrey },
{ nameof(Color.DarkKhaki), Color.DarkKhaki },
{ nameof(Color.DarkMagenta), Color.DarkMagenta },
{ nameof(Color.DarkOliveGreen), Color.DarkOliveGreen },
{ nameof(Color.DarkOrange), Color.DarkOrange },
{ nameof(Color.DarkOrchid), Color.DarkOrchid },
{ nameof(Color.DarkRed), Color.DarkRed },
{ nameof(Color.DarkSalmon), Color.DarkSalmon },
{ nameof(Color.DarkSeaGreen), Color.DarkSeaGreen },
{ nameof(Color.DarkSlateBlue), Color.DarkSlateBlue },
{ nameof(Color.DarkSlateGray), Color.DarkSlateGray },
{ nameof(Color.DarkSlateGrey), Color.DarkSlateGrey },
{ nameof(Color.DarkTurquoise), Color.DarkTurquoise },
{ nameof(Color.DarkViolet), Color.DarkViolet },
{ nameof(Color.DeepPink), Color.DeepPink },
{ nameof(Color.DeepSkyBlue), Color.DeepSkyBlue },
{ nameof(Color.DimGray), Color.DimGray },
{ nameof(Color.DimGrey), Color.DimGrey },
{ nameof(Color.DodgerBlue), Color.DodgerBlue },
{ nameof(Color.Firebrick), Color.Firebrick },
{ nameof(Color.FloralWhite), Color.FloralWhite },
{ nameof(Color.ForestGreen), Color.ForestGreen },
{ nameof(Color.Fuchsia), Color.Fuchsia },
{ nameof(Color.Gainsboro), Color.Gainsboro },
{ nameof(Color.GhostWhite), Color.GhostWhite },
{ nameof(Color.Gold), Color.Gold },
{ nameof(Color.Goldenrod), Color.Goldenrod },
{ nameof(Color.Gray), Color.Gray },
{ nameof(Color.Green), Color.Green },
{ nameof(Color.GreenYellow), Color.GreenYellow },
{ nameof(Color.Grey), Color.Grey },
{ nameof(Color.Honeydew), Color.Honeydew },
{ nameof(Color.HotPink), Color.HotPink },
{ nameof(Color.IndianRed), Color.IndianRed },
{ nameof(Color.Indigo), Color.Indigo },
{ nameof(Color.Ivory), Color.Ivory },
{ nameof(Color.Khaki), Color.Khaki },
{ nameof(Color.Lavender), Color.Lavender },
{ nameof(Color.LavenderBlush), Color.LavenderBlush },
{ nameof(Color.LawnGreen), Color.LawnGreen },
{ nameof(Color.LemonChiffon), Color.LemonChiffon },
{ nameof(Color.LightBlue), Color.LightBlue },
{ nameof(Color.LightCoral), Color.LightCoral },
{ nameof(Color.LightCyan), Color.LightCyan },
{ nameof(Color.LightGoldenrodYellow), Color.LightGoldenrodYellow },
{ nameof(Color.LightGray), Color.LightGray },
{ nameof(Color.LightGreen), Color.LightGreen },
{ nameof(Color.LightGrey), Color.LightGrey },
{ nameof(Color.LightPink), Color.LightPink },
{ nameof(Color.LightSalmon), Color.LightSalmon },
{ nameof(Color.LightSeaGreen), Color.LightSeaGreen },
{ nameof(Color.LightSkyBlue), Color.LightSkyBlue },
{ nameof(Color.LightSlateGray), Color.LightSlateGray },
{ nameof(Color.LightSlateGrey), Color.LightSlateGrey },
{ nameof(Color.LightSteelBlue), Color.LightSteelBlue },
{ nameof(Color.LightYellow), Color.LightYellow },
{ nameof(Color.Lime), Color.Lime },
{ nameof(Color.LimeGreen), Color.LimeGreen },
{ nameof(Color.Linen), Color.Linen },
{ nameof(Color.Magenta), Color.Magenta },
{ nameof(Color.Maroon), Color.Maroon },
{ nameof(Color.MediumAquamarine), Color.MediumAquamarine },
{ nameof(Color.MediumBlue), Color.MediumBlue },
{ nameof(Color.MediumOrchid), Color.MediumOrchid },
{ nameof(Color.MediumPurple), Color.MediumPurple },
{ nameof(Color.MediumSeaGreen), Color.MediumSeaGreen },
{ nameof(Color.MediumSlateBlue), Color.MediumSlateBlue },
{ nameof(Color.MediumSpringGreen), Color.MediumSpringGreen },
{ nameof(Color.MediumTurquoise), Color.MediumTurquoise },
{ nameof(Color.MediumVioletRed), Color.MediumVioletRed },
{ nameof(Color.MidnightBlue), Color.MidnightBlue },
{ nameof(Color.MintCream), Color.MintCream },
{ nameof(Color.MistyRose), Color.MistyRose },
{ nameof(Color.Moccasin), Color.Moccasin },
{ nameof(Color.NavajoWhite), Color.NavajoWhite },
{ nameof(Color.Navy), Color.Navy },
{ nameof(Color.OldLace), Color.OldLace },
{ nameof(Color.Olive), Color.Olive },
{ nameof(Color.OliveDrab), Color.OliveDrab },
{ nameof(Color.Orange), Color.Orange },
{ nameof(Color.OrangeRed), Color.OrangeRed },
{ nameof(Color.Orchid), Color.Orchid },
{ nameof(Color.PaleGoldenrod), Color.PaleGoldenrod },
{ nameof(Color.PaleGreen), Color.PaleGreen },
{ nameof(Color.PaleTurquoise), Color.PaleTurquoise },
{ nameof(Color.PaleVioletRed), Color.PaleVioletRed },
{ nameof(Color.PapayaWhip), Color.PapayaWhip },
{ nameof(Color.PeachPuff), Color.PeachPuff },
{ nameof(Color.Peru), Color.Peru },
{ nameof(Color.Pink), Color.Pink },
{ nameof(Color.Plum), Color.Plum },
{ nameof(Color.PowderBlue), Color.PowderBlue },
{ nameof(Color.Purple), Color.Purple },
{ nameof(Color.RebeccaPurple), Color.RebeccaPurple },
{ nameof(Color.Red), Color.Red },
{ nameof(Color.RosyBrown), Color.RosyBrown },
{ nameof(Color.RoyalBlue), Color.RoyalBlue },
{ nameof(Color.SaddleBrown), Color.SaddleBrown },
{ nameof(Color.Salmon), Color.Salmon },
{ nameof(Color.SandyBrown), Color.SandyBrown },
{ nameof(Color.SeaGreen), Color.SeaGreen },
{ nameof(Color.SeaShell), Color.SeaShell },
{ nameof(Color.Sienna), Color.Sienna },
{ nameof(Color.Silver), Color.Silver },
{ nameof(Color.SkyBlue), Color.SkyBlue },
{ nameof(Color.SlateBlue), Color.SlateBlue },
{ nameof(Color.SlateGray), Color.SlateGray },
{ nameof(Color.SlateGrey), Color.SlateGrey },
{ nameof(Color.Snow), Color.Snow },
{ nameof(Color.SpringGreen), Color.SpringGreen },
{ nameof(Color.SteelBlue), Color.SteelBlue },
{ nameof(Color.Tan), Color.Tan },
{ nameof(Color.Teal), Color.Teal },
{ nameof(Color.Thistle), Color.Thistle },
{ nameof(Color.Tomato), Color.Tomato },
{ nameof(Color.Transparent), Color.Transparent },
{ nameof(Color.Turquoise), Color.Turquoise },
{ nameof(Color.Violet), Color.Violet },
{ nameof(Color.Wheat), Color.Wheat },
{ nameof(Color.White), Color.White },
{ nameof(Color.WhiteSmoke), Color.WhiteSmoke },
{ nameof(Color.Yellow), Color.Yellow },
{ nameof(Color.YellowGreen), Color.YellowGreen }
};
} }
} }

4
tests/ImageSharp.Tests/Drawing/DrawImageTests.cs

@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
using (Image<Rgba32> background = provider.GetImage()) using (Image<Rgba32> background = provider.GetImage())
using (var overlay = new Image<Rgba32>(50, 50)) using (var overlay = new Image<Rgba32>(50, 50))
{ {
overlay.GetPixelSpan().Fill(Rgba32.Black); overlay.GetPixelSpan().Fill(Color.Black);
background.Mutate(c => c.DrawImage(overlay, new Point(x, y), PixelColorBlendingMode.Normal, 1F)); background.Mutate(c => c.DrawImage(overlay, new Point(x, y), PixelColorBlendingMode.Normal, 1F));
@ -184,7 +184,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
public void NonOverlappingImageThrows(TestImageProvider<Rgba32> provider, int x, int y) public void NonOverlappingImageThrows(TestImageProvider<Rgba32> provider, int x, int y)
{ {
using (Image<Rgba32> background = provider.GetImage()) using (Image<Rgba32> background = provider.GetImage())
using (var overlay = new Image<Rgba32>(Configuration.Default, 10, 10, Rgba32.Black)) using (var overlay = new Image<Rgba32>(Configuration.Default, 10, 10, Color.Black))
{ {
ImageProcessingException ex = Assert.Throws<ImageProcessingException>(Test); ImageProcessingException ex = Assert.Throws<ImageProcessingException>(Test);

4
tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs

@ -233,10 +233,10 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void CreateFrame_CustomFillColor() public void CreateFrame_CustomFillColor()
{ {
this.Image.Frames.CreateFrame(Rgba32.HotPink); this.Image.Frames.CreateFrame(Color.HotPink);
Assert.Equal(2, this.Image.Frames.Count); Assert.Equal(2, this.Image.Frames.Count);
this.Image.Frames[1].ComparePixelBufferTo(Rgba32.HotPink); this.Image.Frames[1].ComparePixelBufferTo(Color.HotPink);
} }
[Fact] [Fact]

8
tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs

@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests
} }
Rgba32[] expectedAllBlue = Rgba32[] expectedAllBlue =
Enumerable.Repeat(Rgba32.Blue, this.Image.Width * this.Image.Height).ToArray(); Enumerable.Repeat((Rgba32)Color.Blue, this.Image.Width * this.Image.Height).ToArray();
Assert.Equal(2, this.Collection.Count); Assert.Equal(2, this.Collection.Count);
var actualFrame = (ImageFrame<Rgba32>)this.Collection[1]; var actualFrame = (ImageFrame<Rgba32>)this.Collection[1];
@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Tests
} }
Rgba32[] expectedAllBlue = Rgba32[] expectedAllBlue =
Enumerable.Repeat(Rgba32.Blue, this.Image.Width * this.Image.Height).ToArray(); Enumerable.Repeat((Rgba32)Color.Blue, this.Image.Width * this.Image.Height).ToArray();
Assert.Equal(2, this.Collection.Count); Assert.Equal(2, this.Collection.Count);
var actualFrame = (ImageFrame<Rgba32>)this.Collection[0]; var actualFrame = (ImageFrame<Rgba32>)this.Collection[0];
@ -201,13 +201,13 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void CreateFrame_CustomFillColor() public void CreateFrame_CustomFillColor()
{ {
this.Image.Frames.CreateFrame(Rgba32.HotPink); this.Image.Frames.CreateFrame(Color.HotPink);
Assert.Equal(2, this.Image.Frames.Count); Assert.Equal(2, this.Image.Frames.Count);
var frame = (ImageFrame<Rgba32>)this.Image.Frames[1]; var frame = (ImageFrame<Rgba32>)this.Image.Frames[1];
frame.ComparePixelBufferTo(Rgba32.HotPink); frame.ComparePixelBufferTo(Color.HotPink);
} }
[Fact] [Fact]

22
tests/ImageSharp.Tests/Image/ImageTests.LoadPixelData.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
@ -16,18 +16,18 @@ namespace SixLabors.ImageSharp.Tests
[InlineData(true)] [InlineData(true)]
public void FromPixels(bool useSpan) public void FromPixels(bool useSpan)
{ {
Rgba32[] data = { Rgba32.Black, Rgba32.White, Rgba32.White, Rgba32.Black, }; Rgba32[] data = { Color.Black, Color.White, Color.White, Color.Black, };
using (Image<Rgba32> img = useSpan using (Image<Rgba32> img = useSpan
? Image.LoadPixelData<Rgba32>(data.AsSpan(), 2, 2) ? Image.LoadPixelData<Rgba32>(data.AsSpan(), 2, 2)
: Image.LoadPixelData<Rgba32>(data, 2, 2)) : Image.LoadPixelData<Rgba32>(data, 2, 2))
{ {
Assert.NotNull(img); Assert.NotNull(img);
Assert.Equal(Rgba32.Black, img[0, 0]); Assert.Equal(Color.Black, (Color)img[0, 0]);
Assert.Equal(Rgba32.White, img[0, 1]); Assert.Equal(Color.White, (Color)img[0, 1]);
Assert.Equal(Rgba32.White, img[1, 0]); Assert.Equal(Color.White, (Color)img[1, 0]);
Assert.Equal(Rgba32.Black, img[1, 1]); Assert.Equal(Color.Black, (Color)img[1, 1]);
} }
} }
@ -48,13 +48,13 @@ namespace SixLabors.ImageSharp.Tests
: Image.LoadPixelData<Rgba32>(data, 2, 2)) : Image.LoadPixelData<Rgba32>(data, 2, 2))
{ {
Assert.NotNull(img); Assert.NotNull(img);
Assert.Equal(Rgba32.Black, img[0, 0]); Assert.Equal(Color.Black, (Color)img[0, 0]);
Assert.Equal(Rgba32.White, img[0, 1]); Assert.Equal(Color.White, (Color)img[0, 1]);
Assert.Equal(Rgba32.White, img[1, 0]); Assert.Equal(Color.White, (Color)img[1, 0]);
Assert.Equal(Rgba32.Black, img[1, 1]); Assert.Equal(Color.Black, (Color)img[1, 1]);
} }
} }
} }
} }
} }

2
tests/ImageSharp.Tests/Image/ImageTests.cs

@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests
public void Configuration_Width_Height_BackgroundColor() public void Configuration_Width_Height_BackgroundColor()
{ {
Configuration configuration = Configuration.Default.Clone(); Configuration configuration = Configuration.Default.Clone();
Rgba32 color = Rgba32.Aquamarine; Rgba32 color = Color.Aquamarine;
using (var image = new Image<Rgba32>(configuration, 11, 23, color)) using (var image = new Image<Rgba32>(configuration, 11, 23, color))
{ {

42
tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs

@ -45,15 +45,15 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
public static TheoryData<Rgba32, Rgba32, float, PixelColorBlendingMode, Rgba32> ColorBlendingExpectedResults = new TheoryData<Rgba32, Rgba32, float, PixelColorBlendingMode, Rgba32> public static TheoryData<Rgba32, Rgba32, float, PixelColorBlendingMode, Rgba32> ColorBlendingExpectedResults = new TheoryData<Rgba32, Rgba32, float, PixelColorBlendingMode, Rgba32>
{ {
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Normal, Rgba32.MidnightBlue }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Normal, Color.MidnightBlue },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Screen, new Rgba32(0xFFEEE7FF) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Screen, new Rgba32(0xFFEEE7FF) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.HardLight, new Rgba32(0xFFC62D32) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.HardLight, new Rgba32(0xFFC62D32) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Overlay, new Rgba32(0xFFDDCEFF) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Overlay, new Rgba32(0xFFDDCEFF) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Darken, new Rgba32(0xFF701919) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Darken, new Rgba32(0xFF701919) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Lighten, new Rgba32(0xFFE1E4FF) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Lighten, new Rgba32(0xFFE1E4FF) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Add, new Rgba32(0xFFFFFDFF) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Add, new Rgba32(0xFFFFFDFF) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Subtract, new Rgba32(0xFF71CBE6) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Subtract, new Rgba32(0xFF71CBE6) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelColorBlendingMode.Multiply, new Rgba32(0xFF631619) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelColorBlendingMode.Multiply, new Rgba32(0xFF631619) },
}; };
[Theory] [Theory]
@ -69,18 +69,18 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
public static TheoryData<Rgba32, Rgba32, float, PixelAlphaCompositionMode, Rgba32> AlphaCompositionExpectedResults = new TheoryData<Rgba32, Rgba32, float, PixelAlphaCompositionMode, Rgba32> public static TheoryData<Rgba32, Rgba32, float, PixelAlphaCompositionMode, Rgba32> AlphaCompositionExpectedResults = new TheoryData<Rgba32, Rgba32, float, PixelAlphaCompositionMode, Rgba32>
{ {
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.Clear, new Rgba32(0) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.Clear, new Rgba32(0) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.Xor, new Rgba32(0) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.Xor, new Rgba32(0) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.Dest, Rgba32.MistyRose }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.Dest, Color.MistyRose },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.DestAtop, Rgba32.MistyRose }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.DestAtop, Color.MistyRose },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.DestIn, Rgba32.MistyRose }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.DestIn, Color.MistyRose },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.DestOut, new Rgba32(0) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.DestOut, new Rgba32(0) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.DestOver, Rgba32.MistyRose }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.DestOver, Color.MistyRose },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.Src, Rgba32.MidnightBlue }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.Src, Color.MidnightBlue },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.SrcAtop, Rgba32.MidnightBlue }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.SrcAtop, Color.MidnightBlue },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.SrcIn, Rgba32.MidnightBlue }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.SrcIn, Color.MidnightBlue },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.SrcOut, new Rgba32(0) }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.SrcOut, new Rgba32(0) },
{ Rgba32.MistyRose, Rgba32.MidnightBlue, 1, PixelAlphaCompositionMode.SrcOver, Rgba32.MidnightBlue }, { Color.MistyRose, Color.MidnightBlue, 1, PixelAlphaCompositionMode.SrcOver, Color.MidnightBlue },
}; };
[Theory] [Theory]

16
tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs

@ -21,10 +21,10 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{ {
var color1 = new Rgba32(0, 0, 0); var color1 = new Rgba32(0, 0, 0);
var color2 = new Rgba32(0, 0, 0, 1F); var color2 = new Rgba32(0, 0, 0, 1F);
var color3 = Rgba32.FromHex("#000"); var color3 = Rgba32.ParseHex("#000");
var color4 = Rgba32.FromHex("#000F"); var color4 = Rgba32.ParseHex("#000F");
var color5 = Rgba32.FromHex("#000000"); var color5 = Rgba32.ParseHex("#000000");
var color6 = Rgba32.FromHex("#000000FF"); var color6 = Rgba32.ParseHex("#000000FF");
Assert.Equal(color1, color2); Assert.Equal(color1, color2);
Assert.Equal(color1, color3); Assert.Equal(color1, color3);
@ -41,9 +41,9 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{ {
var color1 = new Rgba32(255, 0, 0, 255); var color1 = new Rgba32(255, 0, 0, 255);
var color2 = new Rgba32(0, 0, 0, 255); var color2 = new Rgba32(0, 0, 0, 255);
var color3 = Rgba32.FromHex("#000"); var color3 = Rgba32.ParseHex("#000");
var color4 = Rgba32.FromHex("#000000"); var color4 = Rgba32.ParseHex("#000000");
var color5 = Rgba32.FromHex("#FF000000"); var color5 = Rgba32.ParseHex("#FF000000");
Assert.NotEqual(color1, color2); Assert.NotEqual(color1, color2);
Assert.NotEqual(color1, color3); Assert.NotEqual(color1, color3);
@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
public void FromAndToHex() public void FromAndToHex()
{ {
// 8 digit hex matches css4 spec. RRGGBBAA // 8 digit hex matches css4 spec. RRGGBBAA
var color = Rgba32.FromHex("#AABBCCDD"); // 170, 187, 204, 221 var color = Rgba32.ParseHex("#AABBCCDD"); // 170, 187, 204, 221
Assert.Equal(170, color.R); Assert.Equal(170, color.R);
Assert.Equal(187, color.G); Assert.Equal(187, color.G);
Assert.Equal(204, color.B); Assert.Equal(204, color.B);

2
tests/ImageSharp.Tests/PixelFormats/UnPackedPixelTests.cs

@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Colors
[Fact] [Fact]
public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut() public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut()
{ {
var color = Rgba32.FromHex("183060C0"); var color = Rgba32.ParseHex("183060C0");
var colorVector = RgbaVector.FromHex("183060C0"); var colorVector = RgbaVector.FromHex("183060C0");
Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.R, (byte)(colorVector.R * 255));

2
tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs

@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Overlays
[Fact] [Fact]
public void Glow_Color_GlowProcessorWithDefaultValues() public void Glow_Color_GlowProcessorWithDefaultValues()
{ {
this.operations.Glow(Rgba32.Aquamarine); this.operations.Glow(Color.Aquamarine);
GlowProcessor p = this.Verify<GlowProcessor>(); GlowProcessor p = this.Verify<GlowProcessor>();
Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, GraphicsOptionsComparer); Assert.Equal(new GraphicsOptions(), p.GraphicsOptions, GraphicsOptionsComparer);

4
tests/ImageSharp.Tests/Processing/Processors/Quantization/PaletteQuantizerTests.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Quantization
{ {
public class PaletteQuantizerTests public class PaletteQuantizerTests
{ {
private static readonly Color[] Rgb = new Color[] { Rgba32.Red, Rgba32.Green, Rgba32.Blue }; private static readonly Color[] Rgb = new Color[] { Color.Red, Color.Green, Color.Blue };
[Fact] [Fact]
public void PaletteQuantizerConstructor() public void PaletteQuantizerConstructor()

2
tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs

@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
} }
[Theory] [Theory]
[WithSolidFilledImages(nameof(TaperMatrixData), 30, 30, nameof(Rgba32.Red), PixelTypes.Rgba32)] [WithSolidFilledImages(nameof(TaperMatrixData), 30, 30, nameof(Color.Red), PixelTypes.Rgba32)]
public void Transform_WithTaperMatrix<TPixel>(TestImageProvider<TPixel> provider, TaperSide taperSide, TaperCorner taperCorner) public void Transform_WithTaperMatrix<TPixel>(TestImageProvider<TPixel> provider, TaperSide taperSide, TaperCorner taperCorner)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {

4
tests/ImageSharp.Tests/Quantization/WuQuantizerTests.cs

@ -17,13 +17,13 @@ namespace SixLabors.ImageSharp.Tests.Quantization
Configuration config = Configuration.Default; Configuration config = Configuration.Default;
var quantizer = new WuQuantizer(false); var quantizer = new WuQuantizer(false);
using (var image = new Image<Rgba32>(config, 1, 1, Rgba32.Black)) using (var image = new Image<Rgba32>(config, 1, 1, Color.Black))
using (IQuantizedFrame<Rgba32> result = quantizer.CreateFrameQuantizer<Rgba32>(config).QuantizeFrame(image.Frames[0])) using (IQuantizedFrame<Rgba32> result = quantizer.CreateFrameQuantizer<Rgba32>(config).QuantizeFrame(image.Frames[0]))
{ {
Assert.Equal(1, result.Palette.Length); Assert.Equal(1, result.Palette.Length);
Assert.Equal(1, result.GetPixelSpan().Length); Assert.Equal(1, result.GetPixelSpan().Length);
Assert.Equal(Rgba32.Black, result.Palette.Span[0]); Assert.Equal(Color.Black, (Color)result.Palette.Span[0]);
Assert.Equal(0, result.GetPixelSpan()[0]); Assert.Equal(0, result.GetPixelSpan()[0]);
} }
} }

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

@ -157,9 +157,9 @@ namespace SixLabors.ImageSharp.Tests
int bottom = pixels.Height; int bottom = pixels.Height;
int height = (int)Math.Ceiling(pixels.Height / 6f); int height = (int)Math.Ceiling(pixels.Height / 6f);
var red = Rgba32.Red.ToVector4(); // use real color so we can see har it translates in the test pattern var red = Color.Red.ToPixel<TPixel>().ToVector4(); // use real color so we can see how it translates in the test pattern
var green = Rgba32.Green.ToVector4(); // use real color so we can see har it translates in the test pattern var green = Color.Green.ToPixel<TPixel>().ToVector4(); // use real color so we can see how it translates in the test pattern
var blue = Rgba32.Blue.ToVector4(); // use real color so we can see har it translates in the test pattern var blue = Color.Blue.ToPixel<TPixel>().ToVector4(); // use real color so we can see how it translates in the test pattern
var c = default(TPixel); var c = default(TPixel);

Loading…
Cancel
Save