diff --git a/src/ImageSharp/Color/Color.Conversions.cs b/src/ImageSharp/Color/Color.Conversions.cs
deleted file mode 100644
index 309ab83ec4..0000000000
--- a/src/ImageSharp/Color/Color.Conversions.cs
+++ /dev/null
@@ -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;
-
-///
-/// Contains constructors and implicit conversion methods.
-///
-public readonly partial struct Color
-{
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(Rgba64 pixel)
- {
- this.data = pixel;
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(Rgb48 pixel)
- {
- this.data = new Rgba64(pixel.R, pixel.G, pixel.B, ushort.MaxValue);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(La32 pixel)
- {
- this.data = new Rgba64(pixel.L, pixel.L, pixel.L, pixel.A);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(L16 pixel)
- {
- this.data = new Rgba64(pixel.PackedValue, pixel.PackedValue, pixel.PackedValue, ushort.MaxValue);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(Rgba32 pixel)
- {
- this.data = new Rgba64(pixel);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(Argb32 pixel)
- {
- this.data = new Rgba64(pixel);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(Bgra32 pixel)
- {
- this.data = new Rgba64(pixel);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(Abgr32 pixel)
- {
- this.data = new Rgba64(pixel);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(Rgb24 pixel)
- {
- this.data = new Rgba64(pixel);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [MethodImpl(InliningOptions.ShortMethod)]
- public Color(Bgr24 pixel)
- {
- this.data = new Rgba64(pixel);
- this.boxedHighPrecisionPixel = null;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The containing the color information.
- [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;
- }
-
- ///
- /// Converts a to .
- ///
- /// The .
- /// The .
- public static explicit operator Vector4(Color color) => color.ToScaledVector4();
-
- ///
- /// Converts an to .
- ///
- /// The .
- /// The .
- [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();
- }
-}
diff --git a/src/ImageSharp/Color/Color.NamedColors.cs b/src/ImageSharp/Color/Color.NamedColors.cs
index f8b4c90fd6..00130dd904 100644
--- a/src/ImageSharp/Color/Color.NamedColors.cs
+++ b/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;
///
@@ -9,107 +11,107 @@ namespace SixLabors.ImageSharp;
///
public readonly partial struct Color
{
- private static readonly Lazy> NamedColorsLookupLazy = new Lazy>(CreateNamedColorsLookup, true);
+ private static readonly Lazy> NamedColorsLookupLazy = new(CreateNamedColorsLookup, true);
///
/// Represents a matching the W3C definition that has an hex value of #F0F8FF.
///
- public static readonly Color AliceBlue = FromRgba(240, 248, 255, 255);
+ public static readonly Color AliceBlue = FromPixel(new Rgba32(240, 248, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FAEBD7.
///
- public static readonly Color AntiqueWhite = FromRgba(250, 235, 215, 255);
+ public static readonly Color AntiqueWhite = FromPixel(new Rgba32(250, 235, 215, 255));
///
/// Represents a matching the W3C definition that has an hex value of #00FFFF.
///
- public static readonly Color Aqua = FromRgba(0, 255, 255, 255);
+ public static readonly Color Aqua = FromPixel(new Rgba32(0, 255, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #7FFFD4.
///
- public static readonly Color Aquamarine = FromRgba(127, 255, 212, 255);
+ public static readonly Color Aquamarine = FromPixel(new Rgba32(127, 255, 212, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F0FFFF.
///
- public static readonly Color Azure = FromRgba(240, 255, 255, 255);
+ public static readonly Color Azure = FromPixel(new Rgba32(240, 255, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F5F5DC.
///
- public static readonly Color Beige = FromRgba(245, 245, 220, 255);
+ public static readonly Color Beige = FromPixel(new Rgba32(245, 245, 220, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFE4C4.
///
- public static readonly Color Bisque = FromRgba(255, 228, 196, 255);
+ public static readonly Color Bisque = FromPixel(new Rgba32(255, 228, 196, 255));
///
/// Represents a matching the W3C definition that has an hex value of #000000.
///
- public static readonly Color Black = FromRgba(0, 0, 0, 255);
+ public static readonly Color Black = FromPixel(new Rgba32(0, 0, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFEBCD.
///
- public static readonly Color BlanchedAlmond = FromRgba(255, 235, 205, 255);
+ public static readonly Color BlanchedAlmond = FromPixel(new Rgba32(255, 235, 205, 255));
///
/// Represents a matching the W3C definition that has an hex value of #0000FF.
///
- public static readonly Color Blue = FromRgba(0, 0, 255, 255);
+ public static readonly Color Blue = FromPixel(new Rgba32(0, 0, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #8A2BE2.
///
- public static readonly Color BlueViolet = FromRgba(138, 43, 226, 255);
+ public static readonly Color BlueViolet = FromPixel(new Rgba32(138, 43, 226, 255));
///
/// Represents a matching the W3C definition that has an hex value of #A52A2A.
///
- public static readonly Color Brown = FromRgba(165, 42, 42, 255);
+ public static readonly Color Brown = FromPixel(new Rgba32(165, 42, 42, 255));
///
/// Represents a matching the W3C definition that has an hex value of #DEB887.
///
- public static readonly Color BurlyWood = FromRgba(222, 184, 135, 255);
+ public static readonly Color BurlyWood = FromPixel(new Rgba32(222, 184, 135, 255));
///
/// Represents a matching the W3C definition that has an hex value of #5F9EA0.
///
- public static readonly Color CadetBlue = FromRgba(95, 158, 160, 255);
+ public static readonly Color CadetBlue = FromPixel(new Rgba32(95, 158, 160, 255));
///
/// Represents a matching the W3C definition that has an hex value of #7FFF00.
///
- public static readonly Color Chartreuse = FromRgba(127, 255, 0, 255);
+ public static readonly Color Chartreuse = FromPixel(new Rgba32(127, 255, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #D2691E.
///
- public static readonly Color Chocolate = FromRgba(210, 105, 30, 255);
+ public static readonly Color Chocolate = FromPixel(new Rgba32(210, 105, 30, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF7F50.
///
- public static readonly Color Coral = FromRgba(255, 127, 80, 255);
+ public static readonly Color Coral = FromPixel(new Rgba32(255, 127, 80, 255));
///
/// Represents a matching the W3C definition that has an hex value of #6495ED.
///
- public static readonly Color CornflowerBlue = FromRgba(100, 149, 237, 255);
+ public static readonly Color CornflowerBlue = FromPixel(new Rgba32(100, 149, 237, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFF8DC.
///
- public static readonly Color Cornsilk = FromRgba(255, 248, 220, 255);
+ public static readonly Color Cornsilk = FromPixel(new Rgba32(255, 248, 220, 255));
///
/// Represents a matching the W3C definition that has an hex value of #DC143C.
///
- public static readonly Color Crimson = FromRgba(220, 20, 60, 255);
+ public static readonly Color Crimson = FromPixel(new Rgba32(220, 20, 60, 255));
///
/// Represents a matching the W3C definition that has an hex value of #00FFFF.
@@ -119,27 +121,27 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #00008B.
///
- public static readonly Color DarkBlue = FromRgba(0, 0, 139, 255);
+ public static readonly Color DarkBlue = FromPixel(new Rgba32(0, 0, 139, 255));
///
/// Represents a matching the W3C definition that has an hex value of #008B8B.
///
- public static readonly Color DarkCyan = FromRgba(0, 139, 139, 255);
+ public static readonly Color DarkCyan = FromPixel(new Rgba32(0, 139, 139, 255));
///
/// Represents a matching the W3C definition that has an hex value of #B8860B.
///
- public static readonly Color DarkGoldenrod = FromRgba(184, 134, 11, 255);
+ public static readonly Color DarkGoldenrod = FromPixel(new Rgba32(184, 134, 11, 255));
///
/// Represents a matching the W3C definition that has an hex value of #A9A9A9.
///
- public static readonly Color DarkGray = FromRgba(169, 169, 169, 255);
+ public static readonly Color DarkGray = FromPixel(new Rgba32(169, 169, 169, 255));
///
/// Represents a matching the W3C definition that has an hex value of #006400.
///
- public static readonly Color DarkGreen = FromRgba(0, 100, 0, 255);
+ public static readonly Color DarkGreen = FromPixel(new Rgba32(0, 100, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #A9A9A9.
@@ -149,52 +151,52 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #BDB76B.
///
- public static readonly Color DarkKhaki = FromRgba(189, 183, 107, 255);
+ public static readonly Color DarkKhaki = FromPixel(new Rgba32(189, 183, 107, 255));
///
/// Represents a matching the W3C definition that has an hex value of #8B008B.
///
- public static readonly Color DarkMagenta = FromRgba(139, 0, 139, 255);
+ public static readonly Color DarkMagenta = FromPixel(new Rgba32(139, 0, 139, 255));
///
/// Represents a matching the W3C definition that has an hex value of #556B2F.
///
- public static readonly Color DarkOliveGreen = FromRgba(85, 107, 47, 255);
+ public static readonly Color DarkOliveGreen = FromPixel(new Rgba32(85, 107, 47, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF8C00.
///
- public static readonly Color DarkOrange = FromRgba(255, 140, 0, 255);
+ public static readonly Color DarkOrange = FromPixel(new Rgba32(255, 140, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #9932CC.
///
- public static readonly Color DarkOrchid = FromRgba(153, 50, 204, 255);
+ public static readonly Color DarkOrchid = FromPixel(new Rgba32(153, 50, 204, 255));
///
/// Represents a matching the W3C definition that has an hex value of #8B0000.
///
- public static readonly Color DarkRed = FromRgba(139, 0, 0, 255);
+ public static readonly Color DarkRed = FromPixel(new Rgba32(139, 0, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #E9967A.
///
- public static readonly Color DarkSalmon = FromRgba(233, 150, 122, 255);
+ public static readonly Color DarkSalmon = FromPixel(new Rgba32(233, 150, 122, 255));
///
/// Represents a matching the W3C definition that has an hex value of #8FBC8F.
///
- public static readonly Color DarkSeaGreen = FromRgba(143, 188, 143, 255);
+ public static readonly Color DarkSeaGreen = FromPixel(new Rgba32(143, 188, 143, 255));
///
/// Represents a matching the W3C definition that has an hex value of #483D8B.
///
- public static readonly Color DarkSlateBlue = FromRgba(72, 61, 139, 255);
+ public static readonly Color DarkSlateBlue = FromPixel(new Rgba32(72, 61, 139, 255));
///
/// Represents a matching the W3C definition that has an hex value of #2F4F4F.
///
- public static readonly Color DarkSlateGray = FromRgba(47, 79, 79, 255);
+ public static readonly Color DarkSlateGray = FromPixel(new Rgba32(47, 79, 79, 255));
///
/// Represents a matching the W3C definition that has an hex value of #2F4F4F.
@@ -204,27 +206,27 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #00CED1.
///
- public static readonly Color DarkTurquoise = FromRgba(0, 206, 209, 255);
+ public static readonly Color DarkTurquoise = FromPixel(new Rgba32(0, 206, 209, 255));
///
/// Represents a matching the W3C definition that has an hex value of #9400D3.
///
- public static readonly Color DarkViolet = FromRgba(148, 0, 211, 255);
+ public static readonly Color DarkViolet = FromPixel(new Rgba32(148, 0, 211, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF1493.
///
- public static readonly Color DeepPink = FromRgba(255, 20, 147, 255);
+ public static readonly Color DeepPink = FromPixel(new Rgba32(255, 20, 147, 255));
///
/// Represents a matching the W3C definition that has an hex value of #00BFFF.
///
- public static readonly Color DeepSkyBlue = FromRgba(0, 191, 255, 255);
+ public static readonly Color DeepSkyBlue = FromPixel(new Rgba32(0, 191, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #696969.
///
- public static readonly Color DimGray = FromRgba(105, 105, 105, 255);
+ public static readonly Color DimGray = FromPixel(new Rgba32(105, 105, 105, 255));
///
/// Represents a matching the W3C definition that has an hex value of #696969.
@@ -234,62 +236,62 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #1E90FF.
///
- public static readonly Color DodgerBlue = FromRgba(30, 144, 255, 255);
+ public static readonly Color DodgerBlue = FromPixel(new Rgba32(30, 144, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #B22222.
///
- public static readonly Color Firebrick = FromRgba(178, 34, 34, 255);
+ public static readonly Color Firebrick = FromPixel(new Rgba32(178, 34, 34, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFFAF0.
///
- public static readonly Color FloralWhite = FromRgba(255, 250, 240, 255);
+ public static readonly Color FloralWhite = FromPixel(new Rgba32(255, 250, 240, 255));
///
/// Represents a matching the W3C definition that has an hex value of #228B22.
///
- public static readonly Color ForestGreen = FromRgba(34, 139, 34, 255);
+ public static readonly Color ForestGreen = FromPixel(new Rgba32(34, 139, 34, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF00FF.
///
- public static readonly Color Fuchsia = FromRgba(255, 0, 255, 255);
+ public static readonly Color Fuchsia = FromPixel(new Rgba32(255, 0, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #DCDCDC.
///
- public static readonly Color Gainsboro = FromRgba(220, 220, 220, 255);
+ public static readonly Color Gainsboro = FromPixel(new Rgba32(220, 220, 220, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F8F8FF.
///
- public static readonly Color GhostWhite = FromRgba(248, 248, 255, 255);
+ public static readonly Color GhostWhite = FromPixel(new Rgba32(248, 248, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFD700.
///
- public static readonly Color Gold = FromRgba(255, 215, 0, 255);
+ public static readonly Color Gold = FromPixel(new Rgba32(255, 215, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #DAA520.
///
- public static readonly Color Goldenrod = FromRgba(218, 165, 32, 255);
+ public static readonly Color Goldenrod = FromPixel(new Rgba32(218, 165, 32, 255));
///
/// Represents a matching the W3C definition that has an hex value of #808080.
///
- public static readonly Color Gray = FromRgba(128, 128, 128, 255);
+ public static readonly Color Gray = FromPixel(new Rgba32(128, 128, 128, 255));
///
/// Represents a matching the W3C definition that has an hex value of #008000.
///
- public static readonly Color Green = FromRgba(0, 128, 0, 255);
+ public static readonly Color Green = FromPixel(new Rgba32(0, 128, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #ADFF2F.
///
- public static readonly Color GreenYellow = FromRgba(173, 255, 47, 255);
+ public static readonly Color GreenYellow = FromPixel(new Rgba32(173, 255, 47, 255));
///
/// Represents a matching the W3C definition that has an hex value of #808080.
@@ -299,82 +301,82 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #F0FFF0.
///
- public static readonly Color Honeydew = FromRgba(240, 255, 240, 255);
+ public static readonly Color Honeydew = FromPixel(new Rgba32(240, 255, 240, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF69B4.
///
- public static readonly Color HotPink = FromRgba(255, 105, 180, 255);
+ public static readonly Color HotPink = FromPixel(new Rgba32(255, 105, 180, 255));
///
/// Represents a matching the W3C definition that has an hex value of #CD5C5C.
///
- public static readonly Color IndianRed = FromRgba(205, 92, 92, 255);
+ public static readonly Color IndianRed = FromPixel(new Rgba32(205, 92, 92, 255));
///
/// Represents a matching the W3C definition that has an hex value of #4B0082.
///
- public static readonly Color Indigo = FromRgba(75, 0, 130, 255);
+ public static readonly Color Indigo = FromPixel(new Rgba32(75, 0, 130, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFFFF0.
///
- public static readonly Color Ivory = FromRgba(255, 255, 240, 255);
+ public static readonly Color Ivory = FromPixel(new Rgba32(255, 255, 240, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F0E68C.
///
- public static readonly Color Khaki = FromRgba(240, 230, 140, 255);
+ public static readonly Color Khaki = FromPixel(new Rgba32(240, 230, 140, 255));
///
/// Represents a matching the W3C definition that has an hex value of #E6E6FA.
///
- public static readonly Color Lavender = FromRgba(230, 230, 250, 255);
+ public static readonly Color Lavender = FromPixel(new Rgba32(230, 230, 250, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFF0F5.
///
- public static readonly Color LavenderBlush = FromRgba(255, 240, 245, 255);
+ public static readonly Color LavenderBlush = FromPixel(new Rgba32(255, 240, 245, 255));
///
/// Represents a matching the W3C definition that has an hex value of #7CFC00.
///
- public static readonly Color LawnGreen = FromRgba(124, 252, 0, 255);
+ public static readonly Color LawnGreen = FromPixel(new Rgba32(124, 252, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFFACD.
///
- public static readonly Color LemonChiffon = FromRgba(255, 250, 205, 255);
+ public static readonly Color LemonChiffon = FromPixel(new Rgba32(255, 250, 205, 255));
///
/// Represents a matching the W3C definition that has an hex value of #ADD8E6.
///
- public static readonly Color LightBlue = FromRgba(173, 216, 230, 255);
+ public static readonly Color LightBlue = FromPixel(new Rgba32(173, 216, 230, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F08080.
///
- public static readonly Color LightCoral = FromRgba(240, 128, 128, 255);
+ public static readonly Color LightCoral = FromPixel(new Rgba32(240, 128, 128, 255));
///
/// Represents a matching the W3C definition that has an hex value of #E0FFFF.
///
- public static readonly Color LightCyan = FromRgba(224, 255, 255, 255);
+ public static readonly Color LightCyan = FromPixel(new Rgba32(224, 255, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FAFAD2.
///
- public static readonly Color LightGoldenrodYellow = FromRgba(250, 250, 210, 255);
+ public static readonly Color LightGoldenrodYellow = FromPixel(new Rgba32(250, 250, 210, 255));
///
/// Represents a matching the W3C definition that has an hex value of #D3D3D3.
///
- public static readonly Color LightGray = FromRgba(211, 211, 211, 255);
+ public static readonly Color LightGray = FromPixel(new Rgba32(211, 211, 211, 255));
///
/// Represents a matching the W3C definition that has an hex value of #90EE90.
///
- public static readonly Color LightGreen = FromRgba(144, 238, 144, 255);
+ public static readonly Color LightGreen = FromPixel(new Rgba32(144, 238, 144, 255));
///
/// Represents a matching the W3C definition that has an hex value of #D3D3D3.
@@ -384,27 +386,27 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #FFB6C1.
///
- public static readonly Color LightPink = FromRgba(255, 182, 193, 255);
+ public static readonly Color LightPink = FromPixel(new Rgba32(255, 182, 193, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFA07A.
///
- public static readonly Color LightSalmon = FromRgba(255, 160, 122, 255);
+ public static readonly Color LightSalmon = FromPixel(new Rgba32(255, 160, 122, 255));
///
/// Represents a matching the W3C definition that has an hex value of #20B2AA.
///
- public static readonly Color LightSeaGreen = FromRgba(32, 178, 170, 255);
+ public static readonly Color LightSeaGreen = FromPixel(new Rgba32(32, 178, 170, 255));
///
/// Represents a matching the W3C definition that has an hex value of #87CEFA.
///
- public static readonly Color LightSkyBlue = FromRgba(135, 206, 250, 255);
+ public static readonly Color LightSkyBlue = FromPixel(new Rgba32(135, 206, 250, 255));
///
/// Represents a matching the W3C definition that has an hex value of #778899.
///
- public static readonly Color LightSlateGray = FromRgba(119, 136, 153, 255);
+ public static readonly Color LightSlateGray = FromPixel(new Rgba32(119, 136, 153, 255));
///
/// Represents a matching the W3C definition that has an hex value of #778899.
@@ -414,27 +416,27 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #B0C4DE.
///
- public static readonly Color LightSteelBlue = FromRgba(176, 196, 222, 255);
+ public static readonly Color LightSteelBlue = FromPixel(new Rgba32(176, 196, 222, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFFFE0.
///
- public static readonly Color LightYellow = FromRgba(255, 255, 224, 255);
+ public static readonly Color LightYellow = FromPixel(new Rgba32(255, 255, 224, 255));
///
/// Represents a matching the W3C definition that has an hex value of #00FF00.
///
- public static readonly Color Lime = FromRgba(0, 255, 0, 255);
+ public static readonly Color Lime = FromPixel(new Rgba32(0, 255, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #32CD32.
///
- public static readonly Color LimeGreen = FromRgba(50, 205, 50, 255);
+ public static readonly Color LimeGreen = FromPixel(new Rgba32(50, 205, 50, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FAF0E6.
///
- public static readonly Color Linen = FromRgba(250, 240, 230, 255);
+ public static readonly Color Linen = FromPixel(new Rgba32(250, 240, 230, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF00FF.
@@ -444,237 +446,237 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #800000.
///
- public static readonly Color Maroon = FromRgba(128, 0, 0, 255);
+ public static readonly Color Maroon = FromPixel(new Rgba32(128, 0, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #66CDAA.
///
- public static readonly Color MediumAquamarine = FromRgba(102, 205, 170, 255);
+ public static readonly Color MediumAquamarine = FromPixel(new Rgba32(102, 205, 170, 255));
///
/// Represents a matching the W3C definition that has an hex value of #0000CD.
///
- public static readonly Color MediumBlue = FromRgba(0, 0, 205, 255);
+ public static readonly Color MediumBlue = FromPixel(new Rgba32(0, 0, 205, 255));
///
/// Represents a matching the W3C definition that has an hex value of #BA55D3.
///
- public static readonly Color MediumOrchid = FromRgba(186, 85, 211, 255);
+ public static readonly Color MediumOrchid = FromPixel(new Rgba32(186, 85, 211, 255));
///
/// Represents a matching the W3C definition that has an hex value of #9370DB.
///
- public static readonly Color MediumPurple = FromRgba(147, 112, 219, 255);
+ public static readonly Color MediumPurple = FromPixel(new Rgba32(147, 112, 219, 255));
///
/// Represents a matching the W3C definition that has an hex value of #3CB371.
///
- public static readonly Color MediumSeaGreen = FromRgba(60, 179, 113, 255);
+ public static readonly Color MediumSeaGreen = FromPixel(new Rgba32(60, 179, 113, 255));
///
/// Represents a matching the W3C definition that has an hex value of #7B68EE.
///
- public static readonly Color MediumSlateBlue = FromRgba(123, 104, 238, 255);
+ public static readonly Color MediumSlateBlue = FromPixel(new Rgba32(123, 104, 238, 255));
///
/// Represents a matching the W3C definition that has an hex value of #00FA9A.
///
- public static readonly Color MediumSpringGreen = FromRgba(0, 250, 154, 255);
+ public static readonly Color MediumSpringGreen = FromPixel(new Rgba32(0, 250, 154, 255));
///
/// Represents a matching the W3C definition that has an hex value of #48D1CC.
///
- public static readonly Color MediumTurquoise = FromRgba(72, 209, 204, 255);
+ public static readonly Color MediumTurquoise = FromPixel(new Rgba32(72, 209, 204, 255));
///
/// Represents a matching the W3C definition that has an hex value of #C71585.
///
- public static readonly Color MediumVioletRed = FromRgba(199, 21, 133, 255);
+ public static readonly Color MediumVioletRed = FromPixel(new Rgba32(199, 21, 133, 255));
///
/// Represents a matching the W3C definition that has an hex value of #191970.
///
- public static readonly Color MidnightBlue = FromRgba(25, 25, 112, 255);
+ public static readonly Color MidnightBlue = FromPixel(new Rgba32(25, 25, 112, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F5FFFA.
///
- public static readonly Color MintCream = FromRgba(245, 255, 250, 255);
+ public static readonly Color MintCream = FromPixel(new Rgba32(245, 255, 250, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFE4E1.
///
- public static readonly Color MistyRose = FromRgba(255, 228, 225, 255);
+ public static readonly Color MistyRose = FromPixel(new Rgba32(255, 228, 225, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFE4B5.
///
- public static readonly Color Moccasin = FromRgba(255, 228, 181, 255);
+ public static readonly Color Moccasin = FromPixel(new Rgba32(255, 228, 181, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFDEAD.
///
- public static readonly Color NavajoWhite = FromRgba(255, 222, 173, 255);
+ public static readonly Color NavajoWhite = FromPixel(new Rgba32(255, 222, 173, 255));
///
/// Represents a matching the W3C definition that has an hex value of #000080.
///
- public static readonly Color Navy = FromRgba(0, 0, 128, 255);
+ public static readonly Color Navy = FromPixel(new Rgba32(0, 0, 128, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FDF5E6.
///
- public static readonly Color OldLace = FromRgba(253, 245, 230, 255);
+ public static readonly Color OldLace = FromPixel(new Rgba32(253, 245, 230, 255));
///
/// Represents a matching the W3C definition that has an hex value of #808000.
///
- public static readonly Color Olive = FromRgba(128, 128, 0, 255);
+ public static readonly Color Olive = FromPixel(new Rgba32(128, 128, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #6B8E23.
///
- public static readonly Color OliveDrab = FromRgba(107, 142, 35, 255);
+ public static readonly Color OliveDrab = FromPixel(new Rgba32(107, 142, 35, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFA500.
///
- public static readonly Color Orange = FromRgba(255, 165, 0, 255);
+ public static readonly Color Orange = FromPixel(new Rgba32(255, 165, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF4500.
///
- public static readonly Color OrangeRed = FromRgba(255, 69, 0, 255);
+ public static readonly Color OrangeRed = FromPixel(new Rgba32(255, 69, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #DA70D6.
///
- public static readonly Color Orchid = FromRgba(218, 112, 214, 255);
+ public static readonly Color Orchid = FromPixel(new Rgba32(218, 112, 214, 255));
///
/// Represents a matching the W3C definition that has an hex value of #EEE8AA.
///
- public static readonly Color PaleGoldenrod = FromRgba(238, 232, 170, 255);
+ public static readonly Color PaleGoldenrod = FromPixel(new Rgba32(238, 232, 170, 255));
///
/// Represents a matching the W3C definition that has an hex value of #98FB98.
///
- public static readonly Color PaleGreen = FromRgba(152, 251, 152, 255);
+ public static readonly Color PaleGreen = FromPixel(new Rgba32(152, 251, 152, 255));
///
/// Represents a matching the W3C definition that has an hex value of #AFEEEE.
///
- public static readonly Color PaleTurquoise = FromRgba(175, 238, 238, 255);
+ public static readonly Color PaleTurquoise = FromPixel(new Rgba32(175, 238, 238, 255));
///
/// Represents a matching the W3C definition that has an hex value of #DB7093.
///
- public static readonly Color PaleVioletRed = FromRgba(219, 112, 147, 255);
+ public static readonly Color PaleVioletRed = FromPixel(new Rgba32(219, 112, 147, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFEFD5.
///
- public static readonly Color PapayaWhip = FromRgba(255, 239, 213, 255);
+ public static readonly Color PapayaWhip = FromPixel(new Rgba32(255, 239, 213, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFDAB9.
///
- public static readonly Color PeachPuff = FromRgba(255, 218, 185, 255);
+ public static readonly Color PeachPuff = FromPixel(new Rgba32(255, 218, 185, 255));
///
/// Represents a matching the W3C definition that has an hex value of #CD853F.
///
- public static readonly Color Peru = FromRgba(205, 133, 63, 255);
+ public static readonly Color Peru = FromPixel(new Rgba32(205, 133, 63, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFC0CB.
///
- public static readonly Color Pink = FromRgba(255, 192, 203, 255);
+ public static readonly Color Pink = FromPixel(new Rgba32(255, 192, 203, 255));
///
/// Represents a matching the W3C definition that has an hex value of #DDA0DD.
///
- public static readonly Color Plum = FromRgba(221, 160, 221, 255);
+ public static readonly Color Plum = FromPixel(new Rgba32(221, 160, 221, 255));
///
/// Represents a matching the W3C definition that has an hex value of #B0E0E6.
///
- public static readonly Color PowderBlue = FromRgba(176, 224, 230, 255);
+ public static readonly Color PowderBlue = FromPixel(new Rgba32(176, 224, 230, 255));
///
/// Represents a matching the W3C definition that has an hex value of #800080.
///
- public static readonly Color Purple = FromRgba(128, 0, 128, 255);
+ public static readonly Color Purple = FromPixel(new Rgba32(128, 0, 128, 255));
///
/// Represents a matching the W3C definition that has an hex value of #663399.
///
- public static readonly Color RebeccaPurple = FromRgba(102, 51, 153, 255);
+ public static readonly Color RebeccaPurple = FromPixel(new Rgba32(102, 51, 153, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF0000.
///
- public static readonly Color Red = FromRgba(255, 0, 0, 255);
+ public static readonly Color Red = FromPixel(new Rgba32(255, 0, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #BC8F8F.
///
- public static readonly Color RosyBrown = FromRgba(188, 143, 143, 255);
+ public static readonly Color RosyBrown = FromPixel(new Rgba32(188, 143, 143, 255));
///
/// Represents a matching the W3C definition that has an hex value of #4169E1.
///
- public static readonly Color RoyalBlue = FromRgba(65, 105, 225, 255);
+ public static readonly Color RoyalBlue = FromPixel(new Rgba32(65, 105, 225, 255));
///
/// Represents a matching the W3C definition that has an hex value of #8B4513.
///
- public static readonly Color SaddleBrown = FromRgba(139, 69, 19, 255);
+ public static readonly Color SaddleBrown = FromPixel(new Rgba32(139, 69, 19, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FA8072.
///
- public static readonly Color Salmon = FromRgba(250, 128, 114, 255);
+ public static readonly Color Salmon = FromPixel(new Rgba32(250, 128, 114, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F4A460.
///
- public static readonly Color SandyBrown = FromRgba(244, 164, 96, 255);
+ public static readonly Color SandyBrown = FromPixel(new Rgba32(244, 164, 96, 255));
///
/// Represents a matching the W3C definition that has an hex value of #2E8B57.
///
- public static readonly Color SeaGreen = FromRgba(46, 139, 87, 255);
+ public static readonly Color SeaGreen = FromPixel(new Rgba32(46, 139, 87, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFF5EE.
///
- public static readonly Color SeaShell = FromRgba(255, 245, 238, 255);
+ public static readonly Color SeaShell = FromPixel(new Rgba32(255, 245, 238, 255));
///
/// Represents a matching the W3C definition that has an hex value of #A0522D.
///
- public static readonly Color Sienna = FromRgba(160, 82, 45, 255);
+ public static readonly Color Sienna = FromPixel(new Rgba32(160, 82, 45, 255));
///
/// Represents a matching the W3C definition that has an hex value of #C0C0C0.
///
- public static readonly Color Silver = FromRgba(192, 192, 192, 255);
+ public static readonly Color Silver = FromPixel(new Rgba32(192, 192, 192, 255));
///
/// Represents a matching the W3C definition that has an hex value of #87CEEB.
///
- public static readonly Color SkyBlue = FromRgba(135, 206, 235, 255);
+ public static readonly Color SkyBlue = FromPixel(new Rgba32(135, 206, 235, 255));
///
/// Represents a matching the W3C definition that has an hex value of #6A5ACD.
///
- public static readonly Color SlateBlue = FromRgba(106, 90, 205, 255);
+ public static readonly Color SlateBlue = FromPixel(new Rgba32(106, 90, 205, 255));
///
/// Represents a matching the W3C definition that has an hex value of #708090.
///
- public static readonly Color SlateGray = FromRgba(112, 128, 144, 255);
+ public static readonly Color SlateGray = FromPixel(new Rgba32(112, 128, 144, 255));
///
/// Represents a matching the W3C definition that has an hex value of #708090.
@@ -684,81 +686,80 @@ public readonly partial struct Color
///
/// Represents a matching the W3C definition that has an hex value of #FFFAFA.
///
- public static readonly Color Snow = FromRgba(255, 250, 250, 255);
+ public static readonly Color Snow = FromPixel(new Rgba32(255, 250, 250, 255));
///
/// Represents a matching the W3C definition that has an hex value of #00FF7F.
///
- public static readonly Color SpringGreen = FromRgba(0, 255, 127, 255);
+ public static readonly Color SpringGreen = FromPixel(new Rgba32(0, 255, 127, 255));
///
/// Represents a matching the W3C definition that has an hex value of #4682B4.
///
- public static readonly Color SteelBlue = FromRgba(70, 130, 180, 255);
+ public static readonly Color SteelBlue = FromPixel(new Rgba32(70, 130, 180, 255));
///
/// Represents a matching the W3C definition that has an hex value of #D2B48C.
///
- public static readonly Color Tan = FromRgba(210, 180, 140, 255);
+ public static readonly Color Tan = FromPixel(new Rgba32(210, 180, 140, 255));
///
/// Represents a matching the W3C definition that has an hex value of #008080.
///
- public static readonly Color Teal = FromRgba(0, 128, 128, 255);
+ public static readonly Color Teal = FromPixel(new Rgba32(0, 128, 128, 255));
///
/// Represents a matching the W3C definition that has an hex value of #D8BFD8.
///
- public static readonly Color Thistle = FromRgba(216, 191, 216, 255);
+ public static readonly Color Thistle = FromPixel(new Rgba32(216, 191, 216, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FF6347.
///
- public static readonly Color Tomato = FromRgba(255, 99, 71, 255);
+ public static readonly Color Tomato = FromPixel(new Rgba32(255, 99, 71, 255));
///
/// Represents a matching the W3C definition that has an hex value of #00000000.
///
- public static readonly Color Transparent = FromRgba(0, 0, 0, 0);
+ public static readonly Color Transparent = FromPixel(new Rgba32(0, 0, 0, 0));
///
/// Represents a matching the W3C definition that has an hex value of #40E0D0.
///
- public static readonly Color Turquoise = FromRgba(64, 224, 208, 255);
+ public static readonly Color Turquoise = FromPixel(new Rgba32(64, 224, 208, 255));
///
/// Represents a matching the W3C definition that has an hex value of #EE82EE.
///
- public static readonly Color Violet = FromRgba(238, 130, 238, 255);
+ public static readonly Color Violet = FromPixel(new Rgba32(238, 130, 238, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F5DEB3.
///
- public static readonly Color Wheat = FromRgba(245, 222, 179, 255);
+ public static readonly Color Wheat = FromPixel(new Rgba32(245, 222, 179, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFFFFF.
///
- public static readonly Color White = FromRgba(255, 255, 255, 255);
+ public static readonly Color White = FromPixel(new Rgba32(255, 255, 255, 255));
///
/// Represents a matching the W3C definition that has an hex value of #F5F5F5.
///
- public static readonly Color WhiteSmoke = FromRgba(245, 245, 245, 255);
+ public static readonly Color WhiteSmoke = FromPixel(new Rgba32(245, 245, 245, 255));
///
/// Represents a matching the W3C definition that has an hex value of #FFFF00.
///
- public static readonly Color Yellow = FromRgba(255, 255, 0, 255);
+ public static readonly Color Yellow = FromPixel(new Rgba32(255, 255, 0, 255));
///
/// Represents a matching the W3C definition that has an hex value of #9ACD32.
///
- 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 CreateNamedColorsLookup()
- {
- return new Dictionary(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 }
};
- }
}
diff --git a/src/ImageSharp/Color/Color.cs b/src/ImageSharp/Color/Color.cs
index 7110090501..ec19a86eb9 100644
--- a/src/ImageSharp/Color/Color.cs
+++ b/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;
///
public readonly partial struct Color : IEquatable
{
- private readonly Rgba64 data;
+ private readonly Vector4 data;
private readonly IPixel? boxedHighPrecisionPixel;
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The containing the color information.
[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;
}
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The pixel containing color information.
[MethodImpl(InliningOptions.ShortMethod)]
private Color(IPixel pixel)
{
@@ -53,6 +43,21 @@ public readonly partial struct Color : IEquatable
this.data = default;
}
+ ///
+ /// Converts a to .
+ ///
+ /// The .
+ /// The .
+ public static explicit operator Vector4(Color color) => color.ToScaledVector4();
+
+ ///
+ /// Converts an to .
+ ///
+ /// The .
+ /// The .
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static explicit operator Color(Vector4 source) => new(source);
+
///
/// Checks whether two structures are equal.
///
@@ -77,27 +82,6 @@ public readonly partial struct Color : IEquatable
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Color left, Color right) => !left.Equals(right);
- ///
- /// Creates a from RGBA bytes.
- ///
- /// The red component (0-255).
- /// The green component (0-255).
- /// The blue component (0-255).
- /// The alpha component (0-255).
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static Color FromRgba(byte r, byte g, byte b, byte a) => new(r, g, b, a);
-
- ///
- /// Creates a from RGB bytes.
- ///
- /// The red component (0-255).
- /// The green component (0-255).
- /// The blue component (0-255).
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static Color FromRgb(byte r, byte g, byte b) => new(r, g, b);
-
///
/// Creates a from the given .
///
@@ -108,34 +92,45 @@ public readonly partial struct Color : IEquatable
public static Color FromPixel(TPixel pixel)
where TPixel : unmanaged, IPixel
{
- // 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);
}
+ }
+ ///
+ /// Bulk converts a span of a specified type to a span of .
+ ///
+ /// The pixel type to convert to.
+ /// The source pixel span.
+ /// The destination color span.
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public static void FromPixel(ReadOnlySpan source, Span destination)
+ where TPixel : unmanaged, IPixel
+ {
+ 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
public static Color ParseHex(string hex)
{
Rgba32 rgba = Rgba32.ParseHex(hex);
-
- return new Color(rgba);
+ return FromPixel(rgba);
}
///
@@ -177,7 +171,7 @@ public readonly partial struct Color : IEquatable
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
[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();
}
///
@@ -286,7 +281,7 @@ public readonly partial struct Color : IEquatable
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
public static void ToPixel(ReadOnlySpan source, Span destination)
where TPixel : unmanaged, IPixel
{
- // 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
{
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
{
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();
+ }
}
diff --git a/src/ImageSharp/Formats/AnimationUtilities.cs b/src/ImageSharp/Formats/AnimationUtilities.cs
index 288f3d1329..4605d4daa7 100644
--- a/src/ImageSharp/Formats/AnimationUtilities.cs
+++ b/src/ImageSharp/Formats/AnimationUtilities.cs
@@ -50,7 +50,7 @@ internal static class AnimationUtilities
Span next = buffers.GetSpan().Slice(currentFrame.Width * 2, currentFrame.Width);
Span result = buffers.GetSpan()[(currentFrame.Width * 3)..];
- Rgba32 bg = replacement;
+ Rgba32 bg = replacement.ToPixel();
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;
diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index aecbbbbc71..8916da6e0e 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
@@ -711,10 +711,7 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
Color[] colorTable = new Color[this.imageDescriptor.LocalColorTableSize];
ReadOnlySpan rgbTable = MemoryMarshal.Cast(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 rgbTable = MemoryMarshal.Cast(globalColorTableSpan);
- for (int i = 0; i < colorTable.Length; i++)
- {
- colorTable[i] = new Color(rgbTable[i]);
- }
+ Color.FromPixel(rgbTable, colorTable);
this.gifMetadata.GlobalColorTable = colorTable;
}
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index 3eabbdef0c..4178d28209 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -1240,10 +1240,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
Color[] colorTable = new Color[palette.Length / Unsafe.SizeOf()];
ReadOnlySpan rgbTable = MemoryMarshal.Cast(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)
diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs
index e348d74679..8bf8be2adc 100644
--- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs
+++ b/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();
for (int y = 0; y < accessor.Height; y++)
{
Span 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();
alpha[1] = rgb.R;
alpha[3] = rgb.G;
alpha[5] = rgb.B;
diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
index f217515e3c..39b3fff27a 100644
--- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
+++ b/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());
Unsafe.Add(ref rowSpanRef, x) = pixel;
}
}
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs
index a8a70f7272..89d1b9d20e 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs
@@ -22,8 +22,8 @@ internal class BlackIsZero1TiffColor : TiffBaseColorDecoder
TPixel colorBlack = default;
TPixel colorWhite = default;
- colorBlack.FromRgba32(Color.Black);
- colorWhite.FromRgba32(Color.White);
+ colorBlack.FromRgba32(Color.Black.ToPixel());
+ colorWhite.FromRgba32(Color.White.ToPixel());
ref byte dataRef = ref MemoryMarshal.GetReference(data);
for (nuint y = (uint)top; y < (uint)(top + height); y++)
{
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs
index c5b662979e..4cba8f2d72 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs
@@ -21,8 +21,8 @@ internal class WhiteIsZero1TiffColor : TiffBaseColorDecoder
var colorBlack = default(TPixel);
var colorWhite = default(TPixel);
- colorBlack.FromRgba32(Color.Black);
- colorWhite.FromRgba32(Color.White);
+ colorBlack.FromRgba32(Color.Black.ToPixel());
+ colorWhite.FromRgba32(Color.White.ToPixel());
ref byte dataRef = ref MemoryMarshal.GetReference(data);
for (nuint y = (uint)top; y < (uint)(top + height); y++)
{
diff --git a/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs b/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs
index 9ffda0f51f..c98be1fcd8 100644
--- a/src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs
+++ b/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
/// The number of times to loop the animation. If it is 0, this means infinitely.
public static void WriteAnimationParameter(Stream stream, Color background, ushort loopCount)
{
- WebpAnimationParameter chunk = new(background.ToBgra32().PackedValue, loopCount);
+ WebpAnimationParameter chunk = new(background.ToPixel().PackedValue, loopCount);
chunk.WriteTo(stream);
}
diff --git a/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs b/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs
index 65f1a4da46..70372fe985 100644
--- a/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs
+++ b/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;
diff --git a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs
index 69a0afcd9b..2991f355ff 100644
--- a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs
+++ b/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)
{
diff --git a/src/ImageSharp/ImageInfo.cs b/src/ImageSharp/ImageInfo.cs
index 00319e9b55..c0d1f27ca4 100644
--- a/src/ImageSharp/ImageInfo.cs
+++ b/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;
diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs
index 38f0b94d62..e12631cbd7 100644
--- a/src/ImageSharp/Image{TPixel}.cs
+++ b/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;
diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs
index adbf688612..b28911a904 100644
--- a/src/ImageSharp/PixelFormats/IPixel.cs
+++ b/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;
diff --git a/src/ImageSharp/PixelFormats/PixelComponentInfo.cs b/src/ImageSharp/PixelFormats/PixelComponentInfo.cs
new file mode 100644
index 0000000000..a761054144
--- /dev/null
+++ b/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;
+
+///
+/// Represents pixel component information within a pixel format.
+///
+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;
+ }
+
+ ///
+ /// Gets the number of components within the pixel.
+ ///
+ public int ComponentCount { get; }
+
+ ///
+ /// Gets the number of bytes of padding within the pixel.
+ ///
+ public int Padding { get; }
+
+ ///
+ /// Creates a new instance.
+ ///
+ /// The type of pixel format.
+ /// The number of components within the pixel format.
+ /// The precision in bits of each component.
+ /// The .
+ /// The component precision and index cannot exceed the component range.
+ public static PixelComponentInfo Create(int count, params int[] precision)
+ where TPixel : unmanaged, IPixel
+ {
+ 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() * 8) - sum, precisionData1, precisionData2);
+ }
+
+ ///
+ /// Returns the precision of the component in bits at the given index.
+ ///
+ /// The component index.
+ /// The .
+ /// The component index cannot exceed the component range.
+ 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);
+ }
+
+ ///
+ /// Returns the maximum precision in bits of all components.
+ ///
+ /// The .
+ 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;
+ }
+}
diff --git a/src/ImageSharp/PixelFormats/PixelComponentPrecision.cs b/src/ImageSharp/PixelFormats/PixelComponentPrecision.cs
index 3480ac76ed..2f15b7fad8 100644
--- a/src/ImageSharp/PixelFormats/PixelComponentPrecision.cs
+++ b/src/ImageSharp/PixelFormats/PixelComponentPrecision.cs
@@ -4,47 +4,67 @@
namespace SixLabors.ImageSharp.PixelFormats;
///
-/// 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.
///
public enum PixelComponentPrecision
{
///
/// 8-bit signed integer.
///
- SByte,
+ SByte = sizeof(sbyte) * 8,
///
/// 8-bit unsigned integer.
///
- Byte,
+ Byte = sizeof(byte) * 8,
///
/// 16-bit signed integer.
///
- Short,
+ Short = sizeof(short) * 8,
///
/// 16-bit unsigned integer.
///
- UShort,
+ UShort = sizeof(ushort) * 8,
///
/// 32-bit signed integer.
///
- Int,
+ Int = sizeof(int) * 8,
///
/// 32-bit unsigned integer.
///
- UInt,
+ UInt = sizeof(uint) * 8,
+
+ ///
+ /// 64-bit signed integer.
+ ///
+ Long = sizeof(long) * 8,
+
+ ///
+ /// 64-bit unsigned integer.
+ ///
+ ULong = sizeof(ulong) * 8,
///
/// 16-bit floating point.
///
- Half,
+ Half = (sizeof(float) * 8) / 2,
///
/// 32-bit floating point.
///
- Float
+ Float = sizeof(float) * 8,
+
+ ///
+ /// 64-bit floating point.
+ ///
+ Double = sizeof(double) * 8,
+
+ ///
+ /// 128-bit floating point.
+ ///
+ Decimal = sizeof(decimal) * 8,
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
index 33fa62d1af..abae4f246f 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
+++ b/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, IPackedVector
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(1, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(1, 8), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
index 66523f0408..e1399f05c0 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
+++ b/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, IPackedVector
set => this.Abgr = value;
}
- ///
- /// Converts an to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Color(Abgr32 source) => new(source);
-
- ///
- /// Converts a to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Abgr32(Color color) => color.ToAbgr32();
-
///
/// Compares two objects for equality.
///
@@ -185,7 +168,7 @@ public partial struct Abgr32 : IPixel, IPackedVector
public static bool operator !=(Abgr32 left, Abgr32 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
index d3375f65f6..2b7bcf9133 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
+++ b/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, IPackedVector
set => this.Argb = value;
}
- ///
- /// Converts an to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Color(Argb32 source) => new(source);
-
- ///
- /// Converts a to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Argb32(Color color) => color.ToArgb32();
-
///
/// Compares two objects for equality.
///
@@ -185,7 +168,7 @@ public partial struct Argb32 : IPixel, IPackedVector
public static bool operator !=(Argb32 left, Argb32 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
index 9d0186c835..c9c3246807 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
+++ b/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
this.B = b;
}
- ///
- /// Converts an to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Color(Bgr24 source) => new(source);
-
- ///
- /// Converts a to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Bgr24(Color color) => color.ToBgr24();
-
///
/// Compares two objects for equality.
///
@@ -89,7 +72,7 @@ public partial struct Bgr24 : IPixel
public static bool operator !=(Bgr24 left, Bgr24 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(3, 8, 8, 8), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
index 6135ab3e7e..d020cf0256 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
+++ b/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, IPackedVector
public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(3, 5, 6, 5), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
index 7da4fad4f5..b3a96523ee 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
+++ b/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, IPackedVector
set => this.Bgra = value;
}
- ///
- /// Converts an to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Color(Bgra32 source) => new(source);
-
- ///
- /// Converts a to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Bgra32(Color color) => color.ToBgra32();
-
///
/// Compares two objects for equality.
///
@@ -138,7 +121,7 @@ public partial struct Bgra32 : IPixel, IPackedVector
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
index effc0d6e5d..510d6666f7 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
+++ b/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, IPackedVector
public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 4, 4, 4, 4), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
index 14110b1d10..68dbd9544e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
+++ b/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, IPackedVector
public static bool operator !=(Bgra5551 left, Bgra5551 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 5, 5, 5, 1), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
index f9a36305d7..fbe7a0c52f 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
+++ b/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, IPackedVector
public static bool operator !=(Byte4 left, Byte4 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
index 7e1997251e..aca64ae7a0 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
+++ b/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, IPackedVector
public static bool operator !=(HalfSingle left, HalfSingle right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(1, PixelComponentPrecision.Half, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(1, 16), PixelAlphaRepresentation.None);
///
public PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
index 1e3854feb7..5a25d523bb 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
+++ b/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, IPackedVector
public static bool operator !=(HalfVector2 left, HalfVector2 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(2, PixelComponentPrecision.Half, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(2, 16, 16), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
index 2331605794..7ad7b07f40 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
+++ b/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, IPackedVector
public static bool operator !=(HalfVector4 left, HalfVector4 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Half, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 16, 16, 16, 16), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
index fa07d650bc..0c58fb1fda 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
+++ b/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, IPackedVector
public static bool operator !=(L16 left, L16 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(1, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(1, 16), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
index 28fb7ec720..2cd8b20e77 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
+++ b/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, IPackedVector
public static bool operator !=(L8 left, L8 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(1, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(1, 8), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
index 99203518af..b811df4b4d 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
+++ b/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, IPackedVector
public static bool operator !=(La16 left, La16 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(2, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(2, 8, 8), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
index a8c0dcd940..e6a63f5ec1 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
+++ b/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, IPackedVector
public static bool operator !=(La32 left, La32 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(2, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(2, 16, 16), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
index 5db53e8539..f7427e65ce 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
+++ b/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, IPackedVector !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(2, PixelComponentPrecision.SByte, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(2, 8, 8), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
index 4c850e4269..beeae655a0 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
+++ b/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, IPackedVector !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.SByte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
index 7fd299d6db..8152c89d37 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
+++ b/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, IPackedVector
public static bool operator !=(NormalizedShort2 left, NormalizedShort2 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(2, PixelComponentPrecision.Short, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(2, 16, 16), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
index ff5cd6a987..3f37cb80f7 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
+++ b/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, IPackedVector
public static bool operator !=(NormalizedShort4 left, NormalizedShort4 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Short, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 16, 16, 16, 16), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
index 9a27533414..594bdd9a13 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
+++ b/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, IPackedVector
public static bool operator !=(Rg32 left, Rg32 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(2, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(2, 16, 16), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
index f4c907abf0..8d0c7cd48c 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
+++ b/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
this.B = b;
}
- ///
- /// Converts an to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Color(Rgb24 source) => new(source);
-
- ///
- /// Converts a to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Rgb24(Color color) => color.ToRgb24();
-
///
/// Allows the implicit conversion of an instance of to a
/// .
@@ -108,7 +91,7 @@ public partial struct Rgb24 : IPixel
public static bool operator !=(Rgb24 left, Rgb24 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(3, PixelComponentPrecision.Byte, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(3, 8, 8, 8), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
index 642883ff02..f7aac32f42 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
+++ b/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
public static bool operator !=(Rgb48 left, Rgb48 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(3, PixelComponentPrecision.UShort, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(3, 16, 16, 16), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
index 5f289577fe..84482a7aaa 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
+++ b/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, IPackedVector
public static bool operator !=(Rgba1010102 left, Rgba1010102 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 10, 10, 10, 2), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
index f775e8ae11..f391e64740 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
+++ b/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, IPackedVector
set => this.Rgba = value;
}
- ///
- /// Converts an to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Color(Rgba32 source) => new(source);
-
- ///
- /// Converts a to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Rgba32(Color color) => color.ToRgba32();
-
///
/// Allows the implicit conversion of an instance of to a
/// .
@@ -288,7 +271,7 @@ public partial struct Rgba32 : IPixel, IPackedVector
}
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Byte, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 8, 8, 8, 8), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
index 84860d66d8..47062779ba 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
+++ b/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, IPackedVector
set => Unsafe.As(ref this) = value;
}
- ///
- /// Converts an to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Color(Rgba64 source) => new(source);
-
- ///
- /// Converts a to .
- ///
- /// The .
- /// The .
- [MethodImpl(InliningOptions.ShortMethod)]
- public static implicit operator Rgba64(Color color) => color.ToPixel();
-
///
/// Compares two objects for equality.
///
@@ -208,7 +191,7 @@ public partial struct Rgba64 : IPixel, IPackedVector
public static bool operator !=(Rgba64 left, Rgba64 right) => left.PackedValue != right.PackedValue;
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.UShort, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 16, 16, 16, 16), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
index 064064f737..ce1c6d5729 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
+++ b/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
public static RgbaVector FromHex(string hex) => Color.ParseHex(hex).ToPixel();
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Float, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 32, 32, 32, 32), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
index 8af952b180..786c98ee46 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
+++ b/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, IPackedVector
public static bool operator !=(Short2 left, Short2 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(2, PixelComponentPrecision.Short, PixelAlphaRepresentation.None);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(2, 16, 16), PixelAlphaRepresentation.None);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
index 4c60887df0..890e66299a 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
+++ b/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, IPackedVector
public static bool operator !=(Short4 left, Short4 right) => !left.Equals(right);
///
- public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(4, PixelComponentPrecision.Short, PixelAlphaRepresentation.Unassociated);
+ public static PixelTypeInfo GetPixelTypeInfo() => PixelTypeInfo.Create(PixelComponentInfo.Create(4, 16, 16, 16, 16), PixelAlphaRepresentation.Unassociated);
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
index cf3707f9e5..4d3f9e22d4 100644
--- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
+++ b/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;
diff --git a/src/ImageSharp/Formats/PixelTypeInfo.cs b/src/ImageSharp/PixelFormats/PixelTypeInfo.cs
similarity index 65%
rename from src/ImageSharp/Formats/PixelTypeInfo.cs
rename to src/ImageSharp/PixelFormats/PixelTypeInfo.cs
index 170ffcfae6..e209b21e12 100644
--- a/src/ImageSharp/Formats/PixelTypeInfo.cs
+++ b/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;
///
/// Contains information about the pixels that make up an images visual data.
@@ -23,15 +22,10 @@ public readonly struct PixelTypeInfo(int bitsPerPixel)
///
public int BitsPerPixel { get; init; } = bitsPerPixel;
- ///
- /// Gets the count of the color components
- ///
- public int ComponentCount { get; init; }
-
///
/// Gets the maximum precision of components within the pixel.
///
- public PixelComponentPrecision? MaxComponentPrecision { get; init; }
+ public PixelComponentInfo? ComponentInfo { get; init; }
///
/// Gets the pixel alpha transparency behavior.
@@ -39,16 +33,21 @@ public readonly struct PixelTypeInfo(int bitsPerPixel)
///
public PixelAlphaRepresentation? AlphaRepresentation { get; init; }
- internal static PixelTypeInfo Create(
- byte componentCount,
- PixelComponentPrecision componentPrecision,
- PixelAlphaRepresentation pixelAlphaRepresentation)
+ ///
+ /// Creates a new instance.
+ ///
+ /// The type of pixel format.
+ /// The pixel component info.
+ /// The pixel alpha representation.
+ /// The .
+ public static PixelTypeInfo Create(
+ PixelComponentInfo info,
+ PixelAlphaRepresentation alphaRepresentation)
where TPixel : unmanaged, IPixel
=> new()
{
BitsPerPixel = Unsafe.SizeOf() * 8,
- ComponentCount = componentCount,
- MaxComponentPrecision = componentPrecision,
- AlphaRepresentation = pixelAlphaRepresentation
+ ComponentInfo = info,
+ AlphaRepresentation = alphaRepresentation
};
}
diff --git a/src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
index 4a02642fd6..c8a381d590 100644
--- a/src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
+++ b/src/ImageSharp/Processing/Processors/Filters/LomographProcessor{TPixel}.cs
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters;
internal class LomographProcessor : FilterProcessor
where TPixel : unmanaged, IPixel
{
- 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;
///