diff --git a/README.md b/README.md index 6d37dd5e7b..4d079de391 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The **ImageSharp** library is made up of multiple packages. Packages include: - **ImageSharp** - - Contains the Image classes, Colors, Primitives, Configuration, and other core functionality. + - Contains the Image classes, PixelFormats, Primitives, Configuration, and other core functionality. - The IImageFormat interface, Jpeg, Png, Bmp, and Gif formats. - Transform methods like Resize, Crop, Skew, Rotate - Anything that alters the dimensions of the image. - Non-transform methods like Gaussian Blur, Pixelate, Edge Detection - Anything that maintains the original image dimensions. @@ -108,11 +108,12 @@ Setting individual pixel values is perfomed as follows: using (image = new Image(400, 400) using (var pixels = image.Lock()) { - pixels[200, 200] = Color.White; + // Rgba32 is our default PixelFormat, equivalent to System.Drawing Color + pixels[200, 200] = Rgba32.White; } ``` -For advanced usage the `Image` and `PixelAccessor` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame. +For advanced usage the `Image` and `PixelAccessor` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame. All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start. @@ -204,4 +205,4 @@ Become a sponsor and get your logo on our README on Github with a link to your s - + \ No newline at end of file diff --git a/features.md b/features.md index 6bc5630eed..1e35b88e0d 100644 --- a/features.md +++ b/features.md @@ -13,6 +13,7 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway - [ ] Tiff (Help needed) - **Metadata** - [x] EXIF Read/Write (Jpeg just now) + - [ ] ICC (In Progress) - **Quantizers (IQuantizer with alpha channel support, dithering, and thresholding)** - [x] Octree - [x] Xiaolin Wu @@ -28,7 +29,6 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway - [x] Bayer - [x] Ordered - **Basic color structs with implicit operators.** - - [x] Color - 32bit color in RGBA order (IPackedPixel\). - [x] Bgra32 - [x] CIE Lab - [x] CIE XYZ @@ -38,7 +38,7 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway - [x] YCbCr - **IPackedPixel representations of color models. Compatible with Microsoft XNA Game Studio and MonoGame IPackedVector\.** - [x] Alpha8 - - [x] Argb + - [x] Argb32 - [x] Bgr565 - [x] Bgra444 - [x] Bgra565 @@ -52,7 +52,9 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway - [x] NormalizedShort4 - [x] Rg32 - [x] Rgba1010102 + - [x] Rgba32 - 32bit color in RGBA order - Our default pixel format. - [x] Rgba64 + - [x] RgbaVector - [x] Short2 - [x] Short4 - **Basic shape primitives.** diff --git a/src/ImageSharp.Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Brushes/Brushes.cs index e8269848ce..8998c60f6e 100644 --- a/src/ImageSharp.Drawing/Brushes/Brushes.cs +++ b/src/ImageSharp.Drawing/Brushes/Brushes.cs @@ -5,8 +5,10 @@ namespace ImageSharp.Drawing.Brushes { + using ImageSharp.PixelFormats; + /// - /// A collection of methods for creating brushes. Brushes use for painting. + /// A collection of methods for creating brushes. Brushes use for painting. /// public class Brushes { @@ -15,7 +17,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color. /// A Brush - public static SolidBrush Solid(Color color) + public static SolidBrush Solid(Rgba32 color) => new SolidBrush(color); /// @@ -24,8 +26,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Percent10(Color foreColor) - => new PatternBrush(Brushes.Percent10(foreColor, Color.Transparent)); + public static PatternBrush Percent10(Rgba32 foreColor) + => new PatternBrush(Brushes.Percent10(foreColor, Rgba32.Transparent)); /// /// Create as brush that will paint a Percent10 Hatch Pattern with @@ -34,8 +36,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent10(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Percent10(foreColor, backColor)); + public static PatternBrush Percent10(Rgba32 foreColor, Rgba32 backColor) + => new PatternBrush(Brushes.Percent10(foreColor, backColor)); /// /// Create as brush that will paint a Percent20 Hatch Pattern with @@ -43,8 +45,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Percent20(Color foreColor) - => new PatternBrush(Brushes.Percent20(foreColor, Color.Transparent)); + public static PatternBrush Percent20(Rgba32 foreColor) + => new PatternBrush(Brushes.Percent20(foreColor, Rgba32.Transparent)); /// /// Create as brush that will paint a Percent20 Hatch Pattern with @@ -53,8 +55,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent20(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Percent20(foreColor, backColor)); + public static PatternBrush Percent20(Rgba32 foreColor, Rgba32 backColor) + => new PatternBrush(Brushes.Percent20(foreColor, backColor)); /// /// Create as brush that will paint a Horizontal Hatch Pattern with @@ -62,8 +64,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Horizontal(Color foreColor) - => new PatternBrush(Brushes.Horizontal(foreColor, Color.Transparent)); + public static PatternBrush Horizontal(Rgba32 foreColor) + => new PatternBrush(Brushes.Horizontal(foreColor, Rgba32.Transparent)); /// /// Create as brush that will paint a Horizontal Hatch Pattern with @@ -72,8 +74,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Horizontal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); + public static PatternBrush Horizontal(Rgba32 foreColor, Rgba32 backColor) + => new PatternBrush(Brushes.Horizontal(foreColor, backColor)); /// /// Create as brush that will paint a Min Hatch Pattern with @@ -81,8 +83,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Min(Color foreColor) - => new PatternBrush(Brushes.Min(foreColor, Color.Transparent)); + public static PatternBrush Min(Rgba32 foreColor) + => new PatternBrush(Brushes.Min(foreColor, Rgba32.Transparent)); /// /// Create as brush that will paint a Min Hatch Pattern with @@ -91,8 +93,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Min(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Min(foreColor, backColor)); + public static PatternBrush Min(Rgba32 foreColor, Rgba32 backColor) + => new PatternBrush(Brushes.Min(foreColor, backColor)); /// /// Create as brush that will paint a Vertical Hatch Pattern with @@ -100,8 +102,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush Vertical(Color foreColor) - => new PatternBrush(Brushes.Vertical(foreColor, Color.Transparent)); + public static PatternBrush Vertical(Rgba32 foreColor) + => new PatternBrush(Brushes.Vertical(foreColor, Rgba32.Transparent)); /// /// Create as brush that will paint a Vertical Hatch Pattern with @@ -110,8 +112,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Vertical(Color foreColor, Color backColor) - => new PatternBrush(Brushes.Vertical(foreColor, backColor)); + public static PatternBrush Vertical(Rgba32 foreColor, Rgba32 backColor) + => new PatternBrush(Brushes.Vertical(foreColor, backColor)); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern with @@ -119,8 +121,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush ForwardDiagonal(Color foreColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color.Transparent)); + public static PatternBrush ForwardDiagonal(Rgba32 foreColor) + => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Rgba32.Transparent)); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern with @@ -129,8 +131,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); + public static PatternBrush ForwardDiagonal(Rgba32 foreColor, Rgba32 backColor) + => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor)); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern with @@ -138,8 +140,8 @@ namespace ImageSharp.Drawing.Brushes /// /// Color of the foreground. /// A Brush - public static PatternBrush BackwardDiagonal(Color foreColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color.Transparent)); + public static PatternBrush BackwardDiagonal(Rgba32 foreColor) + => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Rgba32.Transparent)); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern with @@ -148,7 +150,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) - => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); + public static PatternBrush BackwardDiagonal(Rgba32 foreColor, Rgba32 backColor) + => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor)); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/Brushes{TColor}.cs b/src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs similarity index 78% rename from src/ImageSharp.Drawing/Brushes/Brushes{TColor}.cs rename to src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs index 6e092bf185..4b2f6c0261 100644 --- a/src/ImageSharp.Drawing/Brushes/Brushes{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs @@ -1,19 +1,19 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Drawing.Brushes { - using System; + using ImageSharp.PixelFormats; /// /// A collection of methods for creating generic brushes. /// - /// The pixel format. + /// The pixel format. /// A Brush - public class Brushes - where TColor : struct, IPixel + public class Brushes + where TPixel : struct, IPixel { /// /// Percent10 Hatch Pattern @@ -99,8 +99,8 @@ namespace ImageSharp.Drawing.Brushes /// /// The color. /// A Brush - public static SolidBrush Solid(TColor color) - => new SolidBrush(color); + public static SolidBrush Solid(TPixel color) + => new SolidBrush(color); /// /// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors @@ -108,8 +108,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent10(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, Percent10Pattern); + public static PatternBrush Percent10(TPixel foreColor, TPixel backColor) + => new PatternBrush(foreColor, backColor, Percent10Pattern); /// /// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors @@ -117,8 +117,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Percent20(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, Percent20Pattern); + public static PatternBrush Percent20(TPixel foreColor, TPixel backColor) + => new PatternBrush(foreColor, backColor, Percent20Pattern); /// /// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors @@ -126,8 +126,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Horizontal(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, HorizontalPattern); + public static PatternBrush Horizontal(TPixel foreColor, TPixel backColor) + => new PatternBrush(foreColor, backColor, HorizontalPattern); /// /// Create as brush that will paint a Min Hatch Pattern within the specified colors @@ -135,8 +135,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Min(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, MinPattern); + public static PatternBrush Min(TPixel foreColor, TPixel backColor) + => new PatternBrush(foreColor, backColor, MinPattern); /// /// Create as brush that will paint a Vertical Hatch Pattern within the specified colors @@ -144,8 +144,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush Vertical(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, VerticalPattern); + public static PatternBrush Vertical(TPixel foreColor, TPixel backColor) + => new PatternBrush(foreColor, backColor, VerticalPattern); /// /// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors @@ -153,8 +153,8 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush ForwardDiagonal(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, ForwardDiagonalPattern); + public static PatternBrush ForwardDiagonal(TPixel foreColor, TPixel backColor) + => new PatternBrush(foreColor, backColor, ForwardDiagonalPattern); /// /// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors @@ -162,7 +162,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the foreground. /// Color of the background. /// A Brush - public static PatternBrush BackwardDiagonal(TColor foreColor, TColor backColor) - => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern); + public static PatternBrush BackwardDiagonal(TPixel foreColor, TPixel backColor) + => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern); } } diff --git a/src/ImageSharp.Drawing/Brushes/IBrush.cs b/src/ImageSharp.Drawing/Brushes/IBrush.cs index df05fa23e1..e16f220288 100644 --- a/src/ImageSharp.Drawing/Brushes/IBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/IBrush.cs @@ -5,20 +5,19 @@ namespace ImageSharp.Drawing { - using System; - + using ImageSharp.PixelFormats; using Processors; /// /// Brush represents a logical configuration of a brush which can be used to source pixel colors /// - /// The pixel format. + /// The pixel format. /// - /// A brush is a simple class that will return an that will perform the - /// logic for converting a pixel location to a . + /// A brush is a simple class that will return an that will perform the + /// logic for converting a pixel location to a . /// - public interface IBrush - where TColor : struct, IPixel + public interface IBrush + where TPixel : struct, IPixel { /// /// Creates the applicator for this brush. @@ -32,6 +31,6 @@ namespace ImageSharp.Drawing /// The when being applied to things like shapes would usually be the /// bounding box of the shape not necessarily the bounds of the whole image /// - BrushApplicator CreateApplicator(PixelAccessor pixelSource, RectangleF region); + BrushApplicator CreateApplicator(PixelAccessor pixelSource, RectangleF region); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs index a7124bfe86..6a3ff1d9d3 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs @@ -5,16 +5,18 @@ namespace ImageSharp.Drawing.Brushes { + using ImageSharp.PixelFormats; + /// - /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting. + /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting. /// - public class ImageBrush : ImageBrush + public class ImageBrush : ImageBrush { /// /// Initializes a new instance of the class. /// /// The image to paint. - public ImageBrush(IImageBase image) + public ImageBrush(IImageBase image) : base(image) { } diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs similarity index 83% rename from src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs rename to src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs index b68b02eff1..3e2da040fd 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs @@ -1,38 +1,37 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Drawing.Brushes { - using System; using System.Numerics; - + using ImageSharp.PixelFormats; using Processors; /// /// Provides an implementation of an image brush for painting images within areas. /// - /// The pixel format. - public class ImageBrush : IBrush - where TColor : struct, IPixel + /// The pixel format. + public class ImageBrush : IBrush + where TPixel : struct, IPixel { /// /// The image to paint. /// - private readonly IImageBase image; + private readonly IImageBase image; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image. - public ImageBrush(IImageBase image) + public ImageBrush(IImageBase image) { this.image = image; } /// - public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { return new ImageBrushApplicator(sourcePixels, this.image, region); } @@ -40,12 +39,12 @@ namespace ImageSharp.Drawing.Brushes /// /// The image brush applicator. /// - private class ImageBrushApplicator : BrushApplicator + private class ImageBrushApplicator : BrushApplicator { /// /// The source pixel accessor. /// - private readonly PixelAccessor source; + private readonly PixelAccessor source; /// /// The y-length. @@ -74,7 +73,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The sourcePixels. /// - public ImageBrushApplicator(PixelAccessor sourcePixels, IImageBase image, RectangleF region) + public ImageBrushApplicator(PixelAccessor sourcePixels, IImageBase image, RectangleF region) : base(sourcePixels) { this.source = image.Lock(); @@ -91,7 +90,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color /// - internal override TColor this[int x, int y] + internal override TPixel this[int x, int y] { get { @@ -135,7 +134,7 @@ namespace ImageSharp.Drawing.Brushes Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(finalColor); this.Target[targetX, targetY] = packed; } diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs index 5093a7df06..f00862fe78 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs @@ -5,10 +5,12 @@ namespace ImageSharp.Drawing.Brushes { + using ImageSharp.PixelFormats; + /// - /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting. + /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting. /// - public class PatternBrush : PatternBrush + public class PatternBrush : PatternBrush { /// /// Initializes a new instance of the class. @@ -16,7 +18,7 @@ namespace ImageSharp.Drawing.Brushes /// Color of the fore. /// Color of the back. /// The pattern. - public PatternBrush(Color foreColor, Color backColor, bool[,] pattern) + public PatternBrush(Rgba32 foreColor, Rgba32 backColor, bool[,] pattern) : base(foreColor, backColor, pattern) { } @@ -25,7 +27,7 @@ namespace ImageSharp.Drawing.Brushes /// Initializes a new instance of the class. /// /// The brush. - internal PatternBrush(PatternBrush brush) + internal PatternBrush(PatternBrush brush) : base(brush) { } diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs similarity index 84% rename from src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs rename to src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs index 1af58bc62f..ad37f4d289 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -7,7 +7,7 @@ namespace ImageSharp.Drawing.Brushes { using System; using System.Numerics; - + using ImageSharp.PixelFormats; using Processors; /// @@ -31,38 +31,38 @@ namespace ImageSharp.Drawing.Brushes /// 0 /// /// - /// The pixel format. - public class PatternBrush : IBrush - where TColor : struct, IPixel + /// The pixel format. + public class PatternBrush : IBrush + where TPixel : struct, IPixel { /// /// The pattern. /// - private readonly Fast2DArray pattern; + private readonly Fast2DArray pattern; private readonly Fast2DArray patternVector; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Color of the fore. /// Color of the back. /// The pattern. - public PatternBrush(TColor foreColor, TColor backColor, bool[,] pattern) + public PatternBrush(TPixel foreColor, TPixel backColor, bool[,] pattern) : this(foreColor, backColor, new Fast2DArray(pattern)) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Color of the fore. /// Color of the back. /// The pattern. - internal PatternBrush(TColor foreColor, TColor backColor, Fast2DArray pattern) + internal PatternBrush(TPixel foreColor, TPixel backColor, Fast2DArray pattern) { Vector4 foreColorVector = foreColor.ToVector4(); Vector4 backColorVector = backColor.ToVector4(); - this.pattern = new Fast2DArray(pattern.Width, pattern.Height); + this.pattern = new Fast2DArray(pattern.Width, pattern.Height); this.patternVector = new Fast2DArray(pattern.Width, pattern.Height); for (int i = 0; i < pattern.Data.Length; i++) { @@ -80,17 +80,17 @@ namespace ImageSharp.Drawing.Brushes } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. - internal PatternBrush(PatternBrush brush) + internal PatternBrush(PatternBrush brush) { this.pattern = brush.pattern; this.patternVector = brush.patternVector; } /// - public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { return new PatternBrushApplicator(sourcePixels, this.pattern, this.patternVector); } @@ -98,12 +98,12 @@ namespace ImageSharp.Drawing.Brushes /// /// The pattern brush applicator. /// - private class PatternBrushApplicator : BrushApplicator + private class PatternBrushApplicator : BrushApplicator { /// /// The pattern. /// - private readonly Fast2DArray pattern; + private readonly Fast2DArray pattern; private readonly Fast2DArray patternVector; /// @@ -112,7 +112,7 @@ namespace ImageSharp.Drawing.Brushes /// The sourcePixels. /// The pattern. /// The patternVector. - public PatternBrushApplicator(PixelAccessor sourcePixels, Fast2DArray pattern, Fast2DArray patternVector) + public PatternBrushApplicator(PixelAccessor sourcePixels, Fast2DArray pattern, Fast2DArray patternVector) : base(sourcePixels) { this.pattern = pattern; @@ -127,7 +127,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The Color. /// - internal override TColor this[int x, int y] + internal override TPixel this[int x, int y] { get { @@ -169,7 +169,7 @@ namespace ImageSharp.Drawing.Brushes Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(finalColor); this.Target[targetX, targetY] = packed; } diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index 0ef11e1611..5dd6dad76d 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -7,21 +7,21 @@ namespace ImageSharp.Drawing.Processors { using System; using System.Numerics; - using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; /// /// primitive that converts a point in to a color for discovering the fill color based on an implementation /// - /// The pixel format. + /// The pixel format. /// - public abstract class BrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush - where TColor : struct, IPixel + public abstract class BrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The target. - internal BrushApplicator(PixelAccessor target) + internal BrushApplicator(PixelAccessor target) { this.Target = target; } @@ -29,15 +29,15 @@ namespace ImageSharp.Drawing.Processors /// /// Gets the destinaion /// - protected PixelAccessor Target { get; } + protected PixelAccessor Target { get; } /// /// Gets the color for a single pixel. /// /// The x cordinate. /// The y cordinate. - /// The a that should be applied to the pixel. - internal abstract TColor this[int x, int y] { get; } + /// The a that should be applied to the pixel. + internal abstract TPixel this[int x, int y] { get; } /// public abstract void Dispose(); @@ -73,7 +73,7 @@ namespace ImageSharp.Drawing.Processors Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(finalColor); this.Target[targetX, targetY] = packed; } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs index 0452a3f015..bfe5c01e63 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs @@ -5,19 +5,21 @@ namespace ImageSharp.Drawing.Brushes { + using ImageSharp.PixelFormats; + /// /// Provides an implementation of a recolor brush for painting color changes. /// - public class RecolorBrush : RecolorBrush + public class RecolorBrush : RecolorBrush { /// /// Initializes a new instance of the class. /// /// Color of the source. - /// Color of the target. + /// Color of the target. /// The threshold. - public RecolorBrush(Color sourceColor, Color targetColor, float threshold) - : base(sourceColor, targetColor, threshold) + public RecolorBrush(Rgba32 sourceColor, Rgba32 targeTPixel, float threshold) + : base(sourceColor, targeTPixel, threshold) { } } diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs similarity index 80% rename from src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs rename to src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs index 4e3cd01ae8..7c192b2d3c 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -1,33 +1,32 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Drawing.Brushes { - using System; using System.Numerics; - + using ImageSharp.PixelFormats; using Processors; /// /// Provides an implementation of a brush that can recolor an image /// - /// The pixel format. - public class RecolorBrush : IBrush - where TColor : struct, IPixel + /// The pixel format. + public class RecolorBrush : IBrush + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Color of the source. - /// Color of the target. + /// Color of the target. /// The threshold as a value between 0 and 1. - public RecolorBrush(TColor sourceColor, TColor targetColor, float threshold) + public RecolorBrush(TPixel sourceColor, TPixel targeTPixel, float threshold) { this.SourceColor = sourceColor; this.Threshold = threshold; - this.TargetColor = targetColor; + this.TargeTPixel = targeTPixel; } /// @@ -44,7 +43,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color of the source. /// - public TColor SourceColor { get; } + public TPixel SourceColor { get; } /// /// Gets the target color. @@ -52,18 +51,18 @@ namespace ImageSharp.Drawing.Brushes /// /// The color of the target. /// - public TColor TargetColor { get; } + public TPixel TargeTPixel { get; } /// - public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { - return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargetColor, this.Threshold); + return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargeTPixel, this.Threshold); } /// /// The recolor brush applicator. /// - private class RecolorBrushApplicator : BrushApplicator + private class RecolorBrushApplicator : BrushApplicator { /// /// The source color. @@ -73,7 +72,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The target color. /// - private readonly Vector4 targetColor; + private readonly Vector4 targeTPixel; /// /// The threshold. @@ -85,18 +84,18 @@ namespace ImageSharp.Drawing.Brushes /// /// The source pixels. /// Color of the source. - /// Color of the target. + /// Color of the target. /// The threshold . - public RecolorBrushApplicator(PixelAccessor sourcePixels, TColor sourceColor, TColor targetColor, float threshold) + public RecolorBrushApplicator(PixelAccessor sourcePixels, TPixel sourceColor, TPixel targeTPixel, float threshold) : base(sourcePixels) { this.sourceColor = sourceColor.ToVector4(); - this.targetColor = targetColor.ToVector4(); + this.targeTPixel = targeTPixel.ToVector4(); // Lets hack a min max extreams for a color space by letteing the IPackedPixel clamp our values to something in the correct spaces :) - TColor maxColor = default(TColor); + TPixel maxColor = default(TPixel); maxColor.PackFromVector4(new Vector4(float.MaxValue)); - TColor minColor = default(TColor); + TPixel minColor = default(TPixel); minColor.PackFromVector4(new Vector4(float.MinValue)); this.threshold = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()) * threshold; } @@ -109,12 +108,12 @@ namespace ImageSharp.Drawing.Brushes /// /// The color /// - internal override TColor this[int x, int y] + internal override TPixel this[int x, int y] { get { // Offset the requested pixel by the value in the rectangle (the shapes position) - TColor result = this.Target[x, y]; + TPixel result = this.Target[x, y]; Vector4 background = result.ToVector4(); float distance = Vector4.DistanceSquared(background, this.sourceColor); if (distance <= this.threshold) @@ -122,7 +121,7 @@ namespace ImageSharp.Drawing.Brushes float lerpAmount = (this.threshold - distance) / this.threshold; Vector4 blended = Vector4BlendTransforms.PremultipliedLerp( background, - this.targetColor, + this.targeTPixel, lerpAmount); result.PackFromVector4(blended); } @@ -162,12 +161,12 @@ namespace ImageSharp.Drawing.Brushes float lerpAmount = (this.threshold - distance) / this.threshold; sourceVector = Vector4BlendTransforms.PremultipliedLerp( sourceVector, - this.targetColor, + this.targeTPixel, lerpAmount); Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(finalColor); this.Target[targetX, targetY] = packed; } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs index 123d8a7e31..8a3ad50e7c 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs @@ -5,16 +5,18 @@ namespace ImageSharp.Drawing.Brushes { + using ImageSharp.PixelFormats; + /// - /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting. + /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting. /// - public class SolidBrush : SolidBrush + public class SolidBrush : SolidBrush { /// /// Initializes a new instance of the class. /// /// The color. - public SolidBrush(Color color) + public SolidBrush(Rgba32 color) : base(color) { } diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs similarity index 79% rename from src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs rename to src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs index 74c7081b3b..634a2b70de 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs @@ -1,32 +1,31 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Drawing.Brushes { - using System; using System.Numerics; - + using ImageSharp.PixelFormats; using Processors; /// /// Provides an implementation of a solid brush for painting solid color areas. /// - /// The pixel format. - public class SolidBrush : IBrush - where TColor : struct, IPixel + /// The pixel format. + public class SolidBrush : IBrush + where TPixel : struct, IPixel { /// /// The color to paint. /// - private readonly TColor color; + private readonly TPixel color; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color. - public SolidBrush(TColor color) + public SolidBrush(TPixel color) { this.color = color; } @@ -37,10 +36,10 @@ namespace ImageSharp.Drawing.Brushes /// /// The color. /// - public TColor Color => this.color; + public TPixel Color => this.color; /// - public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { return new SolidBrushApplicator(sourcePixels, this.color); } @@ -48,12 +47,12 @@ namespace ImageSharp.Drawing.Brushes /// /// The solid brush applicator. /// - private class SolidBrushApplicator : BrushApplicator + private class SolidBrushApplicator : BrushApplicator { /// /// The solid color. /// - private readonly TColor color; + private readonly TPixel color; private readonly Vector4 colorVector; /// @@ -61,7 +60,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color. /// The sourcePixels. - public SolidBrushApplicator(PixelAccessor sourcePixels, TColor color) + public SolidBrushApplicator(PixelAccessor sourcePixels, TPixel color) : base(sourcePixels) { this.color = color; @@ -76,7 +75,7 @@ namespace ImageSharp.Drawing.Brushes /// /// The color /// - internal override TColor this[int x, int y] => this.color; + internal override TPixel this[int x, int y] => this.color; /// public override void Dispose() @@ -106,7 +105,7 @@ namespace ImageSharp.Drawing.Brushes Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(finalColor); this.Target[targetX, targetY] = packed; } diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/DrawImage.cs index 16582e7ee5..6a4f49337c 100644 --- a/src/ImageSharp.Drawing/DrawImage.cs +++ b/src/ImageSharp.Drawing/DrawImage.cs @@ -5,9 +5,8 @@ namespace ImageSharp { - using System; - using Drawing.Processors; + using ImageSharp.PixelFormats; /// /// Extension methods for the type. @@ -17,13 +16,13 @@ namespace ImageSharp /// /// Draws the given image together with the current one by blending their pixels. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The image to blend with the currently processing image. /// The opacity of the image image to blend. Must be between 0 and 100. - /// The . - public static Image Blend(this Image source, Image image, int percent = 50) - where TColor : struct, IPixel + /// The . + public static Image Blend(this Image source, Image image, int percent = 50) + where TPixel : struct, IPixel { return DrawImage(source, image, percent, default(Size), default(Point)); } @@ -33,13 +32,13 @@ namespace ImageSharp /// /// The image this method extends. /// The image to blend with the currently processing image. - /// The pixel format. + /// The pixel format. /// The opacity of the image image to blend. Must be between 0 and 100. /// The size to draw the blended image. /// The location to draw the blended image. - /// The . - public static Image DrawImage(this Image source, Image image, int percent, Size size, Point location) - where TColor : struct, IPixel + /// The . + public static Image DrawImage(this Image source, Image image, int percent, Size size, Point location) + where TPixel : struct, IPixel { if (size == default(Size)) { @@ -51,7 +50,7 @@ namespace ImageSharp location = Point.Empty; } - source.ApplyProcessor(new DrawImageProcessor(image, size, location, percent), source.Bounds); + source.ApplyProcessor(new DrawImageProcessor(image, size, location, percent), source.Bounds); return source; } } diff --git a/src/ImageSharp.Drawing/DrawPath.cs b/src/ImageSharp.Drawing/DrawPath.cs index e91b972033..09d3dbb028 100644 --- a/src/ImageSharp.Drawing/DrawPath.cs +++ b/src/ImageSharp.Drawing/DrawPath.cs @@ -5,43 +5,42 @@ namespace ImageSharp { - using System; - using Drawing; using Drawing.Brushes; using Drawing.Pens; using Drawing.Processors; + using ImageSharp.PixelFormats; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Draws the outline of the region with the provided pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The path. /// The options. - /// The . - public static Image Draw(this Image source, IPen pen, Drawable path, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IPen pen, Drawable path, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Apply(new DrawPathProcessor(pen, path, options)); + return source.Apply(new DrawPathProcessor(pen, path, options)); } /// /// Draws the outline of the polygon with the provided pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The path. - /// The . - public static Image Draw(this Image source, IPen pen, Drawable path) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IPen pen, Drawable path) + where TPixel : struct, IPixel { return source.Draw(pen, path, GraphicsOptions.Default); } @@ -49,63 +48,63 @@ namespace ImageSharp /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The path. /// The options. - /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, Drawable path, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IBrush brush, float thickness, Drawable path, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), path, options); + return source.Draw(new Pen(brush, thickness), path, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The path. - /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, Drawable path) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IBrush brush, float thickness, Drawable path) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), path); + return source.Draw(new Pen(brush, thickness), path); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The path. /// The options. - /// The . - public static Image Draw(this Image source, TColor color, float thickness, Drawable path, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, TPixel color, float thickness, Drawable path, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new SolidBrush(color), thickness, path, options); + return source.Draw(new SolidBrush(color), thickness, path, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The path. - /// The . - public static Image Draw(this Image source, TColor color, float thickness, Drawable path) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, TPixel color, float thickness, Drawable path) + where TPixel : struct, IPixel { - return source.Draw(new SolidBrush(color), thickness, path); + return source.Draw(new SolidBrush(color), thickness, path); } } } diff --git a/src/ImageSharp.Drawing/FillRegion.cs b/src/ImageSharp.Drawing/FillRegion.cs index 8aab202519..f29c37a67f 100644 --- a/src/ImageSharp.Drawing/FillRegion.cs +++ b/src/ImageSharp.Drawing/FillRegion.cs @@ -5,68 +5,67 @@ namespace ImageSharp { - using System; - using Drawing; using Drawing.Brushes; using Drawing.Processors; + using ImageSharp.PixelFormats; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Flood fills the image with the specified brush. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The details how to fill the region of interest. - /// The . - public static Image Fill(this Image source, IBrush brush) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, IBrush brush) + where TPixel : struct, IPixel { - return source.Apply(new FillProcessor(brush)); + return source.Apply(new FillProcessor(brush)); } /// /// Flood fills the image with the specified color. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. - /// The . - public static Image Fill(this Image source, TColor color) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, TPixel color) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color)); + return source.Fill(new SolidBrush(color)); } /// /// Flood fills the image with in the region with the specified brush. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The region. /// The graphics options. - /// The . - public static Image Fill(this Image source, IBrush brush, Region region, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, IBrush brush, Region region, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Apply(new FillRegionProcessor(brush, region, options)); + return source.Apply(new FillRegionProcessor(brush, region, options)); } /// /// Flood fills the image with in the region with the specified brush. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The region. - /// The . - public static Image Fill(this Image source, IBrush brush, Region region) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, IBrush brush, Region region) + where TPixel : struct, IPixel { return source.Fill(brush, region, GraphicsOptions.Default); } @@ -74,30 +73,30 @@ namespace ImageSharp /// /// Flood fills the image with in the region with the specified color. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The region. /// The options. - /// The . - public static Image Fill(this Image source, TColor color, Region region, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, TPixel color, Region region, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color), region, options); + return source.Fill(new SolidBrush(color), region, options); } /// /// Flood fills the image with in the region with the specified color. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The region. - /// The . - public static Image Fill(this Image source, TColor color, Region region) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, TPixel color, Region region) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color), region); + return source.Fill(new SolidBrush(color), region); } } } diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj index c4515db375..7c483712d2 100644 --- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj +++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj @@ -2,7 +2,7 @@ An extension to ImageSharp that allows the drawing of images, paths, and text. ImageSharp.Drawing - 1.0.0-alpha6 + 1.0.0-alpha7 James Jackson-South and contributors netstandard1.1 true diff --git a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs index 936d5a9ce5..c4ea8c3785 100644 --- a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs +++ b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs @@ -5,92 +5,91 @@ namespace ImageSharp { - using System; using System.Numerics; using Drawing; using Drawing.Brushes; using Drawing.Pens; - + using ImageSharp.PixelFormats; using SixLabors.Shapes; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The points. /// The options. - /// The . - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), new Path(new BezierLineSegment(points)), options); + return source.Draw(new Pen(brush, thickness), new Path(new BezierLineSegment(points)), options); } /// /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The points. - /// The . - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), new Path(new BezierLineSegment(points))); + return source.Draw(new Pen(brush, thickness), new Path(new BezierLineSegment(points))); } /// /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The points. - /// The . - public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawBeziers(this Image source, TPixel color, float thickness, Vector2[] points) + where TPixel : struct, IPixel { - return source.DrawBeziers(new SolidBrush(color), thickness, points); + return source.DrawBeziers(new SolidBrush(color), thickness, points); } /// /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The points. /// The options. - /// The . - public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image DrawBeziers(this Image source, TPixel color, float thickness, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.DrawBeziers(new SolidBrush(color), thickness, points, options); + return source.DrawBeziers(new SolidBrush(color), thickness, points, options); } /// /// Draws the provided Points as an open Bezier path with the supplied pen /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The points. /// The options. - /// The . - public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { return source.Draw(pen, new Path(new BezierLineSegment(points)), options); } @@ -98,13 +97,13 @@ namespace ImageSharp /// /// Draws the provided Points as an open Bezier path with the supplied pen /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The points. - /// The . - public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points) + where TPixel : struct, IPixel { return source.Draw(pen, new Path(new BezierLineSegment(points))); } diff --git a/src/ImageSharp.Drawing/Paths/DrawLines.cs b/src/ImageSharp.Drawing/Paths/DrawLines.cs index 42f4406e83..e8c463638f 100644 --- a/src/ImageSharp.Drawing/Paths/DrawLines.cs +++ b/src/ImageSharp.Drawing/Paths/DrawLines.cs @@ -5,92 +5,91 @@ namespace ImageSharp { - using System; using System.Numerics; using Drawing; using Drawing.Brushes; using Drawing.Pens; - + using ImageSharp.PixelFormats; using SixLabors.Shapes; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The points. /// The options. - /// The . - public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); + return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); } /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The points. - /// The . - public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); + return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); } /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The points. - /// The . - public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawLines(this Image source, TPixel color, float thickness, Vector2[] points) + where TPixel : struct, IPixel { - return source.DrawLines(new SolidBrush(color), thickness, points); + return source.DrawLines(new SolidBrush(color), thickness, points); } /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The points. /// The options. - /// The .> - public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The .> + public static Image DrawLines(this Image source, TPixel color, float thickness, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.DrawLines(new SolidBrush(color), thickness, points, options); + return source.DrawLines(new SolidBrush(color), thickness, points, options); } /// /// Draws the provided Points as an open Linear path with the supplied pen /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The points. /// The options. - /// The . - public static Image DrawLines(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image DrawLines(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points)), options); } @@ -98,13 +97,13 @@ namespace ImageSharp /// /// Draws the provided Points as an open Linear path with the supplied pen /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The points. - /// The . - public static Image DrawLines(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawLines(this Image source, IPen pen, Vector2[] points) + where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points))); } diff --git a/src/ImageSharp.Drawing/Paths/DrawPath.cs b/src/ImageSharp.Drawing/Paths/DrawPath.cs index e2c1442de8..176539663c 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPath.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPath.cs @@ -5,30 +5,28 @@ namespace ImageSharp { - using System; - using Drawing; using Drawing.Brushes; using Drawing.Pens; - + using ImageSharp.PixelFormats; using SixLabors.Shapes; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Draws the outline of the polygon with the provided pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The path. /// The options. - /// The . - public static Image Draw(this Image source, IPen pen, IPath path, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IPen pen, IPath path, GraphicsOptions options) + where TPixel : struct, IPixel { return source.Draw(pen, new ShapePath(path), options); } @@ -36,13 +34,13 @@ namespace ImageSharp /// /// Draws the outline of the polygon with the provided pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The path. - /// The . - public static Image Draw(this Image source, IPen pen, IPath path) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IPen pen, IPath path) + where TPixel : struct, IPixel { return source.Draw(pen, path, GraphicsOptions.Default); } @@ -50,63 +48,63 @@ namespace ImageSharp /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The shape. /// The options. - /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPath path, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), path, options); + return source.Draw(new Pen(brush, thickness), path, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The path. - /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPath path) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IBrush brush, float thickness, IPath path) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), path); + return source.Draw(new Pen(brush, thickness), path); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The path. /// The options. - /// The . - public static Image Draw(this Image source, TColor color, float thickness, IPath path, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, TPixel color, float thickness, IPath path, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new SolidBrush(color), thickness, path, options); + return source.Draw(new SolidBrush(color), thickness, path, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The path. - /// The . - public static Image Draw(this Image source, TColor color, float thickness, IPath path) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, TPixel color, float thickness, IPath path) + where TPixel : struct, IPixel { - return source.Draw(new SolidBrush(color), thickness, path); + return source.Draw(new SolidBrush(color), thickness, path); } } } diff --git a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs index 8043d18e56..4b99e60c02 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs @@ -5,91 +5,90 @@ namespace ImageSharp { - using System; using System.Numerics; using Drawing; using Drawing.Brushes; using Drawing.Pens; - + using ImageSharp.PixelFormats; using SixLabors.Shapes; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The points. /// The options. - /// The . - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); + return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); } /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The points. - /// The . - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); + return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); } /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The points. - /// The . - public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawPolygon(this Image source, TPixel color, float thickness, Vector2[] points) + where TPixel : struct, IPixel { - return source.DrawPolygon(new SolidBrush(color), thickness, points); + return source.DrawPolygon(new SolidBrush(color), thickness, points); } /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The points. /// The options. - /// The . - public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image DrawPolygon(this Image source, TPixel color, float thickness, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.DrawPolygon(new SolidBrush(color), thickness, points, options); + return source.DrawPolygon(new SolidBrush(color), thickness, points, options); } /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The points. - /// The . - public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points) + where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); } @@ -97,14 +96,14 @@ namespace ImageSharp /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The points. /// The options. - /// The . - public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); } diff --git a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs index b356652409..0fefc6cab4 100644 --- a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs @@ -5,28 +5,27 @@ namespace ImageSharp { - using System; - using Drawing; using Drawing.Brushes; using Drawing.Pens; + using ImageSharp.PixelFormats; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Draws the outline of the polygon with the provided pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The shape. /// The options. - /// The . - public static Image Draw(this Image source, IPen pen, Rectangle shape, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IPen pen, Rectangle shape, GraphicsOptions options) + where TPixel : struct, IPixel { return source.Draw(pen, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options); } @@ -34,13 +33,13 @@ namespace ImageSharp /// /// Draws the outline of the polygon with the provided pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The pen. /// The shape. - /// The . - public static Image Draw(this Image source, IPen pen, Rectangle shape) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IPen pen, Rectangle shape) + where TPixel : struct, IPixel { return source.Draw(pen, shape, GraphicsOptions.Default); } @@ -48,63 +47,63 @@ namespace ImageSharp /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The shape. /// The options. - /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, Rectangle shape, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IBrush brush, float thickness, Rectangle shape, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), shape, options); + return source.Draw(new Pen(brush, thickness), shape, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The shape. - /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, Rectangle shape) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, IBrush brush, float thickness, Rectangle shape) + where TPixel : struct, IPixel { - return source.Draw(new Pen(brush, thickness), shape); + return source.Draw(new Pen(brush, thickness), shape); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The shape. /// The options. - /// The . - public static Image Draw(this Image source, TColor color, float thickness, Rectangle shape, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, TPixel color, float thickness, Rectangle shape, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Draw(new SolidBrush(color), thickness, shape, options); + return source.Draw(new SolidBrush(color), thickness, shape, options); } /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The shape. - /// The . - public static Image Draw(this Image source, TColor color, float thickness, Rectangle shape) - where TColor : struct, IPixel + /// The . + public static Image Draw(this Image source, TPixel color, float thickness, Rectangle shape) + where TPixel : struct, IPixel { - return source.Draw(new SolidBrush(color), thickness, shape); + return source.Draw(new SolidBrush(color), thickness, shape); } } } diff --git a/src/ImageSharp.Drawing/Paths/FillPaths.cs b/src/ImageSharp.Drawing/Paths/FillPaths.cs index 92e227ce1f..f579c4ad02 100644 --- a/src/ImageSharp.Drawing/Paths/FillPaths.cs +++ b/src/ImageSharp.Drawing/Paths/FillPaths.cs @@ -5,29 +5,27 @@ namespace ImageSharp { - using System; - using Drawing; using Drawing.Brushes; - + using ImageSharp.PixelFormats; using SixLabors.Shapes; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The shape. /// The graphics options. - /// The . - public static Image Fill(this Image source, IBrush brush, IPath path, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, IBrush brush, IPath path, GraphicsOptions options) + where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), options); } @@ -35,13 +33,13 @@ namespace ImageSharp /// /// Flood fills the image in the shape of the provided polygon with the specified brush. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The path. - /// The . - public static Image Fill(this Image source, IBrush brush, IPath path) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, IBrush brush, IPath path) + where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); } @@ -49,30 +47,30 @@ namespace ImageSharp /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The path. /// The options. - /// The . - public static Image Fill(this Image source, TColor color, IPath path, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, TPixel color, IPath path, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color), path, options); + return source.Fill(new SolidBrush(color), path, options); } /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The path. - /// The . - public static Image Fill(this Image source, TColor color, IPath path) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, TPixel color, IPath path) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color), path); + return source.Fill(new SolidBrush(color), path); } } } diff --git a/src/ImageSharp.Drawing/Paths/FillPolygon.cs b/src/ImageSharp.Drawing/Paths/FillPolygon.cs index cd3d154666..3360cff13c 100644 --- a/src/ImageSharp.Drawing/Paths/FillPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/FillPolygon.cs @@ -9,25 +9,25 @@ namespace ImageSharp using System.Numerics; using Drawing; using Drawing.Brushes; - + using ImageSharp.PixelFormats; using SixLabors.Shapes; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Flood fills the image in the shape of a Linear polygon described by the points /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The points. /// The options. - /// The . - public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); } @@ -35,13 +35,13 @@ namespace ImageSharp /// /// Flood fills the image in the shape of a Linear polygon described by the points /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The points. - /// The . - public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points) + where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points))); } @@ -49,30 +49,30 @@ namespace ImageSharp /// /// Flood fills the image in the shape of a Linear polygon described by the points /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The points. /// The options. - /// The . - public static Image FillPolygon(this Image source, TColor color, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image FillPolygon(this Image source, TPixel color, Vector2[] points, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); + return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); } /// /// Flood fills the image in the shape of a Linear polygon described by the points /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The points. - /// The . - public static Image FillPolygon(this Image source, TColor color, Vector2[] points) - where TColor : struct, IPixel + /// The . + public static Image FillPolygon(this Image source, TPixel color, Vector2[] points) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); + return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); } } } diff --git a/src/ImageSharp.Drawing/Paths/FillRectangle.cs b/src/ImageSharp.Drawing/Paths/FillRectangle.cs index 1928e54d3c..07ff4c69c5 100644 --- a/src/ImageSharp.Drawing/Paths/FillRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/FillRectangle.cs @@ -5,27 +5,26 @@ namespace ImageSharp { - using System; - using Drawing; using Drawing.Brushes; + using ImageSharp.PixelFormats; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The shape. /// The options. - /// The . - public static Image Fill(this Image source, IBrush brush, Rectangle shape, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, IBrush brush, Rectangle shape, GraphicsOptions options) + where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options); } @@ -33,13 +32,13 @@ namespace ImageSharp /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The brush. /// The shape. - /// The . - public static Image Fill(this Image source, IBrush brush, Rectangle shape) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, IBrush brush, Rectangle shape) + where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height)); } @@ -47,30 +46,30 @@ namespace ImageSharp /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The shape. /// The options. - /// The . - public static Image Fill(this Image source, TColor color, Rectangle shape, GraphicsOptions options) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, TPixel color, Rectangle shape, GraphicsOptions options) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color), shape, options); + return source.Fill(new SolidBrush(color), shape, options); } /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The color. /// The shape. - /// The . - public static Image Fill(this Image source, TColor color, Rectangle shape) - where TColor : struct, IPixel + /// The . + public static Image Fill(this Image source, TPixel color, Rectangle shape) + where TPixel : struct, IPixel { - return source.Fill(new SolidBrush(color), shape); + return source.Fill(new SolidBrush(color), shape); } } } diff --git a/src/ImageSharp.Drawing/Pens/IPen.cs b/src/ImageSharp.Drawing/Pens/IPen.cs index 72a5ffc367..31a609c8e0 100644 --- a/src/ImageSharp.Drawing/Pens/IPen.cs +++ b/src/ImageSharp.Drawing/Pens/IPen.cs @@ -5,15 +5,15 @@ namespace ImageSharp.Drawing.Pens { - using System; + using ImageSharp.PixelFormats; using Processors; /// /// Interface representing a Pen /// - /// The type of the color. - public interface IPen - where TColor : struct, IPixel + /// The type of the color. + public interface IPen + where TPixel : struct, IPixel { /// /// Creates the applicator for applying this pen to an Image @@ -26,6 +26,6 @@ namespace ImageSharp.Drawing.Pens /// /// The when being applied to things like shapes would usually be the bounding box of the shape not necessarily the shape of the whole image. /// - PenApplicator CreateApplicator(PixelAccessor pixelSource, RectangleF region); + PenApplicator CreateApplicator(PixelAccessor pixelSource, RectangleF region); } } diff --git a/src/ImageSharp.Drawing/Pens/Pen.cs b/src/ImageSharp.Drawing/Pens/Pen.cs index 09fe89419c..a3cc3cbdf1 100644 --- a/src/ImageSharp.Drawing/Pens/Pen.cs +++ b/src/ImageSharp.Drawing/Pens/Pen.cs @@ -5,17 +5,19 @@ namespace ImageSharp.Drawing.Pens { + using ImageSharp.PixelFormats; + /// - /// Represents a in the color space. + /// Represents a in the color space. /// - public class Pen : Pen + public class Pen : Pen { /// /// Initializes a new instance of the class. /// /// The color. /// The width. - public Pen(Color color, float width) + public Pen(Rgba32 color, float width) : base(color, width) { } @@ -25,7 +27,7 @@ namespace ImageSharp.Drawing.Pens /// /// The brush. /// The width. - public Pen(IBrush brush, float width) + public Pen(IBrush brush, float width) : base(brush, width) { } @@ -36,7 +38,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The pattern. - public Pen(IBrush brush, float width, float[] pattern) + public Pen(IBrush brush, float width, float[] pattern) : base(brush, width, pattern) { } @@ -45,7 +47,7 @@ namespace ImageSharp.Drawing.Pens /// Initializes a new instance of the class. /// /// The pen. - internal Pen(Pen pen) + internal Pen(Pen pen) : base(pen) { } diff --git a/src/ImageSharp.Drawing/Pens/Pens.cs b/src/ImageSharp.Drawing/Pens/Pens.cs index 039b7113ff..5c91df2261 100644 --- a/src/ImageSharp.Drawing/Pens/Pens.cs +++ b/src/ImageSharp.Drawing/Pens/Pens.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Drawing.Pens { + using ImageSharp.PixelFormats; + /// /// Common Pen styles /// @@ -16,7 +18,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Solid(Color color, float width) => new Pen(color, width); + public static Pen Solid(Rgba32 color, float width) => new Pen(color, width); /// /// Create a solid pen with out any drawing patterns @@ -24,7 +26,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Solid(IBrush brush, float width) => new Pen(brush, width); + public static Pen Solid(IBrush brush, float width) => new Pen(brush, width); /// /// Create a pen with a 'Dash' drawing patterns @@ -32,7 +34,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dash(Color color, float width) => new Pen(Pens.Dash(color, width)); + public static Pen Dash(Rgba32 color, float width) => new Pen(Pens.Dash(color, width)); /// /// Create a pen with a 'Dash' drawing patterns @@ -40,7 +42,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width)); + public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width)); /// /// Create a pen with a 'Dot' drawing patterns @@ -48,7 +50,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dot(Color color, float width) => new Pen(Pens.Dot(color, width)); + public static Pen Dot(Rgba32 color, float width) => new Pen(Pens.Dot(color, width)); /// /// Create a pen with a 'Dot' drawing patterns @@ -56,7 +58,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width)); + public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width)); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -64,7 +66,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDot(Color color, float width) => new Pen(Pens.DashDot(color, width)); + public static Pen DashDot(Rgba32 color, float width) => new Pen(Pens.DashDot(color, width)); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -72,7 +74,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width)); + public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width)); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -80,7 +82,7 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDotDot(Color color, float width) => new Pen(Pens.DashDotDot(color, width)); + public static Pen DashDotDot(Rgba32 color, float width) => new Pen(Pens.DashDotDot(color, width)); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -88,6 +90,6 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width)); + public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width)); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Pens/Pens{TColor}.cs b/src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs similarity index 67% rename from src/ImageSharp.Drawing/Pens/Pens{TColor}.cs rename to src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs index 49eed370df..5eb78dc444 100644 --- a/src/ImageSharp.Drawing/Pens/Pens{TColor}.cs +++ b/src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs @@ -1,18 +1,18 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Drawing.Pens { - using System; + using ImageSharp.PixelFormats; /// /// Common Pen styles /// - /// The type of the color. - public class Pens - where TColor : struct, IPixel + /// The type of the color. + public class Pens + where TPixel : struct, IPixel { private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f }; private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f }; @@ -25,8 +25,8 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Solid(TColor color, float width) - => new Pen(color, width); + public static Pen Solid(TPixel color, float width) + => new Pen(color, width); /// /// Create a solid pen with out any drawing patterns @@ -34,8 +34,8 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Solid(IBrush brush, float width) - => new Pen(brush, width); + public static Pen Solid(IBrush brush, float width) + => new Pen(brush, width); /// /// Create a pen with a 'Dash' drawing patterns @@ -43,8 +43,8 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dash(TColor color, float width) - => new Pen(color, width, DashedPattern); + public static Pen Dash(TPixel color, float width) + => new Pen(color, width, DashedPattern); /// /// Create a pen with a 'Dash' drawing patterns @@ -52,8 +52,8 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dash(IBrush brush, float width) - => new Pen(brush, width, DashedPattern); + public static Pen Dash(IBrush brush, float width) + => new Pen(brush, width, DashedPattern); /// /// Create a pen with a 'Dot' drawing patterns @@ -61,8 +61,8 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen Dot(TColor color, float width) - => new Pen(color, width, DottedPattern); + public static Pen Dot(TPixel color, float width) + => new Pen(color, width, DottedPattern); /// /// Create a pen with a 'Dot' drawing patterns @@ -70,8 +70,8 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen Dot(IBrush brush, float width) - => new Pen(brush, width, DottedPattern); + public static Pen Dot(IBrush brush, float width) + => new Pen(brush, width, DottedPattern); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -79,8 +79,8 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDot(TColor color, float width) - => new Pen(color, width, DashDotPattern); + public static Pen DashDot(TPixel color, float width) + => new Pen(color, width, DashDotPattern); /// /// Create a pen with a 'Dash Dot' drawing patterns @@ -88,8 +88,8 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDot(IBrush brush, float width) - => new Pen(brush, width, DashDotPattern); + public static Pen DashDot(IBrush brush, float width) + => new Pen(brush, width, DashDotPattern); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -97,8 +97,8 @@ namespace ImageSharp.Drawing.Pens /// The color. /// The width. /// The Pen - public static Pen DashDotDot(TColor color, float width) - => new Pen(color, width, DashDotDotPattern); + public static Pen DashDotDot(TPixel color, float width) + => new Pen(color, width, DashDotDotPattern); /// /// Create a pen with a 'Dash Dot Dot' drawing patterns @@ -106,7 +106,7 @@ namespace ImageSharp.Drawing.Pens /// The brush. /// The width. /// The Pen - public static Pen DashDotDot(IBrush brush, float width) - => new Pen(brush, width, DashDotDotPattern); + public static Pen DashDotDot(IBrush brush, float width) + => new Pen(brush, width, DashDotDotPattern); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Pens/Pen{TColor}.cs b/src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs similarity index 81% rename from src/ImageSharp.Drawing/Pens/Pen{TColor}.cs rename to src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs index e3716124e3..f49d03cbca 100644 --- a/src/ImageSharp.Drawing/Pens/Pen{TColor}.cs +++ b/src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs @@ -1,20 +1,20 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Drawing.Pens { - using System; using System.Numerics; using ImageSharp.Drawing.Brushes; + using ImageSharp.PixelFormats; using Processors; /// /// Provides a pen that can apply a pattern to a line with a set brush and thickness /// - /// The type of the color. + /// The type of the color. /// /// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be /// converted into a pattern that is 3.5 times longer that the width with 3 sections @@ -23,30 +23,30 @@ namespace ImageSharp.Drawing.Pens /// section 3 will be width/2 long and will be filled /// the the pattern will imidiatly repeat without gap. /// - public class Pen : IPen - where TColor : struct, IPixel + public class Pen : IPen + where TPixel : struct, IPixel { private static readonly float[] EmptyPattern = new float[0]; private readonly float[] pattern; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color. /// The width. /// The pattern. - public Pen(TColor color, float width, float[] pattern) - : this(new SolidBrush(color), width, pattern) + public Pen(TPixel color, float width, float[] pattern) + : this(new SolidBrush(color), width, pattern) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. /// The width. /// The pattern. - public Pen(IBrush brush, float width, float[] pattern) + public Pen(IBrush brush, float width, float[] pattern) { this.Brush = brush; this.Width = width; @@ -54,30 +54,30 @@ namespace ImageSharp.Drawing.Pens } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color. /// The width. - public Pen(TColor color, float width) - : this(new SolidBrush(color), width) + public Pen(TPixel color, float width) + : this(new SolidBrush(color), width) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. /// The width. - public Pen(IBrush brush, float width) + public Pen(IBrush brush, float width) : this(brush, width, EmptyPattern) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The pen. - internal Pen(Pen pen) + internal Pen(Pen pen) : this(pen.Brush, pen.Width, pen.pattern) { } @@ -88,7 +88,7 @@ namespace ImageSharp.Drawing.Pens /// /// The brush. /// - public IBrush Brush { get; } + public IBrush Brush { get; } /// /// Gets the width. @@ -110,7 +110,7 @@ namespace ImageSharp.Drawing.Pens /// The when being applied to things like shapes would ussually be the /// bounding box of the shape not necorserrally the shape of the whole image /// - public PenApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) + public PenApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region) { if (this.pattern == null || this.pattern.Length < 2) { @@ -122,12 +122,12 @@ namespace ImageSharp.Drawing.Pens return new PatternPenApplicator(sourcePixels, this.Brush, region, this.Width, this.pattern); } - private class SolidPenApplicator : PenApplicator + private class SolidPenApplicator : PenApplicator { - private readonly BrushApplicator brush; + private readonly BrushApplicator brush; private readonly float halfWidth; - public SolidPenApplicator(PixelAccessor sourcePixels, IBrush brush, RectangleF region, float width) + public SolidPenApplicator(PixelAccessor sourcePixels, IBrush brush, RectangleF region, float width) { this.brush = brush.CreateApplicator(sourcePixels, region); this.halfWidth = width / 2; @@ -144,9 +144,9 @@ namespace ImageSharp.Drawing.Pens this.brush.Dispose(); } - public override ColoredPointInfo GetColor(int x, int y, PointInfo info) + public override ColoredPointInfo GetColor(int x, int y, PointInfo info) { - ColoredPointInfo result = default(ColoredPointInfo); + ColoredPointInfo result = default(ColoredPointInfo); result.Color = this.brush[x, y]; if (info.DistanceFromPath < this.halfWidth) @@ -163,14 +163,14 @@ namespace ImageSharp.Drawing.Pens } } - private class PatternPenApplicator : PenApplicator + private class PatternPenApplicator : PenApplicator { - private readonly BrushApplicator brush; + private readonly BrushApplicator brush; private readonly float halfWidth; private readonly float[] pattern; private readonly float totalLength; - public PatternPenApplicator(PixelAccessor sourcePixels, IBrush brush, RectangleF region, float width, float[] pattern) + public PatternPenApplicator(PixelAccessor sourcePixels, IBrush brush, RectangleF region, float width, float[] pattern) { this.brush = brush.CreateApplicator(sourcePixels, region); this.halfWidth = width / 2; @@ -197,16 +197,16 @@ namespace ImageSharp.Drawing.Pens this.brush.Dispose(); } - public override ColoredPointInfo GetColor(int x, int y, PointInfo info) + public override ColoredPointInfo GetColor(int x, int y, PointInfo info) { - ColoredPointInfo infoResult = default(ColoredPointInfo); + ColoredPointInfo infoResult = default(ColoredPointInfo); infoResult.DistanceFromElement = float.MaxValue; // is really outside the element float length = info.DistanceAlongPath % this.totalLength; // we can treat the DistanceAlongPath and DistanceFromPath as x,y coords for the pattern // we need to calcualte the distance from the outside edge of the pattern - // and set them on the ColoredPointInfo along with the color. + // and set them on the ColoredPointInfo along with the color. infoResult.Color = this.brush[x, y]; float distanceWAway = 0; diff --git a/src/ImageSharp.Drawing/Pens/Processors/ColoredPointInfo.cs b/src/ImageSharp.Drawing/Pens/Processors/ColoredPointInfo.cs index d042bdccbb..65a8a61319 100644 --- a/src/ImageSharp.Drawing/Pens/Processors/ColoredPointInfo.cs +++ b/src/ImageSharp.Drawing/Pens/Processors/ColoredPointInfo.cs @@ -5,19 +5,19 @@ namespace ImageSharp.Drawing.Processors { - using System; + using ImageSharp.PixelFormats; /// /// Returns details about how far away from the inside of a shape and the color the pixel could be. /// - /// The type of the color. - public struct ColoredPointInfo - where TColor : struct, IPixel + /// The type of the color. + public struct ColoredPointInfo + where TPixel : struct, IPixel { /// /// The color /// - public TColor Color; + public TPixel Color; /// /// The distance from element diff --git a/src/ImageSharp.Drawing/Pens/Processors/PenApplicator.cs b/src/ImageSharp.Drawing/Pens/Processors/PenApplicator.cs index 8cdb04b455..ac18890685 100644 --- a/src/ImageSharp.Drawing/Pens/Processors/PenApplicator.cs +++ b/src/ImageSharp.Drawing/Pens/Processors/PenApplicator.cs @@ -6,14 +6,14 @@ namespace ImageSharp.Drawing.Processors { using System; - using System.Numerics; + using ImageSharp.PixelFormats; /// /// primitive that converts a into a color and a distance away from the drawable part of the path. /// - /// The type of the color. - public abstract class PenApplicator : IDisposable - where TColor : struct, IPixel + /// The type of the color. + public abstract class PenApplicator : IDisposable + where TPixel : struct, IPixel { /// /// Gets the required region. @@ -27,7 +27,7 @@ namespace ImageSharp.Drawing.Processors public abstract void Dispose(); /// - /// Gets a from a point represented by a . + /// Gets a from a point represented by a . /// /// The x. /// The y. @@ -35,6 +35,6 @@ namespace ImageSharp.Drawing.Processors /// /// Returns the color details and distance from a solid bit of the line. /// - public abstract ColoredPointInfo GetColor(int x, int y, PointInfo info); + public abstract ColoredPointInfo GetColor(int x, int y, PointInfo info); } } diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index c67ba0370b..e2a9ef0248 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -8,24 +8,24 @@ namespace ImageSharp.Drawing.Processors using System; using System.Numerics; using System.Threading.Tasks; - + using ImageSharp.PixelFormats; using ImageSharp.Processing; /// /// Combines two images together by blending the pixels. /// - /// The pixel format. - internal class DrawImageProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class DrawImageProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image to blend with the currently processing image. /// The size to draw the blended image. /// The location to draw the blended image. /// The opacity of the image to blend. Between 0 and 100. - public DrawImageProcessor(Image image, Size size, Point location, int alpha = 100) + public DrawImageProcessor(Image image, Size size, Point location, int alpha = 100) { Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha)); this.Image = image; @@ -37,7 +37,7 @@ namespace ImageSharp.Drawing.Processors /// /// Gets the image to blend. /// - public Image Image { get; private set; } + public Image Image { get; private set; } /// /// Gets the alpha percentage value. @@ -55,7 +55,7 @@ namespace ImageSharp.Drawing.Processors public Point Location { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { if (this.Image.Bounds.Size != this.Size) { @@ -72,8 +72,8 @@ namespace ImageSharp.Drawing.Processors float alpha = this.Alpha / 100F; - using (PixelAccessor toBlendPixels = this.Image.Lock()) - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor toBlendPixels = this.Image.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -89,7 +89,7 @@ namespace ImageSharp.Drawing.Processors // Lerping colors is dependent on the alpha of the blended color backgroundVector = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, alpha); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(backgroundVector); sourcePixels[x, y] = packed; } diff --git a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs index 89ba0968bb..62e366d2ae 100644 --- a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs @@ -8,28 +8,28 @@ namespace ImageSharp.Drawing.Processors using System; using System.Numerics; using System.Threading.Tasks; - + using ImageSharp.PixelFormats; using ImageSharp.Processing; using Pens; /// /// Draws a path using the processor pipeline /// - /// The type of the color. - /// - internal class DrawPathProcessor : ImageProcessor - where TColor : struct, IPixel + /// The type of the color. + /// + internal class DrawPathProcessor : ImageProcessor + where TPixel : struct, IPixel { private const float AntialiasFactor = 1f; private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The details how to draw the outline/path. /// The details of the paths and outlines to draw. /// The drawing configuration options. - public DrawPathProcessor(IPen pen, Drawable drawable, GraphicsOptions options) + public DrawPathProcessor(IPen pen, Drawable drawable, GraphicsOptions options) { this.Path = drawable; this.Pen = pen; @@ -44,7 +44,7 @@ namespace ImageSharp.Drawing.Processors /// /// Gets the pen. /// - public IPen Pen { get; } + public IPen Pen { get; } /// /// Gets the path. @@ -52,10 +52,10 @@ namespace ImageSharp.Drawing.Processors public Drawable Path { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - using (PixelAccessor sourcePixels = source.Lock()) - using (PenApplicator applicator = this.Pen.CreateApplicator(sourcePixels, this.Path.Bounds)) + using (PixelAccessor sourcePixels = source.Lock()) + using (PenApplicator applicator = this.Pen.CreateApplicator(sourcePixels, this.Path.Bounds)) { Rectangle rect = RectangleF.Ceiling(applicator.RequiredRegion); @@ -100,7 +100,7 @@ namespace ImageSharp.Drawing.Processors int offsetX = x - startX; PointInfo info = this.Path.GetPointInfo(offsetX, offsetY); - ColoredPointInfo color = applicator.GetColor(offsetX, offsetY, info); + ColoredPointInfo color = applicator.GetColor(offsetX, offsetY, info); float opacity = this.Opacity(color.DistanceFromElement); @@ -111,7 +111,7 @@ namespace ImageSharp.Drawing.Processors Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(finalColor); sourcePixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp.Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processors/FillProcessor.cs index 635829e9f1..ca2dc99824 100644 --- a/src/ImageSharp.Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillProcessor.cs @@ -10,31 +10,32 @@ namespace ImageSharp.Drawing.Processors using System.Threading.Tasks; using Drawing; + using ImageSharp.PixelFormats; using ImageSharp.Processing; /// /// Using the bursh as a source of pixels colors blends the brush color with source. /// - /// The pixel format. - internal class FillProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class FillProcessor : ImageProcessor + where TPixel : struct, IPixel { /// /// The brush. /// - private readonly IBrush brush; + private readonly IBrush brush; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush to source pixel colors from. - public FillProcessor(IBrush brush) + public FillProcessor(IBrush brush) { this.brush = brush; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startX = sourceRectangle.X; int endX = sourceRectangle.Right; @@ -59,10 +60,10 @@ namespace ImageSharp.Drawing.Processors } // we could possibly do some optermising by having knowledge about the individual brushes operate - // for example If brush is SolidBrush then we could just get the color upfront - // and skip using the IBrushApplicator?. - using (PixelAccessor sourcePixels = source.Lock()) - using (BrushApplicator applicator = this.brush.CreateApplicator(sourcePixels, sourceRectangle)) + // for example If brush is SolidBrush then we could just get the color upfront + // and skip using the IBrushApplicator?. + using (PixelAccessor sourcePixels = source.Lock()) + using (BrushApplicator applicator = this.brush.CreateApplicator(sourcePixels, sourceRectangle)) { Parallel.For( minY, @@ -80,7 +81,7 @@ namespace ImageSharp.Drawing.Processors Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, 1); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(finalColor); sourcePixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs index 80a3e67932..af1e6fa895 100644 --- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs @@ -7,29 +7,28 @@ namespace ImageSharp.Drawing.Processors { using System; using System.Buffers; - using System.Numerics; - using System.Threading.Tasks; using Drawing; + using ImageSharp.PixelFormats; using ImageSharp.Processing; /// /// Usinf a brsuh and a shape fills shape with contents of brush the /// - /// The type of the color. - /// - internal class FillRegionProcessor : ImageProcessor - where TColor : struct, IPixel + /// The type of the color. + /// + internal class FillRegionProcessor : ImageProcessor + where TPixel : struct, IPixel { private const float AntialiasFactor = 1f; private const int DrawPadding = 1; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The details how to fill the region of interest. /// The region of interest to be filled. /// The configuration options. - public FillRegionProcessor(IBrush brush, Region region, GraphicsOptions options) + public FillRegionProcessor(IBrush brush, Region region, GraphicsOptions options) { this.Region = region; this.Brush = brush; @@ -39,7 +38,7 @@ namespace ImageSharp.Drawing.Processors /// /// Gets the brush. /// - public IBrush Brush { get; } + public IBrush Brush { get; } /// /// Gets the region that this processor applies to. @@ -55,7 +54,7 @@ namespace ImageSharp.Drawing.Processors public GraphicsOptions Options { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { Region region = this.Region; Rectangle rect = region.Bounds; @@ -88,8 +87,8 @@ namespace ImageSharp.Drawing.Processors } } - using (PixelAccessor sourcePixels = source.Lock()) - using (BrushApplicator applicator = this.Brush.CreateApplicator(sourcePixels, rect)) + using (PixelAccessor sourcePixels = source.Lock()) + using (BrushApplicator applicator = this.Brush.CreateApplicator(sourcePixels, rect)) { float[] buffer = arrayPool.Rent(maxIntersections); int scanlineWidth = maxX - minX; diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs index eba11b5c5e..876d17aca0 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.cs @@ -10,11 +10,11 @@ namespace ImageSharp using Drawing; using Drawing.Brushes; using Drawing.Pens; - + using ImageSharp.PixelFormats; using SixLabors.Fonts; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -23,17 +23,17 @@ namespace ImageSharp /// /// Draws the text onto the the image filled via the brush. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The text. /// The font. /// The color. /// The location. /// - /// The . + /// The . /// - public static Image DrawText(this Image source, string text, Font font, TColor color, Vector2 location) - where TColor : struct, IPixel + public static Image DrawText(this Image source, string text, Font font, TPixel color, Vector2 location) + where TPixel : struct, IPixel { return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); } @@ -41,7 +41,7 @@ namespace ImageSharp /// /// Draws the text onto the the image filled via the brush. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The text. /// The font. @@ -49,28 +49,28 @@ namespace ImageSharp /// The location. /// The options. /// - /// The . + /// The . /// - public static Image DrawText(this Image source, string text, Font font, TColor color, Vector2 location, TextGraphicsOptions options) - where TColor : struct, IPixel + public static Image DrawText(this Image source, string text, Font font, TPixel color, Vector2 location, TextGraphicsOptions options) + where TPixel : struct, IPixel { - return source.DrawText(text, font, Brushes.Solid(color), null, location, options); + return source.DrawText(text, font, Brushes.Solid(color), null, location, options); } /// /// Draws the text onto the the image filled via the brush. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The text. /// The font. /// The brush. /// The location. /// - /// The . + /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, Vector2 location) - where TColor : struct, IPixel + public static Image DrawText(this Image source, string text, Font font, IBrush brush, Vector2 location) + where TPixel : struct, IPixel { return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); } @@ -78,7 +78,7 @@ namespace ImageSharp /// /// Draws the text onto the the image filled via the brush. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The text. /// The font. @@ -86,10 +86,10 @@ namespace ImageSharp /// The location. /// The options. /// - /// The . + /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, Vector2 location, TextGraphicsOptions options) - where TColor : struct, IPixel + public static Image DrawText(this Image source, string text, Font font, IBrush brush, Vector2 location, TextGraphicsOptions options) + where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, location, options); } @@ -97,17 +97,17 @@ namespace ImageSharp /// /// Draws the text onto the the image outlined via the pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The text. /// The font. /// The pen. /// The location. /// - /// The . + /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, Vector2 location) - where TColor : struct, IPixel + public static Image DrawText(this Image source, string text, Font font, IPen pen, Vector2 location) + where TPixel : struct, IPixel { return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); } @@ -115,7 +115,7 @@ namespace ImageSharp /// /// Draws the text onto the the image outlined via the pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The text. /// The font. @@ -123,10 +123,10 @@ namespace ImageSharp /// The location. /// The options. /// - /// The . + /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, Vector2 location, TextGraphicsOptions options) - where TColor : struct, IPixel + public static Image DrawText(this Image source, string text, Font font, IPen pen, Vector2 location, TextGraphicsOptions options) + where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, location, options); } @@ -134,7 +134,7 @@ namespace ImageSharp /// /// Draws the text onto the the image filled via the brush then outlined via the pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The text. /// The font. @@ -142,10 +142,10 @@ namespace ImageSharp /// The pen. /// The location. /// - /// The . + /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, Vector2 location) - where TColor : struct, IPixel + public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, Vector2 location) + where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); } @@ -153,7 +153,7 @@ namespace ImageSharp /// /// Draws the text onto the the image filled via the brush then outlined via the pen. /// - /// The type of the color. + /// The type of the color. /// The image this method extends. /// The text. /// The font. @@ -162,10 +162,10 @@ namespace ImageSharp /// The location. /// The options. /// - /// The . + /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, Vector2 location, TextGraphicsOptions options) - where TColor : struct, IPixel + public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, Vector2 location, TextGraphicsOptions options) + where TPixel : struct, IPixel { GlyphBuilder glyphBuilder = new GlyphBuilder(location); diff --git a/src/ImageSharp/Colors/Color.Definitions.cs b/src/ImageSharp/Colors/Color.Definitions.cs deleted file mode 100644 index 4bc0d486a8..0000000000 --- a/src/ImageSharp/Colors/Color.Definitions.cs +++ /dev/null @@ -1,728 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - /// - /// 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 - { - /// - /// Represents a matching the W3C definition that has an hex value of #F0F8FF. - /// - public static readonly Color AliceBlue = NamedColors.AliceBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAEBD7. - /// - public static readonly Color AntiqueWhite = NamedColors.AntiqueWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly Color Aqua = NamedColors.Aqua; - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFFD4. - /// - public static readonly Color Aquamarine = NamedColors.Aquamarine; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFFF. - /// - public static readonly Color Azure = NamedColors.Azure; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5DC. - /// - public static readonly Color Beige = NamedColors.Beige; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4C4. - /// - public static readonly Color Bisque = NamedColors.Bisque; - - /// - /// Represents a matching the W3C definition that has an hex value of #000000. - /// - public static readonly Color Black = NamedColors.Black; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEBCD. - /// - public static readonly Color BlanchedAlmond = NamedColors.BlanchedAlmond; - - /// - /// Represents a matching the W3C definition that has an hex value of #0000FF. - /// - public static readonly Color Blue = NamedColors.Blue; - - /// - /// Represents a matching the W3C definition that has an hex value of #8A2BE2. - /// - public static readonly Color BlueViolet = NamedColors.BlueViolet; - - /// - /// Represents a matching the W3C definition that has an hex value of #A52A2A. - /// - public static readonly Color Brown = NamedColors.Brown; - - /// - /// Represents a matching the W3C definition that has an hex value of #DEB887. - /// - public static readonly Color BurlyWood = NamedColors.BurlyWood; - - /// - /// Represents a matching the W3C definition that has an hex value of #5F9EA0. - /// - public static readonly Color CadetBlue = NamedColors.CadetBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFF00. - /// - public static readonly Color Chartreuse = NamedColors.Chartreuse; - - /// - /// Represents a matching the W3C definition that has an hex value of #D2691E. - /// - public static readonly Color Chocolate = NamedColors.Chocolate; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF7F50. - /// - public static readonly Color Coral = NamedColors.Coral; - - /// - /// Represents a matching the W3C definition that has an hex value of #6495ED. - /// - public static readonly Color CornflowerBlue = NamedColors.CornflowerBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF8DC. - /// - public static readonly Color Cornsilk = NamedColors.Cornsilk; - - /// - /// Represents a matching the W3C definition that has an hex value of #DC143C. - /// - public static readonly Color Crimson = NamedColors.Crimson; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly Color Cyan = NamedColors.Cyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #00008B. - /// - public static readonly Color DarkBlue = NamedColors.DarkBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #008B8B. - /// - public static readonly Color DarkCyan = NamedColors.DarkCyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #B8860B. - /// - public static readonly Color DarkGoldenrod = NamedColors.DarkGoldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #A9A9A9. - /// - public static readonly Color DarkGray = NamedColors.DarkGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #006400. - /// - public static readonly Color DarkGreen = NamedColors.DarkGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #BDB76B. - /// - public static readonly Color DarkKhaki = NamedColors.DarkKhaki; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B008B. - /// - public static readonly Color DarkMagenta = NamedColors.DarkMagenta; - - /// - /// Represents a matching the W3C definition that has an hex value of #556B2F. - /// - public static readonly Color DarkOliveGreen = NamedColors.DarkOliveGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF8C00. - /// - public static readonly Color DarkOrange = NamedColors.DarkOrange; - - /// - /// Represents a matching the W3C definition that has an hex value of #9932CC. - /// - public static readonly Color DarkOrchid = NamedColors.DarkOrchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B0000. - /// - public static readonly Color DarkRed = NamedColors.DarkRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #E9967A. - /// - public static readonly Color DarkSalmon = NamedColors.DarkSalmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #8FBC8B. - /// - public static readonly Color DarkSeaGreen = NamedColors.DarkSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #483D8B. - /// - public static readonly Color DarkSlateBlue = NamedColors.DarkSlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #2F4F4F. - /// - public static readonly Color DarkSlateGray = NamedColors.DarkSlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #00CED1. - /// - public static readonly Color DarkTurquoise = NamedColors.DarkTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #9400D3. - /// - public static readonly Color DarkViolet = NamedColors.DarkViolet; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF1493. - /// - public static readonly Color DeepPink = NamedColors.DeepPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #00BFFF. - /// - public static readonly Color DeepSkyBlue = NamedColors.DeepSkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #696969. - /// - public static readonly Color DimGray = NamedColors.DimGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #1E90FF. - /// - public static readonly Color DodgerBlue = NamedColors.DodgerBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #B22222. - /// - public static readonly Color Firebrick = NamedColors.Firebrick; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAF0. - /// - public static readonly Color FloralWhite = NamedColors.FloralWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #228B22. - /// - public static readonly Color ForestGreen = NamedColors.ForestGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly Color Fuchsia = NamedColors.Fuchsia; - - /// - /// Represents a matching the W3C definition that has an hex value of #DCDCDC. - /// - public static readonly Color Gainsboro = NamedColors.Gainsboro; - - /// - /// Represents a matching the W3C definition that has an hex value of #F8F8FF. - /// - public static readonly Color GhostWhite = NamedColors.GhostWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFD700. - /// - public static readonly Color Gold = NamedColors.Gold; - - /// - /// Represents a matching the W3C definition that has an hex value of #DAA520. - /// - public static readonly Color Goldenrod = NamedColors.Goldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #808080. - /// - public static readonly Color Gray = NamedColors.Gray; - - /// - /// Represents a matching the W3C definition that has an hex value of #008000. - /// - public static readonly Color Green = NamedColors.Green; - - /// - /// Represents a matching the W3C definition that has an hex value of #ADFF2F. - /// - public static readonly Color GreenYellow = NamedColors.GreenYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFF0. - /// - public static readonly Color Honeydew = NamedColors.Honeydew; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF69B4. - /// - public static readonly Color HotPink = NamedColors.HotPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #CD5C5C. - /// - public static readonly Color IndianRed = NamedColors.IndianRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #4B0082. - /// - public static readonly Color Indigo = NamedColors.Indigo; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFF0. - /// - public static readonly Color Ivory = NamedColors.Ivory; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0E68C. - /// - public static readonly Color Khaki = NamedColors.Khaki; - - /// - /// Represents a matching the W3C definition that has an hex value of #E6E6FA. - /// - public static readonly Color Lavender = NamedColors.Lavender; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF0F5. - /// - public static readonly Color LavenderBlush = NamedColors.LavenderBlush; - - /// - /// Represents a matching the W3C definition that has an hex value of #7CFC00. - /// - public static readonly Color LawnGreen = NamedColors.LawnGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFACD. - /// - public static readonly Color LemonChiffon = NamedColors.LemonChiffon; - - /// - /// Represents a matching the W3C definition that has an hex value of #ADD8E6. - /// - public static readonly Color LightBlue = NamedColors.LightBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #F08080. - /// - public static readonly Color LightCoral = NamedColors.LightCoral; - - /// - /// Represents a matching the W3C definition that has an hex value of #E0FFFF. - /// - public static readonly Color LightCyan = NamedColors.LightCyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAFAD2. - /// - public static readonly Color LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #D3D3D3. - /// - public static readonly Color LightGray = NamedColors.LightGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #90EE90. - /// - public static readonly Color LightGreen = NamedColors.LightGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFB6C1. - /// - public static readonly Color LightPink = NamedColors.LightPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA07A. - /// - public static readonly Color LightSalmon = NamedColors.LightSalmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #20B2AA. - /// - public static readonly Color LightSeaGreen = NamedColors.LightSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEFA. - /// - public static readonly Color LightSkyBlue = NamedColors.LightSkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #778899. - /// - public static readonly Color LightSlateGray = NamedColors.LightSlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #B0C4DE. - /// - public static readonly Color LightSteelBlue = NamedColors.LightSteelBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFE0. - /// - public static readonly Color LightYellow = NamedColors.LightYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF00. - /// - public static readonly Color Lime = NamedColors.Lime; - - /// - /// Represents a matching the W3C definition that has an hex value of #32CD32. - /// - public static readonly Color LimeGreen = NamedColors.LimeGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAF0E6. - /// - public static readonly Color Linen = NamedColors.Linen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly Color Magenta = NamedColors.Magenta; - - /// - /// Represents a matching the W3C definition that has an hex value of #800000. - /// - public static readonly Color Maroon = NamedColors.Maroon; - - /// - /// Represents a matching the W3C definition that has an hex value of #66CDAA. - /// - public static readonly Color MediumAquamarine = NamedColors.MediumAquamarine; - - /// - /// Represents a matching the W3C definition that has an hex value of #0000CD. - /// - public static readonly Color MediumBlue = NamedColors.MediumBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #BA55D3. - /// - public static readonly Color MediumOrchid = NamedColors.MediumOrchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #9370DB. - /// - public static readonly Color MediumPurple = NamedColors.MediumPurple; - - /// - /// Represents a matching the W3C definition that has an hex value of #3CB371. - /// - public static readonly Color MediumSeaGreen = NamedColors.MediumSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #7B68EE. - /// - public static readonly Color MediumSlateBlue = NamedColors.MediumSlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FA9A. - /// - public static readonly Color MediumSpringGreen = NamedColors.MediumSpringGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #48D1CC. - /// - public static readonly Color MediumTurquoise = NamedColors.MediumTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #C71585. - /// - public static readonly Color MediumVioletRed = NamedColors.MediumVioletRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #191970. - /// - public static readonly Color MidnightBlue = NamedColors.MidnightBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5FFFA. - /// - public static readonly Color MintCream = NamedColors.MintCream; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4E1. - /// - public static readonly Color MistyRose = NamedColors.MistyRose; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4B5. - /// - public static readonly Color Moccasin = NamedColors.Moccasin; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDEAD. - /// - public static readonly Color NavajoWhite = NamedColors.NavajoWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #000080. - /// - public static readonly Color Navy = NamedColors.Navy; - - /// - /// Represents a matching the W3C definition that has an hex value of #FDF5E6. - /// - public static readonly Color OldLace = NamedColors.OldLace; - - /// - /// Represents a matching the W3C definition that has an hex value of #808000. - /// - public static readonly Color Olive = NamedColors.Olive; - - /// - /// Represents a matching the W3C definition that has an hex value of #6B8E23. - /// - public static readonly Color OliveDrab = NamedColors.OliveDrab; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA500. - /// - public static readonly Color Orange = NamedColors.Orange; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF4500. - /// - public static readonly Color OrangeRed = NamedColors.OrangeRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #DA70D6. - /// - public static readonly Color Orchid = NamedColors.Orchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #EEE8AA. - /// - public static readonly Color PaleGoldenrod = NamedColors.PaleGoldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #98FB98. - /// - public static readonly Color PaleGreen = NamedColors.PaleGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #AFEEEE. - /// - public static readonly Color PaleTurquoise = NamedColors.PaleTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #DB7093. - /// - public static readonly Color PaleVioletRed = NamedColors.PaleVioletRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEFD5. - /// - public static readonly Color PapayaWhip = NamedColors.PapayaWhip; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDAB9. - /// - public static readonly Color PeachPuff = NamedColors.PeachPuff; - - /// - /// Represents a matching the W3C definition that has an hex value of #CD853F. - /// - public static readonly Color Peru = NamedColors.Peru; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFC0CB. - /// - public static readonly Color Pink = NamedColors.Pink; - - /// - /// Represents a matching the W3C definition that has an hex value of #DDA0DD. - /// - public static readonly Color Plum = NamedColors.Plum; - - /// - /// Represents a matching the W3C definition that has an hex value of #B0E0E6. - /// - public static readonly Color PowderBlue = NamedColors.PowderBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #800080. - /// - public static readonly Color Purple = NamedColors.Purple; - - /// - /// Represents a matching the W3C definition that has an hex value of #663399. - /// - public static readonly Color RebeccaPurple = NamedColors.RebeccaPurple; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF0000. - /// - public static readonly Color Red = NamedColors.Red; - - /// - /// Represents a matching the W3C definition that has an hex value of #BC8F8F. - /// - public static readonly Color RosyBrown = NamedColors.RosyBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #4169E1. - /// - public static readonly Color RoyalBlue = NamedColors.RoyalBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B4513. - /// - public static readonly Color SaddleBrown = NamedColors.SaddleBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #FA8072. - /// - public static readonly Color Salmon = NamedColors.Salmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #F4A460. - /// - public static readonly Color SandyBrown = NamedColors.SandyBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #2E8B57. - /// - public static readonly Color SeaGreen = NamedColors.SeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF5EE. - /// - public static readonly Color SeaShell = NamedColors.SeaShell; - - /// - /// Represents a matching the W3C definition that has an hex value of #A0522D. - /// - public static readonly Color Sienna = NamedColors.Sienna; - - /// - /// Represents a matching the W3C definition that has an hex value of #C0C0C0. - /// - public static readonly Color Silver = NamedColors.Silver; - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEEB. - /// - public static readonly Color SkyBlue = NamedColors.SkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #6A5ACD. - /// - public static readonly Color SlateBlue = NamedColors.SlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #708090. - /// - public static readonly Color SlateGray = NamedColors.SlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAFA. - /// - public static readonly Color Snow = NamedColors.Snow; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF7F. - /// - public static readonly Color SpringGreen = NamedColors.SpringGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #4682B4. - /// - public static readonly Color SteelBlue = NamedColors.SteelBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #D2B48C. - /// - public static readonly Color Tan = NamedColors.Tan; - - /// - /// Represents a matching the W3C definition that has an hex value of #008080. - /// - public static readonly Color Teal = NamedColors.Teal; - - /// - /// Represents a matching the W3C definition that has an hex value of #D8BFD8. - /// - public static readonly Color Thistle = NamedColors.Thistle; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF6347. - /// - public static readonly Color Tomato = NamedColors.Tomato; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly Color Transparent = NamedColors.Transparent; - - /// - /// Represents a matching the W3C definition that has an hex value of #40E0D0. - /// - public static readonly Color Turquoise = NamedColors.Turquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #EE82EE. - /// - public static readonly Color Violet = NamedColors.Violet; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5DEB3. - /// - public static readonly Color Wheat = NamedColors.Wheat; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly Color White = NamedColors.White; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5F5. - /// - public static readonly Color WhiteSmoke = NamedColors.WhiteSmoke; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFF00. - /// - public static readonly Color Yellow = NamedColors.Yellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #9ACD32. - /// - public static readonly Color YellowGreen = NamedColors.YellowGreen; - } -} \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorConstants.cs b/src/ImageSharp/Colors/ColorConstants.cs deleted file mode 100644 index 1397b6da6f..0000000000 --- a/src/ImageSharp/Colors/ColorConstants.cs +++ /dev/null @@ -1,179 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.Collections.Generic; - - /// - /// Provides useful color definitions. - /// - public static class ColorConstants - { - /// - /// Provides a lazy, one time method of returning the colors. - /// - private static readonly Lazy SafeColors = new Lazy(GetWebSafeColors); - - /// - /// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4. - /// - public static Color[] WebSafeColors => SafeColors.Value; - - /// - /// Returns an array of web safe colors. - /// - /// The - private static Color[] GetWebSafeColors() - { - return new List - { - Color.AliceBlue, - Color.AntiqueWhite, - Color.Aqua, - Color.Aquamarine, - Color.Azure, - Color.Beige, - Color.Bisque, - Color.Black, - Color.BlanchedAlmond, - Color.Blue, - Color.BlueViolet, - Color.Brown, - Color.BurlyWood, - Color.CadetBlue, - Color.Chartreuse, - Color.Chocolate, - Color.Coral, - Color.CornflowerBlue, - Color.Cornsilk, - Color.Crimson, - Color.Cyan, - Color.DarkBlue, - Color.DarkCyan, - Color.DarkGoldenrod, - Color.DarkGray, - Color.DarkGreen, - Color.DarkKhaki, - Color.DarkMagenta, - Color.DarkOliveGreen, - Color.DarkOrange, - Color.DarkOrchid, - Color.DarkRed, - Color.DarkSalmon, - Color.DarkSeaGreen, - Color.DarkSlateBlue, - Color.DarkSlateGray, - Color.DarkTurquoise, - Color.DarkViolet, - Color.DeepPink, - Color.DeepSkyBlue, - Color.DimGray, - Color.DodgerBlue, - Color.Firebrick, - Color.FloralWhite, - Color.ForestGreen, - Color.Fuchsia, - Color.Gainsboro, - Color.GhostWhite, - Color.Gold, - Color.Goldenrod, - Color.Gray, - Color.Green, - Color.GreenYellow, - Color.Honeydew, - Color.HotPink, - Color.IndianRed, - Color.Indigo, - Color.Ivory, - Color.Khaki, - Color.Lavender, - Color.LavenderBlush, - Color.LawnGreen, - Color.LemonChiffon, - Color.LightBlue, - Color.LightCoral, - Color.LightCyan, - Color.LightGoldenrodYellow, - Color.LightGray, - Color.LightGreen, - Color.LightPink, - Color.LightSalmon, - Color.LightSeaGreen, - Color.LightSkyBlue, - Color.LightSlateGray, - Color.LightSteelBlue, - Color.LightYellow, - Color.Lime, - Color.LimeGreen, - Color.Linen, - Color.Magenta, - Color.Maroon, - Color.MediumAquamarine, - Color.MediumBlue, - Color.MediumOrchid, - Color.MediumPurple, - Color.MediumSeaGreen, - Color.MediumSlateBlue, - Color.MediumSpringGreen, - Color.MediumTurquoise, - Color.MediumVioletRed, - Color.MidnightBlue, - Color.MintCream, - Color.MistyRose, - Color.Moccasin, - Color.NavajoWhite, - Color.Navy, - Color.OldLace, - Color.Olive, - Color.OliveDrab, - Color.Orange, - Color.OrangeRed, - Color.Orchid, - Color.PaleGoldenrod, - Color.PaleGreen, - Color.PaleTurquoise, - Color.PaleVioletRed, - Color.PapayaWhip, - Color.PeachPuff, - Color.Peru, - Color.Pink, - Color.Plum, - Color.PowderBlue, - Color.Purple, - Color.RebeccaPurple, - Color.Red, - Color.RosyBrown, - Color.RoyalBlue, - Color.SaddleBrown, - Color.Salmon, - Color.SandyBrown, - Color.SeaGreen, - Color.SeaShell, - Color.Sienna, - Color.Silver, - Color.SkyBlue, - Color.SlateBlue, - Color.SlateGray, - Color.Snow, - Color.SpringGreen, - Color.SteelBlue, - Color.Tan, - Color.Teal, - Color.Thistle, - Color.Tomato, - Color.Transparent, - Color.Turquoise, - Color.Violet, - Color.Wheat, - Color.White, - Color.WhiteSmoke, - Color.Yellow, - Color.YellowGreen - }.ToArray(); - } - } -} diff --git a/src/ImageSharp/Colors/ColorVector.BulkOperations.cs b/src/ImageSharp/Colors/ColorVector.BulkOperations.cs deleted file mode 100644 index ab32313c04..0000000000 --- a/src/ImageSharp/Colors/ColorVector.BulkOperations.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace ImageSharp -{ - using System.Numerics; - - /// - /// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1. - /// 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 ColorVector - { - /// - /// implementation optimized for . - /// - internal class BulkOperations : BulkPixelOperations - { - /// - internal override unsafe void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) - { - BufferSpan.Copy(sourceColors.AsBytes(), destVectors.AsBytes(), count * sizeof(Vector4)); - } - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorVector.Definitions.cs b/src/ImageSharp/Colors/ColorVector.Definitions.cs deleted file mode 100644 index 150b7209c7..0000000000 --- a/src/ImageSharp/Colors/ColorVector.Definitions.cs +++ /dev/null @@ -1,728 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - /// - /// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1. - /// 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 ColorVector - { - /// - /// Represents a matching the W3C definition that has an hex value of #F0F8FF. - /// - public static readonly ColorVector AliceBlue = NamedColors.AliceBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAEBD7. - /// - public static readonly ColorVector AntiqueWhite = NamedColors.AntiqueWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly ColorVector Aqua = NamedColors.Aqua; - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFFD4. - /// - public static readonly ColorVector Aquamarine = NamedColors.Aquamarine; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFFF. - /// - public static readonly ColorVector Azure = NamedColors.Azure; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5DC. - /// - public static readonly ColorVector Beige = NamedColors.Beige; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4C4. - /// - public static readonly ColorVector Bisque = NamedColors.Bisque; - - /// - /// Represents a matching the W3C definition that has an hex value of #000000. - /// - public static readonly ColorVector Black = NamedColors.Black; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEBCD. - /// - public static readonly ColorVector BlanchedAlmond = NamedColors.BlanchedAlmond; - - /// - /// Represents a matching the W3C definition that has an hex value of #0000FF. - /// - public static readonly ColorVector Blue = NamedColors.Blue; - - /// - /// Represents a matching the W3C definition that has an hex value of #8A2BE2. - /// - public static readonly ColorVector BlueViolet = NamedColors.BlueViolet; - - /// - /// Represents a matching the W3C definition that has an hex value of #A52A2A. - /// - public static readonly ColorVector Brown = NamedColors.Brown; - - /// - /// Represents a matching the W3C definition that has an hex value of #DEB887. - /// - public static readonly ColorVector BurlyWood = NamedColors.BurlyWood; - - /// - /// Represents a matching the W3C definition that has an hex value of #5F9EA0. - /// - public static readonly ColorVector CadetBlue = NamedColors.CadetBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFF00. - /// - public static readonly ColorVector Chartreuse = NamedColors.Chartreuse; - - /// - /// Represents a matching the W3C definition that has an hex value of #D2691E. - /// - public static readonly ColorVector Chocolate = NamedColors.Chocolate; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF7F50. - /// - public static readonly ColorVector Coral = NamedColors.Coral; - - /// - /// Represents a matching the W3C definition that has an hex value of #6495ED. - /// - public static readonly ColorVector CornflowerBlue = NamedColors.CornflowerBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF8DC. - /// - public static readonly ColorVector Cornsilk = NamedColors.Cornsilk; - - /// - /// Represents a matching the W3C definition that has an hex value of #DC143C. - /// - public static readonly ColorVector Crimson = NamedColors.Crimson; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly ColorVector Cyan = NamedColors.Cyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #00008B. - /// - public static readonly ColorVector DarkBlue = NamedColors.DarkBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #008B8B. - /// - public static readonly ColorVector DarkCyan = NamedColors.DarkCyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #B8860B. - /// - public static readonly ColorVector DarkGoldenrod = NamedColors.DarkGoldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #A9A9A9. - /// - public static readonly ColorVector DarkGray = NamedColors.DarkGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #006400. - /// - public static readonly ColorVector DarkGreen = NamedColors.DarkGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #BDB76B. - /// - public static readonly ColorVector DarkKhaki = NamedColors.DarkKhaki; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B008B. - /// - public static readonly ColorVector DarkMagenta = NamedColors.DarkMagenta; - - /// - /// Represents a matching the W3C definition that has an hex value of #556B2F. - /// - public static readonly ColorVector DarkOliveGreen = NamedColors.DarkOliveGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF8C00. - /// - public static readonly ColorVector DarkOrange = NamedColors.DarkOrange; - - /// - /// Represents a matching the W3C definition that has an hex value of #9932CC. - /// - public static readonly ColorVector DarkOrchid = NamedColors.DarkOrchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B0000. - /// - public static readonly ColorVector DarkRed = NamedColors.DarkRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #E9967A. - /// - public static readonly ColorVector DarkSalmon = NamedColors.DarkSalmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #8FBC8B. - /// - public static readonly ColorVector DarkSeaGreen = NamedColors.DarkSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #483D8B. - /// - public static readonly ColorVector DarkSlateBlue = NamedColors.DarkSlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #2F4F4F. - /// - public static readonly ColorVector DarkSlateGray = NamedColors.DarkSlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #00CED1. - /// - public static readonly ColorVector DarkTurquoise = NamedColors.DarkTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #9400D3. - /// - public static readonly ColorVector DarkViolet = NamedColors.DarkViolet; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF1493. - /// - public static readonly ColorVector DeepPink = NamedColors.DeepPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #00BFFF. - /// - public static readonly ColorVector DeepSkyBlue = NamedColors.DeepSkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #696969. - /// - public static readonly ColorVector DimGray = NamedColors.DimGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #1E90FF. - /// - public static readonly ColorVector DodgerBlue = NamedColors.DodgerBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #B22222. - /// - public static readonly ColorVector Firebrick = NamedColors.Firebrick; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAF0. - /// - public static readonly ColorVector FloralWhite = NamedColors.FloralWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #228B22. - /// - public static readonly ColorVector ForestGreen = NamedColors.ForestGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly ColorVector Fuchsia = NamedColors.Fuchsia; - - /// - /// Represents a matching the W3C definition that has an hex value of #DCDCDC. - /// - public static readonly ColorVector Gainsboro = NamedColors.Gainsboro; - - /// - /// Represents a matching the W3C definition that has an hex value of #F8F8FF. - /// - public static readonly ColorVector GhostWhite = NamedColors.GhostWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFD700. - /// - public static readonly ColorVector Gold = NamedColors.Gold; - - /// - /// Represents a matching the W3C definition that has an hex value of #DAA520. - /// - public static readonly ColorVector Goldenrod = NamedColors.Goldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #808080. - /// - public static readonly ColorVector Gray = NamedColors.Gray; - - /// - /// Represents a matching the W3C definition that has an hex value of #008000. - /// - public static readonly ColorVector Green = NamedColors.Green; - - /// - /// Represents a matching the W3C definition that has an hex value of #ADFF2F. - /// - public static readonly ColorVector GreenYellow = NamedColors.GreenYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFF0. - /// - public static readonly ColorVector Honeydew = NamedColors.Honeydew; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF69B4. - /// - public static readonly ColorVector HotPink = NamedColors.HotPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #CD5C5C. - /// - public static readonly ColorVector IndianRed = NamedColors.IndianRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #4B0082. - /// - public static readonly ColorVector Indigo = NamedColors.Indigo; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFF0. - /// - public static readonly ColorVector Ivory = NamedColors.Ivory; - - /// - /// Represents a matching the W3C definition that has an hex value of #F0E68C. - /// - public static readonly ColorVector Khaki = NamedColors.Khaki; - - /// - /// Represents a matching the W3C definition that has an hex value of #E6E6FA. - /// - public static readonly ColorVector Lavender = NamedColors.Lavender; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF0F5. - /// - public static readonly ColorVector LavenderBlush = NamedColors.LavenderBlush; - - /// - /// Represents a matching the W3C definition that has an hex value of #7CFC00. - /// - public static readonly ColorVector LawnGreen = NamedColors.LawnGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFACD. - /// - public static readonly ColorVector LemonChiffon = NamedColors.LemonChiffon; - - /// - /// Represents a matching the W3C definition that has an hex value of #ADD8E6. - /// - public static readonly ColorVector LightBlue = NamedColors.LightBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #F08080. - /// - public static readonly ColorVector LightCoral = NamedColors.LightCoral; - - /// - /// Represents a matching the W3C definition that has an hex value of #E0FFFF. - /// - public static readonly ColorVector LightCyan = NamedColors.LightCyan; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAFAD2. - /// - public static readonly ColorVector LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #D3D3D3. - /// - public static readonly ColorVector LightGray = NamedColors.LightGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #90EE90. - /// - public static readonly ColorVector LightGreen = NamedColors.LightGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFB6C1. - /// - public static readonly ColorVector LightPink = NamedColors.LightPink; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA07A. - /// - public static readonly ColorVector LightSalmon = NamedColors.LightSalmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #20B2AA. - /// - public static readonly ColorVector LightSeaGreen = NamedColors.LightSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEFA. - /// - public static readonly ColorVector LightSkyBlue = NamedColors.LightSkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #778899. - /// - public static readonly ColorVector LightSlateGray = NamedColors.LightSlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #B0C4DE. - /// - public static readonly ColorVector LightSteelBlue = NamedColors.LightSteelBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFE0. - /// - public static readonly ColorVector LightYellow = NamedColors.LightYellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF00. - /// - public static readonly ColorVector Lime = NamedColors.Lime; - - /// - /// Represents a matching the W3C definition that has an hex value of #32CD32. - /// - public static readonly ColorVector LimeGreen = NamedColors.LimeGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FAF0E6. - /// - public static readonly ColorVector Linen = NamedColors.Linen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly ColorVector Magenta = NamedColors.Magenta; - - /// - /// Represents a matching the W3C definition that has an hex value of #800000. - /// - public static readonly ColorVector Maroon = NamedColors.Maroon; - - /// - /// Represents a matching the W3C definition that has an hex value of #66CDAA. - /// - public static readonly ColorVector MediumAquamarine = NamedColors.MediumAquamarine; - - /// - /// Represents a matching the W3C definition that has an hex value of #0000CD. - /// - public static readonly ColorVector MediumBlue = NamedColors.MediumBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #BA55D3. - /// - public static readonly ColorVector MediumOrchid = NamedColors.MediumOrchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #9370DB. - /// - public static readonly ColorVector MediumPurple = NamedColors.MediumPurple; - - /// - /// Represents a matching the W3C definition that has an hex value of #3CB371. - /// - public static readonly ColorVector MediumSeaGreen = NamedColors.MediumSeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #7B68EE. - /// - public static readonly ColorVector MediumSlateBlue = NamedColors.MediumSlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FA9A. - /// - public static readonly ColorVector MediumSpringGreen = NamedColors.MediumSpringGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #48D1CC. - /// - public static readonly ColorVector MediumTurquoise = NamedColors.MediumTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #C71585. - /// - public static readonly ColorVector MediumVioletRed = NamedColors.MediumVioletRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #191970. - /// - public static readonly ColorVector MidnightBlue = NamedColors.MidnightBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5FFFA. - /// - public static readonly ColorVector MintCream = NamedColors.MintCream; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4E1. - /// - public static readonly ColorVector MistyRose = NamedColors.MistyRose; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4B5. - /// - public static readonly ColorVector Moccasin = NamedColors.Moccasin; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDEAD. - /// - public static readonly ColorVector NavajoWhite = NamedColors.NavajoWhite; - - /// - /// Represents a matching the W3C definition that has an hex value of #000080. - /// - public static readonly ColorVector Navy = NamedColors.Navy; - - /// - /// Represents a matching the W3C definition that has an hex value of #FDF5E6. - /// - public static readonly ColorVector OldLace = NamedColors.OldLace; - - /// - /// Represents a matching the W3C definition that has an hex value of #808000. - /// - public static readonly ColorVector Olive = NamedColors.Olive; - - /// - /// Represents a matching the W3C definition that has an hex value of #6B8E23. - /// - public static readonly ColorVector OliveDrab = NamedColors.OliveDrab; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA500. - /// - public static readonly ColorVector Orange = NamedColors.Orange; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF4500. - /// - public static readonly ColorVector OrangeRed = NamedColors.OrangeRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #DA70D6. - /// - public static readonly ColorVector Orchid = NamedColors.Orchid; - - /// - /// Represents a matching the W3C definition that has an hex value of #EEE8AA. - /// - public static readonly ColorVector PaleGoldenrod = NamedColors.PaleGoldenrod; - - /// - /// Represents a matching the W3C definition that has an hex value of #98FB98. - /// - public static readonly ColorVector PaleGreen = NamedColors.PaleGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #AFEEEE. - /// - public static readonly ColorVector PaleTurquoise = NamedColors.PaleTurquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #DB7093. - /// - public static readonly ColorVector PaleVioletRed = NamedColors.PaleVioletRed; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEFD5. - /// - public static readonly ColorVector PapayaWhip = NamedColors.PapayaWhip; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDAB9. - /// - public static readonly ColorVector PeachPuff = NamedColors.PeachPuff; - - /// - /// Represents a matching the W3C definition that has an hex value of #CD853F. - /// - public static readonly ColorVector Peru = NamedColors.Peru; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFC0CB. - /// - public static readonly ColorVector Pink = NamedColors.Pink; - - /// - /// Represents a matching the W3C definition that has an hex value of #DDA0DD. - /// - public static readonly ColorVector Plum = NamedColors.Plum; - - /// - /// Represents a matching the W3C definition that has an hex value of #B0E0E6. - /// - public static readonly ColorVector PowderBlue = NamedColors.PowderBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #800080. - /// - public static readonly ColorVector Purple = NamedColors.Purple; - - /// - /// Represents a matching the W3C definition that has an hex value of #663399. - /// - public static readonly ColorVector RebeccaPurple = NamedColors.RebeccaPurple; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF0000. - /// - public static readonly ColorVector Red = NamedColors.Red; - - /// - /// Represents a matching the W3C definition that has an hex value of #BC8F8F. - /// - public static readonly ColorVector RosyBrown = NamedColors.RosyBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #4169E1. - /// - public static readonly ColorVector RoyalBlue = NamedColors.RoyalBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #8B4513. - /// - public static readonly ColorVector SaddleBrown = NamedColors.SaddleBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #FA8072. - /// - public static readonly ColorVector Salmon = NamedColors.Salmon; - - /// - /// Represents a matching the W3C definition that has an hex value of #F4A460. - /// - public static readonly ColorVector SandyBrown = NamedColors.SandyBrown; - - /// - /// Represents a matching the W3C definition that has an hex value of #2E8B57. - /// - public static readonly ColorVector SeaGreen = NamedColors.SeaGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF5EE. - /// - public static readonly ColorVector SeaShell = NamedColors.SeaShell; - - /// - /// Represents a matching the W3C definition that has an hex value of #A0522D. - /// - public static readonly ColorVector Sienna = NamedColors.Sienna; - - /// - /// Represents a matching the W3C definition that has an hex value of #C0C0C0. - /// - public static readonly ColorVector Silver = NamedColors.Silver; - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEEB. - /// - public static readonly ColorVector SkyBlue = NamedColors.SkyBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #6A5ACD. - /// - public static readonly ColorVector SlateBlue = NamedColors.SlateBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #708090. - /// - public static readonly ColorVector SlateGray = NamedColors.SlateGray; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAFA. - /// - public static readonly ColorVector Snow = NamedColors.Snow; - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF7F. - /// - public static readonly ColorVector SpringGreen = NamedColors.SpringGreen; - - /// - /// Represents a matching the W3C definition that has an hex value of #4682B4. - /// - public static readonly ColorVector SteelBlue = NamedColors.SteelBlue; - - /// - /// Represents a matching the W3C definition that has an hex value of #D2B48C. - /// - public static readonly ColorVector Tan = NamedColors.Tan; - - /// - /// Represents a matching the W3C definition that has an hex value of #008080. - /// - public static readonly ColorVector Teal = NamedColors.Teal; - - /// - /// Represents a matching the W3C definition that has an hex value of #D8BFD8. - /// - public static readonly ColorVector Thistle = NamedColors.Thistle; - - /// - /// Represents a matching the W3C definition that has an hex value of #FF6347. - /// - public static readonly ColorVector Tomato = NamedColors.Tomato; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly ColorVector Transparent = NamedColors.Transparent; - - /// - /// Represents a matching the W3C definition that has an hex value of #40E0D0. - /// - public static readonly ColorVector Turquoise = NamedColors.Turquoise; - - /// - /// Represents a matching the W3C definition that has an hex value of #EE82EE. - /// - public static readonly ColorVector Violet = NamedColors.Violet; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5DEB3. - /// - public static readonly ColorVector Wheat = NamedColors.Wheat; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly ColorVector White = NamedColors.White; - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5F5. - /// - public static readonly ColorVector WhiteSmoke = NamedColors.WhiteSmoke; - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFF00. - /// - public static readonly ColorVector Yellow = NamedColors.Yellow; - - /// - /// Represents a matching the W3C definition that has an hex value of #9ACD32. - /// - public static readonly ColorVector YellowGreen = NamedColors.YellowGreen; - } -} \ No newline at end of file diff --git a/src/ImageSharp/Colors/NamedColors{TColor}.cs b/src/ImageSharp/Colors/NamedColors{TColor}.cs deleted file mode 100644 index f8080195d0..0000000000 --- a/src/ImageSharp/Colors/NamedColors{TColor}.cs +++ /dev/null @@ -1,727 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - - /// - /// A set of named colors mapped to the provided color space. - /// - /// The type of the color. - public static class NamedColors - where TColor : struct, IPixel - { - /// - /// Represents a matching the W3C definition that has an hex value of #F0F8FF. - /// - public static readonly TColor AliceBlue = ColorBuilder.FromRGBA(240, 248, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FAEBD7. - /// - public static readonly TColor AntiqueWhite = ColorBuilder.FromRGBA(250, 235, 215, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly TColor Aqua = ColorBuilder.FromRGBA(0, 255, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFFD4. - /// - public static readonly TColor Aquamarine = ColorBuilder.FromRGBA(127, 255, 212, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFFF. - /// - public static readonly TColor Azure = ColorBuilder.FromRGBA(240, 255, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5DC. - /// - public static readonly TColor Beige = ColorBuilder.FromRGBA(245, 245, 220, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4C4. - /// - public static readonly TColor Bisque = ColorBuilder.FromRGBA(255, 228, 196, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #000000. - /// - public static readonly TColor Black = ColorBuilder.FromRGBA(0, 0, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEBCD. - /// - public static readonly TColor BlanchedAlmond = ColorBuilder.FromRGBA(255, 235, 205, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #0000FF. - /// - public static readonly TColor Blue = ColorBuilder.FromRGBA(0, 0, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #8A2BE2. - /// - public static readonly TColor BlueViolet = ColorBuilder.FromRGBA(138, 43, 226, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #A52A2A. - /// - public static readonly TColor Brown = ColorBuilder.FromRGBA(165, 42, 42, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #DEB887. - /// - public static readonly TColor BurlyWood = ColorBuilder.FromRGBA(222, 184, 135, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #5F9EA0. - /// - public static readonly TColor CadetBlue = ColorBuilder.FromRGBA(95, 158, 160, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #7FFF00. - /// - public static readonly TColor Chartreuse = ColorBuilder.FromRGBA(127, 255, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #D2691E. - /// - public static readonly TColor Chocolate = ColorBuilder.FromRGBA(210, 105, 30, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF7F50. - /// - public static readonly TColor Coral = ColorBuilder.FromRGBA(255, 127, 80, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #6495ED. - /// - public static readonly TColor CornflowerBlue = ColorBuilder.FromRGBA(100, 149, 237, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF8DC. - /// - public static readonly TColor Cornsilk = ColorBuilder.FromRGBA(255, 248, 220, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #DC143C. - /// - public static readonly TColor Crimson = ColorBuilder.FromRGBA(220, 20, 60, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #00FFFF. - /// - public static readonly TColor Cyan = ColorBuilder.FromRGBA(0, 255, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #00008B. - /// - public static readonly TColor DarkBlue = ColorBuilder.FromRGBA(0, 0, 139, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #008B8B. - /// - public static readonly TColor DarkCyan = ColorBuilder.FromRGBA(0, 139, 139, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #B8860B. - /// - public static readonly TColor DarkGoldenrod = ColorBuilder.FromRGBA(184, 134, 11, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #A9A9A9. - /// - public static readonly TColor DarkGray = ColorBuilder.FromRGBA(169, 169, 169, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #006400. - /// - public static readonly TColor DarkGreen = ColorBuilder.FromRGBA(0, 100, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #BDB76B. - /// - public static readonly TColor DarkKhaki = ColorBuilder.FromRGBA(189, 183, 107, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #8B008B. - /// - public static readonly TColor DarkMagenta = ColorBuilder.FromRGBA(139, 0, 139, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #556B2F. - /// - public static readonly TColor DarkOliveGreen = ColorBuilder.FromRGBA(85, 107, 47, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF8C00. - /// - public static readonly TColor DarkOrange = ColorBuilder.FromRGBA(255, 140, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #9932CC. - /// - public static readonly TColor DarkOrchid = ColorBuilder.FromRGBA(153, 50, 204, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #8B0000. - /// - public static readonly TColor DarkRed = ColorBuilder.FromRGBA(139, 0, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #E9967A. - /// - public static readonly TColor DarkSalmon = ColorBuilder.FromRGBA(233, 150, 122, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #8FBC8B. - /// - public static readonly TColor DarkSeaGreen = ColorBuilder.FromRGBA(143, 188, 139, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #483D8B. - /// - public static readonly TColor DarkSlateBlue = ColorBuilder.FromRGBA(72, 61, 139, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #2F4F4F. - /// - public static readonly TColor DarkSlateGray = ColorBuilder.FromRGBA(47, 79, 79, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #00CED1. - /// - public static readonly TColor DarkTurquoise = ColorBuilder.FromRGBA(0, 206, 209, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #9400D3. - /// - public static readonly TColor DarkViolet = ColorBuilder.FromRGBA(148, 0, 211, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF1493. - /// - public static readonly TColor DeepPink = ColorBuilder.FromRGBA(255, 20, 147, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #00BFFF. - /// - public static readonly TColor DeepSkyBlue = ColorBuilder.FromRGBA(0, 191, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #696969. - /// - public static readonly TColor DimGray = ColorBuilder.FromRGBA(105, 105, 105, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #1E90FF. - /// - public static readonly TColor DodgerBlue = ColorBuilder.FromRGBA(30, 144, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #B22222. - /// - public static readonly TColor Firebrick = ColorBuilder.FromRGBA(178, 34, 34, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAF0. - /// - public static readonly TColor FloralWhite = ColorBuilder.FromRGBA(255, 250, 240, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #228B22. - /// - public static readonly TColor ForestGreen = ColorBuilder.FromRGBA(34, 139, 34, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly TColor Fuchsia = ColorBuilder.FromRGBA(255, 0, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #DCDCDC. - /// - public static readonly TColor Gainsboro = ColorBuilder.FromRGBA(220, 220, 220, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F8F8FF. - /// - public static readonly TColor GhostWhite = ColorBuilder.FromRGBA(248, 248, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFD700. - /// - public static readonly TColor Gold = ColorBuilder.FromRGBA(255, 215, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #DAA520. - /// - public static readonly TColor Goldenrod = ColorBuilder.FromRGBA(218, 165, 32, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #808080. - /// - public static readonly TColor Gray = ColorBuilder.FromRGBA(128, 128, 128, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #008000. - /// - public static readonly TColor Green = ColorBuilder.FromRGBA(0, 128, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #ADFF2F. - /// - public static readonly TColor GreenYellow = ColorBuilder.FromRGBA(173, 255, 47, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F0FFF0. - /// - public static readonly TColor Honeydew = ColorBuilder.FromRGBA(240, 255, 240, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF69B4. - /// - public static readonly TColor HotPink = ColorBuilder.FromRGBA(255, 105, 180, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #CD5C5C. - /// - public static readonly TColor IndianRed = ColorBuilder.FromRGBA(205, 92, 92, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #4B0082. - /// - public static readonly TColor Indigo = ColorBuilder.FromRGBA(75, 0, 130, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFF0. - /// - public static readonly TColor Ivory = ColorBuilder.FromRGBA(255, 255, 240, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F0E68C. - /// - public static readonly TColor Khaki = ColorBuilder.FromRGBA(240, 230, 140, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #E6E6FA. - /// - public static readonly TColor Lavender = ColorBuilder.FromRGBA(230, 230, 250, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF0F5. - /// - public static readonly TColor LavenderBlush = ColorBuilder.FromRGBA(255, 240, 245, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #7CFC00. - /// - public static readonly TColor LawnGreen = ColorBuilder.FromRGBA(124, 252, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFACD. - /// - public static readonly TColor LemonChiffon = ColorBuilder.FromRGBA(255, 250, 205, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #ADD8E6. - /// - public static readonly TColor LightBlue = ColorBuilder.FromRGBA(173, 216, 230, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F08080. - /// - public static readonly TColor LightCoral = ColorBuilder.FromRGBA(240, 128, 128, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #E0FFFF. - /// - public static readonly TColor LightCyan = ColorBuilder.FromRGBA(224, 255, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FAFAD2. - /// - public static readonly TColor LightGoldenrodYellow = ColorBuilder.FromRGBA(250, 250, 210, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #D3D3D3. - /// - public static readonly TColor LightGray = ColorBuilder.FromRGBA(211, 211, 211, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #90EE90. - /// - public static readonly TColor LightGreen = ColorBuilder.FromRGBA(144, 238, 144, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFB6C1. - /// - public static readonly TColor LightPink = ColorBuilder.FromRGBA(255, 182, 193, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA07A. - /// - public static readonly TColor LightSalmon = ColorBuilder.FromRGBA(255, 160, 122, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #20B2AA. - /// - public static readonly TColor LightSeaGreen = ColorBuilder.FromRGBA(32, 178, 170, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEFA. - /// - public static readonly TColor LightSkyBlue = ColorBuilder.FromRGBA(135, 206, 250, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #778899. - /// - public static readonly TColor LightSlateGray = ColorBuilder.FromRGBA(119, 136, 153, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #B0C4DE. - /// - public static readonly TColor LightSteelBlue = ColorBuilder.FromRGBA(176, 196, 222, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFE0. - /// - public static readonly TColor LightYellow = ColorBuilder.FromRGBA(255, 255, 224, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF00. - /// - public static readonly TColor Lime = ColorBuilder.FromRGBA(0, 255, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #32CD32. - /// - public static readonly TColor LimeGreen = ColorBuilder.FromRGBA(50, 205, 50, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FAF0E6. - /// - public static readonly TColor Linen = ColorBuilder.FromRGBA(250, 240, 230, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF00FF. - /// - public static readonly TColor Magenta = ColorBuilder.FromRGBA(255, 0, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #800000. - /// - public static readonly TColor Maroon = ColorBuilder.FromRGBA(128, 0, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #66CDAA. - /// - public static readonly TColor MediumAquamarine = ColorBuilder.FromRGBA(102, 205, 170, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #0000CD. - /// - public static readonly TColor MediumBlue = ColorBuilder.FromRGBA(0, 0, 205, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #BA55D3. - /// - public static readonly TColor MediumOrchid = ColorBuilder.FromRGBA(186, 85, 211, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #9370DB. - /// - public static readonly TColor MediumPurple = ColorBuilder.FromRGBA(147, 112, 219, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #3CB371. - /// - public static readonly TColor MediumSeaGreen = ColorBuilder.FromRGBA(60, 179, 113, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #7B68EE. - /// - public static readonly TColor MediumSlateBlue = ColorBuilder.FromRGBA(123, 104, 238, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #00FA9A. - /// - public static readonly TColor MediumSpringGreen = ColorBuilder.FromRGBA(0, 250, 154, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #48D1CC. - /// - public static readonly TColor MediumTurquoise = ColorBuilder.FromRGBA(72, 209, 204, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #C71585. - /// - public static readonly TColor MediumVioletRed = ColorBuilder.FromRGBA(199, 21, 133, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #191970. - /// - public static readonly TColor MidnightBlue = ColorBuilder.FromRGBA(25, 25, 112, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F5FFFA. - /// - public static readonly TColor MintCream = ColorBuilder.FromRGBA(245, 255, 250, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4E1. - /// - public static readonly TColor MistyRose = ColorBuilder.FromRGBA(255, 228, 225, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFE4B5. - /// - public static readonly TColor Moccasin = ColorBuilder.FromRGBA(255, 228, 181, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDEAD. - /// - public static readonly TColor NavajoWhite = ColorBuilder.FromRGBA(255, 222, 173, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #000080. - /// - public static readonly TColor Navy = ColorBuilder.FromRGBA(0, 0, 128, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FDF5E6. - /// - public static readonly TColor OldLace = ColorBuilder.FromRGBA(253, 245, 230, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #808000. - /// - public static readonly TColor Olive = ColorBuilder.FromRGBA(128, 128, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #6B8E23. - /// - public static readonly TColor OliveDrab = ColorBuilder.FromRGBA(107, 142, 35, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFA500. - /// - public static readonly TColor Orange = ColorBuilder.FromRGBA(255, 165, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF4500. - /// - public static readonly TColor OrangeRed = ColorBuilder.FromRGBA(255, 69, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #DA70D6. - /// - public static readonly TColor Orchid = ColorBuilder.FromRGBA(218, 112, 214, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #EEE8AA. - /// - public static readonly TColor PaleGoldenrod = ColorBuilder.FromRGBA(238, 232, 170, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #98FB98. - /// - public static readonly TColor PaleGreen = ColorBuilder.FromRGBA(152, 251, 152, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #AFEEEE. - /// - public static readonly TColor PaleTurquoise = ColorBuilder.FromRGBA(175, 238, 238, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #DB7093. - /// - public static readonly TColor PaleVioletRed = ColorBuilder.FromRGBA(219, 112, 147, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFEFD5. - /// - public static readonly TColor PapayaWhip = ColorBuilder.FromRGBA(255, 239, 213, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFDAB9. - /// - public static readonly TColor PeachPuff = ColorBuilder.FromRGBA(255, 218, 185, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #CD853F. - /// - public static readonly TColor Peru = ColorBuilder.FromRGBA(205, 133, 63, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFC0CB. - /// - public static readonly TColor Pink = ColorBuilder.FromRGBA(255, 192, 203, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #DDA0DD. - /// - public static readonly TColor Plum = ColorBuilder.FromRGBA(221, 160, 221, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #B0E0E6. - /// - public static readonly TColor PowderBlue = ColorBuilder.FromRGBA(176, 224, 230, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #800080. - /// - public static readonly TColor Purple = ColorBuilder.FromRGBA(128, 0, 128, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #663399. - /// - public static readonly TColor RebeccaPurple = ColorBuilder.FromRGBA(102, 51, 153, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF0000. - /// - public static readonly TColor Red = ColorBuilder.FromRGBA(255, 0, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #BC8F8F. - /// - public static readonly TColor RosyBrown = ColorBuilder.FromRGBA(188, 143, 143, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #4169E1. - /// - public static readonly TColor RoyalBlue = ColorBuilder.FromRGBA(65, 105, 225, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #8B4513. - /// - public static readonly TColor SaddleBrown = ColorBuilder.FromRGBA(139, 69, 19, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FA8072. - /// - public static readonly TColor Salmon = ColorBuilder.FromRGBA(250, 128, 114, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F4A460. - /// - public static readonly TColor SandyBrown = ColorBuilder.FromRGBA(244, 164, 96, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #2E8B57. - /// - public static readonly TColor SeaGreen = ColorBuilder.FromRGBA(46, 139, 87, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFF5EE. - /// - public static readonly TColor SeaShell = ColorBuilder.FromRGBA(255, 245, 238, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #A0522D. - /// - public static readonly TColor Sienna = ColorBuilder.FromRGBA(160, 82, 45, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #C0C0C0. - /// - public static readonly TColor Silver = ColorBuilder.FromRGBA(192, 192, 192, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #87CEEB. - /// - public static readonly TColor SkyBlue = ColorBuilder.FromRGBA(135, 206, 235, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #6A5ACD. - /// - public static readonly TColor SlateBlue = ColorBuilder.FromRGBA(106, 90, 205, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #708090. - /// - public static readonly TColor SlateGray = ColorBuilder.FromRGBA(112, 128, 144, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFAFA. - /// - public static readonly TColor Snow = ColorBuilder.FromRGBA(255, 250, 250, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #00FF7F. - /// - public static readonly TColor SpringGreen = ColorBuilder.FromRGBA(0, 255, 127, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #4682B4. - /// - public static readonly TColor SteelBlue = ColorBuilder.FromRGBA(70, 130, 180, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #D2B48C. - /// - public static readonly TColor Tan = ColorBuilder.FromRGBA(210, 180, 140, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #008080. - /// - public static readonly TColor Teal = ColorBuilder.FromRGBA(0, 128, 128, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #D8BFD8. - /// - public static readonly TColor Thistle = ColorBuilder.FromRGBA(216, 191, 216, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FF6347. - /// - public static readonly TColor Tomato = ColorBuilder.FromRGBA(255, 99, 71, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly TColor Transparent = ColorBuilder.FromRGBA(255, 255, 255, 0); - - /// - /// Represents a matching the W3C definition that has an hex value of #40E0D0. - /// - public static readonly TColor Turquoise = ColorBuilder.FromRGBA(64, 224, 208, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #EE82EE. - /// - public static readonly TColor Violet = ColorBuilder.FromRGBA(238, 130, 238, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F5DEB3. - /// - public static readonly TColor Wheat = ColorBuilder.FromRGBA(245, 222, 179, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFFFF. - /// - public static readonly TColor White = ColorBuilder.FromRGBA(255, 255, 255, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #F5F5F5. - /// - public static readonly TColor WhiteSmoke = ColorBuilder.FromRGBA(245, 245, 245, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #FFFF00. - /// - public static readonly TColor Yellow = ColorBuilder.FromRGBA(255, 255, 0, 255); - - /// - /// Represents a matching the W3C definition that has an hex value of #9ACD32. - /// - public static readonly TColor YellowGreen = ColorBuilder.FromRGBA(154, 205, 50, 255); - } -} \ No newline at end of file diff --git a/src/ImageSharp/Colors/Spaces/Bgra32.cs b/src/ImageSharp/Colors/Spaces/Bgra32.cs index cbd1d61194..b1f72033d3 100644 --- a/src/ImageSharp/Colors/Spaces/Bgra32.cs +++ b/src/ImageSharp/Colors/Spaces/Bgra32.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using ImageSharp.PixelFormats; /// /// Represents an BGRA (blue, green, red, alpha) color. @@ -79,16 +80,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator Bgra32(Color color) + public static implicit operator Bgra32(Rgba32 color) { return new Bgra32(color.B, color.G, color.R, color.A); } diff --git a/src/ImageSharp/Colors/Spaces/CieLab.cs b/src/ImageSharp/Colors/Spaces/CieLab.cs index 921158174c..c1e5cba5a0 100644 --- a/src/ImageSharp/Colors/Spaces/CieLab.cs +++ b/src/ImageSharp/Colors/Spaces/CieLab.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using ImageSharp.PixelFormats; /// /// Represents an CIE LAB 1976 color. @@ -72,16 +73,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator CieLab(Color color) + public static implicit operator CieLab(Rgba32 color) { // First convert to CIE XYZ Vector4 vector = color.ToVector4().Expand(); diff --git a/src/ImageSharp/Colors/Spaces/CieXyz.cs b/src/ImageSharp/Colors/Spaces/CieXyz.cs index 5bd1eac634..9c6c9bf60f 100644 --- a/src/ImageSharp/Colors/Spaces/CieXyz.cs +++ b/src/ImageSharp/Colors/Spaces/CieXyz.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using ImageSharp.PixelFormats; /// /// Represents an CIE 1931 color @@ -63,16 +64,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator CieXyz(Color color) + public static implicit operator CieXyz(Rgba32 color) { Vector4 vector = color.ToVector4().Expand(); diff --git a/src/ImageSharp/Colors/Spaces/Cmyk.cs b/src/ImageSharp/Colors/Spaces/Cmyk.cs index c81a55c0bb..4ca9f018c6 100644 --- a/src/ImageSharp/Colors/Spaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Spaces/Cmyk.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using ImageSharp.PixelFormats; /// /// Represents an CMYK (cyan, magenta, yellow, keyline) color. @@ -78,7 +79,7 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// @@ -87,7 +88,7 @@ namespace ImageSharp.Colors.Spaces /// /// An instance of . /// - public static implicit operator Cmyk(Color color) + public static implicit operator Cmyk(Rgba32 color) { float c = 1f - (color.R / 255F); float m = 1f - (color.G / 255F); diff --git a/src/ImageSharp/Colors/Spaces/Hsl.cs b/src/ImageSharp/Colors/Spaces/Hsl.cs index 1d655ec326..de706c3506 100644 --- a/src/ImageSharp/Colors/Spaces/Hsl.cs +++ b/src/ImageSharp/Colors/Spaces/Hsl.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using ImageSharp.PixelFormats; /// /// Represents a Hsl (hue, saturation, lightness) color. @@ -70,14 +71,14 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Hsl(Color color) + public static implicit operator Hsl(Rgba32 color) { float r = color.R / 255F; float g = color.G / 255F; diff --git a/src/ImageSharp/Colors/Spaces/Hsv.cs b/src/ImageSharp/Colors/Spaces/Hsv.cs index e171c95282..2b3d79afe9 100644 --- a/src/ImageSharp/Colors/Spaces/Hsv.cs +++ b/src/ImageSharp/Colors/Spaces/Hsv.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using ImageSharp.PixelFormats; /// /// Represents a HSV (hue, saturation, value) color. Also known as HSB (hue, saturation, brightness). @@ -70,14 +71,14 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Hsv(Color color) + public static implicit operator Hsv(Rgba32 color) { float r = color.R / 255F; float g = color.G / 255F; diff --git a/src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs b/src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs index a2183d396c..04ea91cbad 100644 --- a/src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs +++ b/src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs @@ -11,9 +11,9 @@ namespace ImageSharp.Colors.Spaces /// Defines a generalized method that a value type or class implements to create /// a type-specific method for determining approximate equality of instances. /// - /// The type of objects to compare. + /// The type of objects to compare. /// The object specifying the type to specify precision with. - public interface IAlmostEquatable + public interface IAlmostEquatable where TPrecision : struct, IComparable { /// @@ -25,6 +25,6 @@ namespace ImageSharp.Colors.Spaces /// /// true if the current object is equal to the other parameter; otherwise, false. /// - bool AlmostEquals(TColor other, TPrecision precision); + bool AlmostEquals(TPixel other, TPrecision precision); } } diff --git a/src/ImageSharp/Colors/Spaces/YCbCr.cs b/src/ImageSharp/Colors/Spaces/YCbCr.cs index ef9f4462b1..06696af9ea 100644 --- a/src/ImageSharp/Colors/Spaces/YCbCr.cs +++ b/src/ImageSharp/Colors/Spaces/YCbCr.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using ImageSharp.PixelFormats; /// /// Represents an YCbCr (luminance, blue chroma, red chroma) color conforming to the full range standard used in digital imaging systems. @@ -72,16 +73,16 @@ namespace ImageSharp.Colors.Spaces public bool IsEmpty => this.Equals(Empty); /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// /// - /// The instance of to convert. + /// The instance of to convert. /// /// /// An instance of . /// - public static implicit operator YCbCr(Color color) + public static implicit operator YCbCr(Rgba32 color) { byte r = color.R; byte g = color.G; diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs index 9f3aa405ed..31f3f32ae7 100644 --- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -8,6 +8,7 @@ namespace ImageSharp using System; using System.Numerics; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; /// /// Extension methods for the struct. @@ -32,7 +33,7 @@ namespace ImageSharp /// /// /// - /// The whose signal to expand. + /// The whose signal to expand. /// The . public static Vector4 Expand(this Vector4 gamma) { diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs index 1be7bd6197..cf0ac5c297 100644 --- a/src/ImageSharp/Common/Helpers/ImageMaths.cs +++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs @@ -10,6 +10,8 @@ namespace ImageSharp using System.Numerics; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; + /// /// Provides common mathematical methods. /// @@ -156,22 +158,22 @@ namespace ImageSharp /// Finds the bounding rectangle based on the first instance of any color component other /// than the given one. /// - /// The pixel format. + /// The pixel format. /// 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) - where TColor : struct, IPixel + public static Rectangle GetFilteredBoundingRectangle(ImageBase bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) + where TPixel : struct, IPixel { int width = bitmap.Width; int height = bitmap.Height; Point topLeft = default(Point); Point bottomRight = default(Point); - Func, int, int, float, bool> delegateFunc; + Func, int, int, float, bool> delegateFunc; // Determine which channel to check against switch (channel) @@ -193,7 +195,7 @@ namespace ImageSharp break; } - Func, int> getMinY = pixels => + Func, int> getMinY = pixels => { for (int y = 0; y < height; y++) { @@ -209,7 +211,7 @@ namespace ImageSharp return 0; }; - Func, int> getMaxY = pixels => + Func, int> getMaxY = pixels => { for (int y = height - 1; y > -1; y--) { @@ -225,7 +227,7 @@ namespace ImageSharp return height; }; - Func, int> getMinX = pixels => + Func, int> getMinX = pixels => { for (int x = 0; x < width; x++) { @@ -241,7 +243,7 @@ namespace ImageSharp return 0; }; - Func, int> getMaxX = pixels => + Func, int> getMaxX = pixels => { for (int x = width - 1; x > -1; x--) { @@ -257,7 +259,7 @@ namespace ImageSharp return height; }; - using (PixelAccessor bitmapPixels = bitmap.Lock()) + using (PixelAccessor bitmapPixels = bitmap.Lock()) { topLeft.Y = getMinY(bitmapPixels); topLeft.X = getMinX(bitmapPixels); diff --git a/src/ImageSharp/Common/Memory/PixelDataPool{T}.cs b/src/ImageSharp/Common/Memory/PixelDataPool{T}.cs index f5c7871409..0ec367d246 100644 --- a/src/ImageSharp/Common/Memory/PixelDataPool{T}.cs +++ b/src/ImageSharp/Common/Memory/PixelDataPool{T}.cs @@ -8,6 +8,8 @@ namespace ImageSharp using System; using System.Buffers; + using ImageSharp.PixelFormats; + /// /// Provides a resource pool that enables reusing instances of value type arrays for image data . /// @@ -24,7 +26,7 @@ namespace ImageSharp /// Rents the pixel array from the pool. /// /// The minimum length of the array to return. - /// The + /// The public static T[] Rent(int minimumLength) { return ArrayPool.Rent(minimumLength); diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs index d6ab8eb64a..5d0ecde6ba 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Dithering using System.Numerics; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; + /// /// The base class for performing error diffusion based dithering. /// @@ -68,16 +70,16 @@ namespace ImageSharp.Dithering /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dither(PixelAccessor pixels, TColor source, TColor transformed, int x, int y, int width, int height) - where TColor : struct, IPixel + public void Dither(PixelAccessor pixels, TPixel source, TPixel transformed, int x, int y, int width, int height) + where TPixel : struct, IPixel { this.Dither(pixels, source, transformed, x, y, width, height, true); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dither(PixelAccessor pixels, TColor source, TColor transformed, int x, int y, int width, int height, bool replacePixel) - where TColor : struct, IPixel + public void Dither(PixelAccessor pixels, TPixel source, TPixel transformed, int x, int y, int width, int height, bool replacePixel) + where TPixel : struct, IPixel { if (replacePixel) { @@ -113,7 +115,7 @@ namespace ImageSharp.Dithering Vector4 result = ((error * coefficientVector) / this.divisorVector) + offsetColor; result.W = offsetColor.W; - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(result); pixels[matrixX, matrixY] = packed; } diff --git a/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs b/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs index 66ec3d5155..f49e7e62d2 100644 --- a/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs +++ b/src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs @@ -5,7 +5,7 @@ namespace ImageSharp.Dithering { - using System; + using ImageSharp.PixelFormats; /// /// Encapsulates properties and methods required to perfom diffused error dithering on an image. @@ -22,9 +22,9 @@ namespace ImageSharp.Dithering /// The row index. /// The image width. /// The image height. - /// The pixel format. - void Dither(PixelAccessor pixels, TColor source, TColor transformed, int x, int y, int width, int height) - where TColor : struct, IPixel; + /// The pixel format. + void Dither(PixelAccessor pixels, TPixel source, TPixel transformed, int x, int y, int width, int height) + where TPixel : struct, IPixel; /// /// Transforms the image applying the dither matrix. This method alters the input pixels array @@ -40,8 +40,8 @@ namespace ImageSharp.Dithering /// Whether to replace the pixel at the given coordinates with the transformed value. /// Generally this would be true for standard two-color dithering but when used in conjunction with color quantization this should be false. /// - /// The pixel format. - void Dither(PixelAccessor pixels, TColor source, TColor transformed, int x, int y, int width, int height, bool replacePixel) - where TColor : struct, IPixel; + /// The pixel format. + void Dither(PixelAccessor pixels, TPixel source, TPixel transformed, int x, int y, int width, int height, bool replacePixel) + where TPixel : struct, IPixel; } } diff --git a/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs b/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs index 5c98973747..3f7cf49885 100644 --- a/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs +++ b/src/ImageSharp/Dithering/Ordered/IOrderedDither.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering { + using ImageSharp.PixelFormats; + /// /// Encapsulates properties and methods required to perfom ordered dithering on an image. /// @@ -23,8 +25,8 @@ namespace ImageSharp.Dithering /// The row index. /// The image width. /// The image height. - /// The pixel format. - void Dither(PixelAccessor pixels, TColor source, TColor upper, TColor lower, byte[] bytes, int index, int x, int y, int width, int height) - where TColor : struct, IPixel; + /// The pixel format. + void Dither(PixelAccessor pixels, TPixel source, TPixel upper, TPixel lower, byte[] bytes, int index, int x, int y, int width, int height) + where TPixel : struct, IPixel; } } \ No newline at end of file diff --git a/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs b/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs index c2b55d98eb..917f573182 100644 --- a/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs +++ b/src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Dithering.Ordered { + using ImageSharp.PixelFormats; + /// /// The base class for performing ordered ditheroing using a 4x4 matrix. /// @@ -25,8 +27,8 @@ namespace ImageSharp.Dithering.Ordered } /// - public void Dither(PixelAccessor pixels, TColor source, TColor upper, TColor lower, byte[] bytes, int index, int x, int y, int width, int height) - where TColor : struct, IPixel + public void Dither(PixelAccessor pixels, TPixel source, TPixel upper, TPixel lower, byte[] bytes, int index, int x, int y, int width, int height) + where TPixel : struct, IPixel { // TODO: This doesn't really cut it for me. // I'd rather be using float but we need to add some sort of movalization vector methods to all IPixel implementations diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs index da5d246372..9090e9a8cd 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Image decoder for generating an image out of a Windows bitmap stream. /// @@ -26,13 +28,13 @@ namespace ImageSharp.Formats public class BmpDecoder : IImageDecoder { /// - public Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) + public Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) - where TColor : struct, IPixel + where TPixel : struct, IPixel { Guard.NotNull(stream, "stream"); - return new BmpDecoderCore(configuration).Decode(stream); + return new BmpDecoderCore(configuration).Decode(stream); } } } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 18e4e858b8..a9aac5efa7 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Performs the bmp decoding operation. /// @@ -58,15 +60,15 @@ namespace ImageSharp.Formats /// Decodes the image from the specified this._stream and sets /// the data to image. /// - /// The pixel format. + /// The pixel format. /// The stream, where the image should be /// decoded from. Cannot be null (Nothing in Visual Basic). /// /// is null. /// /// The decoded image. - public Image Decode(Stream stream) - where TColor : struct, IPixel + public Image Decode(Stream stream) + where TPixel : struct, IPixel { this.currentStream = stream; @@ -118,15 +120,15 @@ namespace ImageSharp.Formats this.currentStream.Read(palette, 0, colorMapSize); } - if (this.infoHeader.Width > Image.MaxWidth || this.infoHeader.Height > Image.MaxHeight) + if (this.infoHeader.Width > Image.MaxWidth || this.infoHeader.Height > Image.MaxHeight) { throw new ArgumentOutOfRangeException( $"The input bitmap '{this.infoHeader.Width}x{this.infoHeader.Height}' is " - + $"bigger then the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'"); + + $"bigger then the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'"); } - Image image = Image.Create(this.infoHeader.Width, this.infoHeader.Height, this.configuration); - using (PixelAccessor pixels = image.Lock()) + Image image = Image.Create(this.infoHeader.Width, this.infoHeader.Height, this.configuration); + using (PixelAccessor pixels = image.Lock()) { switch (this.infoHeader.Compression) { @@ -213,15 +215,15 @@ namespace ImageSharp.Formats /// /// Reads the color palette from the stream. /// - /// The pixel format. - /// The to assign the palette to. + /// The pixel format. + /// The to assign the palette to. /// The containing the colors. /// The width of the bitmap. /// The height of the bitmap. /// The number of bits per pixel. /// Whether the bitmap is inverted. - private void ReadRgbPalette(PixelAccessor pixels, byte[] colors, int width, int height, int bits, bool inverted) - where TColor : struct, IPixel + private void ReadRgbPalette(PixelAccessor pixels, byte[] colors, int width, int height, int bits, bool inverted) + where TPixel : struct, IPixel { // Pixels per byte (bits per pixel) int ppb = 8 / bits; @@ -239,7 +241,7 @@ namespace ImageSharp.Formats } byte[] row = new byte[arrayWidth + padding]; - TColor color = default(TColor); + TPixel color = default(TPixel); for (int y = 0; y < height; y++) { @@ -270,21 +272,21 @@ namespace ImageSharp.Formats /// /// Reads the 16 bit color palette from the stream /// - /// The pixel format. - /// The to assign the palette to. + /// The pixel format. + /// The to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb16(PixelAccessor pixels, int width, int height, bool inverted) - where TColor : struct, IPixel + private void ReadRgb16(PixelAccessor pixels, int width, int height, bool inverted) + where TPixel : struct, IPixel { // We divide here as we will store the colors in our floating point format. const int ScaleR = 8; // 256/32 const int ScaleG = 4; // 256/64 const int ComponentCount = 2; - TColor color = default(TColor); - using (PixelArea row = new PixelArea(width, ComponentOrder.Xyz)) + TPixel color = default(TPixel); + using (PixelArea row = new PixelArea(width, ComponentOrder.Xyz)) { for (int y = 0; y < height; y++) { @@ -312,16 +314,16 @@ namespace ImageSharp.Formats /// /// Reads the 24 bit color palette from the stream /// - /// The pixel format. - /// The to assign the palette to. + /// The pixel format. + /// The to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb24(PixelAccessor pixels, int width, int height, bool inverted) - where TColor : struct, IPixel + private void ReadRgb24(PixelAccessor pixels, int width, int height, bool inverted) + where TPixel : struct, IPixel { int padding = CalculatePadding(width, 3); - using (PixelArea row = new PixelArea(width, ComponentOrder.Zyx, padding)) + using (PixelArea row = new PixelArea(width, ComponentOrder.Zyx, padding)) { for (int y = 0; y < height; y++) { @@ -336,16 +338,16 @@ namespace ImageSharp.Formats /// /// Reads the 32 bit color palette from the stream /// - /// The pixel format. - /// The to assign the palette to. + /// The pixel format. + /// The to assign the palette to. /// The width of the bitmap. /// The height of the bitmap. /// Whether the bitmap is inverted. - private void ReadRgb32(PixelAccessor pixels, int width, int height, bool inverted) - where TColor : struct, IPixel + private void ReadRgb32(PixelAccessor pixels, int width, int height, bool inverted) + where TPixel : struct, IPixel { int padding = CalculatePadding(width, 4); - using (PixelArea row = new PixelArea(width, ComponentOrder.Zyxw, padding)) + using (PixelArea row = new PixelArea(width, ComponentOrder.Zyxw, padding)) { for (int y = 0; y < height; y++) { diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs index d0a3550f6f..dc2bc0e972 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoder.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Image encoder for writing an image to a stream as a Windows bitmap. /// @@ -15,8 +17,8 @@ namespace ImageSharp.Formats public class BmpEncoder : IImageEncoder { /// - public void Encode(Image image, Stream stream, IEncoderOptions options) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IEncoderOptions options) + where TPixel : struct, IPixel { IBmpEncoderOptions bmpOptions = BmpEncoderOptions.Create(options); @@ -24,14 +26,14 @@ namespace ImageSharp.Formats } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The to encode from. + /// The pixel format. + /// The to encode from. /// The to encode the image data to. /// The options for the encoder. - public void Encode(Image image, Stream stream, IBmpEncoderOptions options) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IBmpEncoderOptions options) + where TPixel : struct, IPixel { BmpEncoderCore encoder = new BmpEncoderCore(options); encoder.Encode(image, stream); diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index df62fb6f40..617edde8eb 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + using IO; /// @@ -35,13 +37,13 @@ namespace ImageSharp.Formats } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The to encode from. + /// The pixel format. + /// The to encode from. /// The to encode the image data to. - public void Encode(ImageBase image, Stream stream) - where TColor : struct, IPixel + public void Encode(ImageBase image, Stream stream) + where TPixel : struct, IPixel { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -124,15 +126,15 @@ namespace ImageSharp.Formats /// /// Writes the pixel data to the binary stream. /// - /// The pixel format. + /// The pixel format. /// The containing the stream to write to. /// - /// The containing pixel data. + /// The containing pixel data. /// - private void WriteImage(EndianBinaryWriter writer, ImageBase image) - where TColor : struct, IPixel + private void WriteImage(EndianBinaryWriter writer, ImageBase image) + where TPixel : struct, IPixel { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { switch (this.options.BitsPerPixel) { @@ -150,13 +152,13 @@ namespace ImageSharp.Formats /// /// Writes the 32bit color palette to the stream. /// - /// The pixel format. + /// The pixel format. /// The containing the stream to write to. - /// The containing pixel data. - private void Write32Bit(EndianBinaryWriter writer, PixelAccessor pixels) - where TColor : struct, IPixel + /// The containing pixel data. + private void Write32Bit(EndianBinaryWriter writer, PixelAccessor pixels) + where TPixel : struct, IPixel { - using (PixelArea row = new PixelArea(pixels.Width, ComponentOrder.Zyxw, this.padding)) + using (PixelArea row = new PixelArea(pixels.Width, ComponentOrder.Zyxw, this.padding)) { for (int y = pixels.Height - 1; y >= 0; y--) { @@ -169,13 +171,13 @@ namespace ImageSharp.Formats /// /// Writes the 24bit color palette to the stream. /// - /// The pixel format. + /// The pixel format. /// The containing the stream to write to. - /// The containing pixel data. - private void Write24Bit(EndianBinaryWriter writer, PixelAccessor pixels) - where TColor : struct, IPixel + /// The containing pixel data. + private void Write24Bit(EndianBinaryWriter writer, PixelAccessor pixels) + where TPixel : struct, IPixel { - using (PixelArea row = new PixelArea(pixels.Width, ComponentOrder.Zyx, this.padding)) + using (PixelArea row = new PixelArea(pixels.Width, ComponentOrder.Zyx, this.padding)) { for (int y = pixels.Height - 1; y >= 0; y--) { diff --git a/src/ImageSharp/Formats/Bmp/ImageExtensions.cs b/src/ImageSharp/Formats/Bmp/ImageExtensions.cs index 5b92b90d63..aba24f9997 100644 --- a/src/ImageSharp/Formats/Bmp/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Bmp/ImageExtensions.cs @@ -10,23 +10,25 @@ namespace ImageSharp using Formats; + using ImageSharp.PixelFormats; + /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Saves the image to the given stream with the bmp format. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsBmp(this Image source, Stream stream) - where TColor : struct, IPixel + public static Image SaveAsBmp(this Image source, Stream stream) + where TPixel : struct, IPixel => source.Save(stream, new BmpEncoder()); } } diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs index 2eb89de8ff..88aaccf6a4 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoder.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs @@ -8,33 +8,35 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Decoder for generating an image out of a gif encoded stream. /// public class GifDecoder : IImageDecoder { /// - public Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) + public Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) - where TColor : struct, IPixel + where TPixel : struct, IPixel { IGifDecoderOptions gifOptions = GifDecoderOptions.Create(options); - return this.Decode(configuration, stream, gifOptions); + return this.Decode(configuration, stream, gifOptions); } /// - /// Decodes the image from the specified stream to the . + /// Decodes the image from the specified stream to the . /// - /// The pixel format. + /// The pixel format. /// The configuration. /// The containing image data. /// The options for the decoder. /// The image thats been decoded. - public Image Decode(Configuration configuration, Stream stream, IGifDecoderOptions options) - where TColor : struct, IPixel + public Image Decode(Configuration configuration, Stream stream, IGifDecoderOptions options) + where TPixel : struct, IPixel { - return new GifDecoderCore(options, configuration).Decode(stream); + return new GifDecoderCore(options, configuration).Decode(stream); } } } diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 4c119ca737..93d0bcaf18 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -10,12 +10,14 @@ namespace ImageSharp.Formats using System.IO; using System.Text; + using ImageSharp.PixelFormats; + /// /// Performs the gif decoding operation. /// - /// The pixel format. - internal class GifDecoderCore - where TColor : struct, IPixel + /// The pixel format. + internal class GifDecoderCore + where TPixel : struct, IPixel { /// /// The temp buffer used to reduce allocations. @@ -50,7 +52,7 @@ namespace ImageSharp.Formats /// /// The previous frame. /// - private ImageFrame previousFrame; + private ImageFrame previousFrame; /// /// The area to restore. @@ -75,10 +77,10 @@ namespace ImageSharp.Formats /// /// The image to decode the information to. /// - private Image image; + private Image image; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The decoder options. /// The configuration. @@ -93,7 +95,7 @@ namespace ImageSharp.Formats /// /// The stream containing image data. /// The decoded image - public Image Decode(Stream stream) + public Image Decode(Stream stream) { try { @@ -227,10 +229,10 @@ namespace ImageSharp.Formats } /* // No point doing this as the max width/height is always int.Max and that always bigger than the max size of a gif which is stored in a short. - if (this.logicalScreenDescriptor.Width > Image.MaxWidth || this.logicalScreenDescriptor.Height > Image.MaxHeight) + if (this.logicalScreenDescriptor.Width > Image.MaxWidth || this.logicalScreenDescriptor.Height > Image.MaxHeight) { throw new ArgumentOutOfRangeException( - $"The input gif '{this.logicalScreenDescriptor.Width}x{this.logicalScreenDescriptor.Height}' is bigger then the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'"); + $"The input gif '{this.logicalScreenDescriptor.Width}x{this.logicalScreenDescriptor.Height}' is bigger then the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'"); } */ } @@ -351,18 +353,18 @@ namespace ImageSharp.Formats int imageWidth = this.logicalScreenDescriptor.Width; int imageHeight = this.logicalScreenDescriptor.Height; - ImageFrame previousFrame = null; + ImageFrame previousFrame = null; - ImageFrame currentFrame = null; + ImageFrame currentFrame = null; - ImageBase image; + ImageBase image; if (this.previousFrame == null) { this.metaData.Quality = colorTableLength / 3; // This initializes the image to become fully transparent because the alpha channel is zero. - this.image = Image.Create(imageWidth, imageHeight, this.metaData, this.configuration); + this.image = Image.Create(imageWidth, imageHeight, this.metaData, this.configuration); this.SetFrameDelay(this.metaData); @@ -392,7 +394,7 @@ namespace ImageSharp.Formats int interlaceIncrement = 8; // The interlacing line increment int interlaceY = 0; // The current interlaced line - using (PixelAccessor pixelAccessor = image.Lock()) + using (PixelAccessor pixelAccessor = image.Lock()) { for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++) { @@ -441,7 +443,7 @@ namespace ImageSharp.Formats { int indexOffset = index * 3; - TColor pixel = default(TColor); + TPixel pixel = default(TPixel); pixel.PackFromBytes(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2], 255); pixelAccessor[x, writeY] = pixel; } @@ -470,7 +472,7 @@ namespace ImageSharp.Formats /// Restores the current frame area to the background. /// /// The frame. - private void RestoreToBackground(ImageBase frame) + private void RestoreToBackground(ImageBase frame) { if (this.restoreArea == null) { @@ -481,16 +483,16 @@ namespace ImageSharp.Formats if (this.restoreArea.Value.Width == this.image.Width && this.restoreArea.Value.Height == this.image.Height) { - using (PixelAccessor pixelAccessor = frame.Lock()) + using (PixelAccessor pixelAccessor = frame.Lock()) { pixelAccessor.Reset(); } } else { - using (PixelArea emptyRow = new PixelArea(this.restoreArea.Value.Width, ComponentOrder.Xyzw)) + using (PixelArea emptyRow = new PixelArea(this.restoreArea.Value.Width, ComponentOrder.Xyzw)) { - using (PixelAccessor pixelAccessor = frame.Lock()) + using (PixelAccessor pixelAccessor = frame.Lock()) { for (int y = this.restoreArea.Value.Top; y < this.restoreArea.Value.Top + this.restoreArea.Value.Height; y++) { diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index cc8516ed9d..b5cadd834e 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Image encoder for writing image data to a stream in gif format. /// public class GifEncoder : IImageEncoder { /// - public void Encode(Image image, Stream stream, IEncoderOptions options) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IEncoderOptions options) + where TPixel : struct, IPixel { IGifEncoderOptions gifOptions = GifEncoderOptions.Create(options); @@ -23,14 +25,14 @@ namespace ImageSharp.Formats } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The to encode from. + /// The pixel format. + /// The to encode from. /// The to encode the image data to. /// The options for the encoder. - public void Encode(Image image, Stream stream, IGifEncoderOptions options) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IGifEncoderOptions options) + where TPixel : struct, IPixel { GifEncoderCore encoder = new GifEncoderCore(options); encoder.Encode(image, stream); diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 38cbba8500..82f32323e8 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -10,6 +10,8 @@ namespace ImageSharp.Formats using System.IO; using System.Linq; + using ImageSharp.PixelFormats; + using IO; using Quantizers; @@ -48,18 +50,18 @@ namespace ImageSharp.Formats public IQuantizer Quantizer { get; set; } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The to encode from. + /// The pixel format. + /// The to encode from. /// The to encode the image data to. - public void Encode(Image image, Stream stream) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream) + where TPixel : struct, IPixel { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); - this.Quantizer = this.options.Quantizer ?? new OctreeQuantizer(); + this.Quantizer = this.options.Quantizer ?? new OctreeQuantizer(); // Do not use IDisposable pattern here as we want to preserve the stream. EndianBinaryWriter writer = new EndianBinaryWriter(Endianness.LittleEndian, stream); @@ -72,7 +74,7 @@ namespace ImageSharp.Formats this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quality); // Quantize the image returning a palette. - QuantizedImage quantized = ((IQuantizer)this.Quantizer).Quantize(image, quality); + QuantizedImage quantized = ((IQuantizer)this.Quantizer).Quantize(image, quality); int index = this.GetTransparentIndex(quantized); @@ -97,8 +99,8 @@ namespace ImageSharp.Formats // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < image.Frames.Count; i++) { - ImageFrame frame = image.Frames[i]; - QuantizedImage quantizedFrame = ((IQuantizer)this.Quantizer).Quantize(frame, quality); + ImageFrame frame = image.Frames[i]; + QuantizedImage quantizedFrame = ((IQuantizer)this.Quantizer).Quantize(frame, quality); this.WriteGraphicalControlExtension(frame, writer, this.GetTransparentIndex(quantizedFrame)); this.WriteImageDescriptor(frame, writer); @@ -117,12 +119,12 @@ namespace ImageSharp.Formats /// /// The quantized. /// - /// The pixel format. + /// The pixel format. /// /// The . /// - private int GetTransparentIndex(QuantizedImage quantized) - where TColor : struct, IPixel + private int GetTransparentIndex(QuantizedImage quantized) + where TPixel : struct, IPixel { // Find the lowest alpha value and make it the transparent index. int index = 255; @@ -167,12 +169,12 @@ namespace ImageSharp.Formats /// /// Writes the logical screen descriptor to the stream. /// - /// The pixel format. + /// The pixel format. /// The image to encode. /// The writer to write to the stream with. /// The transparency index to set the default background index to. - private void WriteLogicalScreenDescriptor(Image image, EndianBinaryWriter writer, int tranparencyIndex) - where TColor : struct, IPixel + private void WriteLogicalScreenDescriptor(Image image, EndianBinaryWriter writer, int tranparencyIndex) + where TPixel : struct, IPixel { GifLogicalScreenDescriptor descriptor = new GifLogicalScreenDescriptor { @@ -233,11 +235,11 @@ namespace ImageSharp.Formats /// /// Writes the image comments to the stream. /// - /// The pixel format. - /// The to be encoded. + /// The pixel format. + /// The to be encoded. /// The stream to write to. - private void WriteComments(Image image, EndianBinaryWriter writer) - where TColor : struct, IPixel + private void WriteComments(Image image, EndianBinaryWriter writer) + where TPixel : struct, IPixel { if (this.options.IgnoreMetadata == true) { @@ -266,12 +268,12 @@ namespace ImageSharp.Formats /// /// Writes the graphics control extension to the stream. /// - /// The pixel format. - /// The to encode. + /// The pixel format. + /// The to encode. /// The stream to write to. /// The index of the color in the color palette to make transparent. - private void WriteGraphicalControlExtension(Image image, EndianBinaryWriter writer, int transparencyIndex) - where TColor : struct, IPixel + private void WriteGraphicalControlExtension(Image image, EndianBinaryWriter writer, int transparencyIndex) + where TPixel : struct, IPixel { this.WriteGraphicalControlExtension(image, image.MetaData, writer, transparencyIndex); } @@ -279,12 +281,12 @@ namespace ImageSharp.Formats /// /// Writes the graphics control extension to the stream. /// - /// The pixel format. - /// The to encode. + /// The pixel format. + /// The to encode. /// The stream to write to. /// The index of the color in the color palette to make transparent. - private void WriteGraphicalControlExtension(ImageFrame imageFrame, EndianBinaryWriter writer, int transparencyIndex) - where TColor : struct, IPixel + private void WriteGraphicalControlExtension(ImageFrame imageFrame, EndianBinaryWriter writer, int transparencyIndex) + where TPixel : struct, IPixel { this.WriteGraphicalControlExtension(imageFrame, imageFrame.MetaData, writer, transparencyIndex); } @@ -292,13 +294,13 @@ namespace ImageSharp.Formats /// /// Writes the graphics control extension to the stream. /// - /// The pixel format. - /// The to encode. + /// The pixel format. + /// The to encode. /// The metadata of the image or frame. /// The stream to write to. /// The index of the color in the color palette to make transparent. - private void WriteGraphicalControlExtension(ImageBase image, IMetaData metaData, EndianBinaryWriter writer, int transparencyIndex) - where TColor : struct, IPixel + private void WriteGraphicalControlExtension(ImageBase image, IMetaData metaData, EndianBinaryWriter writer, int transparencyIndex) + where TPixel : struct, IPixel { // TODO: Check transparency logic. bool hasTransparent = transparencyIndex < 255; @@ -336,11 +338,11 @@ namespace ImageSharp.Formats /// /// Writes the image descriptor to the stream. /// - /// The pixel format. - /// The to be encoded. + /// The pixel format. + /// The to be encoded. /// The stream to write to. - private void WriteImageDescriptor(ImageBase image, EndianBinaryWriter writer) - where TColor : struct, IPixel + private void WriteImageDescriptor(ImageBase image, EndianBinaryWriter writer) + where TPixel : struct, IPixel { writer.Write(GifConstants.ImageDescriptorLabel); // 2c @@ -362,11 +364,11 @@ namespace ImageSharp.Formats /// /// Writes the color table to the stream. /// - /// The pixel format. - /// The to encode. + /// The pixel format. + /// The to encode. /// The writer to write to the stream with. - private void WriteColorTable(QuantizedImage image, EndianBinaryWriter writer) - where TColor : struct, IPixel + private void WriteColorTable(QuantizedImage image, EndianBinaryWriter writer) + where TPixel : struct, IPixel { // Grab the palette and write it to the stream. int pixelCount = image.Palette.Length; @@ -397,11 +399,11 @@ namespace ImageSharp.Formats /// /// Writes the image pixel data to the stream. /// - /// The pixel format. - /// The containing indexed pixels. + /// The pixel format. + /// The containing indexed pixels. /// The stream to write to. - private void WriteImageData(QuantizedImage image, EndianBinaryWriter writer) - where TColor : struct, IPixel + private void WriteImageData(QuantizedImage image, EndianBinaryWriter writer) + where TPixel : struct, IPixel { using (LzwEncoder encoder = new LzwEncoder(image.Pixels, (byte)this.bitDepth)) { diff --git a/src/ImageSharp/Formats/Gif/ImageExtensions.cs b/src/ImageSharp/Formats/Gif/ImageExtensions.cs index 1ba03ed351..d64203f6ce 100644 --- a/src/ImageSharp/Formats/Gif/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Gif/ImageExtensions.cs @@ -10,23 +10,25 @@ namespace ImageSharp using Formats; + using ImageSharp.PixelFormats; + /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Saves the image to the given stream with the gif format. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsGif(this Image source, Stream stream) - where TColor : struct, IPixel + public static Image SaveAsGif(this Image source, Stream stream) + where TPixel : struct, IPixel { return SaveAsGif(source, stream, null); } @@ -34,16 +36,16 @@ namespace ImageSharp /// /// Saves the image to the given stream with the gif format. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsGif(this Image source, Stream stream, IGifEncoderOptions options) - where TColor : struct, IPixel + public static Image SaveAsGif(this Image source, Stream stream, IGifEncoderOptions options) + where TPixel : struct, IPixel { GifEncoder encoder = new GifEncoder(); encoder.Encode(source, stream, options); diff --git a/src/ImageSharp/Formats/IImageDecoder.cs b/src/ImageSharp/Formats/IImageDecoder.cs index c85fbef101..4fd25df13e 100644 --- a/src/ImageSharp/Formats/IImageDecoder.cs +++ b/src/ImageSharp/Formats/IImageDecoder.cs @@ -8,20 +8,22 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Encapsulates properties and methods required for decoding an image from a stream. /// public interface IImageDecoder { /// - /// Decodes the image from the specified stream to the . + /// Decodes the image from the specified stream to the . /// - /// The pixel format. + /// The pixel format. /// The configuration for the image. /// The containing image data. /// The options for the decoder. /// The decoded image - Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) - where TColor : struct, IPixel; + Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) + where TPixel : struct, IPixel; } } diff --git a/src/ImageSharp/Formats/IImageEncoder.cs b/src/ImageSharp/Formats/IImageEncoder.cs index 918f0d273c..a28511c173 100644 --- a/src/ImageSharp/Formats/IImageEncoder.cs +++ b/src/ImageSharp/Formats/IImageEncoder.cs @@ -8,19 +8,21 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Encapsulates properties and methods required for encoding an image to a stream. /// public interface IImageEncoder { /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The to encode from. + /// The pixel format. + /// The to encode from. /// The to encode the image data to. /// The options for the encoder. - void Encode(Image image, Stream stream, IEncoderOptions options) - where TColor : struct, IPixel; + void Encode(Image image, Stream stream, IEncoderOptions options) + where TPixel : struct, IPixel; } } diff --git a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs index 351275ebb7..420af6b742 100644 --- a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs @@ -10,23 +10,25 @@ namespace ImageSharp using Formats; + using ImageSharp.PixelFormats; + /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Saves the image to the given stream with the jpeg format. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsJpeg(this Image source, Stream stream) - where TColor : struct, IPixel + public static Image SaveAsJpeg(this Image source, Stream stream) + where TPixel : struct, IPixel { return SaveAsJpeg(source, stream, null); } @@ -34,16 +36,16 @@ namespace ImageSharp /// /// Saves the image to the given stream with the jpeg format. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsJpeg(this Image source, Stream stream, IJpegEncoderOptions options) - where TColor : struct, IPixel + public static Image SaveAsJpeg(this Image source, Stream stream, IJpegEncoderOptions options) + where TPixel : struct, IPixel { JpegEncoder encoder = new JpegEncoder(); encoder.Encode(source, stream, options); diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs index 0aac316035..56d025504d 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs @@ -8,20 +8,22 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Image decoder for generating an image out of a jpg stream. /// public class JpegDecoder : IImageDecoder { /// - public Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) - where TColor : struct, IPixel + public Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) + where TPixel : struct, IPixel { Guard.NotNull(stream, "stream"); using (JpegDecoderCore decoder = new JpegDecoderCore(options, configuration)) { - return decoder.Decode(stream); + return decoder.Decode(stream); } } } diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 33533aa12b..186c1e5282 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Formats using System.Threading.Tasks; using ImageSharp.Formats.Jpg; + using ImageSharp.PixelFormats; /// /// Performs the jpeg decoding operation. @@ -121,7 +122,7 @@ namespace ImageSharp.Formats /// /// Gets the array of -s storing the "raw" frequency-domain decoded blocks. /// We need to apply IDCT, dequantiazition and unzigging to transform them into color-space blocks. - /// This is done by . + /// This is done by . /// When ==true, we are touching these blocks multiple times - each time we process a Scan. /// public DecodedBlockArray[] DecodedBlocks { get; } @@ -186,16 +187,16 @@ namespace ImageSharp.Formats /// Decodes the image from the specified and sets /// the data to image. /// - /// The pixel format. + /// The pixel format. /// The stream, where the image should be. /// The decoded image. - public Image Decode(Stream stream) - where TColor : struct, IPixel + public Image Decode(Stream stream) + where TPixel : struct, IPixel { ImageMetaData metadata = new ImageMetaData(); this.ProcessStream(metadata, stream, false); - this.ProcessBlocksIntoJpegImageChannels(); - Image image = this.ConvertJpegPixelsToImagePixels(metadata); + this.ProcessBlocksIntoJpegImageChannels(); + Image image = this.ConvertJpegPixelsToImagePixels(metadata); return image; } @@ -254,14 +255,14 @@ namespace ImageSharp.Formats /// Optimized method to pack bytes to the image from the YCbCr color space. /// This is faster than implicit casting as it avoids double packing. /// - /// The pixel format. + /// The pixel format. /// The packed pixel. /// The y luminance component. /// The cb chroma component. /// The cr chroma component. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void PackYcbCr(ref TColor packed, byte y, byte cb, byte cr) - where TColor : struct, IPixel + private static void PackYcbCr(ref TPixel packed, byte y, byte cb, byte cr) + where TPixel : struct, IPixel { int ccb = cb - 128; int ccr = cr - 128; @@ -481,9 +482,9 @@ namespace ImageSharp.Formats /// are in a "raw" frequency-domain form. We need to apply IDCT, dequantization and unzigging to transform them into color-space blocks. /// We can copy these blocks into -s afterwards. /// - /// The pixel type - private void ProcessBlocksIntoJpegImageChannels() - where TColor : struct, IPixel + /// The pixel type + private void ProcessBlocksIntoJpegImageChannels() + where TPixel : struct, IPixel { Parallel.For( 0, @@ -497,15 +498,15 @@ namespace ImageSharp.Formats } /// - /// Convert the pixel data in and/or into pixels of + /// Convert the pixel data in and/or into pixels of /// - /// The pixel type + /// The pixel type /// The metadata for the image. /// The decoded image. - private Image ConvertJpegPixelsToImagePixels(ImageMetaData metadata) - where TColor : struct, IPixel + private Image ConvertJpegPixelsToImagePixels(ImageMetaData metadata) + where TPixel : struct, IPixel { - Image image = Image.Create(this.ImageWidth, this.ImageHeight, metadata, this.configuration); + Image image = Image.Create(this.ImageWidth, this.ImageHeight, metadata, this.configuration); if (this.grayImage.IsInitialized) { @@ -561,10 +562,10 @@ namespace ImageSharp.Formats /// /// Assigns the horizontal and vertical resolution to the image if it has a JFIF header. /// - /// The pixel format. + /// The pixel format. /// The image to assign the resolution to. - private void AssignResolution(Image image) - where TColor : struct, IPixel + private void AssignResolution(Image image) + where TPixel : struct, IPixel { if (this.isJfif && this.horizontalResolution > 0 && this.verticalResolution > 0) { @@ -589,14 +590,14 @@ namespace ImageSharp.Formats /// /// Converts the image from the original CMYK image pixels. /// - /// The pixel format. + /// The pixel format. /// The image. - private void ConvertFromCmyk(Image image) - where TColor : struct, IPixel + private void ConvertFromCmyk(Image image) + where TPixel : struct, IPixel { int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor; - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -613,7 +614,7 @@ namespace ImageSharp.Formats byte magenta = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; byte yellow = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; - TColor packed = default(TColor); + TPixel packed = default(TPixel); this.PackCmyk(ref packed, cyan, magenta, yellow, x, y); pixels[x, y] = packed; } @@ -626,12 +627,12 @@ namespace ImageSharp.Formats /// /// Converts the image from the original grayscale image pixels. /// - /// The pixel format. + /// The pixel format. /// The image. - private void ConvertFromGrayScale(Image image) - where TColor : struct, IPixel + private void ConvertFromGrayScale(Image image) + where TPixel : struct, IPixel { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -644,7 +645,7 @@ namespace ImageSharp.Formats { byte rgb = this.grayImage.Pixels[yoff + x]; - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromBytes(rgb, rgb, rgb, 255); pixels[x, y] = packed; } @@ -657,14 +658,14 @@ namespace ImageSharp.Formats /// /// Converts the image from the original RBG image pixels. /// - /// The pixel format. + /// The pixel format. /// The image. - private void ConvertFromRGB(Image image) - where TColor : struct, IPixel + private void ConvertFromRGB(Image image) + where TPixel : struct, IPixel { int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor; - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -682,7 +683,7 @@ namespace ImageSharp.Formats byte green = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; byte blue = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromBytes(red, green, blue, 255); pixels[x, y] = packed; } @@ -695,13 +696,13 @@ namespace ImageSharp.Formats /// /// Converts the image from the original YCbCr image pixels. /// - /// The pixel format. + /// The pixel format. /// The image. - private void ConvertFromYCbCr(Image image) - where TColor : struct, IPixel + private void ConvertFromYCbCr(Image image) + where TPixel : struct, IPixel { int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor; - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -719,8 +720,8 @@ namespace ImageSharp.Formats byte cb = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; - TColor packed = default(TColor); - PackYcbCr(ref packed, yy, cb, cr); + TPixel packed = default(TPixel); + PackYcbCr(ref packed, yy, cb, cr); pixels[x, y] = packed; } }); @@ -732,14 +733,14 @@ namespace ImageSharp.Formats /// /// Converts the image from the original YCCK image pixels. /// - /// The pixel format. + /// The pixel format. /// The image. - private void ConvertFromYcck(Image image) - where TColor : struct, IPixel + private void ConvertFromYcck(Image image) + where TPixel : struct, IPixel { int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor; - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { Parallel.For( 0, @@ -756,7 +757,7 @@ namespace ImageSharp.Formats byte cb = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; - TColor packed = default(TColor); + TPixel packed = default(TPixel); this.PackYcck(ref packed, yy, cb, cr, x, y); pixels[x, y] = packed; } @@ -850,15 +851,15 @@ namespace ImageSharp.Formats /// Optimized method to pack bytes to the image from the CMYK color space. /// This is faster than implicit casting as it avoids double packing. /// - /// The pixel format. + /// The pixel format. /// The packed pixel. /// The cyan component. /// The magenta component. /// The yellow component. /// The x-position within the image. /// The y-position within the image. - private void PackCmyk(ref TColor packed, byte c, byte m, byte y, int xx, int yy) - where TColor : struct, IPixel + private void PackCmyk(ref TPixel packed, byte c, byte m, byte y, int xx, int yy) + where TPixel : struct, IPixel { // Get keyline float keyline = (255 - this.blackImage[xx, yy]) / 255F; @@ -875,15 +876,15 @@ namespace ImageSharp.Formats /// Optimized method to pack bytes to the image from the YCCK color space. /// This is faster than implicit casting as it avoids double packing. /// - /// The pixel format. + /// The pixel format. /// The packed pixel. /// The y luminance component. /// The cb chroma component. /// The cr chroma component. /// The x-position within the image. /// The y-position within the image. - private void PackYcck(ref TColor packed, byte y, byte cb, byte cr, int xx, int yy) - where TColor : struct, IPixel + private void PackYcck(ref TPixel packed, byte y, byte cb, byte cr, int xx, int yy) + where TPixel : struct, IPixel { // Convert the YCbCr part of the YCbCrK to RGB, invert the RGB to get // CMY, and patch in the original K. The RGB to CMY inversion cancels diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs index 2f2823fa28..152fd2c64c 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs @@ -7,14 +7,16 @@ namespace ImageSharp.Formats { using System.IO; + using ImageSharp.PixelFormats; + /// /// Encoder for writing the data image to a stream in jpeg format. /// public class JpegEncoder : IImageEncoder { /// - public void Encode(Image image, Stream stream, IEncoderOptions options) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IEncoderOptions options) + where TPixel : struct, IPixel { IJpegEncoderOptions gifOptions = JpegEncoderOptions.Create(options); @@ -22,14 +24,14 @@ namespace ImageSharp.Formats } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The to encode from. + /// The pixel format. + /// The to encode from. /// The to encode the image data to. /// The options for the encoder. - public void Encode(Image image, Stream stream, IJpegEncoderOptions options) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IJpegEncoderOptions options) + where TPixel : struct, IPixel { JpegEncoderCore encode = new JpegEncoderCore(options); encode.Encode(image, stream); diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index c3cf75a0f6..eb083c35d9 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -12,6 +12,7 @@ namespace ImageSharp.Formats using ImageSharp.Formats.Jpg; using ImageSharp.Formats.Jpg.Components; + using ImageSharp.PixelFormats; /// /// Image encoder for writing an image to a stream as a jpeg. @@ -165,11 +166,11 @@ namespace ImageSharp.Formats /// /// Encode writes the image to the jpeg baseline format with the given options. /// - /// The pixel format. + /// The pixel format. /// The image to write from. /// The stream to write to. - public void Encode(Image image, Stream stream) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream) + where TPixel : struct, IPixel { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -225,7 +226,7 @@ namespace ImageSharp.Formats this.WriteDefineHuffmanTables(componentCount); // Write the image data. - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { this.WriteStartOfScan(pixels); } @@ -282,23 +283,23 @@ namespace ImageSharp.Formats /// /// Converts the 8x8 region of the image whose top-left corner is x,y to its YCbCr values. /// - /// The pixel format. + /// The pixel format. /// The pixel accessor. /// The x-position within the image. /// The y-position within the image. /// The luminance block. /// The red chroma block. /// The blue chroma block. - /// Temporal provided by the caller - private static void ToYCbCr( - PixelAccessor pixels, + /// Temporal provided by the caller + private static void ToYCbCr( + PixelAccessor pixels, int x, int y, Block8x8F* yBlock, Block8x8F* cbBlock, Block8x8F* crBlock, - PixelArea rgbBytes) - where TColor : struct, IPixel + PixelArea rgbBytes) + where TPixel : struct, IPixel { float* yBlockRaw = (float*)yBlock; float* cbBlockRaw = (float*)cbBlock; @@ -442,12 +443,12 @@ namespace ImageSharp.Formats /// /// Encodes the image with no subsampling. /// - /// The pixel format. + /// The pixel format. /// The pixel accessor providing access to the image pixels. - private void Encode444(PixelAccessor pixels) - where TColor : struct, IPixel + private void Encode444(PixelAccessor pixels) + where TPixel : struct, IPixel { - // TODO: Need a JpegScanEncoder class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) + // TODO: Need a JpegScanEncoder class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) Block8x8F b = default(Block8x8F); Block8x8F cb = default(Block8x8F); Block8x8F cr = default(Block8x8F); @@ -463,7 +464,7 @@ namespace ImageSharp.Formats // ReSharper disable once InconsistentNaming int prevDCY = 0, prevDCCb = 0, prevDCCr = 0; - using (PixelArea rgbBytes = new PixelArea(8, 8, ComponentOrder.Xyz)) + using (PixelArea rgbBytes = new PixelArea(8, 8, ComponentOrder.Xyz)) { for (int y = 0; y < pixels.Height; y += 8) { @@ -714,9 +715,9 @@ namespace ImageSharp.Formats /// Writes the metadata profiles to the image. /// /// The image. - /// The pixel format. - private void WriteProfiles(Image image) - where TColor : struct, IPixel + /// The pixel format. + private void WriteProfiles(Image image) + where TPixel : struct, IPixel { if (this.options.IgnoreMetadata) { @@ -786,12 +787,12 @@ namespace ImageSharp.Formats /// /// Writes the StartOfScan marker. /// - /// The pixel format. + /// The pixel format. /// The pixel accessor providing access to the image pixels. - private void WriteStartOfScan(PixelAccessor pixels) - where TColor : struct, IPixel + private void WriteStartOfScan(PixelAccessor pixels) + where TPixel : struct, IPixel { - // TODO: Need a JpegScanEncoder class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) + // TODO: Need a JpegScanEncoder class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) // TODO: We should allow grayscale writing. this.outputStream.Write(SosHeaderYCbCr, 0, SosHeaderYCbCr.Length); @@ -813,12 +814,12 @@ namespace ImageSharp.Formats /// Encodes the image with subsampling. The Cb and Cr components are each subsampled /// at a factor of 2 both horizontally and vertically. /// - /// The pixel format. + /// The pixel format. /// The pixel accessor providing access to the image pixels. - private void Encode420(PixelAccessor pixels) - where TColor : struct, IPixel + private void Encode420(PixelAccessor pixels) + where TPixel : struct, IPixel { - // TODO: Need a JpegScanEncoder class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) + // TODO: Need a JpegScanEncoder class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) Block8x8F b = default(Block8x8F); BlockQuad cb = default(BlockQuad); @@ -837,7 +838,7 @@ namespace ImageSharp.Formats // ReSharper disable once InconsistentNaming int prevDCY = 0, prevDCCb = 0, prevDCCr = 0; - using (PixelArea rgbBytes = new PixelArea(8, 8, ComponentOrder.Xyz)) + using (PixelArea rgbBytes = new PixelArea(8, 8, ComponentOrder.Xyz)) { for (int y = 0; y < pixels.Height; y += 16) { diff --git a/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs b/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs index ace309812a..afb8e07007 100644 --- a/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs +++ b/src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Formats.Jpg using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using ImageSharp.PixelFormats; + /// /// Jpeg specific utilities and extension methods /// @@ -16,17 +18,17 @@ namespace ImageSharp.Formats.Jpg /// /// Copy a region of an image into dest. De "outlier" area will be stretched out with pixels on the right and bottom of the image. /// - /// The pixel type + /// The pixel type /// The input pixel acessor - /// The destination + /// The destination /// Starting Y coord /// Starting X coord - public static void CopyRGBBytesStretchedTo( - this PixelAccessor pixels, - PixelArea dest, + public static void CopyRGBBytesStretchedTo( + this PixelAccessor pixels, + PixelArea dest, int sourceY, int sourceX) - where TColor : struct, IPixel + where TPixel : struct, IPixel { pixels.SafeCopyTo(dest, sourceY, sourceX); int stretchFromX = pixels.Width - sourceX; @@ -36,14 +38,14 @@ namespace ImageSharp.Formats.Jpg // Nothing to stretch if (fromX, fromY) is outside the area, or is at (0,0) [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool IsInvalidStretchStartingPosition(PixelArea area, int fromX, int fromY) - where TColor : struct, IPixel + private static bool IsInvalidStretchStartingPosition(PixelArea area, int fromX, int fromY) + where TPixel : struct, IPixel { return fromX <= 0 || fromY <= 0 || fromX >= area.Width || fromY >= area.Height; } - private static void StretchPixels(PixelArea area, int fromX, int fromY) - where TColor : struct, IPixel + private static void StretchPixels(PixelArea area, int fromX, int fromY) + where TPixel : struct, IPixel { if (IsInvalidStretchStartingPosition(area, fromX, fromY)) { @@ -75,8 +77,8 @@ namespace ImageSharp.Formats.Jpg } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static ref RGB24 GetRowStart(PixelArea area, int y) - where TColor : struct, IPixel + private static ref RGB24 GetRowStart(PixelArea area, int y) + where TPixel : struct, IPixel { return ref Unsafe.As(ref area.GetRowSpan(y).DangerousGetPinnableReference()); } diff --git a/src/ImageSharp/Formats/Png/ImageExtensions.cs b/src/ImageSharp/Formats/Png/ImageExtensions.cs index 79e96175c1..44f242b3f8 100644 --- a/src/ImageSharp/Formats/Png/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Png/ImageExtensions.cs @@ -9,23 +9,25 @@ namespace ImageSharp using Formats; + using ImageSharp.PixelFormats; + /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Saves the image to the given stream with the png format. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsPng(this Image source, Stream stream) - where TColor : struct, IPixel + public static Image SaveAsPng(this Image source, Stream stream) + where TPixel : struct, IPixel { return SaveAsPng(source, stream, null); } @@ -33,16 +35,16 @@ namespace ImageSharp /// /// Saves the image to the given stream with the png format. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. /// - /// The . + /// The . /// - public static Image SaveAsPng(this Image source, Stream stream, IPngEncoderOptions options) - where TColor : struct, IPixel + public static Image SaveAsPng(this Image source, Stream stream, IPngEncoderOptions options) + where TPixel : struct, IPixel { PngEncoder encoder = new PngEncoder(); encoder.Encode(source, stream, options); diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs index d0a820c17f..3a34147e2c 100644 --- a/src/ImageSharp/Formats/Png/PngDecoder.cs +++ b/src/ImageSharp/Formats/Png/PngDecoder.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Formats using System; using System.IO; + using ImageSharp.PixelFormats; + /// /// Encoder for generating an image out of a png encoded stream. /// @@ -31,27 +33,27 @@ namespace ImageSharp.Formats public class PngDecoder : IImageDecoder { /// - public Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) + public Image Decode(Configuration configuration, Stream stream, IDecoderOptions options) - where TColor : struct, IPixel + where TPixel : struct, IPixel { IPngDecoderOptions pngOptions = PngDecoderOptions.Create(options); - return this.Decode(configuration, stream, pngOptions); + return this.Decode(configuration, stream, pngOptions); } /// - /// Decodes the image from the specified stream to the . + /// Decodes the image from the specified stream to the . /// - /// The pixel format. + /// The pixel format. /// The configuration for the image. /// The containing image data. /// The options for the decoder. /// The decoded image. - public Image Decode(Configuration configuration, Stream stream, IPngDecoderOptions options) - where TColor : struct, IPixel + public Image Decode(Configuration configuration, Stream stream, IPngDecoderOptions options) + where TPixel : struct, IPixel { - return new PngDecoderCore(options, configuration).Decode(stream); + return new PngDecoderCore(options, configuration).Decode(stream); } } } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 5ce9b5eb06..58cfa6a70b 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -12,6 +12,8 @@ namespace ImageSharp.Formats using System.Linq; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; + using static ComparableExtensions; /// @@ -154,7 +156,7 @@ namespace ImageSharp.Formats /// /// Decodes the stream to the image. /// - /// The pixel format. + /// The pixel format. /// The stream containing image data. /// /// Thrown if the stream does not contain and end chunk. @@ -163,8 +165,8 @@ namespace ImageSharp.Formats /// Thrown if the image is larger than the maximum allowable size. /// /// The decoded image - public Image Decode(Stream stream) - where TColor : struct, IPixel + public Image Decode(Stream stream) + where TPixel : struct, IPixel { ImageMetaData metadata = new ImageMetaData(); this.currentStream = stream; @@ -215,14 +217,14 @@ namespace ImageSharp.Formats } } - if (this.header.Width > Image.MaxWidth || this.header.Height > Image.MaxHeight) + if (this.header.Width > Image.MaxWidth || this.header.Height > Image.MaxHeight) { - throw new ArgumentOutOfRangeException($"The input png '{this.header.Width}x{this.header.Height}' is bigger than the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'"); + throw new ArgumentOutOfRangeException($"The input png '{this.header.Width}x{this.header.Height}' is bigger than the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'"); } - Image image = Image.Create(this.header.Width, this.header.Height, metadata, this.configuration); + Image image = Image.Create(this.header.Width, this.header.Height, metadata, this.configuration); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { this.ReadScanlines(dataStream, pixels); } @@ -340,11 +342,11 @@ namespace ImageSharp.Formats /// /// Reads the scanlines within the image. /// - /// The pixel format. + /// The pixel format. /// The containing data. /// The pixel data. - private void ReadScanlines(MemoryStream dataStream, PixelAccessor pixels) - where TColor : struct, IPixel + private void ReadScanlines(MemoryStream dataStream, PixelAccessor pixels) + where TPixel : struct, IPixel { this.bytesPerPixel = this.CalculateBytesPerPixel(); this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1; @@ -371,11 +373,11 @@ namespace ImageSharp.Formats /// /// Decodes the raw pixel data row by row /// - /// The pixel format. + /// The pixel format. /// The compressed pixel data stream. /// The image pixel accessor. - private void DecodePixelData(Stream compressedStream, PixelAccessor pixels) - where TColor : struct, IPixel + private void DecodePixelData(Stream compressedStream, PixelAccessor pixels) + where TPixel : struct, IPixel { byte[] previousScanline = ArrayPool.Shared.Rent(this.bytesPerScanline); byte[] scanline = ArrayPool.Shared.Rent(this.bytesPerScanline); @@ -444,11 +446,11 @@ namespace ImageSharp.Formats /// Decodes the raw interlaced pixel data row by row /// /// - /// The pixel format. + /// The pixel format. /// The compressed pixel data stream. /// The image pixel accessor. - private void DecodeInterlacedPixelData(Stream compressedStream, PixelAccessor pixels) - where TColor : struct, IPixel + private void DecodeInterlacedPixelData(Stream compressedStream, PixelAccessor pixels) + where TPixel : struct, IPixel { byte[] previousScanline = ArrayPool.Shared.Rent(this.bytesPerScanline); byte[] scanline = ArrayPool.Shared.Rent(this.bytesPerScanline); @@ -532,14 +534,14 @@ namespace ImageSharp.Formats /// /// Processes the de-filtered scanline filling the image pixel data /// - /// The pixel format. + /// The pixel format. /// The de-filtered scanline /// The current image row. /// The image pixels - private void ProcessDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels) - where TColor : struct, IPixel + private void ProcessDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels) + where TPixel : struct, IPixel { - TColor color = default(TColor); + TPixel color = default(TPixel); switch (this.PngColorType) { case PngColorType.Grayscale: @@ -655,16 +657,16 @@ namespace ImageSharp.Formats /// /// Processes the interlaced de-filtered scanline filling the image pixel data /// - /// The pixel format. + /// The pixel format. /// The de-filtered scanline /// The current image row. /// The image pixels /// The column start index. Always 0 for none interlaced images. /// The column increment. Always 1 for none interlaced images. - private void ProcessInterlacedDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels, int pixelOffset = 0, int increment = 1) - where TColor : struct, IPixel + private void ProcessInterlacedDefilteredScanline(byte[] defilteredScanline, int row, PixelAccessor pixels, int pixelOffset = 0, int increment = 1) + where TPixel : struct, IPixel { - TColor color = default(TColor); + TPixel color = default(TPixel); switch (this.PngColorType) { diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index e583f381fb..e7b6bf30ef 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -7,14 +7,16 @@ namespace ImageSharp.Formats { using System.IO; + using ImageSharp.PixelFormats; + /// /// Image encoder for writing image data to a stream in png format. /// public class PngEncoder : IImageEncoder { /// - public void Encode(Image image, Stream stream, IEncoderOptions options) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IEncoderOptions options) + where TPixel : struct, IPixel { IPngEncoderOptions pngOptions = PngEncoderOptions.Create(options); @@ -22,14 +24,14 @@ namespace ImageSharp.Formats } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The to encode from. + /// The pixel format. + /// The to encode from. /// The to encode the image data to. /// The options for the encoder. - public void Encode(Image image, Stream stream, IPngEncoderOptions options) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IPngEncoderOptions options) + where TPixel : struct, IPixel { PngEncoderCore encode = new PngEncoderCore(options); encode.Encode(image, stream); diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index c11fc94dfe..e30f9791e1 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -10,6 +10,8 @@ namespace ImageSharp.Formats using System.IO; using System.Linq; + using ImageSharp.PixelFormats; + using Quantizers; using static ComparableExtensions; @@ -114,13 +116,13 @@ namespace ImageSharp.Formats } /// - /// Encodes the image to the specified stream from the . + /// Encodes the image to the specified stream from the . /// - /// The pixel format. - /// The to encode from. + /// The pixel format. + /// The to encode from. /// The to encode the image data to. - public void Encode(Image image, Stream stream) - where TColor : struct, IPixel + public void Encode(Image image, Stream stream) + where TPixel : struct, IPixel { Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); @@ -196,7 +198,7 @@ namespace ImageSharp.Formats this.WritePhysicalChunk(stream, image); this.WriteGammaChunk(stream); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { this.WriteDataChunks(pixels, stream); } @@ -248,27 +250,27 @@ namespace ImageSharp.Formats /// /// Collects the indexed pixel data. /// - /// The pixel format. + /// The pixel format. /// The image to encode. /// The containing image data. /// The . - private void CollectIndexedBytes(ImageBase image, Stream stream, PngHeader header) - where TColor : struct, IPixel + private void CollectIndexedBytes(ImageBase image, Stream stream, PngHeader header) + where TPixel : struct, IPixel { // Quantize the image and get the pixels. - QuantizedImage quantized = this.WritePaletteChunk(stream, header, image); + QuantizedImage quantized = this.WritePaletteChunk(stream, header, image); this.palettePixelData = quantized.Pixels; } /// /// Collects a row of grayscale pixels. /// - /// The pixel format. + /// The pixel format. /// The image pixels accessor. /// The row index. /// The raw scanline. - private void CollectGrayscaleBytes(PixelAccessor pixels, int row, byte[] rawScanline) - where TColor : struct, IPixel + private void CollectGrayscaleBytes(PixelAccessor pixels, int row, byte[] rawScanline) + where TPixel : struct, IPixel { // Copy the pixels across from the image. // Reuse the chunk type buffer. @@ -297,15 +299,15 @@ namespace ImageSharp.Formats /// /// Collects a row of true color pixel data. /// - /// The pixel format. + /// The pixel format. /// The image pixel accessor. /// The row index. /// The raw scanline. - private void CollectColorBytes(PixelAccessor pixels, int row, byte[] rawScanline) - where TColor : struct, IPixel + private void CollecTPixelBytes(PixelAccessor pixels, int row, byte[] rawScanline) + where TPixel : struct, IPixel { // We can use the optimized PixelAccessor here and copy the bytes in unmanaged memory. - using (PixelArea pixelRow = new PixelArea(this.width, rawScanline, this.bytesPerPixel == 4 ? ComponentOrder.Xyzw : ComponentOrder.Xyz)) + using (PixelArea pixelRow = new PixelArea(this.width, rawScanline, this.bytesPerPixel == 4 ? ComponentOrder.Xyzw : ComponentOrder.Xyz)) { pixels.CopyTo(pixelRow, row); } @@ -315,15 +317,15 @@ namespace ImageSharp.Formats /// Encodes the pixel data line by line. /// Each scanline is encoded in the most optimal manner to improve compression. /// - /// The pixel format. + /// The pixel format. /// The image pixel accessor. /// The row. /// The previous scanline. /// The raw scanline. /// The filtered scanline result. /// The - private byte[] EncodePixelRow(PixelAccessor pixels, int row, byte[] previousScanline, byte[] rawScanline, byte[] result) - where TColor : struct, IPixel + private byte[] EncodePixelRow(PixelAccessor pixels, int row, byte[] previousScanline, byte[] rawScanline, byte[] result) + where TPixel : struct, IPixel { switch (this.pngColorType) { @@ -335,7 +337,7 @@ namespace ImageSharp.Formats this.CollectGrayscaleBytes(pixels, row, rawScanline); break; default: - this.CollectColorBytes(pixels, row, rawScanline); + this.CollecTPixelBytes(pixels, row, rawScanline); break; } @@ -471,13 +473,13 @@ namespace ImageSharp.Formats /// /// Writes the palette chunk to the stream. /// - /// The pixel format. + /// The pixel format. /// The containing image data. /// The . /// The image to encode. - /// The - private QuantizedImage WritePaletteChunk(Stream stream, PngHeader header, ImageBase image) - where TColor : struct, IPixel + /// The + private QuantizedImage WritePaletteChunk(Stream stream, PngHeader header, ImageBase image) + where TPixel : struct, IPixel { if (this.quality > 256) { @@ -486,14 +488,14 @@ namespace ImageSharp.Formats if (this.quantizer == null) { - this.quantizer = new WuQuantizer(); + this.quantizer = new WuQuantizer(); } // Quantize the image returning a palette. This boxing is icky. - QuantizedImage quantized = ((IQuantizer)this.quantizer).Quantize(image, this.quality); + QuantizedImage quantized = ((IQuantizer)this.quantizer).Quantize(image, this.quality); // Grab the palette and write it to the stream. - TColor[] palette = quantized.Palette; + TPixel[] palette = quantized.Palette; byte pixelCount = palette.Length.ToByte(); // Get max colors for bit depth. @@ -548,11 +550,11 @@ namespace ImageSharp.Formats /// /// Writes the physical dimension information to the stream. /// - /// The pixel format. + /// The pixel format. /// The containing image data. /// The image. - private void WritePhysicalChunk(Stream stream, Image image) - where TColor : struct, IPixel + private void WritePhysicalChunk(Stream stream, Image image) + where TPixel : struct, IPixel { if (image.MetaData.HorizontalResolution > 0 && image.MetaData.VerticalResolution > 0) { @@ -593,11 +595,11 @@ namespace ImageSharp.Formats /// /// Writes the pixel information to the stream. /// - /// The pixel format. + /// The pixel format. /// The pixel accessor. /// The stream. - private void WriteDataChunks(PixelAccessor pixels, Stream stream) - where TColor : struct, IPixel + private void WriteDataChunks(PixelAccessor pixels, Stream stream) + where TPixel : struct, IPixel { int bytesPerScanline = this.width * this.bytesPerPixel; byte[] previousScanline = new byte[bytesPerScanline]; diff --git a/src/ImageSharp/Image.Create.cs b/src/ImageSharp/Image.Create.cs index fcecefd7b7..3d92cd66bf 100644 --- a/src/ImageSharp/Image.Create.cs +++ b/src/ImageSharp/Image.Create.cs @@ -5,11 +5,7 @@ namespace ImageSharp { - using System; - using System.Diagnostics; - using System.IO; - - using Formats; + using ImageSharp.PixelFormats; /// /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha @@ -18,10 +14,10 @@ namespace ImageSharp public sealed partial class Image { /// - /// Create a new instance of the class + /// Create a new instance of the class /// with the height and the width of the image. /// - /// The pixel format. + /// The pixel format. /// The width of the image in pixels. /// The height of the image in pixels. /// The images matadata to preload. @@ -29,38 +25,38 @@ namespace ImageSharp /// The configuration providing initialization code which allows extending the library. /// /// - /// A new unless is in which case it returns + /// A new unless is in which case it returns /// - internal static Image Create(int width, int height, ImageMetaData metadata, Configuration configuration) - where TColor : struct, IPixel + internal static Image Create(int width, int height, ImageMetaData metadata, Configuration configuration) + where TPixel : struct, IPixel { - if (typeof(TColor) == typeof(Color)) + if (typeof(TPixel) == typeof(Rgba32)) { - return new Image(width, height, metadata, configuration) as Image; + return new Image(width, height, metadata, configuration) as Image; } else { - return new Image(width, height, metadata, configuration); + return new Image(width, height, metadata, configuration); } } /// - /// Create a new instance of the class + /// Create a new instance of the class /// with the height and the width of the image. /// - /// The pixel format. + /// The pixel format. /// The width of the image in pixels. /// The height of the image in pixels. /// /// The configuration providing initialization code which allows extending the library. /// /// - /// A new unless is in which case it returns + /// A new unless is in which case it returns /// - internal static Image Create(int width, int height, Configuration configuration) - where TColor : struct, IPixel + internal static Image Create(int width, int height, Configuration configuration) + where TPixel : struct, IPixel { - return Image.Create(width, height, null, configuration); + return Image.Create(width, height, null, configuration); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index c1c1371220..b0e4762805 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -10,6 +10,8 @@ namespace ImageSharp using System.Linq; using Formats; + using ImageSharp.PixelFormats; + /// /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// packed into a single unsigned integer value. @@ -51,15 +53,15 @@ namespace ImageSharp /// /// Decodes the image stream to the current image. /// - /// The pixel format. + /// The pixel format. /// The stream. /// The options for the decoder. /// the configuration. /// /// The decoded image /// - private static Image Decode(Stream stream, IDecoderOptions options, Configuration config) - where TColor : struct, IPixel + private static Image Decode(Stream stream, IDecoderOptions options, Configuration config) + where TPixel : struct, IPixel { IImageFormat format = DiscoverFormat(stream, config); if (format == null) @@ -67,7 +69,7 @@ namespace ImageSharp return null; } - Image img = format.Decoder.Decode(config, stream, options); + Image img = format.Decoder.Decode(config, stream, options); img.CurrentImageFormat = format; return img; } diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image.FromBytes.cs index b2f9854f22..540eb60168 100644 --- a/src/ImageSharp/Image.FromBytes.cs +++ b/src/ImageSharp/Image.FromBytes.cs @@ -9,6 +9,8 @@ namespace ImageSharp using System.IO; using Formats; + using ImageSharp.PixelFormats; + /// /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// packed into a single unsigned integer value. @@ -109,70 +111,70 @@ namespace ImageSharp /// /// Loads the image from the given byte array. /// - /// The pixel format. + /// The pixel format. /// The byte array containing image data. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(byte[] data) - where TColor : struct, IPixel + public static Image Load(byte[] data) + where TPixel : struct, IPixel { - return Load(null, data, null); + return Load(null, data, null); } /// /// Loads the image from the given byte array. /// - /// The pixel format. + /// The pixel format. /// The byte array containing image data. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(byte[] data, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(byte[] data, IDecoderOptions options) + where TPixel : struct, IPixel { - return Load(null, data, options); + return Load(null, data, options); } /// /// Loads the image from the given byte array. /// - /// The pixel format. + /// The pixel format. /// The config for the decoder. /// The byte array containing image data. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Configuration config, byte[] data) - where TColor : struct, IPixel + public static Image Load(Configuration config, byte[] data) + where TPixel : struct, IPixel { - return Load(config, data, null); + return Load(config, data, null); } /// /// Loads the image from the given byte array. /// - /// The pixel format. + /// The pixel format. /// The byte array containing image data. /// The decoder. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(byte[] data, IImageDecoder decoder) - where TColor : struct, IPixel + public static Image Load(byte[] data, IImageDecoder decoder) + where TPixel : struct, IPixel { - return Load(data, decoder, null); + return Load(data, decoder, null); } /// /// Loads the image from the given byte array. /// - /// The pixel format. + /// The pixel format. /// The configuration options. /// The byte array containing image data. /// The options for the decoder. @@ -180,19 +182,19 @@ namespace ImageSharp /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Configuration config, byte[] data, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(Configuration config, byte[] data, IDecoderOptions options) + where TPixel : struct, IPixel { using (MemoryStream ms = new MemoryStream(data)) { - return Load(config, ms, options); + return Load(config, ms, options); } } /// /// Loads the image from the given byte array. /// - /// The pixel format. + /// The pixel format. /// The byte array containing image data. /// The decoder. /// The options for the decoder. @@ -200,12 +202,12 @@ namespace ImageSharp /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) + where TPixel : struct, IPixel { using (MemoryStream ms = new MemoryStream(data)) { - return Load(ms, decoder, options); + return Load(ms, decoder, options); } } } diff --git a/src/ImageSharp/Image.FromFile.cs b/src/ImageSharp/Image.FromFile.cs index 40cdfe3eff..8f4c9138b6 100644 --- a/src/ImageSharp/Image.FromFile.cs +++ b/src/ImageSharp/Image.FromFile.cs @@ -9,6 +9,7 @@ namespace ImageSharp using System; using System.IO; using Formats; + using ImageSharp.PixelFormats; /// /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha @@ -83,7 +84,7 @@ namespace ImageSharp /// The image public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) { - return new Image(Load(path, decoder, options)); + return new Image(Load(path, decoder, options)); } /// @@ -108,70 +109,70 @@ namespace ImageSharp /// /// Loads the image from the given file. /// - /// The pixel format. + /// The pixel format. /// The file path to the image. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(string path) - where TColor : struct, IPixel + public static Image Load(string path) + where TPixel : struct, IPixel { - return Load(null, path, null); + return Load(null, path, null); } /// /// Loads the image from the given file. /// - /// The pixel format. + /// The pixel format. /// The file path to the image. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(string path, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(string path, IDecoderOptions options) + where TPixel : struct, IPixel { - return Load(null, path, options); + return Load(null, path, options); } /// /// Loads the image from the given file. /// - /// The pixel format. + /// The pixel format. /// The config for the decoder. /// The file path to the image. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Configuration config, string path) - where TColor : struct, IPixel + public static Image Load(Configuration config, string path) + where TPixel : struct, IPixel { - return Load(config, path, null); + return Load(config, path, null); } /// /// Loads the image from the given file. /// - /// The pixel format. + /// The pixel format. /// The file path to the image. /// The decoder. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(string path, IImageDecoder decoder) - where TColor : struct, IPixel + public static Image Load(string path, IImageDecoder decoder) + where TPixel : struct, IPixel { - return Load(path, decoder, null); + return Load(path, decoder, null); } /// /// Loads the image from the given file. /// - /// The pixel format. + /// The pixel format. /// The configuration options. /// The file path to the image. /// The options for the decoder. @@ -179,20 +180,20 @@ namespace ImageSharp /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Configuration config, string path, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(Configuration config, string path, IDecoderOptions options) + where TPixel : struct, IPixel { config = config ?? Configuration.Default; using (Stream s = config.FileSystem.OpenRead(path)) { - return Load(config, s, options); + return Load(config, s, options); } } /// /// Loads the image from the given file. /// - /// The pixel format. + /// The pixel format. /// The file path to the image. /// The decoder. /// The options for the decoder. @@ -200,13 +201,13 @@ namespace ImageSharp /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) + where TPixel : struct, IPixel { Configuration config = Configuration.Default; using (Stream s = config.FileSystem.OpenRead(path)) { - return Load(s, decoder, options); + return Load(s, decoder, options); } } } diff --git a/src/ImageSharp/Image.FromStream.cs b/src/ImageSharp/Image.FromStream.cs index 112b8a1093..a34c6b7b3c 100644 --- a/src/ImageSharp/Image.FromStream.cs +++ b/src/ImageSharp/Image.FromStream.cs @@ -7,9 +7,12 @@ namespace ImageSharp { using System; using System.IO; + using System.Numerics; using System.Text; using Formats; + using ImageSharp.PixelFormats; + /// /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// packed into a single unsigned integer value. @@ -83,7 +86,7 @@ namespace ImageSharp /// The image public static Image Load(Configuration config, Stream stream, IDecoderOptions options) { - Image image = Load(config, stream, options); + Image image = Load(config, stream, options); return image as Image ?? new Image(image); } @@ -100,7 +103,7 @@ namespace ImageSharp /// The image public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) { - Image image = new Image(Load(stream, decoder, options)); + Image image = new Image(Load(stream, decoder, options)); return image as Image ?? new Image(image); } @@ -108,70 +111,70 @@ namespace ImageSharp /// /// Loads the image from the given stream. /// - /// The pixel format. + /// The pixel format. /// The stream containing image information. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Stream stream) - where TColor : struct, IPixel + public static Image Load(Stream stream) + where TPixel : struct, IPixel { - return Load(null, stream, null); + return Load(null, stream, null); } /// /// Loads the image from the given stream. /// - /// The pixel format. + /// The pixel format. /// The stream containing image information. /// The options for the decoder. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Stream stream, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(Stream stream, IDecoderOptions options) + where TPixel : struct, IPixel { - return Load(null, stream, options); + return Load(null, stream, options); } /// /// Loads the image from the given stream. /// - /// The pixel format. + /// The pixel format. /// The config for the decoder. /// The stream containing image information. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Configuration config, Stream stream) - where TColor : struct, IPixel + public static Image Load(Configuration config, Stream stream) + where TPixel : struct, IPixel { - return Load(config, stream, null); + return Load(config, stream, null); } /// /// Loads the image from the given stream. /// - /// The pixel format. + /// The pixel format. /// The stream containing image information. /// The decoder. /// /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Stream stream, IImageDecoder decoder) - where TColor : struct, IPixel + public static Image Load(Stream stream, IImageDecoder decoder) + where TPixel : struct, IPixel { - return Load(stream, decoder, null); + return Load(stream, decoder, null); } /// /// Loads the image from the given stream. /// - /// The pixel format. + /// The pixel format. /// The stream containing image information. /// The decoder. /// The options for the decoder. @@ -179,16 +182,16 @@ namespace ImageSharp /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) + where TPixel : struct, IPixel { - return WithSeekableStream(stream, s => decoder.Decode(Configuration.Default, s, options)); + return WithSeekableStream(stream, s => decoder.Decode(Configuration.Default, s, options)); } /// /// Loads the image from the given stream. /// - /// The pixel format. + /// The pixel format. /// The configuration options. /// The stream containing image information. /// The options for the decoder. @@ -196,12 +199,12 @@ namespace ImageSharp /// Thrown if the stream is not readable nor seekable. /// /// The image - public static Image Load(Configuration config, Stream stream, IDecoderOptions options) - where TColor : struct, IPixel + public static Image Load(Configuration config, Stream stream, IDecoderOptions options) + where TPixel : struct, IPixel { config = config ?? Configuration.Default; - Image img = WithSeekableStream(stream, s => Decode(s, options, config)); + Image img = WithSeekableStream(stream, s => Decode(s, options, config)); if (img != null) { diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs index 00688afc96..3d33e62630 100644 --- a/src/ImageSharp/Image.cs +++ b/src/ImageSharp/Image.cs @@ -5,18 +5,15 @@ namespace ImageSharp { - using System; using System.Diagnostics; - using System.IO; - - using Formats; + using ImageSharp.PixelFormats; /// /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// packed into a single unsigned integer value. /// [DebuggerDisplay("Image: {Width}x{Height}")] - public sealed partial class Image : Image + public sealed partial class Image : Image { /// /// Initializes a new instance of the class @@ -49,7 +46,7 @@ namespace ImageSharp /// /// The other image, where the clone should be made from. /// is null. - public Image(Image other) + public Image(Image other) : base(other) { } @@ -69,4 +66,4 @@ namespace ImageSharp { } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Image/IImageBase{TColor}.cs b/src/ImageSharp/Image/IImageBase{TPixel}.cs similarity index 67% rename from src/ImageSharp/Image/IImageBase{TColor}.cs rename to src/ImageSharp/Image/IImageBase{TPixel}.cs index 14bdffc672..08d25709b3 100644 --- a/src/ImageSharp/Image/IImageBase{TColor}.cs +++ b/src/ImageSharp/Image/IImageBase{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -6,20 +6,21 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; /// /// Encapsulates the basic properties and methods required to manipulate images in varying formats. /// - /// The pixel format. - public interface IImageBase : IImageBase, IDisposable - where TColor : struct, IPixel + /// The pixel format. + public interface IImageBase : IImageBase, IDisposable + where TPixel : struct, IPixel { /// /// Gets the pixels as an array of the given packed pixel format. /// Important. Due to the nature in the way this is constructed do not rely on the length /// of the array for calculations. Use Width * Height. /// - TColor[] Pixels { get; } + TPixel[] Pixels { get; } /// /// Locks the image providing access to the pixels. @@ -27,7 +28,7 @@ namespace ImageSharp /// It is imperative that the accessor is correctly disposed off after use. /// /// - /// The - PixelAccessor Lock(); + /// The + PixelAccessor Lock(); } } \ No newline at end of file diff --git a/src/ImageSharp/Image/IImageProcessor.cs b/src/ImageSharp/Image/IImageProcessor.cs index 0440cdd766..c4fa9afa29 100644 --- a/src/ImageSharp/Image/IImageProcessor.cs +++ b/src/ImageSharp/Image/IImageProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing using System; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Encapsulates methods to alter the pixels of an image. /// - /// The pixel format. - public interface IImageProcessor - where TColor : struct, IPixel + /// The pixel format. + public interface IImageProcessor + where TPixel : struct, IPixel { /// /// Gets or sets the parallel options for processing tasks in parallel. @@ -27,7 +29,7 @@ namespace ImageSharp.Processing bool Compand { get; set; } /// - /// Applies the process to the specified portion of the specified . + /// Applies the process to the specified portion of the specified . /// /// The source image. Cannot be null. /// @@ -39,6 +41,6 @@ namespace ImageSharp.Processing /// /// doesnt fit the dimension of the image. /// - void Apply(ImageBase source, Rectangle sourceRectangle); + void Apply(ImageBase source, Rectangle sourceRectangle); } } diff --git a/src/ImageSharp/Image/ImageBase{TColor}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs similarity index 86% rename from src/ImageSharp/Image/ImageBase{TColor}.cs rename to src/ImageSharp/Image/ImageBase{TPixel}.cs index cfce7184b6..7bad03cc80 100644 --- a/src/ImageSharp/Image/ImageBase{TColor}.cs +++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -7,16 +7,17 @@ namespace ImageSharp { using System; using System.Diagnostics; + using ImageSharp.PixelFormats; using Processing; /// /// The base class of all images. Encapsulates the basic properties and methods required to manipulate /// images in different pixel formats. /// - /// The pixel format. + /// The pixel format. [DebuggerDisplay("Image: {Width}x{Height}")] - public abstract class ImageBase : IImageBase - where TColor : struct, IPixel + public abstract class ImageBase : IImageBase + where TPixel : struct, IPixel { /// /// Gets or sets the maximum allowable width in pixels. @@ -31,7 +32,7 @@ namespace ImageSharp /// /// The image pixels /// - private TColor[] pixelBuffer; + private TPixel[] pixelBuffer; /// /// A value indicating whether this instance of the given entity has been disposed. @@ -45,7 +46,7 @@ namespace ImageSharp private bool isDisposed; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The configuration providing initialization code which allows extending the library. @@ -56,7 +57,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width of the image in pixels. /// The height of the image in pixels. @@ -79,15 +80,15 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The other to create this instance from. + /// The other to create this instance from. /// /// - /// Thrown if the given is null. + /// Thrown if the given is null. /// - protected ImageBase(ImageBase other) + protected ImageBase(ImageBase other) : this(other.Configuration) { Guard.NotNull(other, nameof(other), "Other image cannot be null."); @@ -98,8 +99,8 @@ namespace ImageSharp // Rent then copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here. this.RentPixels(); - using (PixelAccessor sourcePixels = other.Lock()) - using (PixelAccessor target = this.Lock()) + using (PixelAccessor sourcePixels = other.Lock()) + using (PixelAccessor target = this.Lock()) { // Check we can do this without crashing sourcePixels.CopyTo(target); @@ -107,7 +108,7 @@ namespace ImageSharp } /// - public TColor[] Pixels => this.pixelBuffer; + public TPixel[] Pixels => this.pixelBuffer; /// public int Width { get; private set; } @@ -131,7 +132,7 @@ namespace ImageSharp /// /// The processor. /// The rectangle. - public virtual void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public virtual void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { processor.Apply(this, rectangle); } @@ -150,16 +151,16 @@ namespace ImageSharp } /// - public PixelAccessor Lock() + public PixelAccessor Lock() { - return new PixelAccessor(this); + return new PixelAccessor(this); } /// /// Switches the buffers used by the image and the PixelAccessor meaning that the Image will "own" the buffer from the PixelAccessor and the PixelAccessor will now own the Images buffer. /// /// The pixel source. - internal void SwapPixelsBuffers(PixelAccessor pixelSource) + internal void SwapPixelsBuffers(PixelAccessor pixelSource) { Guard.NotNull(pixelSource, nameof(pixelSource)); @@ -167,7 +168,7 @@ namespace ImageSharp int newHeight = pixelSource.Height; // Push my memory into the accessor (which in turn unpins the old puffer ready for the images use) - TColor[] newPixels = pixelSource.ReturnCurrentPixelsAndReplaceThemInternally(this.Width, this.Height, this.pixelBuffer); + TPixel[] newPixels = pixelSource.ReturnCurrentColorsAndReplaceThemInternally(this.Width, this.Height, this.pixelBuffer); this.Width = newWidth; this.Height = newHeight; this.pixelBuffer = newPixels; @@ -221,7 +222,7 @@ namespace ImageSharp /// private void RentPixels() { - this.pixelBuffer = PixelDataPool.Rent(this.Width * this.Height); + this.pixelBuffer = PixelDataPool.Rent(this.Width * this.Height); } /// @@ -229,7 +230,7 @@ namespace ImageSharp /// private void ReturnPixels() { - PixelDataPool.Return(this.pixelBuffer); + PixelDataPool.Return(this.pixelBuffer); this.pixelBuffer = null; } diff --git a/src/ImageSharp/Image/ImageFrame{TColor}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs similarity index 73% rename from src/ImageSharp/Image/ImageFrame{TColor}.cs rename to src/ImageSharp/Image/ImageFrame{TPixel}.cs index 2712dc6878..e502950d06 100644 --- a/src/ImageSharp/Image/ImageFrame{TColor}.cs +++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -8,16 +8,17 @@ namespace ImageSharp using System; using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; /// /// Represents a single frame in a animation. /// - /// The pixel format. - public class ImageFrame : ImageBase, IImageFrame - where TColor : struct, IPixel + /// The pixel format. + public class ImageFrame : ImageBase, IImageFrame + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width of the image in pixels. /// The height of the image in pixels. @@ -30,10 +31,10 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image to create the frame from. - public ImageFrame(ImageBase image) + public ImageFrame(ImageBase image) : base(image) { } @@ -53,18 +54,18 @@ namespace ImageSharp /// Returns a copy of the image frame in the given pixel format. /// /// A function that allows for the correction of vector scaling between unknown color formats. - /// The pixel format. - /// The - public ImageFrame To(Func scaleFunc = null) - where TColor2 : struct, IPixel + /// The pixel format. + /// The + public ImageFrame To(Func scaleFunc = null) + where TPixel2 : struct, IPixel { - scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); + scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); - ImageFrame target = new ImageFrame(this.Width, this.Height, this.Configuration); + ImageFrame target = new ImageFrame(this.Width, this.Height, this.Configuration); target.CopyProperties(this); - using (PixelAccessor pixels = this.Lock()) - using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor pixels = this.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, @@ -74,7 +75,7 @@ namespace ImageSharp { for (int x = 0; x < target.Width; x++) { - TColor2 color = default(TColor2); + TPixel2 color = default(TPixel2); color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4())); targetPixels[x, y] = color; } @@ -87,10 +88,10 @@ namespace ImageSharp /// /// Clones the current instance. /// - /// The - internal virtual ImageFrame Clone() + /// The + internal virtual ImageFrame Clone() { - return new ImageFrame(this); + return new ImageFrame(this); } /// diff --git a/src/ImageSharp/Image/ImageProcessingExtensions.cs b/src/ImageSharp/Image/ImageProcessingExtensions.cs index ff3ecd5eef..c9577ac15f 100644 --- a/src/ImageSharp/Image/ImageProcessingExtensions.cs +++ b/src/ImageSharp/Image/ImageProcessingExtensions.cs @@ -5,11 +5,12 @@ namespace ImageSharp { - using System; + using ImageSharp.PixelFormats; + using Processing; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { @@ -17,12 +18,12 @@ namespace ImageSharp /// Applies the processor to the image. /// This method does not resize the target image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The processor to apply to the image. - /// The . - public static Image Apply(this Image source, IImageProcessor processor) - where TColor : struct, IPixel + /// The . + public static Image Apply(this Image source, IImageProcessor processor) + where TPixel : struct, IPixel { source.ApplyProcessor(processor, source.Bounds); return source; diff --git a/src/ImageSharp/Image/Image{TColor}.cs b/src/ImageSharp/Image/Image{TPixel}.cs similarity index 82% rename from src/ImageSharp/Image/Image{TColor}.cs rename to src/ImageSharp/Image/Image{TPixel}.cs index d063c3ff16..f49943b539 100644 --- a/src/ImageSharp/Image/Image{TColor}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -6,28 +6,27 @@ namespace ImageSharp { using System; - using System.Buffers; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; - using System.Text; using System.Threading.Tasks; using Formats; + using ImageSharp.PixelFormats; using Processing; /// /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// - /// The pixel format. + /// The pixel format. [DebuggerDisplay("Image: {Width}x{Height}")] - public class Image : ImageBase, IImage - where TColor : struct, IPixel + public class Image : ImageBase, IImage + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// with the height and the width of the image. /// /// The width of the image in pixels. @@ -41,7 +40,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// with the height and the width of the image. /// /// The width of the image in pixels. @@ -52,19 +51,19 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// by making a copy from another image. /// /// The other image, where the clone should be made from. /// is null. - public Image(Image other) + public Image(Image other) : base(other) { - foreach (ImageFrame frame in other.Frames) + foreach (ImageFrame frame in other.Frames) { if (frame != null) { - this.Frames.Add(new ImageFrame(frame)); + this.Frames.Add(new ImageFrame(frame)); } } @@ -72,19 +71,19 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// by making a copy from another image. /// /// The other image, where the clone should be made from. /// is null. - public Image(ImageBase other) + public Image(ImageBase other) : base(other) { this.MetaData = new ImageMetaData(); } /// - /// Initializes a new instance of the class + /// Initializes a new instance of the class /// with the height and the width of the image. /// /// The width of the image in pixels. @@ -138,7 +137,7 @@ namespace ImageSharp /// Gets the other frames for the animation. /// /// The list of frame images. - public IList> Frames { get; } = new List>(); + public IList> Frames { get; } = new List>(); /// /// Gets the currently loaded image format. @@ -150,11 +149,11 @@ namespace ImageSharp /// /// The processor to apply to the image. /// The structure that specifies the portion of the image object to draw. - public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { // we want to put this on on here as it gives us a really go place to test/verify processor settings base.ApplyProcessor(processor, rectangle); - foreach (ImageFrame sourceFrame in this.Frames) + foreach (ImageFrame sourceFrame in this.Frames) { sourceFrame.ApplyProcessor(processor, rectangle); } @@ -165,8 +164,8 @@ namespace ImageSharp /// /// The stream to save the image to. /// Thrown if the stream is null. - /// The - public Image Save(Stream stream) + /// The + public Image Save(Stream stream) { return this.Save(stream, (IEncoderOptions)null); } @@ -177,8 +176,8 @@ namespace ImageSharp /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. - /// The - public Image Save(Stream stream, IEncoderOptions options) + /// The + public Image Save(Stream stream, IEncoderOptions options) { return this.Save(stream, this.CurrentImageFormat?.Encoder, options); } @@ -188,8 +187,8 @@ namespace ImageSharp /// /// The stream to save the image to. /// The format to save the image as. - /// The - public Image Save(Stream stream, IImageFormat format) + /// The + public Image Save(Stream stream, IImageFormat format) { return this.Save(stream, format, null); } @@ -200,8 +199,8 @@ namespace ImageSharp /// The stream to save the image to. /// The format to save the image as. /// The options for the encoder. - /// The - public Image Save(Stream stream, IImageFormat format, IEncoderOptions options) + /// The + public Image Save(Stream stream, IImageFormat format, IEncoderOptions options) { Guard.NotNull(format, nameof(format)); @@ -215,9 +214,9 @@ namespace ImageSharp /// The encoder to save the image with. /// Thrown if the stream or encoder is null. /// - /// The . + /// The . /// - public Image Save(Stream stream, IImageEncoder encoder) + public Image Save(Stream stream, IImageEncoder encoder) { return this.Save(stream, encoder, null); } @@ -230,9 +229,9 @@ namespace ImageSharp /// The options for the encoder. /// Thrown if the stream or encoder is null. /// - /// The . + /// The . /// - public Image Save(Stream stream, IImageEncoder encoder, IEncoderOptions options) + public Image Save(Stream stream, IImageEncoder encoder, IEncoderOptions options) { Guard.NotNull(stream, nameof(stream)); Guard.NotNull(encoder, nameof(encoder)); @@ -248,8 +247,8 @@ namespace ImageSharp /// /// The file path to save the image to. /// Thrown if the stream is null. - /// The - public Image Save(string filePath) + /// The + public Image Save(string filePath) { return this.Save(filePath, (IEncoderOptions)null); } @@ -260,8 +259,8 @@ namespace ImageSharp /// The file path to save the image to. /// The options for the encoder. /// Thrown if the stream is null. - /// The - public Image Save(string filePath, IEncoderOptions options) + /// The + public Image Save(string filePath, IEncoderOptions options) { string ext = Path.GetExtension(filePath).Trim('.'); IImageFormat format = this.Configuration.ImageFormats.SingleOrDefault(f => f.SupportedExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase)); @@ -279,8 +278,8 @@ namespace ImageSharp /// The file path to save the image to. /// The format to save the image as. /// Thrown if the format is null. - /// The - public Image Save(string filePath, IImageFormat format) + /// The + public Image Save(string filePath, IImageFormat format) { return this.Save(filePath, format, null); } @@ -292,8 +291,8 @@ namespace ImageSharp /// The format to save the image as. /// The options for the encoder. /// Thrown if the format is null. - /// The - public Image Save(string filePath, IImageFormat format, IEncoderOptions options) + /// The + public Image Save(string filePath, IImageFormat format, IEncoderOptions options) { Guard.NotNull(format, nameof(format)); return this.Save(filePath, format.Encoder, options); @@ -305,8 +304,8 @@ namespace ImageSharp /// The file path to save the image to. /// The encoder to save the image with. /// Thrown if the encoder is null. - /// The - public Image Save(string filePath, IImageEncoder encoder) + /// The + public Image Save(string filePath, IImageEncoder encoder) { return this.Save(filePath, encoder, null); } @@ -318,8 +317,8 @@ namespace ImageSharp /// The encoder to save the image with. /// The options for the encoder. /// Thrown if the encoder is null. - /// The - public Image Save(string filePath, IImageEncoder encoder, IEncoderOptions options) + /// The + public Image Save(string filePath, IImageEncoder encoder, IEncoderOptions options) { Guard.NotNull(encoder, nameof(encoder)); using (Stream fs = this.Configuration.FileSystem.Create(filePath)) @@ -354,18 +353,18 @@ namespace ImageSharp /// Returns a copy of the image in the given pixel format. /// /// A function that allows for the correction of vector scaling between unknown color formats. - /// The pixel format. - /// The - public Image To(Func scaleFunc = null) - where TColor2 : struct, IPixel + /// The pixel format. + /// The + public Image To(Func scaleFunc = null) + where TPixel2 : struct, IPixel { - scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); + scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); - Image target = new Image(this.Width, this.Height, this.Configuration); + Image target = new Image(this.Width, this.Height, this.Configuration); target.CopyProperties(this); - using (PixelAccessor pixels = this.Lock()) - using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor pixels = this.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, @@ -375,7 +374,7 @@ namespace ImageSharp { for (int x = 0; x < target.Width; x++) { - TColor2 color = default(TColor2); + TPixel2 color = default(TPixel2); color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4())); targetPixels[x, y] = color; } @@ -384,19 +383,19 @@ namespace ImageSharp for (int i = 0; i < this.Frames.Count; i++) { - target.Frames.Add(this.Frames[i].To()); + target.Frames.Add(this.Frames[i].To()); } return target; } /// - /// Creates a new from this instance + /// Creates a new from this instance /// - /// The - internal virtual ImageFrame ToFrame() + /// The + internal virtual ImageFrame ToFrame() { - return new ImageFrame(this); + return new ImageFrame(this); } /// diff --git a/src/ImageSharp/Image/PixelAccessor{TColor}.cs b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs similarity index 87% rename from src/ImageSharp/Image/PixelAccessor{TColor}.cs rename to src/ImageSharp/Image/PixelAccessor{TPixel}.cs index fb3613adf4..3c67638869 100644 --- a/src/ImageSharp/Image/PixelAccessor{TColor}.cs +++ b/src/ImageSharp/Image/PixelAccessor{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -8,15 +8,15 @@ namespace ImageSharp using System; using System.Diagnostics; using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; using System.Threading.Tasks; + using ImageSharp.PixelFormats; /// - /// Provides per-pixel access to generic pixels. + /// Provides per-pixel access to generic pixels. /// - /// The pixel format. - public sealed class PixelAccessor : IDisposable, IBuffer2D - where TColor : struct, IPixel + /// The pixel format. + public sealed class PixelAccessor : IDisposable, IBuffer2D + where TPixel : struct, IPixel { /// /// A value indicating whether this instance of the given entity has been disposed. @@ -32,13 +32,13 @@ namespace ImageSharp /// /// The containing the pixel data. /// - private Buffer2D pixelBuffer; + private Buffer2D pixelBuffer; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image to provide pixel access for. - public PixelAccessor(ImageBase image) + public PixelAccessor(ImageBase image) { Guard.NotNull(image, nameof(image)); Guard.MustBeGreaterThan(image.Width, 0, "image width"); @@ -49,22 +49,22 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width of the image represented by the pixel buffer. /// The height of the image represented by the pixel buffer. public PixelAccessor(int width, int height) - : this(width, height, Buffer2D.CreateClean(width, height)) + : this(width, height, Buffer2D.CreateClean(width, height)) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width of the image represented by the pixel buffer. /// The height of the image represented by the pixel buffer. /// The pixel buffer. - private PixelAccessor(int width, int height, Buffer2D pixels) + private PixelAccessor(int width, int height, Buffer2D pixels) { Guard.NotNull(pixels, nameof(pixels)); Guard.MustBeGreaterThan(width, 0, nameof(width)); @@ -76,7 +76,7 @@ namespace ImageSharp } /// - /// Finalizes an instance of the class. + /// Finalizes an instance of the class. /// ~PixelAccessor() { @@ -86,7 +86,7 @@ namespace ImageSharp /// /// Gets the pixel buffer array. /// - public TColor[] PixelArray => this.pixelBuffer.Array; + public TPixel[] PixelArray => this.pixelBuffer.Array; /// /// Gets the size of a single pixel in the number of bytes. @@ -114,17 +114,17 @@ namespace ImageSharp public ParallelOptions ParallelOptions { get; } /// - BufferSpan IBuffer2D.Span => this.pixelBuffer; + BufferSpan IBuffer2D.Span => this.pixelBuffer; - private static BulkPixelOperations Operations => BulkPixelOperations.Instance; + private static BulkPixelOperations Operations => BulkPixelOperations.Instance; /// /// Gets or sets the pixel at the specified position. /// /// The x-coordinate of the pixel. Must be greater than or equal to zero and less than the width of the image. /// The y-coordinate of the pixel. Must be greater than or equal to zero and less than the height of the image. - /// The at the specified position. - public TColor this[int x, int y] + /// The at the specified position. + public TPixel this[int x, int y] { get { @@ -179,7 +179,7 @@ namespace ImageSharp /// /// Thrown when an unsupported component order value is passed. /// - internal void CopyFrom(PixelArea area, int targetY, int targetX = 0) + internal void CopyFrom(PixelArea area, int targetY, int targetX = 0) { this.CheckCoordinates(area, targetX, targetY); @@ -195,7 +195,7 @@ namespace ImageSharp /// /// Thrown when an unsupported component order value is passed. /// - internal void CopyTo(PixelArea area, int sourceY, int sourceX = 0) + internal void CopyTo(PixelArea area, int sourceY, int sourceX = 0) { this.CheckCoordinates(area, sourceX, sourceY); @@ -212,7 +212,7 @@ namespace ImageSharp /// /// Thrown when an unsupported component order value is passed. /// - internal void SafeCopyTo(PixelArea area, int sourceY, int sourceX = 0) + internal void SafeCopyTo(PixelArea area, int sourceY, int sourceX = 0) { int width = Math.Min(area.Width, this.Width - sourceX); if (width < 1) @@ -237,18 +237,18 @@ namespace ImageSharp /// The pixels. /// Returns the old pixel data thats has gust been replaced. /// If is true then caller is responsible for ensuring is called. - internal TColor[] ReturnCurrentPixelsAndReplaceThemInternally(int width, int height, TColor[] pixels) + internal TPixel[] ReturnCurrentColorsAndReplaceThemInternally(int width, int height, TPixel[] pixels) { - TColor[] oldPixels = this.pixelBuffer.TakeArrayOwnership(); + TPixel[] oldPixels = this.pixelBuffer.TakeArrayOwnership(); this.SetPixelBufferUnsafe(width, height, pixels); return oldPixels; } /// - /// Copies the pixels to another of the same size. + /// Copies the pixels to another of the same size. /// /// The target pixel buffer accessor. - internal void CopyTo(PixelAccessor target) + internal void CopyTo(PixelAccessor target) { BufferSpan.Copy(this.pixelBuffer.Span, target.pixelBuffer.Span); } @@ -262,12 +262,12 @@ namespace ImageSharp /// The width. /// The height. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CopyFromZyx(PixelArea area, int targetX, int targetY, int width, int height) + private void CopyFromZyx(PixelArea area, int targetX, int targetY, int width, int height) { for (int y = 0; y < height; y++) { BufferSpan source = area.GetRowSpan(y); - BufferSpan destination = this.GetRowSpan(targetX, targetY + y); + BufferSpan destination = this.GetRowSpan(targetX, targetY + y); Operations.PackFromZyxBytes(source, destination, width); } @@ -282,12 +282,12 @@ namespace ImageSharp /// The width. /// The height. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CopyFromZyxw(PixelArea area, int targetX, int targetY, int width, int height) + private void CopyFromZyxw(PixelArea area, int targetX, int targetY, int width, int height) { for (int y = 0; y < height; y++) { BufferSpan source = area.GetRowSpan(y); - BufferSpan destination = this.GetRowSpan(targetX, targetY + y); + BufferSpan destination = this.GetRowSpan(targetX, targetY + y); Operations.PackFromZyxwBytes(source, destination, width); } @@ -302,12 +302,12 @@ namespace ImageSharp /// The width. /// The height. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CopyFromXyz(PixelArea area, int targetX, int targetY, int width, int height) + private void CopyFromXyz(PixelArea area, int targetX, int targetY, int width, int height) { for (int y = 0; y < height; y++) { BufferSpan source = area.GetRowSpan(y); - BufferSpan destination = this.GetRowSpan(targetX, targetY + y); + BufferSpan destination = this.GetRowSpan(targetX, targetY + y); Operations.PackFromXyzBytes(source, destination, width); } @@ -322,12 +322,12 @@ namespace ImageSharp /// The width. /// The height. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CopyFromXyzw(PixelArea area, int targetX, int targetY, int width, int height) + private void CopyFromXyzw(PixelArea area, int targetX, int targetY, int width, int height) { for (int y = 0; y < height; y++) { BufferSpan source = area.GetRowSpan(y); - BufferSpan destination = this.GetRowSpan(targetX, targetY + y); + BufferSpan destination = this.GetRowSpan(targetX, targetY + y); Operations.PackFromXyzwBytes(source, destination, width); } } @@ -341,11 +341,11 @@ namespace ImageSharp /// The width. /// The height. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CopyToZyx(PixelArea area, int sourceX, int sourceY, int width, int height) + private void CopyToZyx(PixelArea area, int sourceX, int sourceY, int width, int height) { for (int y = 0; y < height; y++) { - BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); + BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); BufferSpan destination = area.GetRowSpan(y); Operations.ToZyxBytes(source, destination, width); } @@ -360,11 +360,11 @@ namespace ImageSharp /// The width. /// The height. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CopyToZyxw(PixelArea area, int sourceX, int sourceY, int width, int height) + private void CopyToZyxw(PixelArea area, int sourceX, int sourceY, int width, int height) { for (int y = 0; y < height; y++) { - BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); + BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); BufferSpan destination = area.GetRowSpan(y); Operations.ToZyxwBytes(source, destination, width); } @@ -379,11 +379,11 @@ namespace ImageSharp /// The width. /// The height. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CopyToXyz(PixelArea area, int sourceX, int sourceY, int width, int height) + private void CopyToXyz(PixelArea area, int sourceX, int sourceY, int width, int height) { for (int y = 0; y < height; y++) { - BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); + BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); BufferSpan destination = area.GetRowSpan(y); Operations.ToXyzBytes(source, destination, width); } @@ -398,19 +398,19 @@ namespace ImageSharp /// The width. /// The height. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void CopyToXyzw(PixelArea area, int sourceX, int sourceY, int width, int height) + private void CopyToXyzw(PixelArea area, int sourceX, int sourceY, int width, int height) { for (int y = 0; y < height; y++) { - BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); + BufferSpan source = this.GetRowSpan(sourceX, sourceY + y); BufferSpan destination = area.GetRowSpan(y); Operations.ToXyzwBytes(source, destination, width); } } - private void SetPixelBufferUnsafe(int width, int height, TColor[] pixels) + private void SetPixelBufferUnsafe(int width, int height, TPixel[] pixels) { - this.SetPixelBufferUnsafe(width, height, new Buffer2D(pixels, width, height)); + this.SetPixelBufferUnsafe(width, height, new Buffer2D(pixels, width, height)); } /// @@ -419,13 +419,13 @@ namespace ImageSharp /// The width. /// The height. /// The pixel buffer - private void SetPixelBufferUnsafe(int width, int height, Buffer2D pixels) + private void SetPixelBufferUnsafe(int width, int height, Buffer2D pixels) { this.pixelBuffer = pixels; this.Width = width; this.Height = height; - this.PixelSize = Unsafe.SizeOf(); + this.PixelSize = Unsafe.SizeOf(); this.RowStride = this.Width * this.PixelSize; } @@ -440,7 +440,7 @@ namespace ImageSharp /// /// Thrown when an unsupported component order value is passed. /// - private void CopyFrom(PixelArea area, int targetX, int targetY, int width, int height) + private void CopyFrom(PixelArea area, int targetX, int targetY, int width, int height) { switch (area.ComponentOrder) { @@ -472,7 +472,7 @@ namespace ImageSharp /// /// Thrown when an unsupported component order value is passed. /// - private void CopyTo(PixelArea area, int sourceX, int sourceY, int width, int height) + private void CopyTo(PixelArea area, int sourceX, int sourceY, int width, int height) { switch (area.ComponentOrder) { @@ -503,7 +503,7 @@ namespace ImageSharp /// Thrown if the dimensions are not within the bounds of the image. /// [Conditional("DEBUG")] - private void CheckCoordinates(PixelArea area, int x, int y) + private void CheckCoordinates(PixelArea area, int x, int y) { int width = Math.Min(area.Width, this.Width - x); if (width < 1) diff --git a/src/ImageSharp/Image/PixelArea{TColor}.cs b/src/ImageSharp/Image/PixelArea{TPixel}.cs similarity index 94% rename from src/ImageSharp/Image/PixelArea{TColor}.cs rename to src/ImageSharp/Image/PixelArea{TPixel}.cs index 176eb0a160..3dd187768e 100644 --- a/src/ImageSharp/Image/PixelArea{TColor}.cs +++ b/src/ImageSharp/Image/PixelArea{TPixel}.cs @@ -1,20 +1,21 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // + namespace ImageSharp { using System; using System.Diagnostics; using System.IO; - using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; /// - /// Represents an area of generic pixels. + /// Represents an area of generic pixels. /// - /// The pixel format. - internal sealed class PixelArea : IDisposable - where TColor : struct, IPixel + /// The pixel format. + internal sealed class PixelArea : IDisposable + where TPixel : struct, IPixel { /// /// A value indicating whether this instance of the given entity has been disposed. @@ -33,7 +34,7 @@ namespace ImageSharp private Buffer byteBuffer; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The bytes. @@ -47,7 +48,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The height. @@ -70,7 +71,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The component order. @@ -80,7 +81,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The component order. @@ -91,7 +92,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The height. @@ -102,7 +103,7 @@ namespace ImageSharp } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The width. /// The height. diff --git a/src/ImageSharp/ImageProcessor.cs b/src/ImageSharp/ImageProcessor.cs index 79525a8e83..7b9f745471 100644 --- a/src/ImageSharp/ImageProcessor.cs +++ b/src/ImageSharp/ImageProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing using System; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Allows the application of processors to images. /// - /// The pixel format. - internal abstract class ImageProcessor : IImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal abstract class ImageProcessor : IImageProcessor + where TPixel : struct, IPixel { /// public virtual ParallelOptions ParallelOptions { get; set; } @@ -22,7 +24,7 @@ namespace ImageSharp.Processing public virtual bool Compand { get; set; } = false; /// - public void Apply(ImageBase source, Rectangle sourceRectangle) + public void Apply(ImageBase source, Rectangle sourceRectangle) { if (this.ParallelOptions == null) { @@ -50,19 +52,19 @@ namespace ImageSharp.Processing /// /// The structure that specifies the portion of the image object to draw. /// - protected virtual void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected virtual void BeforeApply(ImageBase source, Rectangle sourceRectangle) { } /// - /// Applies the process to the specified portion of the specified at the specified location + /// Applies the process to the specified portion of the specified at the specified location /// and with the specified size. /// /// The source image. Cannot be null. /// /// The structure that specifies the portion of the image object to draw. /// - protected abstract void OnApply(ImageBase source, Rectangle sourceRectangle); + protected abstract void OnApply(ImageBase source, Rectangle sourceRectangle); /// /// This method is called after the process is applied to prepare the processor. @@ -71,7 +73,7 @@ namespace ImageSharp.Processing /// /// The structure that specifies the portion of the image object to draw. /// - protected virtual void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected virtual void AfterApply(ImageBase source, Rectangle sourceRectangle) { } } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 303e511d7e..64183d05cc 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -2,7 +2,7 @@ A cross-platform library for the processing of image files; written in C# ImageSharp - 1.0.0-alpha6 + 1.0.0-alpha7 James Jackson-South and contributors netstandard1.3;netstandard1.1 true diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs index c4a94c5ff1..f65c020431 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs @@ -10,6 +10,8 @@ namespace ImageSharp using System.Collections.ObjectModel; using System.IO; + using ImageSharp.PixelFormats; + /// /// Represents an EXIF profile providing access to the collection of values. /// @@ -116,12 +118,12 @@ namespace ImageSharp /// /// Returns the thumbnail in the EXIF profile when available. /// - /// The pixel format. + /// The pixel format. /// - /// The . + /// The . /// - public Image CreateThumbnail() - where TColor : struct, IPixel + public Image CreateThumbnail() + where TPixel : struct, IPixel { this.InitializeValues(); @@ -137,7 +139,7 @@ namespace ImageSharp using (MemoryStream memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength)) { - return Image.Load(memStream); + return Image.Load(memStream); } } diff --git a/src/ImageSharp/Colors/PackedPixel/Alpha8.cs b/src/ImageSharp/PixelFormats/Alpha8.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Alpha8.cs rename to src/ImageSharp/PixelFormats/Alpha8.cs index 9a340544cf..5e2fff5d02 100644 --- a/src/ImageSharp/Colors/PackedPixel/Alpha8.cs +++ b/src/ImageSharp/PixelFormats/Alpha8.cs @@ -3,14 +3,15 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; using System.Runtime.CompilerServices; /// - /// Packed pixel type containing a single 8 bit normalized W values ranging from 0 to 1. + /// Packed pixel type containing a single 8 bit normalized W values. + /// Ranges from <0, 0, 0, 0> to <0, 0, 0, 1> in vector form. /// public struct Alpha8 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/Argb32.cs b/src/ImageSharp/PixelFormats/Argb32.cs similarity index 99% rename from src/ImageSharp/Colors/PackedPixel/Argb32.cs rename to src/ImageSharp/PixelFormats/Argb32.cs index 64255a53b5..a6db505bbc 100644 --- a/src/ImageSharp/Colors/PackedPixel/Argb32.cs +++ b/src/ImageSharp/PixelFormats/Argb32.cs @@ -3,15 +3,15 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { - using System; using System.Numerics; using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// The color components are stored in alpha, red, green, and blue order. + /// Ranges from <0, 0, 0, 0> to <1, 1, 1, 1> in vector form. /// /// /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, diff --git a/src/ImageSharp/Colors/PackedPixel/Bgr565.cs b/src/ImageSharp/PixelFormats/Bgr565.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Bgr565.cs rename to src/ImageSharp/PixelFormats/Bgr565.cs index 2975d4ad90..a3d8cbcf28 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgr565.cs +++ b/src/ImageSharp/PixelFormats/Bgr565.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x and z components use 5 bits, and the y component uses 6 bits. + /// Ranges from <0, 0, 0, 1> to <1, 1, 1, 1> in vector form. /// public struct Bgr565 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs b/src/ImageSharp/PixelFormats/Bgra4444.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Bgra4444.cs rename to src/ImageSharp/PixelFormats/Bgra4444.cs index 1346a54efc..8d4e9b4f47 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs +++ b/src/ImageSharp/PixelFormats/Bgra4444.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed pixel type containing unsigned normalized values, ranging from 0 to 1, using 4 bits each for x, y, z, and w. + /// Ranges from <0, 0, 0, 0> to <1, 1, 1, 1> in vector form. /// public struct Bgra4444 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs b/src/ImageSharp/PixelFormats/Bgra5551.cs similarity index 99% rename from src/ImageSharp/Colors/PackedPixel/Bgra5551.cs rename to src/ImageSharp/PixelFormats/Bgra5551.cs index 7989804cfb..8ae1cd4304 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs +++ b/src/ImageSharp/PixelFormats/Bgra5551.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; diff --git a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs b/src/ImageSharp/PixelFormats/BulkPixelOperations{TPixel}.cs similarity index 77% rename from src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs rename to src/ImageSharp/PixelFormats/BulkPixelOperations{TPixel}.cs index db0251703f..9a3d266c13 100644 --- a/src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs +++ b/src/ImageSharp/PixelFormats/BulkPixelOperations{TPixel}.cs @@ -1,25 +1,25 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System.Numerics; using System.Runtime.CompilerServices; /// /// A stateless class implementing Strategy Pattern for batched pixel-data conversion operations - /// for pixel buffers of type . + /// for pixel buffers of type . /// - /// The pixel format. - public class BulkPixelOperations - where TColor : struct, IPixel + /// The pixel format. + public class BulkPixelOperations + where TPixel : struct, IPixel { /// - /// Gets the global instance for the pixel type + /// Gets the global instance for the pixel type /// - public static BulkPixelOperations Instance { get; } = default(TColor).CreateBulkOperations(); + public static BulkPixelOperations Instance { get; } = default(TPixel).CreateBulkOperations(); /// /// Bulk version of @@ -27,15 +27,15 @@ namespace ImageSharp /// The to the source vectors. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromVector4(BufferSpan sourceVectors, BufferSpan destColors, int count) + internal virtual void PackFromVector4(BufferSpan sourceVectors, BufferSpan destColors, int count) { ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference(); - ref TColor destRef = ref destColors.DangerousGetPinnableReference(); + ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { ref Vector4 sp = ref Unsafe.Add(ref sourceRef, i); - ref TColor dp = ref Unsafe.Add(ref destRef, i); + ref TPixel dp = ref Unsafe.Add(ref destRef, i); dp.PackFromVector4(sp); } } @@ -46,14 +46,14 @@ namespace ImageSharp /// The to the source colors. /// The to the destination vectors. /// The number of pixels to convert. - internal virtual void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) + internal virtual void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) { - ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { - ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); ref Vector4 dp = ref Unsafe.Add(ref destRef, i); dp = sp.ToVector4(); } @@ -65,15 +65,15 @@ namespace ImageSharp /// The to the source bytes. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal virtual void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); - ref TColor destRef = ref destColors.DangerousGetPinnableReference(); + ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { int i3 = i * 3; - ref TColor dp = ref Unsafe.Add(ref destRef, i); + ref TPixel dp = ref Unsafe.Add(ref destRef, i); dp.PackFromBytes( Unsafe.Add(ref sourceRef, i3), Unsafe.Add(ref sourceRef, i3 + 1), @@ -88,14 +88,14 @@ namespace ImageSharp /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - internal virtual void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal virtual void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; for (int i = 0; i < count; i++) { - ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); sp.ToXyzBytes(dest, destBytes.Start + (i * 3)); } } @@ -106,15 +106,15 @@ namespace ImageSharp /// The to the source bytes. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal virtual void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); - ref TColor destRef = ref destColors.DangerousGetPinnableReference(); + ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { int i4 = i * 4; - ref TColor dp = ref Unsafe.Add(ref destRef, i); + ref TPixel dp = ref Unsafe.Add(ref destRef, i); dp.PackFromBytes( Unsafe.Add(ref sourceRef, i4), Unsafe.Add(ref sourceRef, i4 + 1), @@ -129,14 +129,14 @@ namespace ImageSharp /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - internal virtual void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal virtual void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; for (int i = 0; i < count; i++) { - ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); sp.ToXyzwBytes(dest, destBytes.Start + (i * 4)); } } @@ -147,15 +147,15 @@ namespace ImageSharp /// The to the source bytes. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal virtual void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); - ref TColor destRef = ref destColors.DangerousGetPinnableReference(); + ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { int i3 = i * 3; - ref TColor dp = ref Unsafe.Add(ref destRef, i); + ref TPixel dp = ref Unsafe.Add(ref destRef, i); dp.PackFromBytes( Unsafe.Add(ref sourceRef, i3 + 2), Unsafe.Add(ref sourceRef, i3 + 1), @@ -170,14 +170,14 @@ namespace ImageSharp /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - internal virtual void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal virtual void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; for (int i = 0; i < count; i++) { - ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); sp.ToZyxBytes(dest, destBytes.Start + (i * 3)); } } @@ -188,15 +188,15 @@ namespace ImageSharp /// The to the source bytes. /// The to the destination colors. /// The number of pixels to convert. - internal virtual void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal virtual void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); - ref TColor destRef = ref destColors.DangerousGetPinnableReference(); + ref TPixel destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { int i4 = i * 4; - ref TColor dp = ref Unsafe.Add(ref destRef, i); + ref TPixel dp = ref Unsafe.Add(ref destRef, i); dp.PackFromBytes( Unsafe.Add(ref sourceRef, i4 + 2), Unsafe.Add(ref sourceRef, i4 + 1), @@ -211,14 +211,14 @@ namespace ImageSharp /// The to the source colors. /// The to the destination bytes. /// The number of pixels to convert. - internal virtual void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal virtual void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference(); byte[] dest = destBytes.Array; for (int i = 0; i < count; i++) { - ref TColor sp = ref Unsafe.Add(ref sourceRef, i); + ref TPixel sp = ref Unsafe.Add(ref sourceRef, i); sp.ToZyxwBytes(dest, destBytes.Start + (i * 4)); } } diff --git a/src/ImageSharp/Colors/PackedPixel/Byte4.cs b/src/ImageSharp/PixelFormats/Byte4.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Byte4.cs rename to src/ImageSharp/PixelFormats/Byte4.cs index 11ec5eaf4b..acb73dd1c0 100644 --- a/src/ImageSharp/Colors/PackedPixel/Byte4.cs +++ b/src/ImageSharp/PixelFormats/Byte4.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 8-bit unsigned integer values, ranging from 0 to 255. + /// Ranges from <0, 0, 0, 0> to <1, 1, 1, 1> in vector form. /// public struct Byte4 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/ColorBuilder{TColor}.cs b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs similarity index 77% rename from src/ImageSharp/Colors/ColorBuilder{TColor}.cs rename to src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs index f60b5c8c09..4b21130c0d 100644 --- a/src/ImageSharp/Colors/ColorBuilder{TColor}.cs +++ b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs @@ -1,9 +1,9 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Globalization; @@ -11,19 +11,19 @@ namespace ImageSharp /// /// A set of named colors mapped to the provided Color space. /// - /// The type of the color. - public static class ColorBuilder - where TColor : struct, IPixel + /// The type of the color. + public static class ColorBuilder + where TPixel : struct, IPixel { /// - /// Creates a new representation from the string representing a color. + /// Creates a new representation from the string representing a color. /// /// /// The hexadecimal representation of the combined color components arranged /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax. /// - /// Returns a that represents the color defined by the provided RGBA heax string. - public static TColor FromHex(string hex) + /// Returns a that represents the color defined by the provided RGBA heax string. + public static TPixel FromHex(string hex) { Guard.NotNullOrEmpty(hex, nameof(hex)); @@ -34,7 +34,7 @@ namespace ImageSharp throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex)); } - TColor result = default(TColor); + TPixel result = default(TPixel); result.PackFromBytes( (byte)(packedValue >> 24), @@ -45,30 +45,30 @@ namespace ImageSharp } /// - /// Creates a new representation from standard RGB bytes with 100% opacity. + /// Creates a new representation from standard RGB bytes with 100% opacity. /// /// The red intensity. /// The green intensity. /// The blue intensity. - /// Returns a that represents the color defined by the provided RGB values with 100% opacity. - public static TColor FromRGB(byte red, byte green, byte blue) + /// Returns a that represents the color defined by the provided RGB values with 100% opacity. + public static TPixel FromRGB(byte red, byte green, byte blue) { - TColor color = default(TColor); + TPixel color = default(TPixel); color.PackFromBytes(red, green, blue, 255); return color; } /// - /// Creates a new representation from standard RGBA bytes. + /// Creates a new representation from standard RGBA bytes. /// /// The red intensity. /// The green intensity. /// The blue intensity. /// The alpha intensity. - /// Returns a that represents the color defined by the provided RGBA values. - public static TColor FromRGBA(byte red, byte green, byte blue, byte alpha) + /// Returns a that represents the color defined by the provided RGBA values. + public static TPixel FromRGBA(byte red, byte green, byte blue, byte alpha) { - TColor color = default(TColor); + TPixel color = default(TPixel); color.PackFromBytes(red, green, blue, alpha); return color; } diff --git a/src/ImageSharp/PixelFormats/ColorConstants.cs b/src/ImageSharp/PixelFormats/ColorConstants.cs new file mode 100644 index 0000000000..236d3a889e --- /dev/null +++ b/src/ImageSharp/PixelFormats/ColorConstants.cs @@ -0,0 +1,179 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.PixelFormats +{ + using System; + using System.Collections.Generic; + + /// + /// Provides useful color definitions. + /// + public static class ColorConstants + { + /// + /// Provides a lazy, one time method of returning the colors. + /// + private static readonly Lazy SafeColors = new Lazy(GetWebSafeColors); + + /// + /// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4. + /// + public static Rgba32[] WebSafeColors => SafeColors.Value; + + /// + /// Returns an array of web safe colors. + /// + /// The + private static Rgba32[] GetWebSafeColors() + { + return new List + { + Rgba32.AliceBlue, + Rgba32.AntiqueWhite, + Rgba32.Aqua, + Rgba32.Aquamarine, + Rgba32.Azure, + Rgba32.Beige, + Rgba32.Bisque, + Rgba32.Black, + Rgba32.BlanchedAlmond, + Rgba32.Blue, + Rgba32.BlueViolet, + Rgba32.Brown, + Rgba32.BurlyWood, + Rgba32.CadetBlue, + Rgba32.Chartreuse, + Rgba32.Chocolate, + Rgba32.Coral, + Rgba32.CornflowerBlue, + Rgba32.Cornsilk, + Rgba32.Crimson, + Rgba32.Cyan, + Rgba32.DarkBlue, + Rgba32.DarkCyan, + Rgba32.DarkGoldenrod, + Rgba32.DarkGray, + Rgba32.DarkGreen, + Rgba32.DarkKhaki, + Rgba32.DarkMagenta, + Rgba32.DarkOliveGreen, + Rgba32.DarkOrange, + Rgba32.DarkOrchid, + Rgba32.DarkRed, + Rgba32.DarkSalmon, + Rgba32.DarkSeaGreen, + Rgba32.DarkSlateBlue, + Rgba32.DarkSlateGray, + Rgba32.DarkTurquoise, + Rgba32.DarkViolet, + Rgba32.DeepPink, + Rgba32.DeepSkyBlue, + Rgba32.DimGray, + Rgba32.DodgerBlue, + Rgba32.Firebrick, + Rgba32.FloralWhite, + Rgba32.ForestGreen, + Rgba32.Fuchsia, + Rgba32.Gainsboro, + Rgba32.GhostWhite, + Rgba32.Gold, + Rgba32.Goldenrod, + Rgba32.Gray, + Rgba32.Green, + Rgba32.GreenYellow, + Rgba32.Honeydew, + Rgba32.HotPink, + Rgba32.IndianRed, + Rgba32.Indigo, + Rgba32.Ivory, + Rgba32.Khaki, + Rgba32.Lavender, + Rgba32.LavenderBlush, + Rgba32.LawnGreen, + Rgba32.LemonChiffon, + Rgba32.LightBlue, + Rgba32.LightCoral, + Rgba32.LightCyan, + Rgba32.LightGoldenrodYellow, + Rgba32.LightGray, + Rgba32.LightGreen, + Rgba32.LightPink, + Rgba32.LightSalmon, + Rgba32.LightSeaGreen, + Rgba32.LightSkyBlue, + Rgba32.LightSlateGray, + Rgba32.LightSteelBlue, + Rgba32.LightYellow, + Rgba32.Lime, + Rgba32.LimeGreen, + Rgba32.Linen, + Rgba32.Magenta, + Rgba32.Maroon, + Rgba32.MediumAquamarine, + Rgba32.MediumBlue, + Rgba32.MediumOrchid, + Rgba32.MediumPurple, + Rgba32.MediumSeaGreen, + Rgba32.MediumSlateBlue, + Rgba32.MediumSpringGreen, + Rgba32.MediumTurquoise, + Rgba32.MediumVioletRed, + Rgba32.MidnightBlue, + Rgba32.MintCream, + Rgba32.MistyRose, + Rgba32.Moccasin, + Rgba32.NavajoWhite, + Rgba32.Navy, + Rgba32.OldLace, + Rgba32.Olive, + Rgba32.OliveDrab, + Rgba32.Orange, + Rgba32.OrangeRed, + Rgba32.Orchid, + Rgba32.PaleGoldenrod, + Rgba32.PaleGreen, + Rgba32.PaleTurquoise, + Rgba32.PaleVioletRed, + Rgba32.PapayaWhip, + Rgba32.PeachPuff, + Rgba32.Peru, + Rgba32.Pink, + Rgba32.Plum, + Rgba32.PowderBlue, + Rgba32.Purple, + Rgba32.RebeccaPurple, + Rgba32.Red, + Rgba32.RosyBrown, + Rgba32.RoyalBlue, + Rgba32.SaddleBrown, + Rgba32.Salmon, + Rgba32.SandyBrown, + Rgba32.SeaGreen, + Rgba32.SeaShell, + Rgba32.Sienna, + Rgba32.Silver, + Rgba32.SkyBlue, + Rgba32.SlateBlue, + Rgba32.SlateGray, + Rgba32.Snow, + Rgba32.SpringGreen, + Rgba32.SteelBlue, + Rgba32.Tan, + Rgba32.Teal, + Rgba32.Thistle, + Rgba32.Tomato, + Rgba32.Transparent, + Rgba32.Turquoise, + Rgba32.Violet, + Rgba32.Wheat, + Rgba32.White, + Rgba32.WhiteSmoke, + Rgba32.Yellow, + Rgba32.YellowGreen + }.ToArray(); + } + } +} diff --git a/src/ImageSharp/Colors/ComponentOrder.cs b/src/ImageSharp/PixelFormats/ComponentOrder.cs similarity index 88% rename from src/ImageSharp/Colors/ComponentOrder.cs rename to src/ImageSharp/PixelFormats/ComponentOrder.cs index 03fa3bbf81..8f151b41d6 100644 --- a/src/ImageSharp/Colors/ComponentOrder.cs +++ b/src/ImageSharp/PixelFormats/ComponentOrder.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { /// /// Enumerates the various component orders. @@ -11,22 +11,22 @@ namespace ImageSharp public enum ComponentOrder { /// - /// Z-> Y-> X order. Equivalent to B-> G-> R in + /// Z-> Y-> X order. Equivalent to B-> G-> R in /// Zyx, /// - /// Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in + /// Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in /// Zyxw, /// - /// X-> Y-> Z order. Equivalent to R-> G-> B in + /// X-> Y-> Z order. Equivalent to R-> G-> B in /// Xyz, /// - /// X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in + /// X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in /// Xyzw, } diff --git a/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs b/src/ImageSharp/PixelFormats/HalfSingle.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/HalfSingle.cs rename to src/ImageSharp/PixelFormats/HalfSingle.cs index 4c785a8636..893667fc78 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs +++ b/src/ImageSharp/PixelFormats/HalfSingle.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { - using System; using System.Numerics; using System.Runtime.CompilerServices; /// /// Packed pixel type containing a single 16 bit floating point value. + /// Ranges from <0, 0, 0, 1> to <1, 0, 0, 1> in vector form. /// public struct HalfSingle : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/HalfTypeHelper.cs b/src/ImageSharp/PixelFormats/HalfTypeHelper.cs similarity index 99% rename from src/ImageSharp/Colors/PackedPixel/HalfTypeHelper.cs rename to src/ImageSharp/PixelFormats/HalfTypeHelper.cs index a19b513230..740795adc6 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfTypeHelper.cs +++ b/src/ImageSharp/PixelFormats/HalfTypeHelper.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs b/src/ImageSharp/PixelFormats/HalfVector2.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/HalfVector2.cs rename to src/ImageSharp/PixelFormats/HalfVector2.cs index d06ab6ba07..bd3cda55d0 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs +++ b/src/ImageSharp/PixelFormats/HalfVector2.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { - using System; using System.Numerics; using System.Runtime.CompilerServices; /// /// Packed pixel type containing two 16-bit floating-point values. + /// Ranges from <0, 0, 0, 1> to <1, 0, 0, 1> in vector form. /// public struct HalfVector2 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs b/src/ImageSharp/PixelFormats/HalfVector4.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/HalfVector4.cs rename to src/ImageSharp/PixelFormats/HalfVector4.cs index a5fa796e1d..03e4326b70 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs +++ b/src/ImageSharp/PixelFormats/HalfVector4.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { - using System; using System.Numerics; using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 16-bit floating-point values. + /// Ranges from <0, 0, 0, 0> to <1, 1, 1, 1> in vector form. /// public struct HalfVector4 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/IPackedVector{TPacked}.cs b/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs similarity index 94% rename from src/ImageSharp/Colors/PackedPixel/IPackedVector{TPacked}.cs rename to src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs index 0450fb8fba..ec283e6f2a 100644 --- a/src/ImageSharp/Colors/PackedPixel/IPackedVector{TPacked}.cs +++ b/src/ImageSharp/PixelFormats/IPackedVector{TPacked}.cs @@ -3,10 +3,9 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; - using System.Numerics; /// /// This interface exists for ensuring signature compatibility to MonoGame and XNA packed color types. diff --git a/src/ImageSharp/Colors/PackedPixel/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs similarity index 90% rename from src/ImageSharp/Colors/PackedPixel/IPixel.cs rename to src/ImageSharp/PixelFormats/IPixel.cs index 67e013a422..43fe81e953 100644 --- a/src/ImageSharp/Colors/PackedPixel/IPixel.cs +++ b/src/ImageSharp/PixelFormats/IPixel.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -16,10 +16,10 @@ namespace ImageSharp where TSelf : struct, IPixel { /// - /// Creates a instance for this pixel type. - /// This method is not intended to be consumed directly. Use instead. + /// Creates a instance for this pixel type. + /// This method is not intended to be consumed directly. Use instead. /// - /// The instance. + /// The instance. BulkPixelOperations CreateBulkOperations(); } @@ -52,7 +52,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to X-> Y-> Z order. Equivalent to R-> G-> B in + /// Output is expanded to X-> Y-> Z order. Equivalent to R-> G-> B in /// /// The bytes to set the color in. /// The starting index of the . @@ -60,7 +60,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in + /// Output is expanded to X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in /// /// The bytes to set the color in. /// The starting index of the . @@ -68,7 +68,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to Z-> Y-> X order. Equivalent to B-> G-> R in + /// Output is expanded to Z-> Y-> X order. Equivalent to B-> G-> R in /// /// The bytes to set the color in. /// The starting index of the . @@ -76,7 +76,7 @@ namespace ImageSharp /// /// Expands the packed representation into a given byte array. - /// Output is expanded to Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in + /// Output is expanded to Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in /// /// The bytes to set the color in. /// The starting index of the . diff --git a/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs b/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs new file mode 100644 index 0000000000..0b55dcbf91 --- /dev/null +++ b/src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs @@ -0,0 +1,725 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.PixelFormats +{ + /// + /// A set of named colors mapped to the provided color space. + /// + /// The type of the color. + public static class NamedColors + where TPixel : struct, IPixel + { + /// + /// Represents a matching the W3C definition that has an hex value of #F0F8FF. + /// + public static readonly TPixel AliceBlue = ColorBuilder.FromRGBA(240, 248, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FAEBD7. + /// + public static readonly TPixel AntiqueWhite = ColorBuilder.FromRGBA(250, 235, 215, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly TPixel Aqua = ColorBuilder.FromRGBA(0, 255, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFFD4. + /// + public static readonly TPixel Aquamarine = ColorBuilder.FromRGBA(127, 255, 212, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFFF. + /// + public static readonly TPixel Azure = ColorBuilder.FromRGBA(240, 255, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5DC. + /// + public static readonly TPixel Beige = ColorBuilder.FromRGBA(245, 245, 220, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4C4. + /// + public static readonly TPixel Bisque = ColorBuilder.FromRGBA(255, 228, 196, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #000000. + /// + public static readonly TPixel Black = ColorBuilder.FromRGBA(0, 0, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEBCD. + /// + public static readonly TPixel BlanchedAlmond = ColorBuilder.FromRGBA(255, 235, 205, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #0000FF. + /// + public static readonly TPixel Blue = ColorBuilder.FromRGBA(0, 0, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #8A2BE2. + /// + public static readonly TPixel BlueViolet = ColorBuilder.FromRGBA(138, 43, 226, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #A52A2A. + /// + public static readonly TPixel Brown = ColorBuilder.FromRGBA(165, 42, 42, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #DEB887. + /// + public static readonly TPixel BurlyWood = ColorBuilder.FromRGBA(222, 184, 135, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #5F9EA0. + /// + public static readonly TPixel CadetBlue = ColorBuilder.FromRGBA(95, 158, 160, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFF00. + /// + public static readonly TPixel Chartreuse = ColorBuilder.FromRGBA(127, 255, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #D2691E. + /// + public static readonly TPixel Chocolate = ColorBuilder.FromRGBA(210, 105, 30, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF7F50. + /// + public static readonly TPixel Coral = ColorBuilder.FromRGBA(255, 127, 80, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #6495ED. + /// + public static readonly TPixel CornflowerBlue = ColorBuilder.FromRGBA(100, 149, 237, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF8DC. + /// + public static readonly TPixel Cornsilk = ColorBuilder.FromRGBA(255, 248, 220, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #DC143C. + /// + public static readonly TPixel Crimson = ColorBuilder.FromRGBA(220, 20, 60, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly TPixel Cyan = ColorBuilder.FromRGBA(0, 255, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #00008B. + /// + public static readonly TPixel DarkBlue = ColorBuilder.FromRGBA(0, 0, 139, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #008B8B. + /// + public static readonly TPixel DarkCyan = ColorBuilder.FromRGBA(0, 139, 139, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #B8860B. + /// + public static readonly TPixel DarkGoldenrod = ColorBuilder.FromRGBA(184, 134, 11, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #A9A9A9. + /// + public static readonly TPixel DarkGray = ColorBuilder.FromRGBA(169, 169, 169, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #006400. + /// + public static readonly TPixel DarkGreen = ColorBuilder.FromRGBA(0, 100, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #BDB76B. + /// + public static readonly TPixel DarkKhaki = ColorBuilder.FromRGBA(189, 183, 107, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #8B008B. + /// + public static readonly TPixel DarkMagenta = ColorBuilder.FromRGBA(139, 0, 139, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #556B2F. + /// + public static readonly TPixel DarkOliveGreen = ColorBuilder.FromRGBA(85, 107, 47, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF8C00. + /// + public static readonly TPixel DarkOrange = ColorBuilder.FromRGBA(255, 140, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #9932CC. + /// + public static readonly TPixel DarkOrchid = ColorBuilder.FromRGBA(153, 50, 204, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #8B0000. + /// + public static readonly TPixel DarkRed = ColorBuilder.FromRGBA(139, 0, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #E9967A. + /// + public static readonly TPixel DarkSalmon = ColorBuilder.FromRGBA(233, 150, 122, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #8FBC8B. + /// + public static readonly TPixel DarkSeaGreen = ColorBuilder.FromRGBA(143, 188, 139, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #483D8B. + /// + public static readonly TPixel DarkSlateBlue = ColorBuilder.FromRGBA(72, 61, 139, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #2F4F4F. + /// + public static readonly TPixel DarkSlateGray = ColorBuilder.FromRGBA(47, 79, 79, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #00CED1. + /// + public static readonly TPixel DarkTurquoise = ColorBuilder.FromRGBA(0, 206, 209, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #9400D3. + /// + public static readonly TPixel DarkViolet = ColorBuilder.FromRGBA(148, 0, 211, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF1493. + /// + public static readonly TPixel DeepPink = ColorBuilder.FromRGBA(255, 20, 147, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #00BFFF. + /// + public static readonly TPixel DeepSkyBlue = ColorBuilder.FromRGBA(0, 191, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #696969. + /// + public static readonly TPixel DimGray = ColorBuilder.FromRGBA(105, 105, 105, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #1E90FF. + /// + public static readonly TPixel DodgerBlue = ColorBuilder.FromRGBA(30, 144, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #B22222. + /// + public static readonly TPixel Firebrick = ColorBuilder.FromRGBA(178, 34, 34, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAF0. + /// + public static readonly TPixel FloralWhite = ColorBuilder.FromRGBA(255, 250, 240, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #228B22. + /// + public static readonly TPixel ForestGreen = ColorBuilder.FromRGBA(34, 139, 34, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly TPixel Fuchsia = ColorBuilder.FromRGBA(255, 0, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #DCDCDC. + /// + public static readonly TPixel Gainsboro = ColorBuilder.FromRGBA(220, 220, 220, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F8F8FF. + /// + public static readonly TPixel GhostWhite = ColorBuilder.FromRGBA(248, 248, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFD700. + /// + public static readonly TPixel Gold = ColorBuilder.FromRGBA(255, 215, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #DAA520. + /// + public static readonly TPixel Goldenrod = ColorBuilder.FromRGBA(218, 165, 32, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #808080. + /// + public static readonly TPixel Gray = ColorBuilder.FromRGBA(128, 128, 128, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #008000. + /// + public static readonly TPixel Green = ColorBuilder.FromRGBA(0, 128, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #ADFF2F. + /// + public static readonly TPixel GreenYellow = ColorBuilder.FromRGBA(173, 255, 47, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFF0. + /// + public static readonly TPixel Honeydew = ColorBuilder.FromRGBA(240, 255, 240, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF69B4. + /// + public static readonly TPixel HotPink = ColorBuilder.FromRGBA(255, 105, 180, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #CD5C5C. + /// + public static readonly TPixel IndianRed = ColorBuilder.FromRGBA(205, 92, 92, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #4B0082. + /// + public static readonly TPixel Indigo = ColorBuilder.FromRGBA(75, 0, 130, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFF0. + /// + public static readonly TPixel Ivory = ColorBuilder.FromRGBA(255, 255, 240, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F0E68C. + /// + public static readonly TPixel Khaki = ColorBuilder.FromRGBA(240, 230, 140, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #E6E6FA. + /// + public static readonly TPixel Lavender = ColorBuilder.FromRGBA(230, 230, 250, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF0F5. + /// + public static readonly TPixel LavenderBlush = ColorBuilder.FromRGBA(255, 240, 245, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #7CFC00. + /// + public static readonly TPixel LawnGreen = ColorBuilder.FromRGBA(124, 252, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFACD. + /// + public static readonly TPixel LemonChiffon = ColorBuilder.FromRGBA(255, 250, 205, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #ADD8E6. + /// + public static readonly TPixel LightBlue = ColorBuilder.FromRGBA(173, 216, 230, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F08080. + /// + public static readonly TPixel LightCoral = ColorBuilder.FromRGBA(240, 128, 128, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #E0FFFF. + /// + public static readonly TPixel LightCyan = ColorBuilder.FromRGBA(224, 255, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FAFAD2. + /// + public static readonly TPixel LightGoldenrodYellow = ColorBuilder.FromRGBA(250, 250, 210, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #D3D3D3. + /// + public static readonly TPixel LightGray = ColorBuilder.FromRGBA(211, 211, 211, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #90EE90. + /// + public static readonly TPixel LightGreen = ColorBuilder.FromRGBA(144, 238, 144, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFB6C1. + /// + public static readonly TPixel LightPink = ColorBuilder.FromRGBA(255, 182, 193, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA07A. + /// + public static readonly TPixel LightSalmon = ColorBuilder.FromRGBA(255, 160, 122, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #20B2AA. + /// + public static readonly TPixel LightSeaGreen = ColorBuilder.FromRGBA(32, 178, 170, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEFA. + /// + public static readonly TPixel LightSkyBlue = ColorBuilder.FromRGBA(135, 206, 250, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #778899. + /// + public static readonly TPixel LightSlateGray = ColorBuilder.FromRGBA(119, 136, 153, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #B0C4DE. + /// + public static readonly TPixel LightSteelBlue = ColorBuilder.FromRGBA(176, 196, 222, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFE0. + /// + public static readonly TPixel LightYellow = ColorBuilder.FromRGBA(255, 255, 224, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF00. + /// + public static readonly TPixel Lime = ColorBuilder.FromRGBA(0, 255, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #32CD32. + /// + public static readonly TPixel LimeGreen = ColorBuilder.FromRGBA(50, 205, 50, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FAF0E6. + /// + public static readonly TPixel Linen = ColorBuilder.FromRGBA(250, 240, 230, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly TPixel Magenta = ColorBuilder.FromRGBA(255, 0, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #800000. + /// + public static readonly TPixel Maroon = ColorBuilder.FromRGBA(128, 0, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #66CDAA. + /// + public static readonly TPixel MediumAquamarine = ColorBuilder.FromRGBA(102, 205, 170, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #0000CD. + /// + public static readonly TPixel MediumBlue = ColorBuilder.FromRGBA(0, 0, 205, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #BA55D3. + /// + public static readonly TPixel MediumOrchid = ColorBuilder.FromRGBA(186, 85, 211, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #9370DB. + /// + public static readonly TPixel MediumPurple = ColorBuilder.FromRGBA(147, 112, 219, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #3CB371. + /// + public static readonly TPixel MediumSeaGreen = ColorBuilder.FromRGBA(60, 179, 113, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #7B68EE. + /// + public static readonly TPixel MediumSlateBlue = ColorBuilder.FromRGBA(123, 104, 238, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #00FA9A. + /// + public static readonly TPixel MediumSpringGreen = ColorBuilder.FromRGBA(0, 250, 154, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #48D1CC. + /// + public static readonly TPixel MediumTurquoise = ColorBuilder.FromRGBA(72, 209, 204, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #C71585. + /// + public static readonly TPixel MediumVioletRed = ColorBuilder.FromRGBA(199, 21, 133, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #191970. + /// + public static readonly TPixel MidnightBlue = ColorBuilder.FromRGBA(25, 25, 112, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F5FFFA. + /// + public static readonly TPixel MintCream = ColorBuilder.FromRGBA(245, 255, 250, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4E1. + /// + public static readonly TPixel MistyRose = ColorBuilder.FromRGBA(255, 228, 225, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4B5. + /// + public static readonly TPixel Moccasin = ColorBuilder.FromRGBA(255, 228, 181, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDEAD. + /// + public static readonly TPixel NavajoWhite = ColorBuilder.FromRGBA(255, 222, 173, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #000080. + /// + public static readonly TPixel Navy = ColorBuilder.FromRGBA(0, 0, 128, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FDF5E6. + /// + public static readonly TPixel OldLace = ColorBuilder.FromRGBA(253, 245, 230, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #808000. + /// + public static readonly TPixel Olive = ColorBuilder.FromRGBA(128, 128, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #6B8E23. + /// + public static readonly TPixel OliveDrab = ColorBuilder.FromRGBA(107, 142, 35, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA500. + /// + public static readonly TPixel Orange = ColorBuilder.FromRGBA(255, 165, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF4500. + /// + public static readonly TPixel OrangeRed = ColorBuilder.FromRGBA(255, 69, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #DA70D6. + /// + public static readonly TPixel Orchid = ColorBuilder.FromRGBA(218, 112, 214, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #EEE8AA. + /// + public static readonly TPixel PaleGoldenrod = ColorBuilder.FromRGBA(238, 232, 170, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #98FB98. + /// + public static readonly TPixel PaleGreen = ColorBuilder.FromRGBA(152, 251, 152, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #AFEEEE. + /// + public static readonly TPixel PaleTurquoise = ColorBuilder.FromRGBA(175, 238, 238, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #DB7093. + /// + public static readonly TPixel PaleVioletRed = ColorBuilder.FromRGBA(219, 112, 147, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEFD5. + /// + public static readonly TPixel PapayaWhip = ColorBuilder.FromRGBA(255, 239, 213, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDAB9. + /// + public static readonly TPixel PeachPuff = ColorBuilder.FromRGBA(255, 218, 185, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #CD853F. + /// + public static readonly TPixel Peru = ColorBuilder.FromRGBA(205, 133, 63, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFC0CB. + /// + public static readonly TPixel Pink = ColorBuilder.FromRGBA(255, 192, 203, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #DDA0DD. + /// + public static readonly TPixel Plum = ColorBuilder.FromRGBA(221, 160, 221, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #B0E0E6. + /// + public static readonly TPixel PowderBlue = ColorBuilder.FromRGBA(176, 224, 230, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #800080. + /// + public static readonly TPixel Purple = ColorBuilder.FromRGBA(128, 0, 128, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #663399. + /// + public static readonly TPixel RebeccaPurple = ColorBuilder.FromRGBA(102, 51, 153, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF0000. + /// + public static readonly TPixel Red = ColorBuilder.FromRGBA(255, 0, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #BC8F8F. + /// + public static readonly TPixel RosyBrown = ColorBuilder.FromRGBA(188, 143, 143, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #4169E1. + /// + public static readonly TPixel RoyalBlue = ColorBuilder.FromRGBA(65, 105, 225, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #8B4513. + /// + public static readonly TPixel SaddleBrown = ColorBuilder.FromRGBA(139, 69, 19, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FA8072. + /// + public static readonly TPixel Salmon = ColorBuilder.FromRGBA(250, 128, 114, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F4A460. + /// + public static readonly TPixel SandyBrown = ColorBuilder.FromRGBA(244, 164, 96, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #2E8B57. + /// + public static readonly TPixel SeaGreen = ColorBuilder.FromRGBA(46, 139, 87, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF5EE. + /// + public static readonly TPixel SeaShell = ColorBuilder.FromRGBA(255, 245, 238, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #A0522D. + /// + public static readonly TPixel Sienna = ColorBuilder.FromRGBA(160, 82, 45, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #C0C0C0. + /// + public static readonly TPixel Silver = ColorBuilder.FromRGBA(192, 192, 192, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEEB. + /// + public static readonly TPixel SkyBlue = ColorBuilder.FromRGBA(135, 206, 235, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #6A5ACD. + /// + public static readonly TPixel SlateBlue = ColorBuilder.FromRGBA(106, 90, 205, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #708090. + /// + public static readonly TPixel SlateGray = ColorBuilder.FromRGBA(112, 128, 144, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAFA. + /// + public static readonly TPixel Snow = ColorBuilder.FromRGBA(255, 250, 250, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF7F. + /// + public static readonly TPixel SpringGreen = ColorBuilder.FromRGBA(0, 255, 127, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #4682B4. + /// + public static readonly TPixel SteelBlue = ColorBuilder.FromRGBA(70, 130, 180, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #D2B48C. + /// + public static readonly TPixel Tan = ColorBuilder.FromRGBA(210, 180, 140, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #008080. + /// + public static readonly TPixel Teal = ColorBuilder.FromRGBA(0, 128, 128, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #D8BFD8. + /// + public static readonly TPixel Thistle = ColorBuilder.FromRGBA(216, 191, 216, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FF6347. + /// + public static readonly TPixel Tomato = ColorBuilder.FromRGBA(255, 99, 71, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly TPixel Transparent = ColorBuilder.FromRGBA(255, 255, 255, 0); + + /// + /// Represents a matching the W3C definition that has an hex value of #40E0D0. + /// + public static readonly TPixel Turquoise = ColorBuilder.FromRGBA(64, 224, 208, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #EE82EE. + /// + public static readonly TPixel Violet = ColorBuilder.FromRGBA(238, 130, 238, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F5DEB3. + /// + public static readonly TPixel Wheat = ColorBuilder.FromRGBA(245, 222, 179, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly TPixel White = ColorBuilder.FromRGBA(255, 255, 255, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5F5. + /// + public static readonly TPixel WhiteSmoke = ColorBuilder.FromRGBA(245, 245, 245, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFF00. + /// + public static readonly TPixel Yellow = ColorBuilder.FromRGBA(255, 255, 0, 255); + + /// + /// Represents a matching the W3C definition that has an hex value of #9ACD32. + /// + public static readonly TPixel YellowGreen = ColorBuilder.FromRGBA(154, 205, 50, 255); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/NormalizedByte2.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs rename to src/ImageSharp/PixelFormats/NormalizedByte2.cs index 56be64a86c..dab113ae78 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedByte2.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed packed pixel type containing two 8-bit signed normalized values, ranging from −1 to 1. + /// Ranges from <-1, -1, 0, 1> to <1, 1, 0, 1> in vector form. /// public struct NormalizedByte2 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/NormalizedByte4.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs rename to src/ImageSharp/PixelFormats/NormalizedByte4.cs index a1f9b8d847..0cb5c756b6 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs +++ b/src/ImageSharp/PixelFormats/NormalizedByte4.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 8-bit signed normalized values, ranging from −1 to 1. + /// Ranges from <-1, -1, -1, -1> to <1, 1, 1, 1> in vector form. /// public struct NormalizedByte4 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/NormalizedShort2.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs rename to src/ImageSharp/PixelFormats/NormalizedShort2.cs index 46c24be6f9..86d80cbad5 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort2.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { - using System; using System.Numerics; using System.Runtime.CompilerServices; /// /// Packed pixel type containing two 16-bit signed normalized values, ranging from −1 to 1. + /// Ranges from <-1, -1, 0, 1> to <1, 1, 0, 1> in vector form. /// public struct NormalizedShort2 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/NormalizedShort4.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs rename to src/ImageSharp/PixelFormats/NormalizedShort4.cs index 74229a914f..8512d41316 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs +++ b/src/ImageSharp/PixelFormats/NormalizedShort4.cs @@ -3,14 +3,14 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { - using System; using System.Numerics; using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 16-bit signed normalized values, ranging from −1 to 1. + /// Ranges from <-1, -1, -1, -1> to <1, 1, 1, 1> in vector form. /// public struct NormalizedShort4 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs b/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs similarity index 97% rename from src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs rename to src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs index 13727870cf..29ef5675e7 100644 --- a/src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs +++ b/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -22,10 +22,10 @@ namespace ImageSharp /// Returns the correct scaling function for the given types The compute scale function. /// /// The scale function. - /// The source pixel format. - /// The target pixel format. + /// The source pixel format. + /// The target pixel format. /// The - public static Func ComputeScaleFunction(Func scaleFunc) + public static Func ComputeScaleFunction(Func scaleFunc) { // Custom type with a custom function. if (scaleFunc != null) @@ -33,8 +33,8 @@ namespace ImageSharp return scaleFunc; } - Type source = typeof(TColor); - Type target = typeof(TColor2); + Type source = typeof(TPixel); + Type target = typeof(TPixel2); // Normalized standard if (IsStandardNormalizedType(source)) @@ -299,7 +299,7 @@ namespace ImageSharp /// The private static bool IsStandardNormalizedType(Type type) { - return type == typeof(Color) + return type == typeof(Rgba32) || type == typeof(Argb32) || type == typeof(Alpha8) || type == typeof(Bgr565) diff --git a/src/ImageSharp/Colors/PackedPixel/README.md b/src/ImageSharp/PixelFormats/README.md similarity index 100% rename from src/ImageSharp/Colors/PackedPixel/README.md rename to src/ImageSharp/PixelFormats/README.md diff --git a/src/ImageSharp/Colors/PackedPixel/Rg32.cs b/src/ImageSharp/PixelFormats/Rg32.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Rg32.cs rename to src/ImageSharp/PixelFormats/Rg32.cs index f8486f7f29..a4bfc5823e 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rg32.cs +++ b/src/ImageSharp/PixelFormats/Rg32.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed pixel type containing two 16-bit unsigned normalized values ranging from 0 to 1. + /// Ranges from <0, 0, 0, 1> to <1, 1, 0, 1> in vector form. /// public struct Rg32 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs b/src/ImageSharp/PixelFormats/Rgba1010102.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs rename to src/ImageSharp/PixelFormats/Rgba1010102.cs index 65a5e7a5f6..cfd60f410e 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs +++ b/src/ImageSharp/PixelFormats/Rgba1010102.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -12,6 +12,7 @@ namespace ImageSharp /// /// Packed vector type containing unsigned normalized values ranging from 0 to 1. /// The x, y and z components use 10 bits, and the w component uses 2 bits. + /// Ranges from <0, 0, 0, 0> to <1, 1, 1, 1> in vector form. /// public struct Rgba1010102 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/Color.BulkOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.BulkOperations.cs similarity index 73% rename from src/ImageSharp/Colors/Color.BulkOperations.cs rename to src/ImageSharp/PixelFormats/Rgba32.BulkOperations.cs index 2de8222d68..df21cdc701 100644 --- a/src/ImageSharp/Colors/Color.BulkOperations.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.BulkOperations.cs @@ -1,29 +1,24 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - /// - /// Unpacked pixel 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 + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct Rgba32 { /// - /// implementation optimized for . + /// implementation optimized for . /// - internal class BulkOperations : BulkPixelOperations + internal class BulkOperations : BulkPixelOperations { /// /// SIMD optimized bulk implementation of @@ -42,12 +37,12 @@ namespace ImageSharp /// https://github.com/dotnet/corefx/issues/15957 /// /// - internal static unsafe void ToVector4SimdAligned(BufferSpan sourceColors, BufferSpan destVectors, int count) + internal static unsafe void ToVector4SimdAligned(BufferSpan sourceColors, BufferSpan destVectors, int count) { if (!Vector.IsHardwareAccelerated) { throw new InvalidOperationException( - "Color32.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); + "Rgba32.BulkOperations.ToVector4SimdAligned() should not be called when Vector.IsHardwareAccelerated == false!"); } int vecSize = Vector.Count; @@ -64,7 +59,7 @@ namespace ImageSharp int unpackedRawCount = count * 4; - ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); + ref uint src = ref Unsafe.As(ref sourceColors.DangerousGetPinnableReference()); using (Buffer tempBuf = new Buffer( unpackedRawCount + Vector.Count)) @@ -100,7 +95,7 @@ namespace ImageSharp } /// - internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) + internal override void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) { if (count < 256 || !Vector.IsHardwareAccelerated) { @@ -127,103 +122,103 @@ namespace ImageSharp } /// - internal override void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromXyzBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color destRef = ref destColors.DangerousGetPinnableReference(); + ref Rgba32 destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); - Unsafe.As(ref dp) = sp; + Unsafe.As(ref dp) = sp; dp.A = 255; } } /// - internal override void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToXyzBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref Rgba32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); for (int i = 0; i < count; i++) { - ref Color sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref RGB24 dp = ref Unsafe.Add(ref destRef, i); - dp = Unsafe.As(ref sp); + dp = Unsafe.As(ref sp); } } /// - internal override unsafe void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override unsafe void PackFromXyzwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { - BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Color)); + BufferSpan.Copy(sourceBytes, destColors.AsBytes(), count * sizeof(Rgba32)); } /// - internal override unsafe void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override unsafe void ToXyzwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - BufferSpan.Copy(sourceColors.AsBytes(), destBytes, count * sizeof(Color)); + BufferSpan.Copy(sourceColors.AsBytes(), destBytes, count * sizeof(Rgba32)); } /// - internal override void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromZyxBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref RGB24 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color destRef = ref destColors.DangerousGetPinnableReference(); + ref Rgba32 destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { ref RGB24 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); - Unsafe.As(ref dp) = sp.ToZyx(); + Unsafe.As(ref dp) = sp.ToZyx(); dp.A = 255; } } /// - internal override void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToZyxBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref Rgba32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref RGB24 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); for (int i = 0; i < count; i++) { - ref Color sp = ref Unsafe.Add(ref sourceRef, i); + ref Rgba32 sp = ref Unsafe.Add(ref sourceRef, i); ref RGB24 dp = ref Unsafe.Add(ref destRef, i); - dp = Unsafe.As(ref sp).ToZyx(); + dp = Unsafe.As(ref sp).ToZyx(); } } /// - internal override void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) + internal override void PackFromZyxwBytes(BufferSpan sourceBytes, BufferSpan destColors, int count) { ref RGBA32 sourceRef = ref Unsafe.As(ref sourceBytes.DangerousGetPinnableReference()); - ref Color destRef = ref destColors.DangerousGetPinnableReference(); + ref Rgba32 destRef = ref destColors.DangerousGetPinnableReference(); for (int i = 0; i < count; i++) { ref RGBA32 sp = ref Unsafe.Add(ref sourceRef, i); - ref Color dp = ref Unsafe.Add(ref destRef, i); + ref Rgba32 dp = ref Unsafe.Add(ref destRef, i); RGBA32 zyxw = sp.ToZyxw(); - dp = Unsafe.As(ref zyxw); + dp = Unsafe.As(ref zyxw); } } /// - internal override void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) + internal override void ToZyxwBytes(BufferSpan sourceColors, BufferSpan destBytes, int count) { - ref Color sourceRef = ref sourceColors.DangerousGetPinnableReference(); + ref Rgba32 sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref RGBA32 destRef = ref Unsafe.As(ref destBytes.DangerousGetPinnableReference()); for (int i = 0; i < count; i++) { - ref RGBA32 sp = ref Unsafe.As(ref Unsafe.Add(ref sourceRef, i)); + ref RGBA32 sp = ref Unsafe.As(ref Unsafe.Add(ref sourceRef, i)); ref RGBA32 dp = ref Unsafe.Add(ref destRef, i); dp = sp.ToZyxw(); } @@ -264,7 +259,7 @@ namespace ImageSharp } /// - /// Value type to store -s unpacked into multiple -s. + /// Value type to store -s unpacked into multiple -s. /// [StructLayout(LayoutKind.Sequential)] private struct UnpackedRGBA diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/PixelFormats/Rgba32.ColorspaceTransforms.cs similarity index 79% rename from src/ImageSharp/Colors/ColorspaceTransforms.cs rename to src/ImageSharp/PixelFormats/Rgba32.ColorspaceTransforms.cs index 480caab331..45d3489b72 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.ColorspaceTransforms.cs @@ -1,62 +1,57 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; using Colors.Spaces; - /// - /// Packed pixel 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 + /// + /// Provides implicit colorspace transformation. + /// + public partial struct Rgba32 { /// - /// Allows the implicit conversion of an instance of to a + /// Allows the implicit conversion of an instance of to a /// . /// - /// The instance of to convert. + /// The instance of to convert. /// /// An instance of . /// - public static implicit operator Color(Bgra32 color) + public static implicit operator Rgba32(Bgra32 color) { - return new Color(color.R, color.G, color.B, color.A); + return new Rgba32(color.R, color.G, color.B, color.A); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(Cmyk cmykColor) + public static implicit operator Rgba32(Cmyk cmykColor) { 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, 1); + return new Rgba32(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(YCbCr color) + public static implicit operator Rgba32(YCbCr color) { float y = color.Y; float cb = color.Cb - 128; @@ -66,18 +61,18 @@ namespace ImageSharp byte g = (byte)(y - (0.34414F * cb) - (0.71414F * cr)).Clamp(0, 255); byte b = (byte)(y + (1.772F * cb)).Clamp(0, 255); - return new Color(r, g, b); + return new Rgba32(r, g, b); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(CieXyz color) + public static implicit operator Rgba32(CieXyz color) { float x = color.X / 100F; float y = color.Y / 100F; @@ -89,25 +84,25 @@ namespace ImageSharp float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F); Vector4 vector = new Vector4(r, g, b, 1).Compress(); - return new Color(vector); + return new Rgba32(vector); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(Hsv color) + public static implicit operator Rgba32(Hsv color) { float s = color.S; float v = color.V; if (MathF.Abs(s) < Constants.Epsilon) { - return new Color(v, v, v, 1); + return new Rgba32(v, v, v, 1); } float h = (MathF.Abs(color.H - 360) < Constants.Epsilon) ? 0 : color.H / 60; @@ -158,18 +153,18 @@ namespace ImageSharp break; } - return new Color(r, g, b, 1); + return new Rgba32(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(Hsl color) + public static implicit operator Rgba32(Hsl color) { float rangedH = color.H / 360F; float r = 0; @@ -195,18 +190,18 @@ namespace ImageSharp } } - return new Color(r, g, b, 1); + return new Rgba32(r, g, b, 1); } /// /// Allows the implicit conversion of an instance of to a - /// . + /// . /// /// The instance of to convert. /// - /// An instance of . + /// An instance of . /// - public static implicit operator Color(CieLab cieLabColor) + public static implicit operator Rgba32(CieLab cieLabColor) { // First convert back to XYZ... float y = (cieLabColor.L + 16F) / 116F; @@ -229,7 +224,7 @@ namespace ImageSharp float g = (x * -0.9689F) + (y * 1.8758F) + (z * 0.0415F); float b = (x * 0.0557F) + (y * -0.2040F) + (z * 1.0570F); - return new Color(new Vector4(r, g, b, 1F).Compress()); + return new Rgba32(new Vector4(r, g, b, 1F).Compress()); } /// diff --git a/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs b/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs new file mode 100644 index 0000000000..be02d08751 --- /dev/null +++ b/src/ImageSharp/PixelFormats/Rgba32.Definitions.cs @@ -0,0 +1,723 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.PixelFormats +{ + /// + /// Provides standardized deifinitions for named colors. + /// + public partial struct Rgba32 + { + /// + /// Represents a matching the W3C definition that has an hex value of #F0F8FF. + /// + public static readonly Rgba32 AliceBlue = NamedColors.AliceBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAEBD7. + /// + public static readonly Rgba32 AntiqueWhite = NamedColors.AntiqueWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly Rgba32 Aqua = NamedColors.Aqua; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFFD4. + /// + public static readonly Rgba32 Aquamarine = NamedColors.Aquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFFF. + /// + public static readonly Rgba32 Azure = NamedColors.Azure; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5DC. + /// + public static readonly Rgba32 Beige = NamedColors.Beige; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4C4. + /// + public static readonly Rgba32 Bisque = NamedColors.Bisque; + + /// + /// Represents a matching the W3C definition that has an hex value of #000000. + /// + public static readonly Rgba32 Black = NamedColors.Black; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEBCD. + /// + public static readonly Rgba32 BlanchedAlmond = NamedColors.BlanchedAlmond; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000FF. + /// + public static readonly Rgba32 Blue = NamedColors.Blue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8A2BE2. + /// + public static readonly Rgba32 BlueViolet = NamedColors.BlueViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #A52A2A. + /// + public static readonly Rgba32 Brown = NamedColors.Brown; + + /// + /// Represents a matching the W3C definition that has an hex value of #DEB887. + /// + public static readonly Rgba32 BurlyWood = NamedColors.BurlyWood; + + /// + /// Represents a matching the W3C definition that has an hex value of #5F9EA0. + /// + public static readonly Rgba32 CadetBlue = NamedColors.CadetBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFF00. + /// + public static readonly Rgba32 Chartreuse = NamedColors.Chartreuse; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2691E. + /// + public static readonly Rgba32 Chocolate = NamedColors.Chocolate; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF7F50. + /// + public static readonly Rgba32 Coral = NamedColors.Coral; + + /// + /// Represents a matching the W3C definition that has an hex value of #6495ED. + /// + public static readonly Rgba32 CornflowerBlue = NamedColors.CornflowerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF8DC. + /// + public static readonly Rgba32 Cornsilk = NamedColors.Cornsilk; + + /// + /// Represents a matching the W3C definition that has an hex value of #DC143C. + /// + public static readonly Rgba32 Crimson = NamedColors.Crimson; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly Rgba32 Cyan = NamedColors.Cyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #00008B. + /// + public static readonly Rgba32 DarkBlue = NamedColors.DarkBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #008B8B. + /// + public static readonly Rgba32 DarkCyan = NamedColors.DarkCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #B8860B. + /// + public static readonly Rgba32 DarkGoldenrod = NamedColors.DarkGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #A9A9A9. + /// + public static readonly Rgba32 DarkGray = NamedColors.DarkGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #006400. + /// + public static readonly Rgba32 DarkGreen = NamedColors.DarkGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #BDB76B. + /// + public static readonly Rgba32 DarkKhaki = NamedColors.DarkKhaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B008B. + /// + public static readonly Rgba32 DarkMagenta = NamedColors.DarkMagenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #556B2F. + /// + public static readonly Rgba32 DarkOliveGreen = NamedColors.DarkOliveGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF8C00. + /// + public static readonly Rgba32 DarkOrange = NamedColors.DarkOrange; + + /// + /// Represents a matching the W3C definition that has an hex value of #9932CC. + /// + public static readonly Rgba32 DarkOrchid = NamedColors.DarkOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B0000. + /// + public static readonly Rgba32 DarkRed = NamedColors.DarkRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #E9967A. + /// + public static readonly Rgba32 DarkSalmon = NamedColors.DarkSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #8FBC8B. + /// + public static readonly Rgba32 DarkSeaGreen = NamedColors.DarkSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #483D8B. + /// + public static readonly Rgba32 DarkSlateBlue = NamedColors.DarkSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #2F4F4F. + /// + public static readonly Rgba32 DarkSlateGray = NamedColors.DarkSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #00CED1. + /// + public static readonly Rgba32 DarkTurquoise = NamedColors.DarkTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #9400D3. + /// + public static readonly Rgba32 DarkViolet = NamedColors.DarkViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF1493. + /// + public static readonly Rgba32 DeepPink = NamedColors.DeepPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #00BFFF. + /// + public static readonly Rgba32 DeepSkyBlue = NamedColors.DeepSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #696969. + /// + public static readonly Rgba32 DimGray = NamedColors.DimGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #1E90FF. + /// + public static readonly Rgba32 DodgerBlue = NamedColors.DodgerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #B22222. + /// + public static readonly Rgba32 Firebrick = NamedColors.Firebrick; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAF0. + /// + public static readonly Rgba32 FloralWhite = NamedColors.FloralWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #228B22. + /// + public static readonly Rgba32 ForestGreen = NamedColors.ForestGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly Rgba32 Fuchsia = NamedColors.Fuchsia; + + /// + /// Represents a matching the W3C definition that has an hex value of #DCDCDC. + /// + public static readonly Rgba32 Gainsboro = NamedColors.Gainsboro; + + /// + /// Represents a matching the W3C definition that has an hex value of #F8F8FF. + /// + public static readonly Rgba32 GhostWhite = NamedColors.GhostWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFD700. + /// + public static readonly Rgba32 Gold = NamedColors.Gold; + + /// + /// Represents a matching the W3C definition that has an hex value of #DAA520. + /// + public static readonly Rgba32 Goldenrod = NamedColors.Goldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #808080. + /// + public static readonly Rgba32 Gray = NamedColors.Gray; + + /// + /// Represents a matching the W3C definition that has an hex value of #008000. + /// + public static readonly Rgba32 Green = NamedColors.Green; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADFF2F. + /// + public static readonly Rgba32 GreenYellow = NamedColors.GreenYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFF0. + /// + public static readonly Rgba32 Honeydew = NamedColors.Honeydew; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF69B4. + /// + public static readonly Rgba32 HotPink = NamedColors.HotPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD5C5C. + /// + public static readonly Rgba32 IndianRed = NamedColors.IndianRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #4B0082. + /// + public static readonly Rgba32 Indigo = NamedColors.Indigo; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFF0. + /// + public static readonly Rgba32 Ivory = NamedColors.Ivory; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0E68C. + /// + public static readonly Rgba32 Khaki = NamedColors.Khaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #E6E6FA. + /// + public static readonly Rgba32 Lavender = NamedColors.Lavender; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF0F5. + /// + public static readonly Rgba32 LavenderBlush = NamedColors.LavenderBlush; + + /// + /// Represents a matching the W3C definition that has an hex value of #7CFC00. + /// + public static readonly Rgba32 LawnGreen = NamedColors.LawnGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFACD. + /// + public static readonly Rgba32 LemonChiffon = NamedColors.LemonChiffon; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADD8E6. + /// + public static readonly Rgba32 LightBlue = NamedColors.LightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F08080. + /// + public static readonly Rgba32 LightCoral = NamedColors.LightCoral; + + /// + /// Represents a matching the W3C definition that has an hex value of #E0FFFF. + /// + public static readonly Rgba32 LightCyan = NamedColors.LightCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAFAD2. + /// + public static readonly Rgba32 LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #D3D3D3. + /// + public static readonly Rgba32 LightGray = NamedColors.LightGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #90EE90. + /// + public static readonly Rgba32 LightGreen = NamedColors.LightGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFB6C1. + /// + public static readonly Rgba32 LightPink = NamedColors.LightPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA07A. + /// + public static readonly Rgba32 LightSalmon = NamedColors.LightSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #20B2AA. + /// + public static readonly Rgba32 LightSeaGreen = NamedColors.LightSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEFA. + /// + public static readonly Rgba32 LightSkyBlue = NamedColors.LightSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #778899. + /// + public static readonly Rgba32 LightSlateGray = NamedColors.LightSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0C4DE. + /// + public static readonly Rgba32 LightSteelBlue = NamedColors.LightSteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFE0. + /// + public static readonly Rgba32 LightYellow = NamedColors.LightYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF00. + /// + public static readonly Rgba32 Lime = NamedColors.Lime; + + /// + /// Represents a matching the W3C definition that has an hex value of #32CD32. + /// + public static readonly Rgba32 LimeGreen = NamedColors.LimeGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAF0E6. + /// + public static readonly Rgba32 Linen = NamedColors.Linen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly Rgba32 Magenta = NamedColors.Magenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #800000. + /// + public static readonly Rgba32 Maroon = NamedColors.Maroon; + + /// + /// Represents a matching the W3C definition that has an hex value of #66CDAA. + /// + public static readonly Rgba32 MediumAquamarine = NamedColors.MediumAquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000CD. + /// + public static readonly Rgba32 MediumBlue = NamedColors.MediumBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #BA55D3. + /// + public static readonly Rgba32 MediumOrchid = NamedColors.MediumOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #9370DB. + /// + public static readonly Rgba32 MediumPurple = NamedColors.MediumPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #3CB371. + /// + public static readonly Rgba32 MediumSeaGreen = NamedColors.MediumSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #7B68EE. + /// + public static readonly Rgba32 MediumSlateBlue = NamedColors.MediumSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FA9A. + /// + public static readonly Rgba32 MediumSpringGreen = NamedColors.MediumSpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #48D1CC. + /// + public static readonly Rgba32 MediumTurquoise = NamedColors.MediumTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #C71585. + /// + public static readonly Rgba32 MediumVioletRed = NamedColors.MediumVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #191970. + /// + public static readonly Rgba32 MidnightBlue = NamedColors.MidnightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5FFFA. + /// + public static readonly Rgba32 MintCream = NamedColors.MintCream; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4E1. + /// + public static readonly Rgba32 MistyRose = NamedColors.MistyRose; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4B5. + /// + public static readonly Rgba32 Moccasin = NamedColors.Moccasin; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDEAD. + /// + public static readonly Rgba32 NavajoWhite = NamedColors.NavajoWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #000080. + /// + public static readonly Rgba32 Navy = NamedColors.Navy; + + /// + /// Represents a matching the W3C definition that has an hex value of #FDF5E6. + /// + public static readonly Rgba32 OldLace = NamedColors.OldLace; + + /// + /// Represents a matching the W3C definition that has an hex value of #808000. + /// + public static readonly Rgba32 Olive = NamedColors.Olive; + + /// + /// Represents a matching the W3C definition that has an hex value of #6B8E23. + /// + public static readonly Rgba32 OliveDrab = NamedColors.OliveDrab; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA500. + /// + public static readonly Rgba32 Orange = NamedColors.Orange; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF4500. + /// + public static readonly Rgba32 OrangeRed = NamedColors.OrangeRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #DA70D6. + /// + public static readonly Rgba32 Orchid = NamedColors.Orchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #EEE8AA. + /// + public static readonly Rgba32 PaleGoldenrod = NamedColors.PaleGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #98FB98. + /// + public static readonly Rgba32 PaleGreen = NamedColors.PaleGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #AFEEEE. + /// + public static readonly Rgba32 PaleTurquoise = NamedColors.PaleTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #DB7093. + /// + public static readonly Rgba32 PaleVioletRed = NamedColors.PaleVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEFD5. + /// + public static readonly Rgba32 PapayaWhip = NamedColors.PapayaWhip; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDAB9. + /// + public static readonly Rgba32 PeachPuff = NamedColors.PeachPuff; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD853F. + /// + public static readonly Rgba32 Peru = NamedColors.Peru; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFC0CB. + /// + public static readonly Rgba32 Pink = NamedColors.Pink; + + /// + /// Represents a matching the W3C definition that has an hex value of #DDA0DD. + /// + public static readonly Rgba32 Plum = NamedColors.Plum; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0E0E6. + /// + public static readonly Rgba32 PowderBlue = NamedColors.PowderBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #800080. + /// + public static readonly Rgba32 Purple = NamedColors.Purple; + + /// + /// Represents a matching the W3C definition that has an hex value of #663399. + /// + public static readonly Rgba32 RebeccaPurple = NamedColors.RebeccaPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF0000. + /// + public static readonly Rgba32 Red = NamedColors.Red; + + /// + /// Represents a matching the W3C definition that has an hex value of #BC8F8F. + /// + public static readonly Rgba32 RosyBrown = NamedColors.RosyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #4169E1. + /// + public static readonly Rgba32 RoyalBlue = NamedColors.RoyalBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B4513. + /// + public static readonly Rgba32 SaddleBrown = NamedColors.SaddleBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #FA8072. + /// + public static readonly Rgba32 Salmon = NamedColors.Salmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #F4A460. + /// + public static readonly Rgba32 SandyBrown = NamedColors.SandyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #2E8B57. + /// + public static readonly Rgba32 SeaGreen = NamedColors.SeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF5EE. + /// + public static readonly Rgba32 SeaShell = NamedColors.SeaShell; + + /// + /// Represents a matching the W3C definition that has an hex value of #A0522D. + /// + public static readonly Rgba32 Sienna = NamedColors.Sienna; + + /// + /// Represents a matching the W3C definition that has an hex value of #C0C0C0. + /// + public static readonly Rgba32 Silver = NamedColors.Silver; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEEB. + /// + public static readonly Rgba32 SkyBlue = NamedColors.SkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #6A5ACD. + /// + public static readonly Rgba32 SlateBlue = NamedColors.SlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #708090. + /// + public static readonly Rgba32 SlateGray = NamedColors.SlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAFA. + /// + public static readonly Rgba32 Snow = NamedColors.Snow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF7F. + /// + public static readonly Rgba32 SpringGreen = NamedColors.SpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #4682B4. + /// + public static readonly Rgba32 SteelBlue = NamedColors.SteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2B48C. + /// + public static readonly Rgba32 Tan = NamedColors.Tan; + + /// + /// Represents a matching the W3C definition that has an hex value of #008080. + /// + public static readonly Rgba32 Teal = NamedColors.Teal; + + /// + /// Represents a matching the W3C definition that has an hex value of #D8BFD8. + /// + public static readonly Rgba32 Thistle = NamedColors.Thistle; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF6347. + /// + public static readonly Rgba32 Tomato = NamedColors.Tomato; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly Rgba32 Transparent = NamedColors.Transparent; + + /// + /// Represents a matching the W3C definition that has an hex value of #40E0D0. + /// + public static readonly Rgba32 Turquoise = NamedColors.Turquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #EE82EE. + /// + public static readonly Rgba32 Violet = NamedColors.Violet; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5DEB3. + /// + public static readonly Rgba32 Wheat = NamedColors.Wheat; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly Rgba32 White = NamedColors.White; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5F5. + /// + public static readonly Rgba32 WhiteSmoke = NamedColors.WhiteSmoke; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFF00. + /// + public static readonly Rgba32 Yellow = NamedColors.Yellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #9ACD32. + /// + public static readonly Rgba32 YellowGreen = NamedColors.YellowGreen; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/Color.Transforms.cs b/src/ImageSharp/PixelFormats/Rgba32.Transforms.cs similarity index 81% rename from src/ImageSharp/Colors/Color.Transforms.cs rename to src/ImageSharp/PixelFormats/Rgba32.Transforms.cs index 15935afc4d..bd13a2de1a 100644 --- a/src/ImageSharp/Colors/Color.Transforms.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.Transforms.cs @@ -1,22 +1,17 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System.Numerics; using System.Runtime.CompilerServices; - /// - /// Packed pixel 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 + /// + /// Provides operators and composition algorithms. + /// + public partial struct Rgba32 { /// /// Adds the second color to the first. @@ -24,10 +19,10 @@ namespace ImageSharp /// The first source color. /// The second source color. /// - /// The . + /// The . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Color operator +(Color left, Color right) + public static Rgba32 operator +(Rgba32 left, Rgba32 right) { Vector4 add = left.ToVector4() + right.ToVector4(); return PackNew(ref add); @@ -39,10 +34,10 @@ namespace ImageSharp /// The first source color. /// The second source color. /// - /// The . + /// The . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Color operator -(Color left, Color right) + public static Rgba32 operator -(Rgba32 left, Rgba32 right) { Vector4 sub = left.ToVector4() - right.ToVector4(); return PackNew(ref sub); @@ -54,9 +49,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Normal(Color backdrop, Color source) + public static Rgba32 Normal(Rgba32 backdrop, Rgba32 source) { Vector4 normal = Vector4BlendTransforms.Normal(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref normal); @@ -74,9 +69,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Multiply(Color backdrop, Color source) + public static Rgba32 Multiply(Rgba32 backdrop, Rgba32 source) { Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref multiply); @@ -93,9 +88,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Screen(Color backdrop, Color source) + public static Rgba32 Screen(Rgba32 backdrop, Rgba32 source) { Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref subtract); @@ -108,9 +103,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color HardLight(Color backdrop, Color source) + public static Rgba32 HardLight(Rgba32 backdrop, Rgba32 source) { Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref hardlight); @@ -127,9 +122,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Overlay(Color backdrop, Color source) + public static Rgba32 Overlay(Rgba32 backdrop, Rgba32 source) { Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref overlay); @@ -142,9 +137,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Darken(Color backdrop, Color source) + public static Rgba32 Darken(Rgba32 backdrop, Rgba32 source) { Vector4 darken = Vector4BlendTransforms.Darken(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref darken); @@ -157,9 +152,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Lighten(Color backdrop, Color source) + public static Rgba32 Lighten(Rgba32 backdrop, Rgba32 source) { Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref lighten); @@ -172,9 +167,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color SoftLight(Color backdrop, Color source) + public static Rgba32 SoftLight(Rgba32 backdrop, Rgba32 source) { Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref softlight); @@ -186,9 +181,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color ColorDodge(Color backdrop, Color source) + public static Rgba32 ColorDodge(Rgba32 backdrop, Rgba32 source) { Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref dodge); @@ -200,9 +195,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color ColorBurn(Color backdrop, Color source) + public static Rgba32 ColorBurn(Rgba32 backdrop, Rgba32 source) { Vector4 burn = Vector4BlendTransforms.Burn(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref burn); @@ -215,9 +210,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Difference(Color backdrop, Color source) + public static Rgba32 Difference(Rgba32 backdrop, Rgba32 source) { Vector4 difference = Vector4BlendTransforms.Difference(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref difference); @@ -230,9 +225,9 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static Color Exclusion(Color backdrop, Color source) + public static Rgba32 Exclusion(Rgba32 backdrop, Rgba32 source) { Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.ToVector4(), source.ToVector4()); return PackNew(ref exclusion); @@ -248,9 +243,9 @@ namespace ImageSharp /// At amount = 0, "from" is returned, at amount = 1, "to" is returned. /// /// - /// The + /// The /// - public static Color Lerp(Color from, Color to, float amount) + public static Rgba32 Lerp(Rgba32 from, Rgba32 to, float amount) { Vector4 lerp = Vector4.Lerp(from.ToVector4(), to.ToVector4(), amount); return PackNew(ref lerp); diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/PixelFormats/Rgba32.cs similarity index 84% rename from src/ImageSharp/Colors/Color.cs rename to src/ImageSharp/PixelFormats/Rgba32.cs index fa83429df1..d668be76fd 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.cs @@ -1,9 +1,9 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System.Numerics; using System.Runtime.CompilerServices; @@ -12,13 +12,14 @@ namespace ImageSharp /// /// Packed pixel 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. + /// Ranges from <0, 0, 0, 0> to <1, 1, 1, 1> in vector form. /// /// /// 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. /// [StructLayout(LayoutKind.Explicit)] - public partial struct Color : IPixel, IPackedVector + public partial struct Rgba32 : IPixel, IPackedVector { /// /// Gets or sets the red component. @@ -81,14 +82,14 @@ namespace ImageSharp private static readonly Vector4 Half = new Vector4(0.5F); /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The red component. /// The green component. /// The blue component. /// The alpha component. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Color(byte r, byte g, byte b, byte a = 255) + public Rgba32(byte r, byte g, byte b, byte a = 255) : this() { this.R = r; @@ -98,53 +99,53 @@ namespace ImageSharp } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The red component. /// The green component. /// The blue component. /// The alpha component. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Color(float r, float g, float b, float a = 1) + public Rgba32(float r, float g, float b, float a = 1) : this() { this.Pack(r, g, b, a); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The vector containing the components for the packed vector. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Color(Vector3 vector) + public Rgba32(Vector3 vector) : this() { this.Pack(ref vector); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The vector containing the components for the packed vector. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Color(Vector4 vector) + public Rgba32(Vector4 vector) : this() { this = PackNew(ref vector); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The packed value. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Color(uint packed) + public Rgba32(uint packed) : this() { this.Rgba = packed; @@ -154,54 +155,54 @@ namespace ImageSharp public uint PackedValue { get => this.Rgba; set => this.Rgba = value; } /// - /// Compares two objects for equality. + /// Compares two objects for equality. /// /// - /// The on the left side of the operand. + /// The on the left side of the operand. /// /// - /// The on the right side of the operand. + /// The on the right side of the operand. /// /// /// True if the parameter is equal to the parameter; otherwise, false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(Color left, Color right) + public static bool operator ==(Rgba32 left, Rgba32 right) { return left.Rgba == right.Rgba; } /// - /// Compares two objects for equality. + /// 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 parameter is not equal to the parameter; otherwise, false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(Color left, Color right) + public static bool operator !=(Rgba32 left, Rgba32 right) { return left.Rgba != right.Rgba; } /// - /// Creates a new instance of the struct. + /// Creates a new instance of the struct. /// /// /// The hexadecimal representation of the combined color components arranged /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax. /// /// - /// The . + /// The . /// - public static Color FromHex(string hex) + public static Rgba32 FromHex(string hex) { - return ColorBuilder.FromHex(hex); + return ColorBuilder.FromHex(hex); } /// - public BulkPixelOperations CreateBulkOperations() => new BulkOperations(); + public BulkPixelOperations CreateBulkOperations() => new BulkOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -278,12 +279,12 @@ namespace ImageSharp /// public override bool Equals(object obj) { - return (obj is Color) && this.Equals((Color)obj); + return (obj is Rgba32) && this.Equals((Rgba32)obj); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Color other) + public bool Equals(Rgba32 other) { return this.Rgba == other.Rgba; } @@ -328,15 +329,15 @@ namespace ImageSharp /// Packs a into a color returning a new instance as a result. /// /// The vector containing the values to pack. - /// The + /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Color PackNew(ref Vector4 vector) + private static Rgba32 PackNew(ref Vector4 vector) { vector *= MaxBytes; vector += Half; vector = Vector4.Clamp(vector, Vector4.Zero, MaxBytes); - return new Color((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W); + return new Rgba32((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W); } /// diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba64.cs b/src/ImageSharp/PixelFormats/Rgba64.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Rgba64.cs rename to src/ImageSharp/PixelFormats/Rgba64.cs index becc4d072a..20bba9f41e 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rgba64.cs +++ b/src/ImageSharp/PixelFormats/Rgba64.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1. + /// Ranges from <0, 0, 0, 0> to <1, 1, 1, 1> in vector form. /// public struct Rgba64 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/RgbaComponent.cs b/src/ImageSharp/PixelFormats/RgbaComponent.cs similarity index 100% rename from src/ImageSharp/Colors/RgbaComponent.cs rename to src/ImageSharp/PixelFormats/RgbaComponent.cs diff --git a/src/ImageSharp/PixelFormats/RgbaVector.BulkOperations.cs b/src/ImageSharp/PixelFormats/RgbaVector.BulkOperations.cs new file mode 100644 index 0000000000..9dcfc9074d --- /dev/null +++ b/src/ImageSharp/PixelFormats/RgbaVector.BulkOperations.cs @@ -0,0 +1,27 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.PixelFormats +{ + using System.Numerics; + + /// + /// Provides optimized overrides for bulk operations. + /// + public partial struct RgbaVector + { + /// + /// implementation optimized for . + /// + internal class BulkOperations : BulkPixelOperations + { + /// + internal override unsafe void ToVector4(BufferSpan sourceColors, BufferSpan destVectors, int count) + { + BufferSpan.Copy(sourceColors.AsBytes(), destVectors.AsBytes(), count * sizeof(Vector4)); + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/RgbaVector.Definitions.cs b/src/ImageSharp/PixelFormats/RgbaVector.Definitions.cs new file mode 100644 index 0000000000..dc965f9ff5 --- /dev/null +++ b/src/ImageSharp/PixelFormats/RgbaVector.Definitions.cs @@ -0,0 +1,723 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.PixelFormats +{ + /// + /// Provides operators and composition algorithms. + /// + public partial struct RgbaVector + { + /// + /// Represents a matching the W3C definition that has an hex value of #F0F8FF. + /// + public static readonly RgbaVector AliceBlue = NamedColors.AliceBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAEBD7. + /// + public static readonly RgbaVector AntiqueWhite = NamedColors.AntiqueWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly RgbaVector Aqua = NamedColors.Aqua; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFFD4. + /// + public static readonly RgbaVector Aquamarine = NamedColors.Aquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFFF. + /// + public static readonly RgbaVector Azure = NamedColors.Azure; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5DC. + /// + public static readonly RgbaVector Beige = NamedColors.Beige; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4C4. + /// + public static readonly RgbaVector Bisque = NamedColors.Bisque; + + /// + /// Represents a matching the W3C definition that has an hex value of #000000. + /// + public static readonly RgbaVector Black = NamedColors.Black; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEBCD. + /// + public static readonly RgbaVector BlanchedAlmond = NamedColors.BlanchedAlmond; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000FF. + /// + public static readonly RgbaVector Blue = NamedColors.Blue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8A2BE2. + /// + public static readonly RgbaVector BlueViolet = NamedColors.BlueViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #A52A2A. + /// + public static readonly RgbaVector Brown = NamedColors.Brown; + + /// + /// Represents a matching the W3C definition that has an hex value of #DEB887. + /// + public static readonly RgbaVector BurlyWood = NamedColors.BurlyWood; + + /// + /// Represents a matching the W3C definition that has an hex value of #5F9EA0. + /// + public static readonly RgbaVector CadetBlue = NamedColors.CadetBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #7FFF00. + /// + public static readonly RgbaVector Chartreuse = NamedColors.Chartreuse; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2691E. + /// + public static readonly RgbaVector Chocolate = NamedColors.Chocolate; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF7F50. + /// + public static readonly RgbaVector Coral = NamedColors.Coral; + + /// + /// Represents a matching the W3C definition that has an hex value of #6495ED. + /// + public static readonly RgbaVector CornflowerBlue = NamedColors.CornflowerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF8DC. + /// + public static readonly RgbaVector Cornsilk = NamedColors.Cornsilk; + + /// + /// Represents a matching the W3C definition that has an hex value of #DC143C. + /// + public static readonly RgbaVector Crimson = NamedColors.Crimson; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FFFF. + /// + public static readonly RgbaVector Cyan = NamedColors.Cyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #00008B. + /// + public static readonly RgbaVector DarkBlue = NamedColors.DarkBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #008B8B. + /// + public static readonly RgbaVector DarkCyan = NamedColors.DarkCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #B8860B. + /// + public static readonly RgbaVector DarkGoldenrod = NamedColors.DarkGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #A9A9A9. + /// + public static readonly RgbaVector DarkGray = NamedColors.DarkGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #006400. + /// + public static readonly RgbaVector DarkGreen = NamedColors.DarkGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #BDB76B. + /// + public static readonly RgbaVector DarkKhaki = NamedColors.DarkKhaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B008B. + /// + public static readonly RgbaVector DarkMagenta = NamedColors.DarkMagenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #556B2F. + /// + public static readonly RgbaVector DarkOliveGreen = NamedColors.DarkOliveGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF8C00. + /// + public static readonly RgbaVector DarkOrange = NamedColors.DarkOrange; + + /// + /// Represents a matching the W3C definition that has an hex value of #9932CC. + /// + public static readonly RgbaVector DarkOrchid = NamedColors.DarkOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B0000. + /// + public static readonly RgbaVector DarkRed = NamedColors.DarkRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #E9967A. + /// + public static readonly RgbaVector DarkSalmon = NamedColors.DarkSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #8FBC8B. + /// + public static readonly RgbaVector DarkSeaGreen = NamedColors.DarkSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #483D8B. + /// + public static readonly RgbaVector DarkSlateBlue = NamedColors.DarkSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #2F4F4F. + /// + public static readonly RgbaVector DarkSlateGray = NamedColors.DarkSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #00CED1. + /// + public static readonly RgbaVector DarkTurquoise = NamedColors.DarkTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #9400D3. + /// + public static readonly RgbaVector DarkViolet = NamedColors.DarkViolet; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF1493. + /// + public static readonly RgbaVector DeepPink = NamedColors.DeepPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #00BFFF. + /// + public static readonly RgbaVector DeepSkyBlue = NamedColors.DeepSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #696969. + /// + public static readonly RgbaVector DimGray = NamedColors.DimGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #1E90FF. + /// + public static readonly RgbaVector DodgerBlue = NamedColors.DodgerBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #B22222. + /// + public static readonly RgbaVector Firebrick = NamedColors.Firebrick; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAF0. + /// + public static readonly RgbaVector FloralWhite = NamedColors.FloralWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #228B22. + /// + public static readonly RgbaVector ForestGreen = NamedColors.ForestGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly RgbaVector Fuchsia = NamedColors.Fuchsia; + + /// + /// Represents a matching the W3C definition that has an hex value of #DCDCDC. + /// + public static readonly RgbaVector Gainsboro = NamedColors.Gainsboro; + + /// + /// Represents a matching the W3C definition that has an hex value of #F8F8FF. + /// + public static readonly RgbaVector GhostWhite = NamedColors.GhostWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFD700. + /// + public static readonly RgbaVector Gold = NamedColors.Gold; + + /// + /// Represents a matching the W3C definition that has an hex value of #DAA520. + /// + public static readonly RgbaVector Goldenrod = NamedColors.Goldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #808080. + /// + public static readonly RgbaVector Gray = NamedColors.Gray; + + /// + /// Represents a matching the W3C definition that has an hex value of #008000. + /// + public static readonly RgbaVector Green = NamedColors.Green; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADFF2F. + /// + public static readonly RgbaVector GreenYellow = NamedColors.GreenYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0FFF0. + /// + public static readonly RgbaVector Honeydew = NamedColors.Honeydew; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF69B4. + /// + public static readonly RgbaVector HotPink = NamedColors.HotPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD5C5C. + /// + public static readonly RgbaVector IndianRed = NamedColors.IndianRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #4B0082. + /// + public static readonly RgbaVector Indigo = NamedColors.Indigo; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFF0. + /// + public static readonly RgbaVector Ivory = NamedColors.Ivory; + + /// + /// Represents a matching the W3C definition that has an hex value of #F0E68C. + /// + public static readonly RgbaVector Khaki = NamedColors.Khaki; + + /// + /// Represents a matching the W3C definition that has an hex value of #E6E6FA. + /// + public static readonly RgbaVector Lavender = NamedColors.Lavender; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF0F5. + /// + public static readonly RgbaVector LavenderBlush = NamedColors.LavenderBlush; + + /// + /// Represents a matching the W3C definition that has an hex value of #7CFC00. + /// + public static readonly RgbaVector LawnGreen = NamedColors.LawnGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFACD. + /// + public static readonly RgbaVector LemonChiffon = NamedColors.LemonChiffon; + + /// + /// Represents a matching the W3C definition that has an hex value of #ADD8E6. + /// + public static readonly RgbaVector LightBlue = NamedColors.LightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F08080. + /// + public static readonly RgbaVector LightCoral = NamedColors.LightCoral; + + /// + /// Represents a matching the W3C definition that has an hex value of #E0FFFF. + /// + public static readonly RgbaVector LightCyan = NamedColors.LightCyan; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAFAD2. + /// + public static readonly RgbaVector LightGoldenrodYellow = NamedColors.LightGoldenrodYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #D3D3D3. + /// + public static readonly RgbaVector LightGray = NamedColors.LightGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #90EE90. + /// + public static readonly RgbaVector LightGreen = NamedColors.LightGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFB6C1. + /// + public static readonly RgbaVector LightPink = NamedColors.LightPink; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA07A. + /// + public static readonly RgbaVector LightSalmon = NamedColors.LightSalmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #20B2AA. + /// + public static readonly RgbaVector LightSeaGreen = NamedColors.LightSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEFA. + /// + public static readonly RgbaVector LightSkyBlue = NamedColors.LightSkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #778899. + /// + public static readonly RgbaVector LightSlateGray = NamedColors.LightSlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0C4DE. + /// + public static readonly RgbaVector LightSteelBlue = NamedColors.LightSteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFE0. + /// + public static readonly RgbaVector LightYellow = NamedColors.LightYellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF00. + /// + public static readonly RgbaVector Lime = NamedColors.Lime; + + /// + /// Represents a matching the W3C definition that has an hex value of #32CD32. + /// + public static readonly RgbaVector LimeGreen = NamedColors.LimeGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FAF0E6. + /// + public static readonly RgbaVector Linen = NamedColors.Linen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF00FF. + /// + public static readonly RgbaVector Magenta = NamedColors.Magenta; + + /// + /// Represents a matching the W3C definition that has an hex value of #800000. + /// + public static readonly RgbaVector Maroon = NamedColors.Maroon; + + /// + /// Represents a matching the W3C definition that has an hex value of #66CDAA. + /// + public static readonly RgbaVector MediumAquamarine = NamedColors.MediumAquamarine; + + /// + /// Represents a matching the W3C definition that has an hex value of #0000CD. + /// + public static readonly RgbaVector MediumBlue = NamedColors.MediumBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #BA55D3. + /// + public static readonly RgbaVector MediumOrchid = NamedColors.MediumOrchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #9370DB. + /// + public static readonly RgbaVector MediumPurple = NamedColors.MediumPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #3CB371. + /// + public static readonly RgbaVector MediumSeaGreen = NamedColors.MediumSeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #7B68EE. + /// + public static readonly RgbaVector MediumSlateBlue = NamedColors.MediumSlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FA9A. + /// + public static readonly RgbaVector MediumSpringGreen = NamedColors.MediumSpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #48D1CC. + /// + public static readonly RgbaVector MediumTurquoise = NamedColors.MediumTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #C71585. + /// + public static readonly RgbaVector MediumVioletRed = NamedColors.MediumVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #191970. + /// + public static readonly RgbaVector MidnightBlue = NamedColors.MidnightBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5FFFA. + /// + public static readonly RgbaVector MintCream = NamedColors.MintCream; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4E1. + /// + public static readonly RgbaVector MistyRose = NamedColors.MistyRose; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFE4B5. + /// + public static readonly RgbaVector Moccasin = NamedColors.Moccasin; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDEAD. + /// + public static readonly RgbaVector NavajoWhite = NamedColors.NavajoWhite; + + /// + /// Represents a matching the W3C definition that has an hex value of #000080. + /// + public static readonly RgbaVector Navy = NamedColors.Navy; + + /// + /// Represents a matching the W3C definition that has an hex value of #FDF5E6. + /// + public static readonly RgbaVector OldLace = NamedColors.OldLace; + + /// + /// Represents a matching the W3C definition that has an hex value of #808000. + /// + public static readonly RgbaVector Olive = NamedColors.Olive; + + /// + /// Represents a matching the W3C definition that has an hex value of #6B8E23. + /// + public static readonly RgbaVector OliveDrab = NamedColors.OliveDrab; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFA500. + /// + public static readonly RgbaVector Orange = NamedColors.Orange; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF4500. + /// + public static readonly RgbaVector OrangeRed = NamedColors.OrangeRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #DA70D6. + /// + public static readonly RgbaVector Orchid = NamedColors.Orchid; + + /// + /// Represents a matching the W3C definition that has an hex value of #EEE8AA. + /// + public static readonly RgbaVector PaleGoldenrod = NamedColors.PaleGoldenrod; + + /// + /// Represents a matching the W3C definition that has an hex value of #98FB98. + /// + public static readonly RgbaVector PaleGreen = NamedColors.PaleGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #AFEEEE. + /// + public static readonly RgbaVector PaleTurquoise = NamedColors.PaleTurquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #DB7093. + /// + public static readonly RgbaVector PaleVioletRed = NamedColors.PaleVioletRed; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFEFD5. + /// + public static readonly RgbaVector PapayaWhip = NamedColors.PapayaWhip; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFDAB9. + /// + public static readonly RgbaVector PeachPuff = NamedColors.PeachPuff; + + /// + /// Represents a matching the W3C definition that has an hex value of #CD853F. + /// + public static readonly RgbaVector Peru = NamedColors.Peru; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFC0CB. + /// + public static readonly RgbaVector Pink = NamedColors.Pink; + + /// + /// Represents a matching the W3C definition that has an hex value of #DDA0DD. + /// + public static readonly RgbaVector Plum = NamedColors.Plum; + + /// + /// Represents a matching the W3C definition that has an hex value of #B0E0E6. + /// + public static readonly RgbaVector PowderBlue = NamedColors.PowderBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #800080. + /// + public static readonly RgbaVector Purple = NamedColors.Purple; + + /// + /// Represents a matching the W3C definition that has an hex value of #663399. + /// + public static readonly RgbaVector RebeccaPurple = NamedColors.RebeccaPurple; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF0000. + /// + public static readonly RgbaVector Red = NamedColors.Red; + + /// + /// Represents a matching the W3C definition that has an hex value of #BC8F8F. + /// + public static readonly RgbaVector RosyBrown = NamedColors.RosyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #4169E1. + /// + public static readonly RgbaVector RoyalBlue = NamedColors.RoyalBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #8B4513. + /// + public static readonly RgbaVector SaddleBrown = NamedColors.SaddleBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #FA8072. + /// + public static readonly RgbaVector Salmon = NamedColors.Salmon; + + /// + /// Represents a matching the W3C definition that has an hex value of #F4A460. + /// + public static readonly RgbaVector SandyBrown = NamedColors.SandyBrown; + + /// + /// Represents a matching the W3C definition that has an hex value of #2E8B57. + /// + public static readonly RgbaVector SeaGreen = NamedColors.SeaGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFF5EE. + /// + public static readonly RgbaVector SeaShell = NamedColors.SeaShell; + + /// + /// Represents a matching the W3C definition that has an hex value of #A0522D. + /// + public static readonly RgbaVector Sienna = NamedColors.Sienna; + + /// + /// Represents a matching the W3C definition that has an hex value of #C0C0C0. + /// + public static readonly RgbaVector Silver = NamedColors.Silver; + + /// + /// Represents a matching the W3C definition that has an hex value of #87CEEB. + /// + public static readonly RgbaVector SkyBlue = NamedColors.SkyBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #6A5ACD. + /// + public static readonly RgbaVector SlateBlue = NamedColors.SlateBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #708090. + /// + public static readonly RgbaVector SlateGray = NamedColors.SlateGray; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFAFA. + /// + public static readonly RgbaVector Snow = NamedColors.Snow; + + /// + /// Represents a matching the W3C definition that has an hex value of #00FF7F. + /// + public static readonly RgbaVector SpringGreen = NamedColors.SpringGreen; + + /// + /// Represents a matching the W3C definition that has an hex value of #4682B4. + /// + public static readonly RgbaVector SteelBlue = NamedColors.SteelBlue; + + /// + /// Represents a matching the W3C definition that has an hex value of #D2B48C. + /// + public static readonly RgbaVector Tan = NamedColors.Tan; + + /// + /// Represents a matching the W3C definition that has an hex value of #008080. + /// + public static readonly RgbaVector Teal = NamedColors.Teal; + + /// + /// Represents a matching the W3C definition that has an hex value of #D8BFD8. + /// + public static readonly RgbaVector Thistle = NamedColors.Thistle; + + /// + /// Represents a matching the W3C definition that has an hex value of #FF6347. + /// + public static readonly RgbaVector Tomato = NamedColors.Tomato; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly RgbaVector Transparent = NamedColors.Transparent; + + /// + /// Represents a matching the W3C definition that has an hex value of #40E0D0. + /// + public static readonly RgbaVector Turquoise = NamedColors.Turquoise; + + /// + /// Represents a matching the W3C definition that has an hex value of #EE82EE. + /// + public static readonly RgbaVector Violet = NamedColors.Violet; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5DEB3. + /// + public static readonly RgbaVector Wheat = NamedColors.Wheat; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFFFF. + /// + public static readonly RgbaVector White = NamedColors.White; + + /// + /// Represents a matching the W3C definition that has an hex value of #F5F5F5. + /// + public static readonly RgbaVector WhiteSmoke = NamedColors.WhiteSmoke; + + /// + /// Represents a matching the W3C definition that has an hex value of #FFFF00. + /// + public static readonly RgbaVector Yellow = NamedColors.Yellow; + + /// + /// Represents a matching the W3C definition that has an hex value of #9ACD32. + /// + public static readonly RgbaVector YellowGreen = NamedColors.YellowGreen; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorVector.Transforms.cs b/src/ImageSharp/PixelFormats/RgbaVector.Transforms.cs similarity index 71% rename from src/ImageSharp/Colors/ColorVector.Transforms.cs rename to src/ImageSharp/PixelFormats/RgbaVector.Transforms.cs index a884f2618c..fec1aa346e 100644 --- a/src/ImageSharp/Colors/ColorVector.Transforms.cs +++ b/src/ImageSharp/PixelFormats/RgbaVector.Transforms.cs @@ -1,22 +1,17 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System.Numerics; using System.Runtime.CompilerServices; - /// - /// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1. - /// 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 ColorVector + /// + /// Provides operators and composition algorithms. + /// + public partial struct RgbaVector { /// /// Adds the second color to the first. @@ -24,12 +19,12 @@ namespace ImageSharp /// The first source color. /// The second source color. /// - /// The . + /// The . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ColorVector operator +(ColorVector left, ColorVector right) + public static RgbaVector operator +(RgbaVector left, RgbaVector right) { - return new ColorVector(left.backingVector + right.backingVector); + return new RgbaVector(left.backingVector + right.backingVector); } /// @@ -38,12 +33,12 @@ namespace ImageSharp /// The first source color. /// The second source color. /// - /// The . + /// The . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ColorVector operator -(ColorVector left, ColorVector right) + public static RgbaVector operator -(RgbaVector left, RgbaVector right) { - return new ColorVector(left.backingVector - right.backingVector); + return new RgbaVector(left.backingVector - right.backingVector); } /// @@ -52,12 +47,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector Normal(ColorVector backdrop, ColorVector source) + public static RgbaVector Normal(RgbaVector backdrop, RgbaVector source) { Vector4 normal = Vector4BlendTransforms.Normal(backdrop.backingVector, source.backingVector); - return new ColorVector(normal); + return new RgbaVector(normal); } /// @@ -72,12 +67,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector Multiply(ColorVector backdrop, ColorVector source) + public static RgbaVector Multiply(RgbaVector backdrop, RgbaVector source) { Vector4 multiply = Vector4BlendTransforms.Multiply(backdrop.backingVector, source.backingVector); - return new ColorVector(multiply); + return new RgbaVector(multiply); } /// @@ -91,12 +86,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector Screen(ColorVector backdrop, ColorVector source) + public static RgbaVector Screen(RgbaVector backdrop, RgbaVector source) { Vector4 subtract = Vector4BlendTransforms.Screen(backdrop.backingVector, source.backingVector); - return new ColorVector(subtract); + return new RgbaVector(subtract); } /// @@ -106,12 +101,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector HardLight(ColorVector backdrop, ColorVector source) + public static RgbaVector HardLight(RgbaVector backdrop, RgbaVector source) { Vector4 hardlight = Vector4BlendTransforms.HardLight(backdrop.backingVector, source.backingVector); - return new ColorVector(hardlight); + return new RgbaVector(hardlight); } /// @@ -125,12 +120,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector Overlay(ColorVector backdrop, ColorVector source) + public static RgbaVector Overlay(RgbaVector backdrop, RgbaVector source) { Vector4 overlay = Vector4BlendTransforms.Overlay(backdrop.backingVector, source.backingVector); - return new ColorVector(overlay); + return new RgbaVector(overlay); } /// @@ -140,12 +135,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector Darken(ColorVector backdrop, ColorVector source) + public static RgbaVector Darken(RgbaVector backdrop, RgbaVector source) { Vector4 darken = Vector4BlendTransforms.Darken(backdrop.backingVector, source.backingVector); - return new ColorVector(darken); + return new RgbaVector(darken); } /// @@ -155,12 +150,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector Lighten(ColorVector backdrop, ColorVector source) + public static RgbaVector Lighten(RgbaVector backdrop, RgbaVector source) { Vector4 lighten = Vector4BlendTransforms.Lighten(backdrop.backingVector, source.backingVector); - return new ColorVector(lighten); + return new RgbaVector(lighten); } /// @@ -170,12 +165,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector SoftLight(ColorVector backdrop, ColorVector source) + public static RgbaVector SoftLight(RgbaVector backdrop, RgbaVector source) { Vector4 softlight = Vector4BlendTransforms.SoftLight(backdrop.backingVector, source.backingVector); - return new ColorVector(softlight); + return new RgbaVector(softlight); } /// @@ -184,12 +179,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector ColorDodge(ColorVector backdrop, ColorVector source) + public static RgbaVector ColorDodge(RgbaVector backdrop, RgbaVector source) { Vector4 dodge = Vector4BlendTransforms.Dodge(backdrop.backingVector, source.backingVector); - return new ColorVector(dodge); + return new RgbaVector(dodge); } /// @@ -198,12 +193,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector ColorBurn(ColorVector backdrop, ColorVector source) + public static RgbaVector ColorBurn(RgbaVector backdrop, RgbaVector source) { Vector4 burn = Vector4BlendTransforms.Burn(backdrop.backingVector, source.backingVector); - return new ColorVector(burn); + return new RgbaVector(burn); } /// @@ -213,12 +208,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector Difference(ColorVector backdrop, ColorVector source) + public static RgbaVector Difference(RgbaVector backdrop, RgbaVector source) { Vector4 difference = Vector4BlendTransforms.Difference(backdrop.backingVector, source.backingVector); - return new ColorVector(difference); + return new RgbaVector(difference); } /// @@ -228,12 +223,12 @@ namespace ImageSharp /// The backdrop color. /// The source color. /// - /// The . + /// The . /// - public static ColorVector Exclusion(ColorVector backdrop, ColorVector source) + public static RgbaVector Exclusion(RgbaVector backdrop, RgbaVector source) { Vector4 exclusion = Vector4BlendTransforms.Exclusion(backdrop.backingVector, source.backingVector); - return new ColorVector(exclusion); + return new RgbaVector(exclusion); } /// @@ -246,11 +241,11 @@ namespace ImageSharp /// At amount = 0, "from" is returned, at amount = 1, "to" is returned. /// /// - /// The + /// The /// - public static ColorVector Lerp(ColorVector from, ColorVector to, float amount) + public static RgbaVector Lerp(RgbaVector from, RgbaVector to, float amount) { - return new ColorVector(Vector4.Lerp(from.backingVector, to.backingVector, amount)); + return new RgbaVector(Vector4.Lerp(from.backingVector, to.backingVector, amount)); } } } \ No newline at end of file diff --git a/src/ImageSharp/Colors/ColorVector.cs b/src/ImageSharp/PixelFormats/RgbaVector.cs similarity index 83% rename from src/ImageSharp/Colors/ColorVector.cs rename to src/ImageSharp/PixelFormats/RgbaVector.cs index 06ee5b805c..c59e932590 100644 --- a/src/ImageSharp/Colors/ColorVector.cs +++ b/src/ImageSharp/PixelFormats/RgbaVector.cs @@ -1,9 +1,9 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System.Numerics; using System.Runtime.CompilerServices; @@ -11,12 +11,13 @@ namespace ImageSharp /// /// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1. /// The color components are stored in red, green, blue, and alpha order. + /// Ranges from <0, 0, 0, 0> to <1, 1, 1, 1> in vector form. /// /// /// 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 ColorVector : IPixel + public partial struct RgbaVector : IPixel { /// /// The maximum byte value. @@ -34,54 +35,54 @@ namespace ImageSharp private Vector4 backingVector; /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The red component. /// The green component. /// The blue component. /// The alpha component. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ColorVector(byte r, byte g, byte b, byte a = 255) + public RgbaVector(byte r, byte g, byte b, byte a = 255) : this() { this.backingVector = new Vector4(r, g, b, a) / MaxBytes; } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// The red component. /// The green component. /// The blue component. /// The alpha component. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ColorVector(float r, float g, float b, float a = 1) + public RgbaVector(float r, float g, float b, float a = 1) : this() { this.backingVector = new Vector4(r, g, b, a); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The vector containing the components for the packed vector. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ColorVector(Vector3 vector) + public RgbaVector(Vector3 vector) : this() { this.backingVector = new Vector4(vector, 1); } /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// The vector containing the components for the packed vector. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ColorVector(Vector4 vector) + public RgbaVector(Vector4 vector) : this() { this.backingVector = vector; @@ -160,54 +161,54 @@ namespace ImageSharp } /// - /// Compares two objects for equality. + /// Compares two objects for equality. /// /// - /// The on the left side of the operand. + /// The on the left side of the operand. /// /// - /// The on the right side of the operand. + /// The on the right side of the operand. /// /// /// True if the parameter is equal to the parameter; otherwise, false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(ColorVector left, ColorVector right) + public static bool operator ==(RgbaVector left, RgbaVector right) { return left.backingVector == right.backingVector; } /// - /// Compares two objects for equality. + /// 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 parameter is not equal to the parameter; otherwise, false. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(ColorVector left, ColorVector right) + public static bool operator !=(RgbaVector left, RgbaVector right) { return left.backingVector != right.backingVector; } /// - /// Creates a new instance of the struct. + /// Creates a new instance of the struct. /// /// /// The hexadecimal representation of the combined color components arranged /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax. /// /// - /// The . + /// The . /// - public static ColorVector FromHex(string hex) + public static RgbaVector FromHex(string hex) { - return ColorBuilder.FromHex(hex); + return ColorBuilder.FromHex(hex); } /// - public BulkPixelOperations CreateBulkOperations() => new ColorVector.BulkOperations(); + public BulkPixelOperations CreateBulkOperations() => new RgbaVector.BulkOperations(); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -292,12 +293,12 @@ namespace ImageSharp /// public override bool Equals(object obj) { - return (obj is ColorVector) && this.Equals((ColorVector)obj); + return (obj is RgbaVector) && this.Equals((RgbaVector)obj); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ColorVector other) + public bool Equals(RgbaVector other) { return this.backingVector == other.backingVector; } diff --git a/src/ImageSharp/Colors/PackedPixel/Short2.cs b/src/ImageSharp/PixelFormats/Short2.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Short2.cs rename to src/ImageSharp/PixelFormats/Short2.cs index 167a1e786f..60fbb5b35e 100644 --- a/src/ImageSharp/Colors/PackedPixel/Short2.cs +++ b/src/ImageSharp/PixelFormats/Short2.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed pixel type containing two 16-bit signed integer values. + /// Ranges from <-32767, -32767, 0, 1> to <32767, 32767, 0, 1> in vector form. /// public struct Short2 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/PackedPixel/Short4.cs b/src/ImageSharp/PixelFormats/Short4.cs similarity index 98% rename from src/ImageSharp/Colors/PackedPixel/Short4.cs rename to src/ImageSharp/PixelFormats/Short4.cs index e1a559c326..65ce51eb21 100644 --- a/src/ImageSharp/Colors/PackedPixel/Short4.cs +++ b/src/ImageSharp/PixelFormats/Short4.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System; using System.Numerics; @@ -11,6 +11,7 @@ namespace ImageSharp /// /// Packed pixel type containing four 16-bit signed integer values. + /// Ranges from <-37267, -37267, -37267, -37267> to <37267, 37267, 37267, 37267> in vector form. /// public struct Short4 : IPixel, IPackedVector { diff --git a/src/ImageSharp/Colors/Vector4BlendTransforms.cs b/src/ImageSharp/PixelFormats/Vector4BlendTransforms.cs similarity index 99% rename from src/ImageSharp/Colors/Vector4BlendTransforms.cs rename to src/ImageSharp/PixelFormats/Vector4BlendTransforms.cs index a7e2e0e919..87c7a289ed 100644 --- a/src/ImageSharp/Colors/Vector4BlendTransforms.cs +++ b/src/ImageSharp/PixelFormats/Vector4BlendTransforms.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp +namespace ImageSharp.PixelFormats { using System.Numerics; @@ -289,4 +289,4 @@ namespace ImageSharp return b + s - (2F * b * s); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs index 672726d929..f50616aa30 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies binarization to the image splitting the pixels at the given threshold. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. - /// The . - public static Image BinaryThreshold(this Image source, float threshold) - where TColor : struct, IPixel + /// The . + public static Image BinaryThreshold(this Image source, float threshold) + where TPixel : struct, IPixel { return BinaryThreshold(source, threshold, source.Bounds); } @@ -30,17 +32,17 @@ namespace ImageSharp /// /// Applies binarization to the image splitting the pixels at the given threshold. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); + source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs index dd6dfe8a14..617883d6aa 100644 --- a/src/ImageSharp/Processing/Binarization/Dither.cs +++ b/src/ImageSharp/Processing/Binarization/Dither.cs @@ -8,6 +8,7 @@ namespace ImageSharp using System; using ImageSharp.Dithering; + using ImageSharp.PixelFormats; using ImageSharp.Processing.Processors; /// @@ -18,13 +19,13 @@ namespace ImageSharp /// /// Dithers the image reducing it to two colors using ordered dithering. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The ordered ditherer. /// The component index to test the threshold against. Must range from 0 to 3. - /// The . - public static Image Dither(this Image source, IOrderedDither dither, int index = 0) - where TColor : struct, IPixel + /// The . + public static Image Dither(this Image source, IOrderedDither dither, int index = 0) + where TPixel : struct, IPixel { return Dither(source, dither, source.Bounds, index); } @@ -32,7 +33,7 @@ namespace ImageSharp /// /// Dithers the image reducing it to two colors using ordered dithering. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The ordered ditherer. /// @@ -40,23 +41,23 @@ namespace ImageSharp /// /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static Image Dither(this Image source, IOrderedDither dither, Rectangle rectangle, int index = 0) - where TColor : struct, IPixel + public static Image Dither(this Image source, IOrderedDither dither, Rectangle rectangle, int index = 0) + where TPixel : struct, IPixel { - source.ApplyProcessor(new OrderedDitherProcessor(dither, index), rectangle); + source.ApplyProcessor(new OrderedDitherProcessor(dither, index), rectangle); return source; } /// /// Dithers the image reducing it to two colors using error diffusion. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The diffusion algorithm to apply. /// The threshold to apply binarization of the image. Must be between 0 and 1. - /// The . - public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold) - where TColor : struct, IPixel + /// The . + public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold) + where TPixel : struct, IPixel { return Dither(source, diffuser, threshold, source.Bounds); } @@ -64,7 +65,7 @@ namespace ImageSharp /// /// Dithers the image reducing it to two colors using error diffusion. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The diffusion algorithm to apply. /// The threshold to apply binarization of the image. Must be between 0 and 1. @@ -72,10 +73,10 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) - where TColor : struct, IPixel + public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold), rectangle); + source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs index 63d6dd33c5..76977455a4 100644 --- a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs +++ b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.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 pixel format. /// The image this method extends. - /// The . - public static Image BlackWhite(this Image source) - where TColor : struct, IPixel + /// The . + public static Image BlackWhite(this Image source) + where TPixel : struct, IPixel { return BlackWhite(source, source.Bounds); } @@ -30,16 +32,16 @@ namespace ImageSharp /// /// Applies black and white toning to the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image BlackWhite(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image BlackWhite(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); + source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs index 36a139d0ea..d012d6fe2b 100644 --- a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs +++ b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.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 pixel format. /// The image this method extends. /// The type of color blindness simulator to apply. - /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness) - where TColor : struct, IPixel + /// The . + public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness) + where TPixel : struct, IPixel { return ColorBlindness(source, colorBlindness, source.Bounds); } @@ -31,50 +33,50 @@ namespace ImageSharp /// /// Applies the given colorblindness simulator to the image. /// - /// The pixel format. + /// The pixel format. /// 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. /// - /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle) + where TPixel : struct, IPixel { - IImageProcessor processor; + IImageProcessor processor; switch (colorBlindness) { case ImageSharp.Processing.ColorBlindness.Achromatomaly: - processor = new AchromatomalyProcessor(); + processor = new AchromatomalyProcessor(); break; case ImageSharp.Processing.ColorBlindness.Achromatopsia: - processor = new AchromatopsiaProcessor(); + processor = new AchromatopsiaProcessor(); break; case ImageSharp.Processing.ColorBlindness.Deuteranomaly: - processor = new DeuteranomalyProcessor(); + processor = new DeuteranomalyProcessor(); break; case ImageSharp.Processing.ColorBlindness.Deuteranopia: - processor = new DeuteranopiaProcessor(); + processor = new DeuteranopiaProcessor(); break; case ImageSharp.Processing.ColorBlindness.Protanomaly: - processor = new ProtanomalyProcessor(); + processor = new ProtanomalyProcessor(); break; case ImageSharp.Processing.ColorBlindness.Protanopia: - processor = new ProtanopiaProcessor(); + processor = new ProtanopiaProcessor(); break; case ImageSharp.Processing.ColorBlindness.Tritanomaly: - processor = new TritanomalyProcessor(); + processor = new TritanomalyProcessor(); break; default: - processor = new TritanopiaProcessor(); + processor = new TritanopiaProcessor(); break; } diff --git a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs index 613b999d44..8700b63e88 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies Grayscale toning to the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The formula to apply to perform the operation. - /// The . - public static Image Grayscale(this Image source, GrayscaleMode mode = GrayscaleMode.Bt709) - where TColor : struct, IPixel + /// The . + public static Image Grayscale(this Image source, GrayscaleMode mode = GrayscaleMode.Bt709) + where TPixel : struct, IPixel { return Grayscale(source, source.Bounds, mode); } @@ -31,19 +33,19 @@ namespace ImageSharp /// /// Applies Grayscale toning to the image. /// - /// The pixel format. + /// The pixel format. /// 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. - /// The . - public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) - where TColor : struct, IPixel + /// The . + public static Image Grayscale(this Image source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) + where TPixel : struct, IPixel { - IImageProcessor processor = mode == GrayscaleMode.Bt709 - ? (IImageProcessor)new GrayscaleBt709Processor() - : new GrayscaleBt601Processor(); + IImageProcessor processor = mode == GrayscaleMode.Bt709 + ? (IImageProcessor)new GrayscaleBt709Processor() + : new GrayscaleBt601Processor(); source.ApplyProcessor(processor, rectangle); return source; diff --git a/src/ImageSharp/Processing/ColorMatrix/Hue.cs b/src/ImageSharp/Processing/ColorMatrix/Hue.cs index 8edeb2ff31..8dbc555307 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Hue.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Hue.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.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 pixel format. /// The image this method extends. /// The angle in degrees to adjust the image. - /// The . - public static Image Hue(this Image source, float degrees) - where TColor : struct, IPixel + /// The . + public static Image Hue(this Image source, float degrees) + where TPixel : struct, IPixel { return Hue(source, degrees, source.Bounds); } @@ -31,17 +33,17 @@ namespace ImageSharp /// /// Alters the hue component of the image. /// - /// The pixel format. + /// The pixel format. /// 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. /// - /// The . - public static Image Hue(this Image source, float degrees, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Hue(this Image source, float degrees, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new HueProcessor(degrees), rectangle); + source.ApplyProcessor(new HueProcessor(degrees), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs index 5084c96b25..13a71a71ef 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.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 pixel format. /// The image this method extends. - /// The . - public static Image Kodachrome(this Image source) - where TColor : struct, IPixel + /// The . + public static Image Kodachrome(this Image source) + where TPixel : struct, IPixel { return Kodachrome(source, source.Bounds); } @@ -30,16 +32,16 @@ namespace ImageSharp /// /// Alters the colors of the image recreating an old Kodachrome camera effect. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Kodachrome(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Kodachrome(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new KodachromeProcessor(), rectangle); + source.ApplyProcessor(new KodachromeProcessor(), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs index ef6b23d5da..3299add7f7 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.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 pixel format. /// The image this method extends. - /// The . - public static Image Lomograph(this Image source) - where TColor : struct, IPixel + /// The . + public static Image Lomograph(this Image source) + where TPixel : struct, IPixel { return Lomograph(source, source.Bounds); } @@ -30,16 +32,16 @@ namespace ImageSharp /// /// Alters the colors of the image recreating an old Lomograph camera effect. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Lomograph(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Lomograph(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new LomographProcessor(), rectangle); + source.ApplyProcessor(new LomographProcessor(), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs index 68b10173cc..194800ec72 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.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 pixel format. /// The image this method extends. - /// The . - public static Image Polaroid(this Image source) - where TColor : struct, IPixel + /// The . + public static Image Polaroid(this Image source) + where TPixel : struct, IPixel { return Polaroid(source, source.Bounds); } @@ -30,16 +32,16 @@ namespace ImageSharp /// /// Alters the colors of the image recreating an old Polaroid camera effect. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Polaroid(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Polaroid(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new PolaroidProcessor(), rectangle); + source.ApplyProcessor(new PolaroidProcessor(), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs index 7a6359744b..c41f304b4e 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the saturation component of the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. - /// The . - public static Image Saturation(this Image source, int amount) - where TColor : struct, IPixel + /// The . + public static Image Saturation(this Image source, int amount) + where TPixel : struct, IPixel { return Saturation(source, amount, source.Bounds); } @@ -31,17 +33,17 @@ namespace ImageSharp /// /// Alters the saturation component of the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Saturation(this Image source, int amount, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Saturation(this Image source, int amount, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new SaturationProcessor(amount), rectangle); + source.ApplyProcessor(new SaturationProcessor(amount), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs index 4943635e06..d60ec7165a 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies sepia toning to the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The . - public static Image Sepia(this Image source) - where TColor : struct, IPixel + public static Image Sepia(this Image source) + where TPixel : struct, IPixel { return Sepia(source, source.Bounds); } @@ -30,16 +32,16 @@ namespace ImageSharp /// /// Applies sepia toning to the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Sepia(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + public static Image Sepia(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new SepiaProcessor(), rectangle); + source.ApplyProcessor(new SepiaProcessor(), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlur.cs index 428142ffa8..46c134ee20 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Processing/Convolution/BoxBlur.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.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 pixel format. /// The image this method extends. /// The 'radius' value representing the size of the area to sample. - /// The . - public static Image BoxBlur(this Image source, int radius = 7) - where TColor : struct, IPixel + /// The . + public static Image BoxBlur(this Image source, int radius = 7) + where TPixel : struct, IPixel { return BoxBlur(source, radius, source.Bounds); } @@ -30,17 +32,17 @@ namespace ImageSharp /// /// Applies a box blur to the image. /// - /// The pixel format. + /// The pixel format. /// 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. /// - /// The . - public static Image BoxBlur(this Image source, int radius, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image BoxBlur(this Image source, int radius, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); + source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdges.cs index dba062b563..3aa1d0b513 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Processing/Convolution/DetectEdges.cs @@ -7,53 +7,55 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.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 + /// Detects any edges within the image. Uses the filter /// operating in Grayscale mode. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. - /// The . - public static Image DetectEdges(this Image source) - where TColor : struct, IPixel + /// The . + public static Image DetectEdges(this Image source) + where TPixel : struct, IPixel { - return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }); + return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }); } /// - /// Detects any edges within the image. Uses the filter + /// Detects any edges within the image. Uses the filter /// operating in Grayscale mode. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image DetectEdges(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); + return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); } /// /// Detects any edges within the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The filter for detecting edges. /// Whether to convert the image to Grayscale first. Defaults to true. - /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true) - where TColor : struct, IPixel + /// The . + public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true) + where TPixel : struct, IPixel { return DetectEdges(source, filter, source.Bounds, grayscale); } @@ -61,59 +63,59 @@ namespace ImageSharp /// /// Detects any edges within the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The filter for detecting edges. /// /// The structure that specifies the portion of the image object to alter. /// /// Whether to convert the image to Grayscale first. Defaults to true. - /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) - where TColor : struct, IPixel + /// The . + public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + where TPixel : struct, IPixel { - IEdgeDetectorProcessor processor; + IEdgeDetectorProcessor processor; switch (filter) { case EdgeDetection.Kayyali: - processor = new KayyaliProcessor { Grayscale = grayscale }; + processor = new KayyaliProcessor { Grayscale = grayscale }; break; case EdgeDetection.Kirsch: - processor = new KirschProcessor { Grayscale = grayscale }; + processor = new KirschProcessor { Grayscale = grayscale }; break; case EdgeDetection.Lapacian3X3: - processor = new Laplacian3X3Processor { Grayscale = grayscale }; + processor = new Laplacian3X3Processor { Grayscale = grayscale }; break; case EdgeDetection.Lapacian5X5: - processor = new Laplacian5X5Processor { Grayscale = grayscale }; + processor = new Laplacian5X5Processor { Grayscale = grayscale }; break; case EdgeDetection.LaplacianOfGaussian: - processor = new LaplacianOfGaussianProcessor { Grayscale = grayscale }; + processor = new LaplacianOfGaussianProcessor { Grayscale = grayscale }; break; case EdgeDetection.Prewitt: - processor = new PrewittProcessor { Grayscale = grayscale }; + processor = new PrewittProcessor { Grayscale = grayscale }; break; case EdgeDetection.RobertsCross: - processor = new RobertsCrossProcessor { Grayscale = grayscale }; + processor = new RobertsCrossProcessor { Grayscale = grayscale }; break; case EdgeDetection.Robinson: - processor = new RobinsonProcessor { Grayscale = grayscale }; + processor = new RobinsonProcessor { Grayscale = grayscale }; break; case EdgeDetection.Scharr: - processor = new ScharrProcessor { Grayscale = grayscale }; + processor = new ScharrProcessor { Grayscale = grayscale }; break; default: - processor = new SobelProcessor { Grayscale = grayscale }; + processor = new SobelProcessor { Grayscale = grayscale }; break; } @@ -123,12 +125,12 @@ namespace ImageSharp /// /// Detects any edges within the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The filter for detecting edges. - /// The . - public static Image DetectEdges(this Image source, IEdgeDetectorProcessor filter) - where TColor : struct, IPixel + /// The . + public static Image DetectEdges(this Image source, IEdgeDetectorProcessor filter) + where TPixel : struct, IPixel { return DetectEdges(source, source.Bounds, filter); } @@ -136,15 +138,15 @@ namespace ImageSharp /// /// Detects any edges within the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// /// The filter for detecting edges. - /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorProcessor filter) - where TColor : struct, IPixel + /// The . + public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorProcessor filter) + where TPixel : struct, IPixel { source.ApplyProcessor(filter, rectangle); return source; diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs index 81f8546380..72abec6df9 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a Gaussian blur to the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The 'sigma' value representing the weight of the blur. - /// The . - public static Image GaussianBlur(this Image source, float sigma = 3f) - where TColor : struct, IPixel + /// The . + public static Image GaussianBlur(this Image source, float sigma = 3f) + where TPixel : struct, IPixel { return GaussianBlur(source, sigma, source.Bounds); } @@ -31,17 +33,17 @@ namespace ImageSharp /// /// Applies a Gaussian blur to the image. /// - /// The pixel format. + /// The pixel format. /// 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. /// - /// The . - public static Image GaussianBlur(this Image source, float sigma, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image GaussianBlur(this Image source, float sigma, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); + source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs index 61816198a5..2ed99ea260 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a Gaussian sharpening filter to the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The 'sigma' value representing the weight of the blur. - /// The . - public static Image GaussianSharpen(this Image source, float sigma = 3f) - where TColor : struct, IPixel + /// The . + public static Image GaussianSharpen(this Image source, float sigma = 3f) + where TPixel : struct, IPixel { return GaussianSharpen(source, sigma, source.Bounds); } @@ -31,17 +33,17 @@ namespace ImageSharp /// /// Applies a Gaussian sharpening filter to the image. /// - /// The pixel format. + /// The pixel format. /// 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. /// - /// The . - public static Image GaussianSharpen(this Image source, float sigma, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image GaussianSharpen(this Image source, float sigma, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); + source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Effects/Alpha.cs b/src/ImageSharp/Processing/Effects/Alpha.cs index 39849d4d4b..a54bde675b 100644 --- a/src/ImageSharp/Processing/Effects/Alpha.cs +++ b/src/ImageSharp/Processing/Effects/Alpha.cs @@ -7,6 +7,8 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// @@ -17,12 +19,12 @@ namespace ImageSharp /// /// Alters the alpha component of the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The new opacity of the image. Must be between 0 and 100. - /// The . - public static Image Alpha(this Image source, int percent) - where TColor : struct, IPixel + /// The . + public static Image Alpha(this Image source, int percent) + where TPixel : struct, IPixel { return Alpha(source, percent, source.Bounds); } @@ -30,17 +32,17 @@ namespace ImageSharp /// /// Alters the alpha component of the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The new opacity of the image. Must be between 0 and 100. /// /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Alpha(this Image source, int percent, Rectangle rectangle) - where TColor : struct, IPixel + public static Image Alpha(this Image source, int percent, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new AlphaProcessor(percent), rectangle); + source.ApplyProcessor(new AlphaProcessor(percent), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Effects/BackgroundColor.cs index 2e621172e1..cb189338e7 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Effects/BackgroundColor.cs @@ -7,24 +7,26 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Replaces the background color of image with the given one. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The color to set as the background. - /// The . - public static Image BackgroundColor(this Image source, TColor color) - where TColor : struct, IPixel + /// The . + public static Image BackgroundColor(this Image source, TPixel color) + where TPixel : struct, IPixel { - source.ApplyProcessor(new BackgroundColorProcessor(color), source.Bounds); + source.ApplyProcessor(new BackgroundColorProcessor(color), source.Bounds); return source; } } diff --git a/src/ImageSharp/Processing/Effects/Brightness.cs b/src/ImageSharp/Processing/Effects/Brightness.cs index 8ba702c4f5..6b7477488a 100644 --- a/src/ImageSharp/Processing/Effects/Brightness.cs +++ b/src/ImageSharp/Processing/Effects/Brightness.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.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 pixel format. /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. - /// The . - public static Image Brightness(this Image source, int amount) - where TColor : struct, IPixel + /// The . + public static Image Brightness(this Image source, int amount) + where TPixel : struct, IPixel { return Brightness(source, amount, source.Bounds); } @@ -30,17 +32,17 @@ namespace ImageSharp /// /// Alters the brightness component of the image. /// - /// The pixel format. + /// The pixel format. /// 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. /// - /// The . - public static Image Brightness(this Image source, int amount, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Brightness(this Image source, int amount, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); + source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Effects/Contrast.cs b/src/ImageSharp/Processing/Effects/Contrast.cs index 0228f4fe37..8f226d08e2 100644 --- a/src/ImageSharp/Processing/Effects/Contrast.cs +++ b/src/ImageSharp/Processing/Effects/Contrast.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.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 pixel format. /// The image this method extends. /// The new contrast of the image. Must be between -100 and 100. - /// The . - public static Image Contrast(this Image source, int amount) - where TColor : struct, IPixel + /// The . + public static Image Contrast(this Image source, int amount) + where TPixel : struct, IPixel { return Contrast(source, amount, source.Bounds); } @@ -30,17 +32,17 @@ namespace ImageSharp /// /// Alters the contrast component of the image. /// - /// The pixel format. + /// The pixel format. /// 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. /// - /// The . - public static Image Contrast(this Image source, int amount, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Contrast(this Image source, int amount, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new ContrastProcessor(amount), rectangle); + source.ApplyProcessor(new ContrastProcessor(amount), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Effects/Invert.cs b/src/ImageSharp/Processing/Effects/Invert.cs index 6c51ad3eb3..113d8289e7 100644 --- a/src/ImageSharp/Processing/Effects/Invert.cs +++ b/src/ImageSharp/Processing/Effects/Invert.cs @@ -7,21 +7,23 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Inverts the colors of the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The . - public static Image Invert(this Image source) - where TColor : struct, IPixel + public static Image Invert(this Image source) + where TPixel : struct, IPixel { return Invert(source, source.Bounds); } @@ -29,16 +31,16 @@ namespace ImageSharp /// /// Inverts the colors of the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Invert(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + public static Image Invert(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - source.ApplyProcessor(new InvertProcessor(), rectangle); + source.ApplyProcessor(new InvertProcessor(), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Effects/OilPainting.cs b/src/ImageSharp/Processing/Effects/OilPainting.cs index d7d8444c01..d4528b55ba 100644 --- a/src/ImageSharp/Processing/Effects/OilPainting.cs +++ b/src/ImageSharp/Processing/Effects/OilPainting.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Alters the colors of the image recreating an oil painting effect. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. - /// The . - public static Image OilPaint(this Image source, int levels = 10, int brushSize = 15) - where TColor : struct, IPixel + /// The . + public static Image OilPaint(this Image source, int levels = 10, int brushSize = 15) + where TPixel : struct, IPixel { return OilPaint(source, levels, brushSize, source.Bounds); } @@ -31,16 +33,16 @@ namespace ImageSharp /// /// Alters the colors of the image recreating an oil painting effect. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image OilPaint(this Image source, int levels, int brushSize, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image OilPaint(this Image source, int levels, int brushSize, Rectangle rectangle) + where TPixel : struct, IPixel { Guard.MustBeGreaterThan(levels, 0, nameof(levels)); @@ -49,7 +51,7 @@ namespace ImageSharp throw new ArgumentOutOfRangeException(nameof(brushSize)); } - source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); + source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Effects/Pixelate.cs b/src/ImageSharp/Processing/Effects/Pixelate.cs index 721dd930b0..eeffff0925 100644 --- a/src/ImageSharp/Processing/Effects/Pixelate.cs +++ b/src/ImageSharp/Processing/Effects/Pixelate.cs @@ -7,22 +7,24 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Pixelates an image with the given pixel size. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The size of the pixels. - /// The . - public static Image Pixelate(this Image source, int size = 4) - where TColor : struct, IPixel + /// The . + public static Image Pixelate(this Image source, int size = 4) + where TPixel : struct, IPixel { return Pixelate(source, size, source.Bounds); } @@ -30,22 +32,22 @@ namespace ImageSharp /// /// Pixelates an image with the given pixel size. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The size of the pixels. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Pixelate(this Image source, int size, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Pixelate(this Image source, int size, Rectangle rectangle) + where TPixel : struct, IPixel { if (size <= 0 || size > source.Height || size > source.Width) { throw new ArgumentOutOfRangeException(nameof(size)); } - source.ApplyProcessor(new PixelateProcessor(size), rectangle); + source.ApplyProcessor(new PixelateProcessor(size), rectangle); return source; } } diff --git a/src/ImageSharp/Processing/Overlays/Glow.cs b/src/ImageSharp/Processing/Overlays/Glow.cs index e8dfbdf0ef..1be15ad650 100644 --- a/src/ImageSharp/Processing/Overlays/Glow.cs +++ b/src/ImageSharp/Processing/Overlays/Glow.cs @@ -7,34 +7,36 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a radial glow effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. - /// The . - public static Image Glow(this Image source) - where TColor : struct, IPixel + /// The . + public static Image Glow(this Image source) + where TPixel : struct, IPixel { - return Glow(source, NamedColors.Black, source.Bounds.Width * .5F, source.Bounds); + return Glow(source, NamedColors.Black, source.Bounds.Width * .5F, source.Bounds); } /// /// Applies a radial glow effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The color to set as the glow. - /// The . - public static Image Glow(this Image source, TColor color) - where TColor : struct, IPixel + /// The . + public static Image Glow(this Image source, TPixel color) + where TPixel : struct, IPixel { return Glow(source, color, source.Bounds.Width * .5F, source.Bounds); } @@ -42,46 +44,46 @@ namespace ImageSharp /// /// Applies a radial glow effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The the radius. - /// The . - public static Image Glow(this Image source, float radius) - where TColor : struct, IPixel + /// The . + public static Image Glow(this Image source, float radius) + where TPixel : struct, IPixel { - return Glow(source, NamedColors.Black, radius, source.Bounds); + return Glow(source, NamedColors.Black, radius, source.Bounds); } /// /// Applies a radial glow effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Glow(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Glow(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - return Glow(source, NamedColors.Black, 0, rectangle); + return Glow(source, NamedColors.Black, 0, rectangle); } /// /// Applies a radial glow effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The color to set as the glow. /// The the radius. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Glow(this Image source, TColor color, float radius, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Glow(this Image source, TPixel color, float radius, Rectangle rectangle) + where TPixel : struct, IPixel { - GlowProcessor processor = new GlowProcessor(color) { Radius = radius, }; + GlowProcessor processor = new GlowProcessor(color) { Radius = radius, }; source.ApplyProcessor(processor, rectangle); return source; } diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs index e42ead8d3a..f805dd07a0 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/Vignette.cs @@ -7,34 +7,36 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. - /// The . - public static Image Vignette(this Image source) - where TColor : struct, IPixel + /// The . + public static Image Vignette(this Image source) + where TPixel : struct, IPixel { - return Vignette(source, NamedColors.Black, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds); + return Vignette(source, NamedColors.Black, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds); } /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The color to set as the vignette. - /// The . - public static Image Vignette(this Image source, TColor color) - where TColor : struct, IPixel + /// The . + public static Image Vignette(this Image source, TPixel color) + where TPixel : struct, IPixel { return Vignette(source, color, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds); } @@ -42,36 +44,36 @@ namespace ImageSharp /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The the x-radius. /// The the y-radius. - /// The . - public static Image Vignette(this Image source, float radiusX, float radiusY) - where TColor : struct, IPixel + /// The . + public static Image Vignette(this Image source, float radiusX, float radiusY) + where TPixel : struct, IPixel { - return Vignette(source, NamedColors.Black, radiusX, radiusY, source.Bounds); + return Vignette(source, NamedColors.Black, radiusX, radiusY, source.Bounds); } /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Vignette(this Image source, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Vignette(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel { - return Vignette(source, NamedColors.Black, 0, 0, rectangle); + return Vignette(source, NamedColors.Black, 0, 0, rectangle); } /// /// Applies a radial vignette effect to an image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The color to set as the vignette. /// The the x-radius. @@ -79,11 +81,11 @@ namespace ImageSharp /// /// The structure that specifies the portion of the image object to alter. /// - /// The . - public static Image Vignette(this Image source, TColor color, float radiusX, float radiusY, Rectangle rectangle) - where TColor : struct, IPixel + /// The . + public static Image Vignette(this Image source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) + where TPixel : struct, IPixel { - VignetteProcessor processor = new VignetteProcessor(color) { RadiusX = radiusX, RadiusY = radiusY }; + VignetteProcessor processor = new VignetteProcessor(color) { RadiusX = radiusX, RadiusY = radiusY }; source.ApplyProcessor(processor, rectangle); return source; } diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs index 5555463418..566449b275 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs @@ -8,16 +8,18 @@ namespace ImageSharp.Processing.Processors using System; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An to perform binary threshold filtering against an + /// An to perform binary threshold filtering against an /// . The image will be converted to grayscale before thresholding occurs. /// - /// The pixel format. - internal class BinaryThresholdProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class BinaryThresholdProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The threshold to split the image. Must be between 0 and 1. public BinaryThresholdProcessor(float threshold) @@ -27,8 +29,8 @@ namespace ImageSharp.Processing.Processors this.Threshold = threshold; // Default to white/black for upper/lower. - this.UpperColor = NamedColors.White; - this.LowerColor = NamedColors.Black; + this.UpperColor = NamedColors.White; + this.LowerColor = NamedColors.Black; } /// @@ -39,25 +41,25 @@ namespace ImageSharp.Processing.Processors /// /// Gets or sets the color to use for pixels that are above the threshold. /// - public TColor UpperColor { get; set; } + public TPixel UpperColor { get; set; } /// /// Gets or sets the color to use for pixels that fall below the threshold. /// - public TColor LowerColor { get; set; } + public TPixel LowerColor { get; set; } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float threshold = this.Threshold; - TColor upper = this.UpperColor; - TColor lower = this.LowerColor; + TPixel upper = this.UpperColor; + TPixel lower = this.LowerColor; int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -81,7 +83,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -93,7 +95,7 @@ namespace ImageSharp.Processing.Processors for (int x = minX; x < maxX; x++) { int offsetX = x - startX; - TColor color = sourcePixels[offsetX, offsetY]; + TPixel color = sourcePixels[offsetX, offsetY]; // Any channel will do since it's Grayscale. sourcePixels[offsetX, offsetY] = color.ToVector4().X >= threshold ? upper : lower; diff --git a/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs index 50f042bd69..af2d9f760a 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/ErrorDiffusionDitherProcessor.cs @@ -8,16 +8,17 @@ namespace ImageSharp.Processing.Processors using System; using ImageSharp.Dithering; + using ImageSharp.PixelFormats; /// - /// An that dithers an image using error diffusion. + /// An that dithers an image using error diffusion. /// - /// The pixel format. - internal class ErrorDiffusionDitherProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class ErrorDiffusionDitherProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The error diffuser /// The threshold to split the image. Must be between 0 and 1. @@ -29,8 +30,8 @@ namespace ImageSharp.Processing.Processors this.Threshold = threshold; // Default to white/black for upper/lower. - this.UpperColor = NamedColors.White; - this.LowerColor = NamedColors.Black; + this.UpperColor = NamedColors.White; + this.LowerColor = NamedColors.Black; } /// @@ -46,21 +47,21 @@ namespace ImageSharp.Processing.Processors /// /// Gets or sets the color to use for pixels that are above the threshold. /// - public TColor UpperColor { get; set; } + public TPixel UpperColor { get; set; } /// /// Gets or sets the color to use for pixels that fall below the threshold. /// - public TColor LowerColor { get; set; } + public TPixel LowerColor { get; set; } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -84,7 +85,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { for (int y = minY; y < maxY; y++) { @@ -92,8 +93,8 @@ namespace ImageSharp.Processing.Processors for (int x = minX; x < maxX; x++) { int offsetX = x - startX; - TColor sourceColor = sourcePixels[offsetX, offsetY]; - TColor transformedColor = sourceColor.ToVector4().X >= this.Threshold ? this.UpperColor : this.LowerColor; + TPixel sourceColor = sourcePixels[offsetX, offsetY]; + TPixel transformedColor = sourceColor.ToVector4().X >= this.Threshold ? this.UpperColor : this.LowerColor; this.Diffuser.Dither(sourcePixels, sourceColor, transformedColor, offsetX, offsetY, maxX, maxY); } } diff --git a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs index c7f4d20ace..c4d71d9afe 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/OrderedDitherProcessor.cs @@ -9,16 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Buffers; using ImageSharp.Dithering; + using ImageSharp.PixelFormats; /// - /// An that dithers an image using error diffusion. + /// An that dithers an image using error diffusion. /// - /// The pixel format. - internal class OrderedDitherProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class OrderedDitherProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The ordered ditherer. /// The component index to test the threshold against. Must range from 0 to 3. @@ -28,7 +29,7 @@ namespace ImageSharp.Processing.Processors Guard.MustBeBetweenOrEqualTo(index, 0, 3, nameof(index)); // Alpha8 only stores the pixel data in the alpha channel. - if (typeof(TColor) == typeof(Alpha8)) + if (typeof(TPixel) == typeof(Alpha8)) { index = 3; } @@ -37,8 +38,8 @@ namespace ImageSharp.Processing.Processors this.Index = index; // Default to white/black for upper/lower. - this.UpperColor = NamedColors.White; - this.LowerColor = NamedColors.Black; + this.UpperColor = NamedColors.White; + this.LowerColor = NamedColors.Black; } /// @@ -54,21 +55,21 @@ namespace ImageSharp.Processing.Processors /// /// Gets or sets the color to use for pixels that are above the threshold. /// - public TColor UpperColor { get; set; } + public TPixel UpperColor { get; set; } /// /// Gets or sets the color to use for pixels that fall below the threshold. /// - public TColor LowerColor { get; set; } + public TPixel LowerColor { get; set; } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -92,7 +93,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { for (int y = minY; y < maxY; y++) { @@ -102,7 +103,7 @@ namespace ImageSharp.Processing.Processors for (int x = minX; x < maxX; x++) { int offsetX = x - startX; - TColor sourceColor = sourcePixels[offsetX, offsetY]; + TPixel sourceColor = sourcePixels[offsetX, offsetY]; this.Dither.Dither(sourcePixels, sourceColor, this.UpperColor, this.LowerColor, bytes, this.Index, offsetX, offsetY, maxX, maxY); } diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs index 0214af72de..d37d119a41 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/BlackWhiteProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image to their black and white equivalent. /// - /// The pixel format. - internal class BlackWhiteProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class BlackWhiteProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs index d1e986a9df..a91bd19467 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatomalyProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating Achromatomaly (Color desensitivity) color blindness. /// - /// The pixel format. - internal class AchromatomalyProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class AchromatomalyProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs index d17e28dcaf..d543c4edca 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/AchromatopsiaProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating Achromatopsia (Monochrome) color blindness. /// - /// The pixel format. - internal class AchromatopsiaProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class AchromatopsiaProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs index 7f4529ba47..ea73d0c662 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranomalyProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating Deuteranomaly (Green-Weak) color blindness. /// - /// The pixel format. - internal class DeuteranomalyProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class DeuteranomalyProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs index 493ed2caed..4b5129a8bf 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/DeuteranopiaProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating Deuteranopia (Green-Blind) color blindness. /// - /// The pixel format. - internal class DeuteranopiaProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class DeuteranopiaProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs index ddea24be01..14eea08126 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanomalyProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating Protanopia (Red-Weak) color blindness. /// - /// The pixel format. - internal class ProtanomalyProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class ProtanomalyProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs index c5446dbe1a..39cb715bde 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/ProtanopiaProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating Protanopia (Red-Blind) color blindness. /// - /// The pixel format. - internal class ProtanopiaProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class ProtanopiaProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs index 846e9c61a7..2b402197bc 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanomalyProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating Tritanomaly (Blue-Weak) color blindness. /// - /// The pixel format. - internal class TritanomalyProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class TritanomalyProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs index a0094f71f0..5d228afa79 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorBlindness/TritanopiaProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating Tritanopia (Blue-Blind) color blindness. /// - /// The pixel format. - internal class TritanopiaProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class TritanopiaProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs index c75da00037..b38093d634 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/ColorMatrixProcessor.cs @@ -9,12 +9,14 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// The color matrix filter. Inherit from this class to perform operation involving color matrices. /// - /// The pixel format. - internal abstract class ColorMatrixProcessor : ImageProcessor, IColorMatrixFilter - where TColor : struct, IPixel + /// The pixel format. + internal abstract class ColorMatrixProcessor : ImageProcessor, IColorMatrixFilter + where TPixel : struct, IPixel { /// public abstract Matrix4x4 Matrix { get; } @@ -23,7 +25,7 @@ namespace ImageSharp.Processing.Processors public override bool Compand { get; set; } = true; /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -50,7 +52,7 @@ namespace ImageSharp.Processing.Processors Matrix4x4 matrix = this.Matrix; bool compand = this.Compand; - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -75,9 +77,9 @@ namespace ImageSharp.Processing.Processors /// The matrix. /// Whether to compand the color during processing. /// - /// The . + /// The . /// - private TColor ApplyMatrix(TColor color, Matrix4x4 matrix, bool compand) + private TPixel ApplyMatrix(TPixel color, Matrix4x4 matrix, bool compand) { Vector4 vector = color.ToVector4(); @@ -87,7 +89,7 @@ namespace ImageSharp.Processing.Processors } vector = Vector4.Transform(vector, matrix); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(compand ? vector.Compress() : vector); return packed; } diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs index 1f5a0fa7e9..65de8a66d2 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt601Processor.cs @@ -8,13 +8,15 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image to Grayscale applying the formula as specified by ITU-R Recommendation BT.601 /// . /// - /// The pixel format. - internal class GrayscaleBt601Processor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class GrayscaleBt601Processor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs index 048462696a..5f71e357b7 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/GrayscaleBt709Processor.cs @@ -8,13 +8,15 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image to Grayscale applying the formula as specified by ITU-R Recommendation BT.709 /// . /// - /// The pixel format. - internal class GrayscaleBt709Processor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class GrayscaleBt709Processor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs index 0d06c58682..8995663a3b 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/HueProcessor.cs @@ -8,15 +8,17 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// - /// An to change the hue of an . + /// An to change the hue of an . /// - /// The pixel format. - internal class HueProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class HueProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The new brightness of the image. Must be between -100 and 100. public HueProcessor(float angle) diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs index 57296a0c3b..0c29c65a10 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/IColorMatrixFilter.cs @@ -8,13 +8,15 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Encapsulates properties and methods for creating processors that utilize a matrix to /// alter the image pixels. /// - /// The pixel format. - internal interface IColorMatrixFilter : IImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal interface IColorMatrixFilter : IImageProcessor + where TPixel : struct, IPixel { /// /// Gets the used to alter the image. diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs index 8df8efcd19..18514236f7 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/KodachromeProcessor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating an old Kodachrome camera effect. /// - /// The pixel format. - internal class KodachromeProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class KodachromeProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4() diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs index b89caec863..70b9979972 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/LomographProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating an old Lomograph effect. /// - /// The pixel format. - internal class LomographProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class LomographProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { - private static readonly TColor VeryDarkGreen = ColorBuilder.FromRGBA(0, 10, 0, 255); + private static readonly TPixel VeryDarkGreen = ColorBuilder.FromRGBA(0, 10, 0, 255); /// public override Matrix4x4 Matrix => new Matrix4x4() @@ -30,9 +32,9 @@ namespace ImageSharp.Processing.Processors }; /// - protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) { - new VignetteProcessor(VeryDarkGreen).Apply(source, sourceRectangle); + new VignetteProcessor(VeryDarkGreen).Apply(source, sourceRectangle); } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs index b5a23f8557..ccc3c00608 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs @@ -8,15 +8,17 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image recreating an old Polaroid effect. /// - /// The pixel format. - internal class PolaroidProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class PolaroidProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { - private static TColor veryDarkOrange = ColorBuilder.FromRGB(102, 34, 0); - private static TColor lightOrange = ColorBuilder.FromRGBA(255, 153, 102, 178); + private static TPixel veryDarkOrange = ColorBuilder.FromRGB(102, 34, 0); + private static TPixel lightOrange = ColorBuilder.FromRGBA(255, 153, 102, 178); /// public override Matrix4x4 Matrix => new Matrix4x4() @@ -37,10 +39,10 @@ namespace ImageSharp.Processing.Processors }; /// - protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) { - new VignetteProcessor(veryDarkOrange).Apply(source, sourceRectangle); - new GlowProcessor(lightOrange) { Radius = source.Width / 4F }.Apply(source, sourceRectangle); + new VignetteProcessor(veryDarkOrange).Apply(source, sourceRectangle); + new GlowProcessor(lightOrange) { Radius = source.Width / 4F }.Apply(source, sourceRectangle); } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs index 371294dd56..3adfb83114 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs @@ -8,15 +8,17 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// - /// An to change the saturation of an . + /// An to change the saturation of an . /// - /// The pixel format. - internal class SaturationProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class SaturationProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The new saturation of the image. Must be between -100 and 100. /// diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs index 49a071bd98..89be3acad5 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/SepiaProcessor.cs @@ -8,13 +8,15 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Converts the colors of the image to their sepia equivalent. /// The formula used matches the svg specification. /// - /// The pixel format. - internal class SepiaProcessor : ColorMatrixProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class SepiaProcessor : ColorMatrixProcessor + where TPixel : struct, IPixel { /// public override Matrix4x4 Matrix => new Matrix4x4 diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs index 7ffca534cd..6524423880 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs @@ -7,12 +7,14 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.PixelFormats; + /// /// Applies a Box blur sampler to the image. /// - /// The pixel format. - internal class BoxBlurProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class BoxBlurProcessor : ImageProcessor + where TPixel : struct, IPixel { /// /// The maximum size of the kernel in either direction. @@ -20,7 +22,7 @@ namespace ImageSharp.Processing.Processors private readonly int kernelSize; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'radius' value representing the size of the area to sample. @@ -43,9 +45,9 @@ namespace ImageSharp.Processing.Processors public Fast2DArray KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); + new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs index fa06a863ec..ac96c40ae6 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Defines a sampler that uses two one-dimensional matrices to perform convolution against an image. /// - /// The pixel format. - internal class Convolution2DProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class Convolution2DProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The horizontal gradient operator. /// The vertical gradient operator. @@ -38,7 +40,7 @@ namespace ImageSharp.Processing.Processors public Fast2DArray KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int kernelYHeight = this.KernelY.Height; int kernelYWidth = this.KernelY.Width; @@ -54,9 +56,9 @@ namespace ImageSharp.Processing.Processors int maxY = endY - 1; int maxX = endX - 1; - using (PixelAccessor targetPixels = new PixelAccessor(source.Width, source.Height)) + using (PixelAccessor targetPixels = new PixelAccessor(source.Width, source.Height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( startY, @@ -112,7 +114,7 @@ namespace ImageSharp.Processing.Processors float green = MathF.Sqrt((gX * gX) + (gY * gY)); float blue = MathF.Sqrt((bX * bX) + (bY * bY)); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(new Vector4(red, green, blue, sourcePixels[x, y].ToVector4().W)); targetPixels[x, y] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs index 45906a46fc..9b95cb1a37 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Defines a sampler that uses two one-dimensional matrices to perform two-pass convolution against an image. /// - /// The pixel format. - internal class Convolution2PassProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class Convolution2PassProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The horizontal gradient operator. /// The vertical gradient operator. @@ -38,15 +40,15 @@ namespace ImageSharp.Processing.Processors public Fast2DArray KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int width = source.Width; int height = source.Height; - using (PixelAccessor targetPixels = new PixelAccessor(width, height)) + using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { - using (PixelAccessor firstPassPixels = new PixelAccessor(width, height)) - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor firstPassPixels = new PixelAccessor(width, height)) + using (PixelAccessor sourcePixels = source.Lock()) { this.ApplyConvolution(firstPassPixels, sourcePixels, sourceRectangle, this.KernelX); this.ApplyConvolution(targetPixels, firstPassPixels, sourceRectangle, this.KernelY); @@ -57,7 +59,7 @@ namespace ImageSharp.Processing.Processors } /// - /// Applies the process to the specified portion of the specified at the specified location + /// Applies the process to the specified portion of the specified at the specified location /// and with the specified size. /// /// The target pixels to apply the process to. @@ -66,7 +68,7 @@ namespace ImageSharp.Processing.Processors /// The structure that specifies the portion of the image object to draw. /// /// The kernel operator. - private void ApplyConvolution(PixelAccessor targetPixels, PixelAccessor sourcePixels, Rectangle sourceRectangle, Fast2DArray kernel) + private void ApplyConvolution(PixelAccessor targetPixels, PixelAccessor sourcePixels, Rectangle sourceRectangle, Fast2DArray kernel) { int kernelHeight = kernel.Height; int kernelWidth = kernel.Width; @@ -110,7 +112,7 @@ namespace ImageSharp.Processing.Processors } } - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(destination); targetPixels[x, y] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs index 3ab95c4ce9..a0c1400286 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Defines a sampler that uses a 2 dimensional matrix to perform convolution against an image. /// - /// The pixel format. - internal class ConvolutionProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class ConvolutionProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The 2d gradient operator. public ConvolutionProcessor(Fast2DArray kernelXY) @@ -31,7 +33,7 @@ namespace ImageSharp.Processing.Processors public Fast2DArray KernelXY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int kernelLength = this.KernelXY.Height; int radius = kernelLength >> 1; @@ -43,9 +45,9 @@ namespace ImageSharp.Processing.Processors int maxY = endY - 1; int maxX = endX - 1; - using (PixelAccessor targetPixels = new PixelAccessor(source.Width, source.Height)) + using (PixelAccessor targetPixels = new PixelAccessor(source.Width, source.Height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( startY, @@ -83,7 +85,7 @@ namespace ImageSharp.Processing.Processors } } - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(new Vector4(red, green, blue, sourcePixels[x, y].ToVector4().W)); targetPixels[x, y] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs index b5c6816569..457854a314 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs @@ -7,15 +7,17 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.PixelFormats; + /// /// Defines a sampler that detects edges within an image using two one-dimensional matrices. /// - /// The pixel format. - internal abstract class EdgeDetector2DProcessor : ImageProcessor, IEdgeDetectorProcessor - where TColor : struct, IPixel + /// The pixel format. + internal abstract class EdgeDetector2DProcessor : ImageProcessor, IEdgeDetectorProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The horizontal gradient operator. /// The vertical gradient operator. @@ -39,17 +41,17 @@ namespace ImageSharp.Processing.Processors public bool Grayscale { get; set; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new Convolution2DProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); + new Convolution2DProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (this.Grayscale) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs index e92c2d1093..a4d1d54094 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs @@ -9,12 +9,14 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Defines a sampler that detects edges within an image using a eight two dimensional matrices. /// - /// The pixel format. - internal abstract class EdgeDetectorCompassProcessor : ImageProcessor, IEdgeDetectorProcessor - where TColor : struct, IPixel + /// The pixel format. + internal abstract class EdgeDetectorCompassProcessor : ImageProcessor, IEdgeDetectorProcessor + where TPixel : struct, IPixel { /// /// Gets the North gradient operator @@ -60,16 +62,16 @@ namespace ImageSharp.Processing.Processors public bool Grayscale { get; set; } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (this.Grayscale) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { Fast2DArray[] kernels = { this.North, this.NorthWest, this.West, this.SouthWest, this.South, this.SouthEast, this.East, this.NorthEast }; @@ -85,9 +87,9 @@ namespace ImageSharp.Processing.Processors int maxY = Math.Min(source.Height, endY); // we need a clean copy for each pass to start from - using (ImageBase cleanCopy = new Image(source)) + using (ImageBase cleanCopy = new Image(source)) { - new ConvolutionProcessor(kernels[0]).Apply(source, sourceRectangle); + new ConvolutionProcessor(kernels[0]).Apply(source, sourceRectangle); if (kernels.Length == 1) { @@ -112,12 +114,12 @@ namespace ImageSharp.Processing.Processors // ReSharper disable once ForCanBeConvertedToForeach for (int i = 1; i < kernels.Length; i++) { - using (ImageBase pass = new Image(cleanCopy)) + using (ImageBase pass = new Image(cleanCopy)) { - new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle); + new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle); - using (PixelAccessor passPixels = pass.Lock()) - using (PixelAccessor targetPixels = source.Lock()) + using (PixelAccessor passPixels = pass.Lock()) + using (PixelAccessor targetPixels = source.Lock()) { Parallel.For( minY, @@ -131,7 +133,7 @@ namespace ImageSharp.Processing.Processors int offsetX = x - shiftX; // Grab the max components of the two pixels - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(Vector4.Max(passPixels[offsetX, offsetY].ToVector4(), targetPixels[offsetX, offsetY].ToVector4())); targetPixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs index d8b491faf5..e7670dd1d2 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs @@ -7,15 +7,17 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.PixelFormats; + /// /// Defines a sampler that detects edges within an image using a single two dimensional matrix. /// - /// The pixel format. - internal abstract class EdgeDetectorProcessor : ImageProcessor, IEdgeDetectorProcessor - where TColor : struct, IPixel + /// The pixel format. + internal abstract class EdgeDetectorProcessor : ImageProcessor, IEdgeDetectorProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The 2d gradient operator. protected EdgeDetectorProcessor(Fast2DArray kernelXY) @@ -32,18 +34,18 @@ namespace ImageSharp.Processing.Processors public Fast2DArray KernelXY { get; } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (this.Grayscale) { - new GrayscaleBt709Processor().Apply(source, sourceRectangle); + new GrayscaleBt709Processor().Apply(source, sourceRectangle); } } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new ConvolutionProcessor(this.KernelXY).Apply(source, sourceRectangle); + new ConvolutionProcessor(this.KernelXY).Apply(source, sourceRectangle); } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs index 7c0923bbbd..c7c126794d 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs @@ -7,12 +7,14 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.PixelFormats; + /// /// Provides properties and methods allowing the detection of edges within an image. /// - /// The pixel format. - public interface IEdgeDetectorProcessor : IImageProcessor, IEdgeDetectorProcessor - where TColor : struct, IPixel + /// The pixel format. + public interface IEdgeDetectorProcessor : IImageProcessor, IEdgeDetectorProcessor + where TPixel : struct, IPixel { } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs index 20e7b1b176..d72816a76d 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Kayyali operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class KayyaliProcessor : EdgeDetector2DProcessor - where TColor : struct, IPixel + internal class KayyaliProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel { /// /// The horizontal gradient operator. @@ -40,7 +42,7 @@ namespace ImageSharp.Processing.Processors }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public KayyaliProcessor() : base(KayyaliX, KayyaliY) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs index 1b88a2200e..d882bdb169 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/KirschProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Kirsch operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class KirschProcessor : EdgeDetectorCompassProcessor - where TColor : struct, IPixel + internal class KirschProcessor : EdgeDetectorCompassProcessor + where TPixel : struct, IPixel { /// /// The North gradient operator diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs index ec6963b1ea..39f64fb5a3 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian3X3Processor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Laplacian 3 x 3 operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class Laplacian3X3Processor : EdgeDetectorProcessor - where TColor : struct, IPixel + internal class Laplacian3X3Processor : EdgeDetectorProcessor + where TPixel : struct, IPixel { /// /// The 2d gradient operator. @@ -29,7 +31,7 @@ namespace ImageSharp.Processing.Processors }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public Laplacian3X3Processor() : base(Laplacian3X3XY) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs index cc68c4fb71..c65cb5bd76 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/Laplacian5X5Processor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Laplacian 5 x 5 operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class Laplacian5X5Processor : EdgeDetectorProcessor - where TColor : struct, IPixel + internal class Laplacian5X5Processor : EdgeDetectorProcessor + where TPixel : struct, IPixel { /// /// The 2d gradient operator. @@ -31,7 +33,7 @@ namespace ImageSharp.Processing.Processors }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public Laplacian5X5Processor() : base(Laplacian5X5XY) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs index f0944e6818..57ab4dce62 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/LaplacianOfGaussianProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Laplacian of Gaussian operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class LaplacianOfGaussianProcessor : EdgeDetectorProcessor - where TColor : struct, IPixel + internal class LaplacianOfGaussianProcessor : EdgeDetectorProcessor + where TPixel : struct, IPixel { /// /// The 2d gradient operator. @@ -31,7 +33,7 @@ namespace ImageSharp.Processing.Processors }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public LaplacianOfGaussianProcessor() : base(LaplacianOfGaussianXY) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs index fdb63d837e..d1515dee8e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/PrewittProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Prewitt operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class PrewittProcessor : EdgeDetector2DProcessor - where TColor : struct, IPixel + internal class PrewittProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel { /// /// The horizontal gradient operator. @@ -40,7 +42,7 @@ namespace ImageSharp.Processing.Processors }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public PrewittProcessor() : base(PrewittX, PrewittY) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs index d9c5f5d213..bab9ff6222 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Roberts Cross operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class RobertsCrossProcessor : EdgeDetector2DProcessor - where TColor : struct, IPixel + internal class RobertsCrossProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel { /// /// The horizontal gradient operator. @@ -38,7 +40,7 @@ namespace ImageSharp.Processing.Processors }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public RobertsCrossProcessor() : base(RobertsCrossX, RobertsCrossY) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs index 681d983c45..4afca0f017 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/RobinsonProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Kirsch operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class RobinsonProcessor : EdgeDetectorCompassProcessor - where TColor : struct, IPixel + internal class RobinsonProcessor : EdgeDetectorCompassProcessor + where TPixel : struct, IPixel { /// /// The North gradient operator diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs index c1e83b7f97..a583d3c0d0 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/ScharrProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Scharr operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class ScharrProcessor : EdgeDetector2DProcessor - where TColor : struct, IPixel + internal class ScharrProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel { /// /// The horizontal gradient operator. @@ -40,7 +42,7 @@ namespace ImageSharp.Processing.Processors }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public ScharrProcessor() : base(ScharrX, ScharrY) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs index 0c13fa3d24..1c2a6a18f9 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/SobelProcessor.cs @@ -8,14 +8,16 @@ namespace ImageSharp.Processing.Processors using System; using System.Diagnostics.CodeAnalysis; + using ImageSharp.PixelFormats; + /// /// The Sobel operator filter. /// /// - /// The pixel format. + /// The pixel format. [SuppressMessage("ReSharper", "StaticMemberInGenericType", Justification = "We want to use only one instance of each array field for each generic type.")] - internal class SobelProcessor : EdgeDetector2DProcessor - where TColor : struct, IPixel + internal class SobelProcessor : EdgeDetector2DProcessor + where TPixel : struct, IPixel { /// /// The horizontal gradient operator. @@ -40,7 +42,7 @@ namespace ImageSharp.Processing.Processors }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public SobelProcessor() : base(SobelX, SobelY) diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs index 65a137e359..87de922a1d 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs @@ -7,12 +7,14 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.PixelFormats; + /// /// Applies a Gaussian blur sampler to the image. /// - /// The pixel format. - internal class GaussianBlurProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class GaussianBlurProcessor : ImageProcessor + where TPixel : struct, IPixel { /// /// The maximum size of the kernel in either direction. @@ -25,7 +27,7 @@ namespace ImageSharp.Processing.Processors private readonly float sigma; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The 'sigma' value representing the weight of the blur. public GaussianBlurProcessor(float sigma = 3f) @@ -37,7 +39,7 @@ namespace ImageSharp.Processing.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'radius' value representing the size of the area to sample. @@ -51,7 +53,7 @@ namespace ImageSharp.Processing.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'sigma' value representing the weight of the blur. @@ -79,9 +81,9 @@ namespace ImageSharp.Processing.Processors public Fast2DArray KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); + new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs index bb3dc6f999..34d0990335 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs @@ -7,12 +7,14 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.PixelFormats; + /// /// Applies a Gaussian sharpening sampler to the image. /// - /// The pixel format. - internal class GaussianSharpenProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class GaussianSharpenProcessor : ImageProcessor + where TPixel : struct, IPixel { /// /// The maximum size of the kernel in either direction. @@ -25,7 +27,7 @@ namespace ImageSharp.Processing.Processors private readonly float sigma; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'sigma' value representing the weight of the sharpening. @@ -39,7 +41,7 @@ namespace ImageSharp.Processing.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'radius' value representing the size of the area to sample. @@ -53,7 +55,7 @@ namespace ImageSharp.Processing.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The 'sigma' value representing the weight of the sharpen. @@ -81,9 +83,9 @@ namespace ImageSharp.Processing.Processors public Fast2DArray KernelY { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); + new Convolution2PassProcessor(this.KernelX, this.KernelY).Apply(source, sourceRectangle); } /// diff --git a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs index ce48aea1ad..a601065461 100644 --- a/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/AlphaProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An to change the alpha component of an . + /// An to change the alpha component of an . /// - /// The pixel format. - internal class AlphaProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class AlphaProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// 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. /// @@ -35,7 +37,7 @@ namespace ImageSharp.Processing.Processors public int Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float alpha = this.Value / 100F; @@ -63,7 +65,7 @@ namespace ImageSharp.Processing.Processors Vector4 alphaVector = new Vector4(1, 1, 1, alpha); - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -75,7 +77,7 @@ namespace ImageSharp.Processing.Processors for (int x = minX; x < maxX; x++) { int offsetX = x - startX; - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(sourcePixels[offsetX, offsetY].ToVector4() * alphaVector); sourcePixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs index d928eb1a47..21973de3e4 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs @@ -9,18 +9,20 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Sets the background color of the image. /// - /// The pixel format. - internal class BackgroundColorProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class BackgroundColorProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// The to set the background color to. - public BackgroundColorProcessor(TColor color) + /// The to set the background color to. + public BackgroundColorProcessor(TPixel color) { this.Value = color; } @@ -28,10 +30,10 @@ namespace ImageSharp.Processing.Processors /// /// Gets the background color value. /// - public TColor Value { get; } + public TPixel Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -57,7 +59,7 @@ namespace ImageSharp.Processing.Processors Vector4 backgroundColor = this.Value.ToVector4(); - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -82,7 +84,7 @@ namespace ImageSharp.Processing.Processors color = backgroundColor; } - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(color); sourcePixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs index 84df5e89e8..f9f1585ea9 100644 --- a/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/BrightnessProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An to change the brightness of an . + /// An to change the brightness of an . /// - /// The pixel format. - internal class BrightnessProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class BrightnessProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The new brightness of the image. Must be between -100 and 100. /// @@ -35,7 +37,7 @@ namespace ImageSharp.Processing.Processors public int Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float brightness = this.Value / 100F; @@ -61,7 +63,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -79,7 +81,7 @@ namespace ImageSharp.Processing.Processors Vector3 transformed = new Vector3(vector.X, vector.Y, vector.Z) + new Vector3(brightness); vector = new Vector4(transformed, vector.W); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(vector.Compress()); sourcePixels[offsetX, offsetY] = packed; diff --git a/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs index 042e396996..8308c57e2b 100644 --- a/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/ContrastProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An to change the contrast of an . + /// An to change the contrast of an . /// - /// The pixel format. - internal class ContrastProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class ContrastProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The new contrast of the image. Must be between -100 and 100. /// @@ -35,7 +37,7 @@ namespace ImageSharp.Processing.Processors public int Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { float contrast = (100F + this.Value) / 100F; @@ -63,7 +65,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -80,7 +82,7 @@ namespace ImageSharp.Processing.Processors vector -= shiftVector; vector *= contrastVector; vector += shiftVector; - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(vector.Compress()); sourcePixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs index 4358e89460..a0348970e7 100644 --- a/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/InvertProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An to invert the colors of an . + /// An to invert the colors of an . /// - /// The pixel format. - internal class InvertProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class InvertProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -42,7 +44,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -57,7 +59,7 @@ namespace ImageSharp.Processing.Processors Vector4 color = sourcePixels[offsetX, offsetY].ToVector4(); Vector3 vector = inverseVector - new Vector3(color.X, color.Y, color.Z); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(new Vector4(vector, color.W)); sourcePixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs index 957955c6c4..73d956907f 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs @@ -9,16 +9,18 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An to apply an oil painting effect to an . + /// An to apply an oil painting effect to an . /// /// Adapted from by Dewald Esterhuizen. - /// The pixel format. - internal class OilPaintingProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class OilPaintingProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. @@ -46,7 +48,7 @@ namespace ImageSharp.Processing.Processors public int BrushSize { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -67,9 +69,9 @@ namespace ImageSharp.Processing.Processors startX = 0; } - using (PixelAccessor targetPixels = new PixelAccessor(source.Width, source.Height)) + using (PixelAccessor targetPixels = new PixelAccessor(source.Width, source.Height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -143,7 +145,7 @@ namespace ImageSharp.Processing.Processors float green = MathF.Abs(greenBin[maxIndex] / maxIntensity); float blue = MathF.Abs(blueBin[maxIndex] / maxIntensity); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(new Vector4(red, green, blue, sourcePixels[x, y].ToVector4().W)); targetPixels[x, y] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs index 818b1f5137..7a57daa4eb 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Collections.Generic; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An to pixelate the colors of an . + /// An to pixelate the colors of an . /// - /// The pixel format. - internal class PixelateProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class PixelateProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The size of the pixels. Must be greater than 0. /// @@ -35,7 +37,7 @@ namespace ImageSharp.Processing.Processors public int Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; @@ -64,9 +66,9 @@ namespace ImageSharp.Processing.Processors // Get the range on the y-plane to choose from. IEnumerable range = EnumerableExtensions.SteppedRange(minY, i => i < maxY, size); - using (PixelAccessor targetPixels = new PixelAccessor(source.Width, source.Height)) + using (PixelAccessor targetPixels = new PixelAccessor(source.Width, source.Height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.ForEach( range, @@ -94,7 +96,7 @@ namespace ImageSharp.Processing.Processors // Get the pixel color in the centre of the soon to be pixelated area. // ReSharper disable AccessToDisposedClosure - TColor pixel = sourcePixels[offsetX + offsetPx, offsetY + offsetPy]; + TPixel pixel = sourcePixels[offsetX + offsetPx, offsetY + offsetPy]; // For each pixel in the pixelate size, set it to the centre color. for (int l = offsetY; l < offsetY + size && l < maxY; l++) diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 6eeb7398aa..0493782560 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -9,18 +9,20 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An that applies a radial glow effect an . + /// An that applies a radial glow effect an . /// - /// The pixel format. - internal class GlowProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class GlowProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color or the glow. - public GlowProcessor(TColor color) + public GlowProcessor(TPixel color) { this.GlowColor = color; } @@ -28,7 +30,7 @@ namespace ImageSharp.Processing.Processors /// /// Gets or sets the glow color to apply. /// - public TColor GlowColor { get; set; } + public TPixel GlowColor { get; set; } /// /// Gets or sets the the radius. @@ -36,13 +38,13 @@ namespace ImageSharp.Processing.Processors public float Radius { get; set; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X; int endX = sourceRectangle.Right; - TColor glowColor = this.GlowColor; + TPixel glowColor = this.GlowColor; Vector2 centre = Rectangle.Center(sourceRectangle).ToVector2(); float maxDistance = this.Radius > 0 ? MathF.Min(this.Radius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; @@ -63,7 +65,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -77,7 +79,7 @@ namespace ImageSharp.Processing.Processors int offsetX = x - startX; float distance = Vector2.Distance(centre, new Vector2(offsetX, offsetY)); Vector4 sourceColor = sourcePixels[offsetX, offsetY].ToVector4(); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(Vector4BlendTransforms.PremultipliedLerp(sourceColor, glowColor.ToVector4(), 1 - (.95F * (distance / maxDistance)))); sourcePixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index 40d6d94ac9..31e813564b 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -9,18 +9,20 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// - /// An that applies a radial vignette effect to an . + /// An that applies a radial vignette effect to an . /// - /// The pixel format. - internal class VignetteProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class VignetteProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The color of the vignette. - public VignetteProcessor(TColor color) + public VignetteProcessor(TPixel color) { this.VignetteColor = color; } @@ -28,7 +30,7 @@ namespace ImageSharp.Processing.Processors /// /// Gets or sets the vignette color to apply. /// - public TColor VignetteColor { get; set; } + public TPixel VignetteColor { get; set; } /// /// Gets or sets the the x-radius. @@ -41,13 +43,13 @@ namespace ImageSharp.Processing.Processors public float RadiusY { get; set; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X; int endX = sourceRectangle.Right; - TColor vignetteColor = this.VignetteColor; + TPixel vignetteColor = this.VignetteColor; Vector2 centre = Rectangle.Center(sourceRectangle).ToVector2(); float rX = this.RadiusX > 0 ? MathF.Min(this.RadiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; float rY = this.RadiusY > 0 ? MathF.Min(this.RadiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; @@ -70,7 +72,7 @@ namespace ImageSharp.Processing.Processors startY = 0; } - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -84,7 +86,7 @@ namespace ImageSharp.Processing.Processors int offsetX = x - startX; float distance = Vector2.Distance(centre, new Vector2(offsetX, offsetY)); Vector4 sourceColor = sourcePixels[offsetX, offsetY].ToVector4(); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromVector4(Vector4BlendTransforms.PremultipliedLerp(sourceColor, vignetteColor.ToVector4(), .9F * (distance / maxDistance))); sourcePixels[offsetX, offsetY] = packed; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs index 7d473c55ed..b67ef5bf1e 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/CropProcessor.cs @@ -8,15 +8,17 @@ namespace ImageSharp.Processing.Processors using System; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Provides methods to allow the cropping of an image. /// - /// The pixel format. - internal class CropProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class CropProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The target cropped rectangle. public CropProcessor(Rectangle cropRectangle) @@ -30,7 +32,7 @@ namespace ImageSharp.Processing.Processors public Rectangle CropRectangle { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { if (this.CropRectangle == sourceRectangle) { @@ -42,9 +44,9 @@ namespace ImageSharp.Processing.Processors int minX = Math.Max(this.CropRectangle.X, sourceRectangle.X); int maxX = Math.Min(this.CropRectangle.Right, sourceRectangle.Right); - using (PixelAccessor targetPixels = new PixelAccessor(this.CropRectangle.Width, this.CropRectangle.Height)) + using (PixelAccessor targetPixels = new PixelAccessor(this.CropRectangle.Width, this.CropRectangle.Height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs index 049fbf2de0..571c40939e 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs @@ -7,16 +7,18 @@ namespace ImageSharp.Processing.Processors { using System; + using ImageSharp.PixelFormats; + /// /// Provides methods to allow the cropping of an image to preserve areas of highest /// entropy. /// - /// The pixel format. - internal class EntropyCropProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class EntropyCropProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The threshold to split the image. Must be between 0 and 1. /// @@ -34,15 +36,15 @@ namespace ImageSharp.Processing.Processors public float Value { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - using (ImageBase temp = new Image(source)) + using (ImageBase temp = new Image(source)) { // Detect the edges. - new SobelProcessor().Apply(temp, sourceRectangle); + new SobelProcessor().Apply(temp, sourceRectangle); // Apply threshold binarization filter. - new BinaryThresholdProcessor(this.Value).Apply(temp, sourceRectangle); + new BinaryThresholdProcessor(this.Value).Apply(temp, sourceRectangle); // Search for the first white pixels Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); @@ -52,7 +54,7 @@ namespace ImageSharp.Processing.Processors return; } - new CropProcessor(rectangle).Apply(source, sourceRectangle); + new CropProcessor(rectangle).Apply(source, sourceRectangle); } } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs index 290d81799a..2faf779053 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor.cs @@ -8,15 +8,17 @@ namespace ImageSharp.Processing.Processors using System; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Provides methods that allow the flipping of an image around its center point. /// - /// The pixel format. - internal class FlipProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class FlipProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The used to perform flipping. public FlipProcessor(FlipType flipType) @@ -30,7 +32,7 @@ namespace ImageSharp.Processing.Processors public FlipType FlipType { get; } /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { switch (this.FlipType) { @@ -49,15 +51,15 @@ namespace ImageSharp.Processing.Processors /// at half the height of the image. /// /// The source image to apply the process to. - private void FlipX(ImageBase source) + private void FlipX(ImageBase source) { int width = source.Width; int height = source.Height; int halfHeight = (int)Math.Ceiling(source.Height * .5F); - using (PixelAccessor targetPixels = new PixelAccessor(width, height)) + using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( 0, @@ -83,15 +85,15 @@ namespace ImageSharp.Processing.Processors /// at half of the width of the image. /// /// The source image to apply the process to. - private void FlipY(ImageBase source) + private void FlipY(ImageBase source) { int width = source.Width; int height = source.Height; int halfWidth = (int)Math.Ceiling(width * .5F); - using (PixelAccessor targetPixels = new PixelAccessor(width, height)) + using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( 0, diff --git a/src/ImageSharp/Processing/Processors/Transforms/Matrix3x2Processor.cs b/src/ImageSharp/Processing/Processors/Transforms/Matrix3x2Processor.cs index 0c290a9b62..3135551f8a 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Matrix3x2Processor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Matrix3x2Processor.cs @@ -8,12 +8,14 @@ namespace ImageSharp.Processing.Processors using System; using System.Numerics; + using ImageSharp.PixelFormats; + /// /// Provides methods to transform an image using a . /// - /// The pixel format. - internal abstract class Matrix3x2Processor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal abstract class Matrix3x2Processor : ImageProcessor + where TPixel : struct, IPixel { /// /// Gets the rectangle designating the target canvas. @@ -41,7 +43,7 @@ namespace ImageSharp.Processing.Processors /// /// The . /// - protected Matrix3x2 GetCenteredMatrix(ImageBase source, Matrix3x2 matrix) + protected Matrix3x2 GetCenteredMatrix(ImageBase source, Matrix3x2 matrix) { Matrix3x2 translationToTargetCenter = Matrix3x2.CreateTranslation(-this.CanvasRectangle.Width * .5F, -this.CanvasRectangle.Height * .5F); Matrix3x2 translateToSourceCenter = Matrix3x2.CreateTranslation(source.Width * .5F, source.Height * .5F); diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs index 4c43d654d0..5d29924e11 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs @@ -7,7 +7,7 @@ namespace ImageSharp.Processing.Processors /// /// Conains the definition of and . /// - internal abstract partial class ResamplingWeightedProcessor + internal abstract partial class ResamplingWeightedProcessor { /// /// Points to a collection of of weights allocated in . diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs index 50c75a3fdf..e2f77d812e 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs @@ -10,16 +10,18 @@ namespace ImageSharp.Processing.Processors using System.Runtime.CompilerServices; using System.Runtime.InteropServices; + using ImageSharp.PixelFormats; + /// /// Provides methods that allow the resizing of images using various algorithms. /// Adapted from /// - /// The pixel format. - internal abstract partial class ResamplingWeightedProcessor : ImageProcessor - where TColor : struct, IPixel + /// The pixel format. + internal abstract partial class ResamplingWeightedProcessor : ImageProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The sampler to perform the resize operation. /// The target width. @@ -139,7 +141,7 @@ namespace ImageSharp.Processing.Processors } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (!(this.Sampler is NearestNeighborResampler)) { @@ -154,7 +156,7 @@ namespace ImageSharp.Processing.Processors } /// - protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) { base.AfterApply(source, sourceRectangle); this.HorizontalWeights?.Dispose(); diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index 08d96e283c..23166fd3ab 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -9,15 +9,17 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Provides methods that allow the resizing of images using various algorithms. /// - /// The pixel format. - internal class ResizeProcessor : ResamplingWeightedProcessor - where TColor : struct, IPixel + /// The pixel format. + internal class ResizeProcessor : ResamplingWeightedProcessor + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The sampler to perform the resize operation. /// The target width. @@ -28,7 +30,7 @@ namespace ImageSharp.Processing.Processors } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The sampler to perform the resize operation. /// The target width. @@ -42,7 +44,7 @@ namespace ImageSharp.Processing.Processors } /// - protected override unsafe void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override unsafe void OnApply(ImageBase source, Rectangle sourceRectangle) { // Jump out, we'll deal with that later. if (source.Width == this.Width && source.Height == this.Height && sourceRectangle == this.ResizeRectangle) @@ -70,9 +72,9 @@ namespace ImageSharp.Processing.Processors float widthFactor = sourceRectangle.Width / (float)this.ResizeRectangle.Width; float heightFactor = sourceRectangle.Height / (float)this.ResizeRectangle.Height; - using (PixelAccessor targetPixels = new PixelAccessor(width, height)) + using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( minY, @@ -103,9 +105,9 @@ namespace ImageSharp.Processing.Processors // are the upper and lower bounds of the source rectangle. // TODO: Using a transposed variant of 'firstPassPixels' could eliminate the need for the WeightsWindow.ComputeWeightedColumnSum() method, and improve speed! - using (PixelAccessor targetPixels = new PixelAccessor(width, height)) + using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) using (Buffer2D firstPassPixels = new Buffer2D(width, source.Height)) { firstPassPixels.Clear(); @@ -119,9 +121,9 @@ namespace ImageSharp.Processing.Processors // TODO: Without Parallel.For() this buffer object could be reused: using (Buffer tempRowBuffer = new Buffer(sourcePixels.Width)) { - BufferSpan sourceRow = sourcePixels.GetRowSpan(y); + BufferSpan sourceRow = sourcePixels.GetRowSpan(y); - BulkPixelOperations.Instance.ToVector4( + BulkPixelOperations.Instance.ToVector4( sourceRow, tempRowBuffer, sourceRow.Length); @@ -162,7 +164,7 @@ namespace ImageSharp.Processing.Processors // Destination color components Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x); destination = destination.Compress(); - TColor d = default(TColor); + TPixel d = default(TPixel); d.PackFromVector4(destination); targetPixels[x, y] = d; } @@ -174,7 +176,7 @@ namespace ImageSharp.Processing.Processors // Destination color components Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x); - TColor d = default(TColor); + TPixel d = default(TPixel); d.PackFromVector4(destination); targetPixels[x, y] = d; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index 16e0b6635f..fc5d29b06a 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -9,12 +9,14 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Provides methods that allow the rotating of images. /// - /// The pixel format. - internal class RotateProcessor : Matrix3x2Processor - where TColor : struct, IPixel + /// The pixel format. + internal class RotateProcessor : Matrix3x2Processor + where TPixel : struct, IPixel { /// /// The transform matrix to apply. @@ -32,7 +34,7 @@ namespace ImageSharp.Processing.Processors public bool Expand { get; set; } = true; /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { if (this.OptimizedApply(source)) { @@ -43,9 +45,9 @@ namespace ImageSharp.Processing.Processors int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); - using (PixelAccessor targetPixels = new PixelAccessor(width, height)) + using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( 0, @@ -69,7 +71,7 @@ namespace ImageSharp.Processing.Processors } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { if (MathF.Abs(this.Angle) < Constants.Epsilon || MathF.Abs(this.Angle - 90) < Constants.Epsilon || MathF.Abs(this.Angle - 180) < Constants.Epsilon || MathF.Abs(this.Angle - 270) < Constants.Epsilon) { @@ -88,7 +90,7 @@ namespace ImageSharp.Processing.Processors /// /// The source image. /// The - private bool OptimizedApply(ImageBase source) + private bool OptimizedApply(ImageBase source) { if (MathF.Abs(this.Angle) < Constants.Epsilon) { @@ -121,14 +123,14 @@ namespace ImageSharp.Processing.Processors /// Rotates the image 270 degrees clockwise at the centre point. /// /// The source image. - private void Rotate270(ImageBase source) + private void Rotate270(ImageBase source) { int width = source.Width; int height = source.Height; - using (PixelAccessor targetPixels = new PixelAccessor(height, width)) + using (PixelAccessor targetPixels = new PixelAccessor(height, width)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( 0, @@ -154,14 +156,14 @@ namespace ImageSharp.Processing.Processors /// Rotates the image 180 degrees clockwise at the centre point. /// /// The source image. - private void Rotate180(ImageBase source) + private void Rotate180(ImageBase source) { int width = source.Width; int height = source.Height; - using (PixelAccessor targetPixels = new PixelAccessor(width, height)) + using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( 0, @@ -186,14 +188,14 @@ namespace ImageSharp.Processing.Processors /// Rotates the image 90 degrees clockwise at the centre point. /// /// The source image. - private void Rotate90(ImageBase source) + private void Rotate90(ImageBase source) { int width = source.Width; int height = source.Height; - using (PixelAccessor targetPixels = new PixelAccessor(height, width)) + using (PixelAccessor targetPixels = new PixelAccessor(height, width)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( 0, diff --git a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs index 5fe3f7d958..40ea6a94e5 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs @@ -9,12 +9,14 @@ namespace ImageSharp.Processing.Processors using System.Numerics; using System.Threading.Tasks; + using ImageSharp.PixelFormats; + /// /// Provides methods that allow the skewing of images. /// - /// The pixel format. - internal class SkewProcessor : Matrix3x2Processor - where TColor : struct, IPixel + /// The pixel format. + internal class SkewProcessor : Matrix3x2Processor + where TPixel : struct, IPixel { /// /// The transform matrix to apply. @@ -37,15 +39,15 @@ namespace ImageSharp.Processing.Processors public bool Expand { get; set; } = true; /// - protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { int height = this.CanvasRectangle.Height; int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); - using (PixelAccessor targetPixels = new PixelAccessor(width, height)) + using (PixelAccessor targetPixels = new PixelAccessor(width, height)) { - using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) { Parallel.For( 0, @@ -69,7 +71,7 @@ namespace ImageSharp.Processing.Processors } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) { this.processMatrix = Point.CreateSkew(new Point(0, 0), -this.AngleX, -this.AngleY); if (this.Expand) diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrient.cs index 8c5e22b995..de736092da 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Processing/Transforms/AutoOrient.cs @@ -6,22 +6,25 @@ namespace ImageSharp { using System; + + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. /// - /// The pixel format. + /// The pixel format. /// The image to auto rotate. /// The - public static Image AutoOrient(this Image source) - where TColor : struct, IPixel + public static Image AutoOrient(this Image source) + where TPixel : struct, IPixel { Orientation orientation = GetExifOrientation(source); @@ -60,11 +63,11 @@ namespace ImageSharp /// /// Returns the current EXIF orientation /// - /// The pixel format. + /// The pixel format. /// The image to auto rotate. /// The - private static Orientation GetExifOrientation(Image source) - where TColor : struct, IPixel + private static Orientation GetExifOrientation(Image source) + where TPixel : struct, IPixel { if (source.MetaData.ExifProfile == null) { diff --git a/src/ImageSharp/Processing/Transforms/Crop.cs b/src/ImageSharp/Processing/Transforms/Crop.cs index 92773aaeac..073e8136da 100644 --- a/src/ImageSharp/Processing/Transforms/Crop.cs +++ b/src/ImageSharp/Processing/Transforms/Crop.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Crops an image to the given width and height. /// - /// The pixel format. + /// The pixel format. /// The image to resize. /// The target image width. /// The target image height. - /// The - public static Image Crop(this Image source, int width, int height) - where TColor : struct, IPixel + /// The + public static Image Crop(this Image source, int width, int height) + where TPixel : struct, IPixel { return Crop(source, new Rectangle(0, 0, width, height)); } @@ -31,16 +33,16 @@ namespace ImageSharp /// /// Crops an image to the given rectangle. /// - /// The pixel format. + /// The pixel format. /// The image to crop. /// /// The structure that specifies the portion of the image object to retain. /// /// The - public static Image Crop(this Image source, Rectangle cropRectangle) - where TColor : struct, IPixel + public static Image Crop(this Image source, Rectangle cropRectangle) + where TPixel : struct, IPixel { - CropProcessor processor = new CropProcessor(cropRectangle); + CropProcessor processor = new CropProcessor(cropRectangle); source.ApplyProcessor(processor, source.Bounds); return source; diff --git a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs index ad2ce89e3d..aaafd396f2 100644 --- a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs @@ -7,24 +7,26 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Crops an image to the area of greatest entropy. /// - /// The pixel format. + /// The pixel format. /// The image to crop. /// The threshold for entropic density. /// The - public static Image EntropyCrop(this Image source, float threshold = .5f) - where TColor : struct, IPixel + public static Image EntropyCrop(this Image source, float threshold = .5f) + where TPixel : struct, IPixel { - EntropyCropProcessor processor = new EntropyCropProcessor(threshold); + EntropyCropProcessor processor = new EntropyCropProcessor(threshold); source.ApplyProcessor(processor, source.Bounds); return source; diff --git a/src/ImageSharp/Processing/Transforms/Flip.cs b/src/ImageSharp/Processing/Transforms/Flip.cs index ed096eb750..41f2e5616b 100644 --- a/src/ImageSharp/Processing/Transforms/Flip.cs +++ b/src/ImageSharp/Processing/Transforms/Flip.cs @@ -7,25 +7,27 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Flips an image by the given instructions. /// - /// The pixel format. + /// The pixel format. /// The image to rotate, flip, or both. /// The to perform the flip. /// The - public static Image Flip(this Image source, FlipType flipType) - where TColor : struct, IPixel + public static Image Flip(this Image source, FlipType flipType) + where TPixel : struct, IPixel { - FlipProcessor processor = new FlipProcessor(flipType); + FlipProcessor processor = new FlipProcessor(flipType); source.ApplyProcessor(processor, source.Bounds); return source; diff --git a/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs b/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs index 4be938c399..c876882662 100644 --- a/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs +++ b/src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Processing using System; using System.Linq; + using ImageSharp.PixelFormats; + /// /// Provides methods to help calculate the target rectangle when resizing using the /// enumeration. @@ -17,14 +19,14 @@ namespace ImageSharp.Processing /// /// Calculates the target location and bounds to perform the resize operation against. /// - /// The pixel format. + /// The pixel format. /// The source image. /// The resize options. /// /// The . /// - public static Rectangle CalculateTargetLocationAndBounds(ImageBase source, ResizeOptions options) - where TColor : struct, IPixel + public static Rectangle CalculateTargetLocationAndBounds(ImageBase source, ResizeOptions options) + where TPixel : struct, IPixel { switch (options.Mode) { @@ -48,14 +50,14 @@ namespace ImageSharp.Processing /// /// Calculates the target rectangle for crop mode. /// - /// The pixel format. + /// The pixel format. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateCropRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPixel + private static Rectangle CalculateCropRectangle(ImageBase source, ResizeOptions options) + where TPixel : struct, IPixel { int width = options.Size.Width; int height = options.Size.Height; @@ -167,14 +169,14 @@ namespace ImageSharp.Processing /// /// Calculates the target rectangle for pad mode. /// - /// The pixel format. + /// The pixel format. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculatePadRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPixel + private static Rectangle CalculatePadRectangle(ImageBase source, ResizeOptions options) + where TPixel : struct, IPixel { int width = options.Size.Width; int height = options.Size.Height; @@ -248,14 +250,14 @@ namespace ImageSharp.Processing /// /// Calculates the target rectangle for box pad mode. /// - /// The pixel format. + /// The pixel format. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateBoxPadRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPixel + private static Rectangle CalculateBoxPadRectangle(ImageBase source, ResizeOptions options) + where TPixel : struct, IPixel { int width = options.Size.Width; int height = options.Size.Height; @@ -335,14 +337,14 @@ namespace ImageSharp.Processing /// /// Calculates the target rectangle for max mode. /// - /// The pixel format. + /// The pixel format. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateMaxRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPixel + private static Rectangle CalculateMaxRectangle(ImageBase source, ResizeOptions options) + where TPixel : struct, IPixel { int width = options.Size.Width; int height = options.Size.Height; @@ -376,14 +378,14 @@ namespace ImageSharp.Processing /// /// Calculates the target rectangle for min mode. /// - /// The pixel format. + /// The pixel format. /// The source image. /// The resize options. /// /// The . /// - private static Rectangle CalculateMinRectangle(ImageBase source, ResizeOptions options) - where TColor : struct, IPixel + private static Rectangle CalculateMinRectangle(ImageBase source, ResizeOptions options) + where TPixel : struct, IPixel { int width = options.Size.Width; int height = options.Size.Height; diff --git a/src/ImageSharp/Processing/Transforms/Pad.cs b/src/ImageSharp/Processing/Transforms/Pad.cs index bd530ecd82..42851e205d 100644 --- a/src/ImageSharp/Processing/Transforms/Pad.cs +++ b/src/ImageSharp/Processing/Transforms/Pad.cs @@ -7,24 +7,26 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Evenly pads an image to fit the new dimensions. /// - /// The pixel format. + /// The pixel format. /// The source image to pad. /// The new width. /// The new height. - /// The . - public static Image Pad(this Image source, int width, int height) - where TColor : struct, IPixel + /// The . + public static Image Pad(this Image source, int width, int height) + where TPixel : struct, IPixel { ResizeOptions options = new ResizeOptions { diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index 1952aa1a7a..543b982976 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -7,24 +7,26 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Resizes an image in accordance with the given . /// - /// The pixel format. + /// The pixel format. /// The image to resize. /// The resize options. - /// The + /// The /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, ResizeOptions options) - where TColor : struct, IPixel + public static Image Resize(this Image source, ResizeOptions options) + where TPixel : struct, IPixel { // Ensure size is populated across both dimensions. if (options.Size.Width == 0 && options.Size.Height > 0) @@ -45,13 +47,13 @@ namespace ImageSharp /// /// Resizes an image to the given . /// - /// The pixel format. + /// The pixel format. /// The image to resize. /// The target image size. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, Size size) - where TColor : struct, IPixel + public static Image Resize(this Image source, Size size) + where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), false); } @@ -59,14 +61,14 @@ namespace ImageSharp /// /// Resizes an image to the given width and height. /// - /// The pixel format. + /// The pixel format. /// The image to resize. /// The target image width. /// The target image height. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height) - where TColor : struct, IPixel + public static Image Resize(this Image source, int width, int height) + where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), false); } @@ -74,15 +76,15 @@ namespace ImageSharp /// /// Resizes an image to the given width and height. /// - /// The pixel format. + /// The pixel format. /// The image to resize. /// The target image width. /// The target image height. /// Whether to compress and expand the image color-space to gamma correct the image during processing. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, bool compand) - where TColor : struct, IPixel + public static Image Resize(this Image source, int width, int height, bool compand) + where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), compand); } @@ -90,15 +92,15 @@ namespace ImageSharp /// /// Resizes an image to the given width and height with the given sampler. /// - /// The pixel format. + /// The pixel format. /// The image to resize. /// The target image width. /// The target image height. /// The to perform the resampling. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler) - where TColor : struct, IPixel + public static Image Resize(this Image source, int width, int height, IResampler sampler) + where TPixel : struct, IPixel { return Resize(source, width, height, sampler, false); } @@ -106,16 +108,16 @@ namespace ImageSharp /// /// Resizes an image to the given width and height with the given sampler. /// - /// The pixel format. + /// The pixel format. /// The image to resize. /// The target image width. /// The target image height. /// The to perform the resampling. /// Whether to compress and expand the image color-space to gamma correct the image during processing. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler, bool compand) - where TColor : struct, IPixel + public static Image Resize(this Image source, int width, int height, IResampler sampler, bool compand) + where TPixel : struct, IPixel { return Resize(source, width, height, sampler, source.Bounds, new Rectangle(0, 0, width, height), compand); } @@ -124,7 +126,7 @@ namespace ImageSharp /// Resizes an image to the given width and height with the given sampler and /// source rectangle. /// - /// The pixel format. + /// The pixel format. /// The image to resize. /// The target image width. /// The target image height. @@ -136,10 +138,10 @@ namespace ImageSharp /// The structure that specifies the portion of the target image object to draw to. /// /// Whether to compress and expand the image color-space to gamma correct the image during processing. - /// The + /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false) - where TColor : struct, IPixel + public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false) + where TPixel : struct, IPixel { if (width == 0 && height > 0) { @@ -156,8 +158,8 @@ namespace ImageSharp Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); - ResizeProcessor processor = - new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand }; + ResizeProcessor processor = + new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand }; source.ApplyProcessor(processor, sourceRectangle); return source; diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/Rotate.cs index 76311ef252..b335a3c769 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/Rotate.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing; using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Rotates an image by the given angle in degrees, expanding the image to fit the rotated result. /// - /// The pixel format. + /// The pixel format. /// The image to rotate. /// The angle in degrees to perform the rotation. /// The - public static Image Rotate(this Image source, float degrees) - where TColor : struct, IPixel + public static Image Rotate(this Image source, float degrees) + where TPixel : struct, IPixel { return Rotate(source, degrees, true); } @@ -31,12 +33,12 @@ namespace ImageSharp /// /// Rotates and flips an image by the given instructions. /// - /// The pixel format. + /// The pixel format. /// The image to rotate. /// The to perform the rotation. /// The - public static Image Rotate(this Image source, RotateType rotateType) - where TColor : struct, IPixel + public static Image Rotate(this Image source, RotateType rotateType) + where TPixel : struct, IPixel { return Rotate(source, (float)rotateType, false); } @@ -44,15 +46,15 @@ namespace ImageSharp /// /// Rotates an image by the given angle in degrees. /// - /// The pixel format. + /// The pixel format. /// The image to rotate. /// The angle in degrees to perform the rotation. /// Whether to expand the image to fit the rotated result. /// The - public static Image Rotate(this Image source, float degrees, bool expand) - where TColor : struct, IPixel + public static Image Rotate(this Image source, float degrees, bool expand) + where TPixel : struct, IPixel { - RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand }; + RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand }; source.ApplyProcessor(processor, source.Bounds); return source; diff --git a/src/ImageSharp/Processing/Transforms/RotateFlip.cs b/src/ImageSharp/Processing/Transforms/RotateFlip.cs index d6050db3f3..3965903594 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlip.cs @@ -6,23 +6,26 @@ namespace ImageSharp { using System; + + using ImageSharp.PixelFormats; + using Processing; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Rotates and flips an image by the given instructions. /// - /// The pixel format. + /// The pixel format. /// The image to rotate, flip, or both. /// The to perform the rotation. /// The to perform the flip. /// The - public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType) - where TColor : struct, IPixel + public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType) + where TPixel : struct, IPixel { return source.Rotate(rotateType).Flip(flipType); } diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/Skew.cs index 03fdbcceb4..0c9cfbc8e0 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/Skew.cs @@ -7,23 +7,25 @@ namespace ImageSharp { using System; + using ImageSharp.PixelFormats; + using Processing.Processors; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Skews an image by the given angles in degrees, expanding the image to fit the skewed result. /// - /// The pixel format. + /// The pixel format. /// The image to skew. /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// The - public static Image Skew(this Image source, float degreesX, float degreesY) - where TColor : struct, IPixel + public static Image Skew(this Image source, float degreesX, float degreesY) + where TPixel : struct, IPixel { return Skew(source, degreesX, degreesY, true); } @@ -31,16 +33,16 @@ namespace ImageSharp /// /// Skews an image by the given angles in degrees. /// - /// The pixel format. + /// The pixel format. /// The image to skew. /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// Whether to expand the image to fit the skewed result. /// The - public static Image Skew(this Image source, float degreesX, float degreesY, bool expand) - where TColor : struct, IPixel + public static Image Skew(this Image source, float degreesX, float degreesY, bool expand) + where TPixel : struct, IPixel { - SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }; + SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }; source.ApplyProcessor(processor, source.Bounds); return source; diff --git a/src/ImageSharp/Quantizers/IQuantizer.cs b/src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs similarity index 72% rename from src/ImageSharp/Quantizers/IQuantizer.cs rename to src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs index 88f273e9b6..f3bf9b56d6 100644 --- a/src/ImageSharp/Quantizers/IQuantizer.cs +++ b/src/ImageSharp/Quantizers/IQuantizer{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -6,13 +6,14 @@ namespace ImageSharp.Quantizers { using ImageSharp.Dithering; + using ImageSharp.PixelFormats; /// /// Provides methods for allowing quantization of images pixels. /// - /// The pixel format. - public interface IQuantizer : IQuantizer - where TColor : struct, IPixel + /// The pixel format. + public interface IQuantizer : IQuantizer + where TPixel : struct, IPixel { /// /// Quantize an image and return the resulting output pixels. @@ -22,15 +23,15 @@ namespace ImageSharp.Quantizers /// /// A representing a quantized version of the image pixels. /// - QuantizedImage Quantize(ImageBase image, int maxColors); + QuantizedImage Quantize(ImageBase image, int maxColors); } /// /// Provides methods for allowing dithering of quantized image pixels. /// - /// The pixel format. - public interface IDitheredQuantizer : IQuantizer - where TColor : struct, IPixel + /// The pixel format. + public interface IDitheredQuantizer : IQuantizer + where TPixel : struct, IPixel { /// /// Gets or sets a value indicating whether to apply dithering to the output image. diff --git a/src/ImageSharp/Quantizers/OctreeQuantizer.cs b/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs similarity index 91% rename from src/ImageSharp/Quantizers/OctreeQuantizer.cs rename to src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs index df52ee7f9d..d57d297fc8 100644 --- a/src/ImageSharp/Quantizers/OctreeQuantizer.cs +++ b/src/ImageSharp/Quantizers/OctreeQuantizer{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -8,19 +8,20 @@ namespace ImageSharp.Quantizers using System; using System.Collections.Generic; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; /// /// Encapsulates methods to calculate the color palette if an image using an Octree pattern. /// /// - /// The pixel format. - public sealed class OctreeQuantizer : Quantizer - where TColor : struct, IPixel + /// The pixel format. + public sealed class OctreeQuantizer : Quantizer + where TPixel : struct, IPixel { /// /// A lookup table for colors /// - private readonly Dictionary colorMap = new Dictionary(); + private readonly Dictionary colorMap = new Dictionary(); /// /// The pixel buffer, used to reduce allocations. @@ -40,10 +41,10 @@ namespace ImageSharp.Quantizers /// /// The reduced image palette /// - private TColor[] palette; + private TPixel[] palette; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The Octree quantizer is a two pass algorithm. The initial pass sets up the Octree, @@ -55,7 +56,7 @@ namespace ImageSharp.Quantizers } /// - public override QuantizedImage Quantize(ImageBase image, int maxColors) + public override QuantizedImage Quantize(ImageBase image, int maxColors) { this.colors = maxColors.Clamp(1, 255); this.octree = new Octree(this.GetBitsNeededForColorDepth(this.colors)); @@ -64,15 +65,15 @@ namespace ImageSharp.Quantizers } /// - protected override void SecondPass(PixelAccessor source, byte[] output, int width, int height) + protected override void SecondPass(PixelAccessor source, byte[] output, int width, int height) { // Load up the values for the first pixel. We can use these to speed up the second // pass of the algorithm by avoiding transforming rows of identical color. - TColor sourcePixel = source[0, 0]; - TColor previousPixel = sourcePixel; + TPixel sourcePixel = source[0, 0]; + TPixel previousPixel = sourcePixel; byte pixelValue = this.QuantizePixel(sourcePixel); - TColor[] colorPalette = this.GetPalette(); - TColor transformedPixel = colorPalette[pixelValue]; + TPixel[] colorPalette = this.GetPalette(); + TPixel transformedPixel = colorPalette[pixelValue]; for (int y = 0; y < height; y++) { @@ -110,14 +111,14 @@ namespace ImageSharp.Quantizers } /// - protected override void InitialQuantizePixel(TColor pixel) + protected override void InitialQuantizePixel(TPixel pixel) { // Add the color to the Octree this.octree.AddColor(pixel, this.pixelBuffer); } /// - protected override TColor[] GetPalette() + protected override TPixel[] GetPalette() { return this.palette ?? (this.palette = this.octree.Palletize(Math.Max(this.colors, 1))); } @@ -130,13 +131,13 @@ namespace ImageSharp.Quantizers /// The quantized value /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private byte QuantizePixel(TColor pixel) + private byte QuantizePixel(TPixel pixel) { if (this.Dither) { // The colors have changed so we need to use Euclidean distance caclulation to find the closest value. // This palette can never be null here. - return this.GetClosestColor(pixel, this.palette, this.colorMap); + return this.GetClosesTPixel(pixel, this.palette, this.colorMap); } return (byte)this.octree.GetPaletteIndex(pixel, this.pixelBuffer); @@ -190,7 +191,7 @@ namespace ImageSharp.Quantizers /// /// Cache the previous color quantized /// - private TColor previousColor; + private TPixel previousColor; /// /// Initializes a new instance of the class. @@ -204,7 +205,7 @@ namespace ImageSharp.Quantizers this.Leaves = 0; this.reducibleNodes = new OctreeNode[9]; this.root = new OctreeNode(0, this.maxColorBits, this); - this.previousColor = default(TColor); + this.previousColor = default(TPixel); this.previousNode = null; } @@ -223,7 +224,7 @@ namespace ImageSharp.Quantizers /// /// The pixel data. /// The buffer array. - public void AddColor(TColor pixel, byte[] buffer) + public void AddColor(TPixel pixel, byte[] buffer) { // Check if this request is for the same color as the last if (this.previousColor.Equals(pixel)) @@ -253,9 +254,9 @@ namespace ImageSharp.Quantizers /// /// The maximum number of colors /// - /// An with the palletized colors + /// An with the palletized colors /// - public TColor[] Palletize(int colorCount) + public TPixel[] Palletize(int colorCount) { while (this.Leaves > colorCount) { @@ -263,7 +264,7 @@ namespace ImageSharp.Quantizers } // Now palletize the nodes - TColor[] palette = new TColor[colorCount + 1]; + TPixel[] palette = new TPixel[colorCount + 1]; int paletteIndex = 0; this.root.ConstructPalette(palette, ref paletteIndex); @@ -280,7 +281,7 @@ namespace ImageSharp.Quantizers /// /// The . /// - public int GetPaletteIndex(TColor pixel, byte[] buffer) + public int GetPaletteIndex(TPixel pixel, byte[] buffer) { return this.root.GetPaletteIndex(pixel, 0, buffer); } @@ -409,7 +410,7 @@ namespace ImageSharp.Quantizers /// The level in the tree /// The tree to which this node belongs /// The buffer array. - public void AddColor(TColor pixel, int colorBits, int level, Octree octree, byte[] buffer) + public void AddColor(TPixel pixel, int colorBits, int level, Octree octree, byte[] buffer) { // Update the color information if this is a leaf if (this.leaf) @@ -478,7 +479,7 @@ namespace ImageSharp.Quantizers /// /// The palette /// The current palette index - public void ConstructPalette(TColor[] palette, ref int index) + public void ConstructPalette(TPixel[] palette, ref int index) { if (this.leaf) { @@ -488,7 +489,7 @@ namespace ImageSharp.Quantizers byte b = (this.blue / this.pixelCount).ToByte(); // And set the color of the palette entry - TColor pixel = default(TColor); + TPixel pixel = default(TPixel); pixel.PackFromBytes(r, g, b, 255); palette[index] = pixel; @@ -517,7 +518,7 @@ namespace ImageSharp.Quantizers /// /// The representing the index of the pixel in the palette. /// - public int GetPaletteIndex(TColor pixel, int level, byte[] buffer) + public int GetPaletteIndex(TPixel pixel, int level, byte[] buffer) { int index = this.paletteIndex; @@ -548,7 +549,7 @@ namespace ImageSharp.Quantizers /// /// The pixel to add. /// The buffer array. - public void Increment(TColor pixel, byte[] buffer) + public void Increment(TPixel pixel, byte[] buffer) { pixel.ToXyzwBytes(buffer, 0); this.pixelCount++; diff --git a/src/ImageSharp/Quantizers/PaletteQuantizer.cs b/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs similarity index 76% rename from src/ImageSharp/Quantizers/PaletteQuantizer.cs rename to src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs index f039fe0c57..b5e5ccb25e 100644 --- a/src/ImageSharp/Quantizers/PaletteQuantizer.cs +++ b/src/ImageSharp/Quantizers/PaletteQuantizer{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -8,14 +8,15 @@ namespace ImageSharp.Quantizers using System; using System.Collections.Generic; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; /// /// Encapsulates methods to create a quantized image based upon the given palette. /// /// - /// The pixel format. - public sealed class PaletteQuantizer : Quantizer - where TColor : struct, IPixel + /// The pixel format. + public sealed class PaletteQuantizer : Quantizer + where TPixel : struct, IPixel { /// /// The pixel buffer, used to reduce allocations. @@ -25,32 +26,32 @@ namespace ImageSharp.Quantizers /// /// A lookup table for colors /// - private readonly Dictionary colorMap = new Dictionary(); + private readonly Dictionary colorMap = new Dictionary(); /// /// List of all colors in the palette /// - private TColor[] colors; + private TPixel[] colors; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The color palette. If none is given this will default to the web safe colors defined /// in the CSS Color Module Level 4. /// - public PaletteQuantizer(TColor[] palette = null) + public PaletteQuantizer(TPixel[] palette = null) : base(true) { if (palette == null) { - Color[] constants = ColorConstants.WebSafeColors; - TColor[] safe = new TColor[constants.Length + 1]; + Rgba32[] constants = ColorConstants.WebSafeColors; + TPixel[] safe = new TPixel[constants.Length + 1]; for (int i = 0; i < constants.Length; i++) { constants[i].ToXyzwBytes(this.pixelBuffer, 0); - TColor packed = default(TColor); + TPixel packed = default(TPixel); packed.PackFromBytes(this.pixelBuffer[0], this.pixelBuffer[1], this.pixelBuffer[2], this.pixelBuffer[3]); safe[i] = packed; } @@ -64,22 +65,22 @@ namespace ImageSharp.Quantizers } /// - public override QuantizedImage Quantize(ImageBase image, int maxColors) + public override QuantizedImage Quantize(ImageBase image, int maxColors) { Array.Resize(ref this.colors, maxColors.Clamp(1, 255)); return base.Quantize(image, maxColors); } /// - protected override void SecondPass(PixelAccessor source, byte[] output, int width, int height) + protected override void SecondPass(PixelAccessor source, byte[] output, int width, int height) { // Load up the values for the first pixel. We can use these to speed up the second // pass of the algorithm by avoiding transforming rows of identical color. - TColor sourcePixel = source[0, 0]; - TColor previousPixel = sourcePixel; + TPixel sourcePixel = source[0, 0]; + TPixel previousPixel = sourcePixel; byte pixelValue = this.QuantizePixel(sourcePixel); - TColor[] colorPalette = this.GetPalette(); - TColor transformedPixel = colorPalette[pixelValue]; + TPixel[] colorPalette = this.GetPalette(); + TPixel transformedPixel = colorPalette[pixelValue]; for (int y = 0; y < height; y++) { @@ -117,7 +118,7 @@ namespace ImageSharp.Quantizers } /// - protected override TColor[] GetPalette() + protected override TPixel[] GetPalette() { return this.colors; } @@ -130,9 +131,9 @@ namespace ImageSharp.Quantizers /// The quantized value /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private byte QuantizePixel(TColor pixel) + private byte QuantizePixel(TPixel pixel) { - return this.GetClosestColor(pixel, this.GetPalette(), this.colorMap); + return this.GetClosesTPixel(pixel, this.GetPalette(), this.colorMap); } } } \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index f45cd3f799..a235092787 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -8,37 +8,38 @@ namespace ImageSharp using System; using System.Threading.Tasks; + using ImageSharp.PixelFormats; using ImageSharp.Quantizers; /// - /// Extension methods for the type. + /// Extension methods for the type. /// public static partial class ImageExtensions { /// /// Applies quantization to the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. - /// The . - public static Image Quantize(this Image source, Quantization mode = Quantization.Octree, int maxColors = 256) - where TColor : struct, IPixel + /// The . + public static Image Quantize(this Image source, Quantization mode = Quantization.Octree, int maxColors = 256) + where TPixel : struct, IPixel { - IQuantizer quantizer; + IQuantizer quantizer; switch (mode) { case Quantization.Wu: - quantizer = new WuQuantizer(); + quantizer = new WuQuantizer(); break; case Quantization.Palette: - quantizer = new PaletteQuantizer(); + quantizer = new PaletteQuantizer(); break; default: - quantizer = new OctreeQuantizer(); + quantizer = new OctreeQuantizer(); break; } @@ -48,18 +49,18 @@ namespace ImageSharp /// /// Applies quantization to the image. /// - /// The pixel format. + /// The pixel format. /// The image this method extends. /// The quantizer to apply to perform the operation. /// The maximum number of colors to return. - /// The . - public static Image Quantize(this Image source, IQuantizer quantizer, int maxColors) - where TColor : struct, IPixel + /// The . + public static Image Quantize(this Image source, IQuantizer quantizer, int maxColors) + where TPixel : struct, IPixel { - QuantizedImage quantized = quantizer.Quantize(source, maxColors); + QuantizedImage quantized = quantizer.Quantize(source, maxColors); int palleteCount = quantized.Palette.Length - 1; - using (PixelAccessor pixels = new PixelAccessor(quantized.Width, quantized.Height)) + using (PixelAccessor pixels = new PixelAccessor(quantized.Width, quantized.Height)) { Parallel.For( 0, @@ -70,7 +71,7 @@ namespace ImageSharp for (int x = 0; x < pixels.Width; x++) { int i = x + (y * pixels.Width); - TColor color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])]; + TPixel color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])]; pixels[x, y] = color; } }); diff --git a/src/ImageSharp/Quantizers/QuantizedImage.cs b/src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs similarity index 82% rename from src/ImageSharp/Quantizers/QuantizedImage.cs rename to src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs index 471abbae75..c8b2c7df60 100644 --- a/src/ImageSharp/Quantizers/QuantizedImage.cs +++ b/src/ImageSharp/Quantizers/QuantizedImage{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -6,22 +6,23 @@ namespace ImageSharp.Quantizers { using System; + using ImageSharp.PixelFormats; /// /// Represents a quantized image where the pixels indexed by a color palette. /// - /// The pixel format. - public class QuantizedImage - where TColor : struct, IPixel + /// The pixel format. + public class QuantizedImage + where TPixel : struct, IPixel { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image width. /// The image height. /// The color palette. /// The quantized pixels. - public QuantizedImage(int width, int height, TColor[] palette, byte[] pixels) + public QuantizedImage(int width, int height, TPixel[] palette, byte[] pixels) { Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(height, 0, nameof(height)); @@ -52,7 +53,7 @@ namespace ImageSharp.Quantizers /// /// Gets the color palette of this . /// - public TColor[] Palette { get; } + public TPixel[] Palette { get; } /// /// Gets the pixels of this . diff --git a/src/ImageSharp/Quantizers/Quantizer.cs b/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs similarity index 84% rename from src/ImageSharp/Quantizers/Quantizer.cs rename to src/ImageSharp/Quantizers/Quantizer{TPixel}.cs index 492ec5f2bc..02447062ef 100644 --- a/src/ImageSharp/Quantizers/Quantizer.cs +++ b/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs @@ -1,22 +1,22 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Quantizers { - using System; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using ImageSharp.Dithering; + using ImageSharp.PixelFormats; /// /// Encapsulates methods to calculate the color palette of an image. /// - /// The pixel format. - public abstract class Quantizer : IDitheredQuantizer - where TColor : struct, IPixel + /// The pixel format. + public abstract class Quantizer : IDitheredQuantizer + where TPixel : struct, IPixel { /// /// Flag used to indicate whether a single pass or two passes are needed for quantization. @@ -24,7 +24,7 @@ namespace ImageSharp.Quantizers private readonly bool singlePass; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// If true, the quantization only needs to loop through the source pixels once @@ -46,7 +46,7 @@ namespace ImageSharp.Quantizers public IErrorDiffuser DitherType { get; set; } = new SierraLite(); /// - public virtual QuantizedImage Quantize(ImageBase image, int maxColors) + public virtual QuantizedImage Quantize(ImageBase image, int maxColors) { Guard.NotNull(image, nameof(image)); @@ -54,9 +54,9 @@ namespace ImageSharp.Quantizers int height = image.Height; int width = image.Width; byte[] quantizedPixels = new byte[width * height]; - TColor[] colorPalette; + TPixel[] colorPalette; - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { // Call the FirstPass function if not a single pass algorithm. // For something like an Octree quantizer, this will run through @@ -72,8 +72,8 @@ namespace ImageSharp.Quantizers if (this.Dither) { // We clone the image as we don't want to alter the original. - using (Image clone = new Image(image)) - using (PixelAccessor clonedPixels = clone.Lock()) + using (Image clone = new Image(image)) + using (PixelAccessor clonedPixels = clone.Lock()) { this.SecondPass(clonedPixels, quantizedPixels, width, height); } @@ -84,7 +84,7 @@ namespace ImageSharp.Quantizers } } - return new QuantizedImage(width, height, colorPalette, quantizedPixels); + return new QuantizedImage(width, height, colorPalette, quantizedPixels); } /// @@ -93,7 +93,7 @@ namespace ImageSharp.Quantizers /// The source data /// The width in pixels of the image. /// The height in pixels of the image. - protected virtual void FirstPass(PixelAccessor source, int width, int height) + protected virtual void FirstPass(PixelAccessor source, int width, int height) { // Loop through each row for (int y = 0; y < height; y++) @@ -114,7 +114,7 @@ namespace ImageSharp.Quantizers /// The output pixel array /// The width in pixels of the image /// The height in pixels of the image - protected abstract void SecondPass(PixelAccessor source, byte[] output, int width, int height); + protected abstract void SecondPass(PixelAccessor source, byte[] output, int width, int height); /// /// Override this to process the pixel in the first pass of the algorithm @@ -124,7 +124,7 @@ namespace ImageSharp.Quantizers /// This function need only be overridden if your quantize algorithm needs two passes, /// such as an Octree quantizer. /// - protected virtual void InitialQuantizePixel(TColor pixel) + protected virtual void InitialQuantizePixel(TPixel pixel) { } @@ -132,9 +132,9 @@ namespace ImageSharp.Quantizers /// Retrieve the palette for the quantized image. Can be called more than once so make sure calls are cached. /// /// - /// + /// /// - protected abstract TColor[] GetPalette(); + protected abstract TPixel[] GetPalette(); /// /// Returns the closest color from the palette to the given color by calculating the Euclidean distance. @@ -144,7 +144,7 @@ namespace ImageSharp.Quantizers /// The cache to store the result in. /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected byte GetClosestColor(TColor pixel, TColor[] colorPalette, Dictionary cache) + protected byte GetClosesTPixel(TPixel pixel, TPixel[] colorPalette, Dictionary cache) { // Check if the color is in the lookup table if (cache.ContainsKey(pixel)) diff --git a/src/ImageSharp/Quantizers/WuArrayPool.cs b/src/ImageSharp/Quantizers/WuArrayPool.cs index 5e4956f011..bd8ee9d6b9 100644 --- a/src/ImageSharp/Quantizers/WuArrayPool.cs +++ b/src/ImageSharp/Quantizers/WuArrayPool.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Quantizers using System.Buffers; /// - /// Provides array pooling for the . + /// Provides array pooling for the . /// This is a separate class so that the pools can be shared accross multiple generic quantizer instaces. /// internal static class WuArrayPool @@ -29,7 +29,7 @@ namespace ImageSharp.Quantizers public static readonly ArrayPool BytePool = ArrayPool.Create(TableLength, 5); /// - /// The table length. Matches the calculated value in + /// The table length. Matches the calculated value in /// private const int TableLength = 2471625; } diff --git a/src/ImageSharp/Quantizers/WuQuantizer.cs b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs similarity index 96% rename from src/ImageSharp/Quantizers/WuQuantizer.cs rename to src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs index 46af6fab93..482481c710 100644 --- a/src/ImageSharp/Quantizers/WuQuantizer.cs +++ b/src/ImageSharp/Quantizers/WuQuantizer{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -10,6 +10,7 @@ namespace ImageSharp.Quantizers using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; /// /// An implementation of Wu's color quantizer with alpha channel. @@ -30,9 +31,9 @@ namespace ImageSharp.Quantizers /// but more expensive versions. /// /// - /// The pixel format. - public class WuQuantizer : Quantizer - where TColor : struct, IPixel + /// The pixel format. + public class WuQuantizer : Quantizer + where TPixel : struct, IPixel { /// /// The index bits. @@ -67,7 +68,7 @@ namespace ImageSharp.Quantizers /// /// A lookup table for colors /// - private readonly Dictionary colorMap = new Dictionary(); + private readonly Dictionary colorMap = new Dictionary(); /// /// Moment of P(c). @@ -112,7 +113,7 @@ namespace ImageSharp.Quantizers /// /// The reduced image palette /// - private TColor[] palette; + private TPixel[] palette; /// /// The color cube representing the image palette @@ -120,7 +121,7 @@ namespace ImageSharp.Quantizers private Box[] colorCube; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The Wu quantizer is a two pass algorithm. The initial pass sets up the 3-D color histogram, @@ -132,7 +133,7 @@ namespace ImageSharp.Quantizers } /// - public override QuantizedImage Quantize(ImageBase image, int maxColors) + public override QuantizedImage Quantize(ImageBase image, int maxColors) { Guard.NotNull(image, nameof(image)); @@ -163,11 +164,11 @@ namespace ImageSharp.Quantizers } /// - protected override TColor[] GetPalette() + protected override TPixel[] GetPalette() { if (this.palette == null) { - this.palette = new TColor[this.colors]; + this.palette = new TPixel[this.colors]; for (int k = 0; k < this.colors; k++) { this.Mark(this.colorCube[k], (byte)k); @@ -181,7 +182,7 @@ namespace ImageSharp.Quantizers float b = Volume(this.colorCube[k], this.vmb) / weight; float a = Volume(this.colorCube[k], this.vma) / weight; - TColor color = default(TColor); + TPixel color = default(TPixel); color.PackFromVector4(new Vector4(r, g, b, a) / 255F); this.palette[k] = color; } @@ -192,7 +193,7 @@ namespace ImageSharp.Quantizers } /// - protected override void InitialQuantizePixel(TColor pixel) + protected override void InitialQuantizePixel(TPixel pixel) { // Add the color to a 3-D color histogram. // Colors are expected in r->g->b->a format @@ -219,7 +220,7 @@ namespace ImageSharp.Quantizers } /// - protected override void FirstPass(PixelAccessor source, int width, int height) + protected override void FirstPass(PixelAccessor source, int width, int height) { // Build up the 3-D color histogram // Loop through each row @@ -238,15 +239,15 @@ namespace ImageSharp.Quantizers } /// - protected override void SecondPass(PixelAccessor source, byte[] output, int width, int height) + protected override void SecondPass(PixelAccessor source, byte[] output, int width, int height) { // Load up the values for the first pixel. We can use these to speed up the second // pass of the algorithm by avoiding transforming rows of identical color. - TColor sourcePixel = source[0, 0]; - TColor previousPixel = sourcePixel; + TPixel sourcePixel = source[0, 0]; + TPixel previousPixel = sourcePixel; byte pixelValue = this.QuantizePixel(sourcePixel); - TColor[] colorPalette = this.GetPalette(); - TColor transformedPixel = colorPalette[pixelValue]; + TPixel[] colorPalette = this.GetPalette(); + TPixel transformedPixel = colorPalette[pixelValue]; for (int y = 0; y < height; y++) { @@ -825,13 +826,13 @@ namespace ImageSharp.Quantizers /// The quantized value /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private byte QuantizePixel(TColor pixel) + private byte QuantizePixel(TPixel pixel) { if (this.Dither) { // The colors have changed so we need to use Euclidean distance caclulation to find the closest value. // This palette can never be null here. - return this.GetClosestColor(pixel, this.palette, this.colorMap); + return this.GetClosesTPixel(pixel, this.palette, this.colorMap); } // Expected order r->g->b->a diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs index befff61d5c..65c4a235d5 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4ReferenceVsPointer.cs @@ -6,6 +6,7 @@ using BenchmarkDotNet.Attributes; using ImageSharp; + using ImageSharp.PixelFormats; /// /// Compares two implementation candidates for general BulkPixelOperations.ToVector4(): @@ -14,7 +15,7 @@ /// public unsafe class PackFromVector4ReferenceVsPointer { - private Buffer destination; + private Buffer destination; private Buffer source; @@ -24,7 +25,7 @@ [Setup] public void Setup() { - this.destination = new Buffer(this.Count); + this.destination = new Buffer(this.Count); this.source = new Buffer(this.Count * 4); this.source.Pin(); this.destination.Pin(); @@ -43,12 +44,12 @@ Vector4* sp = (Vector4*)this.source.Pin(); byte* dp = (byte*)this.destination.Pin(); int count = this.Count; - int size = sizeof(ImageSharp.Color); + int size = sizeof(Rgba32); for (int i = 0; i < count; i++) { Vector4 v = Unsafe.Read(sp); - ImageSharp.Color c = default(ImageSharp.Color); + Rgba32 c = default(Rgba32); c.PackFromVector4(v); Unsafe.Write(dp, c); @@ -61,7 +62,7 @@ public void PackUsingReferences() { ref Vector4 sp = ref this.source.Array[0]; - ref ImageSharp.Color dp = ref this.destination.Array[0]; + ref Rgba32 dp = ref this.destination.Array[0]; int count = this.Count; for (int i = 0; i < count; i++) diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index 33969b8fba..2a370bc002 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -3,12 +3,12 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using Color = ImageSharp.Color; + using ImageSharp.PixelFormats; - public abstract class PackFromXyzw - where TColor : struct, IPixel + public abstract class PackFromXyzw + where TPixel : struct, IPixel { - private Buffer destination; + private Buffer destination; private Buffer source; @@ -18,7 +18,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Setup] public void Setup() { - this.destination = new Buffer(this.Count); + this.destination = new Buffer(this.Count); this.source = new Buffer(this.Count * 4); } @@ -33,12 +33,12 @@ namespace ImageSharp.Benchmarks.Color.Bulk public void PerElement() { byte[] s = this.source.Array; - TColor[] d = this.destination.Array; + TPixel[] d = this.destination.Array; for (int i = 0; i < this.Count; i++) { int i4 = i * 4; - TColor c = default(TColor); + TPixel c = default(TPixel); c.PackFromBytes(s[i4], s[i4 + 1], s[i4 + 2], s[i4 + 3]); d[i] = c; } @@ -47,17 +47,17 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Benchmark] public void CommonBulk() { - new BulkPixelOperations().PackFromXyzwBytes(this.source, this.destination, this.Count); + new BulkPixelOperations().PackFromXyzwBytes(this.source, this.destination, this.Count); } [Benchmark] public void OptimizedBulk() { - BulkPixelOperations.Instance.PackFromXyzwBytes(this.source, this.destination, this.Count); + BulkPixelOperations.Instance.PackFromXyzwBytes(this.source, this.destination, this.Count); } } - public class PackFromXyzw_Color : PackFromXyzw + public class PackFromXyzw_Color : PackFromXyzw { } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs index 4cabfc01f4..1234a99460 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToVector4.cs @@ -5,10 +5,12 @@ namespace ImageSharp.Benchmarks.Color.Bulk using BenchmarkDotNet.Attributes; - public abstract class ToVector4 - where TColor : struct, IPixel + using ImageSharp.PixelFormats; + + public abstract class ToVector4 + where TPixel : struct, IPixel { - private Buffer source; + private Buffer source; private Buffer destination; @@ -18,7 +20,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Setup] public void Setup() { - this.source = new Buffer(this.Count); + this.source = new Buffer(this.Count); this.destination = new Buffer(this.Count); } @@ -32,12 +34,12 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Benchmark(Baseline = true)] public void PerElement() { - TColor[] s = this.source.Array; + TPixel[] s = this.source.Array; Vector4[] d = this.destination.Array; for (int i = 0; i < this.Count; i++) { - TColor c = s[i]; + TPixel c = s[i]; d[i] = c.ToVector4(); } } @@ -45,17 +47,17 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Benchmark] public void CommonBulk() { - new BulkPixelOperations().ToVector4(this.source, this.destination, this.Count); + new BulkPixelOperations().ToVector4(this.source, this.destination, this.Count); } [Benchmark] public void OptimizedBulk() { - BulkPixelOperations.Instance.ToVector4(this.source, this.destination, this.Count); + BulkPixelOperations.Instance.ToVector4(this.source, this.destination, this.Count); } } - public class ToVector4_Color : ToVector4 + public class ToVector4_Color : ToVector4 { } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs index f6ae4256db..fe201549bc 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyz.cs @@ -3,12 +3,12 @@ namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; - using Color = ImageSharp.Color; + using ImageSharp.PixelFormats; - public abstract class ToXyz - where TColor : struct, IPixel + public abstract class ToXyz + where TPixel : struct, IPixel { - private Buffer source; + private Buffer source; private Buffer destination; @@ -18,7 +18,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Setup] public void Setup() { - this.source = new Buffer(this.Count); + this.source = new Buffer(this.Count); this.destination = new Buffer(this.Count * 3); } @@ -32,12 +32,12 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Benchmark(Baseline = true)] public void PerElement() { - TColor[] s = this.source.Array; + TPixel[] s = this.source.Array; byte[] d = this.destination.Array; for (int i = 0; i < this.Count; i++) { - TColor c = s[i]; + TPixel c = s[i]; c.ToXyzBytes(d, i * 4); } } @@ -45,17 +45,17 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Benchmark] public void CommonBulk() { - new BulkPixelOperations().ToXyzBytes(this.source, this.destination, this.Count); + new BulkPixelOperations().ToXyzBytes(this.source, this.destination, this.Count); } [Benchmark] public void OptimizedBulk() { - BulkPixelOperations.Instance.ToXyzBytes(this.source, this.destination, this.Count); + BulkPixelOperations.Instance.ToXyzBytes(this.source, this.destination, this.Count); } } - public class ToXyz_Color : ToXyz + public class ToXyz_Color : ToXyz { } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs index f23ca3e5cf..f7406d0f61 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/ToXyzw.cs @@ -7,13 +7,12 @@ using System.Threading.Tasks; namespace ImageSharp.Benchmarks.Color.Bulk { using BenchmarkDotNet.Attributes; + using ImageSharp.PixelFormats; - using Color = ImageSharp.Color; - - public abstract class ToXyzw - where TColor : struct, IPixel + public abstract class ToXyzw + where TPixel : struct, IPixel { - private Buffer source; + private Buffer source; private Buffer destination; @@ -23,7 +22,7 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Setup] public void Setup() { - this.source = new Buffer(this.Count); + this.source = new Buffer(this.Count); this.destination = new Buffer(this.Count * 4); } @@ -37,12 +36,12 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Benchmark(Baseline = true)] public void PerElement() { - TColor[] s = this.source.Array; + TPixel[] s = this.source.Array; byte[] d = this.destination.Array; for (int i = 0; i < this.Count; i++) { - TColor c = s[i]; + TPixel c = s[i]; c.ToXyzwBytes(d, i * 4); } } @@ -50,17 +49,17 @@ namespace ImageSharp.Benchmarks.Color.Bulk [Benchmark] public void CommonBulk() { - new BulkPixelOperations().ToXyzwBytes(this.source, this.destination, this.Count); + new BulkPixelOperations().ToXyzwBytes(this.source, this.destination, this.Count); } [Benchmark] public void OptimizedBulk() { - BulkPixelOperations.Instance.ToXyzwBytes(this.source, this.destination, this.Count); + BulkPixelOperations.Instance.ToXyzwBytes(this.source, this.destination, this.Count); } } - public class ToXyzw_Color : ToXyzw + public class ToXyzw_Color : ToXyzw { } diff --git a/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs b/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs index 3ee28d06b4..a641baafe5 100644 --- a/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs +++ b/tests/ImageSharp.Benchmarks/Color/ColorEquality.cs @@ -7,7 +7,8 @@ namespace ImageSharp.Benchmarks { using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using ImageSharp.PixelFormats; + using SystemColor = System.Drawing.Color; public class ColorEquality @@ -21,7 +22,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Color Equals")] public bool ColorEqual() { - return new CoreColor(128, 128, 128, 128).Equals(new CoreColor(128, 128, 128, 128)); + return new Rgba32(128, 128, 128, 128).Equals(new Rgba32(128, 128, 128, 128)); } } } diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index 3e60cae4dc..d0bd9f208f 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -12,7 +12,8 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using ImageSharp.PixelFormats; + using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; @@ -50,7 +51,7 @@ namespace ImageSharp.Benchmarks using (CoreImage image = new CoreImage(800, 800)) { image.DrawBeziers( - CoreColor.HotPink, + Rgba32.HotPink, 10, new[] { new Vector2(10, 500), diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index ee97866e24..2bd3f4a6a9 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -12,7 +12,8 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using ImageSharp.PixelFormats; + using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; @@ -49,7 +50,7 @@ namespace ImageSharp.Benchmarks using (CoreImage image = new CoreImage(800, 800)) { image.DrawLines( - CoreColor.HotPink, + Rgba32.HotPink, 10, new[] { new Vector2(10, 10), diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index 047cacb421..a0f8b21d85 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -11,10 +11,11 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; - using CoreColor = ImageSharp.Color; using System.IO; using System.Numerics; + using ImageSharp.PixelFormats; + public class DrawPolygon : BenchmarkBase { [Benchmark(Baseline = true, Description = "System.Drawing Draw Polygon")] @@ -48,7 +49,7 @@ namespace ImageSharp.Benchmarks using (CoreImage image = new CoreImage(800, 800)) { image.DrawPolygon( - CoreColor.HotPink, + Rgba32.HotPink, 10, new[] { new Vector2(10, 10), diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index 782306deb7..ac10826971 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -13,7 +13,8 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using ImageSharp.PixelFormats; + using CoreImage = ImageSharp.Image; public class FillPolygon : BenchmarkBase @@ -57,7 +58,7 @@ namespace ImageSharp.Benchmarks using (CoreImage image = new CoreImage(800, 800)) { image.FillPolygon( - CoreColor.HotPink, + Rgba32.HotPink, new[] { new Vector2(10, 10), new Vector2(550, 50), @@ -77,7 +78,7 @@ namespace ImageSharp.Benchmarks using (CoreImage image = new CoreImage(800, 800)) { image.Fill( - CoreColor.HotPink, + Rgba32.HotPink, this.shape); using (MemoryStream ms = new MemoryStream()) diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index 691955e8ed..7b21dbdc61 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -11,11 +11,12 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CoreRectangle = ImageSharp.Rectangle; - using CoreColor = ImageSharp.Color; using CoreSize = ImageSharp.Size; using System.Numerics; + using ImageSharp.PixelFormats; + public class FillRectangle : BenchmarkBase { [Benchmark(Baseline = true, Description = "System.Drawing Fill Rectangle")] @@ -39,7 +40,7 @@ namespace ImageSharp.Benchmarks { using (CoreImage image = new CoreImage(800, 800)) { - image.Fill(CoreColor.HotPink, new CoreRectangle(10, 10, 190, 140)); + image.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140)); return new CoreSize(image.Width, image.Height); } @@ -51,7 +52,7 @@ namespace ImageSharp.Benchmarks using (CoreImage image = new CoreImage(800, 800)) { image.FillPolygon( - CoreColor.HotPink, + Rgba32.HotPink, new[] { new Vector2(10, 10), new Vector2(200, 10), diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs index dcd22d6fb4..580120abd7 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs @@ -11,8 +11,10 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; + using ImageSharp.PixelFormats; + using CoreBrushes = ImageSharp.Drawing.Brushes.Brushes; - using CoreColor = ImageSharp.Color; + using CoreImage = ImageSharp.Image; public class FillWithPattern @@ -40,7 +42,7 @@ namespace ImageSharp.Benchmarks { using (CoreImage image = new CoreImage(800, 800)) { - image.Fill(CoreBrushes.BackwardDiagonal(CoreColor.HotPink)); + image.Fill(CoreBrushes.BackwardDiagonal(Rgba32.HotPink)); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs index c7a2021deb..97deb72c57 100644 --- a/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs +++ b/tests/ImageSharp.Benchmarks/General/ClearBuffer.cs @@ -7,11 +7,11 @@ namespace ImageSharp.Benchmarks.General using BenchmarkDotNet.Attributes; - using Color = ImageSharp.Color; + using ImageSharp.PixelFormats; public unsafe class ClearBuffer { - private Buffer buffer; + private Buffer buffer; [Params(32, 128, 512)] public int Count { get; set; } @@ -19,7 +19,7 @@ namespace ImageSharp.Benchmarks.General [Setup] public void Setup() { - this.buffer = new Buffer(this.Count); + this.buffer = new Buffer(this.Count); } [Cleanup] diff --git a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs index 335d8247d3..aade8a8ded 100644 --- a/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs +++ b/tests/ImageSharp.Benchmarks/Image/CopyPixels.cs @@ -9,19 +9,20 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using ImageSharp.PixelFormats; + using CoreImage = ImageSharp.Image; public class CopyPixels : BenchmarkBase { [Benchmark(Description = "Copy by Pixel")] - public CoreColor CopyByPixel() + public Rgba32 CopyByPixel() { using (CoreImage source = new CoreImage(1024, 768)) using (CoreImage target = new CoreImage(1024, 768)) { - using (PixelAccessor sourcePixels = source.Lock()) - using (PixelAccessor targetPixels = target.Lock()) + using (PixelAccessor sourcePixels = source.Lock()) + using (PixelAccessor targetPixels = target.Lock()) { Parallel.For( 0, diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs index 1318c1674a..b27ad5fcc3 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image using ImageSharp; using ImageSharp.Formats; + using ImageSharp.PixelFormats; using ImageSharp.Quantizers; /// @@ -51,7 +52,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new OctreeQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new OctreeQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -62,7 +63,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new OctreeQuantizer { Dither = false }, Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new OctreeQuantizer { Dither = false }, Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -73,7 +74,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -84,7 +85,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer { Dither = false }, Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions { Quantizer = new PaletteQuantizer { Dither = false }, Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -95,7 +96,7 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new WuQuantizer(), Quality = 256 }; + PngEncoderOptions options = new PngEncoderOptions() { Quantizer = new WuQuantizer(), Quality = 256 }; this.bmpCore.SaveAsPng(memoryStream, options); } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs index 4c1feb6c2a..6158e5aac8 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs @@ -12,6 +12,7 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; using ImageSharp.Formats; + using ImageSharp.PixelFormats; using ImageSharp.Quantizers; using CoreImage = ImageSharp.Image; @@ -66,10 +67,10 @@ namespace ImageSharp.Benchmarks.Image { using (MemoryStream memoryStream = new MemoryStream()) { - Quantizer quantizer = this.UseOctreeQuantizer - ? (Quantizer) - new OctreeQuantizer() - : new PaletteQuantizer(); + Quantizer quantizer = this.UseOctreeQuantizer + ? (Quantizer) + new OctreeQuantizer() + : new PaletteQuantizer(); PngEncoderOptions options = new PngEncoderOptions() { Quantizer = quantizer }; this.bmpCore.SaveAsPng(memoryStream, options); diff --git a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs index 78295e27d7..21927c9154 100644 --- a/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs +++ b/tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs @@ -9,7 +9,8 @@ namespace ImageSharp.Benchmarks.Image using BenchmarkDotNet.Attributes; - using CoreColor = ImageSharp.Color; + using ImageSharp.PixelFormats; + using CoreImage = ImageSharp.Image; using SystemColor = System.Drawing.Color; @@ -26,13 +27,13 @@ namespace ImageSharp.Benchmarks.Image } [Benchmark(Description = "ImageSharp GetSet pixel")] - public CoreColor ResizeCore() + public Rgba32 ResizeCore() { using (CoreImage image = new CoreImage(400, 400)) { - using (PixelAccessor imagePixels = image.Lock()) + using (PixelAccessor imagePixels = image.Lock()) { - imagePixels[200, 200] = CoreColor.White; + imagePixels[200, 200] = Rgba32.White; return imagePixels[200, 200]; } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 569070af2a..638a56bf31 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -9,9 +9,11 @@ namespace ImageSharp.Benchmarks using System.Drawing.Drawing2D; using BenchmarkDotNet.Attributes; + + using ImageSharp.PixelFormats; + using CoreSize = ImageSharp.Size; using CoreImage = ImageSharp.Image; - using CoreVectorImage = ImageSharp.Image; public class Resize : BenchmarkBase { @@ -48,7 +50,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Vector Resize")] public CoreSize ResizeCoreVector() { - using (CoreVectorImage image = new CoreVectorImage(2000, 2000)) + using (CoreImage image = new CoreImage(2000, 2000)) { image.Resize(400, 400); return new CoreSize(image.Width, image.Height); @@ -68,7 +70,7 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp Vector Compand Resize")] public CoreSize ResizeCoreVectorCompand() { - using (CoreVectorImage image = new CoreVectorImage(2000, 2000)) + using (CoreImage image = new CoreImage(2000, 2000)) { image.Resize(400, 400, true); return new CoreSize(image.Width, image.Height); diff --git a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs index d4b9f6f3a1..b498c93acc 100644 --- a/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs @@ -5,12 +5,14 @@ namespace ImageSharp.Tests.Colors using System; using System.Numerics; + using ImageSharp.PixelFormats; + using Xunit; using Xunit.Abstractions; public class BulkPixelOperationsTests { - public class Color32 : BulkPixelOperationsTests + public class Color32 : BulkPixelOperationsTests { public Color32(ITestOutputHelper output) : base(output) @@ -23,19 +25,19 @@ namespace ImageSharp.Tests.Colors [Fact] public void IsSpecialImplementation() { - Assert.IsType(BulkPixelOperations.Instance); + Assert.IsType(BulkPixelOperations.Instance); } [Fact] public void ToVector4SimdAligned() { - ImageSharp.Color[] source = CreatePixelTestData(64); + Rgba32[] source = CreatePixelTestData(64); Vector4[] expected = CreateExpectedVector4Data(source); TestOperation( source, expected, - (s, d) => ImageSharp.Color.BulkOperations.ToVector4SimdAligned(s, d, 64) + (s, d) => Rgba32.BulkOperations.ToVector4SimdAligned(s, d, 64) ); } @@ -45,20 +47,20 @@ namespace ImageSharp.Tests.Colors int times = 200000; int count = 1024; - using (Buffer source = new Buffer(count)) + using (Buffer source = new Buffer(count)) using (Buffer dest = new Buffer(count)) { this.Measure( times, () => { - BulkPixelOperations.Instance.ToVector4(source, dest, count); + BulkPixelOperations.Instance.ToVector4(source, dest, count); }); } } } - public class Argb : BulkPixelOperationsTests + public class Argb : BulkPixelOperationsTests { // For 4.6 test runner MemberData does not work without redeclaring the public field in the derived test class: public Argb(ITestOutputHelper output) @@ -71,15 +73,15 @@ namespace ImageSharp.Tests.Colors [Theory] [WithBlankImages(1, 1, PixelTypes.All)] - public void GetGlobalInstance(TestImageProvider dummy) - where TColor : struct, IPixel + public void GetGlobalInstance(TestImageProvider dummy) + where TPixel : struct, IPixel { - Assert.NotNull(BulkPixelOperations.Instance); + Assert.NotNull(BulkPixelOperations.Instance); } } - public abstract class BulkPixelOperationsTests : MeasureFixture - where TColor : struct, IPixel + public abstract class BulkPixelOperationsTests : MeasureFixture + where TPixel : struct, IPixel { protected BulkPixelOperationsTests(ITestOutputHelper output) : base(output) @@ -88,11 +90,11 @@ namespace ImageSharp.Tests.Colors public static TheoryData ArraySizesData => new TheoryData { 7, 16, 1111 }; - private static BulkPixelOperations Operations => BulkPixelOperations.Instance; + private static BulkPixelOperations Operations => BulkPixelOperations.Instance; - internal static TColor[] CreateExpectedPixelData(Vector4[] source) + internal static TPixel[] CreateExpectedPixelData(Vector4[] source) { - TColor[] expected = new TColor[source.Length]; + TPixel[] expected = new TPixel[source.Length]; for (int i = 0; i < expected.Length; i++) { @@ -106,7 +108,7 @@ namespace ImageSharp.Tests.Colors public void PackFromVector4(int count) { Vector4[] source = CreateVector4TestData(count); - TColor[] expected = CreateExpectedPixelData(source); + TPixel[] expected = CreateExpectedPixelData(source); TestOperation( source, @@ -115,7 +117,7 @@ namespace ImageSharp.Tests.Colors ); } - internal static Vector4[] CreateExpectedVector4Data(TColor[] source) + internal static Vector4[] CreateExpectedVector4Data(TPixel[] source) { Vector4[] expected = new Vector4[source.Length]; @@ -130,7 +132,7 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(ArraySizesData))] public void ToVector4(int count) { - TColor[] source = CreatePixelTestData(count); + TPixel[] source = CreatePixelTestData(count); Vector4[] expected = CreateExpectedVector4Data(source); TestOperation( @@ -146,7 +148,7 @@ namespace ImageSharp.Tests.Colors public void PackFromXyzBytes(int count) { byte[] source = CreateByteTestData(count * 3); - TColor[] expected = new TColor[count]; + TPixel[] expected = new TPixel[count]; for (int i = 0; i < count; i++) { @@ -166,7 +168,7 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(ArraySizesData))] public void ToXyzBytes(int count) { - TColor[] source = CreatePixelTestData(count); + TPixel[] source = CreatePixelTestData(count); byte[] expected = new byte[count * 3]; for (int i = 0; i < count; i++) @@ -187,7 +189,7 @@ namespace ImageSharp.Tests.Colors public void PackFromXyzwBytes(int count) { byte[] source = CreateByteTestData(count * 4); - TColor[] expected = new TColor[count]; + TPixel[] expected = new TPixel[count]; for (int i = 0; i < count; i++) { @@ -207,7 +209,7 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(ArraySizesData))] public void ToXyzwBytes(int count) { - TColor[] source = CreatePixelTestData(count); + TPixel[] source = CreatePixelTestData(count); byte[] expected = new byte[count * 4]; for (int i = 0; i < count; i++) @@ -228,7 +230,7 @@ namespace ImageSharp.Tests.Colors public void PackFromZyxBytes(int count) { byte[] source = CreateByteTestData(count * 3); - TColor[] expected = new TColor[count]; + TPixel[] expected = new TPixel[count]; for (int i = 0; i < count; i++) { @@ -248,7 +250,7 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(ArraySizesData))] public void ToZyxBytes(int count) { - TColor[] source = CreatePixelTestData(count); + TPixel[] source = CreatePixelTestData(count); byte[] expected = new byte[count * 3]; for (int i = 0; i < count; i++) @@ -269,7 +271,7 @@ namespace ImageSharp.Tests.Colors public void PackFromZyxwBytes(int count) { byte[] source = CreateByteTestData(count * 4); - TColor[] expected = new TColor[count]; + TPixel[] expected = new TPixel[count]; for (int i = 0; i < count; i++) { @@ -289,7 +291,7 @@ namespace ImageSharp.Tests.Colors [MemberData(nameof(ArraySizesData))] public void ToZyxwBytes(int count) { - TColor[] source = CreatePixelTestData(count); + TPixel[] source = CreatePixelTestData(count); byte[] expected = new byte[count * 4]; for (int i = 0; i < count; i++) @@ -387,9 +389,9 @@ namespace ImageSharp.Tests.Colors return result; } - internal static TColor[] CreatePixelTestData(int length) + internal static TPixel[] CreatePixelTestData(int length) { - TColor[] result = new TColor[length]; + TPixel[] result = new TPixel[length]; Random rnd = new Random(42); // Deterministic random values diff --git a/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs b/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs index d2c5cf8454..eac0644d9a 100644 --- a/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorConstructorTests.cs @@ -7,6 +7,9 @@ namespace ImageSharp.Tests.Colors { using System.Collections.Generic; using System.Numerics; + + using ImageSharp.PixelFormats; + using Xunit; public class ColorConstructorTests diff --git a/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs b/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs index 9ed1c67a70..4b45d0ab48 100644 --- a/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorConversionTests.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Tests using System; using System.Diagnostics.CodeAnalysis; using ImageSharp.Colors.Spaces; + using ImageSharp.PixelFormats; using Xunit; /// @@ -20,7 +21,7 @@ namespace ImageSharp.Tests public class ColorConversionTests { /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -28,7 +29,7 @@ namespace ImageSharp.Tests public void ColorToYCbCr() { // White - Color color = Color.White; + Rgba32 color = Rgba32.White; YCbCr yCbCr = color; Assert.Equal(255, yCbCr.Y); @@ -36,14 +37,14 @@ namespace ImageSharp.Tests Assert.Equal(128, yCbCr.Cr); // Black - Color color2 = Color.Black; + Rgba32 color2 = Rgba32.Black; YCbCr yCbCr2 = color2; Assert.Equal(0, yCbCr2.Y); Assert.Equal(128, yCbCr2.Cb); Assert.Equal(128, yCbCr2.Cr); // Gray - Color color3 = Color.Gray; + Rgba32 color3 = Rgba32.Gray; YCbCr yCbCr3 = color3; Assert.Equal(128, yCbCr3.Y); Assert.Equal(128, yCbCr3.Cb); @@ -51,7 +52,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -60,7 +61,7 @@ namespace ImageSharp.Tests { // White YCbCr yCbCr = new YCbCr(255, 128, 128); - Color color = yCbCr; + Rgba32 color = yCbCr; Assert.Equal(255, color.R); Assert.Equal(255, color.G); @@ -69,7 +70,7 @@ namespace ImageSharp.Tests // Black YCbCr yCbCr2 = new YCbCr(0, 128, 128); - Color color2 = yCbCr2; + Rgba32 color2 = yCbCr2; Assert.Equal(0, color2.R); Assert.Equal(0, color2.G); @@ -78,7 +79,7 @@ namespace ImageSharp.Tests // Gray YCbCr yCbCr3 = new YCbCr(128, 128, 128); - Color color3 = yCbCr3; + Rgba32 color3 = yCbCr3; Assert.Equal(128, color3.R); Assert.Equal(128, color3.G); @@ -87,7 +88,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-xyz /// @@ -95,7 +96,7 @@ namespace ImageSharp.Tests public void ColorToCieXyz() { // White - Color color = Color.White; + Rgba32 color = Rgba32.White; CieXyz ciexyz = color; Assert.Equal(95.05f, ciexyz.X, 3); @@ -103,21 +104,21 @@ namespace ImageSharp.Tests Assert.Equal(108.900f, ciexyz.Z, 3); // Black - Color color2 = Color.Black; + Rgba32 color2 = Rgba32.Black; CieXyz ciexyz2 = color2; Assert.Equal(0, ciexyz2.X, 3); Assert.Equal(0, ciexyz2.Y, 3); Assert.Equal(0, ciexyz2.Z, 3); // Gray - Color color3 = Color.Gray; + Rgba32 color3 = Rgba32.Gray; CieXyz ciexyz3 = color3; Assert.Equal(20.518, ciexyz3.X, 3); Assert.Equal(21.586, ciexyz3.Y, 3); Assert.Equal(23.507, ciexyz3.Z, 3); // Cyan - Color color4 = Color.Cyan; + Rgba32 color4 = Rgba32.Cyan; CieXyz ciexyz4 = color4; Assert.Equal(53.810f, ciexyz4.X, 3); Assert.Equal(78.740f, ciexyz4.Y, 3); @@ -125,7 +126,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-xyz /// @@ -134,7 +135,7 @@ namespace ImageSharp.Tests { // Dark moderate pink. CieXyz ciexyz = new CieXyz(13.337f, 9.297f, 14.727f); - Color color = ciexyz; + Rgba32 color = ciexyz; Assert.Equal(128, color.R); Assert.Equal(64, color.G); @@ -142,7 +143,7 @@ namespace ImageSharp.Tests // Ochre CieXyz ciexyz2 = new CieXyz(31.787f, 26.147f, 4.885f); - Color color2 = ciexyz2; + Rgba32 color2 = ciexyz2; Assert.Equal(204, color2.R); Assert.Equal(119, color2.G); @@ -150,7 +151,7 @@ namespace ImageSharp.Tests // Black CieXyz ciexyz3 = new CieXyz(0, 0, 0); - Color color3 = ciexyz3; + Rgba32 color3 = ciexyz3; Assert.Equal(0, color3.R); Assert.Equal(0, color3.G); @@ -167,7 +168,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -175,7 +176,7 @@ namespace ImageSharp.Tests public void ColorToHsv() { // Black - Color b = Color.Black; + Rgba32 b = Rgba32.Black; Hsv h = b; Assert.Equal(0, h.H, 1); @@ -183,7 +184,7 @@ namespace ImageSharp.Tests Assert.Equal(0, h.V, 1); // White - Color color = Color.White; + Rgba32 color = Rgba32.White; Hsv hsv = color; Assert.Equal(0f, hsv.H, 1); @@ -191,7 +192,7 @@ namespace ImageSharp.Tests Assert.Equal(1f, hsv.V, 1); // Dark moderate pink. - Color color2 = new Color(128, 64, 106); + Rgba32 color2 = new Rgba32(128, 64, 106); Hsv hsv2 = color2; Assert.Equal(320.6f, hsv2.H, 1); @@ -199,7 +200,7 @@ namespace ImageSharp.Tests Assert.Equal(0.502f, hsv2.V, 2); // Ochre. - Color color3 = new Color(204, 119, 34); + Rgba32 color3 = new Rgba32(204, 119, 34); Hsv hsv3 = color3; Assert.Equal(30f, hsv3.H, 1); @@ -208,14 +209,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void HsvToColor() { // Dark moderate pink. Hsv hsv = new Hsv(320.6f, 0.5f, 0.502f); - Color color = hsv; + Rgba32 color = hsv; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -223,7 +224,7 @@ namespace ImageSharp.Tests // Ochre Hsv hsv2 = new Hsv(30, 0.833f, 0.8f); - Color color2 = hsv2; + Rgba32 color2 = hsv2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -231,7 +232,7 @@ namespace ImageSharp.Tests // White Hsv hsv3 = new Hsv(0, 0, 1); - Color color3 = hsv3; + Rgba32 color3 = hsv3; Assert.Equal(color3.B, 255); Assert.Equal(color3.G, 255); @@ -248,7 +249,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -256,7 +257,7 @@ namespace ImageSharp.Tests public void ColorToHsl() { // Black - Color b = Color.Black; + Rgba32 b = Rgba32.Black; Hsl h = b; Assert.Equal(0, h.H, 1); @@ -264,7 +265,7 @@ namespace ImageSharp.Tests Assert.Equal(0, h.L, 1); // White - Color color = Color.White; + Rgba32 color = Rgba32.White; Hsl hsl = color; Assert.Equal(0f, hsl.H, 1); @@ -272,7 +273,7 @@ namespace ImageSharp.Tests Assert.Equal(1f, hsl.L, 1); // Dark moderate pink. - Color color2 = new Color(128, 64, 106); + Rgba32 color2 = new Rgba32(128, 64, 106); Hsl hsl2 = color2; Assert.Equal(320.6f, hsl2.H, 1); @@ -280,7 +281,7 @@ namespace ImageSharp.Tests Assert.Equal(0.376f, hsl2.L, 2); // Ochre. - Color color3 = new Color(204, 119, 34); + Rgba32 color3 = new Rgba32(204, 119, 34); Hsl hsl3 = color3; Assert.Equal(30f, hsl3.H, 1); @@ -289,14 +290,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void HslToColor() { // Dark moderate pink. Hsl hsl = new Hsl(320.6f, 0.33f, 0.376f); - Color color = hsl; + Rgba32 color = hsl; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -304,7 +305,7 @@ namespace ImageSharp.Tests // Ochre Hsl hsl2 = new Hsl(30, 0.714f, 0.467f); - Color color2 = hsl2; + Rgba32 color2 = hsl2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -312,7 +313,7 @@ namespace ImageSharp.Tests // White Hsl hsl3 = new Hsl(0, 0, 1); - Color color3 = hsl3; + Rgba32 color3 = hsl3; Assert.Equal(color3.R, 255); Assert.Equal(color3.G, 255); @@ -329,7 +330,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", @@ -337,7 +338,7 @@ namespace ImageSharp.Tests public void ColorToCmyk() { // White - Color color = Color.White; + Rgba32 color = Rgba32.White; Cmyk cmyk = color; Assert.Equal(0, cmyk.C, 1); @@ -346,7 +347,7 @@ namespace ImageSharp.Tests Assert.Equal(0, cmyk.K, 1); // Black - Color color2 = Color.Black; + Rgba32 color2 = Rgba32.Black; Cmyk cmyk2 = color2; Assert.Equal(0, cmyk2.C, 1); Assert.Equal(0, cmyk2.M, 1); @@ -354,7 +355,7 @@ namespace ImageSharp.Tests Assert.Equal(1, cmyk2.K, 1); // Gray - Color color3 = Color.Gray; + Rgba32 color3 = Rgba32.Gray; Cmyk cmyk3 = color3; Assert.Equal(0f, cmyk3.C, 1); Assert.Equal(0f, cmyk3.M, 1); @@ -362,7 +363,7 @@ namespace ImageSharp.Tests Assert.Equal(0.498, cmyk3.K, 2); // Checked with other online converters. // Cyan - Color color4 = Color.Cyan; + Rgba32 color4 = Rgba32.Cyan; Cmyk cmyk4 = color4; Assert.Equal(1, cmyk4.C, 1); Assert.Equal(0f, cmyk4.M, 1); @@ -371,14 +372,14 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// [Fact] public void CmykToColor() { // Dark moderate pink. Cmyk cmyk = new Cmyk(0f, .5f, .171f, .498f); - Color color = cmyk; + Rgba32 color = cmyk; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -386,7 +387,7 @@ namespace ImageSharp.Tests // Ochre Cmyk cmyk2 = new Cmyk(0, .416f, .833f, .199f); - Color color2 = cmyk2; + Rgba32 color2 = cmyk2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -394,7 +395,7 @@ namespace ImageSharp.Tests // White Cmyk cmyk3 = new Cmyk(0, 0, 0, 0); - Color color3 = cmyk3; + Rgba32 color3 = cmyk3; Assert.Equal(color3.R, 255); Assert.Equal(color3.G, 255); @@ -411,7 +412,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-lab /// @@ -419,7 +420,7 @@ namespace ImageSharp.Tests public void ColorToCieLab() { // White - Color color = Color.White; + Rgba32 color = Rgba32.White; CieLab cielab = color; Assert.Equal(100, cielab.L, 3); @@ -427,21 +428,21 @@ namespace ImageSharp.Tests Assert.Equal(-0.010, cielab.B, 3); // Black - Color color2 = Color.Black; + Rgba32 color2 = Rgba32.Black; CieLab cielab2 = color2; Assert.Equal(0, cielab2.L, 3); Assert.Equal(0, cielab2.A, 3); Assert.Equal(0, cielab2.B, 3); // Gray - Color color3 = Color.Gray; + Rgba32 color3 = Rgba32.Gray; CieLab cielab3 = color3; Assert.Equal(53.585, cielab3.L, 3); Assert.Equal(0.003, cielab3.A, 3); Assert.Equal(-0.006, cielab3.B, 3); // Cyan - Color color4 = Color.Cyan; + Rgba32 color4 = Rgba32.Cyan; CieLab cielab4 = color4; Assert.Equal(91.117, cielab4.L, 3); Assert.Equal(-48.080, cielab4.A, 3); @@ -449,7 +450,7 @@ namespace ImageSharp.Tests } /// - /// Tests the implicit conversion from to . + /// Tests the implicit conversion from to . /// /// Comparison values obtained from /// http://colormine.org/convert/rgb-to-lab @@ -458,7 +459,7 @@ namespace ImageSharp.Tests { // Dark moderate pink. CieLab cielab = new CieLab(36.5492f, 33.3173f, -12.0615f); - Color color = cielab; + Rgba32 color = cielab; Assert.Equal(color.R, 128); Assert.Equal(color.G, 64); @@ -466,7 +467,7 @@ namespace ImageSharp.Tests // Ochre CieLab cielab2 = new CieLab(58.1758f, 27.3399f, 56.8240f); - Color color2 = cielab2; + Rgba32 color2 = cielab2; Assert.Equal(color2.R, 204); Assert.Equal(color2.G, 119); @@ -474,7 +475,7 @@ namespace ImageSharp.Tests // Black CieLab cielab3 = new CieLab(0, 0, 0); - Color color3 = cielab3; + Rgba32 color3 = cielab3; Assert.Equal(color3.R, 0); Assert.Equal(color3.G, 0); diff --git a/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs b/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs index 899ce4f77a..f2113852f3 100644 --- a/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorDefinitionTests.cs @@ -12,17 +12,19 @@ namespace ImageSharp.Tests using System.Reflection; using ImageSharp.Colors.Spaces; + using ImageSharp.PixelFormats; + using Xunit; public class ColorDefinitionTests { - public static IEnumerable ColorNames => typeof(NamedColors).GetTypeInfo().GetFields().Select(x => new[] { x.Name }); + public static IEnumerable ColorNames => typeof(NamedColors).GetTypeInfo().GetFields().Select(x => new[] { x.Name }); [Theory] [MemberData(nameof(ColorNames))] public void AllColorsAreOnGenericAndBaseColor(string name) { - FieldInfo generic = typeof(NamedColors).GetTypeInfo().GetField(name); - FieldInfo specific = typeof(Color).GetTypeInfo().GetField(name); + FieldInfo generic = typeof(NamedColors).GetTypeInfo().GetField(name); + FieldInfo specific = typeof(Rgba32).GetTypeInfo().GetField(name); Assert.NotNull(specific); Assert.NotNull(generic); @@ -30,8 +32,8 @@ namespace ImageSharp.Tests Assert.True(specific.Attributes.HasFlag(FieldAttributes.Static), "specific must be static"); Assert.True(generic.Attributes.HasFlag(FieldAttributes.Public), "generic must be public"); Assert.True(generic.Attributes.HasFlag(FieldAttributes.Static), "generic must be static"); - Color expected = (Color)generic.GetValue(null); - Color actual = (Color)specific.GetValue(null); + Rgba32 expected = (Rgba32)generic.GetValue(null); + Rgba32 actual = (Rgba32)specific.GetValue(null); Assert.Equal(expected, actual); } } diff --git a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs b/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs index ffb04e8b24..efec4ea38c 100644 --- a/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Tests.Colors using System; using System.Numerics; using ImageSharp.Colors.Spaces; + using ImageSharp.PixelFormats; + using Xunit; /// @@ -33,7 +35,7 @@ namespace ImageSharp.Tests.Colors { new NormalizedShort4(Vector4.One), new NormalizedShort4(Vector4.One), typeof(NormalizedShort4) }, { new Rg32(Vector2.One), new Rg32(Vector2.One), typeof(Rg32) }, { new Rgba1010102(Vector4.One), new Rgba1010102(Vector4.One), typeof(Rgba1010102) }, - { new Color(Vector4.One), new Color(Vector4.One), typeof(Color) }, + { new Rgba32(Vector4.One), new Rgba32(Vector4.One), typeof(Rgba32) }, { new Rgba64(Vector4.One), new Rgba64(Vector4.One), typeof(Rgba64) }, { new Short2(Vector2.One * 0x7FFF), new Short2(Vector2.One * 0x7FFF), typeof(Short2) }, { new Short4(Vector4.One * 0x7FFF), new Short4(Vector4.One * 0x7FFF), typeof(Short4) }, @@ -145,7 +147,7 @@ namespace ImageSharp.Tests.Colors { new NormalizedShort4(Vector4.One), new NormalizedShort4(Vector4.Zero), typeof(NormalizedShort4) }, { new Rg32(Vector2.One), new Rg32(Vector2.Zero), typeof(Rg32) }, { new Rgba1010102(Vector4.One), new Rgba1010102(Vector4.Zero), typeof(Rgba1010102) }, - { new Color(Vector4.One), new Color(Vector4.Zero), typeof(Color) }, + { new Rgba32(Vector4.One), new Rgba32(Vector4.Zero), typeof(Rgba32) }, { new Rgba64(Vector4.One), new Rgba64(Vector4.Zero), typeof(Rgba64) }, { new Short2(Vector2.One * 0x7FFF), new Short2(Vector2.Zero), typeof(Short2) }, { new Short4(Vector4.One * 0x7FFF), new Short4(Vector4.Zero), typeof(Short4) }, diff --git a/tests/ImageSharp.Tests/Colors/ColorPackingTests.cs b/tests/ImageSharp.Tests/Colors/ColorPackingTests.cs index 5fbb42b2a3..563b6be3c4 100644 --- a/tests/ImageSharp.Tests/Colors/ColorPackingTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorPackingTests.cs @@ -7,6 +7,9 @@ namespace ImageSharp.Tests.Colors { using System.Collections.Generic; using System.Numerics; + + using ImageSharp.PixelFormats; + using Xunit; public class ColorPackingTests diff --git a/tests/ImageSharp.Tests/Colors/ColorTests.cs b/tests/ImageSharp.Tests/Colors/ColorTests.cs index e2c62b5079..da63025c43 100644 --- a/tests/ImageSharp.Tests/Colors/ColorTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorTests.cs @@ -8,10 +8,12 @@ namespace ImageSharp.Tests using System; using System.Numerics; + using ImageSharp.PixelFormats; + using Xunit; /// - /// Tests the struct. + /// Tests the struct. /// public class ColorTests { @@ -21,12 +23,12 @@ namespace ImageSharp.Tests [Fact] public void AreEqual() { - Color color1 = new Color(0, 0, 0); - Color color2 = new Color(0, 0, 0, 1F); - Color color3 = Color.FromHex("#000"); - Color color4 = Color.FromHex("#000F"); - Color color5 = Color.FromHex("#000000"); - Color color6 = Color.FromHex("#000000FF"); + Rgba32 color1 = new Rgba32(0, 0, 0); + Rgba32 color2 = new Rgba32(0, 0, 0, 1F); + Rgba32 color3 = Rgba32.FromHex("#000"); + Rgba32 color4 = Rgba32.FromHex("#000F"); + Rgba32 color5 = Rgba32.FromHex("#000000"); + Rgba32 color6 = Rgba32.FromHex("#000000FF"); Assert.Equal(color1, color2); Assert.Equal(color1, color3); @@ -41,11 +43,11 @@ namespace ImageSharp.Tests [Fact] public void AreNotEqual() { - Color color1 = new Color(255, 0, 0, 255); - Color color2 = new Color(0, 0, 0, 255); - Color color3 = Color.FromHex("#000"); - Color color4 = Color.FromHex("#000000"); - Color color5 = Color.FromHex("#FF000000"); + Rgba32 color1 = new Rgba32(255, 0, 0, 255); + Rgba32 color2 = new Rgba32(0, 0, 0, 255); + Rgba32 color3 = Rgba32.FromHex("#000"); + Rgba32 color4 = Rgba32.FromHex("#000000"); + Rgba32 color5 = Rgba32.FromHex("#FF000000"); Assert.NotEqual(color1, color2); Assert.NotEqual(color1, color3); @@ -59,25 +61,25 @@ namespace ImageSharp.Tests [Fact] public void ConstructorAssignsProperties() { - Color color1 = new Color(1, .1f, .133f, .864f); + Rgba32 color1 = new Rgba32(1, .1f, .133f, .864f); Assert.Equal(255, color1.R); Assert.Equal((byte)Math.Round(.1f * 255), color1.G); Assert.Equal((byte)Math.Round(.133f * 255), color1.B); Assert.Equal((byte)Math.Round(.864f * 255), color1.A); - Color color2 = new Color(1, .1f, .133f); + Rgba32 color2 = new Rgba32(1, .1f, .133f); Assert.Equal(255, color2.R); Assert.Equal(Math.Round(.1f * 255), color2.G); Assert.Equal(Math.Round(.133f * 255), color2.B); Assert.Equal(255, color2.A); - Color color4 = new Color(new Vector3(1, .1f, .133f)); + Rgba32 color4 = new Rgba32(new Vector3(1, .1f, .133f)); Assert.Equal(255, color4.R); Assert.Equal(Math.Round(.1f * 255), color4.G); Assert.Equal(Math.Round(.133f * 255), color4.B); Assert.Equal(255, color4.A); - Color color5 = new Color(new Vector4(1, .1f, .133f, .5f)); + Rgba32 color5 = new Rgba32(new Vector4(1, .1f, .133f, .5f)); Assert.Equal(255, color5.R); Assert.Equal(Math.Round(.1f * 255), color5.G); Assert.Equal(Math.Round(.133f * 255), color5.B); @@ -90,7 +92,7 @@ namespace ImageSharp.Tests [Fact] public void FromAndToHex() { - Color color = Color.FromHex("#AABBCCDD"); + Rgba32 color = Rgba32.FromHex("#AABBCCDD"); Assert.Equal(170, color.R); Assert.Equal(187, color.G); Assert.Equal(204, color.B); @@ -118,14 +120,14 @@ namespace ImageSharp.Tests [Fact] public unsafe void ByteLayout() { - Color color = new Color(1, 2, 3, 4); + Rgba32 color = new Rgba32(1, 2, 3, 4); byte* colorBase = (byte*)&color; Assert.Equal(1, colorBase[0]); Assert.Equal(2, colorBase[1]); Assert.Equal(3, colorBase[2]); Assert.Equal(4, colorBase[3]); - Assert.Equal(4, sizeof(Color)); + Assert.Equal(4, sizeof(Rgba32)); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs b/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs index 064bdf2d02..8d5e973b13 100644 --- a/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorTransformTests.cs @@ -5,6 +5,8 @@ namespace ImageSharp.Tests.Colors { + using ImageSharp.PixelFormats; + using Xunit; /// @@ -16,101 +18,101 @@ namespace ImageSharp.Tests.Colors /// /// Orange backdrop /// - private static readonly Color Backdrop = new Color(204, 102, 0); + private static readonly Rgba32 Backdrop = new Rgba32(204, 102, 0); /// /// Blue source /// - private static readonly Color Source = new Color(0, 102, 153); + private static readonly Rgba32 Source = new Rgba32(0, 102, 153); [Fact] public void Normal() { - Color normal = Color.Normal(Backdrop, Source); + Rgba32 normal = Rgba32.Normal(Backdrop, Source); Assert.True(normal == Source); } [Fact] public void Multiply() { - Assert.True(Color.Multiply(Backdrop, Color.Black) == Color.Black); - Assert.True(Color.Multiply(Backdrop, Color.White) == Backdrop); + Assert.True(Rgba32.Multiply(Backdrop, Rgba32.Black) == Rgba32.Black); + Assert.True(Rgba32.Multiply(Backdrop, Rgba32.White) == Backdrop); - Color multiply = Color.Multiply(Backdrop, Source); - Assert.True(multiply == new Color(0, 41, 0)); + Rgba32 multiply = Rgba32.Multiply(Backdrop, Source); + Assert.True(multiply == new Rgba32(0, 41, 0)); } [Fact] public void Screen() { - Assert.True(Color.Screen(Backdrop, Color.Black) == Backdrop); - Assert.True(Color.Screen(Backdrop, Color.White) == Color.White); + Assert.True(Rgba32.Screen(Backdrop, Rgba32.Black) == Backdrop); + Assert.True(Rgba32.Screen(Backdrop, Rgba32.White) == Rgba32.White); - Color screen = Color.Screen(Backdrop, Source); - Assert.True(screen == new Color(204, 163, 153)); + Rgba32 screen = Rgba32.Screen(Backdrop, Source); + Assert.True(screen == new Rgba32(204, 163, 153)); } [Fact] public void HardLight() { - Color hardLight = Color.HardLight(Backdrop, Source); - Assert.True(hardLight == new Color(0, 82, 51)); + Rgba32 hardLight = Rgba32.HardLight(Backdrop, Source); + Assert.True(hardLight == new Rgba32(0, 82, 51)); } [Fact] public void Overlay() { - Color overlay = Color.Overlay(Backdrop, Source); - Assert.True(overlay == new Color(153, 82, 0)); + Rgba32 overlay = Rgba32.Overlay(Backdrop, Source); + Assert.True(overlay == new Rgba32(153, 82, 0)); } [Fact] public void Darken() { - Color darken = Color.Darken(Backdrop, Source); - Assert.True(darken == new Color(0, 102, 0)); + Rgba32 darken = Rgba32.Darken(Backdrop, Source); + Assert.True(darken == new Rgba32(0, 102, 0)); } [Fact] public void Lighten() { - Color lighten = Color.Lighten(Backdrop, Source); - Assert.True(lighten == new Color(204, 102, 153)); + Rgba32 lighten = Rgba32.Lighten(Backdrop, Source); + Assert.True(lighten == new Rgba32(204, 102, 153)); } [Fact] public void SoftLight() { - Color softLight = Color.SoftLight(Backdrop, Source); - Assert.True(softLight == new Color(163, 90, 0)); + Rgba32 softLight = Rgba32.SoftLight(Backdrop, Source); + Assert.True(softLight == new Rgba32(163, 90, 0)); } [Fact] public void ColorDodge() { - Color colorDodge = Color.ColorDodge(Backdrop, Source); - Assert.True(colorDodge == new Color(204, 170, 0)); + Rgba32 colorDodge = Rgba32.ColorDodge(Backdrop, Source); + Assert.True(colorDodge == new Rgba32(204, 170, 0)); } [Fact] public void ColorBurn() { - Color colorBurn = Color.ColorBurn(Backdrop, Source); - Assert.True(colorBurn == new Color(0, 0, 0)); + Rgba32 colorBurn = Rgba32.ColorBurn(Backdrop, Source); + Assert.True(colorBurn == new Rgba32(0, 0, 0)); } [Fact] public void Difference() { - Color difference = Color.Difference(Backdrop, Source); - Assert.True(difference == new Color(204, 0, 153)); + Rgba32 difference = Rgba32.Difference(Backdrop, Source); + Assert.True(difference == new Rgba32(204, 0, 153)); } [Fact] public void Exclusion() { - Color exclusion = Color.Exclusion(Backdrop, Source); - Assert.True(exclusion == new Color(204, 122, 153)); + Rgba32 exclusion = Rgba32.Exclusion(Backdrop, Source); + Assert.True(exclusion == new Rgba32(204, 122, 153)); } } } diff --git a/tests/ImageSharp.Tests/Colors/ColorVectorTests.cs b/tests/ImageSharp.Tests/Colors/ColorVectorTests.cs index 4300b1b387..492817015a 100644 --- a/tests/ImageSharp.Tests/Colors/ColorVectorTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorVectorTests.cs @@ -8,10 +8,12 @@ namespace ImageSharp.Tests using System.Numerics; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; + using Xunit; /// - /// Tests the struct. + /// Tests the struct. /// public class ColorVectorTests { @@ -21,12 +23,12 @@ namespace ImageSharp.Tests [Fact] public void AreEqual() { - ColorVector color1 = new ColorVector(0, 0, 0F); - ColorVector color2 = new ColorVector(0, 0, 0, 1F); - ColorVector color3 = ColorVector.FromHex("#000"); - ColorVector color4 = ColorVector.FromHex("#000F"); - ColorVector color5 = ColorVector.FromHex("#000000"); - ColorVector color6 = ColorVector.FromHex("#000000FF"); + RgbaVector color1 = new RgbaVector(0, 0, 0F); + RgbaVector color2 = new RgbaVector(0, 0, 0, 1F); + RgbaVector color3 = RgbaVector.FromHex("#000"); + RgbaVector color4 = RgbaVector.FromHex("#000F"); + RgbaVector color5 = RgbaVector.FromHex("#000000"); + RgbaVector color6 = RgbaVector.FromHex("#000000FF"); Assert.Equal(color1, color2); Assert.Equal(color1, color3); @@ -41,11 +43,11 @@ namespace ImageSharp.Tests [Fact] public void AreNotEqual() { - ColorVector color1 = new ColorVector(1, 0, 0, 1); - ColorVector color2 = new ColorVector(0, 0, 0, 1); - ColorVector color3 = ColorVector.FromHex("#000"); - ColorVector color4 = ColorVector.FromHex("#000000"); - ColorVector color5 = ColorVector.FromHex("#FF000000"); + RgbaVector color1 = new RgbaVector(1, 0, 0, 1); + RgbaVector color2 = new RgbaVector(0, 0, 0, 1); + RgbaVector color3 = RgbaVector.FromHex("#000"); + RgbaVector color4 = RgbaVector.FromHex("#000000"); + RgbaVector color5 = RgbaVector.FromHex("#FF000000"); Assert.NotEqual(color1, color2); Assert.NotEqual(color1, color3); @@ -59,25 +61,25 @@ namespace ImageSharp.Tests [Fact] public void ConstructorAssignsProperties() { - ColorVector color1 = new ColorVector(1, .1F, .133F, .864F); + RgbaVector color1 = new RgbaVector(1, .1F, .133F, .864F); Assert.Equal(1F, color1.R); Assert.Equal(.1F, color1.G); Assert.Equal(.133F, color1.B); Assert.Equal(.864F, color1.A); - ColorVector color2 = new ColorVector(1, .1f, .133f); + RgbaVector color2 = new RgbaVector(1, .1f, .133f); Assert.Equal(1F, color2.R); Assert.Equal(.1F, color2.G); Assert.Equal(.133F, color2.B); Assert.Equal(1F, color2.A); - ColorVector color4 = new ColorVector(new Vector3(1, .1f, .133f)); + RgbaVector color4 = new RgbaVector(new Vector3(1, .1f, .133f)); Assert.Equal(1F, color4.R); Assert.Equal(.1F, color4.G); Assert.Equal(.133F, color4.B); Assert.Equal(1F, color4.A); - ColorVector color5 = new ColorVector(new Vector4(1, .1f, .133f, .5f)); + RgbaVector color5 = new RgbaVector(new Vector4(1, .1f, .133f, .5f)); Assert.Equal(1F, color5.R); Assert.Equal(.1F, color5.G); Assert.Equal(.133F, color5.B); @@ -90,7 +92,7 @@ namespace ImageSharp.Tests [Fact] public void FromAndToHex() { - ColorVector color = ColorVector.FromHex("#AABBCCDD"); + RgbaVector color = RgbaVector.FromHex("#AABBCCDD"); Assert.Equal(170 / 255F, color.R); Assert.Equal(187 / 255F, color.G); Assert.Equal(204 / 255F, color.B); @@ -118,8 +120,8 @@ namespace ImageSharp.Tests [Fact] public void FloatLayout() { - ColorVector color = new ColorVector(1F, 2, 3, 4); - Vector4 colorBase = Unsafe.As(ref Unsafe.Add(ref color, 0)); + RgbaVector color = new RgbaVector(1F, 2, 3, 4); + Vector4 colorBase = Unsafe.As(ref Unsafe.Add(ref color, 0)); float[] ordered = new float[4]; colorBase.CopyTo(ordered); diff --git a/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs b/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs index c2e27d2317..e670944f56 100644 --- a/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs +++ b/tests/ImageSharp.Tests/Colors/ColorVectorTransformTests.cs @@ -5,6 +5,7 @@ namespace ImageSharp.Tests.Colors { + using ImageSharp.PixelFormats; using Xunit; /// @@ -18,101 +19,101 @@ namespace ImageSharp.Tests.Colors /// /// Orange backdrop /// - private static readonly ColorVector Backdrop = new ColorVector(204, 102, 0); + private static readonly RgbaVector Backdrop = new RgbaVector(204, 102, 0); /// /// Blue source /// - private static readonly ColorVector Source = new ColorVector(0, 102, 153); + private static readonly RgbaVector Source = new RgbaVector(0, 102, 153); [Fact] public void Normal() { - ColorVector normal = ColorVector.Normal(Backdrop, Source); + RgbaVector normal = RgbaVector.Normal(Backdrop, Source); Assert.True(normal == Source); } [Fact] public void Multiply() { - Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.Black).ToVector4(), Color.Black.ToVector4(), FloatComparer); - Assert.Equal(ColorVector.Multiply(Backdrop, ColorVector.White).ToVector4(), Backdrop.ToVector4(), FloatComparer); + Assert.Equal(RgbaVector.Multiply(Backdrop, RgbaVector.Black).ToVector4(), Rgba32.Black.ToVector4(), FloatComparer); + Assert.Equal(RgbaVector.Multiply(Backdrop, RgbaVector.White).ToVector4(), Backdrop.ToVector4(), FloatComparer); - ColorVector multiply = ColorVector.Multiply(Backdrop, Source); - Assert.Equal(multiply.ToVector4(), new ColorVector(0, 41, 0).ToVector4(), FloatComparer); + RgbaVector multiply = RgbaVector.Multiply(Backdrop, Source); + Assert.Equal(multiply.ToVector4(), new RgbaVector(0, 41, 0).ToVector4(), FloatComparer); } [Fact] public void Screen() { - Assert.Equal(ColorVector.Screen(Backdrop, ColorVector.Black).ToVector4(), Backdrop.ToVector4(), FloatComparer); - Assert.Equal(ColorVector.Screen(Backdrop, ColorVector.White).ToVector4(), ColorVector.White.ToVector4(), FloatComparer); + Assert.Equal(RgbaVector.Screen(Backdrop, RgbaVector.Black).ToVector4(), Backdrop.ToVector4(), FloatComparer); + Assert.Equal(RgbaVector.Screen(Backdrop, RgbaVector.White).ToVector4(), RgbaVector.White.ToVector4(), FloatComparer); - ColorVector screen = ColorVector.Screen(Backdrop, Source); - Assert.Equal(screen.ToVector4(), new ColorVector(204, 163, 153).ToVector4(), FloatComparer); + RgbaVector screen = RgbaVector.Screen(Backdrop, Source); + Assert.Equal(screen.ToVector4(), new RgbaVector(204, 163, 153).ToVector4(), FloatComparer); } [Fact] public void HardLight() { - ColorVector hardLight = ColorVector.HardLight(Backdrop, Source); - Assert.Equal(hardLight.ToVector4(), new ColorVector(0, 82, 51).ToVector4(), FloatComparer); + RgbaVector hardLight = RgbaVector.HardLight(Backdrop, Source); + Assert.Equal(hardLight.ToVector4(), new RgbaVector(0, 82, 51).ToVector4(), FloatComparer); } [Fact] public void Overlay() { - ColorVector overlay = ColorVector.Overlay(Backdrop, Source); - Assert.Equal(overlay.ToVector4(), new ColorVector(153, 82, 0).ToVector4(), FloatComparer); + RgbaVector overlay = RgbaVector.Overlay(Backdrop, Source); + Assert.Equal(overlay.ToVector4(), new RgbaVector(153, 82, 0).ToVector4(), FloatComparer); } [Fact] public void Darken() { - ColorVector darken = ColorVector.Darken(Backdrop, Source); - Assert.Equal(darken.ToVector4(), new ColorVector(0, 102, 0).ToVector4(), FloatComparer); + RgbaVector darken = RgbaVector.Darken(Backdrop, Source); + Assert.Equal(darken.ToVector4(), new RgbaVector(0, 102, 0).ToVector4(), FloatComparer); } [Fact] public void Lighten() { - ColorVector lighten = ColorVector.Lighten(Backdrop, Source); - Assert.Equal(lighten.ToVector4(), new ColorVector(204, 102, 153).ToVector4(), FloatComparer); + RgbaVector lighten = RgbaVector.Lighten(Backdrop, Source); + Assert.Equal(lighten.ToVector4(), new RgbaVector(204, 102, 153).ToVector4(), FloatComparer); } [Fact] public void SoftLight() { - ColorVector softLight = ColorVector.SoftLight(Backdrop, Source); - Assert.Equal(softLight.ToVector4(), new ColorVector(163, 90, 0).ToVector4(), FloatComparer); + RgbaVector softLight = RgbaVector.SoftLight(Backdrop, Source); + Assert.Equal(softLight.ToVector4(), new RgbaVector(163, 90, 0).ToVector4(), FloatComparer); } [Fact] public void ColorDodge() { - ColorVector colorDodge = ColorVector.ColorDodge(Backdrop, Source); - Assert.Equal(colorDodge.ToVector4(), new ColorVector(204, 170, 0).ToVector4(), FloatComparer); + RgbaVector colorDodge = RgbaVector.ColorDodge(Backdrop, Source); + Assert.Equal(colorDodge.ToVector4(), new RgbaVector(204, 170, 0).ToVector4(), FloatComparer); } [Fact] public void ColorBurn() { - ColorVector colorBurn = ColorVector.ColorBurn(Backdrop, Source); - Assert.Equal(colorBurn.ToVector4(), new ColorVector(0, 0, 0).ToVector4(), FloatComparer); + RgbaVector colorBurn = RgbaVector.ColorBurn(Backdrop, Source); + Assert.Equal(colorBurn.ToVector4(), new RgbaVector(0, 0, 0).ToVector4(), FloatComparer); } [Fact] public void Difference() { - ColorVector difference = ColorVector.Difference(Backdrop, Source); - Assert.Equal(difference.ToVector4(), new ColorVector(204, 0, 153).ToVector4(), FloatComparer); + RgbaVector difference = RgbaVector.Difference(Backdrop, Source); + Assert.Equal(difference.ToVector4(), new RgbaVector(204, 0, 153).ToVector4(), FloatComparer); } [Fact] public void Exclusion() { - ColorVector exclusion = ColorVector.Exclusion(Backdrop, Source); - Assert.Equal(exclusion.ToVector4(), new ColorVector(204, 122, 153).ToVector4(), FloatComparer); + RgbaVector exclusion = RgbaVector.Exclusion(Backdrop, Source); + Assert.Equal(exclusion.ToVector4(), new RgbaVector(204, 122, 153).ToVector4(), FloatComparer); } } } diff --git a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs b/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs index 52ca86cae6..5ec7c21bbf 100644 --- a/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs +++ b/tests/ImageSharp.Tests/Colors/PackedPixelTests.cs @@ -9,6 +9,8 @@ namespace ImageSharp.Tests.Colors using System.Diagnostics; using System.Numerics; + using ImageSharp.PixelFormats; + using Xunit; /// @@ -715,26 +717,26 @@ namespace ImageSharp.Tests.Colors public void Color() { // Test the limits. - Assert.Equal((uint)0x0, new Color(Vector4.Zero).PackedValue); - Assert.Equal(0xFFFFFFFF, new Color(Vector4.One).PackedValue); + Assert.Equal((uint)0x0, new Rgba32(Vector4.Zero).PackedValue); + Assert.Equal(0xFFFFFFFF, new Rgba32(Vector4.One).PackedValue); // Test ToVector4. - Assert.True(Equal(Vector4.One, new Color(Vector4.One).ToVector4())); - Assert.True(Equal(Vector4.Zero, new Color(Vector4.Zero).ToVector4())); - Assert.True(Equal(Vector4.UnitX, new Color(Vector4.UnitX).ToVector4())); - Assert.True(Equal(Vector4.UnitY, new Color(Vector4.UnitY).ToVector4())); - Assert.True(Equal(Vector4.UnitZ, new Color(Vector4.UnitZ).ToVector4())); - Assert.True(Equal(Vector4.UnitW, new Color(Vector4.UnitW).ToVector4())); + Assert.True(Equal(Vector4.One, new Rgba32(Vector4.One).ToVector4())); + Assert.True(Equal(Vector4.Zero, new Rgba32(Vector4.Zero).ToVector4())); + Assert.True(Equal(Vector4.UnitX, new Rgba32(Vector4.UnitX).ToVector4())); + Assert.True(Equal(Vector4.UnitY, new Rgba32(Vector4.UnitY).ToVector4())); + Assert.True(Equal(Vector4.UnitZ, new Rgba32(Vector4.UnitZ).ToVector4())); + Assert.True(Equal(Vector4.UnitW, new Rgba32(Vector4.UnitW).ToVector4())); // Test clamping. - Assert.True(Equal(Vector4.Zero, new Color(Vector4.One * -1234.0f).ToVector4())); - Assert.True(Equal(Vector4.One, new Color(Vector4.One * +1234.0f).ToVector4())); + Assert.True(Equal(Vector4.Zero, new Rgba32(Vector4.One * -1234.0f).ToVector4())); + Assert.True(Equal(Vector4.One, new Rgba32(Vector4.One * +1234.0f).ToVector4())); float x = +0.1f; float y = -0.3f; float z = +0.5f; float w = -0.7f; - Color rgba32 = new Color(x, y, z, w); + Rgba32 rgba32 = new Rgba32(x, y, z, w); Assert.Equal(0x80001Au, rgba32.PackedValue); // Test ordering diff --git a/tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs b/tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs index 4fb189ca81..25a61453b2 100644 --- a/tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs +++ b/tests/ImageSharp.Tests/Colors/UnPackedPixelTests.cs @@ -2,6 +2,8 @@ { using System.Numerics; + using ImageSharp.PixelFormats; + using Xunit; public class UnPackedPixelTests @@ -9,8 +11,8 @@ [Fact] public void Color_Types_From_Bytes_Produce_Equal_Scaled_Component_OutPut() { - Color color = new Color(24, 48, 96, 192); - ColorVector colorVector = new ColorVector(24, 48, 96, 192); + Rgba32 color = new Rgba32(24, 48, 96, 192); + RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255)); @@ -21,8 +23,8 @@ [Fact] public void Color_Types_From_Floats_Produce_Equal_Scaled_Component_OutPut() { - Color color = new Color(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); - ColorVector colorVector = new ColorVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); + Rgba32 color = new Rgba32(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); + RgbaVector colorVector = new RgbaVector(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F); Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255)); @@ -33,8 +35,8 @@ [Fact] public void Color_Types_From_Vector4_Produce_Equal_Scaled_Component_OutPut() { - Color color = new Color(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); - ColorVector colorVector = new ColorVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); + Rgba32 color = new Rgba32(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); + RgbaVector colorVector = new RgbaVector(new Vector4(24 / 255F, 48 / 255F, 96 / 255F, 192 / 255F)); Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255)); @@ -45,8 +47,8 @@ [Fact] public void Color_Types_From_Vector3_Produce_Equal_Scaled_Component_OutPut() { - Color color = new Color(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); - ColorVector colorVector = new ColorVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); + Rgba32 color = new Rgba32(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); + RgbaVector colorVector = new RgbaVector(new Vector3(24 / 255F, 48 / 255F, 96 / 255F)); Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255)); @@ -57,8 +59,8 @@ [Fact] public void Color_Types_From_Hex_Produce_Equal_Scaled_Component_OutPut() { - Color color = Color.FromHex("183060C0"); - ColorVector colorVector = ColorVector.FromHex("183060C0"); + Rgba32 color = Rgba32.FromHex("183060C0"); + RgbaVector colorVector = RgbaVector.FromHex("183060C0"); Assert.Equal(color.R, (byte)(colorVector.R * 255)); Assert.Equal(color.G, (byte)(colorVector.G * 255)); @@ -69,8 +71,8 @@ [Fact] public void Color_Types_To_Vector4_Produce_Equal_OutPut() { - Color color = new Color(24, 48, 96, 192); - ColorVector colorVector = new ColorVector(24, 48, 96, 192); + Rgba32 color = new Rgba32(24, 48, 96, 192); + RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); Assert.Equal(color.ToVector4(), colorVector.ToVector4()); } @@ -78,8 +80,8 @@ [Fact] public void Color_Types_To_RgbBytes_Produce_Equal_OutPut() { - Color color = new Color(24, 48, 96, 192); - ColorVector colorVector = new ColorVector(24, 48, 96, 192); + Rgba32 color = new Rgba32(24, 48, 96, 192); + RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); byte[] rgb = new byte[3]; byte[] rgbVector = new byte[3]; @@ -93,8 +95,8 @@ [Fact] public void Color_Types_To_RgbaBytes_Produce_Equal_OutPut() { - Color color = new Color(24, 48, 96, 192); - ColorVector colorVector = new ColorVector(24, 48, 96, 192); + Rgba32 color = new Rgba32(24, 48, 96, 192); + RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); byte[] rgba = new byte[4]; byte[] rgbaVector = new byte[4]; @@ -108,8 +110,8 @@ [Fact] public void Color_Types_To_BgrBytes_Produce_Equal_OutPut() { - Color color = new Color(24, 48, 96, 192); - ColorVector colorVector = new ColorVector(24, 48, 96, 192); + Rgba32 color = new Rgba32(24, 48, 96, 192); + RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); byte[] bgr = new byte[3]; byte[] bgrVector = new byte[3]; @@ -123,8 +125,8 @@ [Fact] public void Color_Types_To_BgraBytes_Produce_Equal_OutPut() { - Color color = new Color(24, 48, 96, 192); - ColorVector colorVector = new ColorVector(24, 48, 96, 192); + Rgba32 color = new Rgba32(24, 48, 96, 192); + RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); byte[] bgra = new byte[4]; byte[] bgraVector = new byte[4]; @@ -138,8 +140,8 @@ [Fact] public void Color_Types_To_Hex_Produce_Equal_OutPut() { - Color color = new Color(24, 48, 96, 192); - ColorVector colorVector = new ColorVector(24, 48, 96, 192); + Rgba32 color = new Rgba32(24, 48, 96, 192); + RgbaVector colorVector = new RgbaVector(24, 48, 96, 192); // 183060C0 Assert.Equal(color.ToHex(), colorVector.ToHex()); diff --git a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs index ebf3a866a6..3bc59df64a 100644 --- a/tests/ImageSharp.Tests/Common/BufferSpanTests.cs +++ b/tests/ImageSharp.Tests/Common/BufferSpanTests.cs @@ -6,6 +6,8 @@ namespace ImageSharp.Tests.Common using System; using System.Runtime.CompilerServices; + using ImageSharp.PixelFormats; + using Xunit; using static TestStructs; @@ -412,12 +414,12 @@ namespace ImageSharp.Tests.Common [Fact] public void Color32ToBytes() { - Color[] colors = { new Color(0, 1, 2, 3), new Color(4, 5, 6, 7), new Color(8, 9, 10, 11), }; + Rgba32[] colors = { new Rgba32(0, 1, 2, 3), new Rgba32(4, 5, 6, 7), new Rgba32(8, 9, 10, 11), }; - using (Buffer colorBuf = new Buffer(colors)) + using (Buffer colorBuf = new Buffer(colors)) using (Buffer byteBuf = new Buffer(colors.Length * 4)) { - BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length * sizeof(Color)); + BufferSpan.Copy(colorBuf.Span.AsBytes(), byteBuf, colorBuf.Length * sizeof(Rgba32)); byte[] a = byteBuf.Array; diff --git a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs index 403dffba9c..e673b28f1d 100644 --- a/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs +++ b/tests/ImageSharp.Tests/Common/PixelDataPoolTests.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Tests { using System.Linq; + using ImageSharp.PixelFormats; + using Xunit; /// @@ -18,7 +20,7 @@ namespace ImageSharp.Tests [Fact] public void PixelDataPoolRentsMinimumSize() { - Color[] pixels = PixelDataPool.Rent(1024); + Rgba32[] pixels = PixelDataPool.Rent(1024); Assert.True(pixels.Length >= 1024); } @@ -26,9 +28,9 @@ namespace ImageSharp.Tests [Fact] public void PixelDataPoolDoesNotThrowWhenReturningNonPooled() { - Color[] pixels = new Color[1024]; + Rgba32[] pixels = new Rgba32[1024]; - PixelDataPool.Return(pixels); + PixelDataPool.Return(pixels); Assert.True(pixels.Length >= 1024); } @@ -39,7 +41,7 @@ namespace ImageSharp.Tests public void CalculateMaxArrayLength(bool isRawData) { int max = isRawData ? PixelDataPool.CalculateMaxArrayLength() - : PixelDataPool.CalculateMaxArrayLength(); + : PixelDataPool.CalculateMaxArrayLength(); Assert.Equal(max < int.MaxValue, !isRawData); } diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index a1d4d3fd59..eb3a5de86a 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -11,6 +11,9 @@ namespace ImageSharp.Tests.Drawing using System.Diagnostics.CodeAnalysis; using System.IO; using System.Numerics; + + using ImageSharp.PixelFormats; + using Xunit; public class Beziers : FileTestBase @@ -23,8 +26,8 @@ namespace ImageSharp.Tests.Drawing { using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { - image.BackgroundColor(Color.Blue) - .DrawBeziers(Color.HotPink, 5, + image.BackgroundColor(Rgba32.Blue) + .DrawBeziers(Rgba32.HotPink, 5, new[] { new Vector2(10, 400), new Vector2(30, 10), @@ -34,21 +37,21 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve - Assert.Equal(Color.HotPink, sourcePixels[138, 115]); + Assert.Equal(Rgba32.HotPink, sourcePixels[138, 115]); //start points - Assert.Equal(Color.HotPink, sourcePixels[10, 400]); - Assert.Equal(Color.HotPink, sourcePixels[300, 400]); + Assert.Equal(Rgba32.HotPink, sourcePixels[10, 400]); + Assert.Equal(Rgba32.HotPink, sourcePixels[300, 400]); //curve points should not be never be set - Assert.Equal(Color.Blue, sourcePixels[30, 10]); - Assert.Equal(Color.Blue, sourcePixels[240, 30]); + Assert.Equal(Rgba32.Blue, sourcePixels[30, 10]); + Assert.Equal(Rgba32.Blue, sourcePixels[240, 30]); // inside shape should be empty - Assert.Equal(Color.Blue, sourcePixels[200, 250]); + Assert.Equal(Rgba32.Blue, sourcePixels[200, 250]); } } } @@ -59,13 +62,13 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "BezierLine"); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { - image.BackgroundColor(Color.Blue) + image.BackgroundColor(Rgba32.Blue) .DrawBeziers(color, 10, new[] { @@ -78,9 +81,9 @@ namespace ImageSharp.Tests.Drawing } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve Assert.Equal(mergedColor, sourcePixels[138, 115]); @@ -90,11 +93,11 @@ namespace ImageSharp.Tests.Drawing Assert.Equal(mergedColor, sourcePixels[300, 400]); //curve points should not be never be set - Assert.Equal(Color.Blue, sourcePixels[30, 10]); - Assert.Equal(Color.Blue, sourcePixels[240, 30]); + Assert.Equal(Rgba32.Blue, sourcePixels[30, 10]); + Assert.Equal(Rgba32.Blue, sourcePixels[240, 30]); // inside shape should be empty - Assert.Equal(Color.Blue, sourcePixels[200, 250]); + Assert.Equal(Rgba32.Blue, sourcePixels[200, 250]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index fc231a89d5..674823d3a8 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -5,15 +5,13 @@ namespace ImageSharp.Tests.Drawing { - using Drawing; - using ImageSharp.Drawing; using ShapePath = SixLabors.Shapes.Path; using SixLabors.Shapes; - using System; - using System.Diagnostics.CodeAnalysis; using System.IO; using System.Numerics; + using ImageSharp.PixelFormats; + using Xunit; public class DrawPathTests : FileTestBase @@ -38,18 +36,18 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 5, p) + .BackgroundColor(Rgba32.Blue) + .Draw(Rgba32.HotPink, 5, p) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Rgba32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Rgba32.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } } } @@ -60,7 +58,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Path"); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); LinearLineSegment linerSegemnt = new LinearLineSegment( @@ -81,21 +79,21 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .Draw(color, 10, p) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index 8162bc5319..493bab347f 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -10,12 +10,12 @@ namespace ImageSharp.Tests.Drawing using ImageSharp.Drawing; using ImageSharp.Drawing.Brushes; - + using ImageSharp.PixelFormats; using Xunit; public class FillPatternBrushTests : FileTestBase { - private void Test(string name, Color background, IBrush brush, Color[,] expectedPattern) + private void Test(string name, Rgba32 background, IBrush brush, Rgba32[,] expectedPattern) { string path = this.CreateOutputDirectory("Fill", "PatternBrush"); using (Image image = new Image(20, 20)) @@ -29,11 +29,11 @@ namespace ImageSharp.Tests.Drawing image.Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { // lets pick random spots to start checking Random r = new Random(); - Fast2DArray expectedPatternFast = new Fast2DArray(expectedPattern); + Fast2DArray expectedPatternFast = new Fast2DArray(expectedPattern); int xStride = expectedPatternFast.Width; int yStride = expectedPatternFast.Height; int offsetX = r.Next(image.Width / xStride) * xStride; @@ -44,8 +44,8 @@ namespace ImageSharp.Tests.Drawing { int actualX = x + offsetX; int actualY = y + offsetY; - Color expected = expectedPatternFast[y, x]; // inverted pattern - Color actual = sourcePixels[actualX, actualY]; + Rgba32 expected = expectedPatternFast[y, x]; // inverted pattern + Rgba32 actual = sourcePixels[actualX, actualY]; if (expected != actual) { Assert.True(false, $"Expected {expected} but found {actual} at ({actualX},{actualY})"); @@ -63,73 +63,73 @@ namespace ImageSharp.Tests.Drawing [Fact] public void ImageShouldBeFloodFilledWithPercent10() { - this.Test("Percent10", Color.Blue, Brushes.Percent10(Color.HotPink, Color.LimeGreen), + this.Test("Percent10", Rgba32.Blue, Brushes.Percent10(Rgba32.HotPink, Rgba32.LimeGreen), new[,] { - { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen} + { Rgba32.HotPink , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink , Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent10Transparent() { - Test("Percent10_Transparent", Color.Blue, Brushes.Percent10(Color.HotPink), - new Color[,] { - { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.HotPink , Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue, Color.Blue} + Test("Percent10_Transparent", Rgba32.Blue, Brushes.Percent10(Rgba32.HotPink), + new Rgba32[,] { + { Rgba32.HotPink , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink , Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent20() { - Test("Percent20", Color.Blue, Brushes.Percent20(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen}, - { Color.HotPink , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink , Color.LimeGreen} + Test("Percent20", Rgba32.Blue, Brushes.Percent20(Rgba32.HotPink, Rgba32.LimeGreen), + new Rgba32[,] { + { Rgba32.HotPink , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink , Rgba32.LimeGreen}, + { Rgba32.HotPink , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink , Rgba32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithPercent20_transparent() { - Test("Percent20_Transparent", Color.Blue, Brushes.Percent20(Color.HotPink), - new Color[,] { - { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.HotPink , Color.Blue}, - { Color.HotPink , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.HotPink , Color.Blue} + Test("Percent20_Transparent", Rgba32.Blue, Brushes.Percent20(Rgba32.HotPink), + new Rgba32[,] { + { Rgba32.HotPink , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink , Rgba32.Blue}, + { Rgba32.HotPink , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink , Rgba32.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithHorizontal() { - Test("Horizontal", Color.Blue, Brushes.Horizontal(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, - { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen , Color.LimeGreen} + Test("Horizontal", Rgba32.Blue, Brushes.Horizontal(Rgba32.HotPink, Rgba32.LimeGreen), + new Rgba32[,] { + { Rgba32.LimeGreen , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink , Rgba32.HotPink}, + { Rgba32.LimeGreen , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen , Rgba32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithHorizontal_transparent() { - Test("Horizontal_Transparent", Color.Blue, Brushes.Horizontal(Color.HotPink), - new Color[,] { - { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, - { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, - { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue , Color.Blue} + Test("Horizontal_Transparent", Rgba32.Blue, Brushes.Horizontal(Rgba32.HotPink), + new Rgba32[,] { + { Rgba32.Blue , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink , Rgba32.HotPink}, + { Rgba32.Blue , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue , Rgba32.Blue} }); } @@ -138,96 +138,96 @@ namespace ImageSharp.Tests.Drawing [Fact] public void ImageShouldBeFloodFilledWithMin() { - Test("Min", Color.Blue, Brushes.Min(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen , Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen , Color.LimeGreen}, - { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink} + Test("Min", Rgba32.Blue, Brushes.Min(Rgba32.HotPink, Rgba32.LimeGreen), + new Rgba32[,] { + { Rgba32.LimeGreen , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen , Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen , Rgba32.LimeGreen}, + { Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink , Rgba32.HotPink} }); } [Fact] public void ImageShouldBeFloodFilledWithMin_transparent() { - Test("Min_Transparent", Color.Blue, Brushes.Min(Color.HotPink), - new Color[,] { - { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue , Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue , Color.Blue}, - { Color.HotPink, Color.HotPink, Color.HotPink , Color.HotPink}, + Test("Min_Transparent", Rgba32.Blue, Brushes.Min(Rgba32.HotPink), + new Rgba32[,] { + { Rgba32.Blue , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue , Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue , Rgba32.Blue}, + { Rgba32.HotPink, Rgba32.HotPink, Rgba32.HotPink , Rgba32.HotPink}, }); } [Fact] public void ImageShouldBeFloodFilledWithVertical() { - Test("Vertical", Color.Blue, Brushes.Vertical(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen} + Test("Vertical", Rgba32.Blue, Brushes.Vertical(Rgba32.HotPink, Rgba32.LimeGreen), + new Rgba32[,] { + { Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithVertical_transparent() { - Test("Vertical_Transparent", Color.Blue, Brushes.Vertical(Color.HotPink), - new Color[,] { - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue} + Test("Vertical_Transparent", Rgba32.Blue, Brushes.Vertical(Rgba32.HotPink), + new Rgba32[,] { + { Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithForwardDiagonal() { - Test("ForwardDiagonal", Color.Blue, Brushes.ForwardDiagonal(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.HotPink}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen} + Test("ForwardDiagonal", Rgba32.Blue, Brushes.ForwardDiagonal(Rgba32.HotPink, Rgba32.LimeGreen), + new Rgba32[,] { + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen} }); } [Fact] public void ImageShouldBeFloodFilledWithForwardDiagonal_transparent() { - Test("ForwardDiagonal_Transparent", Color.Blue, Brushes.ForwardDiagonal(Color.HotPink), - new Color[,] { - { Color.Blue, Color.Blue, Color.Blue, Color.HotPink}, - { Color.Blue, Color.Blue, Color.HotPink, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.HotPink, Color.Blue, Color.Blue, Color.Blue} + Test("ForwardDiagonal_Transparent", Rgba32.Blue, Brushes.ForwardDiagonal(Rgba32.HotPink), + new Rgba32[,] { + { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue} }); } [Fact] public void ImageShouldBeFloodFilledWithBackwardDiagonal() { - Test("BackwardDiagonal", Color.Blue, Brushes.BackwardDiagonal(Color.HotPink, Color.LimeGreen), - new Color[,] { - { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.HotPink, Color.LimeGreen}, - { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.HotPink} + Test("BackwardDiagonal", Rgba32.Blue, Brushes.BackwardDiagonal(Rgba32.HotPink, Rgba32.LimeGreen), + new Rgba32[,] { + { Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink, Rgba32.LimeGreen}, + { Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.LimeGreen, Rgba32.HotPink} }); } [Fact] public void ImageShouldBeFloodFilledWithBackwardDiagonal_transparent() { - Test("BackwardDiagonal_Transparent", Color.Blue, Brushes.BackwardDiagonal(Color.HotPink), - new Color[,] { - { Color.HotPink, Color.Blue, Color.Blue, Color.Blue}, - { Color.Blue, Color.HotPink, Color.Blue, Color.Blue}, - { Color.Blue, Color.Blue, Color.HotPink, Color.Blue}, - { Color.Blue, Color.Blue, Color.Blue, Color.HotPink} + Test("BackwardDiagonal_Transparent", Rgba32.Blue, Brushes.BackwardDiagonal(Rgba32.HotPink), + new Rgba32[,] { + { Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink, Rgba32.Blue}, + { Rgba32.Blue, Rgba32.Blue, Rgba32.Blue, Rgba32.HotPink} }); } } diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index 03994bc94d..9661a41bba 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -1,20 +1,13 @@  namespace ImageSharp.Tests.Drawing { - using System; - using System.IO; using ImageSharp; - using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; using Xunit; using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; using ImageSharp.Drawing.Processors; - using ImageSharp.Drawing.Pens; using Moq; - using System.Collections.Immutable; + + using ImageSharp.PixelFormats; public class FillRegionProcessorTests { @@ -29,14 +22,14 @@ namespace ImageSharp.Tests.Drawing { ImageSharp.Rectangle bounds = new ImageSharp.Rectangle(0, 0, 1, 1); - Mock> brush = new Mock>(); + Mock> brush = new Mock>(); Mock region = new Mock(); region.Setup(x => x.Bounds).Returns(bounds); GraphicsOptions options = new GraphicsOptions(antialias) { AntialiasSubpixelDepth = 1 }; - FillRegionProcessor processor = new FillRegionProcessor(brush.Object, region.Object, options); + FillRegionProcessor processor = new FillRegionProcessor(brush.Object, region.Object, options); Image img = new Image(1, 1); processor.Apply(img, bounds); diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index bafc84b69f..4a3c8e3058 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -11,6 +11,9 @@ namespace ImageSharp.Tests.Drawing using System.Diagnostics.CodeAnalysis; using System.IO; using System.Numerics; + + using ImageSharp.PixelFormats; + using Xunit; public class FillSolidBrushTests: FileTestBase @@ -24,15 +27,15 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DefaultBack.png")) { image - .Fill(Color.HotPink) + .Fill(Rgba32.HotPink) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Rgba32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Rgba32.HotPink, sourcePixels[199, 149]); } } } @@ -46,16 +49,16 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink) + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Rgba32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Rgba32.HotPink, sourcePixels[199, 149]); } } } @@ -66,20 +69,20 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Fill", "SolidBrush"); using (Image image = new Image(500, 500)) { - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .Fill(color) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index d7a4bde957..bded40f32a 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Tests.Drawing using ImageSharp.Drawing; using System.Numerics; using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; using SixLabors.Shapes; @@ -36,33 +37,33 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Rgba32.Blue) + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[10, 10]); + Assert.Equal(Rgba32.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color.HotPink, sourcePixels[200, 150]); + Assert.Equal(Rgba32.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color.HotPink, sourcePixels[50, 300]); + Assert.Equal(Rgba32.HotPink, sourcePixels[50, 300]); - Assert.Equal(Color.HotPink, sourcePixels[37, 85]); + Assert.Equal(Rgba32.HotPink, sourcePixels[37, 85]); - Assert.Equal(Color.HotPink, sourcePixels[93, 85]); + Assert.Equal(Rgba32.HotPink, sourcePixels[93, 85]); - Assert.Equal(Color.HotPink, sourcePixels[65, 137]); + Assert.Equal(Rgba32.HotPink, sourcePixels[65, 137]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[57, 99]); + Assert.Equal(Rgba32.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color.Blue, sourcePixels[100, 192]); + Assert.Equal(Rgba32.Blue, sourcePixels[100, 192]); } } } @@ -86,18 +87,18 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleVanishHole.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Rgba32.Blue) + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[10, 10]); + Assert.Equal(Rgba32.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color.HotPink, sourcePixels[200, 150]); + Assert.Equal(Rgba32.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color.HotPink, sourcePixels[50, 300]); + Assert.Equal(Rgba32.HotPink, sourcePixels[50, 300]); //Assert.Equal(Color.HotPink, sourcePixels[37, 85]); @@ -106,13 +107,13 @@ namespace ImageSharp.Tests.Drawing //Assert.Equal(Color.HotPink, sourcePixels[65, 137]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[57, 99]); + Assert.Equal(Rgba32.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color.Blue, sourcePixels[100, 192]); + Assert.Equal(Rgba32.Blue, sourcePixels[100, 192]); } } } @@ -137,28 +138,28 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) + .BackgroundColor(Rgba32.Blue) + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[10, 10]); + Assert.Equal(Rgba32.HotPink, sourcePixels[10, 10]); - Assert.Equal(Color.HotPink, sourcePixels[200, 150]); + Assert.Equal(Rgba32.HotPink, sourcePixels[200, 150]); - Assert.Equal(Color.HotPink, sourcePixels[50, 300]); + Assert.Equal(Rgba32.HotPink, sourcePixels[50, 300]); - Assert.Equal(Color.Blue, sourcePixels[130, 41]); + Assert.Equal(Rgba32.Blue, sourcePixels[130, 41]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[57, 99]); + Assert.Equal(Rgba32.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color.Blue, sourcePixels[100, 192]); + Assert.Equal(Rgba32.Blue, sourcePixels[100, 192]); } } } @@ -183,8 +184,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Pens.Dash(Color.HotPink, 5), simplePath.Clip(hole1)) + .BackgroundColor(Rgba32.Blue) + .Draw(Pens.Dash(Rgba32.HotPink, 5), simplePath.Clip(hole1)) .Save(output); } } @@ -204,22 +205,22 @@ namespace ImageSharp.Tests.Drawing new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .Draw(color, 5, simplePath.Clip(hole1)) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[10, 10]); @@ -234,14 +235,14 @@ namespace ImageSharp.Tests.Drawing Assert.Equal(mergedColor, sourcePixels[65, 137]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[57, 99]); + Assert.Equal(Rgba32.Blue, sourcePixels[57, 99]); //inside shape - Assert.Equal(Color.Blue, sourcePixels[100, 192]); + Assert.Equal(Rgba32.Blue, sourcePixels[100, 192]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index 81efd933ba..87bda30bed 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -10,6 +10,9 @@ namespace ImageSharp.Tests.Drawing using System.IO; using System.Numerics; + + using ImageSharp.PixelFormats; + using Xunit; public class LineTests : FileTestBase @@ -23,8 +26,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Color.HotPink, 5, + .BackgroundColor(Rgba32.Blue) + .DrawLines(Rgba32.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -33,13 +36,13 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Rgba32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Rgba32.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } } } @@ -53,8 +56,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple_noantialias.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Color.HotPink, 5, + .BackgroundColor(Rgba32.Blue) + .DrawLines(Rgba32.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -64,13 +67,13 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Rgba32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Rgba32.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } } } @@ -84,8 +87,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dashed.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Pens.Dash(Color.HotPink, 5), + .BackgroundColor(Rgba32.Blue) + .DrawLines(Pens.Dash(Rgba32.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -105,8 +108,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Dot.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Pens.Dot(Color.HotPink, 5), + .BackgroundColor(Rgba32.Blue) + .DrawLines(Pens.Dot(Rgba32.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -126,8 +129,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DashDot.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Pens.DashDot(Color.HotPink, 5), + .BackgroundColor(Rgba32.Blue) + .DrawLines(Pens.DashDot(Rgba32.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -147,8 +150,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/DashDotDot.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Pens.DashDotDot(Color.HotPink, 5), new[] { + .BackgroundColor(Rgba32.Blue) + .DrawLines(Pens.DashDotDot(Rgba32.HotPink, 5), new[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) @@ -162,7 +165,7 @@ namespace ImageSharp.Tests.Drawing { string path = this.CreateOutputDirectory("Drawing", "Lines"); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); Image image = new Image(500, 500); @@ -170,7 +173,7 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .DrawLines(color, 10, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -180,15 +183,15 @@ namespace ImageSharp.Tests.Drawing } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f/255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f/255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } } @@ -202,8 +205,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color.Blue) - .DrawLines(Color.HotPink, 10, new[] { + .BackgroundColor(Rgba32.Blue) + .DrawLines(Rgba32.HotPink, 10, new[] { new Vector2(10, 10), new Vector2(200, 10), new Vector2(200, 150), @@ -212,15 +215,15 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[8, 8]); + Assert.Equal(Rgba32.HotPink, sourcePixels[8, 8]); - Assert.Equal(Color.HotPink, sourcePixels[198, 10]); + Assert.Equal(Rgba32.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color.Blue, sourcePixels[10, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[10, 50]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs index 82e2f72a2f..008df90911 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs @@ -2,25 +2,24 @@ namespace ImageSharp.Tests.Drawing.Paths { using System; - using System.IO; - using ImageSharp; + using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; + using Xunit; using ImageSharp.Drawing; using System.Numerics; using SixLabors.Shapes; using ImageSharp.Drawing.Processors; using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; public class DrawBeziersTests : IDisposable { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Firebrick, 99.9f); + Rgba32 color = Rgba32.HotPink; + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + Pen pen = new Pen(Rgba32.Firebrick, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +44,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -56,7 +55,7 @@ namespace ImageSharp.Tests.Drawing.Paths BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -67,7 +66,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -76,7 +75,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -87,7 +86,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -96,10 +95,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -109,7 +108,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -118,10 +117,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -131,7 +130,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -149,7 +148,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawBeziers(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs index cc126614f6..221cf7f29a 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs @@ -2,25 +2,23 @@ namespace ImageSharp.Tests.Drawing.Paths { using System; - using System.IO; - using ImageSharp; + using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; using Xunit; using ImageSharp.Drawing; using System.Numerics; using SixLabors.Shapes; using ImageSharp.Drawing.Processors; using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; public class DrawLinesTests : IDisposable { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Gray, 99.9f); + Rgba32 color = Rgba32.HotPink; + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + Pen pen = new Pen(Rgba32.Gray, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +43,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -54,7 +52,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -65,7 +63,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -74,7 +72,7 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -85,7 +83,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -94,10 +92,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -107,7 +105,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -116,10 +114,10 @@ namespace ImageSharp.Tests.Drawing.Paths SixLabors.Shapes.Path vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -129,7 +127,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -147,7 +145,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawLines(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs index 6c1c068135..07be85b859 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs @@ -2,25 +2,24 @@ namespace ImageSharp.Tests.Drawing.Paths { using System; - using System.IO; - using ImageSharp; + using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; + using Xunit; using ImageSharp.Drawing; using System.Numerics; using SixLabors.Shapes; using ImageSharp.Drawing.Processors; using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; public class DrawPath : IDisposable { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Gray, 99.9f); + Rgba32 color = Rgba32.HotPink; + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + Pen pen = new Pen(Rgba32.Gray, 99.9f); IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,14 +44,14 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -63,14 +62,14 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -81,17 +80,17 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -101,17 +100,17 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); ShapePath shapepath = Assert.IsType(processor.Path); Assert.Equal(path, shapepath.Path); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -121,7 +120,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, path); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -137,7 +136,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs index 9de0523313..bd90a460df 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs @@ -2,25 +2,24 @@ namespace ImageSharp.Tests.Drawing.Paths { using System; - using System.IO; - using ImageSharp; + using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; + using Xunit; using ImageSharp.Drawing; using System.Numerics; using SixLabors.Shapes; using ImageSharp.Drawing.Processors; using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; public class DrawPolygon : IDisposable { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Gray, 99.9f); + Rgba32 color = Rgba32.HotPink; + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + Pen pen = new Pen(Rgba32.Gray, 99.9f); Vector2[] points = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -45,7 +44,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(brush, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -54,7 +53,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -65,7 +64,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(brush, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -74,7 +73,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -85,7 +84,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(color, thickness, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -94,10 +93,10 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -107,7 +106,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(color, thickness, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -116,10 +115,10 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon vector = Assert.IsType(path.Path); LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -129,7 +128,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(pen, points); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -147,7 +146,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.DrawPolygon(pen, points, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs index 215d5a7c70..7ebc6b14f3 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs @@ -2,25 +2,21 @@ namespace ImageSharp.Tests.Drawing.Paths { using System; - using System.IO; using ImageSharp; using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; using Xunit; using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; using ImageSharp.Drawing.Processors; using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; public class DrawRectangle : IDisposable { float thickness = 7.2f; GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); - Pen pen = new Pen(Color.Gray, 99.9f); + Rgba32 color = Rgba32.HotPink; + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); + Pen pen = new Pen(Rgba32.Gray, 99.9f); ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 98, 324); private ProcessorWatchingImage img; @@ -41,7 +37,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -53,7 +49,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -64,7 +60,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(brush, thickness, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -77,7 +73,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(brush, pen.Brush); Assert.Equal(thickness, pen.Width); } @@ -88,7 +84,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -101,10 +97,10 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -114,7 +110,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(color, thickness, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -127,10 +123,10 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - Pen pen = Assert.IsType>(processor.Pen); + Pen pen = Assert.IsType>(processor.Pen); Assert.Equal(thickness, pen.Width); - SolidBrush brush = Assert.IsType>(pen.Brush); + SolidBrush brush = Assert.IsType>(pen.Brush); Assert.Equal(color, brush.Color); } @@ -140,7 +136,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, rectangle); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -162,7 +158,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Draw(pen, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index 5ba6580bd7..a639a70cf7 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -2,23 +2,20 @@ namespace ImageSharp.Tests.Drawing.Paths { using System; - using System.IO; using ImageSharp; using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; using Xunit; using ImageSharp.Drawing; using System.Numerics; using SixLabors.Shapes; using ImageSharp.Drawing.Processors; - using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; public class FillPath : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); + Rgba32 color = Rgba32.HotPink; + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -43,7 +40,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -62,7 +59,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -79,7 +76,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -87,7 +84,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -97,7 +94,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -105,7 +102,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segments = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index ad72d4c4ee..2935c43a05 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -2,23 +2,20 @@ namespace ImageSharp.Tests.Drawing.Paths { using System; - using System.IO; using ImageSharp; using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; using Xunit; using ImageSharp.Drawing; using System.Numerics; using SixLabors.Shapes; using ImageSharp.Drawing.Processors; - using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; public class FillPolygon : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); + Rgba32 color = Rgba32.HotPink; + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); Vector2[] path = new Vector2[] { new Vector2(10,10), new Vector2(20,10), @@ -43,7 +40,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(brush, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -60,7 +57,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(brush, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -77,7 +74,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(color, path); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -85,7 +82,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -95,7 +92,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.FillPolygon(color, path, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -103,7 +100,7 @@ namespace ImageSharp.Tests.Drawing.Paths Polygon polygon = Assert.IsType(region.Shape); LinearLineSegment segemnt = Assert.IsType(polygon.LineSegments[0]); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index f6b1c4adef..4657db9886 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -2,23 +2,19 @@ namespace ImageSharp.Tests.Drawing.Paths { using System; - using System.IO; - using ImageSharp; + using ImageSharp.Drawing.Brushes; - using Processing; - using System.Collections.Generic; + using Xunit; using ImageSharp.Drawing; - using System.Numerics; - using SixLabors.Shapes; using ImageSharp.Drawing.Processors; - using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; public class FillRectangle : IDisposable { GraphicsOptions noneDefault = new GraphicsOptions(); - Color color = Color.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); + Rgba32 color = Rgba32.HotPink; + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 77, 76); private ProcessorWatchingImage img; @@ -39,7 +35,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, rectangle); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -59,7 +55,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(brush, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -79,7 +75,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, rectangle); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(GraphicsOptions.Default, processor.Options); @@ -90,7 +86,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } @@ -100,7 +96,7 @@ namespace ImageSharp.Tests.Drawing.Paths img.Fill(color, rectangle, noneDefault); Assert.NotEmpty(img.ProcessorApplications); - FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); + FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); Assert.Equal(noneDefault, processor.Options); @@ -111,7 +107,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.Equal(rect.Size.Width, rectangle.Width); Assert.Equal(rect.Size.Height, rectangle.Height); - SolidBrush brush = Assert.IsType>(processor.Brush); + SolidBrush brush = Assert.IsType>(processor.Brush); Assert.Equal(color, brush.Color); } } diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs index 2d3d2cc2b8..d961a59946 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs @@ -6,13 +6,13 @@ namespace ImageSharp.Tests.Drawing.Paths using ImageSharp; using Processing; using System.Collections.Generic; - using ImageSharp.Formats; + using ImageSharp.PixelFormats; /// /// Watches but does not actually run the processors against the image. /// - /// - public class ProcessorWatchingImage : Image + /// + public class ProcessorWatchingImage : Image { public List ProcessorApplications { get; } = new List(); @@ -21,7 +21,7 @@ namespace ImageSharp.Tests.Drawing.Paths { } - public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { this.ProcessorApplications.Add(new ProcessorDetails { @@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing.Paths public struct ProcessorDetails { - public IImageProcessor processor; + public IImageProcessor processor; public Rectangle rectangle; } } diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index 3e06ca918e..554c5a32ed 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -13,6 +13,8 @@ namespace ImageSharp.Tests.Drawing using ImageSharp.Drawing; using System.Numerics; + using ImageSharp.PixelFormats; + public class PolygonTests : FileTestBase { [Fact] @@ -25,8 +27,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .DrawPolygon(Color.HotPink, 5, + .BackgroundColor(Rgba32.Blue) + .DrawPolygon(Rgba32.HotPink, 5, new[] { new Vector2(10, 10), new Vector2(200, 150), @@ -35,15 +37,15 @@ namespace ImageSharp.Tests.Drawing .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[9, 9]); + Assert.Equal(Rgba32.HotPink, sourcePixels[9, 9]); - Assert.Equal(Color.HotPink, sourcePixels[199, 149]); + Assert.Equal(Rgba32.HotPink, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); } } } @@ -58,30 +60,30 @@ namespace ImageSharp.Tests.Drawing new Vector2(50, 300) }; - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .DrawPolygon(color, 10, simplePath) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[9, 9]); Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); } } } @@ -96,22 +98,22 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color.Blue) - .Draw(Color.HotPink, 10, new Rectangle(10, 10, 190, 140)) + .BackgroundColor(Rgba32.Blue) + .Draw(Rgba32.HotPink, 10, new Rectangle(10, 10, 190, 140)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[8, 8]); + Assert.Equal(Rgba32.HotPink, sourcePixels[8, 8]); - Assert.Equal(Color.HotPink, sourcePixels[198, 10]); + Assert.Equal(Rgba32.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color.HotPink, sourcePixels[10, 50]); + Assert.Equal(Rgba32.HotPink, sourcePixels[10, 50]); - Assert.Equal(Color.Blue, sourcePixels[50, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs index 0b450d166e..d3236ae001 100644 --- a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs @@ -9,6 +9,8 @@ namespace ImageSharp.Tests using System.IO; using System.Linq; + using ImageSharp.PixelFormats; + using Xunit; public class RecolorImageTest : FileTestBase @@ -18,7 +20,7 @@ namespace ImageSharp.Tests { string path = this.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Color.Yellow, Color.HotPink, 0.2f); + RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); foreach (TestFile file in Files) { @@ -38,7 +40,7 @@ namespace ImageSharp.Tests { string path = this.CreateOutputDirectory("Drawing", "RecolorImage"); - RecolorBrush brush = new RecolorBrush(Color.Yellow, Color.HotPink, 0.2f); + RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f); foreach (TestFile file in Files) { diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index 1a7e98a12f..0886aa15ae 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Tests.Drawing using System.IO; using System.Numerics; + using ImageSharp.PixelFormats; + using SixLabors.Shapes; using Xunit; @@ -29,20 +31,20 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new Polygon(new BezierLineSegment(simplePath))) + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, new Polygon(new BezierLineSegment(simplePath))) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[150, 300]); + Assert.Equal(Rgba32.HotPink, sourcePixels[150, 300]); //curve points should not be never be set - Assert.Equal(Color.Blue, sourcePixels[240, 30]); + Assert.Equal(Rgba32.Blue, sourcePixels[240, 30]); // inside shape should not be empty - Assert.Equal(Color.HotPink, sourcePixels[200, 250]); + Assert.Equal(Rgba32.HotPink, sourcePixels[200, 250]); } } } @@ -57,28 +59,28 @@ namespace ImageSharp.Tests.Drawing new Vector2(240, 30), new Vector2(300, 400) }; - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .Fill(color, new Polygon(new BezierLineSegment(simplePath))) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { //top of curve Assert.Equal(mergedColor, sourcePixels[138, 116]); //curve points should not be never be set - Assert.Equal(Color.Blue, sourcePixels[240, 30]); + Assert.Equal(Rgba32.Blue, sourcePixels[240, 30]); // inside shape should not be empty Assert.Equal(mergedColor, sourcePixels[200, 250]); diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index 4ff250a934..1de7e21441 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -11,6 +11,8 @@ namespace ImageSharp.Tests.Drawing using ImageSharp.Drawing; using System.Numerics; + using ImageSharp.PixelFormats; + using SixLabors.Shapes; public class SolidComplexPolygonTests : FileTestBase @@ -35,17 +37,17 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, clipped) + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, clipped) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[20, 35]); + Assert.Equal(Rgba32.HotPink, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[60, 100]); + Assert.Equal(Rgba32.Blue, sourcePixels[60, 100]); } } } @@ -70,17 +72,17 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, simplePath.Clip(hole1)) + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, simplePath.Clip(hole1)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[20, 35]); + Assert.Equal(Rgba32.HotPink, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[60, 100]); + Assert.Equal(Rgba32.Blue, sourcePixels[60, 100]); } } } @@ -98,27 +100,27 @@ namespace ImageSharp.Tests.Drawing new Vector2(37, 85), new Vector2(93, 85), new Vector2(65, 137))); - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .Fill(color, simplePath.Clip(hole1)) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { Assert.Equal(mergedColor, sourcePixels[20, 35]); //inside hole - Assert.Equal(Color.Blue, sourcePixels[60, 100]); + Assert.Equal(Rgba32.Blue, sourcePixels[60, 100]); } } } diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index 79363480fc..d76dcf023e 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -13,6 +13,8 @@ namespace ImageSharp.Tests.Drawing using System.Numerics; using Xunit; using ImageSharp.Drawing.Brushes; + using ImageSharp.PixelFormats; + using SixLabors.Shapes; public class SolidPolygonTests : FileTestBase @@ -32,13 +34,13 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image - .FillPolygon(Color.HotPink, simplePath, new GraphicsOptions(true)) + .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(true)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[81, 145]); + Assert.Equal(Rgba32.HotPink, sourcePixels[81, 145]); } } } @@ -58,13 +60,13 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Pattern.png")) { image - .FillPolygon(Brushes.Horizontal(Color.HotPink), simplePath, new GraphicsOptions(true)) + .FillPolygon(Brushes.Horizontal(Rgba32.HotPink), simplePath, new GraphicsOptions(true)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[81, 145]); + Assert.Equal(Rgba32.HotPink, sourcePixels[81, 145]); } } } @@ -83,19 +85,19 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Simple_NoAntialias.png")) { image - .BackgroundColor(Color.Blue) - .FillPolygon(Color.HotPink, simplePath, new GraphicsOptions(false)) + .BackgroundColor(Rgba32.Blue) + .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(false)) .Save(output); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[11, 11]); + Assert.Equal(Rgba32.HotPink, sourcePixels[11, 11]); - Assert.Equal(Color.HotPink, sourcePixels[199, 150]); + Assert.Equal(Rgba32.HotPink, sourcePixels[199, 150]); - Assert.Equal(Color.HotPink, sourcePixels[50, 50]); + Assert.Equal(Rgba32.HotPink, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); } } } @@ -117,7 +119,7 @@ namespace ImageSharp.Tests.Drawing ImageBrush brush = new ImageBrush(brushImage); image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .FillPolygon(brush, simplePath) .Save(output); } @@ -132,24 +134,24 @@ namespace ImageSharp.Tests.Drawing new Vector2(200, 150), new Vector2(50, 300) }; - Color color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); + Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); using (Image image = new Image(500, 500)) { using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { image - .BackgroundColor(Color.Blue) + .BackgroundColor(Rgba32.Blue) .FillPolygon(color, simplePath) .Save(output); } //shift background color towards forground color by the opacity amount - Color mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); } } } @@ -164,22 +166,22 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new SixLabors.Shapes.Rectangle(10, 10, 190, 140)) + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, new SixLabors.Shapes.Rectangle(10, 10, 190, 140)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.HotPink, sourcePixels[11, 11]); + Assert.Equal(Rgba32.HotPink, sourcePixels[11, 11]); - Assert.Equal(Color.HotPink, sourcePixels[198, 10]); + Assert.Equal(Rgba32.HotPink, sourcePixels[198, 10]); - Assert.Equal(Color.HotPink, sourcePixels[10, 50]); + Assert.Equal(Rgba32.HotPink, sourcePixels[10, 50]); - Assert.Equal(Color.HotPink, sourcePixels[50, 50]); + Assert.Equal(Rgba32.HotPink, sourcePixels[50, 50]); - Assert.Equal(Color.Blue, sourcePixels[2, 2]); + Assert.Equal(Rgba32.Blue, sourcePixels[2, 2]); } } } @@ -194,16 +196,16 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Triangle.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new RegularPolygon(50, 50, 3, 30)) + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 3, 30)) .Save(output); } - using (PixelAccessor sourcePixels = image.Lock()) + using (PixelAccessor sourcePixels = image.Lock()) { - Assert.Equal(Color.Blue, sourcePixels[30, 65]); + Assert.Equal(Rgba32.Blue, sourcePixels[30, 65]); - Assert.Equal(Color.HotPink, sourcePixels[50, 50]); + Assert.Equal(Rgba32.HotPink, sourcePixels[50, 50]); } } } @@ -220,8 +222,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/Septagon.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI)) + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI)) .Save(output); } } @@ -239,8 +241,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/ellipse.png")) { image - .BackgroundColor(Color.Blue) - .Fill(Color.HotPink, new Ellipse(50, 50, 30, 50) + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, new Ellipse(50, 50, 30, 50) .Rotate((float)(Math.PI / 3))) .Save(output); } @@ -259,8 +261,8 @@ namespace ImageSharp.Tests.Drawing using (FileStream output = File.OpenWrite($"{path}/clipped-corner.png")) { image - .Fill(Color.Blue) - .FillPolygon(Color.HotPink, new[] + .Fill(Rgba32.Blue) + .FillPolygon(Rgba32.HotPink, new[] { new Vector2( 8, 8 ), new Vector2( 64, 8 ), diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index 52b7fcbb65..bce493a69d 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -12,6 +12,7 @@ namespace ImageSharp.Tests.Drawing.Text using ImageSharp.Drawing.Brushes; using ImageSharp.Drawing.Pens; using ImageSharp.Drawing.Processors; + using ImageSharp.PixelFormats; using ImageSharp.Tests.Drawing.Paths; using SixLabors.Fonts; @@ -21,9 +22,9 @@ namespace ImageSharp.Tests.Drawing.Text public class DrawText : IDisposable { - Color color = Color.HotPink; + Rgba32 color = Rgba32.HotPink; - SolidBrush brush = Brushes.Solid(Color.HotPink); + SolidBrush brush = Brushes.Solid(Rgba32.HotPink); IPath path = new SixLabors.Shapes.Path( new LinearLineSegment( @@ -53,73 +54,73 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "123", this.Font, - Brushes.Solid(Color.Red), + Brushes.Solid(Rgba32.Red), null, Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), null, Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void FillsForEachACharachterWhenColorSet() { - this.img.DrawText("123", this.Font, Color.Red, Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor processor = + Assert.IsType>(this.img.ProcessorApplications[0].processor); - SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(Color.Red, brush.Color); + SolidBrush brush = Assert.IsType>(processor.Brush); + Assert.Equal(Rgba32.Red, brush.Color); } [Fact] public void FillsForEachACharachterWhenColorSetDefaultOptions() { - this.img.DrawText("123", this.Font, Color.Red, Vector2.Zero); + this.img.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor processor = - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor processor = + Assert.IsType>(this.img.ProcessorApplications[0].processor); - SolidBrush brush = Assert.IsType>(processor.Brush); - Assert.Equal(Color.Red, brush.Color); + SolidBrush brush = Assert.IsType>(processor.Brush); + Assert.Equal(Rgba32.Red, brush.Color); } [Fact] @@ -129,43 +130,43 @@ namespace ImageSharp.Tests.Drawing.Text "123", this.Font, null, - Pens.Dash(Color.Red, 1), + Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() { - this.img.DrawText("123", this.Font, null, Pens.Dash(Color.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSet() { - this.img.DrawText("123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); + this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] public void DrawForEachACharachterWhenPenSetDefaultOptions() { - this.img.DrawText("123", this.Font, Pens.Dash(Color.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied - Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); } [Fact] @@ -174,8 +175,8 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "123", this.Font, - Brushes.Solid(Color.Red), - Pens.Dash(Color.Red, 1), + Brushes.Solid(Rgba32.Red), + Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); @@ -186,7 +187,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Color.Red), Pens.Dash(Color.Red, 1), Vector2.Zero); + this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(6, this.img.ProcessorApplications.Count); @@ -198,26 +199,26 @@ namespace ImageSharp.Tests.Drawing.Text this.img.DrawText( "1", this.Font, - Brushes.Solid(Color.Red), - Pens.Dash(Color.Red, 1), + Brushes.Solid(Rgba32.Red), + Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[1].processor); } [Fact] public void BrushAppliesBeforPenDefaultOptions() { - this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Pens.Dash(Color.Red, 1), Vector2.Zero); + this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - Assert.IsType>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + Assert.IsType>(this.img.ProcessorApplications[0].processor); + Assert.IsType>(this.img.ProcessorApplications[1].processor); } [Fact] @@ -225,19 +226,19 @@ namespace ImageSharp.Tests.Drawing.Text { this.img.MetaData.VerticalResolution = 1; this.img.MetaData.HorizontalResolution = 1; - this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true) { + this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true) { UseImageResolution = false }); - this.img.DrawText("1", this.Font, Brushes.Solid(Color.Red), Vector2.Zero, new TextGraphicsOptions(true) + this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true) { UseImageResolution = true }); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(2, this.img.ProcessorApplications.Count); - FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); + FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); + FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); ShapeRegion ownRegion = Assert.IsType(ownResolution.Region); ShapeRegion imgRegion = Assert.IsType(imgResolution.Region); diff --git a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs index 0bb3afccd7..1dbc93b9b4 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs @@ -13,6 +13,8 @@ namespace ImageSharp.Tests.Drawing.Text using SixLabors.Shapes; using ImageSharp.Drawing.Processors; using ImageSharp.Drawing.Pens; + using ImageSharp.PixelFormats; + using SixLabors.Fonts; public class OutputText : FileTestBase @@ -32,8 +34,8 @@ namespace ImageSharp.Tests.Drawing.Text //draws 2 overlapping triangle glyphs twice 1 set on each line using (Image img = new Image(100, 200)) { - img.Fill(Color.DarkBlue) - .DrawText("AB\nAB", new Font(this.Font, 50), Color.Red, new Vector2(0, 0)); + img.Fill(Rgba32.DarkBlue) + .DrawText("AB\nAB", new Font(this.Font, 50), Rgba32.Red, new Vector2(0, 0)); img.Save($"{this.CreateOutputDirectory("Drawing", "Text")}/AB.png"); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs index 8dbdb998c5..dc6985dd34 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/BadEofJpegTests.cs @@ -17,6 +17,7 @@ namespace ImageSharp.Tests using System.Numerics; using ImageSharp.Formats.Jpg; + using ImageSharp.PixelFormats; using ImageSharp.Processing; public class BadEOFJpegTests : MeasureFixture @@ -27,11 +28,11 @@ namespace ImageSharp.Tests } [Theory] - [WithFile(TestImages.Jpeg.Baseline.Bad.MissingEOF, PixelTypes.Color)] - public void LoadBaselineImage(TestImageProvider provider) - where TColor : struct, IPixel + [WithFile(TestImages.Jpeg.Baseline.Bad.MissingEOF, PixelTypes.Rgba32)] + public void LoadBaselineImage(TestImageProvider provider) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) { Assert.NotNull(image); provider.Utility.SaveTestOutputFile(image, "bmp"); @@ -39,11 +40,11 @@ namespace ImageSharp.Tests } [Theory] // TODO: #18 - [WithFile(TestImages.Jpeg.Progressive.Bad.BadEOF, PixelTypes.Color)] - public void LoadProgressiveImage(TestImageProvider provider) - where TColor : struct, IPixel + [WithFile(TestImages.Jpeg.Progressive.Bad.BadEOF, PixelTypes.Rgba32)] + public void LoadProgressiveImage(TestImageProvider provider) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) { Assert.NotNull(image); provider.Utility.SaveTestOutputFile(image, "bmp"); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index d83424b240..1bcc72c43b 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -10,6 +10,7 @@ namespace ImageSharp.Tests using System.IO; using ImageSharp.Formats; + using ImageSharp.PixelFormats; using Xunit; @@ -25,22 +26,22 @@ namespace ImageSharp.Tests public static string[] ProgressiveTestJpegs = TestImages.Jpeg.Progressive.All; [Theory] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32)] - public void OpenBaselineJpeg_SaveBmp(TestImageProvider provider) - where TColor : struct, IPixel + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32 | PixelTypes.StandardImageClass | PixelTypes.Argb32)] + public void OpenBaselineJpeg_SaveBmp(TestImageProvider provider) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) { provider.Utility.SaveTestOutputFile(image, "bmp"); } } [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32)] - public void OpenProgressiveJpeg_SaveBmp(TestImageProvider provider) - where TColor : struct, IPixel + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32 | PixelTypes.StandardImageClass | PixelTypes.Argb32)] + public void OpenProgressiveJpeg_SaveBmp(TestImageProvider provider) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) { provider.Utility.SaveTestOutputFile(image, "bmp"); } @@ -52,14 +53,14 @@ namespace ImageSharp.Tests [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.StandardImageClass, JpegSubsample.Ratio444, 75)] [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.StandardImageClass, JpegSubsample.Ratio444, 100)] [WithSolidFilledImages(8, 8, 255, 0, 0, PixelTypes.StandardImageClass, JpegSubsample.Ratio444, 100)] - public void DecodeGenerated_SaveBmp( - TestImageProvider provider, + public void DecodeGenerated_SaveBmp( + TestImageProvider provider, JpegSubsample subsample, int quality) - where TColor : struct, IPixel + where TPixel : struct, IPixel { byte[] data; - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) { JpegEncoder encoder = new JpegEncoder(); JpegEncoderOptions options = new JpegEncoderOptions { Subsample = subsample, Quality = quality }; @@ -72,18 +73,18 @@ namespace ImageSharp.Tests } // TODO: Automatic image comparers could help here a lot :P - Image mirror = provider.Factory.CreateImage(data); + Image mirror = provider.Factory.CreateImage(data); provider.Utility.TestName += $"_{subsample}_Q{quality}"; provider.Utility.SaveTestOutputFile(mirror, "bmp"); } [Theory] [WithSolidFilledImages(42, 88, 255, 0, 0, PixelTypes.StandardImageClass)] - public void DecodeGenerated_MetadataOnly( - TestImageProvider provider) - where TColor : struct, IPixel + public void DecodeGenerated_MetadataOnly( + TestImageProvider provider) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) { using (MemoryStream ms = new MemoryStream()) { @@ -92,7 +93,7 @@ namespace ImageSharp.Tests using (JpegDecoderCore decoder = new JpegDecoderCore(null, null)) { - Image mirror = decoder.Decode(ms); + Image mirror = decoder.Decode(ms); Assert.Equal(decoder.ImageWidth, image.Width); Assert.Equal(decoder.ImageHeight, image.Height); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs index f900fe782c..d5f7c2ea3f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs @@ -15,6 +15,7 @@ using Xunit.Abstractions; namespace ImageSharp.Tests { using ImageSharp.Formats.Jpg; + using ImageSharp.PixelFormats; using ImageSharp.Processing; public class JpegEncoderTests : MeasureFixture @@ -31,10 +32,10 @@ namespace ImageSharp.Tests [WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio420)] [WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio444)] [WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio444)] - public void LoadResizeSave(TestImageProvider provider, int quality, JpegSubsample subsample) - where TColor : struct, IPixel + public void LoadResizeSave(TestImageProvider provider, int quality, JpegSubsample subsample) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage().Resize(new ResizeOptions { Size = new Size(150, 100), Mode = ResizeMode.Max })) + using (Image image = provider.GetImage().Resize(new ResizeOptions { Size = new Size(150, 100), Mode = ResizeMode.Max })) { image.MetaData.Quality = quality; image.MetaData.ExifProfile = null; // Reduce the size of the file @@ -48,12 +49,12 @@ namespace ImageSharp.Tests } [Theory] - [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32, JpegSubsample.Ratio420, 75)] - [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32, JpegSubsample.Ratio444, 75)] - public void OpenBmp_SaveJpeg(TestImageProvider provider, JpegSubsample subSample, int quality) - where TColor : struct, IPixel + [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32 | PixelTypes.StandardImageClass | PixelTypes.Argb32, JpegSubsample.Ratio420, 75)] + [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32 | PixelTypes.StandardImageClass | PixelTypes.Argb32, JpegSubsample.Ratio444, 75)] + public void OpenBmp_SaveJpeg(TestImageProvider provider, JpegSubsample subSample, int quality) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) { ImagingTestCaseUtility utility = provider.Utility; utility.TestName += "_" + subSample + "_Q" + quality; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs index 28a64a765c..5150925b4f 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Tests using System.Numerics; using ImageSharp.Formats; + using ImageSharp.PixelFormats; using Xunit; using Xunit.Abstractions; @@ -69,9 +70,9 @@ namespace ImageSharp.Tests .Concat(new[] { TestImages.Jpeg.Baseline.Calliphora, TestImages.Jpeg.Baseline.Cmyk }) .ToArray(); - Image[] testImages = + Image[] testImages = testFiles.Select( - tf => TestImageProvider.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) + tf => TestImageProvider.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage()) .ToArray(); using (MemoryStream ms = new MemoryStream()) @@ -79,7 +80,7 @@ namespace ImageSharp.Tests this.Measure(executionCount, () => { - foreach (Image img in testImages) + foreach (Image img in testImages) { JpegEncoder encoder = new JpegEncoder(); JpegEncoderOptions options = new JpegEncoderOptions { Quality = quality, Subsample = subsample }; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs index 25fe46aa24..f242faf12c 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs @@ -10,16 +10,17 @@ namespace ImageSharp.Tests using System.Numerics; using ImageSharp.Formats.Jpg; + using ImageSharp.PixelFormats; using Xunit; public class JpegUtilsTests : TestBase { - public static Image CreateTestImage(GenericFactory factory) - where TColor : struct, IPixel + public static Image CreateTestImage(GenericFactory factory) + where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); - using (PixelAccessor pixels = image.Lock()) + Image image = factory.CreateImage(10, 10); + using (PixelAccessor pixels = image.Lock()) { for (int i = 0; i < 10; i++) { @@ -27,7 +28,7 @@ namespace ImageSharp.Tests { Vector4 v = new Vector4(i / 10f, j / 10f, 0, 1); - TColor color = default(TColor); + TPixel color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; @@ -39,15 +40,15 @@ namespace ImageSharp.Tests } [Theory] - [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32)] - public void CopyStretchedRGBTo_FromOrigo(TestImageProvider provider) - where TColor : struct, IPixel + [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgba32| PixelTypes.StandardImageClass | PixelTypes.Argb32)] + public void CopyStretchedRGBTo_FromOrigo(TestImageProvider provider) + where TPixel : struct, IPixel { - using (Image src = provider.GetImage()) - using (Image dest = provider.Factory.CreateImage(8, 8)) - using (PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz)) - using (PixelAccessor s = src.Lock()) - using (PixelAccessor d = dest.Lock()) + using (Image src = provider.GetImage()) + using (Image dest = provider.Factory.CreateImage(8, 8)) + using (PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz)) + using (PixelAccessor s = src.Lock()) + using (PixelAccessor d = dest.Lock()) { s.CopyRGBBytesStretchedTo(area, 0, 0); d.CopyFrom(area, 0, 0); @@ -61,15 +62,15 @@ namespace ImageSharp.Tests } [Theory] - [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.StandardImageClass | PixelTypes.Argb32)] - public void CopyStretchedRGBTo_WithOffset(TestImageProvider provider) - where TColor : struct, IPixel + [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgba32| PixelTypes.StandardImageClass | PixelTypes.Argb32)] + public void CopyStretchedRGBTo_WithOffset(TestImageProvider provider) + where TPixel : struct, IPixel { - using (Image src = provider.GetImage()) - using (PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz)) - using (Image dest = provider.Factory.CreateImage(8, 8)) - using (PixelAccessor s = src.Lock()) - using (PixelAccessor d = dest.Lock()) + using (Image src = provider.GetImage()) + using (PixelArea area = new PixelArea(8, 8, ComponentOrder.Xyz)) + using (Image dest = provider.Factory.CreateImage(8, 8)) + using (PixelAccessor s = src.Lock()) + using (PixelAccessor d = dest.Lock()) { s.CopyRGBBytesStretchedTo(area, 7, 6); d.CopyFrom(area, 0, 0); diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index 51cb0cdc00..ae4dfc1e9a 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -11,16 +11,18 @@ namespace ImageSharp.Tests using System.Linq; using System.Threading.Tasks; using ImageSharp.IO; + using ImageSharp.PixelFormats; + using Xunit; public class PngEncoderTests : FileTestBase { [Theory] [WithBlankImages(1, 1, PixelTypes.All)] - public void WritesFileMarker(TestImageProvider provider) - where TColor : struct, IPixel + public void WritesFileMarker(TestImageProvider provider) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) using (MemoryStream ms = new MemoryStream()) { image.Save(ms, new PngEncoder()); diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs index a7453f77ca..46ade9f9a6 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs @@ -15,15 +15,17 @@ namespace ImageSharp.Tests.Formats.Png using ImageSharp.IO; using System.Numerics; + using ImageSharp.PixelFormats; + public class PngSmokeTests { [Theory] [WithTestPatternImages(300, 300, PixelTypes.All)] - public void GeneralTest(TestImageProvider provider) - where TColor : struct, IPixel + public void GeneralTest(TestImageProvider provider) + where TPixel : struct, IPixel { // does saving a file then repoening mean both files are identical??? - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) using (MemoryStream ms = new MemoryStream()) { // image.Save(provider.Utility.GetTestOutputFileName("bmp")); @@ -40,11 +42,11 @@ namespace ImageSharp.Tests.Formats.Png [Theory] [WithTestPatternImages(100, 100, PixelTypes.All)] - public void CanSaveIndexedPng(TestImageProvider provider) - where TColor : struct, IPixel + public void CanSaveIndexedPng(TestImageProvider provider) + where TPixel : struct, IPixel { // does saving a file then repoening mean both files are identical??? - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) using (MemoryStream ms = new MemoryStream()) { // image.Save(provider.Utility.GetTestOutputFileName("bmp")); @@ -62,11 +64,11 @@ namespace ImageSharp.Tests.Formats.Png // JJS: Commented out for now since the test does not take into lossy nature of indexing. //[Theory] //[WithTestPatternImages(100, 100, PixelTypes.Color)] - //public void CanSaveIndexedPngTwice(TestImageProvider provider) - // where TColor : struct, IPixel + //public void CanSaveIndexedPngTwice(TestImageProvider provider) + // where TPixel : struct, IPixel //{ // // does saving a file then repoening mean both files are identical??? - // using (Image source = provider.GetImage()) + // using (Image source = provider.GetImage()) // using (MemoryStream ms = new MemoryStream()) // { // source.MetaData.Quality = 256; @@ -104,11 +106,11 @@ namespace ImageSharp.Tests.Formats.Png [Theory] [WithTestPatternImages(300, 300, PixelTypes.All)] - public void Resize(TestImageProvider provider) - where TColor : struct, IPixel + public void Resize(TestImageProvider provider) + where TPixel : struct, IPixel { // does saving a file then repoening mean both files are identical??? - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) using (MemoryStream ms = new MemoryStream()) { // image.Save(provider.Utility.GetTestOutputFileName("png")); diff --git a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs index 10b0cbb947..505074a6aa 100644 --- a/tests/ImageSharp.Tests/Image/ImageLoadTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageLoadTests.cs @@ -7,9 +7,10 @@ namespace ImageSharp.Tests { using System; using System.IO; - using System.Linq; + using ImageSharp.Formats; using ImageSharp.IO; + using ImageSharp.PixelFormats; using Moq; using Xunit; @@ -20,7 +21,7 @@ namespace ImageSharp.Tests { private readonly Mock fileSystem; private readonly IDecoderOptions decoderOptions; - private Image returnImage; + private Image returnImage; private Mock localDecoder; private Mock localFormat; private readonly string FilePath; @@ -44,7 +45,7 @@ namespace ImageSharp.Tests this.localFormat.Setup(x => x.IsSupportedFileFormat(It.IsAny())).Returns(true); this.localFormat.Setup(x => x.SupportedExtensions).Returns(new string[] { "png", "jpg" }); - this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny())) + this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((c, s, o) => { using (var ms = new MemoryStream()) @@ -103,10 +104,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromStreamWithType() { - Image img = Image.Load(this.DataStream); + Image img = Image.Load(this.DataStream); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -128,10 +129,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromStreamWithTypeAndOptions() { - Image img = Image.Load(this.DataStream, this.decoderOptions); + Image img = Image.Load(this.DataStream, this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -147,7 +148,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); } @@ -155,13 +156,13 @@ namespace ImageSharp.Tests public void LoadFromStreamWithTypeAndConfig() { Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream); + Image img = Image.Load(this.LocalConfiguration, stream); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, null)); } @@ -174,7 +175,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); } @@ -182,13 +183,13 @@ namespace ImageSharp.Tests public void LoadFromStreamWithTypeAndConfigAndOptions() { Stream stream = new MemoryStream(); - Image img = Image.Load(this.LocalConfiguration, stream, this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, stream, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream, this.decoderOptions)); } @@ -201,18 +202,18 @@ namespace ImageSharp.Tests Image img = Image.Load(stream, this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); } [Fact] public void LoadFromStreamWithTypeAndDecoder() { Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object); + Image img = Image.Load(stream, this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, null)); } [Fact] @@ -222,18 +223,18 @@ namespace ImageSharp.Tests Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); } [Fact] public void LoadFromStreamWithTypeAndDecoderAndOptions() { Stream stream = new MemoryStream(); - Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(stream, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream, this.decoderOptions)); } [Fact] @@ -252,10 +253,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithType() { - Image img = Image.Load(this.DataStream.ToArray()); + Image img = Image.Load(this.DataStream.ToArray()); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -277,10 +278,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndOptions() { - Image img = Image.Load(this.DataStream.ToArray(), this.decoderOptions); + Image img = Image.Load(this.DataStream.ToArray(), this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -295,7 +296,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -303,14 +304,14 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndConfig() { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); + Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -323,7 +324,7 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -331,13 +332,13 @@ namespace ImageSharp.Tests [Fact] public void LoadFromBytesWithTypeAndConfigAndOptions() { - Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray(), this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray(), this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -349,18 +350,18 @@ namespace ImageSharp.Tests Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } [Fact] public void LoadFromBytesWithTypeAndDecoder() { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); + Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), null)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -370,18 +371,18 @@ namespace ImageSharp.Tests Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } [Fact] public void LoadFromBytesWithTypeAndDecoderAndOptions() { - Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny(), this.decoderOptions)); Assert.Equal(this.DataStream.ToArray(), this.DecodedData); } @@ -401,10 +402,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithType() { - Image img = Image.Load(this.DataStream); + Image img = Image.Load(this.DataStream); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default); @@ -426,10 +427,10 @@ namespace ImageSharp.Tests [Fact] public void LoadFromFileWithTypeAndOptions() { - Image img = Image.Load(this.DataStream, this.decoderOptions); + Image img = Image.Load(this.DataStream, this.decoderOptions); Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); + Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat); TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, this.decoderOptions, Configuration.Default); @@ -444,20 +445,20 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); } [Fact] public void LoadFromFileWithTypeAndConfig() { - Image img = Image.Load(this.LocalConfiguration, this.FilePath); + Image img = Image.Load(this.LocalConfiguration, this.FilePath); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, null)); } @@ -469,20 +470,20 @@ namespace ImageSharp.Tests Assert.NotNull(img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); } [Fact] public void LoadFromFileWithTypeAndConfigAndOptions() { - Image img = Image.Load(this.LocalConfiguration, this.FilePath, this.decoderOptions); + Image img = Image.Load(this.LocalConfiguration, this.FilePath, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); Assert.Equal(this.localFormat.Object, img.CurrentImageFormat); - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream, this.decoderOptions)); } @@ -493,17 +494,17 @@ namespace ImageSharp.Tests Image img = Image.Load(this.FilePath, this.localDecoder.Object); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); } [Fact] public void LoadFromFileWithTypeAndDecoder() { - Image img = Image.Load(this.FilePath, this.localDecoder.Object); + Image img = Image.Load(this.FilePath, this.localDecoder.Object); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, null)); } [Fact] @@ -512,17 +513,17 @@ namespace ImageSharp.Tests Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); } [Fact] public void LoadFromFileWithTypeAndDecoderAndOptions() { - Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); + Image img = Image.Load(this.FilePath, this.localDecoder.Object, this.decoderOptions); Assert.NotNull(img); Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); + this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream, this.decoderOptions)); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs index 0d1c3e09b5..902bedb5e5 100644 --- a/tests/ImageSharp.Tests/Image/ImageSaveTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageSaveTests.cs @@ -10,6 +10,8 @@ namespace ImageSharp.Tests using System.Linq; using ImageSharp.Formats; using ImageSharp.IO; + using ImageSharp.PixelFormats; + using Moq; using Xunit; @@ -59,7 +61,7 @@ namespace ImageSharp.Tests this.fileSystem.Setup(x => x.Create("path.png")).Returns(stream); this.Image.Save("path.png"); - this.encoder.Verify(x => x.Encode(this.Image, stream, null)); + this.encoder.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -70,7 +72,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderOptions); - this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -81,7 +83,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -92,7 +94,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } @@ -105,7 +107,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -116,7 +118,7 @@ namespace ImageSharp.Tests this.Image.Save("path.jpg", this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -125,7 +127,7 @@ namespace ImageSharp.Tests Stream stream = new MemoryStream(); this.Image.Save(stream); - this.encoder.Verify(x => x.Encode(this.Image, stream, null)); + this.encoder.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -135,7 +137,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderOptions); - this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoder.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -145,7 +147,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderNotInFormat.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -155,7 +157,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.encoderNotInFormat.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } [Fact] @@ -165,7 +167,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.formatNotRegistered.Object); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, null)); } [Fact] @@ -175,7 +177,7 @@ namespace ImageSharp.Tests this.Image.Save(stream, this.formatNotRegistered.Object, this.encoderOptions); - this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); + this.encoderNotInFormat.Verify(x => x.Encode(this.Image, stream, this.encoderOptions)); } public void Dispose() diff --git a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs index cd9cd04b72..a6c4b4545d 100644 --- a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs +++ b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs @@ -8,6 +8,8 @@ namespace ImageSharp.Tests using System; using System.Numerics; + using ImageSharp.PixelFormats; + using Xunit; /// @@ -15,11 +17,11 @@ namespace ImageSharp.Tests /// public class PixelAccessorTests { - public static Image CreateTestImage(GenericFactory factory) - where TColor : struct, IPixel + public static Image CreateTestImage(GenericFactory factory) + where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); - using (PixelAccessor pixels = image.Lock()) + Image image = factory.CreateImage(10, 10); + using (PixelAccessor pixels = image.Lock()) { for (int i = 0; i < 10; i++) { @@ -28,7 +30,7 @@ namespace ImageSharp.Tests Vector4 v = new Vector4(i, j, 0, 1); v /= 10; - TColor color = default(TColor); + TPixel color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; @@ -43,21 +45,21 @@ namespace ImageSharp.Tests [WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.Zyx)] [WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.Xyzw)] [WithMemberFactory(nameof(CreateTestImage), PixelTypes.All, ComponentOrder.Zyxw)] - public void CopyTo_Then_CopyFrom_OnFullImageRect(TestImageProvider provider, ComponentOrder order) - where TColor : struct, IPixel + public void CopyTo_Then_CopyFrom_OnFullImageRect(TestImageProvider provider, ComponentOrder order) + where TPixel : struct, IPixel { - using (Image src = provider.GetImage()) + using (Image src = provider.GetImage()) { - using (Image dest = new Image(src.Width, src.Height)) + using (Image dest = new Image(src.Width, src.Height)) { - using (PixelArea area = new PixelArea(src.Width, src.Height, order)) + using (PixelArea area = new PixelArea(src.Width, src.Height, order)) { - using (PixelAccessor srcPixels = src.Lock()) + using (PixelAccessor srcPixels = src.Lock()) { srcPixels.CopyTo(area, 0, 0); } - using (PixelAccessor destPixels = dest.Lock()) + using (PixelAccessor destPixels = dest.Lock()) { destPixels.CopyFrom(area, 0, 0); } @@ -69,10 +71,10 @@ namespace ImageSharp.Tests } // TODO: Need a processor in the library with this signature - private static void Fill(Image image, Rectangle region, TColor color) - where TColor : struct, IPixel + private static void Fill(Image image, Rectangle region, TPixel color) + where TPixel : struct, IPixel { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { for (int y = region.Top; y < region.Bottom; y++) { @@ -89,21 +91,21 @@ namespace ImageSharp.Tests [WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.Zyx)] [WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.Xyzw)] [WithBlankImages(16, 16, PixelTypes.All, ComponentOrder.Zyxw)] - public void CopyToThenCopyFromWithOffset(TestImageProvider provider, ComponentOrder order) - where TColor : struct, IPixel + public void CopyToThenCopyFromWithOffset(TestImageProvider provider, ComponentOrder order) + where TPixel : struct, IPixel { - using (Image destImage = new Image(8, 8)) + using (Image destImage = new Image(8, 8)) { - using (Image srcImage = provider.GetImage()) + using (Image srcImage = provider.GetImage()) { - Fill(srcImage, new Rectangle(4, 4, 8, 8), NamedColors.Red); - using (PixelAccessor srcPixels = srcImage.Lock()) + Fill(srcImage, new Rectangle(4, 4, 8, 8), NamedColors.Red); + using (PixelAccessor srcPixels = srcImage.Lock()) { - using (PixelArea area = new PixelArea(8, 8, order)) + using (PixelArea area = new PixelArea(8, 8, order)) { srcPixels.CopyTo(area, 4, 4); - using (PixelAccessor destPixels = destImage.Lock()) + using (PixelAccessor destPixels = destImage.Lock()) { destPixels.CopyFrom(area, 0, 0); } @@ -114,7 +116,7 @@ namespace ImageSharp.Tests provider.Utility.SourceFileOrDescription = order.ToString(); provider.Utility.SaveTestOutputFile(destImage, "bmp"); - using (Image expectedImage = new Image(8, 8).Fill(NamedColors.Red)) + using (Image expectedImage = new Image(8, 8).Fill(NamedColors.Red)) { Assert.True(destImage.IsEquivalentTo(expectedImage)); } @@ -125,7 +127,7 @@ namespace ImageSharp.Tests [Fact] public void CopyFromZYX() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyFromZYX(image); } @@ -134,7 +136,7 @@ namespace ImageSharp.Tests [Fact] public void CopyFromZYXW() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyFromZYXW(image); } @@ -143,7 +145,7 @@ namespace ImageSharp.Tests [Fact] public void CopyToZYX() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyToZYX(image); } @@ -152,23 +154,23 @@ namespace ImageSharp.Tests [Fact] public void CopyToZYXW() { - using (Image image = new Image(1, 1)) + using (Image image = new Image(1, 1)) { CopyToZYXW(image); } } - private static void CopyFromZYX(Image image) - where TColor : struct, IPixel + private static void CopyFromZYX(Image image) + where TPixel : struct, IPixel { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { byte red = 1; byte green = 2; byte blue = 3; byte alpha = 255; - using (PixelArea row = new PixelArea(1, ComponentOrder.Zyx)) + using (PixelArea row = new PixelArea(1, ComponentOrder.Zyx)) { row.Bytes[0] = blue; row.Bytes[1] = green; @@ -176,7 +178,7 @@ namespace ImageSharp.Tests pixels.CopyFrom(row, 0); - Color color = (Color)(object)pixels[0, 0]; + Rgba32 color = (Rgba32)(object)pixels[0, 0]; Assert.Equal(red, color.R); Assert.Equal(green, color.G); Assert.Equal(blue, color.B); @@ -185,17 +187,17 @@ namespace ImageSharp.Tests } } - private static void CopyFromZYXW(Image image) - where TColor : struct, IPixel + private static void CopyFromZYXW(Image image) + where TPixel : struct, IPixel { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { byte red = 1; byte green = 2; byte blue = 3; byte alpha = 4; - using (PixelArea row = new PixelArea(1, ComponentOrder.Zyxw)) + using (PixelArea row = new PixelArea(1, ComponentOrder.Zyxw)) { row.Bytes[0] = blue; row.Bytes[1] = green; @@ -204,7 +206,7 @@ namespace ImageSharp.Tests pixels.CopyFrom(row, 0); - Color color = (Color)(object)pixels[0, 0]; + Rgba32 color = (Rgba32)(object)pixels[0, 0]; Assert.Equal(red, color.R); Assert.Equal(green, color.G); Assert.Equal(blue, color.B); @@ -213,18 +215,18 @@ namespace ImageSharp.Tests } } - private static void CopyToZYX(Image image) - where TColor : struct, IPixel + private static void CopyToZYX(Image image) + where TPixel : struct, IPixel { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { byte red = 1; byte green = 2; byte blue = 3; - using (PixelArea row = new PixelArea(1, ComponentOrder.Zyx)) + using (PixelArea row = new PixelArea(1, ComponentOrder.Zyx)) { - pixels[0, 0] = (TColor)(object)new Color(red, green, blue); + pixels[0, 0] = (TPixel)(object)new Rgba32(red, green, blue); pixels.CopyTo(row, 0); @@ -235,19 +237,19 @@ namespace ImageSharp.Tests } } - private static void CopyToZYXW(Image image) - where TColor : struct, IPixel + private static void CopyToZYXW(Image image) + where TPixel : struct, IPixel { - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { byte red = 1; byte green = 2; byte blue = 3; byte alpha = 4; - using (PixelArea row = new PixelArea(1, ComponentOrder.Zyxw)) + using (PixelArea row = new PixelArea(1, ComponentOrder.Zyxw)) { - pixels[0, 0] = (TColor)(object)new Color(red, green, blue, alpha); + pixels[0, 0] = (TPixel)(object)new Rgba32(red, green, blue, alpha); pixels.CopyTo(row, 0); diff --git a/tests/ImageSharp.Tests/ImageComparer.cs b/tests/ImageSharp.Tests/ImageComparer.cs index 41b884dd43..7d0a8377d3 100644 --- a/tests/ImageSharp.Tests/ImageComparer.cs +++ b/tests/ImageSharp.Tests/ImageComparer.cs @@ -2,6 +2,8 @@ { using System; using ImageSharp; + using ImageSharp.PixelFormats; + using Xunit; /// @@ -16,8 +18,8 @@ /// /// Does a visual comparison between 2 images and then asserts the difference is less then a configurable threshold /// - /// The color of the expected image - /// The color type fo the the actual image + /// The color of the expected image + /// The color type fo the the actual image /// The expected image /// The actual image /// @@ -32,9 +34,9 @@ /// This is a sampling factor we sample a grid of average pixels width by high /// The default undefined value is /// - public static void CheckSimilarity(Image expected, Image actual, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor) - where TColorA : struct, IPixel - where TColorB : struct, IPixel + public static void CheckSimilarity(Image expected, Image actual, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor) + where TPixelA : struct, IPixel + where TPixelB : struct, IPixel { float percentage = expected.PercentageDifference(actual, segmentThreshold, scalingFactor); @@ -44,8 +46,8 @@ /// /// Does a visual comparison between 2 images and then and returns the percentage diffence between the 2 /// - /// The color of the source image - /// The color type for the target image + /// The color of the source image + /// The color type for the target image /// The source image /// The target image /// @@ -57,9 +59,9 @@ /// The default undefined value is /// /// Returns a number from 0 - 1 which represents the diference focter between the images. - public static float PercentageDifference(this Image source, Image target, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor) - where TColorA : struct, IPixel - where TColorB : struct, IPixel + public static float PercentageDifference(this Image source, Image target, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor) + where TPixelA : struct, IPixel + where TPixelB : struct, IPixel { // code adapted from https://www.codeproject.com/Articles/374386/Simple-image-comparison-in-NET Fast2DArray differences = GetDifferences(source, target, scalingFactor); @@ -74,9 +76,9 @@ return diffPixels / (scalingFactor * scalingFactor); } - private static Fast2DArray GetDifferences(Image source, Image target, int scalingFactor) - where TColorA : struct, IPixel - where TColorB : struct, IPixel + private static Fast2DArray GetDifferences(Image source, Image target, int scalingFactor) + where TPixelA : struct, IPixel + where TPixelB : struct, IPixel { Fast2DArray differences = new Fast2DArray(scalingFactor, scalingFactor); Fast2DArray firstGray = source.GetGrayScaleValues(scalingFactor); @@ -93,13 +95,13 @@ return differences; } - private static Fast2DArray GetGrayScaleValues(this Image source, int scalingFactor) - where TColorA : struct, IPixel + private static Fast2DArray GetGrayScaleValues(this Image source, int scalingFactor) + where TPixelA : struct, IPixel { byte[] buffer = new byte[4]; - using (Image img = new Image(source).Resize(scalingFactor, scalingFactor).Grayscale()) + using (Image img = new Image(source).Resize(scalingFactor, scalingFactor).Grayscale()) { - using (PixelAccessor pixels = img.Lock()) + using (PixelAccessor pixels = img.Lock()) { Fast2DArray grayScale = new Fast2DArray(scalingFactor, scalingFactor); for (int y = 0; y < scalingFactor; y++) diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs index f380724df0..6a832859aa 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs @@ -10,6 +10,9 @@ namespace ImageSharp.Tests using System.IO; using System.Linq; using System.Text; + + using ImageSharp.PixelFormats; + using Xunit; public class ExifProfileTests @@ -243,7 +246,7 @@ namespace ImageSharp.Tests TestProfile(profile); - Image thumbnail = profile.CreateThumbnail(); + Image thumbnail = profile.CreateThumbnail(); Assert.NotNull(thumbnail); Assert.Equal(256, thumbnail.Width); Assert.Equal(170, thumbnail.Height); diff --git a/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs index fd08b87a47..eccfc13af3 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class BackgroundColorTest : FileTestBase @@ -21,7 +23,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{file.FileName}")) { - image.BackgroundColor(Color.HotPink).Save(output); + image.BackgroundColor(Rgba32.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs b/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs index 1afb1300a9..ad10488459 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class GlowTest : FileTestBase @@ -37,7 +39,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { - image.Glow(Color.HotPink).Save(output); + image.Glow(Rgba32.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/Processors/Filters/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processors/Filters/GrayscaleTest.cs index 97947a7874..2b717a0b79 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/GrayscaleTest.cs @@ -12,6 +12,8 @@ namespace ImageSharp.Tests using ImageSharp.Tests; using System.Numerics; + using ImageSharp.PixelFormats; + public class GrayscaleTest : FileTestBase { /// @@ -20,14 +22,14 @@ namespace ImageSharp.Tests [Theory] [WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt709)] [WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt601)] - public void ImageShouldApplyGrayscaleFilterAll(TestImageProvider provider, GrayscaleMode value) - where TColor : struct, IPixel + public void ImageShouldApplyGrayscaleFilterAll(TestImageProvider provider, GrayscaleMode value) + where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) + using (Image image = provider.GetImage()) { image.Grayscale(value); byte[] data = new byte[3]; - foreach (TColor p in image.Pixels) + foreach (TPixel p in image.Pixels) { p.ToXyzBytes(data, 0); Assert.Equal(data[0], data[1]); diff --git a/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs index da09aa85e7..917bb895c5 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs @@ -3,6 +3,7 @@ namespace ImageSharp.Tests using System.IO; using System.Text; + using ImageSharp.PixelFormats; using ImageSharp.Processing; using ImageSharp.Processing.Processors; @@ -36,13 +37,13 @@ namespace ImageSharp.Tests // [Fact] public void PrintWeightsData() { - ResizeProcessor proc = new ResizeProcessor(new BicubicResampler(), 200, 200); + ResizeProcessor proc = new ResizeProcessor(new BicubicResampler(), 200, 200); - ResamplingWeightedProcessor.WeightsBuffer weights = proc.PrecomputeWeights(200, 500); + ResamplingWeightedProcessor.WeightsBuffer weights = proc.PrecomputeWeights(200, 500); StringBuilder bld = new StringBuilder(); - foreach (ResamplingWeightedProcessor.WeightsWindow window in weights.Weights) + foreach (ResamplingWeightedProcessor.WeightsWindow window in weights.Weights) { for (int i = 0; i < window.Length; i++) { diff --git a/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs b/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs index 7f40ef1d21..89794aeaf8 100644 --- a/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processors/Filters/VignetteTest.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System.IO; + using ImageSharp.PixelFormats; + using Xunit; public class VignetteTest : FileTestBase @@ -37,7 +39,7 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) using (FileStream output = File.OpenWrite($"{path}/{filename}")) { - image.Vignette(Color.HotPink).Save(output); + image.Vignette(Rgba32.HotPink).Save(output); } } } diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs index 084ad59938..318df5ead3 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -12,6 +12,8 @@ namespace ImageSharp.Tests using System.Linq; using System.Reflection; using ImageSharp.Formats; + using ImageSharp.PixelFormats; + using Xunit; /// @@ -68,17 +70,17 @@ namespace ImageSharp.Tests } } - public Image Sample() - where TColor : struct, IPixel + public Image Sample() + where TPixel : struct, IPixel { lock (this._sampleImages) { - if (!this._sampleImages.ContainsKey(typeof(TColor))) + if (!this._sampleImages.ContainsKey(typeof(TPixel))) { - this._sampleImages.Add(typeof(TColor), new Image(1, 1)); + this._sampleImages.Add(typeof(TPixel), new Image(1, 1)); } - return (Image)this._sampleImages[typeof(TColor)]; + return (Image)this._sampleImages[typeof(TPixel)]; } } @@ -149,7 +151,7 @@ namespace ImageSharp.Tests } - public Image Decode(Configuration config, Stream stream, IDecoderOptions options) where TColor : struct, IPixel + public Image Decode(Configuration config, Stream stream, IDecoderOptions options) where TPixel : struct, IPixel { var ms = new MemoryStream(); @@ -163,7 +165,7 @@ namespace ImageSharp.Tests }); // TODO record this happend so we an verify it. - return this.testFormat.Sample(); + return this.testFormat.Sample(); } } @@ -176,7 +178,7 @@ namespace ImageSharp.Tests this.testFormat = testFormat; } - public void Encode(Image image, Stream stream, IEncoderOptions options) where TColor : struct, IPixel + public void Encode(Image image, Stream stream, IEncoderOptions options) where TPixel : struct, IPixel { // TODO record this happend so we an verify it. } diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs index 206393e274..ffbd1b888e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs @@ -13,7 +13,7 @@ namespace ImageSharp.Tests using Xunit.Sdk; /// - /// Base class for Theory Data attributes which pass an instance of to the test case. + /// Base class for Theory Data attributes which pass an instance of to the test case. /// public abstract class ImageDataAttributeBase : DataAttribute { diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs index e1f8f4c551..25d3c8cac1 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs @@ -9,13 +9,13 @@ namespace ImageSharp.Tests using System.Reflection; /// - /// Triggers passing instances which produce a blank image of size width * height. - /// One instance will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which produce a blank image of size width * height. + /// One instance will be passed for each the pixel format defined by the pixelTypes parameter /// public class WithBlankImagesAttribute : ImageDataAttributeBase { /// - /// Triggers passing an that produces a blank image of size width * height + /// Triggers passing an that produces a blank image of size width * height /// /// The required width /// The required height diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileAttribute.cs index 617a9a2374..752c114e56 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileAttribute.cs @@ -9,16 +9,16 @@ namespace ImageSharp.Tests using System.Reflection; /// - /// Triggers passing instances which read an image from the given file - /// One instance will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which read an image from the given file + /// One instance will be passed for each the pixel format defined by the pixelTypes parameter /// public class WithFileAttribute : ImageDataAttributeBase { private readonly string fileName; /// - /// Triggers passing instances which read an image from the given file - /// One instance will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which read an image from the given file + /// One instance will be passed for each the pixel format defined by the pixelTypes parameter /// /// The name of the file /// The requested pixel types diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs index be0fa7b3f9..3bd93e6096 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs @@ -11,16 +11,16 @@ namespace ImageSharp.Tests using System.Reflection; /// - /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName - /// instances will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName + /// instances will be passed for each the pixel format defined by the pixelTypes parameter /// public class WithFileCollectionAttribute : ImageDataAttributeBase { private readonly string enumeratorMemberName; /// - /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName - /// instances will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which read an image for each file being enumerated by the (static) test class field/property defined by enumeratorMemberName + /// instances will be passed for each the pixel format defined by the pixelTypes parameter /// /// The name of the static test class field/property enumerating the files /// The requested pixel types diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs index fa5e57dd09..661640f661 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs @@ -10,17 +10,17 @@ namespace ImageSharp.Tests using System.Reflection; /// - /// Triggers passing instances which return the image produced by the given test class member method - /// instances will be passed for each the pixel format defined by the pixelTypes parameter - /// The parameter of the factory method must be a instance + /// Triggers passing instances which return the image produced by the given test class member method + /// instances will be passed for each the pixel format defined by the pixelTypes parameter + /// The parameter of the factory method must be a instance /// public class WithMemberFactoryAttribute : ImageDataAttributeBase { private readonly string memberMethodName; /// - /// Triggers passing instances which return the image produced by the given test class member method - /// instances will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which return the image produced by the given test class member method + /// instances will be passed for each the pixel format defined by the pixelTypes parameter /// /// The name of the static test class which returns the image /// The requested pixel types diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs index d225f8a776..9a8538e78b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs @@ -9,14 +9,14 @@ namespace ImageSharp.Tests using System.Reflection; /// - /// Triggers passing instances which produce an image of size width * height filled with the requested color. - /// One instance will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which produce an image of size width * height filled with the requested color. + /// One instance will be passed for each the pixel format defined by the pixelTypes parameter /// public class WithSolidFilledImagesAttribute : WithBlankImagesAttribute { /// - /// Triggers passing instances which produce an image of size width * height filled with the requested color. - /// One instance will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which produce an image of size width * height filled with the requested color. + /// One instance will be passed for each the pixel format defined by the pixelTypes parameter /// /// The width of the requested image /// The height of the requested image @@ -38,8 +38,8 @@ namespace ImageSharp.Tests } /// - /// Triggers passing instances which produce an image of size width * height filled with the requested color. - /// One instance will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which produce an image of size width * height filled with the requested color. + /// One instance will be passed for each the pixel format defined by the pixelTypes parameter /// /// The width of the requested image /// The height of the requested image diff --git a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs index 98bc45f5b2..f2d2aeb88d 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs @@ -9,13 +9,13 @@ namespace ImageSharp.Tests using System.Reflection; /// - /// Triggers passing instances which produce a blank image of size width * height. - /// One instance will be passed for each the pixel format defined by the pixelTypes parameter + /// Triggers passing instances which produce a blank image of size width * height. + /// One instance will be passed for each the pixel format defined by the pixelTypes parameter /// public class WithTestPatternImagesAttribute : ImageDataAttributeBase { /// - /// Triggers passing an that produces a test pattern image of size width * height + /// Triggers passing an that produces a test pattern image of size width * height /// /// The required width /// The required height diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs index c2fe0dc5c2..4a0950788d 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs @@ -7,26 +7,28 @@ namespace ImageSharp.Tests { using System; + using ImageSharp.PixelFormats; + /// /// Utility class to create specialized subclasses of generic classes (eg. ) /// Used as parameter for -based factory methods /// - public class GenericFactory - where TColor : struct, IPixel + public class GenericFactory + where TPixel : struct, IPixel { - public virtual Image CreateImage(int width, int height) + public virtual Image CreateImage(int width, int height) { - return new Image(width, height); + return new Image(width, height); } - public virtual Image CreateImage(byte[] bytes) + public virtual Image CreateImage(byte[] bytes) { - return Image.Load(bytes); + return Image.Load(bytes); } - public virtual Image CreateImage(Image other) + public virtual Image CreateImage(Image other) { - return new Image(other); + return new Image(other); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs index 2361bc01ce..c4d758bd6c 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs @@ -5,13 +5,15 @@ namespace ImageSharp.Tests { - public class ImageFactory : GenericFactory + using ImageSharp.PixelFormats; + + public class ImageFactory : GenericFactory { - public override Image CreateImage(byte[] bytes) => Image.Load(bytes); + public override Image CreateImage(byte[] bytes) => Image.Load(bytes); - public override Image CreateImage(int width, int height) => new Image(width, height); + public override Image CreateImage(int width, int height) => new Image(width, height); - public override Image CreateImage(Image other) + public override Image CreateImage(Image other) { Image img = (Image)other; return new Image(img); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs index 6dc0d89c52..4252a60b5e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/BlankProvider.cs @@ -6,12 +6,15 @@ namespace ImageSharp.Tests { using System; + + using ImageSharp.PixelFormats; + using Xunit.Abstractions; - public abstract partial class TestImageProvider - where TColor : struct, IPixel + public abstract partial class TestImageProvider + where TPixel : struct, IPixel { - private class BlankProvider : TestImageProvider, IXunitSerializable + private class BlankProvider : TestImageProvider, IXunitSerializable { public BlankProvider(int width, int height) { @@ -30,7 +33,7 @@ namespace ImageSharp.Tests protected int Width { get; private set; } - public override Image GetImage() => this.Factory.CreateImage(this.Width, this.Height); + public override Image GetImage() => this.Factory.CreateImage(this.Width, this.Height); public override void Deserialize(IXunitSerializationInfo info) diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs index bc18209f32..4217d52b06 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/FileProvider.cs @@ -7,14 +7,17 @@ namespace ImageSharp.Tests { using System; using System.Collections.Concurrent; + + using ImageSharp.PixelFormats; + using Xunit.Abstractions; - public abstract partial class TestImageProvider - where TColor : struct, IPixel + public abstract partial class TestImageProvider + where TPixel : struct, IPixel { - private class FileProvider : TestImageProvider, IXunitSerializable + private class FileProvider : TestImageProvider, IXunitSerializable { - // Need PixelTypes in the dictionary key, because result images of TestImageProvider.FileProvider + // Need PixelTypes in the dictionary key, because result images of TestImageProvider.FileProvider // are shared between PixelTypes.Color & PixelTypes.StandardImageClass private class Key : Tuple { @@ -24,8 +27,8 @@ namespace ImageSharp.Tests } } - private static ConcurrentDictionary> cache = - new ConcurrentDictionary>(); + private static ConcurrentDictionary> cache = + new ConcurrentDictionary>(); private string filePath; @@ -40,11 +43,11 @@ namespace ImageSharp.Tests public override string SourceFileOrDescription => this.filePath; - public override Image GetImage() + public override Image GetImage() { Key key = new Key(this.PixelType, this.filePath); - Image cachedImage = cache.GetOrAdd( + Image cachedImage = cache.GetOrAdd( key, fn => { diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs index 9addc8ca6c..30e7a63b50 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/LambdaProvider.cs @@ -7,23 +7,25 @@ namespace ImageSharp.Tests { using System; + using ImageSharp.PixelFormats; + /// - /// Provides instances for parametric unit tests. + /// Provides instances for parametric unit tests. /// - /// The pixel format of the image - public abstract partial class TestImageProvider - where TColor : struct, IPixel + /// The pixel format of the image + public abstract partial class TestImageProvider + where TPixel : struct, IPixel { - private class LambdaProvider : TestImageProvider + private class LambdaProvider : TestImageProvider { - private readonly Func, Image> creator; + private readonly Func, Image> creator; - public LambdaProvider(Func, Image> creator) + public LambdaProvider(Func, Image> creator) { this.creator = creator; } - public override Image GetImage() => this.creator(this.Factory); + public override Image GetImage() => this.creator(this.Factory); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs index 9a67508721..65d55da554 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs @@ -6,14 +6,17 @@ namespace ImageSharp.Tests { using System; + + using ImageSharp.PixelFormats; + using Xunit.Abstractions; /// - /// Provides instances for parametric unit tests. + /// Provides instances for parametric unit tests. /// - /// The pixel format of the image - public abstract partial class TestImageProvider - where TColor : struct, IPixel + /// The pixel format of the image + public abstract partial class TestImageProvider + where TPixel : struct, IPixel { private class SolidProvider : BlankProvider { @@ -46,10 +49,10 @@ namespace ImageSharp.Tests public override string SourceFileOrDescription => $"Solid{this.Width}x{this.Height}_({this.r},{this.g},{this.b},{this.a})"; - public override Image GetImage() + public override Image GetImage() { - Image image = base.GetImage(); - TColor color = default(TColor); + Image image = base.GetImage(); + TPixel color = default(TPixel); color.PackFromBytes(this.r, this.g, this.b, this.a); return image.Fill(color); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 26192ba1e1..9d6f46b72e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -7,16 +7,19 @@ namespace ImageSharp.Tests { using System; using System.Reflection; + + using ImageSharp.PixelFormats; + using Xunit.Abstractions; /// - /// Provides instances for parametric unit tests. + /// Provides instances for parametric unit tests. /// - /// The pixel format of the image - public abstract partial class TestImageProvider - where TColor : struct, IPixel + /// The pixel format of the image + public abstract partial class TestImageProvider + where TPixel : struct, IPixel { - public PixelTypes PixelType { get; private set; } = typeof(TColor).GetPixelType(); + public PixelTypes PixelType { get; private set; } = typeof(TPixel).GetPixelType(); public virtual string SourceFileOrDescription => ""; @@ -25,25 +28,25 @@ namespace ImageSharp.Tests /// public ImagingTestCaseUtility Utility { get; private set; } - public GenericFactory Factory { get; private set; } = new GenericFactory(); + public GenericFactory Factory { get; private set; } = new GenericFactory(); public string TypeName { get; private set; } public string MethodName { get; private set; } - public static TestImageProvider TestPattern( + public static TestImageProvider TestPattern( int width, int height, MethodInfo testMethod = null, PixelTypes pixelTypeOverride = PixelTypes.Undefined) => new TestPatternProvider(width, height).Init(testMethod, pixelTypeOverride); - public static TestImageProvider Blank( + public static TestImageProvider Blank( int width, int height, MethodInfo testMethod = null, PixelTypes pixelTypeOverride = PixelTypes.Undefined) => new BlankProvider(width, height).Init(testMethod, pixelTypeOverride); - public static TestImageProvider File( + public static TestImageProvider File( string filePath, MethodInfo testMethod = null, PixelTypes pixelTypeOverride = PixelTypes.Undefined) @@ -51,13 +54,13 @@ namespace ImageSharp.Tests return new FileProvider(filePath).Init(testMethod, pixelTypeOverride); } - public static TestImageProvider Lambda( - Func, Image> func, + public static TestImageProvider Lambda( + Func, Image> func, MethodInfo testMethod = null, PixelTypes pixelTypeOverride = PixelTypes.Undefined) => new LambdaProvider(func).Init(testMethod, pixelTypeOverride); - public static TestImageProvider Solid( + public static TestImageProvider Solid( int width, int height, byte r, @@ -71,9 +74,9 @@ namespace ImageSharp.Tests } /// - /// Returns an instance to the test case with the necessary traits. + /// Returns an instance to the test case with the necessary traits. /// - public abstract Image GetImage(); + public abstract Image GetImage(); public virtual void Deserialize(IXunitSerializationInfo info) { @@ -91,7 +94,7 @@ namespace ImageSharp.Tests info.AddValue("MethodName", this.MethodName); } - protected TestImageProvider Init(string typeName, string methodName, PixelTypes pixelTypeOverride) + protected TestImageProvider Init(string typeName, string methodName, PixelTypes pixelTypeOverride) { if (pixelTypeOverride != PixelTypes.Undefined) { @@ -102,7 +105,7 @@ namespace ImageSharp.Tests if (pixelTypeOverride == PixelTypes.StandardImageClass) { - this.Factory = new ImageFactory() as GenericFactory; + this.Factory = new ImageFactory() as GenericFactory; } this.Utility = new ImagingTestCaseUtility() @@ -119,7 +122,7 @@ namespace ImageSharp.Tests return this; } - protected TestImageProvider Init(MethodInfo testMethod, PixelTypes pixelTypeOverride) + protected TestImageProvider Init(MethodInfo testMethod, PixelTypes pixelTypeOverride) { return Init(testMethod?.DeclaringType.Name, testMethod?.Name, pixelTypeOverride); } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index c40abd9345..96d38fc401 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -8,19 +8,22 @@ namespace ImageSharp.Tests using System; using System.Collections.Generic; using System.Numerics; + + using ImageSharp.PixelFormats; + using Xunit.Abstractions; - public abstract partial class TestImageProvider - where TColor : struct, IPixel + public abstract partial class TestImageProvider + where TPixel : struct, IPixel { /// /// A test image provider that produces test patterns. /// - /// + /// private class TestPatternProvider : BlankProvider { - static Dictionary> testImages = new Dictionary>(); + static Dictionary> testImages = new Dictionary>(); public TestPatternProvider(int width, int height) : base(width, height) @@ -34,29 +37,29 @@ namespace ImageSharp.Tests public override string SourceFileOrDescription => $"TestPattern{this.Width}x{this.Height}"; - public override Image GetImage() + public override Image GetImage() { lock (testImages) { if (!testImages.ContainsKey(this.SourceFileOrDescription)) { - Image image = new Image(this.Width, this.Height); + Image image = new Image(this.Width, this.Height); DrawTestPattern(image); testImages.Add(this.SourceFileOrDescription, image); } } - return new Image(testImages[this.SourceFileOrDescription]); + return new Image(testImages[this.SourceFileOrDescription]); } /// /// Draws the test pattern on an image by drawing 4 other patterns in the for quadrants of the image. /// /// - private static void DrawTestPattern(Image image) + private static void DrawTestPattern(Image image) { // first lets split the image into 4 quadrants - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { BlackWhiteChecker(pixels); // top left VirticalBars(pixels); // top right @@ -68,7 +71,7 @@ namespace ImageSharp.Tests /// Fills the top right quadrant with alternating solid vertical bars. /// /// - private static void VirticalBars(PixelAccessor pixels) + private static void VirticalBars(PixelAccessor pixels) { // topLeft int left = pixels.Width / 2; @@ -76,9 +79,9 @@ namespace ImageSharp.Tests int top = 0; int bottom = pixels.Height / 2; int stride = pixels.Width / 12; - TColor[] c = { - NamedColors.HotPink, - NamedColors.Blue + TPixel[] c = { + NamedColors.HotPink, + NamedColors.Blue }; int p = 0; for (int y = top; y < bottom; y++) @@ -99,7 +102,7 @@ namespace ImageSharp.Tests /// fills the top left quadrant with a black and white checker board. /// /// - private static void BlackWhiteChecker(PixelAccessor pixels) + private static void BlackWhiteChecker(PixelAccessor pixels) { // topLeft int left = 0; @@ -107,9 +110,9 @@ namespace ImageSharp.Tests int top = 0; int bottom = pixels.Height / 2; int stride = pixels.Width / 6; - TColor[] c = { - NamedColors.Black, - NamedColors.White + TPixel[] c = { + NamedColors.Black, + NamedColors.White }; int p = 0; @@ -138,7 +141,7 @@ namespace ImageSharp.Tests /// Fills the bottom left quadrent with 3 horizental bars in Red, Green and Blue with a alpha gradient from left (transparent) to right (solid). /// /// - private static void TransparentGradients(PixelAccessor pixels) + private static void TransparentGradients(PixelAccessor pixels) { // topLeft int left = 0; @@ -147,11 +150,11 @@ namespace ImageSharp.Tests int bottom = pixels.Height; int height = (int)Math.Ceiling(pixels.Height / 6f); - Vector4 red = Color.Red.ToVector4(); // use real color so we can see har it translates in the test pattern - Vector4 green = Color.Green.ToVector4(); // use real color so we can see har it translates in the test pattern - Vector4 blue = Color.Blue.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 red = Rgba32.Red.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 green = Rgba32.Green.ToVector4(); // use real color so we can see har it translates in the test pattern + Vector4 blue = Rgba32.Blue.ToVector4(); // use real color so we can see har it translates in the test pattern - TColor c = default(TColor); + TPixel c = default(TPixel); for (int x = left; x < right; x++) { @@ -183,7 +186,7 @@ namespace ImageSharp.Tests /// A better algorithm could be used but it works /// /// - private static void Rainbow(PixelAccessor pixels) + private static void Rainbow(PixelAccessor pixels) { int left = pixels.Width / 2; int right = pixels.Width; @@ -192,8 +195,8 @@ namespace ImageSharp.Tests int pixelCount = left * top; uint stepsPerPixel = (uint)(uint.MaxValue / pixelCount); - TColor c = default(TColor); - Color t = new Color(0); + TPixel c = default(TPixel); + Rgba32 t = new Rgba32(0); for (int x = left; x < right; x++) for (int y = top; y < bottom; y++) diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index 9fd33d90b6..6476c4ecf9 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Tests using System.Reflection; using ImageSharp.Formats; + using ImageSharp.PixelFormats; /// /// Utility class to provide information about the test image & the test case for the test code, @@ -19,12 +20,12 @@ namespace ImageSharp.Tests public class ImagingTestCaseUtility : TestBase { /// - /// Name of the TColor in the owner + /// Name of the TPixel in the owner /// public string PixelTypeName { get; set; } = string.Empty; /// - /// The name of the file which is provided by + /// The name of the file which is provided by /// Or a short string describing the image in the case of a non-file based image provider. /// public string SourceFileOrDescription { get; set; } = string.Empty; @@ -91,13 +92,13 @@ namespace ImageSharp.Tests /// /// Encodes image by the format matching the required extension, than saves it to the recommended output file. /// - /// The pixel format of the image + /// The pixel format of the image /// The image instance /// The requested extension /// Optional encoder /// Optional encoder options - public void SaveTestOutputFile(Image image, string extension = null, IImageEncoder encoder = null, IEncoderOptions options = null) - where TColor : struct, IPixel + public void SaveTestOutputFile(Image image, string extension = null, IImageEncoder encoder = null, IEncoderOptions options = null) + where TPixel : struct, IPixel { string path = this.GetTestOutputFileName(extension); extension = Path.GetExtension(path); diff --git a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs index 92a16563a9..77c13f1252 100644 --- a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs +++ b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs @@ -9,7 +9,7 @@ namespace ImageSharp.Tests /// /// Flags that are mapped to PackedPixel types. - /// They trigger the desired parametrization for . + /// They trigger the desired parametrization for . /// [Flags] public enum PixelTypes : uint @@ -26,32 +26,34 @@ namespace ImageSharp.Tests Byte4 = 1 << 4, - Color = 1 << 5, + HalfSingle = 1 << 5, - HalfSingle = 1 << 6, + HalfVector2 = 1 << 6, - HalfVector2 = 1 << 7, + HalfVector4 = 1 << 7, - HalfVector4 = 1 << 8, + NormalizedByte2 = 1 << 8, - NormalizedByte2 = 1 << 9, + NormalizedByte4 = 1 << 9, - NormalizedByte4 = 1 << 10, + NormalizedShort4 = 1 << 10, - NormalizedShort4 = 1 << 11, + Rg32 = 1 << 11, - Rg32 = 1 << 12, + Rgba1010102 = 1 << 12, - Rgba1010102 = 1 << 13, + Rgba32 = 1 << 13, Rgba64 = 1 << 14, - Short2 = 1 << 15, + RgbaVector = 1 << 15, - Short4 = 1 << 16, + Short2 = 1 << 16, + + Short4 = 1 << 17, /// - /// Triggers instantiating the subclass of + /// Triggers instantiating the subclass of /// StandardImageClass = 1 << 29, diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index e2bc2bd2d7..5408d5362b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -5,10 +5,12 @@ namespace ImageSharp.Tests using System.Collections.Generic; using System.Text; + using ImageSharp.PixelFormats; + public static class TestImageExtensions { - public static void DebugSave(this Image img, TestImageProvider provider, string extension = "png") - where TColor : struct, IPixel + public static void DebugSave(this Image img, TestImageProvider provider, string extension = "png") + where TPixel : struct, IPixel { if(!bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCI) || !isCI) { diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs index 260a677d3d..de05e83a9f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtilityExtensions.cs @@ -11,6 +11,8 @@ namespace ImageSharp.Tests using System.Linq; using System.Reflection; + using ImageSharp.PixelFormats; + /// /// Extension methods for TestUtilities /// @@ -18,7 +20,7 @@ namespace ImageSharp.Tests { private static readonly Dictionary ClrTypes2PixelTypes = new Dictionary(); - private static readonly Assembly ImageSharpAssembly = typeof(Color).GetTypeInfo().Assembly; + private static readonly Assembly ImageSharpAssembly = typeof(Rgba32).GetTypeInfo().Assembly; private static readonly Dictionary PixelTypes2ClrTypes = new Dictionary(); @@ -28,8 +30,8 @@ namespace ImageSharp.Tests static TestUtilityExtensions() { - string nameSpace = typeof(Color).FullName; - nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Color).Name.Length - 1); + string nameSpace = typeof(Rgba32).FullName; + nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Rgba32).Name.Length - 1); foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.StandardImageClass)) { string typeName = $"{nameSpace}.{pt.ToString()}"; @@ -42,13 +44,13 @@ namespace ImageSharp.Tests PixelTypes2ClrTypes[pt] = t; ClrTypes2PixelTypes[t] = pt; } - PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Color); + PixelTypes2ClrTypes[PixelTypes.StandardImageClass] = typeof(Rgba32); } public static bool HasFlag(this PixelTypes pixelTypes, PixelTypes flag) => (pixelTypes & flag) == flag; - public static bool IsEquivalentTo(this Image a, Image b, bool compareAlpha = true) - where TColor : struct, IPixel + public static bool IsEquivalentTo(this Image a, Image b, bool compareAlpha = true) + where TPixel : struct, IPixel { if (a.Width != b.Width || a.Height != b.Height) { @@ -58,16 +60,16 @@ namespace ImageSharp.Tests byte[] bytesA = new byte[3]; byte[] bytesB = new byte[3]; - using (PixelAccessor pixA = a.Lock()) + using (PixelAccessor pixA = a.Lock()) { - using (PixelAccessor pixB = b.Lock()) + using (PixelAccessor pixB = b.Lock()) { for (int y = 0; y < a.Height; y++) { for (int x = 0; x < a.Width; x++) { - TColor ca = pixA[x, y]; - TColor cb = pixB[x, y]; + TPixel ca = pixA[x, y]; + TPixel cb = pixB[x, y]; if (compareAlpha) { diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs index cea9cfea07..7d176c1e3e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -7,6 +7,8 @@ namespace ImageSharp.Tests { using System; + using ImageSharp.PixelFormats; + using Xunit; using Xunit.Abstractions; @@ -20,11 +22,11 @@ namespace ImageSharp.Tests private ITestOutputHelper Output { get; } [Theory] - [WithBlankImages(42, 666, PixelTypes.Color | PixelTypes.Argb32 | PixelTypes.HalfSingle, "hello")] - public void Use_WithEmptyImageAttribute(TestImageProvider provider, string message) - where TColor : struct, IPixel + [WithBlankImages(42, 666, PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.HalfSingle, "hello")] + public void Use_WithEmptyImageAttribute(TestImageProvider provider, string message) + where TPixel : struct, IPixel { - Image img = provider.GetImage(); + Image img = provider.GetImage(); Assert.Equal(42, img.Width); Assert.Equal(666, img.Height); @@ -33,12 +35,12 @@ namespace ImageSharp.Tests [Theory] [WithBlankImages(42, 666, PixelTypes.All, "hello")] - public void Use_WithBlankImagesAttribute_WithAllPixelTypes( - TestImageProvider provider, + public void Use_WithBlankImagesAttribute_WithAllPixelTypes( + TestImageProvider provider, string message) - where TColor : struct, IPixel + where TPixel : struct, IPixel { - Image img = provider.GetImage(); + Image img = provider.GetImage(); Assert.Equal(42, img.Width); Assert.Equal(666, img.Height); @@ -46,11 +48,11 @@ namespace ImageSharp.Tests } [Theory] - [WithBlankImages(1, 1, PixelTypes.Color, PixelTypes.Color)] + [WithBlankImages(1, 1, PixelTypes.Rgba32, PixelTypes.Rgba32)] [WithBlankImages(1, 1, PixelTypes.Alpha8, PixelTypes.Alpha8)] [WithBlankImages(1, 1, PixelTypes.StandardImageClass, PixelTypes.StandardImageClass)] - public void PixelType_PropertyValueIsCorrect(TestImageProvider provider, PixelTypes expected) - where TColor : struct, IPixel + public void PixelType_PropertyValueIsCorrect(TestImageProvider provider, PixelTypes expected) + where TPixel : struct, IPixel { Assert.Equal(expected, provider.PixelType); } @@ -58,11 +60,11 @@ namespace ImageSharp.Tests [Theory] [WithBlankImages(1, 1, PixelTypes.StandardImageClass)] [WithFile(TestImages.Bmp.F, PixelTypes.StandardImageClass)] - public void PixelTypes_ColorWithDefaultImageClass_TriggersCreatingTheNonGenericDerivedImageClass( - TestImageProvider provider) - where TColor : struct, IPixel + public void PixelTypes_ColorWithDefaultImageClass_TriggersCreatingTheNonGenericDerivedImageClass( + TestImageProvider provider) + where TPixel : struct, IPixel { - Image img = provider.GetImage(); + Image img = provider.GetImage(); Assert.IsType(img); } @@ -70,11 +72,11 @@ namespace ImageSharp.Tests [Theory] [WithFile(TestImages.Bmp.Car, PixelTypes.All, 88)] [WithFile(TestImages.Bmp.F, PixelTypes.All, 88)] - public void Use_WithFileAttribute(TestImageProvider provider, int yo) - where TColor : struct, IPixel + public void Use_WithFileAttribute(TestImageProvider provider, int yo) + where TPixel : struct, IPixel { Assert.NotNull(provider.Utility.SourceFileOrDescription); - Image img = provider.GetImage(); + Image img = provider.GetImage(); Assert.True(img.Width * img.Height > 0); Assert.Equal(88, yo); @@ -86,27 +88,27 @@ namespace ImageSharp.Tests public static string[] AllBmpFiles => TestImages.Bmp.All; [Theory] - [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Color | PixelTypes.Argb32)] - public void Use_WithFileCollection(TestImageProvider provider) - where TColor : struct, IPixel + [WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32 | PixelTypes.Argb32)] + public void Use_WithFileCollection(TestImageProvider provider) + where TPixel : struct, IPixel { Assert.NotNull(provider.Utility.SourceFileOrDescription); - Image image = provider.GetImage(); + Image image = provider.GetImage(); provider.Utility.SaveTestOutputFile(image, "png"); } [Theory] - [WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Color | PixelTypes.Argb32)] - public void Use_WithSolidFilledImagesAttribute(TestImageProvider provider) - where TColor : struct, IPixel + [WithSolidFilledImages(10, 20, 255, 100, 50, 200, PixelTypes.Rgba32 | PixelTypes.Argb32)] + public void Use_WithSolidFilledImagesAttribute(TestImageProvider provider) + where TPixel : struct, IPixel { - Image img = provider.GetImage(); + Image img = provider.GetImage(); Assert.Equal(img.Width, 10); Assert.Equal(img.Height, 20); byte[] colors = new byte[4]; - using (PixelAccessor pixels = img.Lock()) + using (PixelAccessor pixels = img.Lock()) { for (int y = 0; y < pixels.Height; y++) { @@ -124,23 +126,23 @@ namespace ImageSharp.Tests } /// - /// Need to us to create instance of when pixelType is StandardImageClass + /// Need to us to create instance of when pixelType is StandardImageClass /// - /// + /// /// /// - public static Image CreateTestImage(GenericFactory factory) - where TColor : struct, IPixel + public static Image CreateTestImage(GenericFactory factory) + where TPixel : struct, IPixel { return factory.CreateImage(3, 3); } [Theory] [WithMemberFactory(nameof(CreateTestImage), PixelTypes.All)] - public void Use_WithMemberFactoryAttribute(TestImageProvider provider) - where TColor : struct, IPixel + public void Use_WithMemberFactoryAttribute(TestImageProvider provider) + where TPixel : struct, IPixel { - Image img = provider.GetImage(); + Image img = provider.GetImage(); Assert.Equal(img.Width, 3); if (provider.PixelType == PixelTypes.StandardImageClass) { @@ -151,7 +153,7 @@ namespace ImageSharp.Tests public static readonly TheoryData BasicData = new TheoryData() { - TestImageProvider.Blank(10, 20), + TestImageProvider.Blank(10, 20), TestImageProvider.Blank( 10, 20), @@ -159,17 +161,17 @@ namespace ImageSharp.Tests [Theory] [MemberData(nameof(BasicData))] - public void Blank_MemberData(TestImageProvider provider) - where TColor : struct, IPixel + public void Blank_MemberData(TestImageProvider provider) + where TPixel : struct, IPixel { - Image img = provider.GetImage(); + Image img = provider.GetImage(); Assert.True(img.Width * img.Height > 0); } public static readonly TheoryData FileData = new TheoryData() { - TestImageProvider.File( + TestImageProvider.File( TestImages.Bmp.Car), TestImageProvider.File( TestImages.Bmp.F) @@ -177,13 +179,13 @@ namespace ImageSharp.Tests [Theory] [MemberData(nameof(FileData))] - public void File_MemberData(TestImageProvider provider) - where TColor : struct, IPixel + public void File_MemberData(TestImageProvider provider) + where TPixel : struct, IPixel { this.Output.WriteLine("SRC: " + provider.Utility.SourceFileOrDescription); this.Output.WriteLine("OUT: " + provider.Utility.GetTestOutputFileName()); - Image img = provider.GetImage(); + Image img = provider.GetImage(); Assert.True(img.Width * img.Height > 0); } diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 0d24410ac7..29623e1b59 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -11,6 +11,8 @@ namespace ImageSharp.Tests using System.Numerics; using System.Reflection; + using ImageSharp.PixelFormats; + using Xunit; using Xunit.Abstractions; @@ -23,12 +25,12 @@ namespace ImageSharp.Tests private ITestOutputHelper Output { get; } - public static Image CreateTestImage(GenericFactory factory) - where TColor : struct, IPixel + public static Image CreateTestImage(GenericFactory factory) + where TPixel : struct, IPixel { - Image image = factory.CreateImage(10, 10); + Image image = factory.CreateImage(10, 10); - using (PixelAccessor pixels = image.Lock()) + using (PixelAccessor pixels = image.Lock()) { for (int i = 0; i < 10; i++) { @@ -37,7 +39,7 @@ namespace ImageSharp.Tests Vector4 v = new Vector4(i, j, 0, 1); v /= 10; - TColor color = default(TColor); + TPixel color = default(TPixel); color.PackFromVector4(v); pixels[i, j] = color; @@ -51,50 +53,50 @@ namespace ImageSharp.Tests [Fact] public void Baz() { - Type type = typeof(Color).GetTypeInfo().Assembly.GetType("ImageSharp.Color"); + Type type = typeof(Rgba32).GetTypeInfo().Assembly.GetType("ImageSharp.PixelFormats.Rgba32"); this.Output.WriteLine(type.ToString()); - Type fake = typeof(Color).GetTypeInfo().Assembly.GetType("ImageSharp.dsaada_DASqewrr"); + Type fake = typeof(Rgba32).GetTypeInfo().Assembly.GetType("ImageSharp.dsaada_DASqewrr"); Assert.Null(fake); } [Theory] - [WithFile(TestImages.Bmp.Car, PixelTypes.Color, true)] - [WithFile(TestImages.Bmp.Car, PixelTypes.Color, false)] - public void IsEquivalentTo_WhenFalse(TestImageProvider provider, bool compareAlpha) - where TColor : struct, IPixel + [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, true)] + [WithFile(TestImages.Bmp.Car, PixelTypes.Rgba32, false)] + public void IsEquivalentTo_WhenFalse(TestImageProvider provider, bool compareAlpha) + where TPixel : struct, IPixel { - Image a = provider.GetImage(); - Image b = provider.GetImage(); + Image a = provider.GetImage(); + Image b = provider.GetImage(); b = b.OilPaint(3, 2); Assert.False(a.IsEquivalentTo(b, compareAlpha)); } [Theory] - [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.Bgr565, true)] - [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Color | PixelTypes.Bgr565, false)] - public void IsEquivalentTo_WhenTrue(TestImageProvider provider, bool compareAlpha) - where TColor : struct, IPixel + [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgba32 | PixelTypes.Bgr565, true)] + [WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgba32 | PixelTypes.Bgr565, false)] + public void IsEquivalentTo_WhenTrue(TestImageProvider provider, bool compareAlpha) + where TPixel : struct, IPixel { - Image a = provider.GetImage(); - Image b = provider.GetImage(); + Image a = provider.GetImage(); + Image b = provider.GetImage(); Assert.True(a.IsEquivalentTo(b, compareAlpha)); } [Theory] - [InlineData(PixelTypes.Color, typeof(Color))] + [InlineData(PixelTypes.Rgba32, typeof(Rgba32))] [InlineData(PixelTypes.Argb32, typeof(Argb32))] [InlineData(PixelTypes.HalfVector4, typeof(HalfVector4))] - [InlineData(PixelTypes.StandardImageClass, typeof(Color))] + [InlineData(PixelTypes.StandardImageClass, typeof(Rgba32))] public void ToType(PixelTypes pt, Type expectedType) { Assert.Equal(pt.ToType(), expectedType); } [Theory] - [InlineData(typeof(Color), PixelTypes.Color)] + [InlineData(typeof(Rgba32), PixelTypes.Rgba32)] [InlineData(typeof(Argb32), PixelTypes.Argb32)] public void GetPixelType(Type clrType, PixelTypes expectedPixelType) { @@ -112,7 +114,7 @@ namespace ImageSharp.Tests [Fact] public void ToTypes() { - PixelTypes pixelTypes = PixelTypes.Alpha8 | PixelTypes.Bgr565 | PixelTypes.Color | PixelTypes.HalfVector2 | PixelTypes.StandardImageClass; + PixelTypes pixelTypes = PixelTypes.Alpha8 | PixelTypes.Bgr565 | PixelTypes.Rgba32 | PixelTypes.HalfVector2 | PixelTypes.StandardImageClass; IEnumerable> expanded = pixelTypes.ExpandAllTypes(); @@ -120,9 +122,9 @@ namespace ImageSharp.Tests AssertContainsPixelType(PixelTypes.Alpha8, expanded); AssertContainsPixelType(PixelTypes.Bgr565, expanded); - AssertContainsPixelType(PixelTypes.Color, expanded); + AssertContainsPixelType(PixelTypes.Rgba32, expanded); AssertContainsPixelType(PixelTypes.HalfVector2, expanded); - AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); + AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); } [Fact] @@ -131,8 +133,8 @@ namespace ImageSharp.Tests KeyValuePair[] expanded = PixelTypes.All.ExpandAllTypes().ToArray(); Assert.True(expanded.Length >= TestUtilityExtensions.GetAllPixelTypes().Length - 2); - AssertContainsPixelType(PixelTypes.Color, expanded); - AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); + AssertContainsPixelType(PixelTypes.Rgba32, expanded); + AssertContainsPixelType(PixelTypes.StandardImageClass, expanded); } } } \ No newline at end of file