mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
24 changed files with 2521 additions and 432 deletions
@ -1,4 +1,4 @@ |
|||
// <copyright file="ColorDefinitions.cs" company="James Jackson-South">
|
|||
// <copyright file="Color.Definitions.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
@ -0,0 +1,27 @@ |
|||
namespace ImageSharp |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
|
|||
/// The color components are stored in red, green, blue, and alpha order.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
|
|||
/// as it avoids the need to create new values for modification operations.
|
|||
/// </remarks>
|
|||
public partial struct ColorVector |
|||
{ |
|||
/// <summary>
|
|||
/// <see cref="BulkPixelOperations{TColor}"/> implementation optimized for <see cref="ColorVector"/>.
|
|||
/// </summary>
|
|||
internal class BulkOperations : BulkPixelOperations<ColorVector> |
|||
{ |
|||
/// <inheritdoc />
|
|||
internal override unsafe void ToVector4(BufferSpan<ColorVector> sourceColors, BufferSpan<Vector4> destVectors, int count) |
|||
{ |
|||
BufferSpan.Copy(sourceColors.AsBytes(), destVectors.AsBytes(), count * sizeof(Vector4)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,728 @@ |
|||
// <copyright file="ColorVector.Definitions.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// Unpacked pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
|
|||
/// The color components are stored in red, green, blue, and alpha order.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
|
|||
/// as it avoids the need to create new values for modification operations.
|
|||
/// </remarks>
|
|||
public partial struct ColorVector |
|||
{ |
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0F8FF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector AliceBlue = NamedColors<ColorVector>.AliceBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAEBD7.
|
|||
/// </summary>
|
|||
public static readonly ColorVector AntiqueWhite = NamedColors<ColorVector>.AntiqueWhite; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FFFF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Aqua = NamedColors<ColorVector>.Aqua; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7FFFD4.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Aquamarine = NamedColors<ColorVector>.Aquamarine; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0FFFF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Azure = NamedColors<ColorVector>.Azure; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5F5DC.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Beige = NamedColors<ColorVector>.Beige; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4C4.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Bisque = NamedColors<ColorVector>.Bisque; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #000000.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Black = NamedColors<ColorVector>.Black; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFEBCD.
|
|||
/// </summary>
|
|||
public static readonly ColorVector BlanchedAlmond = NamedColors<ColorVector>.BlanchedAlmond; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #0000FF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Blue = NamedColors<ColorVector>.Blue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8A2BE2.
|
|||
/// </summary>
|
|||
public static readonly ColorVector BlueViolet = NamedColors<ColorVector>.BlueViolet; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A52A2A.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Brown = NamedColors<ColorVector>.Brown; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DEB887.
|
|||
/// </summary>
|
|||
public static readonly ColorVector BurlyWood = NamedColors<ColorVector>.BurlyWood; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #5F9EA0.
|
|||
/// </summary>
|
|||
public static readonly ColorVector CadetBlue = NamedColors<ColorVector>.CadetBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7FFF00.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Chartreuse = NamedColors<ColorVector>.Chartreuse; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D2691E.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Chocolate = NamedColors<ColorVector>.Chocolate; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF7F50.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Coral = NamedColors<ColorVector>.Coral; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6495ED.
|
|||
/// </summary>
|
|||
public static readonly ColorVector CornflowerBlue = NamedColors<ColorVector>.CornflowerBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF8DC.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Cornsilk = NamedColors<ColorVector>.Cornsilk; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DC143C.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Crimson = NamedColors<ColorVector>.Crimson; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FFFF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Cyan = NamedColors<ColorVector>.Cyan; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00008B.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkBlue = NamedColors<ColorVector>.DarkBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008B8B.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkCyan = NamedColors<ColorVector>.DarkCyan; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B8860B.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkGoldenrod = NamedColors<ColorVector>.DarkGoldenrod; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A9A9A9.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkGray = NamedColors<ColorVector>.DarkGray; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #006400.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkGreen = NamedColors<ColorVector>.DarkGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BDB76B.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkKhaki = NamedColors<ColorVector>.DarkKhaki; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B008B.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkMagenta = NamedColors<ColorVector>.DarkMagenta; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #556B2F.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkOliveGreen = NamedColors<ColorVector>.DarkOliveGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF8C00.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkOrange = NamedColors<ColorVector>.DarkOrange; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9932CC.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkOrchid = NamedColors<ColorVector>.DarkOrchid; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B0000.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkRed = NamedColors<ColorVector>.DarkRed; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E9967A.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkSalmon = NamedColors<ColorVector>.DarkSalmon; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8FBC8B.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkSeaGreen = NamedColors<ColorVector>.DarkSeaGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #483D8B.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkSlateBlue = NamedColors<ColorVector>.DarkSlateBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #2F4F4F.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkSlateGray = NamedColors<ColorVector>.DarkSlateGray; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00CED1.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkTurquoise = NamedColors<ColorVector>.DarkTurquoise; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9400D3.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DarkViolet = NamedColors<ColorVector>.DarkViolet; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF1493.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DeepPink = NamedColors<ColorVector>.DeepPink; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00BFFF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DeepSkyBlue = NamedColors<ColorVector>.DeepSkyBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #696969.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DimGray = NamedColors<ColorVector>.DimGray; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #1E90FF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector DodgerBlue = NamedColors<ColorVector>.DodgerBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B22222.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Firebrick = NamedColors<ColorVector>.Firebrick; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFAF0.
|
|||
/// </summary>
|
|||
public static readonly ColorVector FloralWhite = NamedColors<ColorVector>.FloralWhite; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #228B22.
|
|||
/// </summary>
|
|||
public static readonly ColorVector ForestGreen = NamedColors<ColorVector>.ForestGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF00FF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Fuchsia = NamedColors<ColorVector>.Fuchsia; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DCDCDC.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Gainsboro = NamedColors<ColorVector>.Gainsboro; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F8F8FF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector GhostWhite = NamedColors<ColorVector>.GhostWhite; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFD700.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Gold = NamedColors<ColorVector>.Gold; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DAA520.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Goldenrod = NamedColors<ColorVector>.Goldenrod; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #808080.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Gray = NamedColors<ColorVector>.Gray; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008000.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Green = NamedColors<ColorVector>.Green; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #ADFF2F.
|
|||
/// </summary>
|
|||
public static readonly ColorVector GreenYellow = NamedColors<ColorVector>.GreenYellow; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0FFF0.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Honeydew = NamedColors<ColorVector>.Honeydew; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF69B4.
|
|||
/// </summary>
|
|||
public static readonly ColorVector HotPink = NamedColors<ColorVector>.HotPink; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #CD5C5C.
|
|||
/// </summary>
|
|||
public static readonly ColorVector IndianRed = NamedColors<ColorVector>.IndianRed; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4B0082.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Indigo = NamedColors<ColorVector>.Indigo; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFF0.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Ivory = NamedColors<ColorVector>.Ivory; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0E68C.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Khaki = NamedColors<ColorVector>.Khaki; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E6E6FA.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Lavender = NamedColors<ColorVector>.Lavender; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF0F5.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LavenderBlush = NamedColors<ColorVector>.LavenderBlush; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7CFC00.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LawnGreen = NamedColors<ColorVector>.LawnGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFACD.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LemonChiffon = NamedColors<ColorVector>.LemonChiffon; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #ADD8E6.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightBlue = NamedColors<ColorVector>.LightBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F08080.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightCoral = NamedColors<ColorVector>.LightCoral; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E0FFFF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightCyan = NamedColors<ColorVector>.LightCyan; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAFAD2.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightGoldenrodYellow = NamedColors<ColorVector>.LightGoldenrodYellow; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D3D3D3.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightGray = NamedColors<ColorVector>.LightGray; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #90EE90.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightGreen = NamedColors<ColorVector>.LightGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFB6C1.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightPink = NamedColors<ColorVector>.LightPink; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFA07A.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightSalmon = NamedColors<ColorVector>.LightSalmon; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #20B2AA.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightSeaGreen = NamedColors<ColorVector>.LightSeaGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #87CEFA.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightSkyBlue = NamedColors<ColorVector>.LightSkyBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #778899.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightSlateGray = NamedColors<ColorVector>.LightSlateGray; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B0C4DE.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightSteelBlue = NamedColors<ColorVector>.LightSteelBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFE0.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LightYellow = NamedColors<ColorVector>.LightYellow; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FF00.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Lime = NamedColors<ColorVector>.Lime; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #32CD32.
|
|||
/// </summary>
|
|||
public static readonly ColorVector LimeGreen = NamedColors<ColorVector>.LimeGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAF0E6.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Linen = NamedColors<ColorVector>.Linen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF00FF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Magenta = NamedColors<ColorVector>.Magenta; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #800000.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Maroon = NamedColors<ColorVector>.Maroon; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #66CDAA.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumAquamarine = NamedColors<ColorVector>.MediumAquamarine; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #0000CD.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumBlue = NamedColors<ColorVector>.MediumBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BA55D3.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumOrchid = NamedColors<ColorVector>.MediumOrchid; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9370DB.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumPurple = NamedColors<ColorVector>.MediumPurple; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #3CB371.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumSeaGreen = NamedColors<ColorVector>.MediumSeaGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7B68EE.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumSlateBlue = NamedColors<ColorVector>.MediumSlateBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FA9A.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumSpringGreen = NamedColors<ColorVector>.MediumSpringGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #48D1CC.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumTurquoise = NamedColors<ColorVector>.MediumTurquoise; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #C71585.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MediumVioletRed = NamedColors<ColorVector>.MediumVioletRed; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #191970.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MidnightBlue = NamedColors<ColorVector>.MidnightBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5FFFA.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MintCream = NamedColors<ColorVector>.MintCream; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4E1.
|
|||
/// </summary>
|
|||
public static readonly ColorVector MistyRose = NamedColors<ColorVector>.MistyRose; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4B5.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Moccasin = NamedColors<ColorVector>.Moccasin; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFDEAD.
|
|||
/// </summary>
|
|||
public static readonly ColorVector NavajoWhite = NamedColors<ColorVector>.NavajoWhite; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #000080.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Navy = NamedColors<ColorVector>.Navy; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FDF5E6.
|
|||
/// </summary>
|
|||
public static readonly ColorVector OldLace = NamedColors<ColorVector>.OldLace; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #808000.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Olive = NamedColors<ColorVector>.Olive; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6B8E23.
|
|||
/// </summary>
|
|||
public static readonly ColorVector OliveDrab = NamedColors<ColorVector>.OliveDrab; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFA500.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Orange = NamedColors<ColorVector>.Orange; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF4500.
|
|||
/// </summary>
|
|||
public static readonly ColorVector OrangeRed = NamedColors<ColorVector>.OrangeRed; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DA70D6.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Orchid = NamedColors<ColorVector>.Orchid; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #EEE8AA.
|
|||
/// </summary>
|
|||
public static readonly ColorVector PaleGoldenrod = NamedColors<ColorVector>.PaleGoldenrod; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #98FB98.
|
|||
/// </summary>
|
|||
public static readonly ColorVector PaleGreen = NamedColors<ColorVector>.PaleGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #AFEEEE.
|
|||
/// </summary>
|
|||
public static readonly ColorVector PaleTurquoise = NamedColors<ColorVector>.PaleTurquoise; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DB7093.
|
|||
/// </summary>
|
|||
public static readonly ColorVector PaleVioletRed = NamedColors<ColorVector>.PaleVioletRed; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFEFD5.
|
|||
/// </summary>
|
|||
public static readonly ColorVector PapayaWhip = NamedColors<ColorVector>.PapayaWhip; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFDAB9.
|
|||
/// </summary>
|
|||
public static readonly ColorVector PeachPuff = NamedColors<ColorVector>.PeachPuff; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #CD853F.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Peru = NamedColors<ColorVector>.Peru; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFC0CB.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Pink = NamedColors<ColorVector>.Pink; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DDA0DD.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Plum = NamedColors<ColorVector>.Plum; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B0E0E6.
|
|||
/// </summary>
|
|||
public static readonly ColorVector PowderBlue = NamedColors<ColorVector>.PowderBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #800080.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Purple = NamedColors<ColorVector>.Purple; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #663399.
|
|||
/// </summary>
|
|||
public static readonly ColorVector RebeccaPurple = NamedColors<ColorVector>.RebeccaPurple; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF0000.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Red = NamedColors<ColorVector>.Red; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BC8F8F.
|
|||
/// </summary>
|
|||
public static readonly ColorVector RosyBrown = NamedColors<ColorVector>.RosyBrown; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4169E1.
|
|||
/// </summary>
|
|||
public static readonly ColorVector RoyalBlue = NamedColors<ColorVector>.RoyalBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B4513.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SaddleBrown = NamedColors<ColorVector>.SaddleBrown; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FA8072.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Salmon = NamedColors<ColorVector>.Salmon; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F4A460.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SandyBrown = NamedColors<ColorVector>.SandyBrown; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #2E8B57.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SeaGreen = NamedColors<ColorVector>.SeaGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF5EE.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SeaShell = NamedColors<ColorVector>.SeaShell; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A0522D.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Sienna = NamedColors<ColorVector>.Sienna; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #C0C0C0.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Silver = NamedColors<ColorVector>.Silver; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #87CEEB.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SkyBlue = NamedColors<ColorVector>.SkyBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6A5ACD.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SlateBlue = NamedColors<ColorVector>.SlateBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #708090.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SlateGray = NamedColors<ColorVector>.SlateGray; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFAFA.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Snow = NamedColors<ColorVector>.Snow; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FF7F.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SpringGreen = NamedColors<ColorVector>.SpringGreen; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4682B4.
|
|||
/// </summary>
|
|||
public static readonly ColorVector SteelBlue = NamedColors<ColorVector>.SteelBlue; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D2B48C.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Tan = NamedColors<ColorVector>.Tan; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008080.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Teal = NamedColors<ColorVector>.Teal; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D8BFD8.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Thistle = NamedColors<ColorVector>.Thistle; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF6347.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Tomato = NamedColors<ColorVector>.Tomato; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFFF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Transparent = NamedColors<ColorVector>.Transparent; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #40E0D0.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Turquoise = NamedColors<ColorVector>.Turquoise; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #EE82EE.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Violet = NamedColors<ColorVector>.Violet; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5DEB3.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Wheat = NamedColors<ColorVector>.Wheat; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFFF.
|
|||
/// </summary>
|
|||
public static readonly ColorVector White = NamedColors<ColorVector>.White; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5F5F5.
|
|||
/// </summary>
|
|||
public static readonly ColorVector WhiteSmoke = NamedColors<ColorVector>.WhiteSmoke; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFF00.
|
|||
/// </summary>
|
|||
public static readonly ColorVector Yellow = NamedColors<ColorVector>.Yellow; |
|||
|
|||
/// <summary>
|
|||
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9ACD32.
|
|||
/// </summary>
|
|||
public static readonly ColorVector YellowGreen = NamedColors<ColorVector>.YellowGreen; |
|||
} |
|||
} |
|||
@ -0,0 +1,253 @@ |
|||
// <copyright file="ColorVector.Transforms.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
/// <summary>
|
|||
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
|
|||
/// The color components are stored in red, green, blue, and alpha order.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
|
|||
/// as it avoids the need to create new values for modification operations.
|
|||
/// </remarks>
|
|||
public partial struct ColorVector |
|||
{ |
|||
/// <summary>
|
|||
/// Adds the second color to the first.
|
|||
/// </summary>
|
|||
/// <param name="left">The first source color.</param>
|
|||
/// <param name="right">The second source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector operator +(ColorVector left, ColorVector right) |
|||
{ |
|||
return new ColorVector(left.backingVector + right.backingVector); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Subtracts the second color from the first.
|
|||
/// </summary>
|
|||
/// <param name="left">The first source color.</param>
|
|||
/// <param name="right">The second source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector operator -(ColorVector left, ColorVector right) |
|||
{ |
|||
return new ColorVector(left.backingVector - right.backingVector); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// The blending formula simply selects the source color.
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector Normal(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 normal = Vector4BlendTransforms.Normal(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(normal); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Blends two colors by multiplication.
|
|||
/// <remarks>
|
|||
/// The source color is multiplied by the destination color and replaces the destination.
|
|||
/// The resultant color is always at least as dark as either the source or destination color.
|
|||
/// Multiplying any color with black results in black. Multiplying any color with white preserves the
|
|||
/// original color.
|
|||
/// </remarks>
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector Multiply(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(multiply); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies the complements of the backdrop and source color values, then complements the result.
|
|||
/// <remarks>
|
|||
/// The result color is always at least as light as either of the two constituent colors. Screening any
|
|||
/// color with white produces white; screening with black leaves the original color unchanged.
|
|||
/// The effect is similar to projecting multiple photographic slides simultaneously onto a single screen.
|
|||
/// </remarks>
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector Screen(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(subtract); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies or screens the colors, depending on the source color value. The effect is similar to
|
|||
/// shining a harsh spotlight on the backdrop.
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector HardLight(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(hardlight); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies or screens the colors, depending on the backdrop color value.
|
|||
/// <remarks>
|
|||
/// Source colors overlay the backdrop while preserving its highlights and shadows.
|
|||
/// The backdrop color is not replaced but is mixed with the source color to reflect the lightness or darkness
|
|||
/// of the backdrop.
|
|||
/// </remarks>
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector Overlay(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(overlay); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Selects the darker of the backdrop and source colors.
|
|||
/// The backdrop is replaced with the source where the source is darker; otherwise, it is left unchanged.
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector Darken(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 darken = Vector4BlendTransforms.Darken(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(darken); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Selects the lighter of the backdrop and source colors.
|
|||
/// The backdrop is replaced with the source where the source is lighter; otherwise, it is left unchanged.
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector Lighten(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(lighten); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Darkens or lightens the colors, depending on the source color value. The effect is similar to shining
|
|||
/// a diffused spotlight on the backdrop.
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector SoftLight(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(softlight); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Brightens the backdrop color to reflect the source color. Painting with black produces no changes.
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector ColorDodge(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(dodge); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Darkens the backdrop color to reflect the source color. Painting with white produces no change.
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector ColorBurn(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 burn = Vector4BlendTransforms.Burn(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(burn); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Subtracts the darker of the two constituent colors from the lighter color.
|
|||
/// Painting with white inverts the backdrop color; painting with black produces no change.
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector Difference(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 difference = Vector4BlendTransforms.Difference(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(difference); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Produces an effect similar to that of the <see cref="Difference"/> mode but lower in contrast. Painting with white
|
|||
/// inverts the backdrop color; painting with black produces no change
|
|||
/// </summary>
|
|||
/// <param name="backdrop">The backdrop color.</param>
|
|||
/// <param name="source">The source color.</param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector Exclusion(ColorVector backdrop, ColorVector source) |
|||
{ |
|||
Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.backingVector, source.backingVector); |
|||
return new ColorVector(exclusion); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Linearly interpolates from one color to another based on the given weighting.
|
|||
/// </summary>
|
|||
/// <param name="from">The first color value.</param>
|
|||
/// <param name="to">The second color value.</param>
|
|||
/// <param name="amount">
|
|||
/// A value between 0 and 1 indicating the weight of the second source vector.
|
|||
/// At amount = 0, "from" is returned, at amount = 1, "to" is returned.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>
|
|||
/// </returns>
|
|||
public static ColorVector Lerp(ColorVector from, ColorVector to, float amount) |
|||
{ |
|||
return new ColorVector(Vector4.Lerp(from.backingVector, to.backingVector, amount)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,316 @@ |
|||
// <copyright file="ColorVector.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
/// <summary>
|
|||
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
|
|||
/// The color components are stored in red, green, blue, and alpha order.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
|
|||
/// as it avoids the need to create new values for modification operations.
|
|||
/// </remarks>
|
|||
public partial struct ColorVector : IPixel<ColorVector> |
|||
{ |
|||
/// <summary>
|
|||
/// The maximum byte value.
|
|||
/// </summary>
|
|||
private static readonly Vector4 MaxBytes = new Vector4(255); |
|||
|
|||
/// <summary>
|
|||
/// The half vector value.
|
|||
/// </summary>
|
|||
private static readonly Vector4 Half = new Vector4(0.5F); |
|||
|
|||
/// <summary>
|
|||
/// The backing vector for SIMD support.
|
|||
/// </summary>
|
|||
private Vector4 backingVector; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ColorVector"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="r">The red component.</param>
|
|||
/// <param name="g">The green component.</param>
|
|||
/// <param name="b">The blue component.</param>
|
|||
/// <param name="a">The alpha component.</param>
|
|||
public ColorVector(byte r, byte g, byte b, byte a = 255) |
|||
: this() |
|||
{ |
|||
this.backingVector = new Vector4(r, g, b, a) / MaxBytes; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ColorVector"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="r">The red component.</param>
|
|||
/// <param name="g">The green component.</param>
|
|||
/// <param name="b">The blue component.</param>
|
|||
/// <param name="a">The alpha component.</param>
|
|||
public ColorVector(float r, float g, float b, float a = 1) |
|||
: this() |
|||
{ |
|||
this.backingVector = new Vector4(r, g, b, a); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ColorVector"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="vector">
|
|||
/// The vector containing the components for the packed vector.
|
|||
/// </param>
|
|||
public ColorVector(Vector3 vector) |
|||
: this() |
|||
{ |
|||
this.backingVector = new Vector4(vector, 1); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="ColorVector"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="vector">
|
|||
/// The vector containing the components for the packed vector.
|
|||
/// </param>
|
|||
public ColorVector(Vector4 vector) |
|||
: this() |
|||
{ |
|||
this.backingVector = vector; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the red component.
|
|||
/// </summary>
|
|||
public float R |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
get |
|||
{ |
|||
return this.backingVector.X; |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
set |
|||
{ |
|||
this.backingVector.X = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the green component.
|
|||
/// </summary>
|
|||
public float G |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
get |
|||
{ |
|||
return this.backingVector.Y; |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
set |
|||
{ |
|||
this.backingVector.Y = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the blue component.
|
|||
/// </summary>
|
|||
public float B |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
get |
|||
{ |
|||
return this.backingVector.Z; |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
set |
|||
{ |
|||
this.backingVector.Z = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the alpha component.
|
|||
/// </summary>
|
|||
public float A |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
get |
|||
{ |
|||
return this.backingVector.W; |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
set |
|||
{ |
|||
this.backingVector.W = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="ColorVector"/> objects for equality.
|
|||
/// </summary>
|
|||
/// <param name="left">
|
|||
/// The <see cref="ColorVector"/> on the left side of the operand.
|
|||
/// </param>
|
|||
/// <param name="right">
|
|||
/// The <see cref="ColorVector"/> on the right side of the operand.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static bool operator ==(ColorVector left, ColorVector right) |
|||
{ |
|||
return left.backingVector == right.backingVector; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="ColorVector"/> objects for equality.
|
|||
/// </summary>
|
|||
/// <param name="left">The <see cref="ColorVector"/> on the left side of the operand.</param>
|
|||
/// <param name="right">The <see cref="ColorVector"/> on the right side of the operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static bool operator !=(ColorVector left, ColorVector right) |
|||
{ |
|||
return left.backingVector != right.backingVector; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new instance of the <see cref="ColorVector"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="hex">
|
|||
/// The hexadecimal representation of the combined color components arranged
|
|||
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The <see cref="ColorVector"/>.
|
|||
/// </returns>
|
|||
public static ColorVector FromHex(string hex) |
|||
{ |
|||
return ColorBuilder<ColorVector>.FromHex(hex); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public BulkPixelOperations<ColorVector> CreateBulkOperations() => new ColorVector.BulkOperations(); |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void PackFromBytes(byte x, byte y, byte z, byte w) |
|||
{ |
|||
this.backingVector = new Vector4(x, y, z, w) / MaxBytes; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts the value of this instance to a hexadecimal string.
|
|||
/// </summary>
|
|||
/// <returns>A hexadecimal string representation of the value.</returns>
|
|||
public string ToHex() |
|||
{ |
|||
// Hex is RRGGBBAA
|
|||
Vector4 vector = this.backingVector * MaxBytes; |
|||
vector += Half; |
|||
uint hexOrder = (uint)((byte)vector.W | (byte)vector.Z << 8 | (byte)vector.Y << 16 | (byte)vector.X << 24); |
|||
return hexOrder.ToString("X8"); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void ToXyzBytes(byte[] bytes, int startIndex) |
|||
{ |
|||
Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; |
|||
vector += Half; |
|||
bytes[startIndex] = (byte)vector.X; |
|||
bytes[startIndex + 1] = (byte)vector.Y; |
|||
bytes[startIndex + 2] = (byte)vector.Z; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void ToXyzwBytes(byte[] bytes, int startIndex) |
|||
{ |
|||
Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; |
|||
vector += Half; |
|||
bytes[startIndex] = (byte)vector.X; |
|||
bytes[startIndex + 1] = (byte)vector.Y; |
|||
bytes[startIndex + 2] = (byte)vector.Z; |
|||
bytes[startIndex + 3] = (byte)vector.W; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void ToZyxBytes(byte[] bytes, int startIndex) |
|||
{ |
|||
Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; |
|||
vector += Half; |
|||
bytes[startIndex] = (byte)vector.Z; |
|||
bytes[startIndex + 1] = (byte)vector.Y; |
|||
bytes[startIndex + 2] = (byte)vector.X; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void ToZyxwBytes(byte[] bytes, int startIndex) |
|||
{ |
|||
Vector4 vector = Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One) * MaxBytes; |
|||
vector += Half; |
|||
bytes[startIndex] = (byte)vector.Z; |
|||
bytes[startIndex + 1] = (byte)vector.Y; |
|||
bytes[startIndex + 2] = (byte)vector.X; |
|||
bytes[startIndex + 3] = (byte)vector.W; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void PackFromVector4(Vector4 vector) |
|||
{ |
|||
this.backingVector = vector; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public Vector4 ToVector4() |
|||
{ |
|||
return this.backingVector; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
return (obj is ColorVector) && this.Equals((ColorVector)obj); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public bool Equals(ColorVector other) |
|||
{ |
|||
return this.backingVector == other.backingVector; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets a string representation of the packed vector.
|
|||
/// </summary>
|
|||
/// <returns>A string representation of the packed vector.</returns>
|
|||
public override string ToString() |
|||
{ |
|||
return this.ToVector4().ToString(); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() |
|||
{ |
|||
return this.backingVector.GetHashCode(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,398 @@ |
|||
// <copyright file="Rgba32.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
/// <summary>
|
|||
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
|
|||
/// The color components are stored in red, green, blue, and alpha order.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
|
|||
/// as it avoids the need to create new values for modification operations.
|
|||
/// </remarks>
|
|||
public struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint> |
|||
{ |
|||
/// <summary>
|
|||
/// The shift count for the red component
|
|||
/// </summary>
|
|||
private const int RedShift = 0; |
|||
|
|||
/// <summary>
|
|||
/// The shift count for the green component
|
|||
/// </summary>
|
|||
private const int GreenShift = 8; |
|||
|
|||
/// <summary>
|
|||
/// The shift count for the blue component
|
|||
/// </summary>
|
|||
private const int BlueShift = 16; |
|||
|
|||
/// <summary>
|
|||
/// The shift count for the alpha component
|
|||
/// </summary>
|
|||
private const int AlphaShift = 24; |
|||
|
|||
/// <summary>
|
|||
/// The maximum byte value.
|
|||
/// </summary>
|
|||
private static readonly Vector4 MaxBytes = new Vector4(255); |
|||
|
|||
/// <summary>
|
|||
/// The half vector value.
|
|||
/// </summary>
|
|||
private static readonly Vector4 Half = new Vector4(0.5F); |
|||
|
|||
/// <summary>
|
|||
/// The packed value.
|
|||
/// </summary>
|
|||
private uint packedValue; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="r">The red component.</param>
|
|||
/// <param name="g">The green component.</param>
|
|||
/// <param name="b">The blue component.</param>
|
|||
/// <param name="a">The alpha component.</param>
|
|||
public Rgba32(byte r, byte g, byte b, byte a = 255) |
|||
{ |
|||
this.packedValue = Pack(r, g, b, a); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="r">The red component.</param>
|
|||
/// <param name="g">The green component.</param>
|
|||
/// <param name="b">The blue component.</param>
|
|||
/// <param name="a">The alpha component.</param>
|
|||
public Rgba32(float r, float g, float b, float a = 1) |
|||
{ |
|||
this.packedValue = Pack(r, g, b, a); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="vector">
|
|||
/// The vector containing the components for the packed vector.
|
|||
/// </param>
|
|||
public Rgba32(Vector3 vector) |
|||
{ |
|||
this.packedValue = Pack(ref vector); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="vector">
|
|||
/// The vector containing the components for the packed vector.
|
|||
/// </param>
|
|||
public Rgba32(Vector4 vector) |
|||
{ |
|||
this.packedValue = Pack(ref vector); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgba32"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="packed">
|
|||
/// The packed value.
|
|||
/// </param>
|
|||
public Rgba32(uint packed) |
|||
{ |
|||
this.packedValue = packed; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the red component.
|
|||
/// </summary>
|
|||
public byte R |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
get |
|||
{ |
|||
return (byte)(this.packedValue >> RedShift); |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
set |
|||
{ |
|||
this.packedValue = this.packedValue & 0xFFFFFF00 | (uint)value << RedShift; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the green component.
|
|||
/// </summary>
|
|||
public byte G |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
get |
|||
{ |
|||
return (byte)(this.packedValue >> GreenShift); |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
set |
|||
{ |
|||
this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << GreenShift; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the blue component.
|
|||
/// </summary>
|
|||
public byte B |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
get |
|||
{ |
|||
return (byte)(this.packedValue >> BlueShift); |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
set |
|||
{ |
|||
this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << BlueShift; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the alpha component.
|
|||
/// </summary>
|
|||
public byte A |
|||
{ |
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
get |
|||
{ |
|||
return (byte)(this.packedValue >> AlphaShift); |
|||
} |
|||
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
set |
|||
{ |
|||
this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << AlphaShift; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public uint PackedValue |
|||
{ |
|||
get => this.packedValue; |
|||
|
|||
set => this.packedValue = value; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="Rgba32"/> objects for equality.
|
|||
/// </summary>
|
|||
/// <param name="left">
|
|||
/// The <see cref="Rgba32"/> on the left side of the operand.
|
|||
/// </param>
|
|||
/// <param name="right">
|
|||
/// The <see cref="Rgba32"/> on the right side of the operand.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static bool operator ==(Rgba32 left, Rgba32 right) |
|||
{ |
|||
return left.packedValue == right.packedValue; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Compares two <see cref="Rgba32"/> objects for equality.
|
|||
/// </summary>
|
|||
/// <param name="left">The <see cref="Rgba32"/> on the left side of the operand.</param>
|
|||
/// <param name="right">The <see cref="Rgba32"/> on the right side of the operand.</param>
|
|||
/// <returns>
|
|||
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
|
|||
/// </returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public static bool operator !=(Rgba32 left, Rgba32 right) |
|||
{ |
|||
return left.packedValue != right.packedValue; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new instance of the <see cref="Rgba32"/> struct.
|
|||
/// </summary>
|
|||
/// <param name="hex">
|
|||
/// The hexadecimal representation of the combined color components arranged
|
|||
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The <see cref="Rgba32"/>.
|
|||
/// </returns>
|
|||
public static Rgba32 FromHex(string hex) |
|||
{ |
|||
return ColorBuilder<Rgba32>.FromHex(hex); |
|||
} |
|||
|
|||
/// <inheritdoc />
|
|||
public BulkPixelOperations<Rgba32> CreateBulkOperations() => new BulkPixelOperations<Rgba32>(); |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void PackFromBytes(byte x, byte y, byte z, byte w) |
|||
{ |
|||
this.packedValue = Pack(x, y, z, w); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts the value of this instance to a hexadecimal string.
|
|||
/// </summary>
|
|||
/// <returns>A hexadecimal string representation of the value.</returns>
|
|||
public string ToHex() |
|||
{ |
|||
uint hexOrder = Pack(this.A, this.B, this.G, this.R); |
|||
return hexOrder.ToString("X8"); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void ToXyzBytes(byte[] bytes, int startIndex) |
|||
{ |
|||
bytes[startIndex] = this.R; |
|||
bytes[startIndex + 1] = this.G; |
|||
bytes[startIndex + 2] = this.B; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void ToXyzwBytes(byte[] bytes, int startIndex) |
|||
{ |
|||
bytes[startIndex] = this.R; |
|||
bytes[startIndex + 1] = this.G; |
|||
bytes[startIndex + 2] = this.B; |
|||
bytes[startIndex + 3] = this.A; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void ToZyxBytes(byte[] bytes, int startIndex) |
|||
{ |
|||
bytes[startIndex] = this.B; |
|||
bytes[startIndex + 1] = this.G; |
|||
bytes[startIndex + 2] = this.R; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void ToZyxwBytes(byte[] bytes, int startIndex) |
|||
{ |
|||
bytes[startIndex] = this.B; |
|||
bytes[startIndex + 1] = this.G; |
|||
bytes[startIndex + 2] = this.R; |
|||
bytes[startIndex + 3] = this.A; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public void PackFromVector4(Vector4 vector) |
|||
{ |
|||
this.packedValue = Pack(ref vector); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public Vector4 ToVector4() |
|||
{ |
|||
return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
return (obj is Rgba32) && this.Equals((Rgba32)obj); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
public bool Equals(Rgba32 other) |
|||
{ |
|||
return this.packedValue == other.packedValue; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets a string representation of the packed vector.
|
|||
/// </summary>
|
|||
/// <returns>A string representation of the packed vector.</returns>
|
|||
public override string ToString() |
|||
{ |
|||
return this.ToVector4().ToString(); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int GetHashCode() |
|||
{ |
|||
return this.packedValue.GetHashCode(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Packs a <see cref="Vector4"/> into a uint.
|
|||
/// </summary>
|
|||
/// <param name="vector">The vector containing the values to pack.</param>
|
|||
/// <returns>The <see cref="uint"/> containing the packed values.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
private static uint Pack(ref Vector4 vector) |
|||
{ |
|||
vector *= MaxBytes; |
|||
vector += Half; |
|||
vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes); |
|||
return (uint)(((byte)vector.X << RedShift) |
|||
| ((byte)vector.Y << GreenShift) |
|||
| ((byte)vector.Z << BlueShift) |
|||
| (byte)vector.W << AlphaShift); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Packs a <see cref="Vector3"/> into a uint.
|
|||
/// </summary>
|
|||
/// <param name="vector">The vector containing the values to pack.</param>
|
|||
/// <returns>The <see cref="uint"/> containing the packed values.</returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
private static uint Pack(ref Vector3 vector) |
|||
{ |
|||
Vector4 value = new Vector4(vector, 1); |
|||
return Pack(ref value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Packs the four floats into a <see cref="uint"/>.
|
|||
/// </summary>
|
|||
/// <param name="x">The x-component</param>
|
|||
/// <param name="y">The y-component</param>
|
|||
/// <param name="z">The z-component</param>
|
|||
/// <param name="w">The w-component</param>
|
|||
/// <returns>The <see cref="uint"/></returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
private static uint Pack(float x, float y, float z, float w) |
|||
{ |
|||
Vector4 value = new Vector4(x, y, z, w); |
|||
return Pack(ref value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Packs the four floats into a <see cref="uint"/>.
|
|||
/// </summary>
|
|||
/// <param name="x">The x-component</param>
|
|||
/// <param name="y">The y-component</param>
|
|||
/// <param name="z">The z-component</param>
|
|||
/// <param name="w">The w-component</param>
|
|||
/// <returns>The <see cref="uint"/></returns>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
private static uint Pack(byte x, byte y, byte z, byte w) |
|||
{ |
|||
return (uint)(x << RedShift | y << GreenShift | z << BlueShift | w << AlphaShift); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,132 @@ |
|||
// <copyright file="ColorVectorTests.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Tests |
|||
{ |
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
using Xunit; |
|||
|
|||
/// <summary>
|
|||
/// Tests the <see cref="ColorVector"/> struct.
|
|||
/// </summary>
|
|||
public class ColorVectorTests |
|||
{ |
|||
/// <summary>
|
|||
/// Tests the equality operators for equality.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void AreEqual() |
|||
{ |
|||
ColorVector color1 = new ColorVector(0, 0, 0F); |
|||
ColorVector color2 = new ColorVector(0, 0, 0, 1F); |
|||
ColorVector color3 = ColorVector.FromHex("#000"); |
|||
ColorVector color4 = ColorVector.FromHex("#000F"); |
|||
ColorVector color5 = ColorVector.FromHex("#000000"); |
|||
ColorVector color6 = ColorVector.FromHex("#000000FF"); |
|||
|
|||
Assert.Equal(color1, color2); |
|||
Assert.Equal(color1, color3); |
|||
Assert.Equal(color1, color4); |
|||
Assert.Equal(color1, color5); |
|||
Assert.Equal(color1, color6); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests the equality operators for inequality.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void AreNotEqual() |
|||
{ |
|||
ColorVector color1 = new ColorVector(1, 0, 0, 1); |
|||
ColorVector color2 = new ColorVector(0, 0, 0, 1); |
|||
ColorVector color3 = ColorVector.FromHex("#000"); |
|||
ColorVector color4 = ColorVector.FromHex("#000000"); |
|||
ColorVector color5 = ColorVector.FromHex("#FF000000"); |
|||
|
|||
Assert.NotEqual(color1, color2); |
|||
Assert.NotEqual(color1, color3); |
|||
Assert.NotEqual(color1, color4); |
|||
Assert.NotEqual(color1, color5); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests whether the color constructor correctly assign properties.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void ConstructorAssignsProperties() |
|||
{ |
|||
ColorVector color1 = new ColorVector(1, .1F, .133F, .864F); |
|||
Assert.Equal(1F, color1.R); |
|||
Assert.Equal(.1F, color1.G); |
|||
Assert.Equal(.133F, color1.B); |
|||
Assert.Equal(.864F, color1.A); |
|||
|
|||
ColorVector color2 = new ColorVector(1, .1f, .133f); |
|||
Assert.Equal(1F, color2.R); |
|||
Assert.Equal(.1F, color2.G); |
|||
Assert.Equal(.133F, color2.B); |
|||
Assert.Equal(1F, color2.A); |
|||
|
|||
ColorVector color4 = new ColorVector(new Vector3(1, .1f, .133f)); |
|||
Assert.Equal(1F, color4.R); |
|||
Assert.Equal(.1F, color4.G); |
|||
Assert.Equal(.133F, color4.B); |
|||
Assert.Equal(1F, color4.A); |
|||
|
|||
ColorVector color5 = new ColorVector(new Vector4(1, .1f, .133f, .5f)); |
|||
Assert.Equal(1F, color5.R); |
|||
Assert.Equal(.1F, color5.G); |
|||
Assert.Equal(.133F, color5.B); |
|||
Assert.Equal(.5F, color5.A); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests whether FromHex and ToHex work correctly.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void FromAndToHex() |
|||
{ |
|||
ColorVector color = ColorVector.FromHex("#AABBCCDD"); |
|||
Assert.Equal(170 / 255F, color.R); |
|||
Assert.Equal(187 / 255F, color.G); |
|||
Assert.Equal(204 / 255F, color.B); |
|||
Assert.Equal(221 / 255F, color.A); |
|||
|
|||
color.A = 170 / 255F; |
|||
color.B = 187 / 255F; |
|||
color.G = 204 / 255F; |
|||
color.R = 221 / 255F; |
|||
|
|||
Assert.Equal("DDCCBBAA", color.ToHex()); |
|||
|
|||
color.R = 0; |
|||
|
|||
Assert.Equal("00CCBBAA", color.ToHex()); |
|||
|
|||
color.A = 255 / 255F; |
|||
|
|||
Assert.Equal("00CCBBFF", color.ToHex()); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the individual float elements are layed out in RGBA order.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void FloatLayout() |
|||
{ |
|||
ColorVector color = new ColorVector(1F, 2, 3, 4); |
|||
Vector4 colorBase = Unsafe.As<ColorVector, Vector4>(ref Unsafe.Add(ref color, 0)); |
|||
float[] ordered = new float[4]; |
|||
colorBase.CopyTo(ordered); |
|||
|
|||
Assert.Equal(1, ordered[0]); |
|||
Assert.Equal(2, ordered[1]); |
|||
Assert.Equal(3, ordered[2]); |
|||
Assert.Equal(4, ordered[3]); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,118 @@ |
|||
// <copyright file="ColorVectorTransformTests.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp.Tests.Colors |
|||
{ |
|||
using Xunit; |
|||
|
|||
/// <summary>
|
|||
/// Tests the color transform algorithms. Test results match the output of CSS equivalents.
|
|||
/// <see href="https://jsfiddle.net/jamessouth/L1v8r6kh/"/>
|
|||
/// </summary>
|
|||
public class ColorVectorTransformTests |
|||
{ |
|||
private static readonly ApproximateFloatComparer FloatComparer = new ApproximateFloatComparer(0.01F); |
|||
|
|||
/// <summary>
|
|||
/// Orange backdrop
|
|||
/// </summary>
|
|||
private static readonly ColorVector Backdrop = new ColorVector(204, 102, 0); |
|||
|
|||
/// <summary>
|
|||
/// Blue source
|
|||
/// </summary>
|
|||
private static readonly ColorVector Source = new ColorVector(0, 102, 153); |
|||
|
|||
[Fact] |
|||
public void Normal() |
|||
{ |
|||
ColorVector normal = ColorVector.Normal(Backdrop, Source); |
|||
Assert.True(normal == Source); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Multiply() |
|||
{ |
|||
Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.Black).ToVector4(), Color.Black.ToVector4(), FloatComparer); |
|||
Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.White).ToVector4(), Backdrop.ToVector4(), FloatComparer); |
|||
|
|||
ColorVector multiply = ColorVector.Multiply(Backdrop, Source); |
|||
Assert.Equal(multiply.ToVector4(), new ColorVector(0, 41, 0).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Screen() |
|||
{ |
|||
Assert.Equal(ColorVector.Screen(Backdrop, ColorVector.Black).ToVector4(), Backdrop.ToVector4(), FloatComparer); |
|||
Assert.Equal(ColorVector.Screen(Backdrop, ColorVector.White).ToVector4(), ColorVector.White.ToVector4(), FloatComparer); |
|||
|
|||
ColorVector screen = ColorVector.Screen(Backdrop, Source); |
|||
Assert.Equal(screen.ToVector4(), new ColorVector(204, 163, 153).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void HardLight() |
|||
{ |
|||
ColorVector hardLight = ColorVector.HardLight(Backdrop, Source); |
|||
Assert.Equal(hardLight.ToVector4(), new ColorVector(0, 82, 51).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Overlay() |
|||
{ |
|||
ColorVector overlay = ColorVector.Overlay(Backdrop, Source); |
|||
Assert.Equal(overlay.ToVector4(), new ColorVector(153, 82, 0).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Darken() |
|||
{ |
|||
ColorVector darken = ColorVector.Darken(Backdrop, Source); |
|||
Assert.Equal(darken.ToVector4(), new ColorVector(0, 102, 0).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Lighten() |
|||
{ |
|||
ColorVector lighten = ColorVector.Lighten(Backdrop, Source); |
|||
Assert.Equal(lighten.ToVector4(), new ColorVector(204, 102, 153).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void SoftLight() |
|||
{ |
|||
ColorVector softLight = ColorVector.SoftLight(Backdrop, Source); |
|||
Assert.Equal(softLight.ToVector4(), new ColorVector(163, 90, 0).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ColorDodge() |
|||
{ |
|||
ColorVector colorDodge = ColorVector.ColorDodge(Backdrop, Source); |
|||
Assert.Equal(colorDodge.ToVector4(), new ColorVector(204, 170, 0).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ColorBurn() |
|||
{ |
|||
ColorVector colorBurn = ColorVector.ColorBurn(Backdrop, Source); |
|||
Assert.Equal(colorBurn.ToVector4(), new ColorVector(0, 0, 0).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Difference() |
|||
{ |
|||
ColorVector difference = ColorVector.Difference(Backdrop, Source); |
|||
Assert.Equal(difference.ToVector4(), new ColorVector(204, 0, 153).ToVector4(), FloatComparer); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Exclusion() |
|||
{ |
|||
ColorVector exclusion = ColorVector.Exclusion(Backdrop, Source); |
|||
Assert.Equal(exclusion.ToVector4(), new ColorVector(204, 122, 153).ToVector4(), FloatComparer); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,148 @@ |
|||
namespace ImageSharp.Tests.Colors |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
using Xunit; |
|||
|
|||
public class UnPackedPixelTests |
|||
{ |
|||
[Fact] |
|||
public void Color_Types_From_Bytes_Produce_Equal_Scaled_Component_OutPut() |
|||
{ |
|||
Color color = new Color(24, 48, 96, 192); |
|||
ColorVector colorVector = new ColorVector(24, 48, 96, 192); |
|||
|
|||
Assert.Equal(color.R, (byte)(colorVector.R * 255)); |
|||
Assert.Equal(color.G, (byte)(colorVector.G * 255)); |
|||
Assert.Equal(color.B, (byte)(colorVector.B * 255)); |
|||
Assert.Equal(color.A, (byte)(colorVector.A * 255)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_From_Floats_Produce_Equal_Scaled_Component_OutPut() |
|||
{ |
|||
Color color = new Color(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); |
|||
ColorVector colorVector = new ColorVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); |
|||
|
|||
Assert.Equal(color.R, (byte)(colorVector.R * 255)); |
|||
Assert.Equal(color.G, (byte)(colorVector.G * 255)); |
|||
Assert.Equal(color.B, (byte)(colorVector.B * 255)); |
|||
Assert.Equal(color.A, (byte)(colorVector.A * 255)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_From_Vector4_Produce_Equal_Scaled_Component_OutPut() |
|||
{ |
|||
Color color = new Color(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); |
|||
ColorVector colorVector = new ColorVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); |
|||
|
|||
Assert.Equal(color.R, (byte)(colorVector.R * 255)); |
|||
Assert.Equal(color.G, (byte)(colorVector.G * 255)); |
|||
Assert.Equal(color.B, (byte)(colorVector.B * 255)); |
|||
Assert.Equal(color.A, (byte)(colorVector.A * 255)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_From_Vector3_Produce_Equal_Scaled_Component_OutPut() |
|||
{ |
|||
Color color = new Color(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); |
|||
ColorVector colorVector = new ColorVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); |
|||
|
|||
Assert.Equal(color.R, (byte)(colorVector.R * 255)); |
|||
Assert.Equal(color.G, (byte)(colorVector.G * 255)); |
|||
Assert.Equal(color.B, (byte)(colorVector.B * 255)); |
|||
Assert.Equal(color.A, (byte)(colorVector.A * 255)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut() |
|||
{ |
|||
Color color = Color.FromHex("183060C0"); |
|||
ColorVector colorVector = ColorVector.FromHex("183060C0"); |
|||
|
|||
Assert.Equal(color.R, (byte)(colorVector.R * 255)); |
|||
Assert.Equal(color.G, (byte)(colorVector.G * 255)); |
|||
Assert.Equal(color.B, (byte)(colorVector.B * 255)); |
|||
Assert.Equal(color.A, (byte)(colorVector.A * 255)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_To_Vector4_Produce_Equal_OutPut() |
|||
{ |
|||
Color color = new Color(24, 48, 96, 192); |
|||
ColorVector colorVector = new ColorVector(24, 48, 96, 192); |
|||
|
|||
Assert.Equal(color.ToVector4(), colorVector.ToVector4()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_To_RgbBytes_Produce_Equal_OutPut() |
|||
{ |
|||
Color color = new Color(24, 48, 96, 192); |
|||
ColorVector colorVector = new ColorVector(24, 48, 96, 192); |
|||
|
|||
byte[] rgb = new byte[3]; |
|||
byte[] rgbVector = new byte[3]; |
|||
|
|||
color.ToXyzBytes(rgb, 0); |
|||
colorVector.ToXyzBytes(rgbVector, 0); |
|||
|
|||
Assert.Equal(rgb, rgbVector); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_To_RgbaBytes_Produce_Equal_OutPut() |
|||
{ |
|||
Color color = new Color(24, 48, 96, 192); |
|||
ColorVector colorVector = new ColorVector(24, 48, 96, 192); |
|||
|
|||
byte[] rgba = new byte[4]; |
|||
byte[] rgbaVector = new byte[4]; |
|||
|
|||
color.ToXyzwBytes(rgba, 0); |
|||
colorVector.ToXyzwBytes(rgbaVector, 0); |
|||
|
|||
Assert.Equal(rgba, rgbaVector); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_To_BgrBytes_Produce_Equal_OutPut() |
|||
{ |
|||
Color color = new Color(24, 48, 96, 192); |
|||
ColorVector colorVector = new ColorVector(24, 48, 96, 192); |
|||
|
|||
byte[] bgr = new byte[3]; |
|||
byte[] bgrVector = new byte[3]; |
|||
|
|||
color.ToZyxBytes(bgr, 0); |
|||
colorVector.ToZyxBytes(bgrVector, 0); |
|||
|
|||
Assert.Equal(bgr, bgrVector); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_To_BgraBytes_Produce_Equal_OutPut() |
|||
{ |
|||
Color color = new Color(24, 48, 96, 192); |
|||
ColorVector colorVector = new ColorVector(24, 48, 96, 192); |
|||
|
|||
byte[] bgra = new byte[4]; |
|||
byte[] bgraVector = new byte[4]; |
|||
|
|||
color.ToZyxwBytes(bgra, 0); |
|||
colorVector.ToZyxwBytes(bgraVector, 0); |
|||
|
|||
Assert.Equal(bgra, bgraVector); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Color_Types_To_Hex_Produce_Equal_OutPut() |
|||
{ |
|||
Color color = new Color(24, 48, 96, 192); |
|||
ColorVector colorVector = new ColorVector(24, 48, 96, 192); |
|||
|
|||
// 183060C0
|
|||
Assert.Equal(color.ToHex(), colorVector.ToHex()); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue