diff --git a/ImageProcessorCore.sln b/ImageProcessorCore.sln
index 9d828a74a0..28b7b107c3 100644
--- a/ImageProcessorCore.sln
+++ b/ImageProcessorCore.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
-VisualStudioVersion = 14.0.25123.0
+VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageProcessorCore", "src\ImageProcessorCore\ImageProcessorCore.xproj", "{2AA31A1F-142C-43F4-8687-09ABCA4B3A26}"
EndProject
diff --git a/NuGet.config b/NuGet.config
index 554c2f634b..05430a8ee7 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -1,6 +1,7 @@
-
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 85edc99565..65168b6bde 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+
# ImageProcessorCore
@@ -74,6 +75,7 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- Resampling algorithms. (Optional gamma correction, resize modes, Performance improvements?)
- [x] Box
- [x] Bicubic
+ - [x] Lanczos2
- [x] Lanczos3
- [x] Lanczos5
- [x] Lanczos8
@@ -81,7 +83,6 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- [x] Nearest Neighbour
- [x] Robidoux
- [x] Robidoux Sharp
- - [x] Robidoux Soft
- [x] Spline
- [x] Triangle
- [x] Welch
@@ -100,8 +101,8 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- [x] Skew by x/y angles and center point.
- ColorMatrix operations (Uses Matrix4x4)
- [x] BlackWhite
- - [x] Greyscale BT709
- - [x] Greyscale BT601
+ - [x] Grayscale BT709
+ - [x] Grayscale BT601
- [x] Hue
- [x] Saturation
- [x] Lomograph
@@ -160,7 +161,7 @@ With this version the API will change dramatically. Without the constraints of `
Image methods are also fluent which allow chaining much like the `ImageFactory` class in the Framework version.
-Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their greyscale equivalent using the BT709 standard matrix.
+Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their grayscale equivalent using the BT709 standard matrix.
```csharp
using (FileStream stream = File.OpenRead("foo.jpg"))
@@ -168,32 +169,12 @@ using (FileStream output = File.OpenWrite("bar.jpg"))
{
Image image = new Image(stream);
image.Resize(image.Width / 2, image.Height / 2)
- .Greyscale()
+ .Grayscale()
.Save(output);
}
```
-It will also be possible to pass collections of processors as params to manipulate images. For example here I am applying a Gaussian blur with a sigma of 5 to an image, then detecting the edges using a Sobel operator working in greyscale mode.
-
-```csharp
-using (FileStream stream = File.OpenRead("foo.jpg"))
-using (FileStream output = File.OpenWrite("bar.jpg"))
-{
- Image image = new Image(stream);
- List processors = new List()
- {
- new GuassianBlur(5),
- new Sobel { Greyscale = true }
- };
-
- foreach (IImageProcessor processor in processors){
-
- image.Process(processor)
- .Save(output);
- }
-}
-```
-Individual processors can be initialised and apply processing against images. This allows nesting which will allow the powerful combination of processing methods:
+Individual processors can be initialised and apply processing against images. This allows nesting which brings the potential for powerful combinations of processing methods:
```csharp
new Brightness(50).Apply(sourceImage, targetImage, sourceImage.Bounds);
diff --git a/src/ImageProcessorCore/Bootstrapper.cs b/src/ImageProcessorCore/Bootstrapper.cs
index a9c7dc8318..99fa6f1555 100644
--- a/src/ImageProcessorCore/Bootstrapper.cs
+++ b/src/ImageProcessorCore/Bootstrapper.cs
@@ -8,7 +8,10 @@ namespace ImageProcessorCore
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
- using ImageProcessorCore.Formats;
+ using System.Reflection;
+ using System.Threading.Tasks;
+
+ using Formats;
///
/// Provides initialization code which allows extending the library.
@@ -26,18 +29,25 @@ namespace ImageProcessorCore
///
private readonly List imageFormats;
+ private readonly Dictionary> pixelAccessors;
+
///
/// Prevents a default instance of the class from being created.
///
private Bootstrapper()
{
- this.imageFormats = new List(new List
+ this.imageFormats = new List
{
new BmpFormat(),
new JpegFormat(),
new PngFormat(),
new GifFormat()
- });
+ };
+
+ this.pixelAccessors = new Dictionary>
+ {
+ { typeof(Color), i=> new ColorPixelAccessor(i) }
+ };
}
///
@@ -46,9 +56,21 @@ namespace ImageProcessorCore
public static Bootstrapper Instance = Lazy.Value;
///
- /// Gets the list of supported
+ /// Gets the collection of supported
+ ///
+ public IReadOnlyCollection ImageFormats =>
+ new ReadOnlyCollection(this.imageFormats);
+
+ ///
+ /// Gets the collection of supported pixel accessors
+ ///
+ public IReadOnlyDictionary> PixelAccessors =>
+ new ReadOnlyDictionary>(this.pixelAccessors);
+
+ ///
+ /// Gets or sets the global parallel options for processing tasks in parallel.
///
- public IReadOnlyCollection ImageFormats => new ReadOnlyCollection(this.imageFormats);
+ public ParallelOptions ParallelOptions { get; set; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
///
/// Adds a new to the collection of supported image formats.
@@ -58,5 +80,40 @@ namespace ImageProcessorCore
{
this.imageFormats.Add(format);
}
+
+ ///
+ /// Adds a pixel accessor for the given pixel format.
+ ///
+ /// The packed format type, must implement
+ /// The function to return a new instance of the pixel accessor.
+ public void AddPixelAccessor(Type packedType, Func initializer)
+ {
+ if (!typeof(IPackedVector).GetTypeInfo().IsAssignableFrom(packedType.GetTypeInfo()))
+ {
+ throw new ArgumentException($"Type {packedType} must implement {nameof(IPackedVector)}");
+ }
+
+ this.pixelAccessors.Add(packedType, initializer);
+ }
+
+ ///
+ /// Gets an instance of the correct for the packed vector.
+ ///
+ /// The type of pixel data.
+ /// The packed format. long, float.
+ /// The image
+ /// The
+ public IPixelAccessor GetPixelAccessor(IImageBase image)
+ where T : IPackedVector
+ where TP : struct
+ {
+ Type packed = typeof(T);
+ if (this.pixelAccessors.ContainsKey(packed))
+ {
+ return (IPixelAccessor)this.pixelAccessors[packed].Invoke(image);
+ }
+
+ throw new NotSupportedException($"PixelAccessor cannot be loaded for {packed}:");
+ }
}
}
diff --git a/src/ImageProcessorCore/Colors/Color.cs b/src/ImageProcessorCore/Colors/Color.cs
index 0e47e03e1b..69bce48536 100644
--- a/src/ImageProcessorCore/Colors/Color.cs
+++ b/src/ImageProcessorCore/Colors/Color.cs
@@ -6,46 +6,65 @@
namespace ImageProcessorCore
{
using System;
- using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
+ using System.Runtime.InteropServices;
///
- /// Represents a four-component color using red, green, blue, and alpha data.
- /// Each component is stored in premultiplied format multiplied by the alpha component.
+ /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255.
+ /// The color components are stored in red, green, blue, and alpha order.
///
///
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
///
- public partial struct Color : IEquatable, IAlmostEquatable
+ [StructLayout(LayoutKind.Explicit)]
+ public partial struct Color : IPackedVector, IEquatable
{
///
- /// Represents an empty that has R, G, B, and A values set to zero.
+ /// Gets or sets the blue component.
///
- public static readonly Color Empty = default(Color);
+ [FieldOffset(0)]
+ public byte R;
///
- /// The epsilon for comparing floating point numbers.
+ /// Gets or sets the green component.
///
- private const float Epsilon = 0.001f;
+ [FieldOffset(1)]
+ public byte G;
///
- /// The backing vector for SIMD support.
+ /// Gets or sets the red component.
///
- private Vector4 backingVector;
+ [FieldOffset(2)]
+ public byte B;
///
- /// Initializes a new instance of the struct.
+ /// Gets or sets the alpha component.
///
- /// The red component of this .
- /// The green component of this .
- /// The blue component of this .
- /// The alpha component of this .
- public Color(float r, float g, float b, float a = 1)
+ [FieldOffset(3)]
+ public byte A;
+
+ ///
+ /// The packed value.
+ ///
+ [FieldOffset(0)]
+ private readonly uint packedValue;
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The red component.
+ /// The green component.
+ /// The blue component.
+ /// The alpha component.
+ public Color(byte r, byte g, byte b, byte a = 255)
: this()
{
- this.backingVector = new Vector4(r, g, b, a);
+ this.R = r;
+ this.G = g;
+ this.B = b;
+ this.A = a;
}
///
@@ -68,25 +87,17 @@ namespace ImageProcessorCore
if (hex.Length == 8)
{
- float r = Convert.ToByte(hex.Substring(2, 2), 16);
- float g = Convert.ToByte(hex.Substring(4, 2), 16);
- float b = Convert.ToByte(hex.Substring(6, 2), 16);
- float a = Convert.ToByte(hex.Substring(0, 2), 16);
-
- // Do division of Vector4 instead of each component to utilize SIMD optimizations
- this.backingVector = new Vector4(r, g, b, a) / 255f;
- this.backingVector = FromNonPremultiplied(this.backingVector, this.A);
-
+ this.R = Convert.ToByte(hex.Substring(2, 2), 16);
+ this.G = Convert.ToByte(hex.Substring(4, 2), 16);
+ this.B = Convert.ToByte(hex.Substring(6, 2), 16);
+ this.A = Convert.ToByte(hex.Substring(0, 2), 16);
}
else if (hex.Length == 6)
{
- float r = Convert.ToByte(hex.Substring(0, 2), 16);
- float g = Convert.ToByte(hex.Substring(2, 2), 16);
- float b = Convert.ToByte(hex.Substring(4, 2), 16);
- float a = 255f;
-
- // Do division of Vector4 instead of each component to utilize SIMD optimizations
- this.backingVector = new Vector4(r, g, b, a) / 255f;
+ this.R = Convert.ToByte(hex.Substring(0, 2), 16);
+ this.G = Convert.ToByte(hex.Substring(2, 2), 16);
+ this.B = Convert.ToByte(hex.Substring(4, 2), 16);
+ this.A = 255;
}
else
{
@@ -94,185 +105,60 @@ namespace ImageProcessorCore
string gh = char.ToString(hex[1]);
string bh = char.ToString(hex[2]);
- float r = Convert.ToByte(rh + rh, 16);
- float g = Convert.ToByte(gh + gh, 16);
- float b = Convert.ToByte(bh + bh, 16);
- float a = 255f;
-
- this.backingVector = new Vector4(r, g, b, a) / 255f;
+ this.R = Convert.ToByte(rh + rh, 16);
+ this.G = Convert.ToByte(gh + gh, 16);
+ this.B = Convert.ToByte(bh + bh, 16);
+ this.A = 255;
}
}
///
- /// Initializes a new instance of the struct.
+ /// Initializes a new instance of the struct.
///
- /// The vector.
- public Color(Vector4 vector)
+ /// The red component.
+ /// The green component.
+ /// The blue component.
+ /// The alpha component.
+ public Color(float r, float g, float b, float a = 1)
+ : this()
{
- this.backingVector = vector;
+ Vector4 clamped = Vector4.Clamp(new Vector4(r, g, b, a), Vector4.Zero, Vector4.One) * 255F;
+ this.R = (byte)Math.Round(clamped.X);
+ this.G = (byte)Math.Round(clamped.Y);
+ this.B = (byte)Math.Round(clamped.Z);
+ this.A = (byte)Math.Round(clamped.W);
}
///
- /// Initializes a new instance of the struct.
+ /// Initializes a new instance of the struct.
///
///
- /// The vector representing the red, green, and blue componenets.
+ /// The vector containing the components for the packed vector.
///
public Color(Vector3 vector)
+ : this()
{
- this.backingVector = new Vector4(vector, 1);
+ Vector3 clamped = Vector3.Clamp(vector, Vector3.Zero, Vector3.One) * 255F;
+ this.R = (byte)Math.Round(clamped.X);
+ this.G = (byte)Math.Round(clamped.Y);
+ this.B = (byte)Math.Round(clamped.Z);
+ this.A = 255;
}
///
- /// Initializes a new instance of the struct.
+ /// Initializes a new instance of the struct.
///
///
- /// The vector representing the red, green, and blue componenets.
+ /// The vector containing the components for the packed vector.
///
- /// The alpha component.
- public Color(Vector3 vector, float alpha)
- {
- this.backingVector = new Vector4(vector, alpha);
- }
-
- ///
- /// Gets or sets the red component of the color.
- ///
- public float R
- {
- get
- {
- return this.backingVector.X;
- }
-
- set
- {
- this.backingVector.X = value;
- }
- }
-
- ///
- /// Gets or sets the green component of the color.
- ///
- public float G
- {
- get
- {
- return this.backingVector.Y;
- }
-
- set
- {
- this.backingVector.Y = value;
- }
- }
-
- ///
- /// Gets or sets the blue component of the color.
- ///
- public float B
- {
- get
- {
- return this.backingVector.Z;
- }
-
- set
- {
- this.backingVector.Z = value;
- }
- }
-
- ///
- /// Gets or sets the alpha component of the color.
- ///
- public float A
- {
- get
- {
- return this.backingVector.W;
- }
-
- set
- {
- this.backingVector.W = value;
- }
- }
-
- ///
- /// Gets a value indicating whether this is empty.
- ///
- [EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsEmpty => this.Equals(Empty);
-
- ///
- /// Gets this color with the component values clamped from 0 to 1.
- ///
- public Color Limited => new Color(Vector4.Clamp(this.backingVector, Vector4.Zero, Vector4.One));
-
- ///
- /// Computes the product of multiplying a color by a given factor.
- ///
- /// The color.
- /// The multiplication factor.
- ///
- /// The
- ///
- public static Color operator *(Color color, float factor)
- {
- return new Color(color.backingVector * factor);
- }
-
- ///
- /// Computes the product of multiplying a color by a given factor.
- ///
- /// The multiplication factor.
- /// The color.
- ///
- /// The
- ///
- public static Color operator *(float factor, Color color)
- {
- return new Color(color.backingVector * factor);
- }
-
- ///
- /// Computes the product of multiplying two colors.
- ///
- /// The color on the left hand of the operand.
- /// The color on the right hand of the operand.
- ///
- /// The
- ///
- public static Color operator *(Color left, Color right)
- {
- return new Color(left.backingVector * right.backingVector);
- }
-
- ///
- /// Computes the sum of adding two colors.
- ///
- /// The color on the left hand of the operand.
- /// The color on the right hand of the operand.
- ///
- /// The
- ///
- public static Color operator +(Color left, Color right)
- {
- return new Color(left.backingVector + right.backingVector);
- }
-
- ///
- /// Computes the difference left by subtracting one color from another.
- ///
- /// The color on the left hand of the operand.
- /// The color on the right hand of the operand.
- ///
- /// The
- ///
- public static Color operator -(Color left, Color right)
+ public Color(Vector4 vector)
+ : this()
{
- return new Color(left.backingVector - right.backingVector);
+ Vector4 clamped = Vector4.Clamp(vector, Vector4.Zero, Vector4.One) * 255F;
+ this.R = (byte)Math.Round(clamped.X);
+ this.G = (byte)Math.Round(clamped.Y);
+ this.B = (byte)Math.Round(clamped.Z);
+ this.A = (byte)Math.Round(clamped.W);
}
///
@@ -289,230 +175,99 @@ namespace ImageProcessorCore
///
public static bool operator ==(Color left, Color right)
{
- return left.Equals(right);
+ return left.packedValue == right.packedValue;
}
///
- /// Compares two objects for inequality.
+ /// Compares two objects for equality.
///
- ///
- /// The on the left side of the operand.
- ///
- ///
- /// The on the right side of the operand.
- ///
+ /// The on the left side of the operand.
+ /// The on the right side of the operand.
///
- /// True if the current left is unequal to the parameter; otherwise, false.
+ /// True if the current left is equal to the parameter; otherwise, false.
///
public static bool operator !=(Color left, Color right)
{
- return !left.Equals(right);
- }
-
- ///
- /// Returns a new color whose components are the average of the components of first and second.
- ///
- /// The first color.
- /// The second color.
- ///
- /// The
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Color Average(Color first, Color second)
- {
- return new Color((first.backingVector + second.backingVector) * .5f);
- }
-
- ///
- /// Compresses a linear color signal to its sRGB equivalent.
- ///
- ///
- ///
- /// The whose signal to compress.
- /// The .
- public static Color Compress(Color linear)
- {
- // TODO: Is there a faster way to do this?
- float r = Compress(linear.R);
- float g = Compress(linear.G);
- float b = Compress(linear.B);
-
- return new Color(r, g, b, linear.A);
- }
-
- ///
- /// Expands an sRGB color signal to its linear equivalent.
- ///
- ///
- ///
- /// The whose signal to expand.
- /// The .
- public static Color Expand(Color gamma)
- {
- // TODO: Is there a faster way to do this?
- float r = Expand(gamma.R);
- float g = Expand(gamma.G);
- float b = Expand(gamma.B);
-
- return new Color(r, g, b, gamma.A);
- }
-
- ///
- /// Converts a non-premultipled alpha to a
- /// that contains premultiplied alpha.
- ///
- /// The to convert.
- /// The .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Color FromNonPremultiplied(Color color)
- {
- return new Color(FromNonPremultiplied(color.backingVector, color.A));
- }
-
- ///
- /// Converts a non-premultiplied alpha Vector4 to a Vector4 that contains premultiplied alpha.
- ///
- /// The vector to convert.
- /// The alpha to use in conversion.
- /// The Vector4 with premultiplied alpha.
- private static Vector4 FromNonPremultiplied(Vector4 vector, float alpha)
- {
- return vector * new Vector4(alpha, alpha, alpha, 1);
+ return left.packedValue != right.packedValue;
}
- ///
- /// Converts a premultipled alpha to a
- /// that contains non-premultiplied alpha.
- ///
- /// The to convert.
- /// The .
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Color ToNonPremultiplied(Color color)
+ ///
+ public uint PackedValue()
{
- float a = color.A;
- if (Math.Abs(a) < Epsilon)
- {
- return new Color(color.backingVector);
- }
-
- return new Color(color.backingVector / new Vector4(a, a, a, 1));
+ return this.packedValue;
}
- ///
- /// Gets a representation for this .
- ///
- /// A representation for this object.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public Vector4 ToVector4()
+ ///
+ public void PackVector(Vector4 vector)
{
- return new Vector4(this.R, this.G, this.B, this.A);
+ Vector4 clamped = Vector4.Clamp(vector, Vector4.Zero, Vector4.One) * 255F;
+ this.R = (byte)Math.Round(clamped.X);
+ this.G = (byte)Math.Round(clamped.Y);
+ this.B = (byte)Math.Round(clamped.Z);
+ this.A = (byte)Math.Round(clamped.W);
}
- ///
- /// Gets a representation for this .
- ///
- /// A representation for this object.
- public Vector3 ToVector3()
+ ///
+ public void PackBytes(byte x, byte y, byte z, byte w)
{
- return new Vector3(this.R, this.G, this.B);
+ this.R = x;
+ this.G = y;
+ this.B = z;
+ this.A = w;
}
///
- public override int GetHashCode()
+ public Vector4 ToVector4()
{
- return GetHashCode(this);
+ return new Vector4(this.R, this.G, this.B, this.A) / 255F;
}
///
- public override string ToString()
+ public byte[] ToBytes()
{
- if (this.IsEmpty)
- {
- return "Color [ Empty ]";
- }
-
- return $"Color [ R={this.R:#0.##}, G={this.G:#0.##}, B={this.B:#0.##}, A={this.A:#0.##} ]";
+ return new[] { this.R, this.G, this.B, this.A };
}
///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object obj)
{
- if (obj is Color)
- {
- return this.Equals((Color)obj);
- }
-
- return false;
+ return (obj is Color) && this.Equals((Color)obj);
}
///
public bool Equals(Color other)
{
- return this.AlmostEquals(other, Epsilon);
- }
-
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool AlmostEquals(Color other, float precision)
- {
- Vector4 result = Vector4.Abs(this.backingVector - other.backingVector);
-
- return result.X < precision
- && result.Y < precision
- && result.Z < precision
- && result.W < precision;
+ return this.packedValue == other.packedValue;
}
///
- /// Gets the compressed sRGB value from an linear signal.
- ///
- ///
+ /// Gets a string representation of the packed vector.
///
- /// The signal value to compress.
- ///
- /// The .
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static float Compress(float signal)
+ /// A string representation of the packed vector.
+ public override string ToString()
{
- if (signal <= 0.0031308f)
- {
- return signal * 12.92f;
- }
-
- return (1.055f * (float)Math.Pow(signal, 0.41666666f)) - 0.055f;
+ return this.ToVector4().ToString();
}
- ///
- /// Gets the expanded linear value from an sRGB signal.
- ///
- ///
- ///
- /// The signal value to expand.
- ///
- /// The .
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static float Expand(float signal)
+ ///
+ public override int GetHashCode()
{
- if (signal <= 0.04045f)
- {
- return signal / 12.92f;
- }
-
- return (float)Math.Pow((signal + 0.055f) / 1.055f, 2.4f);
+ return this.GetHashCode(this);
}
///
/// Returns the hash code for this instance.
///
- ///
+ ///
/// The instance of to return the hash code for.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
///
- private static int GetHashCode(Color color) => color.backingVector.GetHashCode();
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private int GetHashCode(Color packed)
+ {
+ return packed.packedValue.GetHashCode();
+ }
}
-}
+}
\ No newline at end of file
diff --git a/src/ImageProcessorCore/Colors/ColorDefinitions.cs b/src/ImageProcessorCore/Colors/ColorDefinitions.cs
index aaf99bb1b3..1c853949f6 100644
--- a/src/ImageProcessorCore/Colors/ColorDefinitions.cs
+++ b/src/ImageProcessorCore/Colors/ColorDefinitions.cs
@@ -6,8 +6,8 @@
namespace ImageProcessorCore
{
///
- /// Represents a four-component color using red, green, blue, and alpha data.
- /// Each component is stored in premultiplied format multiplied by the alpha component.
+ /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255.
+ /// The color components are stored in red, green, blue, and alpha order.
///
///
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
@@ -16,713 +16,714 @@ namespace ImageProcessorCore
public partial struct Color
{
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F0F8FF.
+ /// Represents a matching the W3C definition that has an hex value of #F0F8FF.
///
- public static readonly Color AliceBlue = new Color(240 / 255f, 248 / 255f, 1);
+ public static readonly Color AliceBlue = new Color(240, 248, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FAEBD7.
+ /// Represents a matching the W3C definition that has an hex value of #FAEBD7.
///
- public static readonly Color AntiqueWhite = new Color(250 / 255f, 235 / 255f, 215 / 255f);
+ public static readonly Color AntiqueWhite = new Color(250, 235, 215, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #00FFFF.
+ /// Represents a matching the W3C definition that has an hex value of #00FFFF.
///
- public static readonly Color Aqua = new Color(0, 1, 1);
+ public static readonly Color Aqua = new Color(0, 255, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #7FFFD4.
+ /// Represents a matching the W3C definition that has an hex value of #7FFFD4.
///
- public static readonly Color Aquamarine = new Color(127 / 255f, 1, 212 / 255f);
+ public static readonly Color Aquamarine = new Color(127, 255, 212, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F0FFFF.
+ /// Represents a matching the W3C definition that has an hex value of #F0FFFF.
///
- public static readonly Color Azure = new Color(240 / 255f, 1, 1);
+ public static readonly Color Azure = new Color(240, 255, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F5F5DC.
+ /// Represents a matching the W3C definition that has an hex value of #F5F5DC.
///
- public static readonly Color Beige = new Color(245 / 255f, 245 / 255f, 220 / 255f);
+ public static readonly Color Beige = new Color(245, 245, 220, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFE4C4.
+ /// Represents a matching the W3C definition that has an hex value of #FFE4C4.
///
- public static readonly Color Bisque = new Color(1, 228 / 255f, 196 / 255f);
+ public static readonly Color Bisque = new Color(255, 228, 196, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #000000.
+ /// Represents a matching the W3C definition that has an hex value of #000000.
///
- public static readonly Color Black = new Color(0, 0, 0);
+ public static readonly Color Black = new Color(0, 0, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFEBCD.
+ /// Represents a matching the W3C definition that has an hex value of #FFEBCD.
///
- public static readonly Color BlanchedAlmond = new Color(1, 235 / 255f, 205 / 255f);
+ public static readonly Color BlanchedAlmond = new Color(255, 235, 205, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #0000FF.
+ /// Represents a matching the W3C definition that has an hex value of #0000FF.
///
- public static readonly Color Blue = new Color(0, 0, 1);
+ public static readonly Color Blue = new Color(0, 0, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #8A2BE2.
+ /// Represents a matching the W3C definition that has an hex value of #8A2BE2.
///
- public static readonly Color BlueViolet = new Color(138 / 255f, 43 / 255f, 226 / 255f);
+ public static readonly Color BlueViolet = new Color(138, 43, 226, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #A52A2A.
+ /// Represents a matching the W3C definition that has an hex value of #A52A2A.
///
- public static readonly Color Brown = new Color(165 / 255f, 42 / 255f, 42 / 255f);
+ public static readonly Color Brown = new Color(165, 42, 42, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #DEB887.
+ /// Represents a matching the W3C definition that has an hex value of #DEB887.
///
- public static readonly Color BurlyWood = new Color(222 / 255f, 184 / 255f, 135 / 255f);
+ public static readonly Color BurlyWood = new Color(222, 184, 135, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #5F9EA0.
+ /// Represents a matching the W3C definition that has an hex value of #5F9EA0.
///
- public static readonly Color CadetBlue = new Color(95 / 255f, 158 / 255f, 160 / 255f);
+ public static readonly Color CadetBlue = new Color(95, 158, 160, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #7FFF00.
+ /// Represents a matching the W3C definition that has an hex value of #7FFF00.
///
- public static readonly Color Chartreuse = new Color(127 / 255f, 1, 0);
+ public static readonly Color Chartreuse = new Color(127, 255, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #D2691E.
+ /// Represents a matching the W3C definition that has an hex value of #D2691E.
///
- public static readonly Color Chocolate = new Color(210 / 255f, 105 / 255f, 30 / 255f);
+ public static readonly Color Chocolate = new Color(210, 105, 30, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF7F50.
+ /// Represents a matching the W3C definition that has an hex value of #FF7F50.
///
- public static readonly Color Coral = new Color(1, 127 / 255f, 80 / 255f);
+ public static readonly Color Coral = new Color(255, 127, 80, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #6495ED.
+ /// Represents a matching the W3C definition that has an hex value of #6495ED.
///
- public static readonly Color CornflowerBlue = new Color(100 / 255f, 149 / 255f, 237 / 255f);
+ public static readonly Color CornflowerBlue = new Color(100, 149, 237, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFF8DC.
+ /// Represents a matching the W3C definition that has an hex value of #FFF8DC.
///
- public static readonly Color Cornsilk = new Color(1, 248 / 255f, 220 / 255f);
+ public static readonly Color Cornsilk = new Color(255, 248, 220, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #DC143C.
+ /// Represents a matching the W3C definition that has an hex value of #DC143C.
///
- public static readonly Color Crimson = new Color(220 / 255f, 20 / 255f, 60 / 255f);
+ public static readonly Color Crimson = new Color(220, 20, 60, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #00FFFF.
+ /// Represents a matching the W3C definition that has an hex value of #00FFFF.
///
- public static readonly Color Cyan = new Color(0, 1, 1);
+ public static readonly Color Cyan = new Color(0, 255, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #00008B.
+ /// Represents a matching the W3C definition that has an hex value of #00008B.
///
- public static readonly Color DarkBlue = new Color(0, 0, 139 / 255f);
+ public static readonly Color DarkBlue = new Color(0, 0, 139, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #008B8B.
+ /// Represents a matching the W3C definition that has an hex value of #008B8B.
///
- public static readonly Color DarkCyan = new Color(0, 139 / 255f, 139 / 255f);
+ public static readonly Color DarkCyan = new Color(0, 139, 139, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #B8860B.
+ /// Represents a matching the W3C definition that has an hex value of #B8860B.
///
- public static readonly Color DarkGoldenrod = new Color(184 / 255f, 134 / 255f, 11 / 255f);
+ public static readonly Color DarkGoldenrod = new Color(184, 134, 11, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #A9A9A9.
+ /// Represents a matching the W3C definition that has an hex value of #A9A9A9.
///
- public static readonly Color DarkGray = new Color(169 / 255f, 169 / 255f, 169 / 255f);
+ public static readonly Color DarkGray = new Color(169, 169, 169, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #006400.
+ /// Represents a matching the W3C definition that has an hex value of #006400.
///
- public static readonly Color DarkGreen = new Color(0, 100 / 255f, 0);
+ public static readonly Color DarkGreen = new Color(0, 100, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #BDB76B.
+ /// Represents a matching the W3C definition that has an hex value of #BDB76B.
///
- public static readonly Color DarkKhaki = new Color(189 / 255f, 183 / 255f, 107 / 255f);
+ public static readonly Color DarkKhaki = new Color(189, 183, 107, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #8B008B.
+ /// Represents a matching the W3C definition that has an hex value of #8B008B.
///
- public static readonly Color DarkMagenta = new Color(139 / 255f, 0, 139 / 255f);
+ public static readonly Color DarkMagenta = new Color(139, 0, 139, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #556B2F.
+ /// Represents a matching the W3C definition that has an hex value of #556B2F.
///
- public static readonly Color DarkOliveGreen = new Color(85 / 255f, 107 / 255f, 47 / 255f);
+ public static readonly Color DarkOliveGreen = new Color(85, 107, 47, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF8C00.
+ /// Represents a matching the W3C definition that has an hex value of #FF8C00.
///
- public static readonly Color DarkOrange = new Color(1, 140 / 255f, 0);
+ public static readonly Color DarkOrange = new Color(255, 140, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #9932CC.
+ /// Represents a matching the W3C definition that has an hex value of #9932CC.
///
- public static readonly Color DarkOrchid = new Color(153 / 255f, 50 / 255f, 204 / 255f);
+ public static readonly Color DarkOrchid = new Color(153, 50, 204, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #8B0000.
+ /// Represents a matching the W3C definition that has an hex value of #8B0000.
///
- public static readonly Color DarkRed = new Color(139 / 255f, 0, 0);
+ public static readonly Color DarkRed = new Color(139, 0, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #E9967A.
+ /// Represents a matching the W3C definition that has an hex value of #E9967A.
///
- public static readonly Color DarkSalmon = new Color(233 / 255f, 150 / 255f, 122 / 255f);
+ public static readonly Color DarkSalmon = new Color(233, 150, 122, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #8FBC8B.
+ /// Represents a matching the W3C definition that has an hex value of #8FBC8B.
///
- public static readonly Color DarkSeaGreen = new Color(143 / 255f, 188 / 255f, 139 / 255f);
+ public static readonly Color DarkSeaGreen = new Color(143, 188, 139, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #483D8B.
+ /// Represents a matching the W3C definition that has an hex value of #483D8B.
///
- public static readonly Color DarkSlateBlue = new Color(72 / 255f, 61 / 255f, 139 / 255f);
+ public static readonly Color DarkSlateBlue = new Color(72, 61, 139, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #2F4F4F.
+ /// Represents a matching the W3C definition that has an hex value of #2F4F4F.
///
- public static readonly Color DarkSlateGray = new Color(47 / 255f, 79 / 255f, 79 / 255f);
+ public static readonly Color DarkSlateGray = new Color(47, 79, 79, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #00CED1.
+ /// Represents a matching the W3C definition that has an hex value of #00CED1.
///
- public static readonly Color DarkTurquoise = new Color(0, 206 / 255f, 209 / 255f);
+ public static readonly Color DarkTurquoise = new Color(0, 206, 209, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #9400D3.
+ /// Represents a matching the W3C definition that has an hex value of #9400D3.
///
- public static readonly Color DarkViolet = new Color(148 / 255f, 0, 211 / 255f);
+ public static readonly Color DarkViolet = new Color(148, 0, 211, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF1493.
+ /// Represents a matching the W3C definition that has an hex value of #FF1493.
///
- public static readonly Color DeepPink = new Color(1, 20 / 255f, 147 / 255f);
+ public static readonly Color DeepPink = new Color(255, 20, 147, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #00BFFF.
+ /// Represents a matching the W3C definition that has an hex value of #00BFFF.
///
- public static readonly Color DeepSkyBlue = new Color(0, 191 / 255f, 1);
+ public static readonly Color DeepSkyBlue = new Color(0, 191, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #696969.
+ /// Represents a matching the W3C definition that has an hex value of #696969.
///
- public static readonly Color DimGray = new Color(105 / 255f, 105 / 255f, 105 / 255f);
+ public static readonly Color DimGray = new Color(105, 105, 105, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #1E90FF.
+ /// Represents a matching the W3C definition that has an hex value of #1E90FF.
///
- public static readonly Color DodgerBlue = new Color(30 / 255f, 144 / 255f, 1);
+ public static readonly Color DodgerBlue = new Color(30, 144, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #B22222.
+ /// Represents a matching the W3C definition that has an hex value of #B22222.
///
- public static readonly Color Firebrick = new Color(178 / 255f, 34 / 255f, 34 / 255f);
+ public static readonly Color Firebrick = new Color(178, 34, 34, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFFAF0.
+ /// Represents a matching the W3C definition that has an hex value of #FFFAF0.
///
- public static readonly Color FloralWhite = new Color(1, 250 / 255f, 240 / 255f);
+ public static readonly Color FloralWhite = new Color(255, 250, 240, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #228B22.
+ /// Represents a matching the W3C definition that has an hex value of #228B22.
///
- public static readonly Color ForestGreen = new Color(34 / 255f, 139 / 255f, 34 / 255f);
+ public static readonly Color ForestGreen = new Color(34, 139, 34, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF00FF.
+ /// Represents a matching the W3C definition that has an hex value of #FF00FF.
///
- public static readonly Color Fuchsia = new Color(1, 0, 1);
+ public static readonly Color Fuchsia = new Color(255, 0, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #DCDCDC.
+ /// Represents a matching the W3C definition that has an hex value of #DCDCDC.
///
- public static readonly Color Gainsboro = new Color(220 / 255f, 220 / 255f, 220 / 255f);
+ public static readonly Color Gainsboro = new Color(220, 220, 220, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F8F8FF.
+ /// Represents a matching the W3C definition that has an hex value of #F8F8FF.
///
- public static readonly Color GhostWhite = new Color(248 / 255f, 248 / 255f, 1);
+ public static readonly Color GhostWhite = new Color(248, 248, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFD700.
+ /// Represents a matching the W3C definition that has an hex value of #FFD700.
///
- public static readonly Color Gold = new Color(1, 215 / 255f, 0);
+ public static readonly Color Gold = new Color(255, 215, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #DAA520.
+ /// Represents a matching the W3C definition that has an hex value of #DAA520.
///
- public static readonly Color Goldenrod = new Color(218 / 255f, 165 / 255f, 32 / 255f);
+ public static readonly Color Goldenrod = new Color(218, 165, 32, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #808080.
+ /// Represents a matching the W3C definition that has an hex value of #808080.
///
- public static readonly Color Gray = new Color(128 / 255f, 128 / 255f, 128 / 255f);
+ public static readonly Color Gray = new Color(128, 128, 128, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #008000.
+ /// Represents a matching the W3C definition that has an hex value of #008000.
///
- public static readonly Color Green = new Color(0, 128 / 255f, 0);
+ public static readonly Color Green = new Color(0, 128, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #ADFF2F.
+ /// Represents a matching the W3C definition that has an hex value of #ADFF2F.
///
- public static readonly Color GreenYellow = new Color(173 / 255f, 1, 47 / 255f);
+ public static readonly Color GreenYellow = new Color(173, 255, 47, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F0FFF0.
+ /// Represents a matching the W3C definition that has an hex value of #F0FFF0.
///
- public static readonly Color Honeydew = new Color(240 / 255f, 1, 240 / 255f);
+ public static readonly Color Honeydew = new Color(240, 255, 240, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF69B4.
+ /// Represents a matching the W3C definition that has an hex value of #FF69B4.
///
- public static readonly Color HotPink = new Color(1, 105 / 255f, 180 / 255f);
+ public static readonly Color HotPink = new Color(255, 105, 180, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #CD5C5C.
+ /// Represents a matching the W3C definition that has an hex value of #CD5C5C.
///
- public static readonly Color IndianRed = new Color(205 / 255f, 92 / 255f, 92 / 255f);
+ public static readonly Color IndianRed = new Color(205, 92, 92, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #4B0082.
+ /// Represents a matching the W3C definition that has an hex value of #4B0082.
///
- public static readonly Color Indigo = new Color(75 / 255f, 0, 130 / 255f);
+ public static readonly Color Indigo = new Color(75, 0, 130, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFFFF0.
+ /// Represents a matching the W3C definition that has an hex value of #FFFFF0.
///
- public static readonly Color Ivory = new Color(1, 1, 240 / 255f);
+ public static readonly Color Ivory = new Color(255, 255, 240, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F0E68C.
+ /// Represents a matching the W3C definition that has an hex value of #F0E68C.
///
- public static readonly Color Khaki = new Color(240 / 255f, 230 / 255f, 140 / 255f);
+ public static readonly Color Khaki = new Color(240, 230, 140, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #E6E6FA.
+ /// Represents a matching the W3C definition that has an hex value of #E6E6FA.
///
- public static readonly Color Lavender = new Color(230 / 255f, 230 / 255f, 250 / 255f);
+ public static readonly Color Lavender = new Color(230, 230, 250, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFF0F5.
+ /// Represents a matching the W3C definition that has an hex value of #FFF0F5.
///
- public static readonly Color LavenderBlush = new Color(1, 240 / 255f, 245 / 255f);
+ public static readonly Color LavenderBlush = new Color(255, 240, 245, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #7CFC00.
+ /// Represents a matching the W3C definition that has an hex value of #7CFC00.
///
- public static readonly Color LawnGreen = new Color(124 / 255f, 252 / 255f, 0);
+ public static readonly Color LawnGreen = new Color(124, 252, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFFACD.
+ /// Represents a matching the W3C definition that has an hex value of #FFFACD.
///
- public static readonly Color LemonChiffon = new Color(1, 250 / 255f, 205 / 255f);
+ public static readonly Color LemonChiffon = new Color(255, 250, 205, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #ADD8E6.
+ /// Represents a matching the W3C definition that has an hex value of #ADD8E6.
///
- public static readonly Color LightBlue = new Color(173 / 255f, 216 / 255f, 230 / 255f);
+ public static readonly Color LightBlue = new Color(173, 216, 230, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F08080.
+ /// Represents a matching the W3C definition that has an hex value of #F08080.
///
- public static readonly Color LightCoral = new Color(240 / 255f, 128 / 255f, 128 / 255f);
+ public static readonly Color LightCoral = new Color(240, 128, 128, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #E0FFFF.
+ /// Represents a matching the W3C definition that has an hex value of #E0FFFF.
///
- public static readonly Color LightCyan = new Color(224 / 255f, 1, 1);
+ public static readonly Color LightCyan = new Color(224, 255, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FAFAD2.
+ /// Represents a matching the W3C definition that has an hex value of #FAFAD2.
///
- public static readonly Color LightGoldenrodYellow = new Color(250 / 255f, 250 / 255f, 210 / 255f);
+ public static readonly Color LightGoldenrodYellow = new Color(250, 250, 210, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #90EE90.
+ /// Represents a matching the W3C definition that has an hex value of #D3D3D3.
///
- public static readonly Color LightGreen = new Color(144 / 255f, 238 / 255f, 144 / 255f);
+ public static readonly Color LightGray = new Color(211, 211, 211, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #D3D3D3.
+ /// Represents a matching the W3C definition that has an hex value of #90EE90.
///
- public static readonly Color LightGray = new Color(211 / 255f, 211 / 255f, 211 / 255f);
+ public static readonly Color LightGreen = new Color(144, 238, 144, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFB6C1.
+ /// Represents a matching the W3C definition that has an hex value of #FFB6C1.
///
- public static readonly Color LightPink = new Color(1, 182 / 255f, 193 / 255f);
+ public static readonly Color LightPink = new Color(255, 182, 193, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFA07A.
+ /// Represents a matching the W3C definition that has an hex value of #FFA07A.
///
- public static readonly Color LightSalmon = new Color(1, 160 / 255f, 122 / 255f);
+ public static readonly Color LightSalmon = new Color(255, 160, 122, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #20B2AA.
+ /// Represents a matching the W3C definition that has an hex value of #20B2AA.
///
- public static readonly Color LightSeaGreen = new Color(32 / 255f, 178 / 255f, 170 / 255f);
+ public static readonly Color LightSeaGreen = new Color(32, 178, 170, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #87CEFA.
+ /// Represents a matching the W3C definition that has an hex value of #87CEFA.
///
- public static readonly Color LightSkyBlue = new Color(135 / 255f, 206 / 255f, 250 / 255f);
+ public static readonly Color LightSkyBlue = new Color(135, 206, 250, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #778899.
+ /// Represents a matching the W3C definition that has an hex value of #778899.
///
- public static readonly Color LightSlateGray = new Color(119 / 255f, 136 / 255f, 153 / 255f);
+ public static readonly Color LightSlateGray = new Color(119, 136, 153, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #B0C4DE.
+ /// Represents a matching the W3C definition that has an hex value of #B0C4DE.
///
- public static readonly Color LightSteelBlue = new Color(176 / 255f, 196 / 255f, 222 / 255f);
+ public static readonly Color LightSteelBlue = new Color(176, 196, 222, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFFFE0.
+ /// Represents a matching the W3C definition that has an hex value of #FFFFE0.
///
- public static readonly Color LightYellow = new Color(1, 1, 224 / 255f);
+ public static readonly Color LightYellow = new Color(255, 255, 224, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #00FF00.
+ /// Represents a matching the W3C definition that has an hex value of #00FF00.
///
- public static readonly Color Lime = new Color(0, 1, 0);
+ public static readonly Color Lime = new Color(0, 255, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #32CD32.
+ /// Represents a matching the W3C definition that has an hex value of #32CD32.
///
- public static readonly Color LimeGreen = new Color(50 / 255f, 205 / 255f, 50 / 255f);
+ public static readonly Color LimeGreen = new Color(50, 205, 50, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FAF0E6.
+ /// Represents a matching the W3C definition that has an hex value of #FAF0E6.
///
- public static readonly Color Linen = new Color(250 / 255f, 240 / 255f, 230 / 255f);
+ public static readonly Color Linen = new Color(250, 240, 230, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF00FF.
+ /// Represents a matching the W3C definition that has an hex value of #FF00FF.
///
- public static readonly Color Magenta = new Color(1, 0, 1);
+ public static readonly Color Magenta = new Color(255, 0, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #800000.
+ /// Represents a matching the W3C definition that has an hex value of #800000.
///
- public static readonly Color Maroon = new Color(128 / 255f, 0, 0);
+ public static readonly Color Maroon = new Color(128, 0, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #66CDAA.
+ /// Represents a matching the W3C definition that has an hex value of #66CDAA.
///
- public static readonly Color MediumAquamarine = new Color(102 / 255f, 205 / 255f, 170 / 255f);
+ public static readonly Color MediumAquamarine = new Color(102, 205, 170, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #0000CD.
+ /// Represents a matching the W3C definition that has an hex value of #0000CD.
///
- public static readonly Color MediumBlue = new Color(0, 0, 205 / 255f);
+ public static readonly Color MediumBlue = new Color(0, 0, 205, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #BA55D3.
+ /// Represents a matching the W3C definition that has an hex value of #BA55D3.
///
- public static readonly Color MediumOrchid = new Color(186 / 255f, 85 / 255f, 211 / 255f);
+ public static readonly Color MediumOrchid = new Color(186, 85, 211, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #9370DB.
+ /// Represents a matching the W3C definition that has an hex value of #9370DB.
///
- public static readonly Color MediumPurple = new Color(147 / 255f, 112 / 255f, 219 / 255f);
+ public static readonly Color MediumPurple = new Color(147, 112, 219, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #3CB371.
+ /// Represents a matching the W3C definition that has an hex value of #3CB371.
///
- public static readonly Color MediumSeaGreen = new Color(60 / 255f, 179 / 255f, 113 / 255f);
+ public static readonly Color MediumSeaGreen = new Color(60, 179, 113, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #7B68EE.
+ /// Represents a matching the W3C definition that has an hex value of #7B68EE.
///
- public static readonly Color MediumSlateBlue = new Color(123 / 255f, 104 / 255f, 238 / 255f);
+ public static readonly Color MediumSlateBlue = new Color(123, 104, 238, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #00FA9A.
+ /// Represents a matching the W3C definition that has an hex value of #00FA9A.
///
- public static readonly Color MediumSpringGreen = new Color(0, 250 / 255f, 154 / 255f);
+ public static readonly Color MediumSpringGreen = new Color(0, 250, 154, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #48D1CC.
+ /// Represents a matching the W3C definition that has an hex value of #48D1CC.
///
- public static readonly Color MediumTurquoise = new Color(72 / 255f, 209 / 255f, 204 / 255f);
+ public static readonly Color MediumTurquoise = new Color(72, 209, 204, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #C71585.
+ /// Represents a matching the W3C definition that has an hex value of #C71585.
///
- public static readonly Color MediumVioletRed = new Color(199 / 255f, 21 / 255f, 133 / 255f);
+ public static readonly Color MediumVioletRed = new Color(199, 21, 133, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #191970.
+ /// Represents a matching the W3C definition that has an hex value of #191970.
///
- public static readonly Color MidnightBlue = new Color(25 / 255f, 25 / 255f, 112 / 255f);
+ public static readonly Color MidnightBlue = new Color(25, 25, 112, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F5FFFA.
+ /// Represents a matching the W3C definition that has an hex value of #F5FFFA.
///
- public static readonly Color MintCream = new Color(245 / 255f, 1, 250 / 255f);
+ public static readonly Color MintCream = new Color(245, 255, 250, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFE4E1.
+ /// Represents a matching the W3C definition that has an hex value of #FFE4E1.
///
- public static readonly Color MistyRose = new Color(1, 228 / 255f, 225 / 255f);
+ public static readonly Color MistyRose = new Color(255, 228, 225, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFE4B5.
+ /// Represents a matching the W3C definition that has an hex value of #FFE4B5.
///
- public static readonly Color Moccasin = new Color(1, 228 / 255f, 181 / 255f);
+ public static readonly Color Moccasin = new Color(255, 228, 181, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFDEAD.
+ /// Represents a matching the W3C definition that has an hex value of #FFDEAD.
///
- public static readonly Color NavajoWhite = new Color(1, 222 / 255f, 173 / 255f);
+ public static readonly Color NavajoWhite = new Color(255, 222, 173, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #000080.
+ /// Represents a matching the W3C definition that has an hex value of #000080.
///
- public static readonly Color Navy = new Color(0, 0, 128 / 255f);
+ public static readonly Color Navy = new Color(0, 0, 128, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FDF5E6.
+ /// Represents a matching the W3C definition that has an hex value of #FDF5E6.
///
- public static readonly Color OldLace = new Color(253 / 255f, 245 / 255f, 230 / 255f);
+ public static readonly Color OldLace = new Color(253, 245, 230, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #808000.
+ /// Represents a matching the W3C definition that has an hex value of #808000.
///
- public static readonly Color Olive = new Color(128 / 255f, 128 / 255f, 0);
+ public static readonly Color Olive = new Color(128, 128, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #6B8E23.
+ /// Represents a matching the W3C definition that has an hex value of #6B8E23.
///
- public static readonly Color OliveDrab = new Color(107 / 255f, 142 / 255f, 35 / 255f);
+ public static readonly Color OliveDrab = new Color(107, 142, 35, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFA500.
+ /// Represents a matching the W3C definition that has an hex value of #FFA500.
///
- public static readonly Color Orange = new Color(1, 165 / 255f, 0);
+ public static readonly Color Orange = new Color(255, 165, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF4500.
+ /// Represents a matching the W3C definition that has an hex value of #FF4500.
///
- public static readonly Color OrangeRed = new Color(1, 69 / 255f, 0);
+ public static readonly Color OrangeRed = new Color(255, 69, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #DA70D6.
+ /// Represents a matching the W3C definition that has an hex value of #DA70D6.
///
- public static readonly Color Orchid = new Color(218 / 255f, 112 / 255f, 214 / 255f);
+ public static readonly Color Orchid = new Color(218, 112, 214, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #EEE8AA.
+ /// Represents a matching the W3C definition that has an hex value of #EEE8AA.
///
- public static readonly Color PaleGoldenrod = new Color(238 / 255f, 232 / 255f, 170 / 255f);
+ public static readonly Color PaleGoldenrod = new Color(238, 232, 170, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #98FB98.
+ /// Represents a matching the W3C definition that has an hex value of #98FB98.
///
- public static readonly Color PaleGreen = new Color(152 / 255f, 251 / 255f, 152 / 255f);
+ public static readonly Color PaleGreen = new Color(152, 251, 152, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #AFEEEE.
+ /// Represents a matching the W3C definition that has an hex value of #AFEEEE.
///
- public static readonly Color PaleTurquoise = new Color(175 / 255f, 238 / 255f, 238 / 255f);
+ public static readonly Color PaleTurquoise = new Color(175, 238, 238, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #DB7093.
+ /// Represents a matching the W3C definition that has an hex value of #DB7093.
///
- public static readonly Color PaleVioletRed = new Color(219 / 255f, 112 / 255f, 147 / 255f);
+ public static readonly Color PaleVioletRed = new Color(219, 112, 147, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFEFD5.
+ /// Represents a matching the W3C definition that has an hex value of #FFEFD5.
///
- public static readonly Color PapayaWhip = new Color(1, 239 / 255f, 213 / 255f);
+ public static readonly Color PapayaWhip = new Color(255, 239, 213, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFDAB9.
+ /// Represents a matching the W3C definition that has an hex value of #FFDAB9.
///
- public static readonly Color PeachPuff = new Color(1, 218 / 255f, 185 / 255f);
+ public static readonly Color PeachPuff = new Color(255, 218, 185, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #CD853F.
+ /// Represents a matching the W3C definition that has an hex value of #CD853F.
///
- public static readonly Color Peru = new Color(205 / 255f, 133 / 255f, 63 / 255f);
+ public static readonly Color Peru = new Color(205, 133, 63, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFC0CB.
+ /// Represents a matching the W3C definition that has an hex value of #FFC0CB.
///
- public static readonly Color Pink = new Color(1, 192 / 255f, 203 / 255f);
+ public static readonly Color Pink = new Color(255, 192, 203, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #DDA0DD.
+ /// Represents a matching the W3C definition that has an hex value of #DDA0DD.
///
- public static readonly Color Plum = new Color(221 / 255f, 160 / 255f, 221 / 255f);
+ public static readonly Color Plum = new Color(221, 160, 221, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #B0E0E6.
+ /// Represents a matching the W3C definition that has an hex value of #B0E0E6.
///
- public static readonly Color PowderBlue = new Color(176 / 255f, 224 / 255f, 230 / 255f);
+ public static readonly Color PowderBlue = new Color(176, 224, 230, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #800080.
+ /// Represents a matching the W3C definition that has an hex value of #800080.
///
- public static readonly Color Purple = new Color(128 / 255f, 0, 128 / 255f);
+ public static readonly Color Purple = new Color(128, 0, 128, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #663399.
+ /// Represents a matching the W3C definition that has an hex value of #0.
///
- public static readonly Color RebeccaPurple = new Color(102 / 255f, 51 / 255f, 153 / 255f);
+ public static readonly Color RebeccaPurple = new Color(102, 51, 153, 255);
+
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF0000.
+ /// Represents a matching the W3C definition that has an hex value of #FF0000.
///
- public static readonly Color Red = new Color(1, 0, 0);
+ public static readonly Color Red = new Color(255, 0, 0, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #BC8F8F.
+ /// Represents a matching the W3C definition that has an hex value of #BC8F8F.
///
- public static readonly Color RosyBrown = new Color(188 / 255f, 143 / 255f, 143 / 255f);
+ public static readonly Color RosyBrown = new Color(188, 143, 143, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #4169E1.
+ /// Represents a matching the W3C definition that has an hex value of #4169E1.
///
- public static readonly Color RoyalBlue = new Color(65 / 255f, 105 / 255f, 225 / 255f);
+ public static readonly Color RoyalBlue = new Color(65, 105, 225, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #8B4513.
+ /// Represents a matching the W3C definition that has an hex value of #8B4513.
///
- public static readonly Color SaddleBrown = new Color(139 / 255f, 69 / 255f, 19 / 255f);
+ public static readonly Color SaddleBrown = new Color(139, 69, 19, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FA8072.
+ /// Represents a matching the W3C definition that has an hex value of #FA8072.
///
- public static readonly Color Salmon = new Color(250 / 255f, 128 / 255f, 114 / 255f);
+ public static readonly Color Salmon = new Color(250, 128, 114, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F4A460.
+ /// Represents a matching the W3C definition that has an hex value of #F4A460.
///
- public static readonly Color SandyBrown = new Color(244 / 255f, 164 / 255f, 96 / 255f);
+ public static readonly Color SandyBrown = new Color(244, 164, 96, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #2E8B57.
+ /// Represents a matching the W3C definition that has an hex value of #2E8B57.
///
- public static readonly Color SeaGreen = new Color(46 / 255f, 139 / 255f, 87 / 255f);
+ public static readonly Color SeaGreen = new Color(46, 139, 87, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFF5EE.
+ /// Represents a matching the W3C definition that has an hex value of #FFF5EE.
///
- public static readonly Color SeaShell = new Color(1, 245 / 255f, 238 / 255f);
+ public static readonly Color SeaShell = new Color(255, 245, 238, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #A0522D.
+ /// Represents a matching the W3C definition that has an hex value of #A0522D.
///
- public static readonly Color Sienna = new Color(160 / 255f, 82 / 255f, 45 / 255f);
+ public static readonly Color Sienna = new Color(160, 82, 45, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #C0C0C0.
+ /// Represents a matching the W3C definition that has an hex value of #C0C0C0.
///
- public static readonly Color Silver = new Color(192 / 255f, 192 / 255f, 192 / 255f);
+ public static readonly Color Silver = new Color(192, 192, 192, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #87CEEB.
+ /// Represents a matching the W3C definition that has an hex value of #87CEEB.
///
- public static readonly Color SkyBlue = new Color(135 / 255f, 206 / 255f, 235 / 255f);
+ public static readonly Color SkyBlue = new Color(135, 206, 235, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #6A5ACD.
+ /// Represents a matching the W3C definition that has an hex value of #6A5ACD.
///
- public static readonly Color SlateBlue = new Color(106 / 255f, 90 / 255f, 205 / 255f);
+ public static readonly Color SlateBlue = new Color(106, 90, 205, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #708090.
+ /// Represents a matching the W3C definition that has an hex value of #708090.
///
- public static readonly Color SlateGray = new Color(112 / 255f, 128 / 255f, 144 / 255f);
+ public static readonly Color SlateGray = new Color(112, 128, 144, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFFAFA.
+ /// Represents a matching the W3C definition that has an hex value of #FFFAFA.
///
- public static readonly Color Snow = new Color(1, 250 / 255f, 250 / 255f);
+ public static readonly Color Snow = new Color(255, 250, 250, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #00FF7F.
+ /// Represents a matching the W3C definition that has an hex value of #00FF7F.
///
- public static readonly Color SpringGreen = new Color(0, 1, 127 / 255f);
+ public static readonly Color SpringGreen = new Color(0, 255, 127, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #4682B4.
+ /// Represents a matching the W3C definition that has an hex value of #4682B4.
///
- public static readonly Color SteelBlue = new Color(70 / 255f, 130 / 255f, 180 / 255f);
+ public static readonly Color SteelBlue = new Color(70, 130, 180, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #D2B48C.
+ /// Represents a matching the W3C definition that has an hex value of #D2B48C.
///
- public static readonly Color Tan = new Color(210 / 255f, 180 / 255f, 140 / 255f);
+ public static readonly Color Tan = new Color(210, 180, 140, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #008080.
+ /// Represents a matching the W3C definition that has an hex value of #008080.
///
- public static readonly Color Teal = new Color(0, 128 / 255f, 128 / 255f);
+ public static readonly Color Teal = new Color(0, 128, 128, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #D8BFD8.
+ /// Represents a matching the W3C definition that has an hex value of #D8BFD8.
///
- public static readonly Color Thistle = new Color(216 / 255f, 191 / 255f, 216 / 255f);
+ public static readonly Color Thistle = new Color(216, 191, 216, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FF6347.
+ /// Represents a matching the W3C definition that has an hex value of #FF6347.
///
- public static readonly Color Tomato = new Color(1, 99 / 255f, 71 / 255f);
+ public static readonly Color Tomato = new Color(255, 99, 71, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #40E0D0.
+ /// Represents a matching the W3C definition that has an hex value of #FFFFFF.
///
- public static readonly Color Turquoise = new Color(64 / 255f, 224 / 255f, 208 / 255f);
+ public static readonly Color Transparent = new Color(255, 255, 255, 0);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #EE82EE.
+ /// Represents a matching the W3C definition that has an hex value of #40E0D0.
///
- public static readonly Color Violet = new Color(238 / 255f, 130 / 255f, 238 / 255f);
+ public static readonly Color Turquoise = new Color(64, 224, 208, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F5DEB3.
+ /// Represents a matching the W3C definition that has an hex value of #EE82EE.
///
- public static readonly Color Wheat = new Color(245 / 255f, 222 / 255f, 179 / 255f);
+ public static readonly Color Violet = new Color(238, 130, 238, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFFFFF.
+ /// Represents a matching the W3C definition that has an hex value of #F5DEB3.
///
- public static readonly Color White = new Color(1, 1, 1);
+ public static readonly Color Wheat = new Color(245, 222, 179, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #F5F5F5.
+ /// Represents a matching the W3C definition that has an hex value of #FFFFFF.
///
- public static readonly Color WhiteSmoke = new Color(245 / 255f, 245 / 255f, 245 / 255f);
+ public static readonly Color White = new Color(255, 255, 255, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #FFFF00.
+ /// Represents a matching the W3C definition that has an hex value of #F5F5F5.
///
- public static readonly Color Yellow = new Color(1, 1, 0);
+ public static readonly Color WhiteSmoke = new Color(245, 245, 245, 255);
///
- /// Represents a matching the W3C definition that has a hex triplet value of #9ACD32.
+ /// Represents a matching the W3C definition that has an hex value of #FFFF00.
///
- public static readonly Color YellowGreen = new Color(154 / 255f, 205 / 255f, 50 / 255f);
+ public static readonly Color Yellow = new Color(255, 255, 0, 255);
///
- /// Represents a system-defined that has an ARGB value of #00FFFFFF.
+ /// Represents a matching the W3C definition that has an hex value of #9ACD32.
///
- public static readonly Color Transparent = new Color(1, 1, 1, 0);
+ public static readonly Color YellowGreen = new Color(154, 205, 50, 255);
}
-}
+}
\ No newline at end of file
diff --git a/src/ImageProcessorCore/Colors/ColorTransforms.cs b/src/ImageProcessorCore/Colors/ColorTransforms.cs
index 2a0da9407f..cc05f6bb49 100644
--- a/src/ImageProcessorCore/Colors/ColorTransforms.cs
+++ b/src/ImageProcessorCore/Colors/ColorTransforms.cs
@@ -6,10 +6,11 @@
namespace ImageProcessorCore
{
using System;
+ using System.Numerics;
///
- /// Represents a four-component color using red, green, blue, and alpha data.
- /// Each component is stored in premultiplied format multiplied by the alpha component.
+ /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255.
+ /// The color components are stored in red, green, blue, and alpha order.
///
///
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
@@ -43,31 +44,31 @@ namespace ImageProcessorCore
return source;
}
- return new Color(source.backingVector * destination.backingVector);
+ // TODO: This will use less memory than using Vector4
+ // but we should test speed vs memory to see which is best balance.
+ byte r = (byte)(source.R * destination.R).Clamp(0, 255);
+ byte g = (byte)(source.G * destination.G).Clamp(0, 255);
+ byte b = (byte)(source.B * destination.B).Clamp(0, 255);
+ byte a = (byte)(source.A * destination.A).Clamp(0, 255);
+
+ return new Color(r, g, b, a);
}
///
- /// Linearly interpolates from one color to another based on the given amount.
+ /// Linearly interpolates from one color to another based on the given weighting.
///
- /// The first color value.
- /// The second color value.
+ /// The first color value.
+ /// The second color value.
///
- /// The weight value. At amount = 0, "from" is returned, at amount = 1, "to" is returned.
+ /// A value between 0 and 1 indicating the weight of the second source vector.
+ /// At amount = 0, "from" is returned, at amount = 1, "to" is returned.
///
///
/// The
///
- public static Color Lerp(Color source, Color destination, float amount)
+ public static Color Lerp(Color from, Color to, float amount)
{
- amount = amount.Clamp(0f, 1f);
-
- if (Math.Abs(source.A - 1) < Epsilon && Math.Abs(destination.A - 1) < Epsilon)
- {
- return source + ((destination - source) * amount);
- }
-
- // Premultiplied.
- return (source * (1 - amount)) + destination;
+ return new Color(Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount));
}
}
}
diff --git a/src/ImageProcessorCore/Colors/ColorspaceTransforms.cs b/src/ImageProcessorCore/Colors/ColorspaceTransforms.cs
index 50d0af3150..db7e7536fc 100644
--- a/src/ImageProcessorCore/Colors/ColorspaceTransforms.cs
+++ b/src/ImageProcessorCore/Colors/ColorspaceTransforms.cs
@@ -6,10 +6,11 @@
namespace ImageProcessorCore
{
using System;
+ using System.Numerics;
///
- /// Represents a four-component color using red, green, blue, and alpha data.
- /// Each component is stored in premultiplied format multiplied by the alpha component.
+ /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255.
+ /// The color components are stored in red, green, blue, and alpha order.
///
///
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
@@ -17,6 +18,11 @@ namespace ImageProcessorCore
///
public partial struct Color
{
+ ///
+ /// The epsilon for comparing floating point numbers.
+ ///
+ private const float Epsilon = 0.001F;
+
///
/// Allows the implicit conversion of an instance of to a
/// .
@@ -27,7 +33,7 @@ namespace ImageProcessorCore
///
public static implicit operator Color(Bgra32 color)
{
- return new Color(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);
+ return new Color(color.R, color.G, color.B, color.A);
}
///
@@ -43,7 +49,7 @@ namespace ImageProcessorCore
float r = (1 - cmykColor.C) * (1 - cmykColor.K);
float g = (1 - cmykColor.M) * (1 - cmykColor.K);
float b = (1 - cmykColor.Y) * (1 - cmykColor.K);
- return new Color(r, g, b);
+ return new Color(r, g, b, 1);
}
///
@@ -60,11 +66,11 @@ namespace ImageProcessorCore
float cb = color.Cb - 128;
float cr = color.Cr - 128;
- float r = (float)(y + (1.402 * cr)).Clamp(0, 255) / 255f;
- float g = (float)(y - (0.34414 * cb) - (0.71414 * cr)).Clamp(0, 255) / 255f;
- float b = (float)(y + (1.772 * cb)).Clamp(0, 255) / 255f;
+ byte r = (byte)(y + (1.402 * cr)).Clamp(0, 255);
+ byte g = (byte)(y - (0.34414 * cb) - (0.71414 * cr)).Clamp(0, 255);
+ byte b = (byte)(y + (1.772 * cb)).Clamp(0, 255);
- return new Color(r, g, b);
+ return new Color(r, g, b, 255);
}
///
@@ -86,7 +92,8 @@ namespace ImageProcessorCore
float g = (x * -0.9689F) + (y * 1.8758F) + (z * 0.0415F);
float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F);
- return Color.Compress(new Color(r, g, b));
+ Vector4 vector = new Vector4(r, g, b, 1).Compress();
+ return new Color(vector);
}
///
@@ -111,9 +118,9 @@ namespace ImageProcessorCore
int i = (int)Math.Truncate(h);
float f = h - i;
- float p = v * (1.0f - s);
- float q = v * (1.0f - (s * f));
- float t = v * (1.0f - (s * (1.0f - f)));
+ float p = v * (1.0F - s);
+ float q = v * (1.0F - (s * f));
+ float t = v * (1.0F - (s * (1.0F - f)));
float r, g, b;
switch (i)
@@ -155,7 +162,7 @@ namespace ImageProcessorCore
break;
}
- return new Color(r, g, b);
+ return new Color(r, g, b, 1);
}
///
@@ -168,7 +175,7 @@ namespace ImageProcessorCore
///
public static implicit operator Color(Hsl color)
{
- float rangedH = color.H / 360f;
+ float rangedH = color.H / 360F;
float r = 0;
float g = 0;
float b = 0;
@@ -192,7 +199,7 @@ namespace ImageProcessorCore
}
}
- return new Color(r, g, b);
+ return new Color(r, g, b, 1);
}
///
@@ -226,7 +233,7 @@ namespace ImageProcessorCore
float g = (x * -0.9689F) + (y * 1.8758F) + (z * 0.0415F);
float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F);
- return Color.Compress(new Color(r, g, b));
+ return new Color(new Vector4(r, g, b, 1F).Compress());
}
///
diff --git a/src/ImageProcessorCore/Colors/Colorspaces/Bgra32.cs b/src/ImageProcessorCore/Colors/Colorspaces/Bgra32.cs
index e31d693bb8..76a37a7a7b 100644
--- a/src/ImageProcessorCore/Colors/Colorspaces/Bgra32.cs
+++ b/src/ImageProcessorCore/Colors/Colorspaces/Bgra32.cs
@@ -80,8 +80,7 @@ namespace ImageProcessorCore
///
public static implicit operator Bgra32(Color color)
{
- color = color.Limited * 255f;
- return new Bgra32((byte)color.B, (byte)color.G, (byte)color.R, (byte)color.A);
+ return new Bgra32(color.B, color.G, color.R, color.A);
}
///
@@ -158,7 +157,7 @@ namespace ImageProcessorCore
/// Returns the hash code for this instance.
///
///
- /// The instance of to return the hash code for.
+ /// The instance of to return the hash code for.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
diff --git a/src/ImageProcessorCore/Colors/Colorspaces/CieLab.cs b/src/ImageProcessorCore/Colors/Colorspaces/CieLab.cs
index cce92601ad..2480262e00 100644
--- a/src/ImageProcessorCore/Colors/Colorspaces/CieLab.cs
+++ b/src/ImageProcessorCore/Colors/Colorspaces/CieLab.cs
@@ -71,7 +71,7 @@ namespace ImageProcessorCore
/// .
///
///
- /// The instance of to convert.
+ /// The instance of to convert.
///
///
/// An instance of .
@@ -79,11 +79,10 @@ namespace ImageProcessorCore
public static implicit operator CieLab(Color color)
{
// First convert to CIE XYZ
- color = Color.Expand(color);
-
- float x = (color.R * 0.4124F) + (color.G * 0.3576F) + (color.B * 0.1805F);
- float y = (color.R * 0.2126F) + (color.G * 0.7152F) + (color.B * 0.0722F);
- float z = (color.R * 0.0193F) + (color.G * 0.1192F) + (color.B * 0.9505F);
+ Vector4 vector = color.ToVector4().Expand();
+ float x = (vector.X * 0.4124F) + (vector.Y * 0.3576F) + (vector.Z * 0.1805F);
+ float y = (vector.X * 0.2126F) + (vector.Y * 0.7152F) + (vector.Z * 0.0722F);
+ float z = (vector.X * 0.0193F) + (vector.Y * 0.1192F) + (vector.Z * 0.9505F);
// Now to LAB
x /= 0.95047F;
diff --git a/src/ImageProcessorCore/Colors/Colorspaces/CieXyz.cs b/src/ImageProcessorCore/Colors/Colorspaces/CieXyz.cs
index 8f41c8abbe..528e4faf34 100644
--- a/src/ImageProcessorCore/Colors/Colorspaces/CieXyz.cs
+++ b/src/ImageProcessorCore/Colors/Colorspaces/CieXyz.cs
@@ -79,11 +79,11 @@ namespace ImageProcessorCore
///
public static implicit operator CieXyz(Color color)
{
- color = Color.Expand(color);
+ Vector4 vector = color.ToVector4().Expand();
- float x = (color.R * 0.4124F) + (color.G * 0.3576F) + (color.B * 0.1805F);
- float y = (color.R * 0.2126F) + (color.G * 0.7152F) + (color.B * 0.0722F);
- float z = (color.R * 0.0193F) + (color.G * 0.1192F) + (color.B * 0.9505F);
+ float x = (vector.X * 0.4124F) + (vector.Y * 0.3576F) + (vector.Z * 0.1805F);
+ float y = (vector.X * 0.2126F) + (vector.Y * 0.7152F) + (vector.Z * 0.0722F);
+ float z = (vector.X * 0.0193F) + (vector.Y * 0.1192F) + (vector.Z * 0.9505F);
x *= 100F;
y *= 100F;
diff --git a/src/ImageProcessorCore/Colors/Colorspaces/Cmyk.cs b/src/ImageProcessorCore/Colors/Colorspaces/Cmyk.cs
index b343288a68..6cb717e624 100644
--- a/src/ImageProcessorCore/Colors/Colorspaces/Cmyk.cs
+++ b/src/ImageProcessorCore/Colors/Colorspaces/Cmyk.cs
@@ -84,11 +84,9 @@ namespace ImageProcessorCore
///
public static implicit operator Cmyk(Color color)
{
- color = color.Limited;
-
- float c = 1f - color.R;
- float m = 1f - color.G;
- float y = 1f - color.B;
+ float c = 1f - color.R / 255F;
+ float m = 1f - color.G / 255F;
+ float y = 1f - color.B / 255F;
float k = Math.Min(c, Math.Min(m, y));
diff --git a/src/ImageProcessorCore/Colors/Colorspaces/Hsl.cs b/src/ImageProcessorCore/Colors/Colorspaces/Hsl.cs
index e6eee42e35..0e8812a257 100644
--- a/src/ImageProcessorCore/Colors/Colorspaces/Hsl.cs
+++ b/src/ImageProcessorCore/Colors/Colorspaces/Hsl.cs
@@ -22,7 +22,7 @@ namespace ImageProcessorCore
///
/// The epsilon for comparing floating point numbers.
///
- private const float Epsilon = 0.001f;
+ private const float Epsilon = 0.001F;
///
/// The backing vector for SIMD support.
@@ -74,10 +74,9 @@ namespace ImageProcessorCore
///
public static implicit operator Hsl(Color color)
{
- color = Color.ToNonPremultiplied(color.Limited);
- float r = color.R;
- float g = color.G;
- float b = color.B;
+ float r = color.R / 255F;
+ float g = color.G / 255F;
+ float b = color.B / 255F;
float max = Math.Max(r, Math.Max(g, b));
float min = Math.Min(r, Math.Min(g, b));
@@ -114,7 +113,8 @@ namespace ImageProcessorCore
{
s = chroma / (max + min);
}
- else {
+ else
+ {
s = chroma / (2 - chroma);
}
diff --git a/src/ImageProcessorCore/Colors/Colorspaces/Hsv.cs b/src/ImageProcessorCore/Colors/Colorspaces/Hsv.cs
index 914df51c97..0a22ac2731 100644
--- a/src/ImageProcessorCore/Colors/Colorspaces/Hsv.cs
+++ b/src/ImageProcessorCore/Colors/Colorspaces/Hsv.cs
@@ -22,7 +22,7 @@ namespace ImageProcessorCore
///
/// The epsilon for comparing floating point numbers.
///
- private const float Epsilon = 0.001f;
+ private const float Epsilon = 0.001F;
///
/// The backing vector for SIMD support.
@@ -74,10 +74,9 @@ namespace ImageProcessorCore
///
public static implicit operator Hsv(Color color)
{
- color = Color.ToNonPremultiplied(color.Limited);
- float r = color.R;
- float g = color.G;
- float b = color.B;
+ float r = color.R / 255F;
+ float g = color.G / 255F;
+ float b = color.B / 255F;
float max = Math.Max(r, Math.Max(g, b));
float min = Math.Min(r, Math.Min(g, b));
diff --git a/src/ImageProcessorCore/Colors/IAlmostEquatable.cs b/src/ImageProcessorCore/Colors/Colorspaces/IAlmostEquatable.cs
similarity index 100%
rename from src/ImageProcessorCore/Colors/IAlmostEquatable.cs
rename to src/ImageProcessorCore/Colors/Colorspaces/IAlmostEquatable.cs
diff --git a/src/ImageProcessorCore/Colors/Colorspaces/YCbCr.cs b/src/ImageProcessorCore/Colors/Colorspaces/YCbCr.cs
index 5c47c6c087..64560d7d0d 100644
--- a/src/ImageProcessorCore/Colors/Colorspaces/YCbCr.cs
+++ b/src/ImageProcessorCore/Colors/Colorspaces/YCbCr.cs
@@ -24,7 +24,7 @@ namespace ImageProcessorCore
///
/// The epsilon for comparing floating point numbers.
///
- private const float Epsilon = 0.001f;
+ private const float Epsilon = 0.001F;
///
/// The backing vector for SIMD support.
@@ -79,7 +79,6 @@ namespace ImageProcessorCore
///
public static implicit operator YCbCr(Color color)
{
- color = Color.ToNonPremultiplied(color.Limited) * 255f;
float r = color.R;
float g = color.G;
float b = color.B;
@@ -173,7 +172,7 @@ namespace ImageProcessorCore
/// Returns the hash code for this instance.
///
///
- /// The instance of to return the hash code for.
+ /// The instance of to return the hash code for.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
diff --git a/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs b/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs
new file mode 100644
index 0000000000..99cd70d748
--- /dev/null
+++ b/src/ImageProcessorCore/Colors/PackedVector/IPackedVector.cs
@@ -0,0 +1,63 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageProcessorCore
+{
+ using System.Numerics;
+
+ ///
+ /// An interface that converts packed vector types to and from values,
+ /// allowing multiple encodings to be manipulated in a generic way.
+ ///
+ /// The packed format. long, float.
+ public interface IPackedVector : IPackedVector
+ where TP : struct
+ {
+ ///
+ /// Gets the packed representation of the value.
+ /// Typically packed in least to greatest significance order.
+ ///
+ ///
+ /// The .
+ ///
+ TP PackedValue();
+ }
+
+ ///
+ /// An interface that converts packed vector types to and from values.
+ ///
+ public interface IPackedVector
+ {
+ ///
+ /// Sets the packed representation from a .
+ ///
+ /// The vector to pack.
+ void PackVector(Vector4 vector);
+
+ ///
+ /// Sets the packed representation from a .
+ ///
+ /// The x-component.
+ /// The y-component.
+ /// The z-component.
+ /// The w-component.
+ void PackBytes(byte x, byte y, byte z, byte w);
+
+ ///
+ /// Expands the packed representation into a .
+ /// The vector components are typically expanded in least to greatest significance order.
+ ///
+ /// The .
+ Vector4 ToVector4();
+
+ ///
+ /// Expands the packed representation into a .
+ /// The bytes are typically expanded in least to greatest significance order.
+ /// Red -> Green -> Blue -> Alpha
+ ///
+ /// The .
+ byte[] ToBytes();
+ }
+}
diff --git a/src/ImageProcessorCore/Colors/RgbaComponent.cs b/src/ImageProcessorCore/Colors/RgbaComponent.cs
index a4b668cb62..946c47a377 100644
--- a/src/ImageProcessorCore/Colors/RgbaComponent.cs
+++ b/src/ImageProcessorCore/Colors/RgbaComponent.cs
@@ -11,9 +11,9 @@ namespace ImageProcessorCore
public enum RgbaComponent
{
///
- /// The blue component.
+ /// The red component.
///
- B = 0,
+ R = 0,
///
/// The green component.
@@ -21,9 +21,9 @@ namespace ImageProcessorCore
G = 1,
///
- /// The red component.
+ /// The blue component.
///
- R = 2,
+ B = 2,
///
/// The alpha component.
diff --git a/src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs b/src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs
new file mode 100644
index 0000000000..97d2b66d70
--- /dev/null
+++ b/src/ImageProcessorCore/Common/Extensions/Vector4Extensions.cs
@@ -0,0 +1,91 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageProcessorCore
+{
+ using System;
+ using System.Numerics;
+ using System.Runtime.CompilerServices;
+
+ ///
+ /// Extension methods for the struct.
+ ///
+ public static class Vector4Extensions
+ {
+ ///
+ /// Compresses a linear color signal to its sRGB equivalent.
+ ///
+ ///
+ ///
+ /// The whose signal to compress.
+ /// The .
+ public static Vector4 Compress(this Vector4 linear)
+ {
+ // TODO: Is there a faster way to do this?
+ float r = Compress(linear.X);
+ float g = Compress(linear.Y);
+ float b = Compress(linear.Z);
+
+ return new Vector4(r, g, b, linear.W);
+ }
+
+ ///
+ /// Expands an sRGB color signal to its linear equivalent.
+ ///
+ ///
+ ///
+ /// The whose signal to expand.
+ /// The .
+ public static Vector4 Expand(this Vector4 gamma)
+ {
+ // TODO: Is there a faster way to do this?
+ float r = Expand(gamma.X);
+ float g = Expand(gamma.Y);
+ float b = Expand(gamma.Z);
+
+ return new Vector4(r, g, b, gamma.W);
+ }
+
+ ///
+ /// Gets the compressed sRGB value from an linear signal.
+ ///
+ ///
+ ///
+ /// The signal value to compress.
+ ///
+ /// The .
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static float Compress(float signal)
+ {
+ if (signal <= 0.0031308f)
+ {
+ return signal * 12.92f;
+ }
+
+ return (1.055f * (float)Math.Pow(signal, 0.41666666f)) - 0.055f;
+ }
+
+ ///
+ /// Gets the expanded linear value from an sRGB signal.
+ ///
+ ///
+ ///
+ /// The signal value to expand.
+ ///
+ /// The .
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static float Expand(float signal)
+ {
+ if (signal <= 0.04045f)
+ {
+ return signal / 12.92f;
+ }
+
+ return (float)Math.Pow((signal + 0.055f) / 1.055f, 2.4f);
+ }
+ }
+}
diff --git a/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs b/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs
index 051b75f70f..9b890d1c0b 100644
--- a/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs
+++ b/src/ImageProcessorCore/Common/Helpers/ImageMaths.cs
@@ -61,25 +61,25 @@ namespace ImageProcessorCore
{
float temp;
- if (x < 0)
+ if (x < 0F)
{
x = -x;
}
temp = x * x;
- if (x < 1)
+ if (x < 1F)
{
x = ((12 - (9 * b) - (6 * c)) * (x * temp)) + ((-18 + (12 * b) + (6 * c)) * temp) + (6 - (2 * b));
- return x / 6;
+ return x / 6F;
}
- if (x < 2)
+ if (x < 2F)
{
x = ((-b - (6 * c)) * (x * temp)) + (((6 * b) + (30 * c)) * temp) + (((-12 * b) - (48 * c)) * x) + ((8 * b) + (24 * c));
- return x / 6;
+ return x / 6F;
}
- return 0;
+ return 0F;
}
///
@@ -91,7 +91,7 @@ namespace ImageProcessorCore
///
public static float SinC(float x)
{
- const float Epsilon = .00001f;
+ const float Epsilon = .00001F;
if (Math.Abs(x) > Epsilon)
{
@@ -156,13 +156,17 @@ namespace ImageProcessorCore
/// Finds the bounding rectangle based on the first instance of any color component other
/// than the given one.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The to search within.
/// The color component value to remove.
/// The channel to test against.
///
/// The .
///
- public static Rectangle GetFilteredBoundingRectangle(ImageBase bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
+ public static Rectangle GetFilteredBoundingRectangle(ImageBase bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
+ where T : IPackedVector
+ where TP : struct
{
const float Epsilon = .00001f;
int width = bitmap.Width;
@@ -170,29 +174,29 @@ namespace ImageProcessorCore
Point topLeft = new Point();
Point bottomRight = new Point();
- Func delegateFunc;
+ Func, int, int, float, bool> delegateFunc;
// Determine which channel to check against
switch (channel)
{
case RgbaComponent.R:
- delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].R - b) > Epsilon;
+ delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToBytes()[0] - b) > Epsilon;
break;
case RgbaComponent.G:
- delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].G - b) > Epsilon;
+ delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToBytes()[1] - b) > Epsilon;
break;
- case RgbaComponent.A:
- delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].A - b) > Epsilon;
+ case RgbaComponent.B:
+ delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToBytes()[2] - b) > Epsilon;
break;
default:
- delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].B - b) > Epsilon;
+ delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToBytes()[3] - b) > Epsilon;
break;
}
- Func getMinY = pixels =>
+ Func, int> getMinY = pixels =>
{
for (int y = 0; y < height; y++)
{
@@ -208,7 +212,7 @@ namespace ImageProcessorCore
return 0;
};
- Func getMaxY = pixels =>
+ Func, int> getMaxY = pixels =>
{
for (int y = height - 1; y > -1; y--)
{
@@ -224,7 +228,7 @@ namespace ImageProcessorCore
return height;
};
- Func getMinX = pixels =>
+ Func, int> getMinX = pixels =>
{
for (int x = 0; x < width; x++)
{
@@ -240,7 +244,7 @@ namespace ImageProcessorCore
return 0;
};
- Func getMaxX = pixels =>
+ Func, int> getMaxX = pixels =>
{
for (int x = width - 1; x > -1; x--)
{
@@ -256,7 +260,7 @@ namespace ImageProcessorCore
return height;
};
- using (PixelAccessor bitmapPixels = bitmap.Lock())
+ using (IPixelAccessor bitmapPixels = bitmap.Lock())
{
topLeft.Y = getMinY(bitmapPixels);
topLeft.X = getMinX(bitmapPixels);
@@ -276,11 +280,11 @@ namespace ImageProcessorCore
/// .
private static float Clean(float x)
{
- const float Epsilon = .00001f;
+ const float Epsilon = .00001F;
if (Math.Abs(x) < Epsilon)
{
- return 0f;
+ return 0F;
}
return x;
diff --git a/src/ImageProcessorCore/Filters/Alpha.cs b/src/ImageProcessorCore/Filters/Alpha.cs
index 3532bb675d..545639afa0 100644
--- a/src/ImageProcessorCore/Filters/Alpha.cs
+++ b/src/ImageProcessorCore/Filters/Alpha.cs
@@ -1,7 +1,7 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
@@ -15,11 +15,15 @@ namespace ImageProcessorCore
///
/// Alters the alpha component of the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The new opacity of the image. Must be between 0 and 100.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Alpha(this Image source, int percent, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Alpha(this Image source, int percent, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Alpha(source, percent, source.Bounds, progressHandler);
}
@@ -27,6 +31,8 @@ namespace ImageProcessorCore
///
/// Alters the alpha component of the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The new opacity of the image. Must be between 0 and 100.
///
@@ -34,9 +40,11 @@ namespace ImageProcessorCore
///
/// A delegate which is called as progress is made processing the image.
/// The .
- public static Image Alpha(this Image source, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ public static Image Alpha(this Image source, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- AlphaProcessor processor = new AlphaProcessor(percent);
+ AlphaProcessor processor = new AlphaProcessor(percent);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/BackgroundColor.cs b/src/ImageProcessorCore/Filters/BackgroundColor.cs
index 98709cb32c..44f46598b5 100644
--- a/src/ImageProcessorCore/Filters/BackgroundColor.cs
+++ b/src/ImageProcessorCore/Filters/BackgroundColor.cs
@@ -1,27 +1,31 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
- /// Combines the given image together with the current one by blending their pixels.
+ /// Replaces the background color of image with the given one.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The color to set as the background.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image BackgroundColor(this Image source, Color color, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image BackgroundColor(this Image source, T color, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- BackgroundColorProcessor processor = new BackgroundColorProcessor(color);
+ BackgroundColorProcessor processor = new BackgroundColorProcessor(color);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/BinaryThreshold.cs b/src/ImageProcessorCore/Filters/BinaryThreshold.cs
new file mode 100644
index 0000000000..5d244ead4d
--- /dev/null
+++ b/src/ImageProcessorCore/Filters/BinaryThreshold.cs
@@ -0,0 +1,60 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageProcessorCore
+{
+ using Processors;
+
+ ///
+ /// Extension methods for the type.
+ ///
+ public static partial class ImageExtensions
+ {
+ ///
+ /// Applies binerization to the image splitting the pixels at the given threshold.
+ ///
+ /// The pixel format.
+ /// The packed format. long, float.
+ /// The image this method extends.
+ /// The threshold to apply binerization of the image. Must be between 0 and 1.
+ /// A delegate which is called as progress is made processing the image.
+ /// The .
+ public static Image BinaryThreshold(this Image source, float threshold, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
+ {
+ return BinaryThreshold(source, threshold, source.Bounds, progressHandler);
+ }
+
+ ///
+ /// Applies binerization to the image splitting the pixels at the given threshold.
+ ///
+ /// The pixel format.
+ /// The packed format. long, float.
+ /// The image this method extends.
+ /// The threshold to apply binerization of the image. Must be between 0 and 1.
+ ///
+ /// The structure that specifies the portion of the image object to alter.
+ ///
+ /// A delegate which is called as progress is made processing the image.
+ /// The .
+ public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
+ {
+ BinaryThresholdProcessor processor = new BinaryThresholdProcessor(threshold);
+ processor.OnProgress += progressHandler;
+
+ try
+ {
+ return source.Process(rectangle, processor);
+ }
+ finally
+ {
+ processor.OnProgress -= progressHandler;
+ }
+ }
+ }
+}
diff --git a/src/ImageProcessorCore/Filters/BlackWhite.cs b/src/ImageProcessorCore/Filters/BlackWhite.cs
index 98c3b7744a..8799cfe64f 100644
--- a/src/ImageProcessorCore/Filters/BlackWhite.cs
+++ b/src/ImageProcessorCore/Filters/BlackWhite.cs
@@ -1,24 +1,28 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Applies black and white toning to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image BlackWhite(this Image source, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image BlackWhite(this Image source, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return BlackWhite(source, source.Bounds, progressHandler);
}
@@ -26,15 +30,19 @@ namespace ImageProcessorCore
///
/// Applies black and white toning to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image BlackWhite(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image BlackWhite(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- BlackWhiteProcessor processor = new BlackWhiteProcessor();
+ BlackWhiteProcessor processor = new BlackWhiteProcessor();
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Blend.cs b/src/ImageProcessorCore/Filters/Blend.cs
index 77a94e3fa3..96f8f60cda 100644
--- a/src/ImageProcessorCore/Filters/Blend.cs
+++ b/src/ImageProcessorCore/Filters/Blend.cs
@@ -16,14 +16,15 @@ namespace ImageProcessorCore
/// Combines the given image together with the current one by blending their pixels.
///
/// The image this method extends.
- ///
- /// The image to blend with the currently processing image.
- /// Disposal of this image is the responsibility of the developer.
- ///
+ /// The image to blend with the currently processing image.
+ /// The pixel format.
+ /// The packed format. long, float.
/// The opacity of the image image to blend. Must be between 0 and 100.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Blend(this Image source, ImageBase image, int percent = 50, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Blend(this Image source, ImageBase image, int percent = 50, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Blend(source, image, percent, source.Bounds, progressHandler);
}
@@ -32,19 +33,20 @@ namespace ImageProcessorCore
/// Combines the given image together with the current one by blending their pixels.
///
/// The image this method extends.
- ///
- /// The image to blend with the currently processing image.
- /// Disposal of this image is the responsibility of the developer.
- ///
+ /// The image to blend with the currently processing image.
+ /// The pixel format.
+ /// The packed format. long, float.
/// The opacity of the image image to blend. Must be between 0 and 100.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Blend(this Image source, ImageBase image, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Blend(this Image source, ImageBase image, int percent, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- BlendProcessor processor = new BlendProcessor(image, percent);
+ BlendProcessor processor = new BlendProcessor(image, percent);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/BoxBlur.cs b/src/ImageProcessorCore/Filters/BoxBlur.cs
index 474f0d6e77..e1970228f3 100644
--- a/src/ImageProcessorCore/Filters/BoxBlur.cs
+++ b/src/ImageProcessorCore/Filters/BoxBlur.cs
@@ -1,25 +1,29 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Applies a box blur to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The 'radius' value representing the size of the area to sample.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image BoxBlur(this Image source, int radius = 7, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image BoxBlur(this Image source, int radius = 7, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return BoxBlur(source, radius, source.Bounds, progressHandler);
}
@@ -27,16 +31,20 @@ namespace ImageProcessorCore
///
/// Applies a box blur to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The 'radius' value representing the size of the area to sample.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image BoxBlur(this Image source, int radius, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image BoxBlur(this Image source, int radius, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- BoxBlurProcessor processor = new BoxBlurProcessor(radius);
+ BoxBlurProcessor processor = new BoxBlurProcessor(radius);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Brightness.cs b/src/ImageProcessorCore/Filters/Brightness.cs
index 52944c8010..fb29ff0d9c 100644
--- a/src/ImageProcessorCore/Filters/Brightness.cs
+++ b/src/ImageProcessorCore/Filters/Brightness.cs
@@ -1,25 +1,29 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Alters the brightness component of the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The new brightness of the image. Must be between -100 and 100.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Brightness(this Image source, int amount, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Brightness(this Image source, int amount, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Brightness(source, amount, source.Bounds, progressHandler);
}
@@ -27,16 +31,20 @@ namespace ImageProcessorCore
///
/// Alters the brightness component of the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The new brightness of the image. Must be between -100 and 100.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Brightness(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Brightness(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- BrightnessProcessor processor = new BrightnessProcessor(amount);
+ BrightnessProcessor processor = new BrightnessProcessor(amount);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/ColorBlindness.cs b/src/ImageProcessorCore/Filters/ColorBlindness.cs
index 78267b05e3..6ab553ba2d 100644
--- a/src/ImageProcessorCore/Filters/ColorBlindness.cs
+++ b/src/ImageProcessorCore/Filters/ColorBlindness.cs
@@ -1,25 +1,29 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Applies the given colorblindness simulator to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The type of color blindness simulator to apply.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return ColorBlindness(source, colorBlindness, source.Bounds, progressHandler);
}
@@ -27,49 +31,53 @@ namespace ImageProcessorCore
///
/// Applies the given colorblindness simulator to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The type of color blindness simulator to apply.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- IImageProcessor processor;
+ IImageProcessor processor;
switch (colorBlindness)
{
case ImageProcessorCore.ColorBlindness.Achromatomaly:
- processor = new AchromatomalyProcessor();
+ processor = new AchromatomalyProcessor();
break;
case ImageProcessorCore.ColorBlindness.Achromatopsia:
- processor = new AchromatopsiaProcessor();
+ processor = new AchromatopsiaProcessor();
break;
case ImageProcessorCore.ColorBlindness.Deuteranomaly:
- processor = new DeuteranomalyProcessor();
+ processor = new DeuteranomalyProcessor();
break;
case ImageProcessorCore.ColorBlindness.Deuteranopia:
- processor = new DeuteranopiaProcessor();
+ processor = new DeuteranopiaProcessor();
break;
case ImageProcessorCore.ColorBlindness.Protanomaly:
- processor = new ProtanomalyProcessor();
+ processor = new ProtanomalyProcessor();
break;
case ImageProcessorCore.ColorBlindness.Protanopia:
- processor = new ProtanopiaProcessor();
+ processor = new ProtanopiaProcessor();
break;
case ImageProcessorCore.ColorBlindness.Tritanomaly:
- processor = new TritanomalyProcessor();
+ processor = new TritanomalyProcessor();
break;
default:
- processor = new TritanopiaProcessor();
+ processor = new TritanopiaProcessor();
break;
}
diff --git a/src/ImageProcessorCore/Filters/Contrast.cs b/src/ImageProcessorCore/Filters/Contrast.cs
index cab12ca4e5..5025daf641 100644
--- a/src/ImageProcessorCore/Filters/Contrast.cs
+++ b/src/ImageProcessorCore/Filters/Contrast.cs
@@ -1,25 +1,29 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Alters the contrast component of the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The new contrast of the image. Must be between -100 and 100.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Contrast(this Image source, int amount, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Contrast(this Image source, int amount, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Contrast(source, amount, source.Bounds, progressHandler);
}
@@ -27,16 +31,20 @@ namespace ImageProcessorCore
///
/// Alters the contrast component of the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The new contrast of the image. Must be between -100 and 100.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Contrast(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Contrast(this Image source, int amount, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- ContrastProcessor processor = new ContrastProcessor(amount);
+ ContrastProcessor processor = new ContrastProcessor(amount);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/DetectEdges.cs b/src/ImageProcessorCore/Filters/DetectEdges.cs
index ac3a0282d5..33fa00d30d 100644
--- a/src/ImageProcessorCore/Filters/DetectEdges.cs
+++ b/src/ImageProcessorCore/Filters/DetectEdges.cs
@@ -1,37 +1,103 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Detects any edges within the image. Uses the filter
- /// operating in greyscale mode.
+ /// operating in Grayscale mode.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image DetectEdges(this Image source, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image DetectEdges(this Image source, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- return DetectEdges(source, source.Bounds, new SobelProcessor { Greyscale = true }, progressHandler);
+ return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }, progressHandler);
}
///
/// Detects any edges within the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The filter for detecting edges.
+ /// Whether to convert the image to Grayscale first. Defaults to true.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image DetectEdges(this Image source, EdgeDetection filter, bool Grayscale = true, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
+ {
+ IEdgeDetectorFilter processor;
+
+ switch (filter)
+ {
+ case EdgeDetection.Kayyali:
+ processor = new KayyaliProcessor { Grayscale = Grayscale };
+ break;
+
+ case EdgeDetection.Kirsch:
+ processor = new KirschProcessor { Grayscale = Grayscale };
+ break;
+
+ case EdgeDetection.Lapacian3X3:
+ processor = new Laplacian3X3Processor { Grayscale = Grayscale };
+ break;
+
+ case EdgeDetection.Lapacian5X5:
+ processor = new Laplacian5X5Processor { Grayscale = Grayscale };
+ break;
+
+ case EdgeDetection.LaplacianOfGaussian:
+ processor = new LaplacianOfGaussianProcessor { Grayscale = Grayscale };
+ break;
+
+ case EdgeDetection.Prewitt:
+ processor = new PrewittProcessor { Grayscale = Grayscale };
+ break;
+
+ case EdgeDetection.RobertsCross:
+ processor = new RobertsCrossProcessor { Grayscale = Grayscale };
+ break;
+
+ case EdgeDetection.Scharr:
+ processor = new ScharrProcessor { Grayscale = Grayscale };
+ break;
+
+ default:
+ processor = new ScharrProcessor { Grayscale = Grayscale };
+ break;
+ }
+
+ return DetectEdges(source, source.Bounds, processor, progressHandler);
+ }
+
+ ///
+ /// Detects any edges within the image.
+ ///
+ /// The pixel format.
+ /// The packed format. long, float.
+ /// The image this method extends.
+ /// The filter for detecting edges.
+ /// A delegate which is called as progress is made processing the image.
+ /// The .
+ public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return DetectEdges(source, source.Bounds, filter, progressHandler);
}
@@ -45,8 +111,10 @@ namespace ImageProcessorCore
///
/// The filter for detecting edges.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
filter.OnProgress += progressHandler;
diff --git a/src/ImageProcessorCore/Filters/Greyscale.cs b/src/ImageProcessorCore/Filters/Grayscale.cs
similarity index 50%
rename from src/ImageProcessorCore/Filters/Greyscale.cs
rename to src/ImageProcessorCore/Filters/Grayscale.cs
index 786a935766..46ef445266 100644
--- a/src/ImageProcessorCore/Filters/Greyscale.cs
+++ b/src/ImageProcessorCore/Filters/Grayscale.cs
@@ -1,44 +1,52 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
- /// Applies greyscale toning to the image.
+ /// Applies Grayscale toning to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The formula to apply to perform the operation.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Greyscale(this Image source, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Grayscale(this Image source, GrayscaleMode mode = GrayscaleMode.Bt709, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- return Greyscale(source, source.Bounds, mode, progressHandler);
+ return Grayscale(source, source.Bounds, mode, progressHandler);
}
///
- /// Applies greyscale toning to the image.
+ /// Applies Grayscale toning to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// The formula to apply to perform the operation.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Greyscale(this Image source, Rectangle rectangle, GreyscaleMode mode = GreyscaleMode.Bt709, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- IImageProcessor processor = mode == GreyscaleMode.Bt709
- ? (IImageProcessor)new GreyscaleBt709Processor()
- : new GreyscaleBt601Processor();
+ IImageProcessor processor = mode == GrayscaleMode.Bt709
+ ? (IImageProcessor)new GrayscaleBt709Processor()
+ : new GrayscaleBt601Processor();
processor.OnProgress += progressHandler;
diff --git a/src/ImageProcessorCore/Filters/GuassianBlur.cs b/src/ImageProcessorCore/Filters/GuassianBlur.cs
index 646c6bdc08..a57f43b2c2 100644
--- a/src/ImageProcessorCore/Filters/GuassianBlur.cs
+++ b/src/ImageProcessorCore/Filters/GuassianBlur.cs
@@ -1,25 +1,29 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Applies a Guassian blur to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The 'sigma' value representing the weight of the blur.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image GuassianBlur(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image GuassianBlur(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return GuassianBlur(source, sigma, source.Bounds, progressHandler);
}
@@ -27,16 +31,20 @@ namespace ImageProcessorCore
///
/// Applies a Guassian blur to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The 'sigma' value representing the weight of the blur.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image GuassianBlur(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image GuassianBlur(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- GuassianBlurProcessor processor = new GuassianBlurProcessor(sigma);
+ GuassianBlurProcessor processor = new GuassianBlurProcessor(sigma);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/GuassianSharpen.cs b/src/ImageProcessorCore/Filters/GuassianSharpen.cs
index 06993070d8..6fb888cdfc 100644
--- a/src/ImageProcessorCore/Filters/GuassianSharpen.cs
+++ b/src/ImageProcessorCore/Filters/GuassianSharpen.cs
@@ -1,25 +1,29 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Applies a Guassian sharpening filter to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The 'sigma' value representing the weight of the blur.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image GuassianSharpen(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image GuassianSharpen(this Image source, float sigma = 3f, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return GuassianSharpen(source, sigma, source.Bounds, progressHandler);
}
@@ -27,16 +31,20 @@ namespace ImageProcessorCore
///
/// Applies a Guassian sharpening filter to the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The 'sigma' value representing the weight of the blur.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image GuassianSharpen(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image GuassianSharpen(this Image source, float sigma, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- GuassianSharpenProcessor processor = new GuassianSharpenProcessor(sigma);
+ GuassianSharpenProcessor processor = new GuassianSharpenProcessor(sigma);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Hue.cs b/src/ImageProcessorCore/Filters/Hue.cs
index 45a995c301..a4de7c6102 100644
--- a/src/ImageProcessorCore/Filters/Hue.cs
+++ b/src/ImageProcessorCore/Filters/Hue.cs
@@ -1,25 +1,29 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Alters the hue component of the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The angle in degrees to adjust the image.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Hue(this Image source, float degrees, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Hue(this Image source, float degrees, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Hue(source, degrees, source.Bounds, progressHandler);
}
@@ -27,16 +31,20 @@ namespace ImageProcessorCore
///
/// Alters the hue component of the image.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// The angle in degrees to adjust the image.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Hue(this Image source, float degrees, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Hue(this Image source, float degrees, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- HueProcessor processor = new HueProcessor(degrees);
+ HueProcessor processor = new HueProcessor(degrees);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Invert.cs b/src/ImageProcessorCore/Filters/Invert.cs
index eaeddfc62b..d7888be591 100644
--- a/src/ImageProcessorCore/Filters/Invert.cs
+++ b/src/ImageProcessorCore/Filters/Invert.cs
@@ -18,7 +18,9 @@ namespace ImageProcessorCore
/// The image this method extends.
/// A delegate which is called as progress is made processing the image.
/// The .
- public static Image Invert(this Image source, ProgressEventHandler progressHandler = null)
+ public static Image Invert(this Image source, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Invert(source, source.Bounds, progressHandler);
}
@@ -32,9 +34,11 @@ namespace ImageProcessorCore
///
/// A delegate which is called as progress is made processing the image.
/// The .
- public static Image Invert(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ public static Image Invert(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- InvertProcessor processor = new InvertProcessor();
+ InvertProcessor processor = new InvertProcessor();
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Kodachrome.cs b/src/ImageProcessorCore/Filters/Kodachrome.cs
index 3b4e3f1c66..0f4bf2ae83 100644
--- a/src/ImageProcessorCore/Filters/Kodachrome.cs
+++ b/src/ImageProcessorCore/Filters/Kodachrome.cs
@@ -1,24 +1,28 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Alters the colors of the image recreating an old Kodachrome camera effect.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Kodachrome(this Image source, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Kodachrome(this Image source, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Kodachrome(source, source.Bounds, progressHandler);
}
@@ -26,15 +30,19 @@ namespace ImageProcessorCore
///
/// Alters the colors of the image recreating an old Kodachrome camera effect.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Kodachrome(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- KodachromeProcessor processor = new KodachromeProcessor();
+ KodachromeProcessor processor = new KodachromeProcessor();
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Lomograph.cs b/src/ImageProcessorCore/Filters/Lomograph.cs
index 5ecf0bcf4a..5a484bcc87 100644
--- a/src/ImageProcessorCore/Filters/Lomograph.cs
+++ b/src/ImageProcessorCore/Filters/Lomograph.cs
@@ -1,24 +1,28 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Alters the colors of the image recreating an old Lomograph camera effect.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Lomograph(this Image source, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Lomograph(this Image source, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Lomograph(source, source.Bounds, progressHandler);
}
@@ -26,15 +30,19 @@ namespace ImageProcessorCore
///
/// Alters the colors of the image recreating an old Lomograph camera effect.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Lomograph(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Lomograph(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- LomographProcessor processor = new LomographProcessor();
+ LomographProcessor processor = new LomographProcessor();
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Options/ColorBlindness.cs b/src/ImageProcessorCore/Filters/Options/ColorBlindness.cs
index 6d7fe849bc..e128044cd8 100644
--- a/src/ImageProcessorCore/Filters/Options/ColorBlindness.cs
+++ b/src/ImageProcessorCore/Filters/Options/ColorBlindness.cs
@@ -6,7 +6,7 @@
namespace ImageProcessorCore
{
///
- /// Enumerates the various types of color blindness.
+ /// Enumerates the various types of defined color blindness filters.
///
public enum ColorBlindness
{
diff --git a/src/ImageProcessorCore/Filters/Options/EdgeDetection.cs b/src/ImageProcessorCore/Filters/Options/EdgeDetection.cs
new file mode 100644
index 0000000000..f637e4573e
--- /dev/null
+++ b/src/ImageProcessorCore/Filters/Options/EdgeDetection.cs
@@ -0,0 +1,58 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageProcessorCore
+{
+ ///
+ /// Enumerates the various types of defined edge detection filters.
+ ///
+ public enum EdgeDetection
+ {
+ ///
+ /// The Kayyali operator filter.
+ ///
+ Kayyali,
+
+ ///
+ /// The Kirsch operator filter.
+ ///
+ Kirsch,
+
+ ///
+ /// The Lapacian3X3 operator filter.
+ ///
+ Lapacian3X3,
+
+ ///
+ /// The Lapacian5X5 operator filter.
+ ///
+ Lapacian5X5,
+
+ ///
+ /// The LaplacianOfGaussian operator filter.
+ ///
+ LaplacianOfGaussian,
+
+ ///
+ /// The Prewitt operator filter.
+ ///
+ Prewitt,
+
+ ///
+ /// The RobertsCross operator filter.
+ ///
+ RobertsCross,
+
+ ///
+ /// The Scharr operator filter.
+ ///
+ Scharr,
+
+ ///
+ /// The Sobel operator filter.
+ ///
+ Sobel
+ }
+}
diff --git a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleMode.cs b/src/ImageProcessorCore/Filters/Options/GrayscaleMode.cs
similarity index 64%
rename from src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleMode.cs
rename to src/ImageProcessorCore/Filters/Options/GrayscaleMode.cs
index 269c1179ef..9c1b9df5d4 100644
--- a/src/ImageProcessorCore/Filters/Processors/ColorMatrix/GreyscaleMode.cs
+++ b/src/ImageProcessorCore/Filters/Options/GrayscaleMode.cs
@@ -1,14 +1,14 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
-namespace ImageProcessorCore.Processors
+namespace ImageProcessorCore
{
///
- /// Provides enumeration over the various greyscale methods available.
+ /// Enumerates the various types of defined Grayscale filters.
///
- public enum GreyscaleMode
+ public enum GrayscaleMode
{
///
/// ITU-R Recommendation BT.709
diff --git a/src/ImageProcessorCore/Filters/Pixelate.cs b/src/ImageProcessorCore/Filters/Pixelate.cs
index 6f86848d6a..8bfb7cd2d5 100644
--- a/src/ImageProcessorCore/Filters/Pixelate.cs
+++ b/src/ImageProcessorCore/Filters/Pixelate.cs
@@ -1,15 +1,18 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
+ using System;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
+ /// The pixel format.
+ /// The packed format. long, float.
public static partial class ImageExtensions
{
///
@@ -18,8 +21,10 @@ namespace ImageProcessorCore
/// The image this method extends.
/// The size of the pixels.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Pixelate(this Image source, int size = 4, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Pixelate(this Image source, int size = 4, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Pixelate(source, size, source.Bounds, progressHandler);
}
@@ -33,10 +38,17 @@ namespace ImageProcessorCore
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Pixelate(this Image source, int size, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Pixelate(this Image source, int size, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- PixelateProcessor processor = new PixelateProcessor(size);
+ if (size <= 0 || size > source.Height || size > source.Width)
+ {
+ throw new ArgumentOutOfRangeException(nameof(size));
+ }
+
+ PixelateProcessor processor = new PixelateProcessor(size);
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Polaroid.cs b/src/ImageProcessorCore/Filters/Polaroid.cs
index 165f1d59a5..e56496322c 100644
--- a/src/ImageProcessorCore/Filters/Polaroid.cs
+++ b/src/ImageProcessorCore/Filters/Polaroid.cs
@@ -1,24 +1,28 @@
//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
-// -------------------------------------------------------------------------------------------------------------------
+//
namespace ImageProcessorCore
{
using Processors;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Alters the colors of the image recreating an old Polaroid camera effect.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Polaroid(this Image source, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Polaroid(this Image source, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
return Polaroid(source, source.Bounds, progressHandler);
}
@@ -26,15 +30,19 @@ namespace ImageProcessorCore
///
/// Alters the colors of the image recreating an old Polaroid camera effect.
///
+ /// The pixel format.
+ /// The packed format. long, float.
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// A delegate which is called as progress is made processing the image.
- /// The .
- public static Image Polaroid(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ /// The .
+ public static Image Polaroid(this Image source, Rectangle rectangle, ProgressEventHandler progressHandler = null)
+ where T : IPackedVector
+ where TP : struct
{
- PolaroidProcessor processor = new PolaroidProcessor();
+ PolaroidProcessor processor = new PolaroidProcessor();
processor.OnProgress += progressHandler;
try
diff --git a/src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs b/src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs
index 8ed703e034..b2a2520c3b 100644
--- a/src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs
+++ b/src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs
@@ -5,17 +5,20 @@
namespace ImageProcessorCore.Processors
{
- using System;
using System.Numerics;
using System.Threading.Tasks;
///
- /// An to change the Alpha of an .
+ /// An to change the Alpha of an .
///
- public class AlphaProcessor : ImageProcessor
+ /// The pixel format.
+ /// The packed format. long, float.
+ public class AlphaProcessor : ImageProcessor
+ where T : IPackedVector
+ where TP : struct
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The percentage to adjust the opacity of the image. Must be between 0 and 100.
///
@@ -33,7 +36,7 @@ namespace ImageProcessorCore.Processors
public int Value { get; }
///
- protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
+ protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
float alpha = this.Value / 100f;
int sourceY = sourceRectangle.Y;
@@ -42,21 +45,25 @@ namespace ImageProcessorCore.Processors
int endX = sourceRectangle.Right;
Vector4 alphaVector = new Vector4(1, 1, 1, alpha);
- using (PixelAccessor sourcePixels = source.Lock())
- using (PixelAccessor targetPixels = target.Lock())
+ using (IPixelAccessor sourcePixels = source.Lock())
+ using (IPixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
+ Bootstrapper.Instance.ParallelOptions,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
- Vector4 color = Color.ToNonPremultiplied(sourcePixels[x, y]).ToVector4();
+ Vector4 color = sourcePixels[x, y].ToVector4();
color *= alphaVector;
- targetPixels[x, y] = Color.FromNonPremultiplied(new Color(color));
+
+ T packed = default(T);
+ packed.PackVector(color);
+ targetPixels[x, y] = packed;
}
this.OnRowProcessed();
diff --git a/src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs b/src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs
index e78987d23a..cc59d2d4fc 100644
--- a/src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs
+++ b/src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs
@@ -6,12 +6,15 @@
namespace ImageProcessorCore.Processors
{
using System;
+ using System.Numerics;
using System.Threading.Tasks;
///
/// Sets the background color of the image.
///
- public class BackgroundColorProcessor : ImageProcessor
+ public class BackgroundColorProcessor : ImageProcessor
+ where T : IPackedVector
+ where TP : struct
{
///
/// The epsilon for comparing floating point numbers.
@@ -19,46 +22,47 @@ namespace ImageProcessorCore.Processors
private const float Epsilon = 0.001f;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
- /// The to set the background color to.
- public BackgroundColorProcessor(Color color)
+ /// The to set the background color to.
+ public BackgroundColorProcessor(T color)
{
- this.Value = Color.FromNonPremultiplied(color);
+ this.Value = color;
}
///
/// Gets the background color value.
///
- public Color Value { get; }
+ public T Value { get; }
///
- protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
+ protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
- Color backgroundColor = this.Value;
+ Vector4 backgroundColor = this.Value.ToVector4();
- using (PixelAccessor sourcePixels = source.Lock())
- using (PixelAccessor targetPixels = target.Lock())
+ using (IPixelAccessor sourcePixels = source.Lock())
+ using (IPixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
+ Bootstrapper.Instance.ParallelOptions,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
- Color color = sourcePixels[x, y];
- float a = color.A;
+ Vector4 color = sourcePixels[x, y].ToVector4();
+ float a = color.W;
if (a < 1 && a > 0)
{
- color = Color.Lerp(color, backgroundColor, .5f);
+ color = Vector4.Lerp(color, backgroundColor, .5f);
}
if (Math.Abs(a) < Epsilon)
@@ -66,7 +70,9 @@ namespace ImageProcessorCore.Processors
color = backgroundColor;
}
- targetPixels[x, y] = color;
+ T packed = default(T);
+ packed.PackVector(color);
+ targetPixels[x, y] = packed;
}
this.OnRowProcessed();
diff --git a/src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs b/src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs
similarity index 51%
rename from src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs
rename to src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs
index 60b49d0eec..ffe5c4452a 100644
--- a/src/ImageProcessorCore/Filters/Processors/Binarization/ThresholdProcessor.cs
+++ b/src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs
@@ -1,19 +1,22 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageProcessorCore.Processors
{
- using System;
using System.Threading.Tasks;
///
- /// An to perform binary threshold filtering against an
- /// . The image will be converted to greyscale before thresholding
+ /// An to perform binary threshold filtering against an
+ /// . The image will be converted to Grayscale before thresholding
/// occurs.
///
- public class ThresholdProcessor : ImageProcessor
+ /// The pixel format.
+ /// The packed format. long, float.
+ public class BinaryThresholdProcessor : ImageProcessor
+ where T : IPackedVector
+ where TP : struct
{
///
/// Initializes a new instance of the class.
@@ -22,10 +25,19 @@ namespace ImageProcessorCore.Processors
///
/// is less than 0 or is greater than 1.
///
- public ThresholdProcessor(float threshold)
+ public BinaryThresholdProcessor(float threshold)
{
+ // TODO: Check limit.
Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold));
this.Value = threshold;
+
+ T upper = default(T);
+ upper.PackVector(Color.White.ToVector4());
+ this.UpperColor = upper;
+
+ T lower = default(T);
+ lower.PackVector(Color.Black.ToVector4());
+ this.LowerColor = lower;
}
///
@@ -36,46 +48,50 @@ namespace ImageProcessorCore.Processors
///
/// The color to use for pixels that are above the threshold.
///
- public Color UpperColor => Color.White;
+ public T UpperColor { get; set; }
///
/// The color to use for pixels that fall below the threshold.
///
- public Color LowerColor => Color.Black;
+ public T LowerColor { get; set; }
///
- protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle)
+ protected override void OnApply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle)
{
- new GreyscaleBt709Processor().Apply(source, source, sourceRectangle);
+ new GrayscaleBt709Processor().Apply(source, source, sourceRectangle);
}
///
- protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
+ protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
+ // target.SetPixels(source.Width, source.Height, source.Pixels);
+
+
float threshold = this.Value;
- Color upper = this.UpperColor;
- Color lower = this.LowerColor;
+ T upper = this.UpperColor;
+ T lower = this.LowerColor;
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
- using (PixelAccessor sourcePixels = source.Lock())
- using (PixelAccessor targetPixels = target.Lock())
+ using (IPixelAccessor sourcePixels = source.Lock())
+ using (IPixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
endY,
+ Bootstrapper.Instance.ParallelOptions,
y =>
{
if (y >= sourceY && y < sourceBottom)
{
for (int x = startX; x < endX; x++)
{
- Color color = sourcePixels[x, y];
+ T color = sourcePixels[x, y];
- // Any channel will do since it's greyscale.
- targetPixels[x, y] = color.B >= threshold ? upper : lower;
+ // Any channel will do since it's Grayscale.
+ targetPixels[x, y] = color.ToVector4().X >= threshold ? upper : lower;
}
this.OnRowProcessed();
}
diff --git a/src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs b/src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs
index 5de0741fae..56c754729a 100644
--- a/src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs
+++ b/src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs
@@ -5,17 +5,22 @@
namespace ImageProcessorCore.Processors
{
+ using System.Numerics;
using System.Threading.Tasks;
///
/// Combines two images together by blending the pixels.
///
- public class BlendProcessor : ImageProcessor
+ /// The pixel format.
+ /// The packed format. long, float.
+ public class BlendProcessor : ImageProcessor
+ where T : IPackedVector
+ where TP : struct
{
///
/// The image to blend.
///
- private readonly ImageBase blend;
+ private readonly ImageBase blend;
///
/// Initializes a new instance of the class.
@@ -25,7 +30,7 @@ namespace ImageProcessorCore.Processors
/// Disposal of this image is the responsibility of the developer.
///
/// The opacity of the image to blend. Between 0 and 100.
- public BlendProcessor(ImageBase image, int alpha = 100)
+ public BlendProcessor(ImageBase image, int alpha = 100)
{
Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha));
this.blend = image;
@@ -38,7 +43,7 @@ namespace ImageProcessorCore.Processors
public int Value { get; }
///
- protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
+ protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
int sourceY = sourceRectangle.Y;
int sourceBottom = sourceRectangle.Bottom;
@@ -47,9 +52,9 @@ namespace ImageProcessorCore.Processors
Rectangle bounds = this.blend.Bounds;
float alpha = this.Value / 100f;
- using (PixelAccessor toBlendPixels = this.blend.Lock())
- using (PixelAccessor sourcePixels = source.Lock())
- using (PixelAccessor targetPixels = target.Lock())
+ using (IPixelAccessor toBlendPixels = this.blend.Lock())
+ using (IPixelAccessor sourcePixels = source.Lock())
+ using (IPixelAccessor targetPixels = target.Lock())
{
Parallel.For(
startY,
@@ -60,21 +65,23 @@ namespace ImageProcessorCore.Processors
{
for (int x = startX; x < endX; x++)
{
- Color color = sourcePixels[x, y];
+ Vector4 color = sourcePixels[x, y].ToVector4();
if (bounds.Contains(x, y))
{
- Color blendedColor = toBlendPixels[x, y];
+ Vector4 blendedColor = toBlendPixels[x, y].ToVector4();
- if (blendedColor.A > 0)
+ if (blendedColor.W > 0)
{
// Lerping colors is dependent on the alpha of the blended color
- float alphaFactor = alpha > 0 ? alpha : blendedColor.A;
- color = Color.Lerp(color, blendedColor, alphaFactor);
+ float alphaFactor = alpha > 0 ? alpha : blendedColor.W;
+ color = Vector4.Lerp(color, blendedColor, alphaFactor);
}
}
- targetPixels[x, y] = color;
+ T packed = default(T);
+ packed.PackVector(color);
+ targetPixels[x, y] = packed;
}
this.OnRowProcessed();
diff --git a/src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs b/src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs
index 6710ff5938..bedbd6b71d 100644
--- a/src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs
+++ b/src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs
@@ -5,14 +5,17 @@
namespace ImageProcessorCore.Processors
{
- using System;
using System.Numerics;
using System.Threading.Tasks;
///
- /// An to change the brightness of an .
+ /// An to change the brightness of an .
///
- public class BrightnessProcessor : ImageProcessor
+ /// The pixel format.
+ /// The packed format. long, float.
+ public class BrightnessProcessor : ImageProcessor
+ where T : IPackedVector
+ where TP : struct
{
///