diff --git a/ImageSharp.sln b/ImageSharp.sln
index 82eeefcde..162de8416 100644
--- a/ImageSharp.sln
+++ b/ImageSharp.sln
@@ -38,6 +38,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{815C0625-CD3
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Build.targets = src\Directory.Build.targets
src\README.md = src\README.md
+ src\ImageSharp.ruleset = src\ImageSharp.ruleset
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp", "src\ImageSharp\ImageSharp.csproj", "{2AA31A1F-142C-43F4-8687-09ABCA4B3A26}"
diff --git a/shared-infrastructure b/shared-infrastructure
index 1c526a97e..d65232bbb 160000
--- a/shared-infrastructure
+++ b/shared-infrastructure
@@ -1 +1 @@
-Subproject commit 1c526a97eea8bcbc7c79de095676f7fb975a9fb1
+Subproject commit d65232bbbfe55a9a153b4058139dda5230e6eb4f
diff --git a/src/ImageSharp.ruleset b/src/ImageSharp.ruleset
index d7a147df0..f29278c95 100644
--- a/src/ImageSharp.ruleset
+++ b/src/ImageSharp.ruleset
@@ -2,6 +2,5 @@
-
diff --git a/src/ImageSharp/Color/Color.Conversions.cs b/src/ImageSharp/Color/Color.Conversions.cs
deleted file mode 100644
index 309ab83ec..000000000
--- 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 f8b4c90fd..00130dd90 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 cebceabe0..e61abf86f 100644
--- a/src/ImageSharp/Color/Color.cs
+++ b/src/ImageSharp/Color/Color.cs
@@ -18,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)
{
@@ -52,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.
///
@@ -76,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 .
///
@@ -107,32 +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 efficently
- if (typeof(TPixel) == typeof(Rgba64))
- {
- return new((Rgba64)(object)pixel);
- }
- else if (typeof(TPixel) == typeof(Rgb48))
+ // Avoid boxing in case we can convert to Vector4 safely and efficiently
+ PixelTypeInfo info = TPixel.GetPixelTypeInfo();
+ if (info.ComponentInfo.HasValue && info.ComponentInfo.Value.GetMaximumComponentPrecision() <= (int)PixelComponentBitDepth.Bit32)
{
- return new((Rgb48)(object)pixel);
+ return new(pixel.ToScaledVector4());
}
- else if (typeof(TPixel) == typeof(La32))
- {
- return new((La32)(object)pixel);
- }
- else if (typeof(TPixel) == typeof(L16))
+ else
{
- return new((L16)(object)pixel);
+ return new(pixel);
}
- else if (Unsafe.SizeOf() <= Unsafe.SizeOf())
+ }
+
+ ///
+ /// 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.ComponentInfo.HasValue && info.ComponentInfo.Value.GetMaximumComponentPrecision() <= (int)PixelComponentBitDepth.Bit32)
{
- Rgba32 p = default;
- pixel.ToRgba32(ref p);
- return new(p);
+ for (int i = 0; i < destination.Length; i++)
+ {
+ destination[i] = new(source[i].ToScaledVector4());
+ }
}
else
{
- return new(pixel);
+ for (int i = 0; i < destination.Length; i++)
+ {
+ destination[i] = new(source[i]);
+ }
}
}
@@ -151,8 +149,7 @@ public readonly partial struct Color : IEquatable
public static Color ParseHex(string hex)
{
Rgba32 rgba = Rgba32.ParseHex(hex);
-
- return new Color(rgba);
+ return FromPixel(rgba);
}
///
@@ -174,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;
}
@@ -253,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();
}
///
@@ -283,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;
}
@@ -302,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++)
{
@@ -316,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;
@@ -331,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 288f3d132..4605d4daa 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 aecbbbbc7..8916da6e0 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/PixelTypeInfo.cs b/src/ImageSharp/Formats/PixelTypeInfo.cs
deleted file mode 100644
index 1328c6528..000000000
--- a/src/ImageSharp/Formats/PixelTypeInfo.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) Six Labors.
-// Licensed under the Six Labors Split License.
-
-using System.Runtime.CompilerServices;
-using SixLabors.ImageSharp.PixelFormats;
-
-// TODO: Review this class as it's used to represent 2 different things.
-// 1.The encoded image pixel format.
-// 2. The pixel format of the decoded image.
-namespace SixLabors.ImageSharp.Formats;
-
-///
-/// Contains information about the pixels that make up an images visual data.
-///
-public class PixelTypeInfo
-{
- ///
- /// Initializes a new instance of the class.
- ///
- /// Color depth, in number of bits per pixel.
- public PixelTypeInfo(int bitsPerPixel)
- => this.BitsPerPixel = bitsPerPixel;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// Color depth, in number of bits per pixel.
- /// The pixel alpha transparency behavior.
- public PixelTypeInfo(int bitsPerPixel, PixelAlphaRepresentation alpha)
- {
- this.BitsPerPixel = bitsPerPixel;
- this.AlphaRepresentation = alpha;
- }
-
- ///
- /// Gets color depth, in number of bits per pixel.
- ///
- public int BitsPerPixel { get; }
-
- ///
- /// Gets the pixel alpha transparency behavior.
- /// means unknown, unspecified.
- ///
- public PixelAlphaRepresentation? AlphaRepresentation { get; }
-
- internal static PixelTypeInfo Create()
- where TPixel : unmanaged, IPixel
- => new(Unsafe.SizeOf() * 8);
-
- internal static PixelTypeInfo Create(PixelAlphaRepresentation alpha)
- where TPixel : unmanaged, IPixel
- => new(Unsafe.SizeOf() * 8, alpha);
-}
diff --git a/src/ImageSharp/Formats/Png/PngBitDepth.cs b/src/ImageSharp/Formats/Png/PngBitDepth.cs
index 452839d1d..a5cd2026b 100644
--- a/src/ImageSharp/Formats/Png/PngBitDepth.cs
+++ b/src/ImageSharp/Formats/Png/PngBitDepth.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Six Labors.
+// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
// Note the value assignment, This will allow us to add 1, 2, and 4 bit encoding when we support it.
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index 3eabbdef0..4178d2820 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 e348d7467..aa3603cfb 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;
@@ -1466,23 +1466,48 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
// Use options, then check metadata, if nothing set there then we suggest
// a sensible default based upon the pixel format.
- this.colorType = encoder.ColorType ?? pngMetadata.ColorType ?? SuggestColorType();
- if (!encoder.FilterMethod.HasValue)
+ PngColorType? colorType = encoder.ColorType ?? pngMetadata.ColorType;
+ byte? bits = (byte?)(encoder.BitDepth ?? pngMetadata.BitDepth);
+
+ if (colorType is null || bits is null)
{
- // Specification recommends default filter method None for paletted images and Paeth for others.
- this.filterMethod = this.colorType is PngColorType.Palette ? PngFilterMethod.None : PngFilterMethod.Paeth;
+ PixelTypeInfo info = TPixel.GetPixelTypeInfo();
+ PixelComponentInfo? componentInfo = info.ComponentInfo;
+
+ colorType ??= SuggestColorType(in info);
+
+ if (bits is null)
+ {
+ // TODO: Update once we stop abusing PixelTypeInfo in decoders.
+ if (componentInfo.HasValue)
+ {
+ PixelComponentInfo c = componentInfo.Value;
+ bits = (byte)SuggestBitDepth(in c);
+ }
+ else
+ {
+ bits = (byte)PngBitDepth.Bit8;
+ }
+ }
}
// Ensure bit depth and color type are a supported combination.
// Bit8 is the only bit depth supported by all color types.
- byte bits = (byte)(encoder.BitDepth ?? pngMetadata.BitDepth ?? SuggestBitDepth());
- byte[] validBitDepths = PngConstants.ColorTypes[this.colorType];
+ byte[] validBitDepths = PngConstants.ColorTypes[colorType.Value];
if (Array.IndexOf(validBitDepths, bits) == -1)
{
bits = (byte)PngBitDepth.Bit8;
}
- this.bitDepth = bits;
+ this.colorType = colorType.Value;
+ this.bitDepth = bits.Value;
+
+ if (!encoder.FilterMethod.HasValue)
+ {
+ // Specification recommends default filter method None for paletted images and Paeth for others.
+ this.filterMethod = this.colorType is PngColorType.Palette ? PngFilterMethod.None : PngFilterMethod.Paeth;
+ }
+
use16Bit = bits == (byte)PngBitDepth.Bit16;
bytesPerPixel = CalculateBytesPerPixel(this.colorType, use16Bit);
@@ -1611,53 +1636,44 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
///
/// Returns a suggested for the given
- /// This is not exhaustive but covers many common pixel formats.
///
+ /// The pixel type info.
/// The type of pixel format.
- private static PngColorType SuggestColorType()
+ private static PngColorType SuggestColorType(in PixelTypeInfo info)
where TPixel : unmanaged, IPixel
- => default(TPixel) switch
- {
- A8 => PngColorType.GrayscaleWithAlpha,
- Argb32 => PngColorType.RgbWithAlpha,
- Bgr24 => PngColorType.Rgb,
- Bgra32 => PngColorType.RgbWithAlpha,
- L8 => PngColorType.Grayscale,
- L16 => PngColorType.Grayscale,
- La16 => PngColorType.GrayscaleWithAlpha,
- La32 => PngColorType.GrayscaleWithAlpha,
- Rgb24 => PngColorType.Rgb,
- Rgba32 => PngColorType.RgbWithAlpha,
- Rgb48 => PngColorType.Rgb,
- Rgba64 => PngColorType.RgbWithAlpha,
- RgbaVector => PngColorType.RgbWithAlpha,
- _ => PngColorType.RgbWithAlpha
+ {
+ if (info.AlphaRepresentation == PixelAlphaRepresentation.None)
+ {
+ return info.ColorType switch
+ {
+ PixelColorType.Grayscale => PngColorType.Grayscale,
+ _ => PngColorType.Rgb,
+ };
+ }
+
+ return info.ColorType switch
+ {
+ PixelColorType.Grayscale | PixelColorType.Alpha or PixelColorType.Alpha => PngColorType.GrayscaleWithAlpha,
+ _ => PngColorType.RgbWithAlpha,
};
+ }
///
/// Returns a suggested for the given
- /// This is not exhaustive but covers many common pixel formats.
///
+ /// The pixel type info.
/// The type of pixel format.
- private static PngBitDepth SuggestBitDepth()
+ private static PngBitDepth SuggestBitDepth(in PixelComponentInfo info)
where TPixel : unmanaged, IPixel
- => default(TPixel) switch
- {
- A8 => PngBitDepth.Bit8,
- Argb32 => PngBitDepth.Bit8,
- Bgr24 => PngBitDepth.Bit8,
- Bgra32 => PngBitDepth.Bit8,
- L8 => PngBitDepth.Bit8,
- L16 => PngBitDepth.Bit16,
- La16 => PngBitDepth.Bit8,
- La32 => PngBitDepth.Bit16,
- Rgb24 => PngBitDepth.Bit8,
- Rgba32 => PngBitDepth.Bit8,
- Rgb48 => PngBitDepth.Bit16,
- Rgba64 => PngBitDepth.Bit16,
- RgbaVector => PngBitDepth.Bit16,
- _ => PngBitDepth.Bit8
- };
+ {
+ int bits = info.GetMaximumComponentPrecision();
+ if (bits > (int)PixelComponentBitDepth.Bit8)
+ {
+ return PngBitDepth.Bit16;
+ }
+
+ return PngBitDepth.Bit8;
+ }
private unsafe struct ScratchBuffer
{
diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
index f217515e3..39b3fff27 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 a8a70f727..89d1b9d20 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/CieLabPlanarTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs
index 216d17330..eb2fe353e 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabPlanarTiffColor{TPixel}.cs
@@ -27,17 +27,17 @@ internal class CieLabPlanarTiffColor : TiffBasePlanarColorDecoder a = data[1].GetSpan();
Span b = data[2].GetSpan();
- var color = default(TPixel);
+ TPixel color = default;
int offset = 0;
for (int y = top; y < top + height; y++)
{
Span pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width);
for (int x = 0; x < pixelRow.Length; x++)
{
- var lab = new CieLab((l[offset] & 0xFF) * 100f * Inv255, (sbyte)a[offset], (sbyte)b[offset]);
- var rgb = ColorSpaceConverter.ToRgb(lab);
+ CieLab lab = new((l[offset] & 0xFF) * 100f * Inv255, (sbyte)a[offset], (sbyte)b[offset]);
+ Rgb rgb = ColorSpaceConverter.ToRgb(lab);
- color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
+ color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset++;
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs
index b39a64644..f5418774b 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CieLabTiffColor{TPixel}.cs
@@ -34,7 +34,7 @@ internal class CieLabTiffColor : TiffBaseColorDecoder
CieLab lab = new(l, (sbyte)data[offset + 1], (sbyte)data[offset + 2]);
Rgb rgb = ColorSpaceConverter.ToRgb(lab);
- color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
+ color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset += 3;
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CmykTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CmykTiffColor{TPixel}.cs
index c87051d52..2074fb254 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CmykTiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/CmykTiffColor{TPixel}.cs
@@ -27,7 +27,7 @@ internal class CmykTiffColor : TiffBaseColorDecoder
Cmyk cmyk = new(data[offset] * Inv255, data[offset + 1] * Inv255, data[offset + 2] * Inv255, data[offset + 3] * Inv255);
Rgb rgb = ColorSpaceConverter.ToRgb(in cmyk);
- color.FromVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
+ color.FromScaledVector4(new Vector4(rgb.R, rgb.G, rgb.B, 1.0f));
pixelRow[x] = color;
offset += 4;
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs
index c5b662979..4cba8f2d7 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 9ffda0f51..c98be1fcd 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 65f1a4da4..70372fe98 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 69a0afcd9..2991f355f 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 00319e9b5..c0d1f27ca 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 c24014e69..e12631cbd 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;
@@ -78,7 +77,7 @@ public sealed class Image : Image
/// The height of the image in pixels.
/// The images metadata.
internal Image(Configuration configuration, int width, int height, ImageMetadata? metadata)
- : base(configuration, PixelTypeInfo.Create(), metadata ?? new(), width, height)
+ : base(configuration, TPixel.GetPixelTypeInfo(), metadata ?? new(), width, height)
=> this.frames = new ImageFrameCollection(this, width, height, default(TPixel));
///
@@ -111,7 +110,7 @@ public sealed class Image : Image
int width,
int height,
ImageMetadata metadata)
- : base(configuration, PixelTypeInfo.Create(), metadata, width, height)
+ : base(configuration, TPixel.GetPixelTypeInfo(), metadata, width, height)
=> this.frames = new ImageFrameCollection(this, width, height, memoryGroup);
///
@@ -129,7 +128,7 @@ public sealed class Image : Image
int height,
TPixel backgroundColor,
ImageMetadata? metadata)
- : base(configuration, PixelTypeInfo.Create(), metadata ?? new(), width, height)
+ : base(configuration, TPixel.GetPixelTypeInfo(), metadata ?? new(), width, height)
=> this.frames = new ImageFrameCollection(this, width, height, backgroundColor);
///
@@ -140,7 +139,7 @@ public sealed class Image : Image
/// The images metadata.
/// The frames that will be owned by this image instance.
internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable> frames)
- : base(configuration, PixelTypeInfo.Create(), metadata, ValidateFramesAndGetSize(frames))
+ : base(configuration, TPixel.GetPixelTypeInfo(), metadata, ValidateFramesAndGetSize(frames))
=> this.frames = new ImageFrameCollection(this, frames);
///
diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs
index 099444466..b28911a90 100644
--- a/src/ImageSharp/PixelFormats/IPixel.cs
+++ b/src/ImageSharp/PixelFormats/IPixel.cs
@@ -14,6 +14,14 @@ namespace SixLabors.ImageSharp.PixelFormats;
public interface IPixel : IPixel, IEquatable
where TSelf : unmanaged, IPixel
{
+ ///
+ /// Gets the pixel type information.
+ ///
+ /// The .
+#pragma warning disable CA1000
+ static abstract PixelTypeInfo GetPixelTypeInfo();
+#pragma warning restore CA1000
+
///
/// Creates a instance for this pixel type.
/// This method is not intended to be consumed directly. Use instead.
diff --git a/src/ImageSharp/PixelFormats/PixelColorType.cs b/src/ImageSharp/PixelFormats/PixelColorType.cs
new file mode 100644
index 000000000..9ac2c308c
--- /dev/null
+++ b/src/ImageSharp/PixelFormats/PixelColorType.cs
@@ -0,0 +1,46 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+namespace SixLabors.ImageSharp.PixelFormats;
+
+///
+/// Represents the color type and format of a pixel.
+///
+[Flags]
+public enum PixelColorType
+{
+ ///
+ /// Represents the Red component of the color.
+ ///
+ Red = 1 << 0,
+
+ ///
+ /// Represents the Green component of the color.
+ ///
+ Green = 1 << 1,
+
+ ///
+ /// Represents the Blue component of the color.
+ ///
+ Blue = 1 << 2,
+
+ ///
+ /// Represents the Alpha component of the color for transparency.
+ ///
+ Alpha = 1 << 3,
+
+ ///
+ /// Indicates that the color is in grayscale.
+ ///
+ Grayscale = 1 << 4,
+
+ ///
+ /// Indicates that the color is in RGB (Red, Green, Blue) format.
+ ///
+ RGB = Red | Green | Blue | (1 << 5),
+
+ ///
+ /// Indicates that the color is in BGR (Blue, Green, Red) format.
+ ///
+ BGR = Blue | Green | Red | (1 << 6)
+}
diff --git a/src/ImageSharp/PixelFormats/PixelComponentBitDepth.cs b/src/ImageSharp/PixelFormats/PixelComponentBitDepth.cs
new file mode 100644
index 000000000..674c9363b
--- /dev/null
+++ b/src/ImageSharp/PixelFormats/PixelComponentBitDepth.cs
@@ -0,0 +1,50 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+namespace SixLabors.ImageSharp.PixelFormats;
+
+///
+/// Provides enumeration of the precision in bits of individual components within a pixel format.
+///
+public enum PixelComponentBitDepth
+{
+ ///
+ /// 1 bit per component.
+ ///
+ Bit1 = 1,
+
+ ///
+ /// 2 bits per component.
+ ///
+ Bit2 = 2,
+
+ ///
+ /// 4 bits per component.
+ ///
+ Bit4 = 4,
+
+ ///
+ /// 8 bits per component.
+ ///
+ Bit8 = 8,
+
+ ///
+ /// 16 bits per component.
+ ///
+ Bit16 = 16,
+
+ ///
+ /// 32 bits per component.
+ ///
+ Bit32 = 32,
+
+ ///
+ /// 64 bits per component.
+ ///
+ Bit64 = 64,
+
+ ///
+ /// 128 bits per component.
+ ///
+ Bit128 = 128
+}
diff --git a/src/ImageSharp/PixelFormats/PixelComponentInfo.cs b/src/ImageSharp/PixelFormats/PixelComponentInfo.cs
new file mode 100644
index 000000000..a76105414
--- /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/PixelImplementations/A8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
index 025690712..23dae82ab 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
@@ -55,6 +55,13 @@ public partial struct A8 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(1, 8),
+ PixelColorType.Alpha,
+ 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 8bd24c7a0..742f27cc0 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Abgr32.cs
@@ -145,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.
///
@@ -183,6 +167,13 @@ public partial struct Abgr32 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Abgr32 left, Abgr32 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 8, 8, 8, 8),
+ PixelColorType.Alpha | PixelColorType.BGR,
+ 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 fa8af98a0..7a8ee2a63 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
@@ -145,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.
///
@@ -183,6 +167,13 @@ public partial struct Argb32 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Argb32 left, Argb32 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 8, 8, 8, 8),
+ PixelColorType.Alpha | PixelColorType.RGB,
+ 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 aedf4ad19..bdf7d1a7e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
@@ -49,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.
///
@@ -87,6 +71,13 @@ public partial struct Bgr24 : IPixel
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgr24 left, Bgr24 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(3, 8, 8, 8),
+ PixelColorType.BGR,
+ 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 ac3b6f829..0874eb825 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
@@ -59,6 +59,13 @@ public partial struct Bgr565 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgr565 left, Bgr565 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(3, 5, 6, 5),
+ PixelColorType.BGR,
+ 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 d7222f2ef..f50846357 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
@@ -98,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.
///
@@ -136,6 +120,13 @@ public partial struct Bgra32 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra32 left, Bgra32 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 8, 8, 8, 8),
+ PixelColorType.BGR | PixelColorType.Alpha,
+ 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 8ba32c8ac..4bb3f8a0e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
@@ -57,6 +57,13 @@ public partial struct Bgra4444 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra4444 left, Bgra4444 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 4, 4, 4, 4),
+ PixelColorType.BGR | PixelColorType.Alpha,
+ 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 c282f03d8..d57545dee 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
@@ -60,6 +60,13 @@ public partial struct Bgra5551 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Bgra5551 left, Bgra5551 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 5, 5, 5, 1),
+ PixelColorType.BGR | PixelColorType.Alpha,
+ 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 e699e5fe5..d8f1dd0ac 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
@@ -60,6 +60,13 @@ public partial struct Byte4 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Byte4 left, Byte4 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 8, 8, 8, 8),
+ PixelColorType.RGB | PixelColorType.Alpha,
+ 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 db1e02adc..01ae9fc5f 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
@@ -45,6 +45,13 @@ public partial struct HalfSingle : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfSingle left, HalfSingle right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(1, 16),
+ PixelColorType.Red,
+ PixelAlphaRepresentation.None);
+
///
public PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
index 9caae58c9..d591dd855 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
@@ -52,6 +52,13 @@ public partial struct HalfVector2 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfVector2 left, HalfVector2 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(2, 16, 16),
+ PixelColorType.Red | PixelColorType.Green,
+ 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 609fec3bd..ca6bff230 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
@@ -57,6 +57,13 @@ public partial struct HalfVector4 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(HalfVector4 left, HalfVector4 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 16, 16, 16, 16),
+ PixelColorType.RGB | PixelColorType.Alpha,
+ 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 c6ee8744d..8522da3fb 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
@@ -47,6 +47,13 @@ public partial struct L16 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(L16 left, L16 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(1, 16),
+ PixelColorType.Grayscale,
+ 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 383e09b27..706fc1101 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
@@ -48,6 +48,13 @@ public partial struct L8 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(L8 left, L8 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(1, 8),
+ PixelColorType.Grayscale,
+ 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 58aeb6189..e30673153 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
@@ -71,6 +71,13 @@ public partial struct La16 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(La16 left, La16 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(2, 8, 8),
+ PixelColorType.Grayscale | PixelColorType.Alpha,
+ 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 db7f43329..867bfacd3 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
@@ -73,6 +73,13 @@ public partial struct La32 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(La32 left, La32 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(2, 16, 16),
+ PixelColorType.Grayscale | PixelColorType.Alpha,
+ 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 92b9e6148..c5eb2c2de 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
@@ -60,6 +60,13 @@ public partial struct NormalizedByte2 : IPixel, IPackedVector !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(2, 8, 8),
+ PixelColorType.Red | PixelColorType.Green,
+ 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 f87bb5a60..6cf92688e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
@@ -62,6 +62,13 @@ public partial struct NormalizedByte4 : IPixel, IPackedVector !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 8, 8, 8, 8),
+ PixelColorType.RGB | PixelColorType.Alpha,
+ 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 f77dd69b7..03fa2737e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
@@ -61,6 +61,13 @@ public partial struct NormalizedShort2 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedShort2 left, NormalizedShort2 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(2, 16, 16),
+ PixelColorType.Red | PixelColorType.Green,
+ 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 989edbd2b..89ba2a23b 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
@@ -63,6 +63,13 @@ public partial struct NormalizedShort4 : IPixel, IPackedVector
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(NormalizedShort4 left, NormalizedShort4 right) => !left.Equals(right);
+ ///
+ public static PixelTypeInfo GetPixelTypeInfo()
+ => PixelTypeInfo.Create(
+ PixelComponentInfo.Create(4, 16, 16, 16, 16),
+ PixelColorType.RGB | PixelColorType.Alpha,
+ PixelAlphaRepresentation.Unassociated);
+
///
public readonly PixelOperations CreatePixelOperations() => new PixelOperations();
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs
index a7b4b5df0..131191ee2 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/A8.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct A8
///
/// Provides optimized overrides for bulk operations.
///
- internal class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true);
-
- ///
- public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
- }
+ internal class PixelOperations : PixelOperations;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs
index 66f3ecb24..17ca5edd8 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Abgr32.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct Abgr32
///
/// Provides optimized overrides for bulk operations.
///
- internal partial class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true);
-
- ///
- public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
- }
+ internal partial class PixelOperations : PixelOperations;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs
index 894e92963..f2a5eb28b 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Argb32.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct Argb32
///
/// Provides optimized overrides for bulk operations.
///
- internal partial class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true);
-
- ///
- public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
- }
+ internal partial class PixelOperations : PixelOperations;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs
index a8f6ab155..05b198636 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr24.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct Bgr24
///
/// Provides optimized overrides for bulk operations.
///
- internal partial class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true);
-
- ///
- public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
- }
+ internal partial class PixelOperations : PixelOperations;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs
index de9690325..7217b7c0b 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgr565.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct Bgr565
///
/// Provides optimized overrides for bulk operations.
///
- internal class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.None), true);
-
- ///
- public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
- }
+ internal class PixelOperations : PixelOperations;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs
index 1a62b0809..0d77f8566 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra32.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct Bgra32
///
/// Provides optimized overrides for bulk operations.
///
- internal partial class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true);
-
- ///
- public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
- }
+ internal partial class PixelOperations : PixelOperations;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs
index 8ffdaf6cb..5f516f094 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra4444.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct Bgra4444
///
/// Provides optimized overrides for bulk operations.
///
- internal class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true);
-
- ///
- public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
- }
+ internal class PixelOperations : PixelOperations;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs
index 97f5d805e..ea11e5309 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Bgra5551.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct Bgra5551
///
/// Provides optimized overrides for bulk operations.
///
- internal partial class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy(() => PixelTypeInfo.Create(PixelAlphaRepresentation.Unassociated), true);
-
- ///
- public override PixelTypeInfo GetPixelTypeInfo() => LazyInfo.Value;
- }
+ internal partial class PixelOperations : PixelOperations;
}
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs
index f6e0b833c..0946dd4c7 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/PixelOperations/Byte4.PixelOperations.cs
@@ -13,12 +13,5 @@ public partial struct Byte4
///
/// Provides optimized overrides for bulk operations.
///
- internal class PixelOperations : PixelOperations
- {
- private static readonly Lazy LazyInfo =
- new Lazy