Browse Source

Merge branch 'main' into main

pull/2641/head
James Jackson-South 2 years ago
committed by GitHub
parent
commit
e78db37254
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      ImageSharp.sln
  2. 2
      shared-infrastructure
  3. 1
      src/ImageSharp.ruleset
  4. 240
      src/ImageSharp/Color/Color.Conversions.cs
  5. 288
      src/ImageSharp/Color/Color.NamedColors.cs
  6. 146
      src/ImageSharp/Color/Color.cs
  7. 4
      src/ImageSharp/Formats/AnimationUtilities.cs
  8. 10
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  9. 53
      src/ImageSharp/Formats/PixelTypeInfo.cs
  10. 2
      src/ImageSharp/Formats/Png/PngBitDepth.cs
  11. 9
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  12. 108
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  13. 2
      src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
  14. 4
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs
  15. 8
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs
  16. 2
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs
  17. 2
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CmykTiffColor{TPixel}.cs
  18. 4
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs
  19. 3
      src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs
  20. 2
      src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs
  21. 2
      src/ImageSharp/Formats/Webp/WebpDecoderCore.cs
  22. 2
      src/ImageSharp/ImageInfo.cs
  23. 9
      src/ImageSharp/Image{TPixel}.cs
  24. 8
      src/ImageSharp/PixelFormats/IPixel.cs
  25. 46
      src/ImageSharp/PixelFormats/PixelColorType.cs
  26. 50
      src/ImageSharp/PixelFormats/PixelComponentBitDepth.cs
  27. 111
      src/ImageSharp/PixelFormats/PixelComponentInfo.cs
  28. 7
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  29. 23
      src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
  30. 23
      src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
  31. 23
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
  32. 7
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
  33. 23
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
  34. 7
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
  35. 7
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
  36. 7
      src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
  37. 7
      src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
  38. 7
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
  39. 7
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
  40. 7
      src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
  41. 7
      src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
  42. 7
      src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
  43. 7
      src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
  44. 7
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
  45. 7
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
  46. 7
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
  47. 7
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
  48. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs
  49. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs
  50. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs
  51. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs
  52. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs
  53. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs
  54. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs
  55. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs
  56. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs
  57. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs
  58. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs
  59. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs
  60. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs
  61. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs
  62. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs
  63. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs
  64. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs
  65. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs
  66. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs
  67. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs
  68. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs
  69. 6
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs
  70. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs
  71. 11
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs
  72. 6
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs
  73. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs
  74. 6
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs
  75. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs
  76. 9
      src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs
  77. 7
      src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
  78. 23
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
  79. 7
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
  80. 9
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
  81. 23
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
  82. 23
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
  83. 7
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
  84. 7
      src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
  85. 7
      src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
  86. 4
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
  87. 62
      src/ImageSharp/PixelFormats/PixelTypeInfo.cs
  88. 2
      src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
  89. 4
      src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs
  90. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs
  91. 2
      tests/ImageSharp.Benchmarks/General/GetSetPixel.cs
  92. 2
      tests/ImageSharp.Benchmarks/Processing/BokehBlur.cs
  93. 4
      tests/ImageSharp.Benchmarks/Processing/Diffuse.cs
  94. 2
      tests/ImageSharp.Benchmarks/Processing/GaussianBlur.cs
  95. 2
      tests/ImageSharp.Benchmarks/Processing/Rotate.cs
  96. 2
      tests/ImageSharp.Benchmarks/Processing/Skew.cs
  97. 28
      tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs
  98. 32
      tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs
  99. 28
      tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs
  100. 128
      tests/ImageSharp.Tests/Color/ColorTests.cs

1
ImageSharp.sln

@ -38,6 +38,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{815C0625-CD3
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Build.targets = src\Directory.Build.targets
src\README.md = src\README.md
src\ImageSharp.ruleset = src\ImageSharp.ruleset
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp", "src\ImageSharp\ImageSharp.csproj", "{2AA31A1F-142C-43F4-8687-09ABCA4B3A26}"

2
shared-infrastructure

@ -1 +1 @@
Subproject commit 1c526a97eea8bcbc7c79de095676f7fb975a9fb1
Subproject commit d65232bbbfe55a9a153b4058139dda5230e6eb4f

1
src/ImageSharp.ruleset

@ -2,6 +2,5 @@
<RuleSet Name="ImageSharp" ToolsVersion="17.0">
<Include Path="..\shared-infrastructure\sixlabors.ruleset" Action="Default" />
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1011" Action="None" />
</Rules>
</RuleSet>

240
src/ImageSharp/Color/Color.Conversions.cs

@ -1,240 +0,0 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp;
/// <content>
/// Contains constructors and implicit conversion methods.
/// </content>
public readonly partial struct Color
{
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Rgba64"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Rgba64 pixel)
{
this.data = pixel;
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Rgb48"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Rgb48 pixel)
{
this.data = new Rgba64(pixel.R, pixel.G, pixel.B, ushort.MaxValue);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="La32"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(La32 pixel)
{
this.data = new Rgba64(pixel.L, pixel.L, pixel.L, pixel.A);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="L16"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(L16 pixel)
{
this.data = new Rgba64(pixel.PackedValue, pixel.PackedValue, pixel.PackedValue, ushort.MaxValue);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Rgba32"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Rgba32 pixel)
{
this.data = new Rgba64(pixel);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Argb32"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Argb32 pixel)
{
this.data = new Rgba64(pixel);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Bgra32"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Bgra32 pixel)
{
this.data = new Rgba64(pixel);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Abgr32"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Abgr32 pixel)
{
this.data = new Rgba64(pixel);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Rgb24"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Rgb24 pixel)
{
this.data = new Rgba64(pixel);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The <see cref="Bgr24"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Bgr24 pixel)
{
this.data = new Rgba64(pixel);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="vector">The <see cref="Vector4"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Color(Vector4 vector)
{
vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One);
this.boxedHighPrecisionPixel = new RgbaVector(vector.X, vector.Y, vector.Z, vector.W);
this.data = default;
}
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Vector4"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static explicit operator Vector4(Color color) => color.ToScaledVector4();
/// <summary>
/// Converts an <see cref="Vector4"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Vector4"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static explicit operator Color(Vector4 source) => new(source);
[MethodImpl(InliningOptions.ShortMethod)]
internal Rgba32 ToRgba32()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.ToRgba32();
}
Rgba32 value = default;
this.boxedHighPrecisionPixel.ToRgba32(ref value);
return value;
}
[MethodImpl(InliningOptions.ShortMethod)]
internal Bgra32 ToBgra32()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.ToBgra32();
}
Bgra32 value = default;
value.FromScaledVector4(this.boxedHighPrecisionPixel.ToScaledVector4());
return value;
}
[MethodImpl(InliningOptions.ShortMethod)]
internal Argb32 ToArgb32()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.ToArgb32();
}
Argb32 value = default;
value.FromScaledVector4(this.boxedHighPrecisionPixel.ToScaledVector4());
return value;
}
[MethodImpl(InliningOptions.ShortMethod)]
internal Abgr32 ToAbgr32()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.ToAbgr32();
}
Abgr32 value = default;
value.FromScaledVector4(this.boxedHighPrecisionPixel.ToScaledVector4());
return value;
}
[MethodImpl(InliningOptions.ShortMethod)]
internal Rgb24 ToRgb24()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.ToRgb24();
}
Rgb24 value = default;
value.FromScaledVector4(this.boxedHighPrecisionPixel.ToScaledVector4());
return value;
}
[MethodImpl(InliningOptions.ShortMethod)]
internal Bgr24 ToBgr24()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.ToBgr24();
}
Bgr24 value = default;
value.FromScaledVector4(this.boxedHighPrecisionPixel.ToScaledVector4());
return value;
}
[MethodImpl(InliningOptions.ShortMethod)]
internal Vector4 ToScaledVector4()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.ToScaledVector4();
}
return this.boxedHighPrecisionPixel.ToScaledVector4();
}
}

288
src/ImageSharp/Color/Color.NamedColors.cs

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

146
src/ImageSharp/Color/Color.cs

@ -18,33 +18,24 @@ namespace SixLabors.ImageSharp;
/// </remarks>
public readonly partial struct Color : IEquatable<Color>
{
private readonly Rgba64 data;
private readonly Vector4 data;
private readonly IPixel? boxedHighPrecisionPixel;
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="vector">The <see cref="Vector4"/> containing the color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
private Color(byte r, byte g, byte b, byte a)
{
this.data = new Rgba64(
ColorNumerics.UpscaleFrom8BitTo16Bit(r),
ColorNumerics.UpscaleFrom8BitTo16Bit(g),
ColorNumerics.UpscaleFrom8BitTo16Bit(b),
ColorNumerics.UpscaleFrom8BitTo16Bit(a));
this.boxedHighPrecisionPixel = null;
}
[MethodImpl(InliningOptions.ShortMethod)]
private Color(byte r, byte g, byte b)
private Color(Vector4 vector)
{
this.data = new Rgba64(
ColorNumerics.UpscaleFrom8BitTo16Bit(r),
ColorNumerics.UpscaleFrom8BitTo16Bit(g),
ColorNumerics.UpscaleFrom8BitTo16Bit(b),
ushort.MaxValue);
this.data = Numerics.Clamp(vector, Vector4.Zero, Vector4.One);
this.boxedHighPrecisionPixel = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="Color"/> struct.
/// </summary>
/// <param name="pixel">The pixel containing color information.</param>
[MethodImpl(InliningOptions.ShortMethod)]
private Color(IPixel pixel)
{
@ -52,6 +43,21 @@ public readonly partial struct Color : IEquatable<Color>
this.data = default;
}
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Vector4"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Vector4"/>.</returns>
public static explicit operator Vector4(Color color) => color.ToScaledVector4();
/// <summary>
/// Converts an <see cref="Vector4"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Vector4"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static explicit operator Color(Vector4 source) => new(source);
/// <summary>
/// Checks whether two <see cref="Color"/> structures are equal.
/// </summary>
@ -76,27 +82,6 @@ public readonly partial struct Color : IEquatable<Color>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Color left, Color right) => !left.Equals(right);
/// <summary>
/// Creates a <see cref="Color"/> from RGBA bytes.
/// </summary>
/// <param name="r">The red component (0-255).</param>
/// <param name="g">The green component (0-255).</param>
/// <param name="b">The blue component (0-255).</param>
/// <param name="a">The alpha component (0-255).</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static Color FromRgba(byte r, byte g, byte b, byte a) => new(r, g, b, a);
/// <summary>
/// Creates a <see cref="Color"/> from RGB bytes.
/// </summary>
/// <param name="r">The red component (0-255).</param>
/// <param name="g">The green component (0-255).</param>
/// <param name="b">The blue component (0-255).</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static Color FromRgb(byte r, byte g, byte b) => new(r, g, b);
/// <summary>
/// Creates a <see cref="Color"/> from the given <typeparamref name="TPixel"/>.
/// </summary>
@ -107,32 +92,45 @@ public readonly partial struct Color : IEquatable<Color>
public static Color FromPixel<TPixel>(TPixel pixel)
where TPixel : unmanaged, IPixel<TPixel>
{
// Avoid boxing in case we can convert to Rgba64 safely and efficently
if (typeof(TPixel) == typeof(Rgba64))
{
return new((Rgba64)(object)pixel);
}
else if (typeof(TPixel) == typeof(Rgb48))
// Avoid boxing in case we can convert to Vector4 safely and efficiently
PixelTypeInfo info = TPixel.GetPixelTypeInfo();
if (info.ComponentInfo.HasValue && info.ComponentInfo.Value.GetMaximumComponentPrecision() <= (int)PixelComponentBitDepth.Bit32)
{
return new((Rgb48)(object)pixel);
return new(pixel.ToScaledVector4());
}
else if (typeof(TPixel) == typeof(La32))
{
return new((La32)(object)pixel);
}
else if (typeof(TPixel) == typeof(L16))
else
{
return new((L16)(object)pixel);
return new(pixel);
}
else if (Unsafe.SizeOf<TPixel>() <= Unsafe.SizeOf<Rgba32>())
}
/// <summary>
/// Bulk converts a span of a specified <typeparamref name="TPixel"/> type to a span of <see cref="Color"/>.
/// </summary>
/// <typeparam name="TPixel">The pixel type to convert to.</typeparam>
/// <param name="source">The source pixel span.</param>
/// <param name="destination">The destination color span.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static void FromPixel<TPixel>(ReadOnlySpan<TPixel> source, Span<Color> destination)
where TPixel : unmanaged, IPixel<TPixel>
{
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
// Avoid boxing in case we can convert to Vector4 safely and efficiently
PixelTypeInfo info = TPixel.GetPixelTypeInfo();
if (info.ComponentInfo.HasValue && info.ComponentInfo.Value.GetMaximumComponentPrecision() <= (int)PixelComponentBitDepth.Bit32)
{
Rgba32 p = default;
pixel.ToRgba32(ref p);
return new(p);
for (int i = 0; i < destination.Length; i++)
{
destination[i] = new(source[i].ToScaledVector4());
}
}
else
{
return new(pixel);
for (int i = 0; i < destination.Length; i++)
{
destination[i] = new(source[i]);
}
}
}
@ -151,8 +149,7 @@ public readonly partial struct Color : IEquatable<Color>
public static Color ParseHex(string hex)
{
Rgba32 rgba = Rgba32.ParseHex(hex);
return new Color(rgba);
return FromPixel(rgba);
}
/// <summary>
@ -174,7 +171,7 @@ public readonly partial struct Color : IEquatable<Color>
if (Rgba32.TryParseHex(hex, out Rgba32 rgba))
{
result = new Color(rgba);
result = FromPixel(rgba);
return true;
}
@ -253,14 +250,15 @@ public readonly partial struct Color : IEquatable<Color>
[MethodImpl(InliningOptions.ShortMethod)]
public string ToHex()
{
Rgba32 rgba = default;
if (this.boxedHighPrecisionPixel is not null)
{
Rgba32 rgba = default;
this.boxedHighPrecisionPixel.ToRgba32(ref rgba);
return rgba.ToHex();
}
return this.data.ToRgba32().ToHex();
rgba.FromScaledVector4(this.data);
return rgba.ToHex();
}
/// <inheritdoc />
@ -283,7 +281,7 @@ public readonly partial struct Color : IEquatable<Color>
if (this.boxedHighPrecisionPixel is null)
{
pixel = default;
pixel.FromRgba64(this.data);
pixel.FromScaledVector4(this.data);
return pixel;
}
@ -302,7 +300,8 @@ public readonly partial struct Color : IEquatable<Color>
public static void ToPixel<TPixel>(ReadOnlySpan<Color> source, Span<TPixel> destination)
where TPixel : unmanaged, IPixel<TPixel>
{
// TODO: Investigate bulk operations utilizing configuration parameter here.
// We cannot use bulk pixel operations here as there is no guarantee that the source colors are
// created from pixel formats which fit into the unboxed vector data.
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
for (int i = 0; i < source.Length; i++)
{
@ -316,7 +315,7 @@ public readonly partial struct Color : IEquatable<Color>
{
if (this.boxedHighPrecisionPixel is null && other.boxedHighPrecisionPixel is null)
{
return this.data.PackedValue == other.data.PackedValue;
return this.data == other.data;
}
return this.boxedHighPrecisionPixel?.Equals(other.boxedHighPrecisionPixel) == true;
@ -331,9 +330,20 @@ public readonly partial struct Color : IEquatable<Color>
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data.PackedValue.GetHashCode();
return this.data.GetHashCode();
}
return this.boxedHighPrecisionPixel.GetHashCode();
}
[MethodImpl(InliningOptions.ShortMethod)]
private Vector4 ToScaledVector4()
{
if (this.boxedHighPrecisionPixel is null)
{
return this.data;
}
return this.boxedHighPrecisionPixel.ToScaledVector4();
}
}

4
src/ImageSharp/Formats/AnimationUtilities.cs

@ -50,7 +50,7 @@ internal static class AnimationUtilities
Span<Rgba32> next = buffers.GetSpan().Slice(currentFrame.Width * 2, currentFrame.Width);
Span<Rgba32> result = buffers.GetSpan()[(currentFrame.Width * 3)..];
Rgba32 bg = replacement;
Rgba32 bg = replacement.ToPixel<Rgba32>();
int top = int.MinValue;
int bottom = int.MaxValue;
@ -232,7 +232,7 @@ internal static class AnimationUtilities
ref Rgba32 r = ref Unsafe.Add(ref MemoryMarshal.GetReference(result), x);
bool peq = c.Rgba == (previousFrame != null ? p.Rgba : bg.Rgba);
Rgba32 val = (blend & peq) ? replacement : c;
Rgba32 val = (blend & peq) ? bg : c;
peq &= nextFrame == null || (n.Rgba >> 24 >= c.Rgba >> 24);
r = val;

10
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -711,10 +711,7 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
Color[] colorTable = new Color[this.imageDescriptor.LocalColorTableSize];
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(this.currentLocalColorTable!.GetSpan()[..this.currentLocalColorTableSize]);
for (int i = 0; i < colorTable.Length; i++)
{
colorTable[i] = new Color(rgbTable[i]);
}
Color.FromPixel(rgbTable, colorTable);
gifMeta.LocalColorTable = colorTable;
}
@ -789,10 +786,7 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
Color[] colorTable = new Color[this.logicalScreenDescriptor.GlobalColorTableSize];
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(globalColorTableSpan);
for (int i = 0; i < colorTable.Length; i++)
{
colorTable[i] = new Color(rgbTable[i]);
}
Color.FromPixel(rgbTable, colorTable);
this.gifMetadata.GlobalColorTable = colorTable;
}

53
src/ImageSharp/Formats/PixelTypeInfo.cs

@ -1,53 +0,0 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
// TODO: Review this class as it's used to represent 2 different things.
// 1.The encoded image pixel format.
// 2. The pixel format of the decoded image.
namespace SixLabors.ImageSharp.Formats;
/// <summary>
/// Contains information about the pixels that make up an images visual data.
/// </summary>
public class PixelTypeInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="PixelTypeInfo"/> class.
/// </summary>
/// <param name="bitsPerPixel">Color depth, in number of bits per pixel.</param>
public PixelTypeInfo(int bitsPerPixel)
=> this.BitsPerPixel = bitsPerPixel;
/// <summary>
/// Initializes a new instance of the <see cref="PixelTypeInfo"/> class.
/// </summary>
/// <param name="bitsPerPixel">Color depth, in number of bits per pixel.</param>
/// <param name="alpha">The pixel alpha transparency behavior.</param>
public PixelTypeInfo(int bitsPerPixel, PixelAlphaRepresentation alpha)
{
this.BitsPerPixel = bitsPerPixel;
this.AlphaRepresentation = alpha;
}
/// <summary>
/// Gets color depth, in number of bits per pixel.
/// </summary>
public int BitsPerPixel { get; }
/// <summary>
/// Gets the pixel alpha transparency behavior.
/// <see langword="null"/> means unknown, unspecified.
/// </summary>
public PixelAlphaRepresentation? AlphaRepresentation { get; }
internal static PixelTypeInfo Create<TPixel>()
where TPixel : unmanaged, IPixel<TPixel>
=> new(Unsafe.SizeOf<TPixel>() * 8);
internal static PixelTypeInfo Create<TPixel>(PixelAlphaRepresentation alpha)
where TPixel : unmanaged, IPixel<TPixel>
=> new(Unsafe.SizeOf<TPixel>() * 8, alpha);
}

2
src/ImageSharp/Formats/Png/PngBitDepth.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
// Note the value assignment, This will allow us to add 1, 2, and 4 bit encoding when we support it.

9
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -1240,10 +1240,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
Color[] colorTable = new Color[palette.Length / Unsafe.SizeOf<Rgb24>()];
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(palette);
for (int i = 0; i < colorTable.Length; i++)
{
colorTable[i] = new Color(rgbTable[i]);
}
Color.FromPixel(rgbTable, colorTable);
if (alpha.Length > 0)
{
@ -1276,14 +1273,14 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
ushort gc = BinaryPrimitives.ReadUInt16LittleEndian(alpha.Slice(2, 2));
ushort bc = BinaryPrimitives.ReadUInt16LittleEndian(alpha.Slice(4, 2));
pngMetadata.TransparentColor = new(new Rgb48(rc, gc, bc));
pngMetadata.TransparentColor = Color.FromPixel(new Rgb48(rc, gc, bc));
return;
}
byte r = ReadByteLittleEndian(alpha, 0);
byte g = ReadByteLittleEndian(alpha, 2);
byte b = ReadByteLittleEndian(alpha, 4);
pngMetadata.TransparentColor = new(new Rgb24(r, g, b));
pngMetadata.TransparentColor = Color.FromPixel(new Rgb24(r, g, b));
}
}
else if (this.pngColorType == PngColorType.Grayscale)

108
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -329,7 +329,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
{
// TODO: We should be able to speed this up with SIMD and masking.
Rgba32 rgba32 = default;
Rgba32 transparent = Color.Transparent;
Rgba32 transparent = Color.Transparent.ToPixel<Rgba32>();
for (int y = 0; y < accessor.Height; y++)
{
Span<TPixel> span = accessor.GetRowSpan(y);
@ -1066,7 +1066,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
else
{
alpha.Clear();
Rgb24 rgb = pngMetadata.TransparentColor.Value.ToRgb24();
Rgb24 rgb = pngMetadata.TransparentColor.Value.ToPixel<Rgb24>();
alpha[1] = rgb.R;
alpha[3] = rgb.G;
alpha[5] = rgb.B;
@ -1466,23 +1466,48 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
// Use options, then check metadata, if nothing set there then we suggest
// a sensible default based upon the pixel format.
this.colorType = encoder.ColorType ?? pngMetadata.ColorType ?? SuggestColorType<TPixel>();
if (!encoder.FilterMethod.HasValue)
PngColorType? colorType = encoder.ColorType ?? pngMetadata.ColorType;
byte? bits = (byte?)(encoder.BitDepth ?? pngMetadata.BitDepth);
if (colorType is null || bits is null)
{
// Specification recommends default filter method None for paletted images and Paeth for others.
this.filterMethod = this.colorType is PngColorType.Palette ? PngFilterMethod.None : PngFilterMethod.Paeth;
PixelTypeInfo info = TPixel.GetPixelTypeInfo();
PixelComponentInfo? componentInfo = info.ComponentInfo;
colorType ??= SuggestColorType<TPixel>(in info);
if (bits is null)
{
// TODO: Update once we stop abusing PixelTypeInfo in decoders.
if (componentInfo.HasValue)
{
PixelComponentInfo c = componentInfo.Value;
bits = (byte)SuggestBitDepth<TPixel>(in c);
}
else
{
bits = (byte)PngBitDepth.Bit8;
}
}
}
// Ensure bit depth and color type are a supported combination.
// Bit8 is the only bit depth supported by all color types.
byte bits = (byte)(encoder.BitDepth ?? pngMetadata.BitDepth ?? SuggestBitDepth<TPixel>());
byte[] validBitDepths = PngConstants.ColorTypes[this.colorType];
byte[] validBitDepths = PngConstants.ColorTypes[colorType.Value];
if (Array.IndexOf(validBitDepths, bits) == -1)
{
bits = (byte)PngBitDepth.Bit8;
}
this.bitDepth = bits;
this.colorType = colorType.Value;
this.bitDepth = bits.Value;
if (!encoder.FilterMethod.HasValue)
{
// Specification recommends default filter method None for paletted images and Paeth for others.
this.filterMethod = this.colorType is PngColorType.Palette ? PngFilterMethod.None : PngFilterMethod.Paeth;
}
use16Bit = bits == (byte)PngBitDepth.Bit16;
bytesPerPixel = CalculateBytesPerPixel(this.colorType, use16Bit);
@ -1611,53 +1636,44 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
/// <summary>
/// Returns a suggested <see cref="PngColorType"/> for the given <typeparamref name="TPixel"/>
/// This is not exhaustive but covers many common pixel formats.
/// </summary>
/// <param name="info">The pixel type info.</param>
/// <typeparam name="TPixel">The type of pixel format.</typeparam>
private static PngColorType SuggestColorType<TPixel>()
private static PngColorType SuggestColorType<TPixel>(in PixelTypeInfo info)
where TPixel : unmanaged, IPixel<TPixel>
=> default(TPixel) switch
{
A8 => PngColorType.GrayscaleWithAlpha,
Argb32 => PngColorType.RgbWithAlpha,
Bgr24 => PngColorType.Rgb,
Bgra32 => PngColorType.RgbWithAlpha,
L8 => PngColorType.Grayscale,
L16 => PngColorType.Grayscale,
La16 => PngColorType.GrayscaleWithAlpha,
La32 => PngColorType.GrayscaleWithAlpha,
Rgb24 => PngColorType.Rgb,
Rgba32 => PngColorType.RgbWithAlpha,
Rgb48 => PngColorType.Rgb,
Rgba64 => PngColorType.RgbWithAlpha,
RgbaVector => PngColorType.RgbWithAlpha,
_ => PngColorType.RgbWithAlpha
{
if (info.AlphaRepresentation == PixelAlphaRepresentation.None)
{
return info.ColorType switch
{
PixelColorType.Grayscale => PngColorType.Grayscale,
_ => PngColorType.Rgb,
};
}
return info.ColorType switch
{
PixelColorType.Grayscale | PixelColorType.Alpha or PixelColorType.Alpha => PngColorType.GrayscaleWithAlpha,
_ => PngColorType.RgbWithAlpha,
};
}
/// <summary>
/// Returns a suggested <see cref="PngBitDepth"/> for the given <typeparamref name="TPixel"/>
/// This is not exhaustive but covers many common pixel formats.
/// </summary>
/// <param name="info">The pixel type info.</param>
/// <typeparam name="TPixel">The type of pixel format.</typeparam>
private static PngBitDepth SuggestBitDepth<TPixel>()
private static PngBitDepth SuggestBitDepth<TPixel>(in PixelComponentInfo info)
where TPixel : unmanaged, IPixel<TPixel>
=> default(TPixel) switch
{
A8 => PngBitDepth.Bit8,
Argb32 => PngBitDepth.Bit8,
Bgr24 => PngBitDepth.Bit8,
Bgra32 => PngBitDepth.Bit8,
L8 => PngBitDepth.Bit8,
L16 => PngBitDepth.Bit16,
La16 => PngBitDepth.Bit8,
La32 => PngBitDepth.Bit16,
Rgb24 => PngBitDepth.Bit8,
Rgba32 => PngBitDepth.Bit8,
Rgb48 => PngBitDepth.Bit16,
Rgba64 => PngBitDepth.Bit16,
RgbaVector => PngBitDepth.Bit16,
_ => PngBitDepth.Bit8
};
{
int bits = info.GetMaximumComponentPrecision();
if (bits > (int)PixelComponentBitDepth.Bit8)
{
return PngBitDepth.Bit16;
}
return PngBitDepth.Bit8;
}
private unsafe struct ScratchBuffer
{

2
src/ImageSharp/Formats/Png/PngScanlineProcessor.cs

@ -202,7 +202,7 @@ internal static class PngScanlineProcessor
for (nuint x = pixelOffset, o = 0; x < frameControl.XMax; x += increment, o++)
{
uint index = Unsafe.Add(ref scanlineSpanRef, o);
pixel.FromRgba32(Unsafe.Add(ref paletteBase, index).ToRgba32());
pixel.FromRgba32(Unsafe.Add(ref paletteBase, index).ToPixel<Rgba32>());
Unsafe.Add(ref rowSpanRef, x) = pixel;
}
}

4
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs

@ -22,8 +22,8 @@ internal class BlackIsZero1TiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
TPixel colorBlack = default;
TPixel colorWhite = default;
colorBlack.FromRgba32(Color.Black);
colorWhite.FromRgba32(Color.White);
colorBlack.FromRgba32(Color.Black.ToPixel<Rgba32>());
colorWhite.FromRgba32(Color.White.ToPixel<Rgba32>());
ref byte dataRef = ref MemoryMarshal.GetReference(data);
for (nuint y = (uint)top; y < (uint)(top + height); y++)
{

8
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs

@ -27,17 +27,17 @@ internal class CieLabPlanarTiffColor<TPixel> : TiffBasePlanarColorDecoder<TPixel
Span<byte> a = data[1].GetSpan();
Span<byte> b = data[2].GetSpan();
var color = default(TPixel);
TPixel color = default;
int offset = 0;
for (int y = top; y < top + height; y++)
{
Span<TPixel> pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width);
for (int x = 0; x < pixelRow.Length; x++)
{
var lab = new CieLab((l[offset] & 0xFF) * 100f * Inv255, (sbyte)a[offset], (sbyte)b[offset]);
var rgb = ColorSpaceConverter.ToRgb(lab);
CieLab lab = new((l[offset] & 0xFF) * 100f * Inv255, (sbyte)a[offset], (sbyte)b[offset]);
Rgb rgb = ColorSpaceConverter.ToRgb(lab);
color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset++;

2
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs

@ -34,7 +34,7 @@ internal class CieLabTiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
CieLab lab = new(l, (sbyte)data[offset + 1], (sbyte)data[offset + 2]);
Rgb rgb = ColorSpaceConverter.ToRgb(lab);
color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset += 3;

2
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CmykTiffColor{TPixel}.cs

@ -27,7 +27,7 @@ internal class CmykTiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
Cmyk cmyk = new(data[offset] * Inv255, data[offset + 1] * Inv255, data[offset + 2] * Inv255, data[offset + 3] * Inv255);
Rgb rgb = ColorSpaceConverter.ToRgb(in cmyk);
color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset += 4;

4
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs

@ -21,8 +21,8 @@ internal class WhiteIsZero1TiffColor<TPixel> : TiffBaseColorDecoder<TPixel>
var colorBlack = default(TPixel);
var colorWhite = default(TPixel);
colorBlack.FromRgba32(Color.Black);
colorWhite.FromRgba32(Color.White);
colorBlack.FromRgba32(Color.Black.ToPixel<Rgba32>());
colorWhite.FromRgba32(Color.White.ToPixel<Rgba32>());
ref byte dataRef = ref MemoryMarshal.GetReference(data);
for (nuint y = (uint)top; y < (uint)(top + height); y++)
{

3
src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs

@ -6,6 +6,7 @@ using SixLabors.ImageSharp.Formats.Webp.Chunks;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Webp.BitWriter;
@ -157,7 +158,7 @@ internal abstract class BitWriterBase
/// <param name="loopCount">The number of times to loop the animation. If it is 0, this means infinitely.</param>
public static void WriteAnimationParameter(Stream stream, Color background, ushort loopCount)
{
WebpAnimationParameter chunk = new(background.ToBgra32().PackedValue, loopCount);
WebpAnimationParameter chunk = new(background.ToPixel<Bgra32>().PackedValue, loopCount);
chunk.WriteTo(stream);
}

2
src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs

@ -102,7 +102,7 @@ internal class WebpAnimationDecoder : IDisposable
{
case WebpChunkType.FrameData:
Color backgroundColor = this.backgroundColorHandling == BackgroundColorHandling.Ignore
? new Color(new Bgra32(0, 0, 0, 0))
? Color.FromPixel(new Bgra32(0, 0, 0, 0))
: features.AnimationBackgroundColor!.Value;
uint dataSize = this.ReadFrame(stream, ref image, ref previousFrame, width, height, backgroundColor);
remainingBytes -= (int)dataSize;

2
src/ImageSharp/Formats/Webp/WebpDecoderCore.cs

@ -438,7 +438,7 @@ internal sealed class WebpDecoderCore : IImageDecoderInternals, IDisposable
byte green = (byte)stream.ReadByte();
byte red = (byte)stream.ReadByte();
byte alpha = (byte)stream.ReadByte();
features.AnimationBackgroundColor = new Color(new Rgba32(red, green, blue, alpha));
features.AnimationBackgroundColor = Color.FromPixel(new Rgba32(red, green, blue, alpha));
int bytesRead = stream.Read(buffer, 0, 2);
if (bytesRead != 2)
{

2
src/ImageSharp/ImageInfo.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp;

9
src/ImageSharp/Image{TPixel}.cs

@ -4,7 +4,6 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
@ -78,7 +77,7 @@ public sealed class Image<TPixel> : Image
/// <param name="height">The height of the image in pixels.</param>
/// <param name="metadata">The images metadata.</param>
internal Image(Configuration configuration, int width, int height, ImageMetadata? metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata ?? new(), width, height)
: base(configuration, TPixel.GetPixelTypeInfo(), metadata ?? new(), width, height)
=> this.frames = new ImageFrameCollection<TPixel>(this, width, height, default(TPixel));
/// <summary>
@ -111,7 +110,7 @@ public sealed class Image<TPixel> : Image
int width,
int height,
ImageMetadata metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, width, height)
: base(configuration, TPixel.GetPixelTypeInfo(), metadata, width, height)
=> this.frames = new ImageFrameCollection<TPixel>(this, width, height, memoryGroup);
/// <summary>
@ -129,7 +128,7 @@ public sealed class Image<TPixel> : Image
int height,
TPixel backgroundColor,
ImageMetadata? metadata)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata ?? new(), width, height)
: base(configuration, TPixel.GetPixelTypeInfo(), metadata ?? new(), width, height)
=> this.frames = new ImageFrameCollection<TPixel>(this, width, height, backgroundColor);
/// <summary>
@ -140,7 +139,7 @@ public sealed class Image<TPixel> : Image
/// <param name="metadata">The images metadata.</param>
/// <param name="frames">The frames that will be owned by this image instance.</param>
internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable<ImageFrame<TPixel>> frames)
: base(configuration, PixelTypeInfo.Create<TPixel>(), metadata, ValidateFramesAndGetSize(frames))
: base(configuration, TPixel.GetPixelTypeInfo(), metadata, ValidateFramesAndGetSize(frames))
=> this.frames = new ImageFrameCollection<TPixel>(this, frames);
/// <inheritdoc />

8
src/ImageSharp/PixelFormats/IPixel.cs

@ -14,6 +14,14 @@ namespace SixLabors.ImageSharp.PixelFormats;
public interface IPixel<TSelf> : IPixel, IEquatable<TSelf>
where TSelf : unmanaged, IPixel<TSelf>
{
/// <summary>
/// Gets the pixel type information.
/// </summary>
/// <returns>The <see cref="PixelTypeInfo"/>.</returns>
#pragma warning disable CA1000
static abstract PixelTypeInfo GetPixelTypeInfo();
#pragma warning restore CA1000
/// <summary>
/// Creates a <see cref="PixelOperations{TPixel}"/> instance for this pixel type.
/// This method is not intended to be consumed directly. Use <see cref="PixelOperations{TPixel}.Instance"/> instead.

46
src/ImageSharp/PixelFormats/PixelColorType.cs

@ -0,0 +1,46 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Represents the color type and format of a pixel.
/// </summary>
[Flags]
public enum PixelColorType
{
/// <summary>
/// Represents the Red component of the color.
/// </summary>
Red = 1 << 0,
/// <summary>
/// Represents the Green component of the color.
/// </summary>
Green = 1 << 1,
/// <summary>
/// Represents the Blue component of the color.
/// </summary>
Blue = 1 << 2,
/// <summary>
/// Represents the Alpha component of the color for transparency.
/// </summary>
Alpha = 1 << 3,
/// <summary>
/// Indicates that the color is in grayscale.
/// </summary>
Grayscale = 1 << 4,
/// <summary>
/// Indicates that the color is in RGB (Red, Green, Blue) format.
/// </summary>
RGB = Red | Green | Blue | (1 << 5),
/// <summary>
/// Indicates that the color is in BGR (Blue, Green, Red) format.
/// </summary>
BGR = Blue | Green | Red | (1 << 6)
}

50
src/ImageSharp/PixelFormats/PixelComponentBitDepth.cs

@ -0,0 +1,50 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Provides enumeration of the precision in bits of individual components within a pixel format.
/// </summary>
public enum PixelComponentBitDepth
{
/// <summary>
/// 1 bit per component.
/// </summary>
Bit1 = 1,
/// <summary>
/// 2 bits per component.
/// </summary>
Bit2 = 2,
/// <summary>
/// 4 bits per component.
/// </summary>
Bit4 = 4,
/// <summary>
/// 8 bits per component.
/// </summary>
Bit8 = 8,
/// <summary>
/// 16 bits per component.
/// </summary>
Bit16 = 16,
/// <summary>
/// 32 bits per component.
/// </summary>
Bit32 = 32,
/// <summary>
/// 64 bits per component.
/// </summary>
Bit64 = 64,
/// <summary>
/// 128 bits per component.
/// </summary>
Bit128 = 128
}

111
src/ImageSharp/PixelFormats/PixelComponentInfo.cs

@ -0,0 +1,111 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Represents pixel component information within a pixel format.
/// </summary>
public readonly struct PixelComponentInfo
{
private readonly long precisionData1;
private readonly long precisionData2;
private PixelComponentInfo(int count, int padding, long precisionData1, long precisionData2)
{
this.ComponentCount = count;
this.Padding = padding;
this.precisionData1 = precisionData1;
this.precisionData2 = precisionData2;
}
/// <summary>
/// Gets the number of components within the pixel.
/// </summary>
public int ComponentCount { get; }
/// <summary>
/// Gets the number of bytes of padding within the pixel.
/// </summary>
public int Padding { get; }
/// <summary>
/// Creates a new <see cref="PixelComponentInfo"/> instance.
/// </summary>
/// <typeparam name="TPixel">The type of pixel format.</typeparam>
/// <param name="count">The number of components within the pixel format.</param>
/// <param name="precision">The precision in bits of each component.</param>
/// <returns>The <see cref="PixelComponentInfo"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException">The component precision and index cannot exceed the component range.</exception>
public static PixelComponentInfo Create<TPixel>(int count, params int[] precision)
where TPixel : unmanaged, IPixel<TPixel>
{
if (precision.Length != count || precision.Length > 16)
{
throw new ArgumentException($"Count must match the length of precision array and cannot exceed 16.");
}
long precisionData1 = 0;
long precisionData2 = 0;
int sum = 0;
for (int i = 0; i < precision.Length; i++)
{
int p = precision[i];
if (p is < 0 or > 255)
{
throw new ArgumentException("Precision must be between 0 and 255.");
}
if (i < 8)
{
precisionData1 |= ((long)p) << (8 * i);
}
else
{
precisionData2 |= ((long)p) << (8 * (i - 8));
}
sum += p;
}
return new PixelComponentInfo(count, (Unsafe.SizeOf<TPixel>() * 8) - sum, precisionData1, precisionData2);
}
/// <summary>
/// Returns the precision of the component in bits at the given index.
/// </summary>
/// <param name="componentIndex">The component index.</param>
/// <returns>The <see cref="int"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException">The component index cannot exceed the component range.</exception>
public int GetComponentPrecision(int componentIndex)
{
if (componentIndex < 0 || componentIndex >= this.ComponentCount)
{
throw new ArgumentOutOfRangeException($"Component index must be between 0 and {this.ComponentCount - 1} inclusive.");
}
long selectedPrecisionData = componentIndex < 8 ? this.precisionData1 : this.precisionData2;
return (int)((selectedPrecisionData >> (8 * (componentIndex & 7))) & 0xFF);
}
/// <summary>
/// Returns the maximum precision in bits of all components.
/// </summary>
/// <returns>The <see cref="int"/>.</returns>
public int GetMaximumComponentPrecision()
{
int maxPrecision = 0;
for (int i = 0; i < this.ComponentCount; i++)
{
int componentPrecision = this.GetComponentPrecision(i);
if (componentPrecision > maxPrecision)
{
maxPrecision = componentPrecision;
}
}
return maxPrecision;
}
}

7
src/ImageSharp/PixelFormats/PixelImplementations/A8.cs

@ -55,6 +55,13 @@ public partial struct A8 : IPixel<A8>, IPackedVector<byte>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
/// <inheritdoc/>
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<A8>(
PixelComponentInfo.Create<A8>(1, 8),
PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<A8> CreatePixelOperations() => new PixelOperations();

23
src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs

@ -145,22 +145,6 @@ public partial struct Abgr32 : IPixel<Abgr32>, IPackedVector<uint>
set => this.Abgr = value;
}
/// <summary>
/// Converts an <see cref="Abgr32"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Abgr32"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Abgr32 source) => new(source);
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Abgr32"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Abgr32"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Abgr32(Color color) => color.ToAbgr32();
/// <summary>
/// Compares two <see cref="Argb32"/> objects for equality.
/// </summary>
@ -183,6 +167,13 @@ public partial struct Abgr32 : IPixel<Abgr32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Abgr32 left, Abgr32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Abgr32>(
PixelComponentInfo.Create<Abgr32>(4, 8, 8, 8, 8),
PixelColorType.Alpha | PixelColorType.BGR,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Abgr32> CreatePixelOperations() => new PixelOperations();

23
src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs

@ -145,22 +145,6 @@ public partial struct Argb32 : IPixel<Argb32>, IPackedVector<uint>
set => this.Argb = value;
}
/// <summary>
/// Converts an <see cref="Argb32"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Argb32"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Argb32 source) => new(source);
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Argb32"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Argb32"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Argb32(Color color) => color.ToArgb32();
/// <summary>
/// Compares two <see cref="Argb32"/> objects for equality.
/// </summary>
@ -183,6 +167,13 @@ public partial struct Argb32 : IPixel<Argb32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Argb32 left, Argb32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Argb32>(
PixelComponentInfo.Create<Argb32>(4, 8, 8, 8, 8),
PixelColorType.Alpha | PixelColorType.RGB,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Argb32> CreatePixelOperations() => new PixelOperations();

23
src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs

@ -49,22 +49,6 @@ public partial struct Bgr24 : IPixel<Bgr24>
this.B = b;
}
/// <summary>
/// Converts an <see cref="Bgr24"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Bgr24"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Bgr24 source) => new(source);
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Bgr24"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Bgr24"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Bgr24(Color color) => color.ToBgr24();
/// <summary>
/// Compares two <see cref="Bgr24"/> objects for equality.
/// </summary>
@ -87,6 +71,13 @@ public partial struct Bgr24 : IPixel<Bgr24>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgr24 left, Bgr24 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Bgr24>(
PixelComponentInfo.Create<Bgr24>(3, 8, 8, 8),
PixelColorType.BGR,
PixelAlphaRepresentation.None);
/// <inheritdoc/>
public readonly PixelOperations<Bgr24> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs

@ -59,6 +59,13 @@ public partial struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Bgr565>(
PixelComponentInfo.Create<Bgr565>(3, 5, 6, 5),
PixelColorType.BGR,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations();

23
src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs

@ -98,22 +98,6 @@ public partial struct Bgra32 : IPixel<Bgra32>, IPackedVector<uint>
set => this.Bgra = value;
}
/// <summary>
/// Converts an <see cref="Bgra32"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Bgra32"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Bgra32 source) => new(source);
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Bgra32"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Bgra32"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Bgra32(Color color) => color.ToBgra32();
/// <summary>
/// Compares two <see cref="Bgra32"/> objects for equality.
/// </summary>
@ -136,6 +120,13 @@ public partial struct Bgra32 : IPixel<Bgra32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Bgra32>(
PixelComponentInfo.Create<Bgra32>(4, 8, 8, 8, 8),
PixelColorType.BGR | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<Bgra32> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs

@ -57,6 +57,13 @@ public partial struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Bgra4444>(
PixelComponentInfo.Create<Bgra4444>(4, 4, 4, 4, 4),
PixelColorType.BGR | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs

@ -60,6 +60,13 @@ public partial struct Bgra5551 : IPixel<Bgra5551>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra5551 left, Bgra5551 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Bgra5551>(
PixelComponentInfo.Create<Bgra5551>(4, 5, 5, 5, 1),
PixelColorType.BGR | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Bgra5551> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs

@ -60,6 +60,13 @@ public partial struct Byte4 : IPixel<Byte4>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Byte4 left, Byte4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Byte4>(
PixelComponentInfo.Create<Byte4>(4, 8, 8, 8, 8),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Byte4> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs

@ -45,6 +45,13 @@ public partial struct HalfSingle : IPixel<HalfSingle>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfSingle left, HalfSingle right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<HalfSingle>(
PixelComponentInfo.Create<HalfSingle>(1, 16),
PixelColorType.Red,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public PixelOperations<HalfSingle> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs

@ -52,6 +52,13 @@ public partial struct HalfVector2 : IPixel<HalfVector2>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfVector2 left, HalfVector2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<HalfVector2>(
PixelComponentInfo.Create<HalfVector2>(2, 16, 16),
PixelColorType.Red | PixelColorType.Green,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<HalfVector2> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs

@ -57,6 +57,13 @@ public partial struct HalfVector4 : IPixel<HalfVector4>, IPackedVector<ulong>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfVector4 left, HalfVector4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<HalfVector4>(
PixelComponentInfo.Create<HalfVector4>(4, 16, 16, 16, 16),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<HalfVector4> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/L16.cs

@ -47,6 +47,13 @@ public partial struct L16 : IPixel<L16>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(L16 left, L16 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<L16>(
PixelComponentInfo.Create<L16>(1, 16),
PixelColorType.Grayscale,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<L16> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/L8.cs

@ -48,6 +48,13 @@ public partial struct L8 : IPixel<L8>, IPackedVector<byte>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(L8 left, L8 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<L8>(
PixelComponentInfo.Create<L8>(1, 8),
PixelColorType.Grayscale,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<L8> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/La16.cs

@ -71,6 +71,13 @@ public partial struct La16 : IPixel<La16>, IPackedVector<ushort>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(La16 left, La16 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<La16>(
PixelComponentInfo.Create<La16>(2, 8, 8),
PixelColorType.Grayscale | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<La16> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/La32.cs

@ -73,6 +73,13 @@ public partial struct La32 : IPixel<La32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(La32 left, La32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<La32>(
PixelComponentInfo.Create<La32>(2, 16, 16),
PixelColorType.Grayscale | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<La32> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs

@ -60,6 +60,13 @@ public partial struct NormalizedByte2 : IPixel<NormalizedByte2>, IPackedVector<u
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedByte2 left, NormalizedByte2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<NormalizedByte2>(
PixelComponentInfo.Create<NormalizedByte2>(2, 8, 8),
PixelColorType.Red | PixelColorType.Green,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte2> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs

@ -62,6 +62,13 @@ public partial struct NormalizedByte4 : IPixel<NormalizedByte4>, IPackedVector<u
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedByte4 left, NormalizedByte4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<NormalizedByte4>(
PixelComponentInfo.Create<NormalizedByte4>(4, 8, 8, 8, 8),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte4> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs

@ -61,6 +61,13 @@ public partial struct NormalizedShort2 : IPixel<NormalizedShort2>, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedShort2 left, NormalizedShort2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<NormalizedShort2>(
PixelComponentInfo.Create<NormalizedShort2>(2, 16, 16),
PixelColorType.Red | PixelColorType.Green,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort2> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs

@ -63,6 +63,13 @@ public partial struct NormalizedShort4 : IPixel<NormalizedShort4>, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedShort4 left, NormalizedShort4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<NormalizedShort4>(
PixelComponentInfo.Create<NormalizedShort4>(4, 16, 16, 16, 16),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort4> CreatePixelOperations() => new PixelOperations();

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct A8
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<A8>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<A8>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<A8>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Abgr32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Abgr32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Abgr32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Abgr32>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Argb32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Argb32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Argb32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Argb32>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgr24
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgr24>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgr24>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Bgr24>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgr565
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgr565>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgr565>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Bgr565>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgra32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgra32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Bgra32>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgra4444
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Bgra4444>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra4444>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Bgra4444>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Bgra5551
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Bgra5551>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Bgra5551>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Bgra5551>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Byte4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Byte4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Byte4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Byte4>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfSingle.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct HalfSingle
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<HalfSingle>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<HalfSingle>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<HalfSingle>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector2.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct HalfVector2
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<HalfVector2>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<HalfVector2>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<HalfVector2>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/HalfVector4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct HalfVector4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<HalfVector4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<HalfVector4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<HalfVector4>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L16.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct L16
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<L16>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<L16>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<L16>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/L8.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct L8
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<L8>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<L8>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<L8>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La16.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct La16
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<La16>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<La16>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<La16>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/La32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct La32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<La32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<La32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<La32>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte2.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct NormalizedByte2
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<NormalizedByte2>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<NormalizedByte2>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<NormalizedByte2>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedByte4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct NormalizedByte4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<NormalizedByte4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<NormalizedByte4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<NormalizedByte4>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort2.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct NormalizedShort2
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<NormalizedShort2>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<NormalizedShort2>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<NormalizedShort2>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/NormalizedShort4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct NormalizedShort4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<NormalizedShort4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<NormalizedShort4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<NormalizedShort4>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rg32.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Rg32
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rg32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Rg32>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Rg32>;
}

6
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb24.PixelOperations.cs

@ -15,12 +15,6 @@ public partial struct Rgb24
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgb24>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new(() => PixelTypeInfo.Create<Rgb24>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
/// <inheritdoc />
internal override void PackFromRgbPlanes(
ReadOnlySpan<byte> redChannel,

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgb48.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Rgb48
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgb48>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Rgb48>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Rgb48>;
}

11
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba1010102.PixelOperations.cs

@ -1,8 +1,6 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
/// <content>
@ -13,12 +11,5 @@ public partial struct Rgba1010102
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Rgba1010102>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Rgba1010102>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Rgba1010102>;
}

6
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba32.PixelOperations.cs

@ -18,12 +18,6 @@ public partial struct Rgba32
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgba32>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new(() => PixelTypeInfo.Create<Rgba32>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
/// <inheritdoc />
public override void ToVector4(
Configuration configuration,

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Rgba64.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Rgba64
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal partial class PixelOperations : PixelOperations<Rgba64>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Rgba64>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal partial class PixelOperations : PixelOperations<Rgba64>;
}

6
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/RgbaVector.PixelOperations.cs

@ -19,12 +19,6 @@ public partial struct RgbaVector
/// </summary>
internal class PixelOperations : PixelOperations<RgbaVector>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new(() => PixelTypeInfo.Create<RgbaVector>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
/// <inheritdoc />
public override void From<TSourcePixel>(
Configuration configuration,

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short2.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Short2
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Short2>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Short2>(PixelAlphaRepresentation.None), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Short2>;
}

9
src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Short4.PixelOperations.cs

@ -13,12 +13,5 @@ public partial struct Short4
/// <summary>
/// Provides optimized overrides for bulk operations.
/// </summary>
internal class PixelOperations : PixelOperations<Short4>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo =
new Lazy<PixelTypeInfo>(() => PixelTypeInfo.Create<Short4>(PixelAlphaRepresentation.Unassociated), true);
/// <inheritdoc />
public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
}
internal class PixelOperations : PixelOperations<Short4>;
}

7
src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs

@ -57,6 +57,13 @@ public partial struct Rg32 : IPixel<Rg32>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rg32 left, Rg32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Rg32>(
PixelComponentInfo.Create<Rg32>(2, 16, 16),
PixelColorType.Red | PixelColorType.Green,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Rg32> CreatePixelOperations() => new PixelOperations();

23
src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs

@ -52,22 +52,6 @@ public partial struct Rgb24 : IPixel<Rgb24>
this.B = b;
}
/// <summary>
/// Converts an <see cref="Rgb24"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Rgb24"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Rgb24 source) => new(source);
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Rgb24"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Rgb24"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Rgb24(Color color) => color.ToRgb24();
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="ColorSpaces.Rgb"/> to a
/// <see cref="Rgb24"/>.
@ -106,6 +90,13 @@ public partial struct Rgb24 : IPixel<Rgb24>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rgb24 left, Rgb24 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Rgb24>(
PixelComponentInfo.Create<Rgb24>(3, 8, 8, 8),
PixelColorType.RGB,
PixelAlphaRepresentation.None);
/// <inheritdoc/>
public readonly PixelOperations<Rgb24> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs

@ -69,6 +69,13 @@ public partial struct Rgb48 : IPixel<Rgb48>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rgb48 left, Rgb48 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Rgb48>(
PixelComponentInfo.Create<Rgb48>(3, 16, 16, 16),
PixelColorType.RGB,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Rgb48> CreatePixelOperations() => new PixelOperations();

9
src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs

@ -7,7 +7,7 @@ using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Packed vector type containing unsigned normalized values ranging from 0 to 1.
/// Packed vector type containing 4 unsigned normalized values ranging from 0 to 1.
/// The x, y and z components use 10 bits, and the w component uses 2 bits.
/// <para>
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
@ -60,6 +60,13 @@ public partial struct Rgba1010102 : IPixel<Rgba1010102>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rgba1010102 left, Rgba1010102 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Rgba1010102>(
PixelComponentInfo.Create<Rgba1010102>(4, 10, 10, 10, 2),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba1010102> CreatePixelOperations() => new PixelOperations();

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

@ -174,22 +174,6 @@ public partial struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint>
set => this.Rgba = value;
}
/// <summary>
/// Converts an <see cref="Rgba32"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Rgba32"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Rgba32 source) => new(source);
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Rgba32"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Rgba32"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Rgba32(Color color) => color.ToRgba32();
/// <summary>
/// Allows the implicit conversion of an instance of <see cref="ColorSpaces.Rgb"/> to a
/// <see cref="Rgba32"/>.
@ -286,6 +270,13 @@ public partial struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint>
return true;
}
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Rgba32>(
PixelComponentInfo.Create<Rgba32>(4, 8, 8, 8, 8),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba32> CreatePixelOperations() => new PixelOperations();

23
src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs

@ -168,22 +168,6 @@ public partial struct Rgba64 : IPixel<Rgba64>, IPackedVector<ulong>
set => Unsafe.As<Rgba64, ulong>(ref this) = value;
}
/// <summary>
/// Converts an <see cref="Rgba64"/> to <see cref="Color"/>.
/// </summary>
/// <param name="source">The <see cref="Rgba64"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Color(Rgba64 source) => new(source);
/// <summary>
/// Converts a <see cref="Color"/> to <see cref="Rgba64"/>.
/// </summary>
/// <param name="color">The <see cref="Color"/>.</param>
/// <returns>The <see cref="Rgba64"/>.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static implicit operator Rgba64(Color color) => color.ToPixel<Rgba64>();
/// <summary>
/// Compares two <see cref="Rgba64"/> objects for equality.
/// </summary>
@ -206,6 +190,13 @@ public partial struct Rgba64 : IPixel<Rgba64>, IPackedVector<ulong>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Rgba64 left, Rgba64 right) => left.PackedValue != right.PackedValue;
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Rgba64>(
PixelComponentInfo.Create<Rgba64>(4, 16, 16, 16, 16),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba64> CreatePixelOperations() => new PixelOperations();

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

@ -96,6 +96,13 @@ public partial struct RgbaVector : IPixel<RgbaVector>
/// </returns>
public static RgbaVector FromHex(string hex) => Color.ParseHex(hex).ToPixel<RgbaVector>();
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<RgbaVector>(
PixelComponentInfo.Create<RgbaVector>(4, 32, 32, 32, 32),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<RgbaVector> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs

@ -64,6 +64,13 @@ public partial struct Short2 : IPixel<Short2>, IPackedVector<uint>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Short2 left, Short2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Short2>(
PixelComponentInfo.Create<Short2>(2, 16, 16),
PixelColorType.Red | PixelColorType.Green,
PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Short2> CreatePixelOperations() => new PixelOperations();

7
src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs

@ -66,6 +66,13 @@ public partial struct Short4 : IPixel<Short4>, IPackedVector<ulong>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Short4 left, Short4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<Short4>(
PixelComponentInfo.Create<Short4>(4, 16, 16, 16, 16),
PixelColorType.RGB | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Short4> CreatePixelOperations() => new PixelOperations();

4
src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs

@ -5,7 +5,6 @@ using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.PixelFormats;
@ -18,7 +17,6 @@ namespace SixLabors.ImageSharp.PixelFormats;
public partial class PixelOperations<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
private static readonly Lazy<PixelTypeInfo> LazyInfo = new(() => PixelTypeInfo.Create<TPixel>(), true);
private static readonly Lazy<PixelOperations<TPixel>> LazyInstance = new(() => default(TPixel).CreatePixelOperations(), true);
/// <summary>
@ -32,7 +30,7 @@ public partial class PixelOperations<TPixel>
/// Gets the pixel type info for the given <typeparamref name="TPixel"/>.
/// </summary>
/// <returns>The <see cref="PixelTypeInfo"/>.</returns>
public virtual PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
public PixelTypeInfo GetPixelTypeInfo() => TPixel.GetPixelTypeInfo();
/// <summary>
/// Bulk version of <see cref="IPixel.FromVector4"/> converting 'sourceVectors.Length' pixels into 'destinationColors'.

62
src/ImageSharp/PixelFormats/PixelTypeInfo.cs

@ -0,0 +1,62 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
// TODO: Review this type as it's used to represent 2 different things.
// 1. The encoded image pixel format.
// 2. The pixel format of the decoded image.
// Only the bits per pixel is used by the decoder, we should make it a property of the image metadata.
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Contains information about the pixels that make up an images visual data.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="PixelTypeInfo"/> struct.
/// </remarks>
/// <param name="bitsPerPixel">Color depth, in number of bits per pixel.</param>
public readonly struct PixelTypeInfo(int bitsPerPixel)
{
/// <summary>
/// Gets color depth, in number of bits per pixel.
/// </summary>
public int BitsPerPixel { get; init; } = bitsPerPixel;
/// <summary>
/// Gets the component bit depth and padding within the pixel.
/// </summary>
public PixelComponentInfo? ComponentInfo { get; init; }
/// <summary>
/// Gets the pixel color type.
/// </summary>
public PixelColorType? ColorType { get; init; }
/// <summary>
/// Gets the pixel alpha transparency behavior.
/// <see langword="null"/> means unknown, unspecified.
/// </summary>
public PixelAlphaRepresentation? AlphaRepresentation { get; init; }
/// <summary>
/// Creates a new <see cref="PixelTypeInfo"/> instance.
/// </summary>
/// <typeparam name="TPixel">The type of pixel format.</typeparam>
/// <param name="info">The pixel component info.</param>
/// <param name="colorType">The pixel color type.</param>
/// <param name="alphaRepresentation">The pixel alpha representation.</param>
/// <returns>The <see cref="PixelComponentInfo"/>.</returns>
public static PixelTypeInfo Create<TPixel>(
PixelComponentInfo info,
PixelColorType colorType,
PixelAlphaRepresentation alphaRepresentation)
where TPixel : unmanaged, IPixel<TPixel>
=> new()
{
BitsPerPixel = Unsafe.SizeOf<TPixel>() * 8,
ComponentInfo = info,
ColorType = colorType,
AlphaRepresentation = alphaRepresentation
};
}

2
src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters;
internal class LomographProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
private static readonly Color VeryDarkGreen = Color.FromRgba(0, 10, 0, 255);
private static readonly Color VeryDarkGreen = Color.FromPixel(new Rgba32(0, 10, 0, 255));
private readonly LomographProcessor definition;
/// <summary>

4
src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs

@ -12,8 +12,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters;
internal class PolaroidProcessor<TPixel> : FilterProcessor<TPixel>
where TPixel : unmanaged, IPixel<TPixel>
{
private static readonly Color LightOrange = Color.FromRgba(255, 153, 102, 128);
private static readonly Color VeryDarkOrange = Color.FromRgb(102, 34, 0);
private static readonly Color LightOrange = Color.FromPixel(new Rgba32(255, 153, 102, 128));
private static readonly Color VeryDarkOrange = Color.FromPixel(new Rgb24(102, 34, 0));
private readonly PolaroidProcessor definition;
/// <summary>

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

@ -197,7 +197,7 @@ internal class ResizeProcessor<TPixel> : TransformProcessor<TPixel>, IResampling
bool compand,
bool premultiplyAlpha)
{
PixelAlphaRepresentation? alphaRepresentation = PixelOperations<TPixel>.Instance.GetPixelTypeInfo()?.AlphaRepresentation;
PixelAlphaRepresentation? alphaRepresentation = PixelOperations<TPixel>.Instance.GetPixelTypeInfo().AlphaRepresentation;
// Premultiply only if alpha representation is unknown or Unassociated:
bool needsPremultiplication = alphaRepresentation == null || alphaRepresentation.Value == PixelAlphaRepresentation.Unassociated;

2
tests/ImageSharp.Benchmarks/General/GetSetPixel.cs

@ -21,7 +21,7 @@ public class GetSetPixel
public Rgba32 GetSetImageSharp()
{
using Image<Rgba32> image = new(400, 400);
image[200, 200] = Color.White;
image[200, 200] = Color.White.ToPixel<Rgba32>();
return image[200, 200];
}
}

2
tests/ImageSharp.Benchmarks/Processing/BokehBlur.cs

@ -13,7 +13,7 @@ public class BokehBlur
[Benchmark]
public void Blur()
{
using Image<Rgba32> image = new(Configuration.Default, 400, 400, Color.White);
using Image<Rgba32> image = new(Configuration.Default, 400, 400, Color.White.ToPixel<Rgba32>());
image.Mutate(c => c.BokehBlur());
}
}

4
tests/ImageSharp.Benchmarks/Processing/Diffuse.cs

@ -13,7 +13,7 @@ public class Diffuse
[Benchmark]
public Size DoDiffuse()
{
using Image<Rgba32> image = new(Configuration.Default, 800, 800, Color.BlanchedAlmond);
using Image<Rgba32> image = new(Configuration.Default, 800, 800, Color.BlanchedAlmond.ToPixel<Rgba32>());
image.Mutate(x => x.Dither(KnownDitherings.FloydSteinberg));
return image.Size;
@ -22,7 +22,7 @@ public class Diffuse
[Benchmark]
public Size DoDither()
{
using Image<Rgba32> image = new(Configuration.Default, 800, 800, Color.BlanchedAlmond);
using Image<Rgba32> image = new(Configuration.Default, 800, 800, Color.BlanchedAlmond.ToPixel<Rgba32>());
image.Mutate(x => x.Dither());
return image.Size;

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

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

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

@ -13,7 +13,7 @@ public class Rotate
[Benchmark]
public Size DoRotate()
{
using Image<Rgba32> image = new(Configuration.Default, 400, 400, Color.BlanchedAlmond);
using Image<Rgba32> image = new(Configuration.Default, 400, 400, Color.BlanchedAlmond.ToPixel<Rgba32>());
image.Mutate(x => x.Rotate(37.5F));
return image.Size;

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

@ -13,7 +13,7 @@ public class Skew
[Benchmark]
public Size DoSkew()
{
using Image<Rgba32> image = new(Configuration.Default, 400, 400, Color.BlanchedAlmond);
using Image<Rgba32> image = new(Configuration.Default, 400, 400, Color.BlanchedAlmond.ToPixel<Rgba32>());
image.Mutate(x => x.Skew(20, 10));
return image.Size;

28
tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs

@ -12,10 +12,10 @@ public partial class ColorTests
[Fact]
public void Rgba64()
{
var source = new Rgba64(100, 2222, 3333, 4444);
Rgba64 source = new(100, 2222, 3333, 4444);
// Act:
Color color = source;
Color color = Color.FromPixel(source);
// Assert:
Rgba64 data = color.ToPixel<Rgba64>();
@ -25,10 +25,10 @@ public partial class ColorTests
[Fact]
public void Rgba32()
{
var source = new Rgba32(1, 22, 33, 231);
Rgba32 source = new(1, 22, 33, 231);
// Act:
Color color = source;
Color color = Color.FromPixel(source);
// Assert:
Rgba32 data = color.ToPixel<Rgba32>();
@ -38,10 +38,10 @@ public partial class ColorTests
[Fact]
public void Argb32()
{
var source = new Argb32(1, 22, 33, 231);
Argb32 source = new(1, 22, 33, 231);
// Act:
Color color = source;
Color color = Color.FromPixel(source);
// Assert:
Argb32 data = color.ToPixel<Argb32>();
@ -51,10 +51,10 @@ public partial class ColorTests
[Fact]
public void Bgra32()
{
var source = new Bgra32(1, 22, 33, 231);
Bgra32 source = new(1, 22, 33, 231);
// Act:
Color color = source;
Color color = Color.FromPixel(source);
// Assert:
Bgra32 data = color.ToPixel<Bgra32>();
@ -64,10 +64,10 @@ public partial class ColorTests
[Fact]
public void Abgr32()
{
var source = new Abgr32(1, 22, 33, 231);
Abgr32 source = new(1, 22, 33, 231);
// Act:
Color color = source;
Color color = Color.FromPixel(source);
// Assert:
Abgr32 data = color.ToPixel<Abgr32>();
@ -77,10 +77,10 @@ public partial class ColorTests
[Fact]
public void Rgb24()
{
var source = new Rgb24(1, 22, 231);
Rgb24 source = new(1, 22, 231);
// Act:
Color color = source;
Color color = Color.FromPixel(source);
// Assert:
Rgb24 data = color.ToPixel<Rgb24>();
@ -90,10 +90,10 @@ public partial class ColorTests
[Fact]
public void Bgr24()
{
var source = new Bgr24(1, 22, 231);
Bgr24 source = new(1, 22, 231);
// Act:
Color color = source;
Color color = Color.FromPixel(source);
// Assert:
Bgr24 data = color.ToPixel<Bgr24>();

32
tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs

@ -16,10 +16,10 @@ public partial class ColorTests
var source = new Rgba64(100, 2222, 3333, 4444);
// Act:
var color = new Color(source);
var color = Color.FromPixel(source);
// Assert:
Rgba64 data = color;
Rgba64 data = color.ToPixel<Rgba64>();
Assert.Equal(source, data);
}
@ -29,10 +29,10 @@ public partial class ColorTests
var source = new Rgba32(1, 22, 33, 231);
// Act:
var color = new Color(source);
var color = Color.FromPixel(source);
// Assert:
Rgba32 data = color;
Rgba32 data = color.ToPixel<Rgba32>();
Assert.Equal(source, data);
}
@ -42,10 +42,10 @@ public partial class ColorTests
var source = new Argb32(1, 22, 33, 231);
// Act:
var color = new Color(source);
var color = Color.FromPixel(source);
// Assert:
Argb32 data = color;
Argb32 data = color.ToPixel<Argb32>();
Assert.Equal(source, data);
}
@ -55,10 +55,10 @@ public partial class ColorTests
var source = new Bgra32(1, 22, 33, 231);
// Act:
var color = new Color(source);
var color = Color.FromPixel(source);
// Assert:
Bgra32 data = color;
Bgra32 data = color.ToPixel<Bgra32>();
Assert.Equal(source, data);
}
@ -68,10 +68,10 @@ public partial class ColorTests
var source = new Abgr32(1, 22, 33, 231);
// Act:
var color = new Color(source);
var color = Color.FromPixel(source);
// Assert:
Abgr32 data = color;
Abgr32 data = color.ToPixel<Abgr32>();
Assert.Equal(source, data);
}
@ -81,10 +81,10 @@ public partial class ColorTests
var source = new Rgb24(1, 22, 231);
// Act:
var color = new Color(source);
var color = Color.FromPixel(source);
// Assert:
Rgb24 data = color;
Rgb24 data = color.ToPixel<Rgb24>();
Assert.Equal(source, data);
}
@ -94,10 +94,10 @@ public partial class ColorTests
var source = new Bgr24(1, 22, 231);
// Act:
var color = new Color(source);
var color = Color.FromPixel(source);
// Assert:
Bgr24 data = color;
Bgr24 data = color.ToPixel<Bgr24>();
Assert.Equal(source, data);
}
@ -105,7 +105,7 @@ public partial class ColorTests
public void Vector4Constructor()
{
// Act:
Color color = new(Vector4.One);
Color color = (Color)Vector4.One;
// Assert:
Assert.Equal(new RgbaVector(1, 1, 1, 1), color.ToPixel<RgbaVector>());
@ -117,7 +117,7 @@ public partial class ColorTests
[Fact]
public void GenericPixelRoundTrip()
{
AssertGenericPixelRoundTrip(new RgbaVector(float.Epsilon, 2 * float.Epsilon, float.MaxValue, float.MinValue));
AssertGenericPixelRoundTrip(new RgbaVector(0.5f, 0.75f, 1, 0));
AssertGenericPixelRoundTrip(new Rgba64(1, 2, ushort.MaxValue, ushort.MaxValue - 1));
AssertGenericPixelRoundTrip(new Rgb48(1, 2, ushort.MaxValue - 1));
AssertGenericPixelRoundTrip(new La32(1, ushort.MaxValue - 1));

28
tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs

@ -12,10 +12,10 @@ public partial class ColorTests
[Fact]
public void Rgba64()
{
var source = new Rgba64(100, 2222, 3333, 4444);
Rgba64 source = new(100, 2222, 3333, 4444);
// Act:
var color = new Color(source);
Color color = Color.FromPixel(source);
// Assert:
Rgba64 data = color.ToPixel<Rgba64>();
@ -25,10 +25,10 @@ public partial class ColorTests
[Fact]
public void Rgba32()
{
var source = new Rgba32(1, 22, 33, 231);
Rgba32 source = new(1, 22, 33, 231);
// Act:
var color = new Color(source);
Color color = Color.FromPixel(source);
// Assert:
Rgba32 data = color.ToPixel<Rgba32>();
@ -38,10 +38,10 @@ public partial class ColorTests
[Fact]
public void Argb32()
{
var source = new Argb32(1, 22, 33, 231);
Argb32 source = new(1, 22, 33, 231);
// Act:
var color = new Color(source);
Color color = Color.FromPixel(source);
// Assert:
Argb32 data = color.ToPixel<Argb32>();
@ -51,10 +51,10 @@ public partial class ColorTests
[Fact]
public void Bgra32()
{
var source = new Bgra32(1, 22, 33, 231);
Bgra32 source = new(1, 22, 33, 231);
// Act:
var color = new Color(source);
Color color = Color.FromPixel(source);
// Assert:
Bgra32 data = color.ToPixel<Bgra32>();
@ -64,10 +64,10 @@ public partial class ColorTests
[Fact]
public void Abgr32()
{
var source = new Abgr32(1, 22, 33, 231);
Abgr32 source = new(1, 22, 33, 231);
// Act:
var color = new Color(source);
Color color = Color.FromPixel(source);
// Assert:
Abgr32 data = color.ToPixel<Abgr32>();
@ -77,10 +77,10 @@ public partial class ColorTests
[Fact]
public void Rgb24()
{
var source = new Rgb24(1, 22, 231);
Rgb24 source = new(1, 22, 231);
// Act:
var color = new Color(source);
Color color = Color.FromPixel(source);
// Assert:
Rgb24 data = color.ToPixel<Rgb24>();
@ -90,10 +90,10 @@ public partial class ColorTests
[Fact]
public void Bgr24()
{
var source = new Bgr24(1, 22, 231);
Bgr24 source = new(1, 22, 231);
// Act:
var color = new Color(source);
Color color = Color.FromPixel(source);
// Assert:
Bgr24 data = color.ToPixel<Bgr24>();

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

@ -10,12 +10,12 @@ public partial class ColorTests
[Fact]
public void WithAlpha()
{
var c1 = Color.FromRgba(111, 222, 55, 255);
Color c1 = Color.FromPixel(new Rgba32(111, 222, 55, 255));
Color c2 = c1.WithAlpha(0.5f);
var expected = new Rgba32(111, 222, 55, 128);
Rgba32 expected = new(111, 222, 55, 128);
Assert.Equal(expected, (Rgba32)c2);
Assert.Equal(expected, c2.ToPixel<Rgba32>());
}
[Theory]
@ -23,13 +23,13 @@ public partial class ColorTests
[InlineData(true)]
public void Equality_WhenTrue(bool highPrecision)
{
Color c1 = new Rgba64(100, 2000, 3000, 40000);
Color c2 = new Rgba64(100, 2000, 3000, 40000);
Color c1 = Color.FromPixel(new Rgba64(100, 2000, 3000, 40000));
Color c2 = Color.FromPixel(new Rgba64(100, 2000, 3000, 40000));
if (highPrecision)
{
c1 = Color.FromPixel(c1.ToPixel<RgbaVector>());
c2 = Color.FromPixel(c2.ToPixel<RgbaVector>());
c1 = Color.FromPixel(c1.ToPixel<RgbaDouble>());
c2 = Color.FromPixel(c2.ToPixel<RgbaDouble>());
}
Assert.True(c1.Equals(c2));
@ -43,15 +43,15 @@ public partial class ColorTests
[InlineData(true)]
public void Equality_WhenFalse(bool highPrecision)
{
Color c1 = new Rgba64(100, 2000, 3000, 40000);
Color c2 = new Rgba64(101, 2000, 3000, 40000);
Color c3 = new Rgba64(100, 2000, 3000, 40001);
Color c1 = Color.FromPixel(new Rgba64(100, 2000, 3000, 40000));
Color c2 = Color.FromPixel(new Rgba64(101, 2000, 3000, 40000));
Color c3 = Color.FromPixel(new Rgba64(100, 2000, 3000, 40001));
if (highPrecision)
{
c1 = Color.FromPixel(c1.ToPixel<RgbaVector>());
c2 = Color.FromPixel(c2.ToPixel<RgbaVector>());
c3 = Color.FromPixel(c3.ToPixel<RgbaVector>());
c1 = Color.FromPixel(c1.ToPixel<RgbaDouble>());
c2 = Color.FromPixel(c2.ToPixel<RgbaDouble>());
c3 = Color.FromPixel(c3.ToPixel<RgbaDouble>());
}
Assert.False(c1.Equals(c2));
@ -74,7 +74,7 @@ public partial class ColorTests
if (highPrecision)
{
color = Color.FromPixel(color.ToPixel<RgbaVector>());
color = Color.FromPixel(color.ToPixel<RgbaDouble>());
}
string actual = color.ToHex();
@ -84,22 +84,22 @@ public partial class ColorTests
[Fact]
public void WebSafePalette_IsCorrect()
{
Rgba32[] actualPalette = Color.WebSafePalette.ToArray().Select(c => (Rgba32)c).ToArray();
Rgba32[] actualPalette = Color.WebSafePalette.ToArray().Select(c => c.ToPixel<Rgba32>()).ToArray();
for (int i = 0; i < ReferencePalette.WebSafeColors.Length; i++)
{
Assert.Equal((Rgba32)ReferencePalette.WebSafeColors[i], actualPalette[i]);
Assert.Equal(ReferencePalette.WebSafeColors[i].ToPixel<Rgba32>(), actualPalette[i]);
}
}
[Fact]
public void WernerPalette_IsCorrect()
{
Rgba32[] actualPalette = Color.WernerPalette.ToArray().Select(c => (Rgba32)c).ToArray();
Rgba32[] actualPalette = Color.WernerPalette.ToArray().Select(c => c.ToPixel<Rgba32>()).ToArray();
for (int i = 0; i < ReferencePalette.WernerColors.Length; i++)
{
Assert.Equal((Rgba32)ReferencePalette.WernerColors[i], actualPalette[i]);
Assert.Equal(ReferencePalette.WernerColors[i].ToPixel<Rgba32>(), actualPalette[i]);
}
}
@ -108,66 +108,48 @@ public partial class ColorTests
[Fact]
public void ShortHex()
{
Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)Color.ParseHex("#fff"));
Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)Color.ParseHex("fff"));
Assert.Equal(new Rgba32(0, 0, 0, 255), (Rgba32)Color.ParseHex("000f"));
Assert.Equal(new Rgb24(255, 255, 255), Color.ParseHex("#fff").ToPixel<Rgb24>());
Assert.Equal(new Rgb24(255, 255, 255), Color.ParseHex("fff").ToPixel<Rgb24>());
Assert.Equal(new Rgba32(0, 0, 0, 255), Color.ParseHex("000f").ToPixel<Rgba32>());
}
[Fact]
public void TryShortHex()
{
Assert.True(Color.TryParseHex("#fff", out Color actual));
Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)actual);
Assert.Equal(new Rgb24(255, 255, 255), actual.ToPixel<Rgb24>());
Assert.True(Color.TryParseHex("fff", out actual));
Assert.Equal(new Rgb24(255, 255, 255), (Rgb24)actual);
Assert.Equal(new Rgb24(255, 255, 255), actual.ToPixel<Rgb24>());
Assert.True(Color.TryParseHex("000f", out actual));
Assert.Equal(new Rgba32(0, 0, 0, 255), (Rgba32)actual);
Assert.Equal(new Rgba32(0, 0, 0, 255), actual.ToPixel<Rgba32>());
}
[Fact]
public void LeadingPoundIsOptional()
{
Assert.Equal(new Rgb24(0, 128, 128), (Rgb24)Color.ParseHex("#008080"));
Assert.Equal(new Rgb24(0, 128, 128), (Rgb24)Color.ParseHex("008080"));
Assert.Equal(new Rgb24(0, 128, 128), Color.ParseHex("#008080").ToPixel<Rgb24>());
Assert.Equal(new Rgb24(0, 128, 128), Color.ParseHex("008080").ToPixel<Rgb24>());
}
[Fact]
public void ThrowsOnEmpty()
{
Assert.Throws<ArgumentException>(() => Color.ParseHex(string.Empty));
}
public void ThrowsOnEmpty() => Assert.Throws<ArgumentException>(() => Color.ParseHex(string.Empty));
[Fact]
public void ThrowsOnInvalid()
{
Assert.Throws<ArgumentException>(() => Color.ParseHex("!"));
}
public void ThrowsOnInvalid() => Assert.Throws<ArgumentException>(() => Color.ParseHex("!"));
[Fact]
public void ThrowsOnNull()
{
Assert.Throws<ArgumentNullException>(() => Color.ParseHex(null));
}
public void ThrowsOnNull() => Assert.Throws<ArgumentNullException>(() => Color.ParseHex(null));
[Fact]
public void FalseOnEmpty()
{
Assert.False(Color.TryParseHex(string.Empty, out Color _));
}
public void FalseOnEmpty() => Assert.False(Color.TryParseHex(string.Empty, out Color _));
[Fact]
public void FalseOnInvalid()
{
Assert.False(Color.TryParseHex("!", out Color _));
}
public void FalseOnInvalid() => Assert.False(Color.TryParseHex("!", out Color _));
[Fact]
public void FalseOnNull()
{
Assert.False(Color.TryParseHex(null, out Color _));
}
public void FalseOnNull() => Assert.False(Color.TryParseHex(null, out Color _));
}
public class FromString
@ -177,10 +159,10 @@ public partial class ColorTests
{
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()));
Rgba32 expected = ReferencePalette.ColorNames[name].ToPixel<Rgba32>();
Assert.Equal(expected, Color.Parse(name).ToPixel<Rgba32>());
Assert.Equal(expected, Color.Parse(name.ToLowerInvariant()).ToPixel<Rgba32>());
Assert.Equal(expected, Color.Parse(expected.ToHex()).ToPixel<Rgba32>());
}
}
@ -189,53 +171,35 @@ public partial class ColorTests
{
foreach (string name in ReferencePalette.ColorNames.Keys)
{
Rgba32 expected = ReferencePalette.ColorNames[name];
Rgba32 expected = ReferencePalette.ColorNames[name].ToPixel<Rgba32>();
Assert.True(Color.TryParse(name, out Color actual));
Assert.Equal(expected, (Rgba32)actual);
Assert.Equal(expected, actual.ToPixel<Rgba32>());
Assert.True(Color.TryParse(name.ToLowerInvariant(), out actual));
Assert.Equal(expected, (Rgba32)actual);
Assert.Equal(expected, actual.ToPixel<Rgba32>());
Assert.True(Color.TryParse(expected.ToHex(), out actual));
Assert.Equal(expected, (Rgba32)actual);
Assert.Equal(expected, actual.ToPixel<Rgba32>());
}
}
[Fact]
public void ThrowsOnEmpty()
{
Assert.Throws<ArgumentException>(() => Color.Parse(string.Empty));
}
public void ThrowsOnEmpty() => Assert.Throws<ArgumentException>(() => Color.Parse(string.Empty));
[Fact]
public void ThrowsOnInvalid()
{
Assert.Throws<ArgumentException>(() => Color.Parse("!"));
}
public void ThrowsOnInvalid() => Assert.Throws<ArgumentException>(() => Color.Parse("!"));
[Fact]
public void ThrowsOnNull()
{
Assert.Throws<ArgumentNullException>(() => Color.Parse(null));
}
public void ThrowsOnNull() => Assert.Throws<ArgumentNullException>(() => Color.Parse(null));
[Fact]
public void FalseOnEmpty()
{
Assert.False(Color.TryParse(string.Empty, out Color _));
}
public void FalseOnEmpty() => Assert.False(Color.TryParse(string.Empty, out Color _));
[Fact]
public void FalseOnInvalid()
{
Assert.False(Color.TryParse("!", out Color _));
}
public void FalseOnInvalid() => Assert.False(Color.TryParse("!", out Color _));
[Fact]
public void FalseOnNull()
{
Assert.False(Color.TryParse(null, out Color _));
}
public void FalseOnNull() => Assert.False(Color.TryParse(null, out Color _));
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save