Browse Source

Introduce PixelComponentInfo + simplify Color

pull/2601/head
James Jackson-South 3 years ago
parent
commit
6b6b474892
  1. 240
      src/ImageSharp/Color/Color.Conversions.cs
  2. 288
      src/ImageSharp/Color/Color.NamedColors.cs
  3. 145
      src/ImageSharp/Color/Color.cs
  4. 4
      src/ImageSharp/Formats/AnimationUtilities.cs
  5. 10
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  6. 9
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  7. 4
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  8. 2
      src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
  9. 4
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs
  10. 4
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs
  11. 3
      src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs
  12. 2
      src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs
  13. 2
      src/ImageSharp/Formats/Webp/WebpDecoderCore.cs
  14. 2
      src/ImageSharp/ImageInfo.cs
  15. 1
      src/ImageSharp/Image{TPixel}.cs
  16. 1
      src/ImageSharp/PixelFormats/IPixel.cs
  17. 111
      src/ImageSharp/PixelFormats/PixelComponentInfo.cs
  18. 38
      src/ImageSharp/PixelFormats/PixelComponentPrecision.cs
  19. 3
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  20. 19
      src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
  21. 19
      src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
  22. 19
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
  23. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
  24. 19
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
  25. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
  26. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
  27. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
  28. 3
      src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
  29. 3
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
  30. 3
      src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
  31. 3
      src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
  32. 3
      src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
  33. 3
      src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
  34. 3
      src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
  35. 3
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
  36. 3
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
  37. 3
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
  38. 3
      src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
  39. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
  40. 19
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
  41. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
  42. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
  43. 19
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
  44. 19
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
  45. 3
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
  46. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
  47. 3
      src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
  48. 1
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
  49. 29
      src/ImageSharp/PixelFormats/PixelTypeInfo.cs
  50. 2
      src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
  51. 4
      src/ImageSharp/Processing/Processors/Filters/PolaroidProcessor{TPixel}.cs
  52. 2
      tests/ImageSharp.Benchmarks/General/GetSetPixel.cs
  53. 2
      tests/ImageSharp.Benchmarks/Processing/BokehBlur.cs
  54. 4
      tests/ImageSharp.Benchmarks/Processing/Diffuse.cs
  55. 2
      tests/ImageSharp.Benchmarks/Processing/GaussianBlur.cs
  56. 2
      tests/ImageSharp.Benchmarks/Processing/Rotate.cs
  57. 2
      tests/ImageSharp.Benchmarks/Processing/Skew.cs
  58. 28
      tests/ImageSharp.Tests/Color/ColorTests.CastFrom.cs
  59. 32
      tests/ImageSharp.Tests/Color/ColorTests.CastTo.cs
  60. 28
      tests/ImageSharp.Tests/Color/ColorTests.ConstructFrom.cs
  61. 128
      tests/ImageSharp.Tests/Color/ColorTests.cs
  62. 180
      tests/ImageSharp.Tests/Color/RgbaDouble.cs
  63. 4
      tests/ImageSharp.Tests/Drawing/DrawImageTests.cs
  64. 4
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  65. 7
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  66. 2
      tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PhotometricInterpretationTestBase.cs
  67. 20
      tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderMultiframeTests.cs
  68. 2
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs
  69. 13
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs
  70. 4
      tests/ImageSharp.Tests/Image/ImageFrameTests.cs
  71. 49
      tests/ImageSharp.Tests/Image/ImageTests.LoadPixelData.cs
  72. 16
      tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs
  73. 6
      tests/ImageSharp.Tests/Image/ImageTests.cs
  74. 2
      tests/ImageSharp.Tests/ImageInfoTests.cs
  75. 9
      tests/ImageSharp.Tests/PixelFormats/A8Tests.cs
  76. 12
      tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs
  77. 12
      tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs
  78. 11
      tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs
  79. 11
      tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs
  80. 12
      tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs
  81. 12
      tests/ImageSharp.Tests/PixelFormats/Bgra4444Tests.cs
  82. 12
      tests/ImageSharp.Tests/PixelFormats/Bgra5551Tests.cs
  83. 12
      tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs
  84. 9
      tests/ImageSharp.Tests/PixelFormats/HalfSingleTests.cs
  85. 10
      tests/ImageSharp.Tests/PixelFormats/HalfVector2Tests.cs
  86. 12
      tests/ImageSharp.Tests/PixelFormats/HalfVector4Tests.cs
  87. 9
      tests/ImageSharp.Tests/PixelFormats/L16Tests.cs
  88. 9
      tests/ImageSharp.Tests/PixelFormats/L8Tests.cs
  89. 10
      tests/ImageSharp.Tests/PixelFormats/La16Tests.cs
  90. 10
      tests/ImageSharp.Tests/PixelFormats/La32Tests.cs
  91. 10
      tests/ImageSharp.Tests/PixelFormats/NormalizedByte2Tests.cs
  92. 12
      tests/ImageSharp.Tests/PixelFormats/NormalizedByte4Tests.cs
  93. 10
      tests/ImageSharp.Tests/PixelFormats/NormalizedShort2Tests.cs
  94. 12
      tests/ImageSharp.Tests/PixelFormats/NormalizedShort4Tests.cs
  95. 42
      tests/ImageSharp.Tests/PixelFormats/PixelBlenderTests.cs
  96. 10
      tests/ImageSharp.Tests/PixelFormats/Rg32Tests.cs
  97. 11
      tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs
  98. 11
      tests/ImageSharp.Tests/PixelFormats/Rgb48Tests.cs
  99. 12
      tests/ImageSharp.Tests/PixelFormats/Rgba1010102Tests.cs
  100. 12
      tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs

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 }
};
}
}

145
src/ImageSharp/Color/Color.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp;
@ -19,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)
{
@ -53,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>
@ -77,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>
@ -108,34 +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 efficiently
if (typeof(TPixel) == typeof(Rgba64))
{
return new((Rgba64)(object)pixel);
}
else if (typeof(TPixel) == typeof(Rgb48))
{
return new((Rgb48)(object)pixel);
}
else if (typeof(TPixel) == typeof(La32))
// 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)PixelComponentPrecision.Float)
{
return new((La32)(object)pixel);
return new(pixel.ToScaledVector4());
}
else if (typeof(TPixel) == typeof(L16))
else
{
return new((L16)(object)pixel);
return new(pixel);
}
}
/// <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.MaxComponentPrecision <= PixelComponentPrecision.Byte)
if (info.ComponentInfo.HasValue && info.ComponentInfo.Value.GetMaximumComponentPrecision() <= (int)PixelComponentPrecision.Float)
{
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]);
}
}
}
@ -154,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>
@ -177,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;
}
@ -256,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 />
@ -286,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;
}
@ -305,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++)
{
@ -319,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;
@ -334,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;
}

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)

4
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;

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++)
{

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;

1
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;

1
src/ImageSharp/PixelFormats/IPixel.cs

@ -2,7 +2,6 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;

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;
}
}

38
src/ImageSharp/PixelFormats/PixelComponentPrecision.cs

@ -4,47 +4,67 @@
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Provides enumeration of the precision of individual components within a pixel format.
/// Provides enumeration of the precision in bits of individual components within a pixel format.
/// </summary>
public enum PixelComponentPrecision
{
/// <summary>
/// 8-bit signed integer.
/// </summary>
SByte,
SByte = sizeof(sbyte) * 8,
/// <summary>
/// 8-bit unsigned integer.
/// </summary>
Byte,
Byte = sizeof(byte) * 8,
/// <summary>
/// 16-bit signed integer.
/// </summary>
Short,
Short = sizeof(short) * 8,
/// <summary>
/// 16-bit unsigned integer.
/// </summary>
UShort,
UShort = sizeof(ushort) * 8,
/// <summary>
/// 32-bit signed integer.
/// </summary>
Int,
Int = sizeof(int) * 8,
/// <summary>
/// 32-bit unsigned integer.
/// </summary>
UInt,
UInt = sizeof(uint) * 8,
/// <summary>
/// 64-bit signed integer.
/// </summary>
Long = sizeof(long) * 8,
/// <summary>
/// 64-bit unsigned integer.
/// </summary>
ULong = sizeof(ulong) * 8,
/// <summary>
/// 16-bit floating point.
/// </summary>
Half,
Half = (sizeof(float) * 8) / 2,
/// <summary>
/// 32-bit floating point.
/// </summary>
Float
Float = sizeof(float) * 8,
/// <summary>
/// 64-bit floating point.
/// </summary>
Double = sizeof(double) * 8,
/// <summary>
/// 128-bit floating point.
/// </summary>
Decimal = sizeof(decimal) * 8,
}

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -57,7 +56,7 @@ public partial struct A8 : IPixel<A8>, IPackedVector<byte>
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
/// <inheritdoc/>
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<A8>(1, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<A8>(PixelComponentInfo.Create<A8>(1, 8), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<A8> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -146,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>
@ -185,7 +168,7 @@ public partial struct Abgr32 : IPixel<Abgr32>, IPackedVector<uint>
public static bool operator !=(Abgr32 left, Abgr32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Abgr32>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Abgr32>(PixelComponentInfo.Create<Abgr32>(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Abgr32> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -146,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>
@ -185,7 +168,7 @@ public partial struct Argb32 : IPixel<Argb32>, IPackedVector<uint>
public static bool operator !=(Argb32 left, Argb32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Argb32>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Argb32>(PixelComponentInfo.Create<Argb32>(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Argb32> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -50,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>
@ -89,7 +72,7 @@ public partial struct Bgr24 : IPixel<Bgr24>
public static bool operator !=(Bgr24 left, Bgr24 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr24>(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr24>(PixelComponentInfo.Create<Bgr24>(3, 8, 8, 8), PixelAlphaRepresentation.None);
/// <inheritdoc/>
public readonly PixelOperations<Bgr24> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -61,7 +60,7 @@ public partial struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort>
public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr565>(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgr565>(PixelComponentInfo.Create<Bgr565>(3, 5, 6, 5), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Bgr565> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -99,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>
@ -138,7 +121,7 @@ public partial struct Bgra32 : IPixel<Bgra32>, IPackedVector<uint>
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra32>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra32>(PixelComponentInfo.Create<Bgra32>(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<Bgra32> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -59,7 +58,7 @@ public partial struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort>
public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra4444>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra4444>(PixelComponentInfo.Create<Bgra4444>(4, 4, 4, 4, 4), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Bgra4444> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -62,7 +61,7 @@ public partial struct Bgra5551 : IPixel<Bgra5551>, IPackedVector<ushort>
public static bool operator !=(Bgra5551 left, Bgra5551 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra5551>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Bgra5551>(PixelComponentInfo.Create<Bgra5551>(4, 5, 5, 5, 1), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Bgra5551> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -62,7 +61,7 @@ public partial struct Byte4 : IPixel<Byte4>, IPackedVector<uint>
public static bool operator !=(Byte4 left, Byte4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Byte4>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Byte4>(PixelComponentInfo.Create<Byte4>(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Byte4> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -47,7 +46,7 @@ public partial struct HalfSingle : IPixel<HalfSingle>, IPackedVector<ushort>
public static bool operator !=(HalfSingle left, HalfSingle right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfSingle>(1, PixelComponentPrecision.Half, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfSingle>(PixelComponentInfo.Create<HalfSingle>(1, 16), PixelAlphaRepresentation.None);
/// <inheritdoc />
public PixelOperations<HalfSingle> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -54,7 +53,7 @@ public partial struct HalfVector2 : IPixel<HalfVector2>, IPackedVector<uint>
public static bool operator !=(HalfVector2 left, HalfVector2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector2>(2, PixelComponentPrecision.Half, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector2>(PixelComponentInfo.Create<HalfVector2>(2, 16, 16), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<HalfVector2> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -59,7 +58,7 @@ public partial struct HalfVector4 : IPixel<HalfVector4>, IPackedVector<ulong>
public static bool operator !=(HalfVector4 left, HalfVector4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector4>(4, PixelComponentPrecision.Half, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<HalfVector4>(PixelComponentInfo.Create<HalfVector4>(4, 16, 16, 16, 16), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<HalfVector4> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -49,7 +48,7 @@ public partial struct L16 : IPixel<L16>, IPackedVector<ushort>
public static bool operator !=(L16 left, L16 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L16>(1, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L16>(PixelComponentInfo.Create<L16>(1, 16), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<L16> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -50,7 +49,7 @@ public partial struct L8 : IPixel<L8>, IPackedVector<byte>
public static bool operator !=(L8 left, L8 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L8>(1, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<L8>(PixelComponentInfo.Create<L8>(1, 8), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<L8> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -73,7 +72,7 @@ public partial struct La16 : IPixel<La16>, IPackedVector<ushort>
public static bool operator !=(La16 left, La16 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La16>(2, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La16>(PixelComponentInfo.Create<La16>(2, 8, 8), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<La16> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -75,7 +74,7 @@ public partial struct La32 : IPixel<La32>, IPackedVector<uint>
public static bool operator !=(La32 left, La32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La32>(2, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<La32>(PixelComponentInfo.Create<La32>(2, 16, 16), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>
public readonly PixelOperations<La32> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -62,7 +61,7 @@ public partial struct NormalizedByte2 : IPixel<NormalizedByte2>, IPackedVector<u
public static bool operator !=(NormalizedByte2 left, NormalizedByte2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte2>(2, PixelComponentPrecision.SByte, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte2>(PixelComponentInfo.Create<NormalizedByte2>(2, 8, 8), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte2> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -64,7 +63,7 @@ public partial struct NormalizedByte4 : IPixel<NormalizedByte4>, IPackedVector<u
public static bool operator !=(NormalizedByte4 left, NormalizedByte4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte4>(4, PixelComponentPrecision.SByte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedByte4>(PixelComponentInfo.Create<NormalizedByte4>(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<NormalizedByte4> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -63,7 +62,7 @@ public partial struct NormalizedShort2 : IPixel<NormalizedShort2>, IPackedVector
public static bool operator !=(NormalizedShort2 left, NormalizedShort2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort2>(2, PixelComponentPrecision.Short, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort2>(PixelComponentInfo.Create<NormalizedShort2>(2, 16, 16), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort2> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -65,7 +64,7 @@ public partial struct NormalizedShort4 : IPixel<NormalizedShort4>, IPackedVector
public static bool operator !=(NormalizedShort4 left, NormalizedShort4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort4>(4, PixelComponentPrecision.Short, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<NormalizedShort4>(PixelComponentInfo.Create<NormalizedShort4>(4, 16, 16, 16, 16), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<NormalizedShort4> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -59,7 +58,7 @@ public partial struct Rg32 : IPixel<Rg32>, IPackedVector<uint>
public static bool operator !=(Rg32 left, Rg32 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rg32>(2, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rg32>(PixelComponentInfo.Create<Rg32>(2, 16, 16), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Rg32> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -53,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"/>.
@ -108,7 +91,7 @@ public partial struct Rgb24 : IPixel<Rgb24>
public static bool operator !=(Rgb24 left, Rgb24 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb24>(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb24>(PixelComponentInfo.Create<Rgb24>(3, 8, 8, 8), PixelAlphaRepresentation.None);
/// <inheritdoc/>
public readonly PixelOperations<Rgb24> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -71,7 +70,7 @@ public partial struct Rgb48 : IPixel<Rgb48>
public static bool operator !=(Rgb48 left, Rgb48 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb48>(3, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgb48>(PixelComponentInfo.Create<Rgb48>(3, 16, 16, 16), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Rgb48> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -62,7 +61,7 @@ public partial struct Rgba1010102 : IPixel<Rgba1010102>, IPackedVector<uint>
public static bool operator !=(Rgba1010102 left, Rgba1010102 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba1010102>(4, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba1010102>(PixelComponentInfo.Create<Rgba1010102>(4, 10, 10, 10, 2), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba1010102> CreatePixelOperations() => new PixelOperations();

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

@ -6,7 +6,6 @@ using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -175,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"/>.
@ -288,7 +271,7 @@ public partial struct Rgba32 : IPixel<Rgba32>, IPackedVector<uint>
}
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba32>(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba32>(PixelComponentInfo.Create<Rgba32>(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba32> CreatePixelOperations() => new PixelOperations();

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

@ -4,7 +4,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -169,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>
@ -208,7 +191,7 @@ public partial struct Rgba64 : IPixel<Rgba64>, IPackedVector<ulong>
public static bool operator !=(Rgba64 left, Rgba64 right) => left.PackedValue != right.PackedValue;
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba64>(4, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Rgba64>(PixelComponentInfo.Create<Rgba64>(4, 16, 16, 16, 16), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Rgba64> CreatePixelOperations() => new PixelOperations();

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

@ -5,7 +5,6 @@ using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -98,7 +97,7 @@ public partial struct RgbaVector : IPixel<RgbaVector>
public static RgbaVector FromHex(string hex) => Color.ParseHex(hex).ToPixel<RgbaVector>();
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<RgbaVector>(4, PixelComponentPrecision.Float, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<RgbaVector>(PixelComponentInfo.Create<RgbaVector>(4, 32, 32, 32, 32), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<RgbaVector> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -66,7 +65,7 @@ public partial struct Short2 : IPixel<Short2>, IPackedVector<uint>
public static bool operator !=(Short2 left, Short2 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short2>(2, PixelComponentPrecision.Short, PixelAlphaRepresentation.None);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short2>(PixelComponentInfo.Create<Short2>(2, 16, 16), PixelAlphaRepresentation.None);
/// <inheritdoc />
public readonly PixelOperations<Short2> CreatePixelOperations() => new PixelOperations();

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
@ -68,7 +67,7 @@ public partial struct Short4 : IPixel<Short4>, IPackedVector<ulong>
public static bool operator !=(Short4 left, Short4 right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short4>(4, PixelComponentPrecision.Short, PixelAlphaRepresentation.Unassociated);
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<Short4>(PixelComponentInfo.Create<Short4>(4, 16, 16, 16, 16), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<Short4> CreatePixelOperations() => new PixelOperations();

1
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;

29
src/ImageSharp/Formats/PixelTypeInfo.cs → src/ImageSharp/PixelFormats/PixelTypeInfo.cs

@ -2,12 +2,11 @@
// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
// 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.
namespace SixLabors.ImageSharp.Formats;
namespace SixLabors.ImageSharp.PixelFormats;
/// <summary>
/// Contains information about the pixels that make up an images visual data.
@ -23,15 +22,10 @@ public readonly struct PixelTypeInfo(int bitsPerPixel)
/// </summary>
public int BitsPerPixel { get; init; } = bitsPerPixel;
/// <summary>
/// Gets the count of the color components
/// </summary>
public int ComponentCount { get; init; }
/// <summary>
/// Gets the maximum precision of components within the pixel.
/// </summary>
public PixelComponentPrecision? MaxComponentPrecision { get; init; }
public PixelComponentInfo? ComponentInfo { get; init; }
/// <summary>
/// Gets the pixel alpha transparency behavior.
@ -39,16 +33,21 @@ public readonly struct PixelTypeInfo(int bitsPerPixel)
/// </summary>
public PixelAlphaRepresentation? AlphaRepresentation { get; init; }
internal static PixelTypeInfo Create<TPixel>(
byte componentCount,
PixelComponentPrecision componentPrecision,
PixelAlphaRepresentation pixelAlphaRepresentation)
/// <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="alphaRepresentation">The pixel alpha representation.</param>
/// <returns>The <see cref="PixelComponentInfo"/>.</returns>
public static PixelTypeInfo Create<TPixel>(
PixelComponentInfo info,
PixelAlphaRepresentation alphaRepresentation)
where TPixel : unmanaged, IPixel<TPixel>
=> new()
{
BitsPerPixel = Unsafe.SizeOf<TPixel>() * 8,
ComponentCount = componentCount,
MaxComponentPrecision = componentPrecision,
AlphaRepresentation = pixelAlphaRepresentation
ComponentInfo = info,
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
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 _));
}
}

180
tests/ImageSharp.Tests/Color/RgbaDouble.cs

@ -0,0 +1,180 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests;
/// <summary>
/// Unpacked pixel type containing four 64-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// <para>
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
/// </para>
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
/// </remarks>
/// <remarks>
/// Initializes a new instance of the <see cref="RgbaDouble"/> struct.
/// </remarks>
/// <param name="r">The red component.</param>
/// <param name="g">The green component.</param>
/// <param name="b">The blue component.</param>
/// <param name="a">The alpha component.</param>
[StructLayout(LayoutKind.Sequential)]
[method: MethodImpl(InliningOptions.ShortMethod)]
public partial struct RgbaDouble(double r, double g, double b, double a = 1) : IPixel<RgbaDouble>
{
/// <summary>
/// Gets or sets the red component.
/// </summary>
public double R = r;
/// <summary>
/// Gets or sets the green component.
/// </summary>
public double G = g;
/// <summary>
/// Gets or sets the blue component.
/// </summary>
public double B = b;
/// <summary>
/// Gets or sets the alpha component.
/// </summary>
public double A = a;
private const float MaxBytes = byte.MaxValue;
private static readonly Vector4 Max = new(MaxBytes);
private static readonly Vector4 Half = new(0.5F);
/// <summary>
/// Compares two <see cref="RgbaDouble"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="RgbaDouble"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="RgbaDouble"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator ==(RgbaDouble left, RgbaDouble right) => left.Equals(right);
/// <summary>
/// Compares two <see cref="RgbaDouble"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="RgbaDouble"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="RgbaDouble"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(RgbaDouble left, RgbaDouble right) => !left.Equals(right);
/// <inheritdoc />
public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create<RgbaDouble>(PixelComponentInfo.Create<RgbaDouble>(4, 64, 64, 64, 64), PixelAlphaRepresentation.Unassociated);
/// <inheritdoc />
public readonly PixelOperations<RgbaDouble> CreatePixelOperations() => new();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromScaledVector4(Vector4 vector) => this.FromVector4(vector);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToScaledVector4() => this.ToVector4();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromVector4(Vector4 vector)
{
vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One);
this.R = vector.X;
this.G = vector.Y;
this.B = vector.Z;
this.A = vector.W;
}
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public readonly Vector4 ToVector4() => new((float)this.R, (float)this.G, (float)this.B, (float)this.A);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromAbgr32(Abgr32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL8(L8 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromL16(L16 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa16(La16 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromLa32(La32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb48(Rgb48 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4());
/// <inheritdoc/>
public override readonly bool Equals(object obj) => obj is RgbaDouble other && this.Equals(other);
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public readonly bool Equals(RgbaDouble other) =>
this.R.Equals(other.R)
&& this.G.Equals(other.G)
&& this.B.Equals(other.B)
&& this.A.Equals(other.A);
/// <inheritdoc/>
public override readonly string ToString() => FormattableString.Invariant($"RgbaDouble({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##}, {this.A:#0.##})");
/// <inheritdoc/>
public override readonly int GetHashCode() => HashCode.Combine(this.R, this.G, this.B, this.A);
}

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

@ -119,7 +119,7 @@ public class DrawImageTests
public void WorksWithDifferentLocations(TestImageProvider<Rgba32> provider, int x, int y)
{
using Image<Rgba32> background = provider.GetImage();
using Image<Rgba32> overlay = new(50, 50, Color.Black.ToRgba32());
using Image<Rgba32> overlay = new(50, 50, Color.Black.ToPixel<Rgba32>());
background.Mutate(c => c.DrawImage(overlay, new Point(x, y), PixelColorBlendingMode.Normal, 1F));
@ -144,7 +144,7 @@ public class DrawImageTests
public void WorksWithDifferentBounds(TestImageProvider<Rgba32> provider, int width, int height)
{
using Image<Rgba32> background = provider.GetImage();
using Image<Rgba32> overlay = new(50, 50, Color.Black.ToRgba32());
using Image<Rgba32> overlay = new(50, 50, Color.Black.ToPixel<Rgba32>());
background.Mutate(c => c.DrawImage(overlay, new Rectangle(0, 0, width, height), PixelColorBlendingMode.Normal, 1F));

4
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -581,7 +581,7 @@ public partial class PngDecoderTests
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
PngMetadata metadata = image.Metadata.GetPngMetadata();
Assert.NotNull(metadata.ColorTable);
Assert.Contains(metadata.ColorTable.Value.ToArray(), x => x.ToRgba32().A < 255);
Assert.Contains(metadata.ColorTable.Value.ToArray(), x => x.ToPixel<Rgba32>().A < 255);
}
// https://github.com/SixLabors/ImageSharp/issues/2209
@ -594,7 +594,7 @@ public partial class PngDecoderTests
ImageInfo imageInfo = Image.Identify(stream);
PngMetadata metadata = imageInfo.Metadata.GetPngMetadata();
Assert.NotNull(metadata.ColorTable);
Assert.Contains(metadata.ColorTable.Value.ToArray(), x => x.ToRgba32().A < 255);
Assert.Contains(metadata.ColorTable.Value.ToArray(), x => x.ToPixel<Rgba32>().A < 255);
}
// https://github.com/SixLabors/ImageSharp/issues/410

7
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -391,7 +391,7 @@ public partial class PngEncoderTests
TransparentColorMode = PngTransparentColorMode.Clear,
ColorType = colorType
};
Rgba32 rgba32 = Color.Blue;
Rgba32 rgba32 = Color.Blue.ToPixel<Rgba32>();
image.ProcessPixelRows(accessor =>
{
for (int y = 0; y < image.Height; y++)
@ -418,7 +418,7 @@ public partial class PngEncoderTests
// assert
memStream.Position = 0;
using Image<Rgba32> actual = Image.Load<Rgba32>(memStream);
Rgba32 expectedColor = Color.Blue;
Rgba32 expectedColor = Color.Blue.ToPixel<Rgba32>();
if (colorType is PngColorType.Grayscale or PngColorType.GrayscaleWithAlpha)
{
byte luminance = ColorNumerics.Get8BitBT709Luminance(expectedColor.R, expectedColor.G, expectedColor.B);
@ -427,13 +427,14 @@ public partial class PngEncoderTests
actual.ProcessPixelRows(accessor =>
{
Rgba32 transparent = Color.Transparent.ToPixel<Rgba32>();
for (int y = 0; y < accessor.Height; y++)
{
Span<Rgba32> rowSpan = accessor.GetRowSpan(y);
if (y > 25)
{
expectedColor = Color.Transparent;
expectedColor = transparent;
}
for (int x = 0; x < accessor.Width; x++)

2
tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/PhotometricInterpretationTestBase.cs

@ -47,7 +47,7 @@ public abstract class PhotometricInterpretationTestBase
using (var image = new Image<Rgba32>(resultWidth, resultHeight))
{
image.Mutate(x => x.BackgroundColor(DefaultColor));
image.Mutate(x => x.BackgroundColor(Color.FromPixel(DefaultColor)));
Buffer2D<Rgba32> pixels = image.GetRootFramePixelBuffer();
decodeAction(pixels);

20
tests/ImageSharp.Tests/Formats/Tiff/TiffEncoderMultiframeTests.cs

@ -70,9 +70,9 @@ public class TiffEncoderMultiframeTests : TiffEncoderBaseTester
using Image<TPixel> image = provider.GetImage();
Assert.Equal(1, image.Frames.Count);
using var image1 = new Image<Rgba32>(image.Width, image.Height, Color.Green.ToRgba32());
using var image1 = new Image<Rgba32>(image.Width, image.Height, Color.Green.ToPixel<Rgba32>());
using var image2 = new Image<Rgba32>(image.Width, image.Height, Color.Yellow.ToRgba32());
using var image2 = new Image<Rgba32>(image.Width, image.Height, Color.Yellow.ToPixel<Rgba32>());
image.Frames.AddFrame(image1.Frames.RootFrame);
image.Frames.AddFrame(image2.Frames.RootFrame);
@ -97,8 +97,8 @@ public class TiffEncoderMultiframeTests : TiffEncoderBaseTester
ImageFrame<Rgba32> frame1 = output.Frames[1];
ImageFrame<Rgba32> frame2 = output.Frames[2];
Assert.Equal(Color.Green.ToRgba32(), frame1[10, 10]);
Assert.Equal(Color.Yellow.ToRgba32(), frame2[10, 10]);
Assert.Equal(Color.Green.ToPixel<Rgba32>(), frame1[10, 10]);
Assert.Equal(Color.Yellow.ToPixel<Rgba32>(), frame2[10, 10]);
Assert.Equal(TiffCompression.Deflate, frame1.Metadata.GetTiffMetadata().Compression);
Assert.Equal(TiffCompression.Deflate, frame1.Metadata.GetTiffMetadata().Compression);
@ -122,11 +122,11 @@ public class TiffEncoderMultiframeTests : TiffEncoderBaseTester
{
using Image<TPixel> image = provider.GetImage();
using var image0 = new Image<Rgba32>(image.Width, image.Height, Color.Red.ToRgba32());
using var image0 = new Image<Rgba32>(image.Width, image.Height, Color.Red.ToPixel<Rgba32>());
using var image1 = new Image<Rgba32>(image.Width, image.Height, Color.Green.ToRgba32());
using var image1 = new Image<Rgba32>(image.Width, image.Height, Color.Green.ToPixel<Rgba32>());
using var image2 = new Image<Rgba32>(image.Width, image.Height, Color.Yellow.ToRgba32());
using var image2 = new Image<Rgba32>(image.Width, image.Height, Color.Yellow.ToPixel<Rgba32>());
image.Frames.AddFrame(image0.Frames.RootFrame);
image.Frames.AddFrame(image1.Frames.RootFrame);
@ -154,9 +154,9 @@ public class TiffEncoderMultiframeTests : TiffEncoderBaseTester
ImageFrame<Rgba32> frame1 = output.Frames[1];
ImageFrame<Rgba32> frame2 = output.Frames[2];
Assert.Equal(Color.Red.ToRgba32(), frame0[10, 10]);
Assert.Equal(Color.Green.ToRgba32(), frame1[10, 10]);
Assert.Equal(Color.Yellow.ToRgba32(), frame2[10, 10]);
Assert.Equal(Color.Red.ToPixel<Rgba32>(), frame0[10, 10]);
Assert.Equal(Color.Green.ToPixel<Rgba32>(), frame1[10, 10]);
Assert.Equal(Color.Yellow.ToPixel<Rgba32>(), frame2[10, 10]);
Assert.Equal(TiffCompression.Lzw, frame0.Metadata.GetTiffMetadata().Compression);
Assert.Equal(TiffCompression.Lzw, frame1.Metadata.GetTiffMetadata().Compression);

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

@ -237,7 +237,7 @@ public abstract partial class ImageFrameCollectionTests
using (this.Image.Frames.CreateFrame(Color.HotPink))
{
Assert.Equal(2, this.Image.Frames.Count);
this.Image.Frames[1].ComparePixelBufferTo(Color.HotPink);
this.Image.Frames[1].ComparePixelBufferTo(Color.HotPink.ToPixel<Rgba32>());
}
}

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

@ -1,7 +1,6 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.PixelFormats;
@ -23,13 +22,13 @@ public abstract partial class ImageFrameCollectionTests
this.Image.Configuration,
this.Image.Width,
this.Image.Height,
Color.Blue))
Color.Blue.ToPixel<Bgra32>()))
{
this.Collection.AddFrame(sourceImage.Frames.RootFrame);
}
Rgba32[] expectedAllBlue =
Enumerable.Repeat((Rgba32)Color.Blue, this.Image.Width * this.Image.Height).ToArray();
Enumerable.Repeat(Color.Blue.ToPixel<Rgba32>(), this.Image.Width * this.Image.Height).ToArray();
Assert.Equal(2, this.Collection.Count);
ImageFrame<Rgba32> actualFrame = (ImageFrame<Rgba32>)this.Collection[1];
@ -44,13 +43,13 @@ public abstract partial class ImageFrameCollectionTests
this.Image.Configuration,
this.Image.Width,
this.Image.Height,
Color.Blue))
Color.Blue.ToPixel<Bgra32>()))
{
this.Collection.InsertFrame(0, sourceImage.Frames.RootFrame);
}
Rgba32[] expectedAllBlue =
Enumerable.Repeat((Rgba32)Color.Blue, this.Image.Width * this.Image.Height).ToArray();
Enumerable.Repeat(Color.Blue.ToPixel<Rgba32>(), this.Image.Width * this.Image.Height).ToArray();
Assert.Equal(2, this.Collection.Count);
ImageFrame<Rgba32> actualFrame = (ImageFrame<Rgba32>)this.Collection[0];
@ -177,7 +176,7 @@ public abstract partial class ImageFrameCollectionTests
ImageFrame<Rgba32> frame = (ImageFrame<Rgba32>)this.Image.Frames[1];
frame.ComparePixelBufferTo(Color.HotPink);
frame.ComparePixelBufferTo(Color.HotPink.ToPixel<Rgba32>());
}
[Fact]
@ -279,7 +278,7 @@ public abstract partial class ImageFrameCollectionTests
{
using Image source = provider.GetImage();
using Image<TPixel> dest = new(source.Configuration, source.Width, source.Height);
// Giphy.gif has 5 frames
ImportFrameAs<Bgra32>(source.Frames, dest.Frames, 0);
ImportFrameAs<Argb32>(source.Frames, dest.Frames, 1);

4
tests/ImageSharp.Tests/Image/ImageFrameTests.cs

@ -35,9 +35,9 @@ public class ImageFrameTests
ImageFrame<Rgba32> frame = image.Frames.RootFrame;
Rgba32 val = frame[3, 4];
Assert.Equal(default(Rgba32), val);
frame[3, 4] = Color.Red;
frame[3, 4] = Color.Red.ToPixel<Rgba32>();
val = frame[3, 4];
Assert.Equal(Color.Red.ToRgba32(), val);
Assert.Equal(Color.Red.ToPixel<Rgba32>(), val);
}
public static TheoryData<bool, int> OutOfRangeData = new TheoryData<bool, int>()

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

@ -15,19 +15,17 @@ public partial class ImageTests
[ValidateDisposedMemoryAllocations]
public void FromPixels(bool useSpan)
{
Rgba32[] data = { Color.Black, Color.White, Color.White, Color.Black, };
Rgba32[] data = { Color.Black.ToPixel<Rgba32>(), Color.White.ToPixel<Rgba32>(), Color.White.ToPixel<Rgba32>(), Color.Black.ToPixel<Rgba32>(), };
using (Image<Rgba32> img = useSpan
? Image.LoadPixelData<Rgba32>(data.AsSpan(), 2, 2)
: Image.LoadPixelData<Rgba32>(data, 2, 2))
{
Assert.NotNull(img);
Assert.Equal(Color.Black, (Color)img[0, 0]);
Assert.Equal(Color.White, (Color)img[0, 1]);
using Image<Rgba32> img = useSpan
? Image.LoadPixelData<Rgba32>(data.AsSpan(), 2, 2)
: Image.LoadPixelData<Rgba32>(data, 2, 2);
Assert.NotNull(img);
Assert.Equal(Color.Black, Color.FromPixel(img[0, 0]));
Assert.Equal(Color.White, Color.FromPixel(img[0, 1]));
Assert.Equal(Color.White, (Color)img[1, 0]);
Assert.Equal(Color.Black, (Color)img[1, 1]);
}
Assert.Equal(Color.White, Color.FromPixel(img[1, 0]));
Assert.Equal(Color.Black, Color.FromPixel(img[1, 1]));
}
[Theory]
@ -36,23 +34,22 @@ public partial class ImageTests
public void FromBytes(bool useSpan)
{
byte[] data =
{
0, 0, 0, 255, // 0,0
255, 255, 255, 255, // 0,1
255, 255, 255, 255, // 1,0
0, 0, 0, 255, // 1,1
};
using (Image<Rgba32> img = useSpan
? Image.LoadPixelData<Rgba32>(data.AsSpan(), 2, 2)
: Image.LoadPixelData<Rgba32>(data, 2, 2))
{
Assert.NotNull(img);
Assert.Equal(Color.Black, (Color)img[0, 0]);
Assert.Equal(Color.White, (Color)img[0, 1]);
0, 0, 0, 255, // 0,0
255, 255, 255, 255, // 0,1
255, 255, 255, 255, // 1,0
0, 0, 0, 255, // 1,1
};
using Image<Rgba32> img = useSpan
? Image.LoadPixelData<Rgba32>(data.AsSpan(), 2, 2)
: Image.LoadPixelData<Rgba32>(data, 2, 2);
Assert.NotNull(img);
Assert.Equal(Color.Black, Color.FromPixel(img[0, 0]));
Assert.Equal(Color.White, Color.FromPixel(img[0, 1]));
Assert.Equal(Color.White, (Color)img[1, 0]);
Assert.Equal(Color.Black, (Color)img[1, 1]);
}
Assert.Equal(Color.White, Color.FromPixel(img[1, 0]));
Assert.Equal(Color.Black, Color.FromPixel(img[1, 1]));
}
}
}

16
tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs

@ -154,8 +154,8 @@ public partial class ImageTests
using (var memoryManager = new BitmapMemoryManager(bmp))
{
Memory<Bgra32> memory = memoryManager.Memory;
Bgra32 bg = Color.Red;
Bgra32 fg = Color.Green;
Bgra32 bg = Color.Red.ToPixel<Bgra32>();
Bgra32 fg = Color.Green.ToPixel<Bgra32>();
using (var image = Image.WrapMemory(memory, bmp.Width, bmp.Height))
{
@ -198,8 +198,8 @@ public partial class ImageTests
using (var bmp = new Bitmap(51, 23))
{
var memoryManager = new BitmapMemoryManager(bmp);
Bgra32 bg = Color.Red;
Bgra32 fg = Color.Green;
Bgra32 bg = Color.Red.ToPixel<Bgra32>();
Bgra32 fg = Color.Green.ToPixel<Bgra32>();
using (var image = Image.WrapMemory(memoryManager, bmp.Width, bmp.Height))
{
@ -258,8 +258,8 @@ public partial class ImageTests
{
Memory<Bgra32> pixelMemory = memoryManager.Memory;
Memory<byte> byteMemory = new CastMemoryManager<Bgra32, byte>(pixelMemory).Memory;
Bgra32 bg = Color.Red;
Bgra32 fg = Color.Green;
Bgra32 bg = Color.Red.ToPixel<Bgra32>();
Bgra32 fg = Color.Green.ToPixel<Bgra32>();
using (var image = Image.WrapMemory<Bgra32>(byteMemory, bmp.Width, bmp.Height))
{
@ -355,8 +355,8 @@ public partial class ImageTests
using (var memoryManager = new BitmapMemoryManager(bmp))
{
Memory<Bgra32> pixelMemory = memoryManager.Memory;
Bgra32 bg = Color.Red;
Bgra32 fg = Color.Green;
Bgra32 bg = Color.Red.ToPixel<Bgra32>();
Bgra32 fg = Color.Green.ToPixel<Bgra32>();
fixed (void* p = pixelMemory.Span)
{

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

@ -61,7 +61,7 @@ public partial class ImageTests
public void Configuration_Width_Height_BackgroundColor()
{
Configuration configuration = Configuration.Default.Clone();
Rgba32 color = Color.Aquamarine;
Rgba32 color = Color.Aquamarine.ToPixel<Rgba32>();
using (Image<Rgba32> image = new(configuration, 11, 23, color))
{
@ -116,9 +116,9 @@ public partial class ImageTests
using Image<Rgba32> image = new(this.configuration, 10, 10);
Rgba32 val = image[3, 4];
Assert.Equal(default(Rgba32), val);
image[3, 4] = Color.Red;
image[3, 4] = Color.Red.ToPixel<Rgba32>();
val = image[3, 4];
Assert.Equal(Color.Red.ToRgba32(), val);
Assert.Equal(Color.Red.ToPixel<Rgba32>(), val);
}
public static TheoryData<bool, int> OutOfRangeData = new()

2
tests/ImageSharp.Tests/ImageInfoTests.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.Tests;

9
tests/ImageSharp.Tests/PixelFormats/A8Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -116,8 +115,12 @@ public class A8Tests
{
PixelTypeInfo info = A8.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<A8>() * 8, info.BitsPerPixel);
Assert.Equal(1, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(1, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/Abgr32Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -151,8 +150,15 @@ public class Abgr32Tests
{
PixelTypeInfo info = Abgr32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Abgr32>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetComponentPrecision(2));
Assert.Equal(8, componentInfo.GetComponentPrecision(3));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -149,8 +148,15 @@ public class Argb32Tests
{
PixelTypeInfo info = Argb32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Argb32>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetComponentPrecision(2));
Assert.Equal(8, componentInfo.GetComponentPrecision(3));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

11
tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -134,8 +133,14 @@ public class Bgr24Tests
{
PixelTypeInfo info = Bgr24.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgr24>() * 8, info.BitsPerPixel);
Assert.Equal(3, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(3, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetComponentPrecision(2));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

11
tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -256,8 +255,14 @@ public class Bgr565Tests
{
PixelTypeInfo info = Bgr565.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgr565>() * 8, info.BitsPerPixel);
Assert.Equal(3, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(3, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(5, componentInfo.GetComponentPrecision(0));
Assert.Equal(6, componentInfo.GetComponentPrecision(1));
Assert.Equal(5, componentInfo.GetComponentPrecision(2));
Assert.Equal(6, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -151,8 +150,15 @@ public class Bgra32Tests
{
PixelTypeInfo info = Bgra32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgra32>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetComponentPrecision(2));
Assert.Equal(8, componentInfo.GetComponentPrecision(3));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/Bgra4444Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -252,8 +251,15 @@ public class Bgra4444Tests
{
PixelTypeInfo info = Bgra4444.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgra4444>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(4, componentInfo.GetComponentPrecision(0));
Assert.Equal(4, componentInfo.GetComponentPrecision(1));
Assert.Equal(4, componentInfo.GetComponentPrecision(2));
Assert.Equal(4, componentInfo.GetComponentPrecision(3));
Assert.Equal(4, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/Bgra5551Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -278,8 +277,15 @@ public class Bgra5551Tests
{
PixelTypeInfo info = Bgra5551.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Bgra5551>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(5, componentInfo.GetComponentPrecision(0));
Assert.Equal(5, componentInfo.GetComponentPrecision(1));
Assert.Equal(5, componentInfo.GetComponentPrecision(2));
Assert.Equal(1, componentInfo.GetComponentPrecision(3));
Assert.Equal(5, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs

@ -2,7 +2,6 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
@ -245,8 +244,15 @@ public class Byte4Tests
{
PixelTypeInfo info = Byte4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Byte4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetComponentPrecision(2));
Assert.Equal(8, componentInfo.GetComponentPrecision(3));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

9
tests/ImageSharp.Tests/PixelFormats/HalfSingleTests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -74,8 +73,12 @@ public class HalfSingleTests
{
PixelTypeInfo info = HalfSingle.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<HalfSingle>() * 8, info.BitsPerPixel);
Assert.Equal(1, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Half, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(1, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

10
tests/ImageSharp.Tests/PixelFormats/HalfVector2Tests.cs

@ -2,7 +2,6 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
@ -96,8 +95,13 @@ public class HalfVector2Tests
{
PixelTypeInfo info = HalfVector2.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<HalfVector2>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Half, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(2, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetComponentPrecision(1));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/HalfVector4Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -87,8 +86,15 @@ public class HalfVector4Tests
{
PixelTypeInfo info = HalfVector4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<HalfVector4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Half, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetComponentPrecision(1));
Assert.Equal(16, componentInfo.GetComponentPrecision(2));
Assert.Equal(16, componentInfo.GetComponentPrecision(3));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

9
tests/ImageSharp.Tests/PixelFormats/L16Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -166,8 +165,12 @@ public class L16Tests
{
PixelTypeInfo info = L16.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<L16>() * 8, info.BitsPerPixel);
Assert.Equal(1, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(1, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

9
tests/ImageSharp.Tests/PixelFormats/L8Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
// ReSharper disable InconsistentNaming
@ -261,9 +260,13 @@ public class L8Tests
{
PixelTypeInfo info = L8.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<L8>() * 8, info.BitsPerPixel);
Assert.Equal(1, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(1, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}
}

10
tests/ImageSharp.Tests/PixelFormats/La16Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
// ReSharper disable InconsistentNaming
@ -265,9 +264,14 @@ public class La16Tests
{
PixelTypeInfo info = La16.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<La16>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(2, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}
}

10
tests/ImageSharp.Tests/PixelFormats/La32Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -172,8 +171,13 @@ public class La32Tests
{
PixelTypeInfo info = La32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<La32>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(2, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetComponentPrecision(1));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

10
tests/ImageSharp.Tests/PixelFormats/NormalizedByte2Tests.cs

@ -2,7 +2,6 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
@ -88,8 +87,13 @@ public class NormalizedByte2Tests
{
PixelTypeInfo info = NormalizedByte2.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<NormalizedByte2>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.SByte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(2, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/NormalizedByte4Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -238,8 +237,15 @@ public class NormalizedByte4Tests
{
PixelTypeInfo info = NormalizedByte4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<NormalizedByte4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.SByte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetComponentPrecision(2));
Assert.Equal(8, componentInfo.GetComponentPrecision(3));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

10
tests/ImageSharp.Tests/PixelFormats/NormalizedShort2Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -92,8 +91,13 @@ public class NormalizedShort2Tests
{
PixelTypeInfo info = NormalizedShort2.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<NormalizedShort2>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Short, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(2, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetComponentPrecision(1));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/NormalizedShort4Tests.cs

@ -2,7 +2,6 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
@ -239,8 +238,15 @@ public class NormalizedShort4Tests
{
PixelTypeInfo info = NormalizedShort4.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<NormalizedShort4>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Short, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetComponentPrecision(1));
Assert.Equal(16, componentInfo.GetComponentPrecision(2));
Assert.Equal(16, componentInfo.GetComponentPrecision(3));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

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

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

10
tests/ImageSharp.Tests/PixelFormats/Rg32Tests.cs

@ -2,7 +2,6 @@
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
@ -90,8 +89,13 @@ public class Rg32Tests
{
PixelTypeInfo info = Rg32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rg32>() * 8, info.BitsPerPixel);
Assert.Equal(2, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(2, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetComponentPrecision(1));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

11
tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -137,8 +136,14 @@ public class Rgb24Tests
{
PixelTypeInfo info = Rgb24.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgb24>() * 8, info.BitsPerPixel);
Assert.Equal(3, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(3, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetComponentPrecision(2));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

11
tests/ImageSharp.Tests/PixelFormats/Rgb48Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -82,8 +81,14 @@ public class Rgb48Tests
{
PixelTypeInfo info = Rgb48.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgb48>() * 8, info.BitsPerPixel);
Assert.Equal(3, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(3, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(16, componentInfo.GetComponentPrecision(0));
Assert.Equal(16, componentInfo.GetComponentPrecision(1));
Assert.Equal(16, componentInfo.GetComponentPrecision(2));
Assert.Equal(16, componentInfo.GetMaximumComponentPrecision());
}
}

12
tests/ImageSharp.Tests/PixelFormats/Rgba1010102Tests.cs

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -253,8 +252,15 @@ public class Rgba1010102Tests
{
PixelTypeInfo info = Rgba1010102.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgba1010102>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.UShort, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(10, componentInfo.GetComponentPrecision(0));
Assert.Equal(10, componentInfo.GetComponentPrecision(1));
Assert.Equal(10, componentInfo.GetComponentPrecision(2));
Assert.Equal(2, componentInfo.GetComponentPrecision(3));
Assert.Equal(10, componentInfo.GetMaximumComponentPrecision());
}
}

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

@ -3,7 +3,6 @@
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.PixelFormats;
@ -313,8 +312,15 @@ public class Rgba32Tests
{
PixelTypeInfo info = Rgba32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<Rgba32>() * 8, info.BitsPerPixel);
Assert.Equal(4, info.ComponentCount);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelComponentPrecision.Byte, info.MaxComponentPrecision);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(4, componentInfo.ComponentCount);
Assert.Equal(0, componentInfo.Padding);
Assert.Equal(8, componentInfo.GetComponentPrecision(0));
Assert.Equal(8, componentInfo.GetComponentPrecision(1));
Assert.Equal(8, componentInfo.GetComponentPrecision(2));
Assert.Equal(8, componentInfo.GetComponentPrecision(3));
Assert.Equal(8, componentInfo.GetMaximumComponentPrecision());
}
}

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

Loading…
Cancel
Save